Use our own NumberPickerPreference class
This commit is contained in:
parent
d3ad90f4c4
commit
6fc19c625f
6 changed files with 135 additions and 18 deletions
|
@ -131,7 +131,6 @@ If you want to show your appreciation for our work with a small donation you can
|
||||||
* [material-intro](https://github.com/heinrichreimer/material-intro)
|
* [material-intro](https://github.com/heinrichreimer/material-intro)
|
||||||
* [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar)
|
* [MaterialProgressBar](https://github.com/DreaminginCodeZH/MaterialProgressBar)
|
||||||
* [OpenPGP API library](https://github.com/open-keychain/openpgp-api)
|
* [OpenPGP API library](https://github.com/open-keychain/openpgp-api)
|
||||||
* [VNTNumberPickerPreference](https://github.com/vanniktech/VNTNumberPickerPreference)
|
|
||||||
* [ZXing Android Embedded](https://github.com/journeyapps/zxing-android-embedded)
|
* [ZXing Android Embedded](https://github.com/journeyapps/zxing-android-embedded)
|
||||||
* [Droid Sans Mono Zeromod](https://github.com/AlbertoDorado/droid-sans-mono-zeromod)
|
* [Droid Sans Mono Zeromod](https://github.com/AlbertoDorado/droid-sans-mono-zeromod)
|
||||||
|
|
||||||
|
@ -141,11 +140,13 @@ If you want to show your appreciation for our work with a small donation you can
|
||||||
* [Code Parts from Google's Android Samples](https://android.googlesource.com/platform/development/+/master/samples/Vault/src/com/example/android/vault)
|
* [Code Parts from Google's Android Samples](https://android.googlesource.com/platform/development/+/master/samples/Vault/src/com/example/android/vault)
|
||||||
* [LetterBitmap](https://stackoverflow.com/questions/23122088/colored-boxed-with-letters-a-la-gmail)
|
* [LetterBitmap](https://stackoverflow.com/questions/23122088/colored-boxed-with-letters-a-la-gmail)
|
||||||
* [DimensionConverter](https://stackoverflow.com/questions/8343971/how-to-parse-a-dimension-string-and-convert-it-to-a-dimension-value)
|
* [DimensionConverter](https://stackoverflow.com/questions/8343971/how-to-parse-a-dimension-string-and-convert-it-to-a-dimension-value)
|
||||||
|
* [NumberPickerPreference](https://github.com/Alobar/AndroidPreferenceTest/tree/master/alobar-preference)
|
||||||
|
|
||||||
#### Previously used open-source components:
|
#### Previously used open-source components:
|
||||||
|
|
||||||
* [FABsMenu](https://github.com/jahirfiquitiva/FABsMenu)
|
* [FABsMenu](https://github.com/jahirfiquitiva/FABsMenu)
|
||||||
* [LicensesDialog](https://github.com/PSDev/LicensesDialog)
|
* [LicensesDialog](https://github.com/PSDev/LicensesDialog)
|
||||||
|
* [VNTNumberPickerPreference](https://github.com/vanniktech/VNTNumberPickerPreference)
|
||||||
|
|
||||||
#### Previously used code examples:
|
#### Previously used code examples:
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,6 @@ dependencies {
|
||||||
implementation "com.heinrichreimersoftware:material-intro:2.0.0"
|
implementation "com.heinrichreimersoftware:material-intro:2.0.0"
|
||||||
implementation("com.journeyapps:zxing-android-embedded:4.1.0") { transitive = false }
|
implementation("com.journeyapps:zxing-android-embedded:4.1.0") { transitive = false }
|
||||||
implementation('com.google.zxing:core:3.4.1')
|
implementation('com.google.zxing:core:3.4.1')
|
||||||
implementation "com.vanniktech:vntnumberpickerpreference:1.0.0"
|
|
||||||
implementation "me.zhanghai.android.materialprogressbar:library:1.6.1"
|
implementation "me.zhanghai.android.materialprogressbar:library:1.6.1"
|
||||||
implementation "org.sufficientlysecure:openpgp-api:12.0"
|
implementation "org.sufficientlysecure:openpgp-api:12.0"
|
||||||
implementation "com.leinardi.android:speed-dial:3.1.1"
|
implementation "com.leinardi.android:speed-dial:3.1.1"
|
||||||
|
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.shadowice.flocke.andotp.Preferences;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.preference.DialogPreference;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.NumberPicker;
|
||||||
|
|
||||||
|
import org.shadowice.flocke.andotp.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link android.preference.Preference} that displays a number picker as a dialog.
|
||||||
|
*/
|
||||||
|
public class NumberPickerPreference extends DialogPreference {
|
||||||
|
|
||||||
|
public static final int DEFAULT_MAX_VALUE = 100;
|
||||||
|
public static final int DEFAULT_MIN_VALUE = 0;
|
||||||
|
public static final boolean DEFAULT_WRAP_SELECTOR_WHEEL = true;
|
||||||
|
|
||||||
|
private final int minValue;
|
||||||
|
private final int maxValue;
|
||||||
|
private final boolean wrapSelectorWheel;
|
||||||
|
|
||||||
|
private NumberPicker picker;
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public NumberPickerPreference(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, android.R.attr.dialogPreferenceStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NumberPickerPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
|
||||||
|
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference);
|
||||||
|
minValue = a.getInteger(R.styleable.NumberPickerPreference_minValue, DEFAULT_MIN_VALUE);
|
||||||
|
maxValue = a.getInteger(R.styleable.NumberPickerPreference_maxValue, DEFAULT_MAX_VALUE);
|
||||||
|
wrapSelectorWheel = a.getBoolean(R.styleable.NumberPickerPreference_wrapSelectorWheel, DEFAULT_WRAP_SELECTOR_WHEEL);
|
||||||
|
a.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected View onCreateDialogView() {
|
||||||
|
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
layoutParams.gravity = Gravity.CENTER;
|
||||||
|
|
||||||
|
picker = new NumberPicker(getContext());
|
||||||
|
picker.setLayoutParams(layoutParams);
|
||||||
|
|
||||||
|
FrameLayout dialogView = new FrameLayout(getContext());
|
||||||
|
dialogView.addView(picker);
|
||||||
|
|
||||||
|
return dialogView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onBindDialogView(View view) {
|
||||||
|
super.onBindDialogView(view);
|
||||||
|
picker.setMinValue(minValue);
|
||||||
|
picker.setMaxValue(maxValue);
|
||||||
|
picker.setWrapSelectorWheel(wrapSelectorWheel);
|
||||||
|
picker.setValue(getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDialogClosed(boolean positiveResult) {
|
||||||
|
if (positiveResult) {
|
||||||
|
picker.clearFocus();
|
||||||
|
int newValue = picker.getValue();
|
||||||
|
if (callChangeListener(newValue)) {
|
||||||
|
setValue(newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object onGetDefaultValue(TypedArray a, int index) {
|
||||||
|
return a.getInt(index, minValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) {
|
||||||
|
int initialValue = restorePersistedValue ? getPersistedInt(minValue) : (Integer) defaultValue;
|
||||||
|
|
||||||
|
setValue(initialValue);
|
||||||
|
setSummary(String.valueOf(initialValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(int value) {
|
||||||
|
this.value = value;
|
||||||
|
persistInt(this.value);
|
||||||
|
setSummary(String.valueOf(this.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Temporarily add library definitions here until they get merged upstream or in AboutLibraries -->
|
<!-- Temporarily add library definitions here until they get merged upstream or in AboutLibraries -->
|
||||||
|
|
||||||
<resources>
|
<resources
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:ignore="MissingTranslation">
|
||||||
|
|
||||||
<!-- Apache common codec -->
|
<!-- Apache common codec -->
|
||||||
<string name="define_CommonsCodec"></string>
|
<string name="define_CommonsCodec" />
|
||||||
<string name="library_CommonsCodec_author">The Apache Software Foundation</string>
|
<string name="library_CommonsCodec_author">The Apache Software Foundation</string>
|
||||||
<string name="library_CommonsCodec_authorWebsite">http://apache.org</string>
|
<string name="library_CommonsCodec_authorWebsite">http://apache.org</string>
|
||||||
|
|
||||||
|
@ -18,7 +21,7 @@
|
||||||
<string name="library_CommonsCodec_licenseId">apache_2_0</string>
|
<string name="library_CommonsCodec_licenseId">apache_2_0</string>
|
||||||
|
|
||||||
<!-- Expandable Layout -->
|
<!-- Expandable Layout -->
|
||||||
<string name="define_ExpandableLayout"></string>
|
<string name="define_ExpandableLayout" />
|
||||||
<string name="library_ExpandableLayout_author">Akira Aratani</string>
|
<string name="library_ExpandableLayout_author">Akira Aratani</string>
|
||||||
|
|
||||||
<string name="library_ExpandableLayout_libraryName">Expandable Layout</string>
|
<string name="library_ExpandableLayout_libraryName">Expandable Layout</string>
|
||||||
|
@ -32,7 +35,7 @@
|
||||||
<string name="library_ExpandableLayout_licenseId">apache_2_0</string>
|
<string name="library_ExpandableLayout_licenseId">apache_2_0</string>
|
||||||
|
|
||||||
<!-- Floating Action Button Speed Dial -->
|
<!-- Floating Action Button Speed Dial -->
|
||||||
<string name="define_FloatingActionButtonSpeedDial"></string>
|
<string name="define_FloatingActionButtonSpeedDial" />
|
||||||
<string name="library_FloatingActionButtonSpeedDial_author">Roberto Leinardi</string>
|
<string name="library_FloatingActionButtonSpeedDial_author">Roberto Leinardi</string>
|
||||||
|
|
||||||
<string name="library_FloatingActionButtonSpeedDial_libraryName">Floating Action Button Speed Dial</string>
|
<string name="library_FloatingActionButtonSpeedDial_libraryName">Floating Action Button Speed Dial</string>
|
||||||
|
@ -46,7 +49,7 @@
|
||||||
<string name="library_FloatingActionButtonSpeedDial_licenseId">apache_2_0</string>
|
<string name="library_FloatingActionButtonSpeedDial_licenseId">apache_2_0</string>
|
||||||
|
|
||||||
<!-- material-intro -->
|
<!-- material-intro -->
|
||||||
<string name="define_materialintro"></string>
|
<string name="define_materialintro" />
|
||||||
<string name="library_materialintro_author">Jan Heinrich Reimer</string>
|
<string name="library_materialintro_author">Jan Heinrich Reimer</string>
|
||||||
<string name="library_materialintro_authorWebsite">https://heinrichreimer.com/</string>
|
<string name="library_materialintro_authorWebsite">https://heinrichreimer.com/</string>
|
||||||
|
|
||||||
|
@ -61,7 +64,7 @@
|
||||||
<string name="library_materialintro_licenseId">mit</string>
|
<string name="library_materialintro_licenseId">mit</string>
|
||||||
|
|
||||||
<!-- OpenPGP API -->
|
<!-- OpenPGP API -->
|
||||||
<string name="define_OpenPGPAPI"></string>
|
<string name="define_OpenPGPAPI" />
|
||||||
<string name="library_OpenPGPAPI_author">Dominik Schürmann</string>
|
<string name="library_OpenPGPAPI_author">Dominik Schürmann</string>
|
||||||
<string name="library_OpenPGPAPI_authorWebsite">https://www.schuermann.eu/</string>
|
<string name="library_OpenPGPAPI_authorWebsite">https://www.schuermann.eu/</string>
|
||||||
|
|
||||||
|
@ -76,7 +79,7 @@
|
||||||
<string name="library_OpenPGPAPI_licenseId">apache_2_0</string>
|
<string name="library_OpenPGPAPI_licenseId">apache_2_0</string>
|
||||||
|
|
||||||
<!-- Droid Sans Mono Slashed Font -->
|
<!-- Droid Sans Mono Slashed Font -->
|
||||||
<string name="define_MonoSlashedFont"></string>
|
<string name="define_MonoSlashedFont" />
|
||||||
<string name="library_MonoSlashedFont_author"> Alberto Dorado</string>
|
<string name="library_MonoSlashedFont_author"> Alberto Dorado</string>
|
||||||
|
|
||||||
<string name="library_MonoSlashedFont_libraryName">Droid Sans Mono Zeromod</string>
|
<string name="library_MonoSlashedFont_libraryName">Droid Sans Mono Zeromod</string>
|
||||||
|
|
8
app/src/main/res/values/attrs.xml
Normal file
8
app/src/main/res/values/attrs.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<declare-styleable name="NumberPickerPreference">
|
||||||
|
<attr name="minValue" format="integer|reference"/>
|
||||||
|
<attr name="maxValue" format="integer|reference"/>
|
||||||
|
<attr name="wrapSelectorWheel" format="boolean"/>
|
||||||
|
</declare-styleable>
|
||||||
|
</resources>
|
|
@ -1,4 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--suppress AndroidElementNotAllowed -->
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
@ -7,13 +8,14 @@
|
||||||
android:key="@string/settings_key_cat_security"
|
android:key="@string/settings_key_cat_security"
|
||||||
android:title="@string/settings_category_title_security">
|
android:title="@string/settings_category_title_security">
|
||||||
|
|
||||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
<org.shadowice.flocke.andotp.Preferences.NumberPickerPreference
|
||||||
android:key="@string/settings_key_tap_to_reveal_timeout"
|
android:key="@string/settings_key_tap_to_reveal_timeout"
|
||||||
android:title="@string/settings_title_tap_to_reveal_timeout"
|
android:title="@string/settings_title_tap_to_reveal_timeout"
|
||||||
android:dialogMessage="@string/settings_desc_tap_to_reveal_timeout"
|
android:dialogMessage="@string/settings_desc_tap_to_reveal_timeout"
|
||||||
android:defaultValue="@integer/settings_default_tap_to_reveal_timeout"
|
android:defaultValue="@integer/settings_default_tap_to_reveal_timeout"
|
||||||
app:vnt_minValue="@integer/settings_min_tap_to_reveal_timeout"
|
app:minValue="@integer/settings_min_tap_to_reveal_timeout"
|
||||||
app:vnt_maxValue="@integer/settings_max_tap_to_reveal_timeout" />
|
app:maxValue="@integer/settings_max_tap_to_reveal_timeout"
|
||||||
|
app:wrapSelectorWheel="false" />
|
||||||
|
|
||||||
<org.shadowice.flocke.andotp.Preferences.CredentialsPreference
|
<org.shadowice.flocke.andotp.Preferences.CredentialsPreference
|
||||||
android:key="@string/settings_key_auth"
|
android:key="@string/settings_key_auth"
|
||||||
|
@ -53,14 +55,15 @@
|
||||||
android:summary="@string/settings_desc_auth_inactivity"
|
android:summary="@string/settings_desc_auth_inactivity"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
|
||||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
<org.shadowice.flocke.andotp.Preferences.NumberPickerPreference
|
||||||
android:key="@string/settings_key_auth_inactivity_delay"
|
android:key="@string/settings_key_auth_inactivity_delay"
|
||||||
android:title="@string/settings_title_auth_inactivity_delay"
|
android:title="@string/settings_title_auth_inactivity_delay"
|
||||||
android:dialogMessage="@string/settings_desc_auth_inactivity_delay"
|
android:dialogMessage="@string/settings_desc_auth_inactivity_delay"
|
||||||
android:defaultValue="@integer/settings_default_auth_inactivity_delay"
|
android:defaultValue="@integer/settings_default_auth_inactivity_delay"
|
||||||
android:dependency="@string/settings_key_auth_inactivity"
|
android:dependency="@string/settings_key_auth_inactivity"
|
||||||
app:vnt_minValue="@integer/settings_auth_min_inactivity_delay"
|
app:minValue="@integer/settings_auth_min_inactivity_delay"
|
||||||
app:vnt_maxValue="@integer/settings_auth_max_inactivity_delay" />
|
app:maxValue="@integer/settings_auth_max_inactivity_delay"
|
||||||
|
app:wrapSelectorWheel="false" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="@string/settings_key_block_accessibility"
|
android:key="@string/settings_key_block_accessibility"
|
||||||
|
@ -140,12 +143,13 @@
|
||||||
android:entryValues="@array/settings_values_tap"
|
android:entryValues="@array/settings_values_tap"
|
||||||
android:defaultValue="@string/settings_default_tap_double" />
|
android:defaultValue="@string/settings_default_tap_double" />
|
||||||
|
|
||||||
<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
|
<org.shadowice.flocke.andotp.Preferences.NumberPickerPreference
|
||||||
android:key="@string/settings_key_label_size"
|
android:key="@string/settings_key_label_size"
|
||||||
android:title="@string/settings_title_label_size"
|
android:title="@string/settings_title_label_size"
|
||||||
android:defaultValue="@integer/settings_default_label_size"
|
android:defaultValue="@integer/settings_default_label_size"
|
||||||
app:vnt_maxValue="@integer/settings_max_label_size"
|
app:maxValue="@integer/settings_max_label_size"
|
||||||
app:vnt_minValue="@integer/settings_min_label_size" />
|
app:minValue="@integer/settings_min_label_size"
|
||||||
|
app:wrapSelectorWheel="false" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="@string/settings_key_label_display"
|
android:key="@string/settings_key_label_display"
|
||||||
|
|
Loading…
Reference in a new issue