android.widget.EditText#setTypeface ( )源码实例Demo

下面列出了android.widget.EditText#setTypeface ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android-Shortify   文件: Views.java
public static $ font(String path){
    try{
        Typeface type = Typeface.createFromFile(path);
        if(mView instanceof TextView){
            TextView textView = (TextView) mView;
            textView.setTypeface(type);
        }
        else if(mView instanceof EditText){
            EditText editText = (EditText) mView;
            editText.setTypeface(type);
        }
        else if(mView instanceof Button){
            Button button = (Button) mView;
            button.setTypeface(type);
        }
    }catch (Exception e){
        Log.d(TAG, e.getMessage());
    }
    return  $.getInstance();
}
 
源代码2 项目: Mizuu   文件: AddNetworkFilesourceDialog.java
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

	setContentView(R.layout.addnetwork);

	server = (EditText) findViewById(R.id.server);
	domain = (EditText) findViewById(R.id.domain);
	username = (EditText) findViewById(R.id.username);
	password  = (EditText) findViewById(R.id.password);
	password.setTypeface(Typeface.DEFAULT);
	password.setTransformationMethod(new PasswordTransformationMethod());
	anonymous = (CheckBox) findViewById(R.id.checkBox);
	guest = (CheckBox) findViewById(R.id.checkBox2);

	guest.setOnCheckedChangeListener(changeListener);
	anonymous.setOnCheckedChangeListener(changeListener);

	isMovie = getIntent().getExtras().getString("type").equals("movie");

	LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("mizuu-network-search"));
}
 
源代码3 项目: polling-station-app   文件: ManualInputActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manual_input);
    Toolbar appBar = (Toolbar) findViewById(R.id.app_bar);
    setSupportActionBar(appBar);
    Util.setupAppBar(appBar, this);
    Typeface typeFace= Typeface.createFromAsset(getAssets(), "fonts/ro.ttf");

    docNumber = (EditText) findViewById(R.id.doc_num);
    docNumber.setTypeface(typeFace);
    TextView docNumTitle = (TextView) findViewById(R.id.doc_num_title);
    TextView dobTitle = (TextView) findViewById(R.id.dob_title);
    TextView expDateTitle = (TextView) findViewById(R.id.exp_date_title);
    docNumTitle.setTypeface(typeFace);
    dobTitle.setTypeface(typeFace);
    expDateTitle.setTypeface(typeFace);

    Button submitBut = (Button) findViewById(R.id.submit_button);
    submitBut.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if(verifyInput()) {
                Intent returnIntent = new Intent();
                returnIntent.putExtra(DocumentData.identifier, getData());
                setResult(Activity.RESULT_OK, returnIntent);
                finish();
            }
        }
    });
    setupDOBSpinners();
    setupExpirySpinners();

    // When docData was previously filled in, update text fields
    if(getIntent().hasExtra(DocumentData.identifier)) {
        putData(getIntent().getExtras());
    }
}
 
源代码4 项目: FaceT   文件: PostActivity.java
private View createView() {

        LayoutInflater inflater = LayoutInflater.from(getBaseContext());
        RelativeLayout view =
                (RelativeLayout) inflater.inflate(R.layout.activity_post, null, false);

        Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);

        mProductTitle = (EditText) view.findViewById(R.id.product_title);
        mProductDesc = (EditText) view.findViewById(R.id.product_desc);
        mProductBrand = (EditText) view.findViewById(R.id.product_brand_edittext);
        mProductTitle.setTypeface(fontType);
        mProductDesc.setTypeface(fontType);
        mProductBrand.setTypeface(fontType);

        spinner = (Spinner) view.findViewById(R.id.product_type_spinner);
        FontManager.markAsIconContainer(findViewById(R.id.product_type_spinner), fontType);
        ArrayAdapter<CharSequence> typeList = ArrayAdapter.createFromResource(PostActivity.this,
                R.array.product_type_array,
                android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(typeList);

        mProgress = new ProgressDialog(this);
//        mSubmitBtn = (Button) view.findViewById(R.id.submit_btn);
//        mSubmitBtn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                startPosting();
//            }
//        });
        return view;
    }
 
源代码5 项目: hr   文件: OEditTextField.java
public void initControl() {
    // Creating control
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    removeAllViews();
    setOrientation(VERTICAL);
    if (mEditable) {
        edtText = new EditText(mContext);
        edtText.setTypeface(OControlHelper.lightFont());
        edtText.setLayoutParams(params);
        edtText.setBackgroundColor(Color.TRANSPARENT);
        edtText.setPadding(0, 10, 10, 10);
        edtText.setHint(getLabel());
        edtText.setOnFocusChangeListener(this);
        if (textSize > -1) {
            edtText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            edtText.setTextAppearance(mContext, appearance);
        }
        edtText.setTextColor(textColor);
        addView(edtText);
    } else {
        txvText = new TextView(mContext);
        txvText.setTypeface(OControlHelper.lightFont());
        txvText.setLayoutParams(params);
        txvText.setBackgroundColor(Color.TRANSPARENT);
        txvText.setPadding(0, 10, 10, 10);
        if (textSize > -1) {
            txvText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            txvText.setTextAppearance(mContext, appearance);
        }
        txvText.setTextColor(textColor);
        addView(txvText);
    }
}
 
源代码6 项目: framework   文件: OEditTextField.java
public void initControl() {
    // Creating control
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    removeAllViews();
    setOrientation(VERTICAL);
    if (mEditable) {
        edtText = new EditText(mContext);
        edtText.setTypeface(OControlHelper.lightFont());
        edtText.setLayoutParams(params);
        edtText.setBackgroundColor(Color.TRANSPARENT);
        edtText.setPadding(0, 10, 10, 10);
        edtText.setHint(getLabel());
        edtText.setOnFocusChangeListener(this);
        if (textSize > -1) {
            edtText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            edtText.setTextAppearance(mContext, appearance);
        }
        edtText.setTextColor(textColor);
        addView(edtText);
    } else {
        txvText = new TextView(mContext);
        txvText.setTypeface(OControlHelper.lightFont());
        txvText.setLayoutParams(params);
        txvText.setBackgroundColor(Color.TRANSPARENT);
        txvText.setPadding(0, 10, 10, 10);
        if (textSize > -1) {
            txvText.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            txvText.setTextAppearance(mContext, appearance);
        }
        txvText.setTextColor(textColor);
        addView(txvText);
    }
}
 
源代码7 项目: QuickLyric   文件: LyricsViewFragment.java
private void startEditTagsMode() {
    ImageButton editButton = getActivity().findViewById(R.id.edit_tags_btn);
    editButton.setImageResource(R.drawable.ic_edit_anim);
    ((Animatable) editButton.getDrawable()).start();

    ((DrawerLayout) ((MainActivity) getActivity()).drawer).setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mRefreshLayout.setEnabled(false);
    getActivity().findViewById(R.id.refresh_fab).setEnabled(false);
    ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide();
    ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear();

    ViewSwitcher viewSwitcher = getActivity().findViewById(R.id.switcher);
    EditText songTV = getActivity().findViewById(R.id.song);
    TextView artistTV = getActivity().findViewById(R.id.artist);

    EditText newLyrics = getActivity().findViewById(R.id.edit_lyrics);
    newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity()));
    newLyrics.setText(Html.fromHtml(TextUtils.isEmpty(mLyrics.getText()) ? "" : mLyrics.getText()), TextView.BufferType.EDITABLE);

    viewSwitcher.setVisibility(View.GONE);
    newLyrics.setVisibility(View.VISIBLE);

    songTV.setInputType(InputType.TYPE_CLASS_TEXT);
    artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
    songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
    artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);


    if (songTV.requestFocus()) {
        InputMethodManager imm = (InputMethodManager)
                getActivity().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT);
    }
}
 
源代码8 项目: PLDroidShortVideo   文件: TransitionEditView.java
private void cloneEditText(EditText dstText, EditText srcText) {
    dstText.setText(srcText.getText());
    dstText.setTextColor(srcText.getTextColors());
    dstText.setTypeface(srcText.getTypeface());
    dstText.setTextSize(TypedValue.COMPLEX_UNIT_PX, srcText.getTextSize());
}
 
源代码9 项目: Rey-MusicPlayer   文件: EqualizerActivity.java
/**
 * Builds the "Save Preset" dialog. Does not call the show() method, so you
 * should do this manually when calling this method.
 *
 * @return A fully built AlertDialog reference.
 */
private AlertDialog buildSavePresetDialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View dialogView = getLayoutInflater().inflate(R.layout.add_new_equalizer_preset_dialog_layout, null);

    final EditText newPresetNameField = (EditText) dialogView.findViewById(R.id.new_preset_name_text_field);
    newPresetNameField.setTypeface(TypefaceHelper.getTypeface(mContext, TypefaceHelper.FUTURA_BOOK));
    newPresetNameField.setPaintFlags(newPresetNameField.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);


    //Set the dialog title.
    builder.setTitle(R.string.save_preset);
    builder.setView(dialogView);
    builder.setNegativeButton(R.string.cancel, (dialog, arg1) -> dialog.dismiss());

    builder.setPositiveButton(R.string.done, (dialog, which) -> {

        //Get the preset name from the text field.
        String presetName = newPresetNameField.getText().toString();

        //Add the preset and it's values to the DB.
        mApp.getDBAccessHelper().addNewEQPreset(presetName,
                fiftyHertzLevel,
                oneThirtyHertzLevel,
                threeTwentyHertzLevel,
                eightHundredHertzLevel,
                twoKilohertzLevel,
                fiveKilohertzLevel,
                twelvePointFiveKilohertzLevel,
                (short) mVirtualizerSeekArc.getProgress(),
                (short) mBassBoostSeekArc.getProgress(),
                (short) mReverbSpinner.getSelectedItemPosition());

        Toast.makeText(mContext, R.string.preset_saved, Toast.LENGTH_SHORT).show();
        dialog.dismiss();
    });

    return builder.create();

}
 
源代码10 项目: Yahala-Messenger   文件: UpdatesActivity.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    if (fragmentView == null) {

            /*searching = false;
            searchWas = false;*/


        // NotificationCenter.getInstance().addObserver(this,MessagesController.dialogDidLoaded);

        fragmentView = inflater.inflate(R.layout.updates, container, false);
        TextView welcome = (TextView) fragmentView.findViewById(R.id.welcome);
        TextView updateStatus = (TextView) fragmentView.findViewById(R.id.updateStatus);
        final EditText statusText = (EditText) fragmentView.findViewById(R.id.status_text);
        Button updateButton = (Button) fragmentView.findViewById(R.id.update_button);

        Typeface typefaceR = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), "fonts/Roboto-Regular.ttf");
        Typeface typefaceL = Typeface.createFromAsset(ApplicationLoader.applicationContext.getAssets(), "fonts/Roboto-Light.ttf");

        welcome.setTypeface(typefaceR);
        updateStatus.setTypeface(typefaceL);
        updateButton.setTypeface(typefaceL);
        statusText.setTypeface(typefaceL);
        try {
            statusText.setText(UserConfig.clientUserStatus);
        } catch (Exception e) {
            e.printStackTrace();
        }
        updateButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FileLog.e("Test", "onClick");
                UserConfig.clientUserStatus = statusText.getText().toString();
                UserConfig.saveConfig(false);
            }
        });
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}
 
源代码11 项目: Cirrus_depricated   文件: AuthenticatorActivity.java
/**
 * 
 * @param savedInstanceState        Saved activity state, as in {{@link #onCreate(Bundle)}
 */
private void initAuthorizationPreFragment(Bundle savedInstanceState) {
    
    /// step 0 - get UI elements in layout
    mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);
    mOAuthAuthEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_1);
    mOAuthTokenEndpointText = (TextView)findViewById(R.id.oAuthEntryPoint_2);
    mUsernameInput = (EditText) findViewById(R.id.account_username);
    mPasswordInput = (EditText) findViewById(R.id.account_password);
    mPasswordInput.setTypeface(mUsernameInput.getTypeface());
    mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); 
    
    /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)
    String presetUserName = null;
    boolean isPasswordExposed = false;
    if (savedInstanceState == null) {
        if (mAccount != null) {
            presetUserName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));
        }
        
    } else {
        isPasswordExposed = savedInstanceState.getBoolean(KEY_PASSWORD_EXPOSED, false);
        mAuthStatusText = savedInstanceState.getInt(KEY_AUTH_STATUS_TEXT);
        mAuthStatusIcon = savedInstanceState.getInt(KEY_AUTH_STATUS_ICON);
        mAuthToken = savedInstanceState.getString(KEY_AUTH_TOKEN);
    }
    
    /// step 2 - set properties of UI elements (text, visibility, enabled...)
    mOAuth2Check.setChecked(
            AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType())
                .equals(mAuthTokenType));
    if (presetUserName != null) {
        mUsernameInput.setText(presetUserName);
    }
    if (mAction != ACTION_CREATE) {
        mUsernameInput.setEnabled(false);
        mUsernameInput.setFocusable(false);
    }
    mPasswordInput.setText(""); // clean password to avoid social hacking
    if (isPasswordExposed) {
        showPassword();
    }
    updateAuthenticationPreFragmentVisibility();
    showAuthStatus();
    mOkButton.setEnabled(mServerIsValid);

    
    /// step 3 - bind listeners
    // bindings for password input field
    mPasswordInput.setOnFocusChangeListener(this);
    mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
    mPasswordInput.setOnEditorActionListener(this);
    mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() {
        @Override
        public boolean onDrawableTouch(final MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                AuthenticatorActivity.this.onViewPasswordClick();
            }
            return true;
        }
    });
    
}
 
源代码12 项目: GittyReporter   文件: GittyReporter.java
@Override
final protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gitty_reporter_layout);

    // Get Device info and print them in EditText
    deviceInfoEditText = (EditText) findViewById(R.id.gittyreporter_device_info);
    getDeviceInfo();
    deviceInfoEditText.setText(deviceInfo);

    init(savedInstanceState);

    final View nextFab = findViewById(R.id.gittyreporter_fab_next);
    final View sendFab = findViewById(R.id.gittyreporter_fab_send);

    if (!enableGitHubLogin){
        nextFab.setVisibility(View.INVISIBLE);
        sendFab.setVisibility(View.VISIBLE);
    }

    AppCompatCheckBox githubCheckbox = (AppCompatCheckBox) findViewById(R.id.gittyreporter_github_checkbox);
    AppCompatButton registerButton = (AppCompatButton) findViewById(R.id.gittyreporter_github_register);

    final EditText userName = (EditText) findViewById(R.id.gittyreporter_login_username);
    final EditText userPassword = (EditText) findViewById(R.id.gittyreporter_login_password);

    userPassword.setTypeface(Typeface.DEFAULT);
    userPassword.setTransformationMethod(new PasswordTransformationMethod());

    if (!enableGuestGitHubLogin){
        githubCheckbox.setChecked(false);
        githubCheckbox.setVisibility(View.GONE);
        registerButton.setVisibility(View.VISIBLE);
    }

    githubCheckbox.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked){
                        userName.setEnabled(false);
                        userName.setText("");
                        userPassword.setEnabled(false);
                        userPassword.setText("");
                    } else {
                        userName.setEnabled(true);
                        userPassword.setEnabled(true);
                    }
                }
            }
    );
}
 
源代码13 项目: Bitocle   文件: LoginActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    /*
     * 检测用户登陆状态
     *
     * 如果SharedPreferences中存在用户信息,
     * 则说明用户已经登陆,此时直接跳转到MainActivity即可;
     * 否则进入登陆界面
     */
    sharedPreferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
    String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null);
    if (oAuth != null) {
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        intent.putExtra(getString(R.string.login_intent), false);
        startActivity(intent);
        finish();
    }

    getActionBar().setDisplayShowHomeEnabled(false);

    final EditText userText = (EditText) findViewById(R.id.login_username);
    final EditText passText = (EditText) findViewById(R.id.login_password);
    /* 保持EditText字体的一致性 */
    passText.setTypeface(Typeface.DEFAULT);
    passText.setTransformationMethod(new PasswordTransformationMethod());
    Button button = (Button) findViewById(R.id.login_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            username = userText.getText().toString();
            password = passText.getText().toString();

            /* 给出相应的错误提示 */
            if (username.length() == 0 && password.length() == 0) {
                SuperToast.create(
                        LoginActivity.this,
                        getString(R.string.login_message_miss_both),
                        SuperToast.Duration.SHORT,
                        Style.getStyle(Style.RED)
                ).show();
            } else if (username.length() != 0 && password.length() == 0) {
                SuperToast.create(
                        LoginActivity.this,
                        getString(R.string.login_message_miss_password),
                        SuperToast.Duration.SHORT,
                        Style.getStyle(Style.RED)
                ).show();
            } else if (username.length() == 0 && password.length() != 0) {
                SuperToast.create(
                        LoginActivity.this,
                        getString(R.string.login_message_miss_username),
                        SuperToast.Duration.SHORT,
                        Style.getStyle(Style.RED)
                ).show();
            } else {
                /* ProgressDialog显示当前正在运行的状态 */
                progressDialog = new ProgressDialog(LoginActivity.this);
                progressDialog.setMessage(getString(R.string.login_message_authoring));
                progressDialog.setCancelable(false);
                progressDialog.show();
                /* 开启新的线程用于认证 */
                HandlerThread handlerThread = new HandlerThread(getString(R.string.login_thread));
                handlerThread.start();
                Handler handler = new Handler(handlerThread.getLooper());
                handler.post(authorizationThread);
            }
        }
    });

}
 
源代码14 项目: Bitocle   文件: LoginActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    // getActionBar().setIcon(R.drawable.ic_launcher_black);

    /*
     * 检测用户登陆状态
     *
     * 如果SharedPreferences中存在用户信息,
     * 则说明用户已经登陆,此时直接跳转到MainActivity即可;
     * 否则进入登陆界面
     */
    sharedPreferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
    String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null);
    if (oAuth != null) {
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        intent.putExtra(getString(R.string.login_intent), false);
        startActivity(intent);
        finish();
    }

    final EditText userText = (EditText) findViewById(R.id.login_username);
    final EditText passText = (EditText) findViewById(R.id.login_password);
    /* 保持EditText字体的一致性 */
    passText.setTypeface(Typeface.DEFAULT);
    passText.setTransformationMethod(new PasswordTransformationMethod());
    Button button = (Button) findViewById(R.id.login_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            username = userText.getText().toString();
            password = passText.getText().toString();

            /* 给出相应的错误提示 */
            if (username.length() == 0 && password.length() == 0) {
                Toast.makeText(
                        LoginActivity.this,
                        R.string.login_message_miss_username_and_password,
                        Toast.LENGTH_SHORT
                ).show();
            } else if (username.length() != 0 && password.length() == 0) {
                Toast.makeText(
                        LoginActivity.this,
                        R.string.login_message_miss_password,
                        Toast.LENGTH_SHORT
                ).show();
            } else if (username.length() == 0 && password.length() != 0) {
                Toast.makeText(
                        LoginActivity.this,
                        R.string.login_message_miss_username,
                        Toast.LENGTH_SHORT
                ).show();
            } else {
                /* ProgressDialog显示当前正在运行的状态 */
                progressDialog = new ProgressDialog(LoginActivity.this);
                progressDialog.setMessage(getString(R.string.login_message_authoring));
                progressDialog.setCancelable(false);
                progressDialog.show();
                /* 开启新的线程用于认证 */
                HandlerThread handlerThread = new HandlerThread(getString(R.string.login_thread));
                handlerThread.start();
                Handler handler = new Handler(handlerThread.getLooper());
                handler.post(authorizationThread);
            }
        }
    });

}
 
源代码15 项目: Bitocle   文件: LoginActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    /*
     * 检测用户登陆状态
     *
     * 如果SharedPreferences中存在用户信息,
     * 则说明用户已经登陆,此时直接跳转到MainActivity即可;
     * 否则进入登陆界面
     */
    sharedPreferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
    String oAuth = sharedPreferences.getString(getString(R.string.login_sp_oauth), null);
    if (oAuth != null) {
        Intent intent = new Intent(LoginActivity.this, MainActivity.class);
        intent.putExtra(getString(R.string.login_intent), false);
        startActivity(intent);
        finish();
    }

    getActionBar().setDisplayShowHomeEnabled(false);

    final EditText userText = (EditText) findViewById(R.id.login_username);
    final EditText passText = (EditText) findViewById(R.id.login_password);
    /* 保持EditText字体的一致性 */
    passText.setTypeface(Typeface.DEFAULT);
    passText.setTransformationMethod(new PasswordTransformationMethod());
    Button button = (Button) findViewById(R.id.login_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            username = userText.getText().toString();
            password = passText.getText().toString();

            /* 给出相应的错误提示 */
            if (username.length() == 0 && password.length() == 0) {
                SuperToast.create(
                        LoginActivity.this,
                        getString(R.string.login_message_miss_both),
                        SuperToast.Duration.SHORT,
                        Style.getStyle(Style.RED)
                ).show();
            } else if (username.length() != 0 && password.length() == 0) {
                SuperToast.create(
                        LoginActivity.this,
                        getString(R.string.login_message_miss_password),
                        SuperToast.Duration.SHORT,
                        Style.getStyle(Style.RED)
                ).show();
            } else if (username.length() == 0 && password.length() != 0) {
                SuperToast.create(
                        LoginActivity.this,
                        getString(R.string.login_message_miss_username),
                        SuperToast.Duration.SHORT,
                        Style.getStyle(Style.RED)
                ).show();
            } else {
                /* ProgressDialog显示当前正在运行的状态 */
                progressDialog = new ProgressDialog(LoginActivity.this);
                progressDialog.setMessage(getString(R.string.login_message_authoring));
                progressDialog.setCancelable(false);
                progressDialog.show();
                /* 开启新的线程用于认证 */
                HandlerThread handlerThread = new HandlerThread(getString(R.string.login_thread));
                handlerThread.start();
                Handler handler = new Handler(handlerThread.getLooper());
                handler.post(authorizationThread);
            }
        }
    });

}
 
源代码16 项目: Android-SDK   文件: LoginActivity.java
@Override
public void onCreate( Bundle savedInstanceState )
{
  super.onCreate( savedInstanceState );
  setContentView( R.layout.login );

  progressDialog = UIFactory.getDefaultProgressDialog( this );

  //Initializing Backendless API
  Backendless.initApp( this, Defaults.APPLICATION_ID, Defaults.APPLICATION_API_KEY, Defaults.APPLICATION_VERSION );

  //Binding UI elements
  emailField = (EditText) findViewById( R.id.emailField );
  passwordField = (EditText) findViewById( R.id.passwordField );
  passwordField.setTypeface( Typeface.DEFAULT );
  passwordField.setTransformationMethod( new PasswordTransformationMethod() );

  //Checking for a login intent (it can be send from a Registration activity)
  Intent intent = getIntent();
  userEmail = intent.getStringExtra( BackendlessUser.EMAIL_KEY );
  String userPassword = intent.getStringExtra( BackendlessUser.PASSWORD_KEY );

  //Checking if user is already logged in and was saved in Backendless.UserService.CurrentUser
  if( (userEmail == null || userPassword == null) && Backendless.UserService.CurrentUser() != null )
  {
    userEmail = Backendless.UserService.CurrentUser().getEmail();
    userPassword = Backendless.UserService.CurrentUser().getPassword();
  }

  if( userEmail != null )
    emailField.setText( userEmail );

  if( userEmail != null && userPassword != null )
  {
    //Sending login request asynchronously from the intent credentials
    Backendless.UserService.login( userEmail, userPassword, loginCallback );
  }
  else
  {
    Button loginButton = (Button) findViewById( R.id.loginButton );
    loginButton.setOnClickListener( loginListener );

    findViewById( R.id.registerButton ).setOnClickListener( registerListener );
    progressDialog.cancel();
  }

  Button loginFacebookButton = (Button) findViewById( R.id.loginFacebookButton );
  loginFacebookButton.setVisibility( View.INVISIBLE );
  TextView loginFacebookText = (TextView) findViewById( R.id.loginWith );
  loginFacebookText.setVisibility( View.INVISIBLE );
}