Example #1
0
  private void onChangePassword(CharSequence old, CharSequence new1, CharSequence new2) {
    if (!new1.toString().equals(new2.toString())) {
      showMsg(R.string.pref_dialog_pwd_mismatch);
      return;
    }

    if (mModel.changePassword(old, new1)) {
      showMsg(R.string.pref_dialog_pwd_success);
      mModel.save();
    } else {
      showMsg(R.string.pref_dialog_pwd_incorrect);
    }
  }
Example #2
0
 private void doDeleteData() {
   if (mModel.delete()) {
     showMsg(R.string.pref_dialog_del_success);
   } else {
     showMsg(R.string.pref_dialog_del_fail);
   }
 }
Example #3
0
  private void onExportData() {
    List<Item> items = mModel.getItems();
    File output = new File(EXTERNAL_DIR, FILENAME);
    if (!output.getParentFile().canWrite()) {
      showMsg(super.getString(R.string.pref_dialog_export_data_cannot_write) + output.getPath());
      return;
    }

    try {
      FileOutputStream fos = new FileOutputStream(output);
      boolean success = mModel.saveHelper(fos, items);
      if (success) {
        showMsg(R.string.pref_dialog_done);
      } else {
        showMsg(R.string.pref_dialog_export_data_fail);
      }
    } catch (Exception e) {
      showMsg("Exception occurred!");
      e.printStackTrace();
    }
  }
Example #4
0
  private void updateVisibility() {
    Preference exportPref = findPreference(KEY_EXPORT_DATA);
    Preference importPref = findPreference(KEY_IMPORT_DATA);
    Preference changePref = findPreference(KEY_CHANGE_PASSWORD);
    Preference sendPref = findPreference(KEY_SEND_DATA);

    if (mModel.status() == DataStatus.OK) {
      exportPref.setEnabled(true);
      importPref.setEnabled(true);
      changePref.setEnabled(true);
      sendPref.setEnabled(true);
    } else {
      exportPref.setEnabled(false);
      importPref.setEnabled(false);
      changePref.setEnabled(false);
      sendPref.setEnabled(false);
    }

    if (mModel.status() == DataStatus.FILE_IS_EMPTY) {
      importPref.setEnabled(true);
    }
  }
Example #5
0
  private void onImportData(CharSequence password) {
    File input = new File(EXTERNAL_DIR, FILENAME);
    if (!input.exists()) {
      showMsg(super.getString(R.string.pref_dialog_import_data_fail) + input.getPath());
      return;
    }

    try {
      FileInputStream fis = new FileInputStream(input);
      List<Item> list = mModel.loadHelper(fis, password);
      if (list != null) {
        for (int i = 0; i < list.size(); i++) {
          mModel.addItem(list.get(i));
        }
        mModel.save();
        showMsg(super.getString(R.string.pref_dialog_done));
      } else {
        showMsg(super.getString(R.string.pref_dialog_import_data_fail));
      }
    } catch (Exception e) {
      showMsg("Exception occurred!");
      e.printStackTrace();
    }
  }
Example #6
0
 @Override
 public void onPause() {
   super.onResume();
   mModel.removeListener(this);
 }
Example #7
0
 @Override
 public void onResume() {
   super.onResume();
   mModel.addListener(this);
 }