diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fdde22505..19770da5d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -37,9 +37,8 @@ android:resource="@xml/nnf_provider_paths" /> + android:name="com.keepassdroid.FilePickerStylishActivity" + android:label="@string/app_name"> diff --git a/app/src/main/java/com/keepassdroid/AssignPasswordDialog.java b/app/src/main/java/com/keepassdroid/AssignPasswordDialog.java index 5b0c0637c..a8bce41fd 100644 --- a/app/src/main/java/com/keepassdroid/AssignPasswordDialog.java +++ b/app/src/main/java/com/keepassdroid/AssignPasswordDialog.java @@ -83,17 +83,14 @@ public class AssignPasswordDialog extends DialogFragment { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { - - } }) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - } }); - passwordCheckBox = (CompoundButton) rootView.findViewById(R.id.password_checkBox); + passwordCheckBox = (CompoundButton) rootView.findViewById(R.id.password_checkbox); keyfileCheckBox = (CompoundButton) rootView.findViewById(R.id.keyfile_checkox); keyFileHelper = new KeyFileHelper(this); @@ -198,13 +195,15 @@ public class AssignPasswordDialog extends DialogFragment { keyFileHelper.onActivityResultCallback(requestCode, resultCode, data, new KeyFileHelper.KeyFileCallback() { - @Override - public void onResultCallback(Uri uri) { - if(uri != null) { - EditText keyFileView = (EditText) rootView.findViewById(R.id.pass_keyfile); - keyFileView.setText(uri.toString()); - } - } - }); + @Override + public void onResultCallback(Uri uri) { + if(uri != null) { + EditText keyFileView = (EditText) rootView.findViewById(R.id.pass_keyfile); + Uri pathString = UriUtil.parseDefaultFile(uri.toString()); + if (pathString != null) + keyFileView.setText(pathString.toString()); + } + } + }); } } diff --git a/app/src/main/java/com/keepassdroid/CreateFileDialog.java b/app/src/main/java/com/keepassdroid/CreateFileDialog.java index bb205c70f..d7b1c4b84 100644 --- a/app/src/main/java/com/keepassdroid/CreateFileDialog.java +++ b/app/src/main/java/com/keepassdroid/CreateFileDialog.java @@ -1,3 +1,22 @@ +/* + * Copyright 2017 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ package com.keepassdroid; import android.app.Activity; @@ -84,7 +103,7 @@ public class CreateFileDialog extends DialogFragment implements AdapterView.OnIt browseView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent i = new Intent(getContext(), FilePickerActivity.class); + Intent i = new Intent(getContext(), FilePickerStylishActivity.class); i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false); i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true); i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR); diff --git a/app/src/main/java/com/keepassdroid/FilePickerStylishActivity.java b/app/src/main/java/com/keepassdroid/FilePickerStylishActivity.java new file mode 100644 index 000000000..61952740e --- /dev/null +++ b/app/src/main/java/com/keepassdroid/FilePickerStylishActivity.java @@ -0,0 +1,62 @@ +/* + * Copyright 2017 Jeremy Jamet / Kunzisoft. + * + * This file is part of KeePass DX. + * + * KeePass DX is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * KeePass DX is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with KeePass DX. If not, see . + * + */ +package com.keepassdroid; + +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.annotation.StyleRes; +import android.util.Log; + +import com.keepassdroid.stylish.Stylish; +import com.kunzisoft.keepass.R; +import com.nononsenseapps.filepicker.FilePickerActivity; + + +public class FilePickerStylishActivity extends FilePickerActivity { + + private @StyleRes + int themeId; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + this.themeId = FilePickerStylish.getThemeId(this); + setTheme(themeId); + super.onCreate(savedInstanceState); + } + + @Override + protected void onResume() { + super.onResume(); + if(FilePickerStylish.getThemeId(this) != this.themeId) { + Log.d(this.getClass().getName(), "Theme change detected, restarting activity"); + this.recreate(); + } + } + + public static class FilePickerStylish extends Stylish { + public static @StyleRes int getThemeId(Context context) { + if (themeString.equals(context.getString(R.string.list_style_name_night))) + return R.style.KeepassDXStyle_FilePickerStyle_Night; + + return R.style.KeepassDXStyle_FilePickerStyle_Light; + } + } +} diff --git a/app/src/main/java/com/keepassdroid/PasswordActivity.java b/app/src/main/java/com/keepassdroid/PasswordActivity.java index 5976993d7..4324a99ab 100644 --- a/app/src/main/java/com/keepassdroid/PasswordActivity.java +++ b/app/src/main/java/com/keepassdroid/PasswordActivity.java @@ -40,6 +40,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.TextView; @@ -90,7 +91,10 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp private View fingerprintView; private TextView confirmationView; private EditText passwordView; + private EditText keyFileView; private Button confirmButton; + private CheckBox checkboxPassword; + private CheckBox checkboxKeyfile; private KeyFileHelper keyFileHelper; @@ -109,6 +113,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp } Uri uri = UriUtil.parseDefaultFile(fileName); + assert uri != null; String scheme = uri.getScheme(); if (!EmptyUtils.isNullOrEmpty(scheme) && scheme.equalsIgnoreCase("file")) { @@ -146,13 +151,13 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp switch (requestCode) { case KeePass.EXIT_NORMAL: - setEditText(R.id.password, ""); + setEmptyViews(); App.getDB().clear(); break; case KeePass.EXIT_LOCK: setResult(KeePass.EXIT_LOCK); - setEditText(R.id.password, ""); + setEmptyViews(); finish(); App.getDB().clear(); break; @@ -183,6 +188,10 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp fingerprintView = findViewById(R.id.fingerprint); confirmationView = (TextView) findViewById(R.id.fingerprint_label); passwordView = (EditText) findViewById(R.id.password); + keyFileView = (EditText) findViewById(R.id.pass_keyfile); + + checkboxPassword = (CheckBox) findViewById(R.id.password_checkbox); + checkboxKeyfile = (CheckBox) findViewById(R.id.keyfile_checkox); new InitTask().execute(i); } @@ -194,8 +203,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp // 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(""); + setEmptyViews(); } // Clear the shutdown flag @@ -208,6 +216,11 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp } } + private void setEmptyViews() { + passwordView.setText(""); + keyFileView.setText(""); + } + private void retrieveSettings() { String defaultFilename = prefs.getString(KEY_DEFAULT_FILENAME, ""); if (!EmptyUtils.isNullOrEmpty(mDbUri.getPath()) && UriUtil.equalsDefaultfile(mDbUri, defaultFilename)) { @@ -232,10 +245,6 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp setEditText(R.id.pass_keyfile, key); } - private void errorMessage(int resId) { - Toast.makeText(this, resId, Toast.LENGTH_LONG).show(); - } - // fingerprint related code here @RequiresApi(api = Build.VERSION_CODES.M) private void initForFingerprint() { @@ -366,9 +375,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp else if (!fingerPrintHelper.hasEnrolledFingerprints()) { setFingerPrintVisibility(View.VISIBLE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - fingerprintView.setAlpha(0.3f); - } + fingerprintView.setAlpha(0.3f); // This happens when no fingerprints are registered. Listening won't start confirmationView.setText(R.string.configure_fingerprint); } @@ -376,9 +383,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp else { fingerprintMustBeConfigured = false; setFingerPrintVisibility(View.VISIBLE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - fingerprintView.setAlpha(1f); - } + fingerprintView.setAlpha(1f); // fingerprint available but no stored password found yet for this DB so show info don't listen if (prefsNoBackup.getString(getPreferenceKeyValue(), null) == null) { confirmationView.setText(R.string.no_password_stored); @@ -480,6 +485,13 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp // Clear the shutdown flag App.clearShutdown(); + if (!checkboxPassword.isChecked()) { + pass = ""; + } + if (!checkboxKeyfile.isChecked()) { + keyfile = null; + } + Handler handler = new Handler(); LoadDB task = new LoadDB(db, PasswordActivity.this, mDbUri, pass, keyfile, new AfterLoad(handler, db)); ProgressTask pt = new ProgressTask(PasswordActivity.this, task, R.string.loading_database); @@ -525,7 +537,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp private Database db; - public AfterLoad( + AfterLoad( Handler handler, Database db) { super(handler); @@ -625,8 +637,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp confirmButton.setOnClickListener(new OkClickHandler()); if (password != null) { - TextView tv_password = (TextView) findViewById(R.id.password); - tv_password.setText(password); + passwordView.setText(password); } CompoundButton defaultCheck = (CompoundButton) findViewById(R.id.default_database); diff --git a/app/src/main/java/com/keepassdroid/stylish/Stylish.java b/app/src/main/java/com/keepassdroid/stylish/Stylish.java index 3ef7f3e5d..abb93d8ad 100644 --- a/app/src/main/java/com/keepassdroid/stylish/Stylish.java +++ b/app/src/main/java/com/keepassdroid/stylish/Stylish.java @@ -9,9 +9,9 @@ import com.kunzisoft.keepass.R; public class Stylish { - private static String stylishPrefKey; + protected static String stylishPrefKey; - private static String themeString; + protected static String themeString; public static void init(Context context) { stylishPrefKey = context.getString(R.string.setting_style_key); @@ -23,7 +23,7 @@ public class Stylish { themeString = styleString; } - static @StyleRes int getThemeId(Context context) { + public static @StyleRes int getThemeId(Context context) { if (themeString.equals(context.getString(R.string.list_style_name_night))) return R.style.KeepassDXStyle_Night; diff --git a/app/src/main/res/layout/file_selection_filename.xml b/app/src/main/res/layout/file_selection_filename.xml index e834cc969..049f503b7 100644 --- a/app/src/main/res/layout/file_selection_filename.xml +++ b/app/src/main/res/layout/file_selection_filename.xml @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with KeePass DX. If not, see . --> - @@ -25,7 +25,8 @@ + android:layout_height="wrap_content" + android:layout_marginBottom="32dp"> + android:layout_marginBottom="12dp"> - + diff --git a/app/src/main/res/layout/password.xml b/app/src/main/res/layout/password.xml index e1a2bd0f0..098801e60 100644 --- a/app/src/main/res/layout/password.xml +++ b/app/src/main/res/layout/password.xml @@ -114,7 +114,7 @@ android:layout_height="wrap_content"> diff --git a/app/src/main/res/layout/set_password.xml b/app/src/main/res/layout/set_password.xml index 53715f165..ba007e5d7 100644 --- a/app/src/main/res/layout/set_password.xml +++ b/app/src/main/res/layout/set_password.xml @@ -36,7 +36,7 @@ android:orientation="vertical"> - -