예제 #1
0
 private void rememberClick() {
   String remember = checkbox_remember.isChecked() ? "1" : "0";
   GlobalContext.setPreference(GlobalContext.PREF.REMEMBER, remember);
   if (remember.equals("1")) {
     GlobalContext.setPreference(
         GlobalContext.PREF.USERNAME, edittext_username.getText().toString());
     GlobalContext.setPreference(
         GlobalContext.PREF.PASSWORD, edittext_password.getText().toString());
   } else {
     GlobalContext.setPreference(GlobalContext.PREF.USERNAME, "");
     GlobalContext.setPreference(GlobalContext.PREF.PASSWORD, "");
   }
 }
예제 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen01);
    GlobalContext.setContext(getApplicationContext());
    SQLite.staticInitialization(getApplicationContext());

    // guardarmos la screen01 en el contexto porque luego de que el usuario se haya logueado
    // no nos interesará más volver a a ella, y querremos invocar su método: finish().
    // No es necesario guardar todas las activities en el contexto, sino sólo aquellas
    // que se puedan necesitar más adelante
    GlobalContext.screen01 = this;
    initControls();
  }
예제 #3
0
  private void initControls() {

    edittext_username = (EditText) findViewById(R.id.edittext_username);
    edittext_password = (EditText) findViewById(R.id.edittext_password);
    checkbox_remember = (CheckBox) findViewById(R.id.checkbox_remember);
    button_login = (Button) findViewById(R.id.button_login);
    button_register = (Button) findViewById(R.id.button_register);
    button_clear = (Button) findViewById(R.id.button_clear);
    button_exit = (Button) findViewById(R.id.button_exit);

    edittext_username.addTextChangedListener(
        new TextWatcher() {
          public void onTextChanged(CharSequence seq, int start, int before, int count) {
            if (checkbox_remember.isChecked())
              GlobalContext.setPreference(GlobalContext.PREF.USERNAME, seq.toString());
          }

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void afterTextChanged(Editable s) {}
        });

    edittext_password.addTextChangedListener(
        new TextWatcher() {
          public void onTextChanged(CharSequence seq, int start, int before, int count) {
            if (checkbox_remember.isChecked())
              GlobalContext.setPreference(GlobalContext.PREF.PASSWORD, seq.toString());
          }

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void afterTextChanged(Editable s) {}
        });

    checkbox_remember.setOnClickListener(
        new CheckBox.OnClickListener() {
          public void onClick(View v) {
            rememberClick();
          }
        });

    button_login.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            loginClick();
          }
        });
    button_register.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            registerClick();
          }
        });
    button_clear.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            clearClick();
          }
        });
    button_exit.setOnClickListener(
        new Button.OnClickListener() {
          public void onClick(View v) {
            exitClick();
          }
        });

    String remember = GlobalContext.getPreference(GlobalContext.PREF.REMEMBER);
    if (remember != null && remember.equals("1")) {
      edittext_username.setText(GlobalContext.getPreference(GlobalContext.PREF.USERNAME));
      edittext_password.setText(GlobalContext.getPreference(GlobalContext.PREF.PASSWORD));
      checkbox_remember.setChecked(true);
    }
  }