Solve layout for selections

This commit is contained in:
Jeremy
2017-12-04 21:28:44 +01:00
parent 421bdae0d7
commit 9173c99928
10 changed files with 159 additions and 51 deletions

View File

@@ -37,9 +37,8 @@
android:resource="@xml/nnf_provider_paths" /> android:resource="@xml/nnf_provider_paths" />
</provider> </provider>
<activity <activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity" android:name="com.keepassdroid.FilePickerStylishActivity"
android:label="@string/app_name" android:label="@string/app_name">
android:theme="@style/KeepassDXStyle.FilePickerStyle">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.GET_CONTENT" /> <action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />

View File

@@ -83,17 +83,14 @@ public class AssignPasswordDialog extends DialogFragment {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
} }
}) })
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { 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); keyfileCheckBox = (CompoundButton) rootView.findViewById(R.id.keyfile_checkox);
keyFileHelper = new KeyFileHelper(this); keyFileHelper = new KeyFileHelper(this);
@@ -202,7 +199,9 @@ public class AssignPasswordDialog extends DialogFragment {
public void onResultCallback(Uri uri) { public void onResultCallback(Uri uri) {
if(uri != null) { if(uri != null) {
EditText keyFileView = (EditText) rootView.findViewById(R.id.pass_keyfile); EditText keyFileView = (EditText) rootView.findViewById(R.id.pass_keyfile);
keyFileView.setText(uri.toString()); Uri pathString = UriUtil.parseDefaultFile(uri.toString());
if (pathString != null)
keyFileView.setText(pathString.toString());
} }
} }
}); });

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
package com.keepassdroid; package com.keepassdroid;
import android.app.Activity; import android.app.Activity;
@@ -84,7 +103,7 @@ public class CreateFileDialog extends DialogFragment implements AdapterView.OnIt
browseView.setOnClickListener(new View.OnClickListener() { browseView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { 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_MULTIPLE, false);
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true); i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR); i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);

View File

@@ -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 <http://www.gnu.org/licenses/>.
*
*/
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;
}
}
}

View File

@@ -40,6 +40,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@@ -90,7 +91,10 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
private View fingerprintView; private View fingerprintView;
private TextView confirmationView; private TextView confirmationView;
private EditText passwordView; private EditText passwordView;
private EditText keyFileView;
private Button confirmButton; private Button confirmButton;
private CheckBox checkboxPassword;
private CheckBox checkboxKeyfile;
private KeyFileHelper keyFileHelper; private KeyFileHelper keyFileHelper;
@@ -109,6 +113,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
} }
Uri uri = UriUtil.parseDefaultFile(fileName); Uri uri = UriUtil.parseDefaultFile(fileName);
assert uri != null;
String scheme = uri.getScheme(); String scheme = uri.getScheme();
if (!EmptyUtils.isNullOrEmpty(scheme) && scheme.equalsIgnoreCase("file")) { if (!EmptyUtils.isNullOrEmpty(scheme) && scheme.equalsIgnoreCase("file")) {
@@ -146,13 +151,13 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
switch (requestCode) { switch (requestCode) {
case KeePass.EXIT_NORMAL: case KeePass.EXIT_NORMAL:
setEditText(R.id.password, ""); setEmptyViews();
App.getDB().clear(); App.getDB().clear();
break; break;
case KeePass.EXIT_LOCK: case KeePass.EXIT_LOCK:
setResult(KeePass.EXIT_LOCK); setResult(KeePass.EXIT_LOCK);
setEditText(R.id.password, ""); setEmptyViews();
finish(); finish();
App.getDB().clear(); App.getDB().clear();
break; break;
@@ -183,6 +188,10 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
fingerprintView = findViewById(R.id.fingerprint); fingerprintView = findViewById(R.id.fingerprint);
confirmationView = (TextView) findViewById(R.id.fingerprint_label); confirmationView = (TextView) findViewById(R.id.fingerprint_label);
passwordView = (EditText) findViewById(R.id.password); 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); 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 // If the application was shutdown make sure to clear the password field, if it
// was saved in the instance state // was saved in the instance state
if (App.isShutdown()) { if (App.isShutdown()) {
TextView password = (TextView) findViewById(R.id.password); setEmptyViews();
password.setText("");
} }
// Clear the shutdown flag // 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() { private void retrieveSettings() {
String defaultFilename = prefs.getString(KEY_DEFAULT_FILENAME, ""); String defaultFilename = prefs.getString(KEY_DEFAULT_FILENAME, "");
if (!EmptyUtils.isNullOrEmpty(mDbUri.getPath()) && UriUtil.equalsDefaultfile(mDbUri, defaultFilename)) { 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); setEditText(R.id.pass_keyfile, key);
} }
private void errorMessage(int resId) {
Toast.makeText(this, resId, Toast.LENGTH_LONG).show();
}
// fingerprint related code here // fingerprint related code here
@RequiresApi(api = Build.VERSION_CODES.M) @RequiresApi(api = Build.VERSION_CODES.M)
private void initForFingerprint() { private void initForFingerprint() {
@@ -366,9 +375,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
else if (!fingerPrintHelper.hasEnrolledFingerprints()) { else if (!fingerPrintHelper.hasEnrolledFingerprints()) {
setFingerPrintVisibility(View.VISIBLE); 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 // This happens when no fingerprints are registered. Listening won't start
confirmationView.setText(R.string.configure_fingerprint); confirmationView.setText(R.string.configure_fingerprint);
} }
@@ -376,9 +383,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
else { else {
fingerprintMustBeConfigured = false; fingerprintMustBeConfigured = false;
setFingerPrintVisibility(View.VISIBLE); 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 // fingerprint available but no stored password found yet for this DB so show info don't listen
if (prefsNoBackup.getString(getPreferenceKeyValue(), null) == null) { if (prefsNoBackup.getString(getPreferenceKeyValue(), null) == null) {
confirmationView.setText(R.string.no_password_stored); confirmationView.setText(R.string.no_password_stored);
@@ -480,6 +485,13 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
// Clear the shutdown flag // Clear the shutdown flag
App.clearShutdown(); App.clearShutdown();
if (!checkboxPassword.isChecked()) {
pass = "";
}
if (!checkboxKeyfile.isChecked()) {
keyfile = null;
}
Handler handler = new Handler(); Handler handler = new Handler();
LoadDB task = new LoadDB(db, PasswordActivity.this, mDbUri, pass, keyfile, new AfterLoad(handler, db)); 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); 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; private Database db;
public AfterLoad( AfterLoad(
Handler handler, Handler handler,
Database db) { Database db) {
super(handler); super(handler);
@@ -625,8 +637,7 @@ public class PasswordActivity extends LockingActivity implements FingerPrintHelp
confirmButton.setOnClickListener(new OkClickHandler()); confirmButton.setOnClickListener(new OkClickHandler());
if (password != null) { if (password != null) {
TextView tv_password = (TextView) findViewById(R.id.password); passwordView.setText(password);
tv_password.setText(password);
} }
CompoundButton defaultCheck = (CompoundButton) findViewById(R.id.default_database); CompoundButton defaultCheck = (CompoundButton) findViewById(R.id.default_database);

View File

@@ -9,9 +9,9 @@ import com.kunzisoft.keepass.R;
public class Stylish { 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) { public static void init(Context context) {
stylishPrefKey = context.getString(R.string.setting_style_key); stylishPrefKey = context.getString(R.string.setting_style_key);
@@ -23,7 +23,7 @@ public class Stylish {
themeString = styleString; 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))) if (themeString.equals(context.getString(R.string.list_style_name_night)))
return R.style.KeepassDXStyle_Night; return R.style.KeepassDXStyle_Night;

View File

@@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with KeePass DX. If not, see <http://www.gnu.org/licenses/>. along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
--> -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
@@ -25,7 +25,8 @@
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:id="@+id/filename_container" android:id="@+id/filename_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:layout_marginBottom="32dp">
<RelativeLayout <RelativeLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -35,7 +36,7 @@
android:layout_marginStart="@dimen/default_margin" android:layout_marginStart="@dimen/default_margin"
android:layout_marginRight="@dimen/default_margin" android:layout_marginRight="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_margin" android:layout_marginEnd="@dimen/default_margin"
android:layout_marginBottom="28dp"> android:layout_marginBottom="12dp">
<TextView android:id="@+id/label_warning" <TextView android:id="@+id/label_warning"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -79,13 +80,13 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/filename_container" android:layout_below="@+id/filename_container"
android:layout_alignParentEnd="true" android:layout_marginStart="24dp"
android:layout_alignParentRight="true" android:layout_marginLeft="24dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:layout_marginRight="24dp" android:layout_marginRight="24dp"
android:layout_marginTop="-22dp"
android:layout_marginBottom="5dp"
app:fabSize="mini" app:fabSize="mini"
app:layout_anchor="@id/filename_container"
app:layout_anchorGravity="bottom|start"
android:src="@drawable/ic_open_folder_white_24dp" /> android:src="@drawable/ic_open_folder_white_24dp" />
</RelativeLayout> </android.support.design.widget.CoordinatorLayout>

View File

@@ -114,7 +114,7 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatCheckBox <android.support.v7.widget.AppCompatCheckBox
android:id="@+id/password_checkBox" android:id="@+id/password_checkbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
@@ -126,8 +126,8 @@
android:id="@+id/password_input_layout" android:id="@+id/password_input_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/password_checkBox" android:layout_toRightOf="@+id/password_checkbox"
android:layout_toEndOf="@+id/password_checkBox" android:layout_toEndOf="@+id/password_checkbox"
app:passwordToggleEnabled="true" app:passwordToggleEnabled="true"
app:passwordToggleTint="?attr/colorAccent"> app:passwordToggleTint="?attr/colorAccent">

View File

@@ -36,7 +36,7 @@
android:orientation="vertical"> android:orientation="vertical">
<android.support.v7.widget.AppCompatCheckBox <android.support.v7.widget.AppCompatCheckBox
android:id="@+id/password_checkBox" android:id="@+id/password_checkbox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:checked="true"
@@ -81,6 +81,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin" android:layout_marginTop="@dimen/default_margin"
android:layout_marginBottom="@dimen/default_margin"
app:cardCornerRadius="4dp"> app:cardCornerRadius="4dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -238,14 +238,30 @@
</style> </style>
<!-- File Picker Theme --> <!-- File Picker Theme -->
<style name="KeepassDXStyle.FilePickerStyle" parent="NNF_BaseTheme"> <style name="KeepassDXStyle.FilePickerStyle.Night" parent="Theme.AppCompat.Dialog">
<!-- You can override this in your sub theme -->
<item name="nnf_toolbarTheme">@style/ThemeOverlay.AppCompat.ActionBar</item>
<item name="nnf_separator_color">@color/nnf_dark_separator_color</item>
<item name="nnf_save_icon_color">?attr/colorAccent</item>
<item name="nnf_dir_icon_color">?attr/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/green</item> <item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/green_dark</item> <item name="colorPrimaryDark">@color/green_dark</item>
<item name="colorAccent">@color/orange</item> <item name="colorAccent">@color/orange</item>
<item name="alertDialogTheme">@style/KeepassDXStyle.FilePickerStyle.AlertDialog</item>
</style> </style>
<style name="KeepassDXStyle.FilePickerStyle.AlertDialog" parent="Theme.AppCompat.Dialog.Alert"> <style name="KeepassDXStyle.FilePickerStyle.Light" parent="Theme.AppCompat.Light.Dialog">
<item name="nnf_toolbarTheme">@style/ThemeOverlay.AppCompat.ActionBar</item>
<item name="nnf_separator_color">@color/nnf_light_separator_color</item>
<item name="nnf_save_icon_color">?attr/colorAccent</item>
<item name="nnf_dir_icon_color">?attr/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">@color/green</item> <item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/green_dark</item> <item name="colorPrimaryDark">@color/green_dark</item>
<item name="colorAccent">@color/orange</item> <item name="colorAccent">@color/orange</item>