mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
tabs to spaces.
This commit is contained in:
@@ -64,405 +64,405 @@ import com.keepassdroid.utils.Util;
|
|||||||
|
|
||||||
public class PasswordActivity extends LockingActivity {
|
public class PasswordActivity extends LockingActivity {
|
||||||
|
|
||||||
public static final String KEY_DEFAULT_FILENAME = "defaultFileName";
|
public static final String KEY_DEFAULT_FILENAME = "defaultFileName";
|
||||||
private static final String KEY_FILENAME = "fileName";
|
private static final String KEY_FILENAME = "fileName";
|
||||||
private static final String KEY_KEYFILE = "keyFile";
|
private static final String KEY_KEYFILE = "keyFile";
|
||||||
private static final String KEY_PASSWORD = "password";
|
private static final String KEY_PASSWORD = "password";
|
||||||
private static final String KEY_LAUNCH_IMMEDIATELY = "launchImmediately";
|
private static final String KEY_LAUNCH_IMMEDIATELY = "launchImmediately";
|
||||||
private static final String VIEW_INTENT = "android.intent.action.VIEW";
|
private static final String VIEW_INTENT = "android.intent.action.VIEW";
|
||||||
|
|
||||||
private static final int FILE_BROWSE = 256;
|
|
||||||
public static final int GET_CONTENT = 257;
|
|
||||||
|
|
||||||
private String mFileName;
|
private static final int FILE_BROWSE = 256;
|
||||||
private String mKeyFile;
|
public static final int GET_CONTENT = 257;
|
||||||
private boolean mRememberKeyfile;
|
|
||||||
SharedPreferences prefs;
|
|
||||||
|
|
||||||
public static void Launch(Activity act, String fileName) throws FileNotFoundException {
|
|
||||||
Launch(act,fileName,"");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Launch(Activity act, String fileName, String keyFile) throws FileNotFoundException {
|
|
||||||
File dbFile = new File(fileName);
|
|
||||||
if ( ! dbFile.exists() ) {
|
|
||||||
throw new FileNotFoundException();
|
|
||||||
}
|
|
||||||
|
|
||||||
Intent i = new Intent(act, PasswordActivity.class);
|
|
||||||
i.putExtra(KEY_FILENAME, fileName);
|
|
||||||
i.putExtra(KEY_KEYFILE, keyFile);
|
|
||||||
|
|
||||||
act.startActivityForResult(i, 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private String mFileName;
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
private String mKeyFile;
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
private boolean mRememberKeyfile;
|
||||||
|
SharedPreferences prefs;
|
||||||
switch (requestCode) {
|
|
||||||
|
|
||||||
case KeePass.EXIT_NORMAL:
|
|
||||||
setEditText(R.id.password, "");
|
|
||||||
App.getDB().clear();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case KeePass.EXIT_LOCK:
|
|
||||||
setResult(KeePass.EXIT_LOCK);
|
|
||||||
setEditText(R.id.password, "");
|
|
||||||
finish();
|
|
||||||
App.getDB().clear();
|
|
||||||
break;
|
|
||||||
case FILE_BROWSE:
|
|
||||||
if (resultCode == RESULT_OK) {
|
|
||||||
String filename = data.getDataString();
|
|
||||||
if (filename != null) {
|
|
||||||
if (filename.startsWith("file://")) {
|
|
||||||
filename = filename.substring(7);
|
|
||||||
}
|
|
||||||
|
|
||||||
filename = URLDecoder.decode(filename);
|
|
||||||
|
|
||||||
EditText fn = (EditText) findViewById(R.id.pass_keyfile);
|
|
||||||
fn.setText(filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GET_CONTENT:
|
|
||||||
if (resultCode == RESULT_OK) {
|
|
||||||
if (data != null) {
|
|
||||||
Uri uri = data.getData();
|
|
||||||
if (uri != null) {
|
|
||||||
String path = uri.getPath();
|
|
||||||
if (path != null) {
|
|
||||||
EditText fn = (EditText) findViewById(R.id.pass_keyfile);
|
|
||||||
fn.setText(path);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public static void Launch(Activity act, String fileName) throws FileNotFoundException {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
Launch(act,fileName,"");
|
||||||
super.onCreate(savedInstanceState);
|
}
|
||||||
|
|
||||||
Intent i = getIntent();
|
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
mRememberKeyfile = prefs.getBoolean(getString(R.string.keyfile_key), getResources().getBoolean(R.bool.keyfile_default));
|
|
||||||
setContentView(R.layout.password);
|
|
||||||
|
|
||||||
new InitTask().execute(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
// If the application was shutdown make sure to clear the password field, if it
|
|
||||||
// was saved in the instance state
|
|
||||||
if (App.isShutdown()) {
|
|
||||||
TextView password = (TextView) findViewById(R.id.password);
|
|
||||||
password.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear the shutdown flag
|
|
||||||
App.clearShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void retrieveSettings() {
|
public static void Launch(Activity act, String fileName, String keyFile) throws FileNotFoundException {
|
||||||
String defaultFilename = prefs.getString(KEY_DEFAULT_FILENAME, "");
|
File dbFile = new File(fileName);
|
||||||
if (mFileName.length() > 0 && mFileName.equals(defaultFilename)) {
|
if ( ! dbFile.exists() ) {
|
||||||
CheckBox checkbox = (CheckBox) findViewById(R.id.default_database);
|
throw new FileNotFoundException();
|
||||||
checkbox.setChecked(true);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getKeyFile(String filename) {
|
|
||||||
if ( mRememberKeyfile ) {
|
|
||||||
|
|
||||||
String keyfile = App.getFileHistory().getFileByName(filename);
|
|
||||||
|
|
||||||
return keyfile;
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateView() {
|
|
||||||
setEditText(R.id.filename, mFileName);
|
|
||||||
|
|
||||||
setEditText(R.id.pass_keyfile, mKeyFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
private void errorMessage(CharSequence text)
|
|
||||||
{
|
|
||||||
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void errorMessage(int resId)
|
|
||||||
{
|
|
||||||
Toast.makeText(this, resId, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DefaultCheckChange implements CompoundButton.OnCheckedChangeListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView,
|
|
||||||
boolean isChecked) {
|
|
||||||
|
|
||||||
String newDefaultFileName;
|
|
||||||
|
|
||||||
if (isChecked) {
|
|
||||||
newDefaultFileName = mFileName;
|
|
||||||
} else {
|
|
||||||
newDefaultFileName = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
editor.putString(KEY_DEFAULT_FILENAME, newDefaultFileName);
|
|
||||||
EditorCompat.apply(editor);
|
|
||||||
|
|
||||||
BackupManagerCompat backupManager = new BackupManagerCompat(PasswordActivity.this);
|
|
||||||
backupManager.dataChanged();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class OkClickHandler implements View.OnClickListener {
|
|
||||||
|
|
||||||
public void onClick(View view) {
|
|
||||||
String pass = getEditText(R.id.password);
|
|
||||||
String key = getEditText(R.id.pass_keyfile);
|
|
||||||
loadDatabase(pass, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadDatabase(String pass, String keyfile)
|
|
||||||
{
|
|
||||||
if ( pass.length() == 0 && keyfile.length() == 0 ) {
|
|
||||||
errorMessage(R.string.error_nopass);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String fileName = getEditText(R.id.filename);
|
|
||||||
|
|
||||||
|
|
||||||
// Clear before we load
|
|
||||||
Database db = App.getDB();
|
|
||||||
db.clear();
|
|
||||||
|
|
||||||
// Clear the shutdown flag
|
|
||||||
App.clearShutdown();
|
|
||||||
|
|
||||||
Handler handler = new Handler();
|
|
||||||
LoadDB task = new LoadDB(db, PasswordActivity.this, fileName, pass, keyfile, new AfterLoad(handler, db));
|
|
||||||
ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database);
|
|
||||||
pt.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getEditText(int resId) {
|
|
||||||
return Util.getEditText(this, resId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setEditText(int resId, String str) {
|
|
||||||
TextView te = (TextView) findViewById(resId);
|
|
||||||
assert(te == null);
|
|
||||||
|
|
||||||
if (te != null) {
|
|
||||||
te.setText(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
Intent i = new Intent(act, PasswordActivity.class);
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
i.putExtra(KEY_FILENAME, fileName);
|
||||||
super.onCreateOptionsMenu(menu);
|
i.putExtra(KEY_KEYFILE, keyFile);
|
||||||
|
|
||||||
MenuInflater inflate = getMenuInflater();
|
|
||||||
inflate.inflate(R.menu.password, menu);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
act.startActivityForResult(i, 0);
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch ( item.getItemId() ) {
|
|
||||||
case R.id.menu_about:
|
|
||||||
AboutDialog dialog = new AboutDialog(this);
|
|
||||||
dialog.show();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.id.menu_app_settings:
|
|
||||||
AppSettingsActivity.Launch(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class AfterLoad extends OnFinish {
|
}
|
||||||
private Database db;
|
|
||||||
|
|
||||||
public AfterLoad(Handler handler, Database db) {
|
|
||||||
super(handler);
|
|
||||||
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if ( db.passwordEncodingError) {
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
|
|
||||||
dialog.show(PasswordActivity.this, new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
switch (requestCode) {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
GroupActivity.Launch(PasswordActivity.this);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
} else if ( mSuccess ) {
|
|
||||||
GroupActivity.Launch(PasswordActivity.this);
|
|
||||||
} else {
|
|
||||||
displayMessage(PasswordActivity.this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InitTask extends AsyncTask<Intent, Void, Integer> {
|
|
||||||
String password = "";
|
|
||||||
boolean launch_immediately = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer doInBackground(Intent... args) {
|
|
||||||
Intent i = args[0];
|
|
||||||
String action = i.getAction();;
|
|
||||||
if ( action != null && action.equals(VIEW_INTENT) ) {
|
|
||||||
mFileName = i.getDataString();
|
|
||||||
|
|
||||||
if ( ! mFileName.substring(0, 7).equals("file://") ) {
|
|
||||||
return R.string.error_can_not_handle_uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
mFileName = URLDecoder.decode(mFileName.substring(7, mFileName.length()));
|
|
||||||
|
|
||||||
if ( mFileName.length() == 0 ) {
|
|
||||||
// No file name
|
|
||||||
return R.string.FileNotFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
File dbFile = new File(mFileName);
|
|
||||||
if ( ! dbFile.exists() ) {
|
|
||||||
// File does not exist
|
|
||||||
return R.string.FileNotFound;
|
|
||||||
}
|
|
||||||
|
|
||||||
mKeyFile = getKeyFile(mFileName);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
mFileName = i.getStringExtra(KEY_FILENAME);
|
|
||||||
mKeyFile = i.getStringExtra(KEY_KEYFILE);
|
|
||||||
password = i.getStringExtra(KEY_PASSWORD);
|
|
||||||
launch_immediately = i.getBooleanExtra(KEY_LAUNCH_IMMEDIATELY, false);
|
|
||||||
|
|
||||||
if ( mKeyFile == null || mKeyFile.length() == 0) {
|
|
||||||
mKeyFile = getKeyFile(mFileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onPostExecute(Integer result) {
|
|
||||||
if(result != null) {
|
|
||||||
Toast.makeText(PasswordActivity.this, result, Toast.LENGTH_LONG).show();
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
populateView();
|
|
||||||
|
|
||||||
Button confirmButton = (Button) findViewById(R.id.pass_ok);
|
case KeePass.EXIT_NORMAL:
|
||||||
confirmButton.setOnClickListener(new OkClickHandler());
|
setEditText(R.id.password, "");
|
||||||
|
App.getDB().clear();
|
||||||
CheckBox checkBox = (CheckBox) findViewById(R.id.show_password);
|
break;
|
||||||
// Show or hide password
|
|
||||||
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
||||||
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView,
|
case KeePass.EXIT_LOCK:
|
||||||
boolean isChecked) {
|
setResult(KeePass.EXIT_LOCK);
|
||||||
TextView password = (TextView) findViewById(R.id.password);
|
setEditText(R.id.password, "");
|
||||||
|
finish();
|
||||||
|
App.getDB().clear();
|
||||||
|
break;
|
||||||
|
case FILE_BROWSE:
|
||||||
|
if (resultCode == RESULT_OK) {
|
||||||
|
String filename = data.getDataString();
|
||||||
|
if (filename != null) {
|
||||||
|
if (filename.startsWith("file://")) {
|
||||||
|
filename = filename.substring(7);
|
||||||
|
}
|
||||||
|
|
||||||
if ( isChecked ) {
|
filename = URLDecoder.decode(filename);
|
||||||
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
|
||||||
} else {
|
EditText fn = (EditText) findViewById(R.id.pass_keyfile);
|
||||||
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
fn.setText(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
});
|
case GET_CONTENT:
|
||||||
|
if (resultCode == RESULT_OK) {
|
||||||
if (password != null) {
|
if (data != null) {
|
||||||
TextView tv_password = (TextView) findViewById(R.id.password);
|
Uri uri = data.getData();
|
||||||
tv_password.setText(password);
|
if (uri != null) {
|
||||||
}
|
String path = uri.getPath();
|
||||||
|
if (path != null) {
|
||||||
CheckBox defaultCheck = (CheckBox) findViewById(R.id.default_database);
|
EditText fn = (EditText) findViewById(R.id.pass_keyfile);
|
||||||
defaultCheck.setOnCheckedChangeListener(new DefaultCheckChange());
|
fn.setText(path);
|
||||||
|
|
||||||
ImageButton browse = (ImageButton) findViewById(R.id.browse_button);
|
}
|
||||||
browse.setOnClickListener(new View.OnClickListener() {
|
}
|
||||||
|
}
|
||||||
public void onClick(View v) {
|
}
|
||||||
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
break;
|
||||||
i.setType("file/*");
|
}
|
||||||
|
}
|
||||||
try {
|
|
||||||
startActivityForResult(i, GET_CONTENT);
|
@Override
|
||||||
} catch (ActivityNotFoundException e) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
lookForOpenIntentsFilePicker();
|
super.onCreate(savedInstanceState);
|
||||||
}
|
|
||||||
}
|
Intent i = getIntent();
|
||||||
|
|
||||||
private void lookForOpenIntentsFilePicker() {
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
if (Interaction.isIntentAvailable(PasswordActivity.this, Intents.OPEN_INTENTS_FILE_BROWSE)) {
|
mRememberKeyfile = prefs.getBoolean(getString(R.string.keyfile_key), getResources().getBoolean(R.bool.keyfile_default));
|
||||||
Intent i = new Intent(Intents.OPEN_INTENTS_FILE_BROWSE);
|
setContentView(R.layout.password);
|
||||||
|
|
||||||
if (mFileName.length() > 0) {
|
new InitTask().execute(i);
|
||||||
File keyfile = new File(mFileName);
|
}
|
||||||
File parent = keyfile.getParentFile();
|
|
||||||
if (parent != null) {
|
@Override
|
||||||
i.setData(Uri.parse("file://" + parent.getAbsolutePath()));
|
protected void onResume() {
|
||||||
}
|
super.onResume();
|
||||||
}
|
|
||||||
|
// If the application was shutdown make sure to clear the password field, if it
|
||||||
try {
|
// was saved in the instance state
|
||||||
startActivityForResult(i, FILE_BROWSE);
|
if (App.isShutdown()) {
|
||||||
} catch (ActivityNotFoundException e) {
|
TextView password = (TextView) findViewById(R.id.password);
|
||||||
showBrowserDialog();
|
password.setText("");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
showBrowserDialog();
|
// Clear the shutdown flag
|
||||||
}
|
App.clearShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showBrowserDialog() {
|
private void retrieveSettings() {
|
||||||
BrowserDialog diag = new BrowserDialog(PasswordActivity.this);
|
String defaultFilename = prefs.getString(KEY_DEFAULT_FILENAME, "");
|
||||||
diag.show();
|
if (mFileName.length() > 0 && mFileName.equals(defaultFilename)) {
|
||||||
}
|
CheckBox checkbox = (CheckBox) findViewById(R.id.default_database);
|
||||||
});
|
checkbox.setChecked(true);
|
||||||
|
}
|
||||||
retrieveSettings();
|
}
|
||||||
|
|
||||||
if (launch_immediately)
|
private String getKeyFile(String filename) {
|
||||||
loadDatabase(password, mKeyFile);
|
if ( mRememberKeyfile ) {
|
||||||
}
|
|
||||||
}
|
String keyfile = App.getFileHistory().getFileByName(filename);
|
||||||
|
|
||||||
|
return keyfile;
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateView() {
|
||||||
|
setEditText(R.id.filename, mFileName);
|
||||||
|
|
||||||
|
setEditText(R.id.pass_keyfile, mKeyFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
private void errorMessage(CharSequence text)
|
||||||
|
{
|
||||||
|
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private void errorMessage(int resId)
|
||||||
|
{
|
||||||
|
Toast.makeText(this, resId, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class DefaultCheckChange implements CompoundButton.OnCheckedChangeListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||||||
|
boolean isChecked) {
|
||||||
|
|
||||||
|
String newDefaultFileName;
|
||||||
|
|
||||||
|
if (isChecked) {
|
||||||
|
newDefaultFileName = mFileName;
|
||||||
|
} else {
|
||||||
|
newDefaultFileName = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putString(KEY_DEFAULT_FILENAME, newDefaultFileName);
|
||||||
|
EditorCompat.apply(editor);
|
||||||
|
|
||||||
|
BackupManagerCompat backupManager = new BackupManagerCompat(PasswordActivity.this);
|
||||||
|
backupManager.dataChanged();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class OkClickHandler implements View.OnClickListener {
|
||||||
|
|
||||||
|
public void onClick(View view) {
|
||||||
|
String pass = getEditText(R.id.password);
|
||||||
|
String key = getEditText(R.id.pass_keyfile);
|
||||||
|
loadDatabase(pass, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadDatabase(String pass, String keyfile)
|
||||||
|
{
|
||||||
|
if ( pass.length() == 0 && keyfile.length() == 0 ) {
|
||||||
|
errorMessage(R.string.error_nopass);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String fileName = getEditText(R.id.filename);
|
||||||
|
|
||||||
|
|
||||||
|
// Clear before we load
|
||||||
|
Database db = App.getDB();
|
||||||
|
db.clear();
|
||||||
|
|
||||||
|
// Clear the shutdown flag
|
||||||
|
App.clearShutdown();
|
||||||
|
|
||||||
|
Handler handler = new Handler();
|
||||||
|
LoadDB task = new LoadDB(db, PasswordActivity.this, fileName, pass, keyfile, new AfterLoad(handler, db));
|
||||||
|
ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database);
|
||||||
|
pt.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getEditText(int resId) {
|
||||||
|
return Util.getEditText(this, resId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEditText(int resId, String str) {
|
||||||
|
TextView te = (TextView) findViewById(resId);
|
||||||
|
assert(te == null);
|
||||||
|
|
||||||
|
if (te != null) {
|
||||||
|
te.setText(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
super.onCreateOptionsMenu(menu);
|
||||||
|
|
||||||
|
MenuInflater inflate = getMenuInflater();
|
||||||
|
inflate.inflate(R.menu.password, menu);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch ( item.getItemId() ) {
|
||||||
|
case R.id.menu_about:
|
||||||
|
AboutDialog dialog = new AboutDialog(this);
|
||||||
|
dialog.show();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_app_settings:
|
||||||
|
AppSettingsActivity.Launch(this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class AfterLoad extends OnFinish {
|
||||||
|
private Database db;
|
||||||
|
|
||||||
|
public AfterLoad(Handler handler, Database db) {
|
||||||
|
super(handler);
|
||||||
|
|
||||||
|
this.db = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if ( db.passwordEncodingError) {
|
||||||
|
PasswordEncodingDialogHelper dialog = new PasswordEncodingDialogHelper();
|
||||||
|
dialog.show(PasswordActivity.this, new OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
GroupActivity.Launch(PasswordActivity.this);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} else if ( mSuccess ) {
|
||||||
|
GroupActivity.Launch(PasswordActivity.this);
|
||||||
|
} else {
|
||||||
|
displayMessage(PasswordActivity.this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InitTask extends AsyncTask<Intent, Void, Integer> {
|
||||||
|
String password = "";
|
||||||
|
boolean launch_immediately = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground(Intent... args) {
|
||||||
|
Intent i = args[0];
|
||||||
|
String action = i.getAction();;
|
||||||
|
if ( action != null && action.equals(VIEW_INTENT) ) {
|
||||||
|
mFileName = i.getDataString();
|
||||||
|
|
||||||
|
if ( ! mFileName.substring(0, 7).equals("file://") ) {
|
||||||
|
return R.string.error_can_not_handle_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
mFileName = URLDecoder.decode(mFileName.substring(7, mFileName.length()));
|
||||||
|
|
||||||
|
if ( mFileName.length() == 0 ) {
|
||||||
|
// No file name
|
||||||
|
return R.string.FileNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
File dbFile = new File(mFileName);
|
||||||
|
if ( ! dbFile.exists() ) {
|
||||||
|
// File does not exist
|
||||||
|
return R.string.FileNotFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
mKeyFile = getKeyFile(mFileName);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
mFileName = i.getStringExtra(KEY_FILENAME);
|
||||||
|
mKeyFile = i.getStringExtra(KEY_KEYFILE);
|
||||||
|
password = i.getStringExtra(KEY_PASSWORD);
|
||||||
|
launch_immediately = i.getBooleanExtra(KEY_LAUNCH_IMMEDIATELY, false);
|
||||||
|
|
||||||
|
if ( mKeyFile == null || mKeyFile.length() == 0) {
|
||||||
|
mKeyFile = getKeyFile(mFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPostExecute(Integer result) {
|
||||||
|
if(result != null) {
|
||||||
|
Toast.makeText(PasswordActivity.this, result, Toast.LENGTH_LONG).show();
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
populateView();
|
||||||
|
|
||||||
|
Button confirmButton = (Button) findViewById(R.id.pass_ok);
|
||||||
|
confirmButton.setOnClickListener(new OkClickHandler());
|
||||||
|
|
||||||
|
CheckBox checkBox = (CheckBox) findViewById(R.id.show_password);
|
||||||
|
// Show or hide password
|
||||||
|
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
|
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||||||
|
boolean isChecked) {
|
||||||
|
TextView password = (TextView) findViewById(R.id.password);
|
||||||
|
|
||||||
|
if ( isChecked ) {
|
||||||
|
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
||||||
|
} else {
|
||||||
|
password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if (password != null) {
|
||||||
|
TextView tv_password = (TextView) findViewById(R.id.password);
|
||||||
|
tv_password.setText(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckBox defaultCheck = (CheckBox) findViewById(R.id.default_database);
|
||||||
|
defaultCheck.setOnCheckedChangeListener(new DefaultCheckChange());
|
||||||
|
|
||||||
|
ImageButton browse = (ImageButton) findViewById(R.id.browse_button);
|
||||||
|
browse.setOnClickListener(new View.OnClickListener() {
|
||||||
|
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
i.setType("file/*");
|
||||||
|
|
||||||
|
try {
|
||||||
|
startActivityForResult(i, GET_CONTENT);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
lookForOpenIntentsFilePicker();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lookForOpenIntentsFilePicker() {
|
||||||
|
if (Interaction.isIntentAvailable(PasswordActivity.this, Intents.OPEN_INTENTS_FILE_BROWSE)) {
|
||||||
|
Intent i = new Intent(Intents.OPEN_INTENTS_FILE_BROWSE);
|
||||||
|
|
||||||
|
if (mFileName.length() > 0) {
|
||||||
|
File keyfile = new File(mFileName);
|
||||||
|
File parent = keyfile.getParentFile();
|
||||||
|
if (parent != null) {
|
||||||
|
i.setData(Uri.parse("file://" + parent.getAbsolutePath()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
startActivityForResult(i, FILE_BROWSE);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
showBrowserDialog();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showBrowserDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showBrowserDialog() {
|
||||||
|
BrowserDialog diag = new BrowserDialog(PasswordActivity.this);
|
||||||
|
diag.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
retrieveSettings();
|
||||||
|
|
||||||
|
if (launch_immediately)
|
||||||
|
loadDatabase(password, mKeyFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user