fixes
This commit is contained in:
parent
7d97b28821
commit
b1127d96f9
15
res/values/default_values.xml
Normal file
15
res/values/default_values.xml
Normal 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>
|
@ -14,24 +14,24 @@
|
|||||||
|
|
||||||
|
|
||||||
<org.solovyev.android.view.prefs.IntegerRangeSeekBarPreference
|
<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:title="Distance of drag event"
|
||||||
a:text=" pxs"
|
a:text=" pxs"
|
||||||
a:defaultValue="40;150"
|
a:defaultValue="@string/p_drag_distance"
|
||||||
range:boundaries="15;500"/>
|
range:boundaries="10;500"/>
|
||||||
|
|
||||||
<org.solovyev.android.view.prefs.IntegerRangeSeekBarPreference
|
<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:title="Duration of drag event"
|
||||||
a:text=" ms"
|
a:text=" ms"
|
||||||
a:defaultValue="40;1000"
|
a:defaultValue="@string/p_drag_duration"
|
||||||
range:boundaries="5;4000"/>
|
range:boundaries="5;4000"/>
|
||||||
|
|
||||||
<org.solovyev.android.view.prefs.IntegerRangeSeekBarPreference
|
<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:title="Angle of drag event"
|
||||||
a:text=" degrees"
|
a:text=" degrees"
|
||||||
a:defaultValue="130;180"
|
a:defaultValue="@string/p_drag_angle"
|
||||||
range:boundaries="100;180"/>
|
range:boundaries="100;180"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
@ -202,44 +202,35 @@ public class DragButtonCalibrationActivity extends Activity {
|
|||||||
for (PreferenceType preferenceType : PreferenceType.values()) {
|
for (PreferenceType preferenceType : PreferenceType.values()) {
|
||||||
for (DragDirection dragDirection : DragDirection.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) {
|
switch (preferenceType) {
|
||||||
case angle:
|
case angle:
|
||||||
switch (dragDirection) {
|
defaultValue = context.getResources().getString(R.string.p_drag_angle);
|
||||||
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);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case distance:
|
case distance:
|
||||||
defaultValue = new IntervalImpl<Float>(10f, 150f);
|
defaultValue = context.getResources().getString(R.string.p_drag_distance);
|
||||||
break;
|
break;
|
||||||
case duration:
|
case duration:
|
||||||
defaultValue = new IntervalImpl<Float>(40f, 1000f);
|
defaultValue = context.getResources().getString(R.string.p_drag_duration);
|
||||||
break;
|
break;
|
||||||
default:
|
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, defaultValue);
|
||||||
final String value = preferences.getString(preferenceId, mapper.formatValue(defaultValue));
|
|
||||||
Log.d(DragButtonCalibrationActivity.class.getName(), "For " + preferenceId + " next value found in persistence: " + value);
|
|
||||||
|
|
||||||
final Interval<Float> interval = mapper.parseValue(value);
|
if (defaultValue != null) {
|
||||||
assert interval != null;
|
final Interval<Float> intervalPref = mapper.parseValue(value);
|
||||||
|
assert intervalPref != null;
|
||||||
|
|
||||||
transformInterval(preferenceType, dragDirection, interval);
|
transformInterval(preferenceType, dragDirection, intervalPref);
|
||||||
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());
|
|
||||||
|
|
||||||
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);
|
Preference preference = result.getPreferencesMap().get(preferenceType);
|
||||||
if (preference == null) {
|
if (preference == null) {
|
||||||
@ -248,9 +239,6 @@ public class DragButtonCalibrationActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
preference.getDirectionPreferences().put(dragDirection, directionPreference);
|
preference.getDirectionPreferences().put(dragDirection, directionPreference);
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.e(DragButtonCalibrationActivity.class.getName(), "New preference type added: default preferences should be defined. Preference id: " + preferenceId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() ;
|
||||||
|
}
|
||||||
|
}
|
@ -30,8 +30,16 @@ public abstract class RangeSeekBarPreference<T extends Number> extends AbstractD
|
|||||||
boundaries = getMapper().parseValue(attrs.getAttributeValue(localNameSpace, "boundaries"));
|
boundaries = getMapper().parseValue(attrs.getAttributeValue(localNameSpace, "boundaries"));
|
||||||
|
|
||||||
assert boundaries != null;
|
assert boundaries != null;
|
||||||
|
|
||||||
|
createPreferenceView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createPreferenceView() {
|
||||||
this.rangeSeekBar = new NumberRangeSeekBar<T>(boundaries, null, context);
|
this.rangeSeekBar = new NumberRangeSeekBar<T>(boundaries, null, context);
|
||||||
rangeSeekBar.setOnRangeSeekBarChangeListener(this);
|
this.rangeSeekBar.setNotifyWhileDragging(true);
|
||||||
|
this.rangeSeekBar.setOnRangeSeekBarChangeListener(this);
|
||||||
|
|
||||||
|
initPreferenceView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -39,9 +47,7 @@ public abstract class RangeSeekBarPreference<T extends Number> extends AbstractD
|
|||||||
protected LinearLayout onCreateDialogView() {
|
protected LinearLayout onCreateDialogView() {
|
||||||
final LinearLayout result = super.onCreateDialogView();
|
final LinearLayout result = super.onCreateDialogView();
|
||||||
|
|
||||||
this.rangeSeekBar = new NumberRangeSeekBar<T>(boundaries, null, context);
|
createPreferenceView();
|
||||||
rangeSeekBar.setOnRangeSeekBarChangeListener(this);
|
|
||||||
initPreferenceView();
|
|
||||||
|
|
||||||
result.addView(rangeSeekBar);
|
result.addView(rangeSeekBar);
|
||||||
|
|
||||||
@ -58,9 +64,12 @@ public abstract class RangeSeekBarPreference<T extends Number> extends AbstractD
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
final Interval<T> interval = new NumberInterval<T>(minValue, maxValue);
|
||||||
persistValue(interval);
|
|
||||||
|
if (changeComplete) {
|
||||||
|
persistValue(interval);
|
||||||
|
}
|
||||||
|
|
||||||
setValueText(interval);
|
setValueText(interval);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ public abstract class AbstractRangeSeekBar<T> extends ImageView {
|
|||||||
setNormalizedMaxValue(convertToNormalizedValue(event.getX()));
|
setNormalizedMaxValue(convertToNormalizedValue(event.getX()));
|
||||||
}
|
}
|
||||||
if (notifyWhileDragging && listener != null) {
|
if (notifyWhileDragging && listener != null) {
|
||||||
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue());
|
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -195,7 +195,7 @@ public abstract class AbstractRangeSeekBar<T> extends ImageView {
|
|||||||
pressedThumb = null;
|
pressedThumb = null;
|
||||||
invalidate();
|
invalidate();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue());
|
listener.rangeSeekBarValuesChanged(getSelectedMinValue(), getSelectedMaxValue(), true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -364,7 +364,9 @@ public abstract class AbstractRangeSeekBar<T> extends ImageView {
|
|||||||
* @author Stephan Tittel (stephan.tittel@kom.tu-darmstadt.de)
|
* @author Stephan Tittel (stephan.tittel@kom.tu-darmstadt.de)
|
||||||
*/
|
*/
|
||||||
public interface OnRangeSeekBarChangeListener<T> {
|
public interface OnRangeSeekBarChangeListener<T> {
|
||||||
void rangeSeekBarValuesChanged(T minValue, T maxValue);
|
|
||||||
|
void rangeSeekBarValuesChanged(T minValue, T maxValue, boolean changeComplete);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,9 +57,17 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
|
|||||||
DragDirection direction = null;
|
DragDirection direction = null;
|
||||||
for (Map.Entry<DragDirection, DragButtonCalibrationActivity.DragPreference> directionEntry : distancePreferences.getDirectionPreferences().entrySet()) {
|
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)) {
|
if (isInInterval(directionEntry.getValue().getInterval(), distance)) {
|
||||||
for (Map.Entry<DragDirection, DragButtonCalibrationActivity.DragPreference> angleEntry : anglePreferences.getDirectionPreferences().entrySet()) {
|
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)) {
|
if (isInInterval(angleEntry.getValue().getInterval(), (float)angle)) {
|
||||||
|
|
||||||
|
Log.d(String.valueOf(dragButton.getId()), "MATCH! Direction: " + angleEntry.getKey());
|
||||||
|
|
||||||
direction = angleEntry.getKey();
|
direction = angleEntry.getKey();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -76,9 +84,10 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
|
|||||||
|
|
||||||
final DragButtonCalibrationActivity.DragPreference durationDragPreferences = durationPreferences.getDirectionPreferences().get(direction);
|
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)) {
|
if (isInInterval(durationDragPreferences.getInterval(), (float)duration)) {
|
||||||
|
Log.d(String.valueOf(dragButton.getId()), "MATCH!");
|
||||||
result = dragProcessor.processDragEvent(direction, dragButton, startPoint, motionEvent);
|
result = dragProcessor.processDragEvent(direction, dragButton, startPoint, motionEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user