private static final int ACTION_SELECT_UPLOAD_PATH = 1;
private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH = 2;
+ private static final int ACTION_REQUEST_PASSCODE = 5;
+ private static final int ACTION_CONFIRM_PASSCODE = 6;
private static final int ACTION_SELECT_STORAGE_PATH = 3;
private static final int ACTION_PERFORM_MIGRATION = 4;
private PreferenceWithLongSummary mPrefStoragePath;
private String mStoragePath;
+
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
registerForContextMenu(getListView());
pCode = (CheckBoxPreference) findPreference("set_pincode");
- if (pCode != null){
+ if (pCode != null) {
pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
- Boolean enable = (Boolean) newValue;
+ Boolean incoming = (Boolean) newValue;
+
i.setAction(
- enable.booleanValue() ? PassCodeActivity.ACTION_ENABLE :
- PassCodeActivity.ACTION_DISABLE
+ incoming.booleanValue() ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT :
+ PassCodeActivity.ACTION_CHECK_WITH_RESULT
);
- startActivity(i);
-
- return true;
+
+ startActivityForResult(i, incoming.booleanValue() ? ACTION_REQUEST_PASSCODE :
+ ACTION_CONFIRM_PASSCODE);
+
+ // Don't update just yet, we will decide on it in onActivityResult
+ return false;
}
- });
+ });
}
} else if (requestCode == ACTION_PERFORM_MIGRATION && resultCode == RESULT_OK) {
String resultStorageDir = data.getStringExtra(StorageMigrationActivity.KEY_MIGRATION_TARGET_DIR);
saveStoragePath(resultStorageDir);
+ } else if (requestCode == ACTION_REQUEST_PASSCODE && resultCode == RESULT_OK) {
+ String passcode = data.getStringExtra(PassCodeActivity.KEY_PASSCODE);
+ if (passcode != null && passcode.length() == 4) {
+ SharedPreferences.Editor appPrefs = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext()).edit();
+
+ for (int i = 1; i <= 4; ++i) {
+ appPrefs.putString("PrefPinCode" + i, passcode.substring(i-1, i));
+ }
+ appPrefs.putBoolean("set_pincode", true);
+ appPrefs.commit();
+ Toast.makeText(this, R.string.pass_code_stored, Toast.LENGTH_LONG).show();
+ }
+ } else if (requestCode == ACTION_CONFIRM_PASSCODE && resultCode == RESULT_OK) {
+ if (data.getBooleanExtra(PassCodeActivity.KEY_CHECK_RESULT, false)) {
+
+ SharedPreferences.Editor appPrefs = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext()).edit();
+ appPrefs.putBoolean("set_pincode", false);
+ appPrefs.commit();
+
+ Toast.makeText(this, R.string.pass_code_removed, Toast.LENGTH_LONG).show();
+ }
}
}