number picker preferences
This commit is contained in:
parent
0a22093246
commit
85765478f3
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user