Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    tracker.start(TipsetApplication.ANALYTICS_KEY, this);
    tracker.trackPageView(this.getLocalClassName());

    mUser = (EditText) findViewById(R.id.userInput);
    mPassword = (EditText) findViewById(R.id.passwordInput);
    mSavePrefs = (CheckBox) findViewById(R.id.checkbox);

    Button confirmButton = (Button) findViewById(R.id.login);
    Button aboutButton = (Button) findViewById(R.id.about_button);
    confirmButton.setOnClickListener(this);
    aboutButton.setOnClickListener(this);

    progressDialog = new ProgressDialog(this);
    progressDialog.setTitle(R.string.loading_dialog_title);
    progressDialog.setMessage(getString(R.string.login_dialog_text));
    progressDialog.setCancelable(true);

    // Initializes the alert dialog.
    alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.loginFailed));
    alertDialog.setMessage(getString(R.string.loginFailedText));
    alertDialog.setButton(
        getString(R.string.ok),
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            return;
          }
        });

    // Initializes SharedPreferences
    SharedPreferences prefs = getPreferences(MODE_PRIVATE);

    try {
      mUser.setText(
          SimpleCrypto.decrypt(TipsetApplication.CRYPTO_KEY, prefs.getString("user", "")));
      mPassword.setText(
          SimpleCrypto.decrypt(TipsetApplication.CRYPTO_KEY, prefs.getString("pass", "")));
      mSavePrefs.setChecked(prefs.getBoolean("save", false));
    } catch (Exception e) {
      _logger.log(Level.SEVERE, e.getMessage(), e);
    }
  }
Пример #2
0
  private void savePrefs() {
    SharedPreferences prefs = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();

    try {
      if (mSavePrefs.isChecked()) {
        editor.putString(
            "user", SimpleCrypto.encrypt(TipsetApplication.CRYPTO_KEY, mUser.getText().toString()));
        editor.putString(
            "pass",
            SimpleCrypto.encrypt(TipsetApplication.CRYPTO_KEY, mPassword.getText().toString()));
        editor.putBoolean("save", true);
        editor.commit();

      } else {
        editor.clear();
        editor.commit();
      }

    } catch (Exception e) {
      _logger.log(Level.SEVERE, e.getMessage(), e);
    }
  }