This commit is contained in:
serso 2011-09-22 00:23:41 +04:00
parent 04032a9787
commit 4714a8542a
7 changed files with 99 additions and 44 deletions

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
~ For more information, please, contact se.solovyev@gmail.com
~ or visit http://se.solovyev.org
-->
<resources>
<string name="p_drag_distance_key">org.solovyev.android.calculator.DragButtonCalibrationActivity_distance</string>
<string name="p_drag_distance">15;350</string>
<string name="p_drag_angle_key">org.solovyev.android.calculator.DragButtonCalibrationActivity_angle</string>
<string name="p_drag_angle">130;180</string>
<string name="p_drag_duration_key">org.solovyev.android.calculator.DragButtonCalibrationActivity_duration</string>
<string name="p_drag_duration">40;2500</string>
</resources>

View File

@ -14,24 +14,24 @@
<org.solovyev.android.view.prefs.IntegerRangeSeekBarPreference
a:key="org.solovyev.android.calculator.DragButtonCalibrationActivity_distance"
a:key="@string/p_drag_distance_key"
a:title="Distance of drag event"
a:text=" pxs"
a:defaultValue="40;150"
range:boundaries="15;500"/>
a:defaultValue="@string/p_drag_distance"
range:boundaries="10;500"/>
<org.solovyev.android.view.prefs.IntegerRangeSeekBarPreference
a:key="org.solovyev.android.calculator.DragButtonCalibrationActivity_duration"
a:key="@string/p_drag_duration_key"
a:title="Duration of drag event"
a:text=" ms"
a:defaultValue="40;1000"
a:defaultValue="@string/p_drag_duration"
range:boundaries="5;4000"/>
<org.solovyev.android.view.prefs.IntegerRangeSeekBarPreference
a:key="org.solovyev.android.calculator.DragButtonCalibrationActivity_angle"
a:key="@string/p_drag_angle_key"
a:title="Angle of drag event"
a:text=" degrees"
a:defaultValue="130;180"
a:defaultValue="@string/p_drag_angle"
range:boundaries="100;180"/>
</PreferenceCategory>

View File

@ -202,44 +202,35 @@ public class DragButtonCalibrationActivity extends Activity {
for (PreferenceType preferenceType : PreferenceType.values()) {
for (DragDirection dragDirection : DragDirection.values()) {
Log.d(DragButtonCalibrationActivity.class.getName(), "Determining drag preference for " + preferenceType + ", " + dragDirection);
final String preferenceId = getPreferenceId(preferenceType, dragDirection);
final Interval<Float> defaultValue;
final String defaultValue;
switch (preferenceType) {
case angle:
switch (dragDirection) {
case up:
defaultValue = new IntervalImpl<Float>(130f, 180f);
break;
case down:
defaultValue = new IntervalImpl<Float>(130f, 180f);
break;
default:
defaultValue = new IntervalImpl<Float>(0f, 0f);
}
defaultValue = context.getResources().getString(R.string.p_drag_angle);
break;
case distance:
defaultValue = new IntervalImpl<Float>(10f, 150f);
defaultValue = context.getResources().getString(R.string.p_drag_distance);
break;
case duration:
defaultValue = new IntervalImpl<Float>(40f, 1000f);
defaultValue = context.getResources().getString(R.string.p_drag_duration);
break;
default:
defaultValue = new IntervalImpl<Float>(DEFAULT_VALUE, DEFAULT_VALUE);
defaultValue = null;
Log.e(DragButtonCalibrationActivity.class.getName(), "New preference type added: default preferences should be defined. Preference id: " + preferenceId);
}
final String preferenceId = getPreferenceId(preferenceType, dragDirection);
final String value = preferences.getString(preferenceId, mapper.formatValue(defaultValue));
Log.d(DragButtonCalibrationActivity.class.getName(), "For " + preferenceId + " next value found in persistence: " + value);
final String value = preferences.getString(preferenceId, defaultValue);
final Interval<Float> interval = mapper.parseValue(value);
assert interval != null;
if (defaultValue != null) {
final Interval<Float> intervalPref = mapper.parseValue(value);
assert intervalPref != null;
transformInterval(preferenceType, dragDirection, interval);
if (!new IntervalImpl<Float>(DEFAULT_VALUE, DEFAULT_VALUE).equals(interval)) {
Log.d(DragButtonCalibrationActivity.class.getName(), "Preference retrieved from persistence. Preference id: " + preferenceId + ", value: " + interval.toString());
transformInterval(preferenceType, dragDirection, intervalPref);
final DragPreference directionPreference = new DragPreference(dragDirection, interval);
Log.d(DragButtonCalibrationActivity.class.getName(), "Preference loaded. Id: " + preferenceId + ", value: " + intervalPref.toString());
final DragPreference directionPreference = new DragPreference(dragDirection, intervalPref);
Preference preference = result.getPreferencesMap().get(preferenceType);
if (preference == null) {
@ -248,9 +239,6 @@ public class DragButtonCalibrationActivity extends Activity {
}
preference.getDirectionPreferences().put(dragDirection, directionPreference);
} else {
Log.e(DragButtonCalibrationActivity.class.getName(), "New preference type added: default preferences should be defined. Preference id: " + preferenceId);
}
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2009-2011. Created by serso aka se.solovyev.
* For more information, please, contact se.solovyev@gmail.com
* or visit http://se.solovyev.org
*/
package org.solovyev.android.view.prefs;
import android.content.Context;
import android.util.AttributeSet;
import org.jetbrains.annotations.NotNull;
import org.solovyev.common.FloatIntervalMapper;
import org.solovyev.common.utils.Interval;
import org.solovyev.common.utils.Mapper;
/**
* User: serso
* Date: 9/21/11
* Time: 11:41 PM
*/
public class FloatRangeSeekBarPreference extends RangeSeekBarPreference<Float> {
public FloatRangeSeekBarPreference(@NotNull Context context, AttributeSet attrs) {
super(context, attrs);
}
@NotNull
@Override
protected Mapper<Interval<Float>> getMapper() {
return new FloatIntervalMapper() ;
}
}

View File

@ -30,8 +30,16 @@ public abstract class RangeSeekBarPreference<T extends Number> extends AbstractD
boundaries = getMapper().parseValue(attrs.getAttributeValue(localNameSpace, "boundaries"));
assert boundaries != null;
createPreferenceView();
}
private void createPreferenceView() {
this.rangeSeekBar = new NumberRangeSeekBar<T>(boundaries, null, context);
rangeSeekBar.setOnRangeSeekBarChangeListener(this);
this.rangeSeekBar.setNotifyWhileDragging(true);
this.rangeSeekBar.setOnRangeSeekBarChangeListener(this);
initPreferenceView();
}
@NotNull
@ -39,9 +47,7 @@ public abstract class RangeSeekBarPreference<T extends Number> extends AbstractD
protected LinearLayout onCreateDialogView() {
final LinearLayout result = super.onCreateDialogView();
this.rangeSeekBar = new NumberRangeSeekBar<T>(boundaries, null, context);
rangeSeekBar.setOnRangeSeekBarChangeListener(this);
initPreferenceView();
createPreferenceView();
result.addView(rangeSeekBar);
@ -58,9 +64,12 @@ public abstract class RangeSeekBarPreference<T extends Number> extends AbstractD
}
@Override
public void rangeSeekBarValuesChanged(T minValue, T maxValue) {
public void rangeSeekBarValuesChanged(T minValue, T maxValue, boolean changeComplete) {
final Interval<T> interval = new NumberInterval<T>(minValue, maxValue);
persistValue(interval);
if (changeComplete) {
persistValue(interval);
}
setValueText(interval);
}

View File

@ -186,7 +186,7 @@ public abstract class AbstractRangeSeekBar<T> extends ImageView {
setNormalizedMaxValue(convertToNormalizedValue(event.getX()));
}
if (notifyWhileDragging && listener != null) {
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue());
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue(), false);
}
}
break;
@ -195,7 +195,7 @@ public abstract class AbstractRangeSeekBar<T> extends ImageView {
pressedThumb = null;
invalidate();
if (listener != null) {
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue());
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue(), true);
}
break;
}
@ -364,7 +364,9 @@ public abstract class AbstractRangeSeekBar<T> extends ImageView {
* @author Stephan Tittel (stephan.tittel@kom.tu-darmstadt.de)
*/
public interface OnRangeSeekBarChangeListener<T> {
void rangeSeekBarValuesChanged(T minValue, T maxValue);
void rangeSeekBarValuesChanged(T minValue, T maxValue, boolean changeComplete);
}
/**

View File

@ -57,9 +57,17 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
DragDirection direction = null;
for (Map.Entry<DragDirection, DragButtonCalibrationActivity.DragPreference> directionEntry : distancePreferences.getDirectionPreferences().entrySet()) {
Log.d(String.valueOf(dragButton.getId()), "Trying direction interval: " + directionEntry.getValue().getInterval());
if (isInInterval(directionEntry.getValue().getInterval(), distance)) {
for (Map.Entry<DragDirection, DragButtonCalibrationActivity.DragPreference> angleEntry : anglePreferences.getDirectionPreferences().entrySet()) {
Log.d(String.valueOf(dragButton.getId()), "Trying angle interval: " + angleEntry.getValue().getInterval());
if (isInInterval(angleEntry.getValue().getInterval(), (float)angle)) {
Log.d(String.valueOf(dragButton.getId()), "MATCH! Direction: " + angleEntry.getKey());
direction = angleEntry.getKey();
break;
}
@ -76,9 +84,10 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
final DragButtonCalibrationActivity.DragPreference durationDragPreferences = durationPreferences.getDirectionPreferences().get(direction);
Log.d(String.valueOf(dragButton.getId()), "Trying time interval: " + durationDragPreferences.getInterval());
if (isInInterval(durationDragPreferences.getInterval(), (float)duration)) {
Log.d(String.valueOf(dragButton.getId()), "MATCH!");
result = dragProcessor.processDragEvent(direction, dragButton, startPoint, motionEvent);
}
}