From 85765478f306d02fa8d9ac918d9d3fef8439788e Mon Sep 17 00:00:00 2001 From: serso Date: Mon, 19 Sep 2011 15:27:39 +0400 Subject: [PATCH] number picker preferences --- .../view/prefs/AbstractDialogPreference.java | 62 +++++++++++++++++++ .../view/prefs/IntervalPreference.java | 33 +++++----- .../android/view/prefs/SeekBarPreference.java | 36 ++--------- 3 files changed, 85 insertions(+), 46 deletions(-) create mode 100644 src/main/java/org/solovyev/android/view/prefs/AbstractDialogPreference.java diff --git a/src/main/java/org/solovyev/android/view/prefs/AbstractDialogPreference.java b/src/main/java/org/solovyev/android/view/prefs/AbstractDialogPreference.java new file mode 100644 index 00000000..6176da0f --- /dev/null +++ b/src/main/java/org/solovyev/android/view/prefs/AbstractDialogPreference.java @@ -0,0 +1,62 @@ +package org.solovyev.android.view.prefs; + +import android.content.Context; +import android.preference.DialogPreference; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; +import org.jetbrains.annotations.NotNull; + +/** + * User: serso + * Date: 9/19/11 + * Time: 3:17 PM + */ +public class AbstractDialogPreference extends DialogPreference { + + @NotNull + protected static final String androidns = "http://schemas.android.com/apk/res/android"; + + @NotNull + protected TextView splashText, valueText; + + @NotNull + protected final Context context; + + protected String dialogMessage, suffix; + + public AbstractDialogPreference(Context context, AttributeSet attrs) { + super(context, attrs); + this.context = context; + + dialogMessage = attrs.getAttributeValue(androidns, "dialogMessage"); + suffix = attrs.getAttributeValue(androidns, "text"); + } + + @Override + protected LinearLayout onCreateDialogView() { + LinearLayout.LayoutParams params; + LinearLayout layout = new LinearLayout(context); + layout.setOrientation(LinearLayout.VERTICAL); + layout.setPadding(6, 6, 6, 6); + + splashText = new TextView(context); + if (dialogMessage != null) + splashText.setText(dialogMessage); + layout.addView(splashText); + + valueText = new TextView(context); + valueText.setGravity(Gravity.CENTER_HORIZONTAL); + valueText.setTextSize(32); + params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.FILL_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + layout.addView(valueText, params); + + return layout; + } + + +} diff --git a/src/main/java/org/solovyev/android/view/prefs/IntervalPreference.java b/src/main/java/org/solovyev/android/view/prefs/IntervalPreference.java index d4288880..b834b0bf 100644 --- a/src/main/java/org/solovyev/android/view/prefs/IntervalPreference.java +++ b/src/main/java/org/solovyev/android/view/prefs/IntervalPreference.java @@ -16,33 +16,38 @@ import org.solovyev.android.view.widgets.NumberPicker; * Date: 9/19/11 * Time: 12:27 PM */ -public class IntervalPreference extends DialogPreference implements NumberPicker.OnChangedListener { +public class IntervalPreference extends AbstractDialogPreference implements NumberPicker.OnChangedListener { @NotNull - private final Context context; + private final NumberPicker leftBorder; + + @NotNull + private final NumberPicker rightBorder; - public IntervalPreference(@NotNull Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - this.context = context; - } public IntervalPreference(@NotNull Context context, AttributeSet attrs) { super(context, attrs); - this.context = context; + this.leftBorder = new NumberPicker(context); + this.rightBorder = new NumberPicker(context); } @Override public void onChanged(NumberPicker picker, int oldVal, int newVal) { - //To change body of implemented methods use File | Settings | File Templates. +/* if (shouldPersist()) + persistString(value); + callChangeListener(new Integer(value));*/ } @Override - protected View onCreateDialogView() { - LinearLayout.LayoutParams params; - LinearLayout layout = new LinearLayout(context); - layout.setOrientation(LinearLayout.VERTICAL); - layout.setPadding(6, 6, 6, 6); + protected LinearLayout onCreateDialogView() { + final LinearLayout result = super.onCreateDialogView(); - return layout; + final LinearLayout horizontal = new LinearLayout(context); + horizontal.setOrientation(LinearLayout.HORIZONTAL); + + horizontal.addView(leftBorder); + horizontal.addView(rightBorder); + + return result; } } diff --git a/src/main/java/org/solovyev/android/view/prefs/SeekBarPreference.java b/src/main/java/org/solovyev/android/view/prefs/SeekBarPreference.java index e66f52cd..e7c4b61c 100644 --- a/src/main/java/org/solovyev/android/view/prefs/SeekBarPreference.java +++ b/src/main/java/org/solovyev/android/view/prefs/SeekBarPreference.java @@ -23,53 +23,24 @@ import org.jetbrains.annotations.NotNull; * http://www.apache.org/licenses/LICENSE-2.0 */ -public class SeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener { - - private static final String androidns = "http://schemas.android.com/apk/res/android"; +public class SeekBarPreference extends AbstractDialogPreference implements SeekBar.OnSeekBarChangeListener { @NotNull private SeekBar seekBar; - @NotNull - private TextView splashText, valueText; - - @NotNull - private final Context context; - - private String dialogMessage, suffix; - private int defaultValue, max, value = 0; public SeekBarPreference(Context context, AttributeSet attrs) { super(context, attrs); - this.context = context; - dialogMessage = attrs.getAttributeValue(androidns, "dialogMessage"); - suffix = attrs.getAttributeValue(androidns, "text"); defaultValue = attrs.getAttributeIntValue(androidns, "defaultValue", 0); max = attrs.getAttributeIntValue(androidns, "max", 100); } @Override - protected View onCreateDialogView() { - LinearLayout.LayoutParams params; - LinearLayout layout = new LinearLayout(context); - layout.setOrientation(LinearLayout.VERTICAL); - layout.setPadding(6, 6, 6, 6); - - splashText = new TextView(context); - if (dialogMessage != null) - splashText.setText(dialogMessage); - layout.addView(splashText); - - valueText = new TextView(context); - valueText.setGravity(Gravity.CENTER_HORIZONTAL); - valueText.setTextSize(32); - params = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.FILL_PARENT, - LinearLayout.LayoutParams.WRAP_CONTENT); - layout.addView(valueText, params); + protected LinearLayout onCreateDialogView() { + final LinearLayout layout = onCreateDialogView(); seekBar = new SeekBar(context); seekBar.setOnSeekBarChangeListener(this); @@ -80,6 +51,7 @@ public class SeekBarPreference extends DialogPreference implements SeekBar.OnSee seekBar.setMax(max); seekBar.setProgress(value); + return layout; }