1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

new style number picker preference

This commit is contained in:
Nikolay Pultsin 2015-08-06 16:52:21 +02:00
parent e56e5ac0ac
commit e7fdb36886
2 changed files with 44 additions and 19 deletions

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<NumberPicker
android:id="@+id/picker_preference_central"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
/>
</LinearLayout>

View file

@ -20,35 +20,46 @@
package org.geometerplus.android.fbreader.preferences; package org.geometerplus.android.fbreader.preferences;
import android.content.Context; import android.content.Context;
import android.preference.ListPreference; import android.preference.DialogPreference;
import android.view.View;
import android.widget.NumberPicker;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption; import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.ui.android.R;
class ZLIntegerRangePreference extends ListPreference { class ZLIntegerRangePreference extends DialogPreference {
private final ZLIntegerRangeOption myOption; private final ZLIntegerRangeOption myOption;
private NumberPicker myPicker;
ZLIntegerRangePreference(Context context, ZLResource resource, ZLIntegerRangeOption option) { public ZLIntegerRangePreference(Context context, ZLResource resource, ZLIntegerRangeOption option) {
super(context); super(context, null);
myOption = option; myOption = option;
setTitle(resource.getValue()); setTitle(resource.getValue());
String[] entries = new String[option.MaxValue - option.MinValue + 1]; updateSummary();
for (int i = 0; i < entries.length; ++i) { setDialogLayoutResource(R.layout.picker_preference);
entries[i] = ((Integer)(i + option.MinValue)).toString();
}
setEntries(entries);
setEntryValues(entries);
setValueIndex(option.getValue() - option.MinValue);
setSummary(getValue());
} }
@Override @Override
protected void onDialogClosed(boolean result) { protected void onBindDialogView(View view) {
super.onDialogClosed(result); myPicker = (NumberPicker)view.findViewById(R.id.picker_preference_central);
if (result) { myPicker.setMinValue(myOption.MinValue);
final String value = getValue(); myPicker.setMaxValue(myOption.MaxValue);
setSummary(value); myPicker.setValue(myOption.getValue());
myOption.setValue(myOption.MinValue + findIndexOfValue(value)); myPicker.setWrapSelectorWheel(false);
super.onBindDialogView(view);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
myOption.setValue(myPicker.getValue());
updateSummary();
} }
} }
private void updateSummary() {
setSummary(String.valueOf(myOption.getValue()));
}
} }