Add setting to disable the open button #126

This commit is contained in:
J-Jamet
2018-06-25 10:42:19 +02:00
parent acba7fc5de
commit c3ac550c93
12 changed files with 81 additions and 2 deletions

View File

@@ -121,6 +121,7 @@ public class PasswordActivity extends StylishActivity
private CompoundButton checkboxPasswordView;
private CompoundButton checkboxKeyfileView;
private CompoundButton checkboxDefaultDatabaseView;
private CompoundButton.OnCheckedChangeListener enableButtonOncheckedChangeListener;
private DefaultCheckChange defaultCheckChange;
private ValidateButtonViewClickListener validateButtonViewClickListener;
@@ -322,6 +323,18 @@ public class PasswordActivity extends StylishActivity
// For check shutdown
super.onResume();
// Enable or not the open button
if (!PreferencesUtil.emptyPasswordAllowed(PasswordActivity.this)) {
confirmButtonView.setEnabled(checkboxPasswordView.isChecked());
} else {
confirmButtonView.setEnabled(true);
}
enableButtonOncheckedChangeListener = (buttonView, isChecked) -> {
if (!PreferencesUtil.emptyPasswordAllowed(PasswordActivity.this)) {
confirmButtonView.setEnabled(isChecked);
}
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Check if fingerprint well init (be called the first time the fingerprint is configured
// and the activity still active)
@@ -511,6 +524,9 @@ public class PasswordActivity extends StylishActivity
}
}
}
// Add old listener to enable the button, only be call here because of onCheckedChange bug
enableButtonOncheckedChangeListener.onCheckedChanged(compoundButton, checked);
});
// callback for fingerprint findings

View File

@@ -152,6 +152,12 @@ public class PreferencesUtil {
context.getString(R.string.setting_icon_pack_choose_default));
}
public static boolean emptyPasswordAllowed(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.allow_no_password_key),
context.getResources().getBoolean(R.bool.allow_no_password_default));
}
/**
* All preference keys associated with education
*/

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/grey" android:state_enabled="false" />
<item android:color="@color/colorTextInverse" android:state_enabled="true" />
</selector>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_large_enable" android:state_enabled="true" />
<item android:drawable="@drawable/button_large_disable" android:state_enabled="false" />
</selector>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners
android:radius="0dp" />
<padding
android:left="0dp"
android:right="0dp"
android:top="12dp"
android:bottom="12dp"/>
<solid android:color="@color/grey_dark"/>
</shape>
</item>
</layer-list>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners
android:radius="0dp" />
<padding
android:left="0dp"
android:right="0dp"
android:top="12dp"
android:bottom="12dp"/>
<solid android:color="@color/orange"/>
</shape>
</item>
</layer-list>

View File

@@ -22,6 +22,8 @@
<color name="white">#ffffff</color>
<color name="black">#000000</color>
<color name="dark">#0e0e0e</color>
<color name="grey">#bdbdbd</color>
<color name="grey_dark">#9e9e9e</color>
<color name="orange_light">#ffa726</color>
<color name="orange">#fb8c00</color>

View File

@@ -93,6 +93,7 @@
<string name="education_screen_reclicked_key" translatable="false">education_screen_reclicked_key</string>
<string name="settings_appearance_key" translatable="false">settings_appearance_key</string>
<string name="magic_keyboard_key" translatable="false">magic_keyboard_key</string>
<string name="allow_no_password_key" translatable="false">allow_no_password_key</string>
<bool name="maskpass_default" translatable="false">true</bool>
<bool name="keyfile_default" translatable="false">true</bool>
@@ -124,6 +125,7 @@
<bool name="education_entry_new_field_default" translatable="false">false</bool>
<bool name="education_screen_reclicked_default" translatable="false">false</bool>
<bool name="magic_keyboard_default" translatable="false">false</bool>
<bool name="allow_no_password_default" translatable="false">true</bool>
<string name="app_timeout_default" translatable="false">300000</string>
<string name="clipboard_timeout_default" translatable="false">60000</string>

View File

@@ -265,6 +265,8 @@
<string name="keyboard">Keyboard</string>
<string name="magic_keyboard_title">Magikeyboayd</string>
<string name="magic_keyboard_summary">Activate a custom keyboard that populates your passwords and all your identity fields easily.</string>
<string name="allow_no_password_title">Allow no password</string>
<string name="allow_no_password_summary">Enable the open button if no password identification is selected.</string>
<string name="reset_education_screens_title">Reset education screens</string>
<string name="reset_education_screens_summary">Highlight the elements to learn how the application works</string>

View File

@@ -249,8 +249,8 @@
<!-- Button Style -->
<style name="KeepassDXStyle.v21.Button" parent="Base.TextAppearance.AppCompat.Button" />
<style name="KeepassDXStyle.Button" parent="KeepassDXStyle.v21.Button">
<item name="android:textColor">?attr/textColorInverse</item>
<item name="android:background">@drawable/button_background</item>
<item name="android:textColor">@color/text_color_button</item>
<item name="android:background">@drawable/button_large</item>
<item name="android:gravity">center</item>
</style>
<style name="KeepassDXStyle.Button.Primary" parent="KeepassDXStyle.v21.Button">

View File

@@ -20,6 +20,17 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:title="@string/general">
<SwitchPreference
android:summary="@string/allow_no_password_summary"
android:defaultValue="@bool/allow_no_password_default"
android:title="@string/allow_no_password_title"
android:key="@string/allow_no_password_key"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/search_label">