code and ui refactoring in the Password activity, encapsulation and wrappers.

This commit is contained in:
Ernir Erlingsson
2015-12-08 23:56:34 +01:00
parent d0342f9a4e
commit 27edc2e3e8
9 changed files with 208 additions and 86 deletions

View File

@@ -0,0 +1,56 @@
package org.briarproject.android;
import static android.view.inputmethod.InputMethodManager.HIDE_IMPLICIT_ONLY;
import static org.briarproject.android.TestingConstants.PREVENT_SCREENSHOTS;
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.inputmethod.InputMethodManager;
import roboguice.activity.RoboActivity;
public abstract class BaseActivity extends RoboActivity {
private final static String PREFS_DB = "db";
private final static String KEY_DB_KEY = "key";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
}
private SharedPreferences getBriarPrefs(String prefsName) {
return getSharedPreferences(prefsName, MODE_PRIVATE);
}
protected String getDbKeyInHex() {
return getBriarPrefs(PREFS_DB).getString(KEY_DB_KEY, null);
}
private void clearPrefs(String prefsName) {
SharedPreferences.Editor editor = getBriarPrefs(prefsName).edit();
editor.clear();
editor.apply();
}
protected void clearDbPrefs() {
this.clearPrefs(PREFS_DB);
}
protected void gotoAndFinish(Class classInstance, int resultCode) {
if (resultCode != Integer.MIN_VALUE)
this.setResult(resultCode);
this.startActivity(new Intent(this, classInstance));
this.finish();
}
protected void hideSoftKeyboard()
{
Object o = getSystemService(INPUT_METHOD_SERVICE);
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
}
}