history changes

This commit is contained in:
Sergey Solovyev
2011-12-18 22:38:34 +04:00
parent c4ecdbf8d3
commit dc40632cc0
48 changed files with 455 additions and 476 deletions

View File

@@ -136,26 +136,22 @@ public class DirectionDragButton extends DragButton {
@NotNull
@Override
public Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, int w, int h) {
final Point2d result = new Point2d();
float width = paint.measureText(" ");
result.setX(width);
float selfHeight = paint.ascent() + paint.descent();
basePaint.measureText(StringUtils.getNotEmpty(baseText, "|"));
result.setY(h / 2 - selfHeight / 2);
return result;
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, true);
}
}/*,
},
right(DragDirection.right, 1) {
@Override
public int getAttributeId() {
return 0;
return R.styleable.DragButton_textRight;
}
}*/;
@NotNull
@Override
public Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, int w, int h) {
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, false);
}
};
@NotNull
private final DragDirection dragDirection;
@@ -176,6 +172,27 @@ public class DirectionDragButton extends DragButton {
@NotNull
public abstract Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, int w, int h);
@NotNull
private static Point2d getLeftRightTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, CharSequence text, @NotNull CharSequence baseText, int w, int h, boolean left) {
final Point2d result = new Point2d();
if (left) {
float width = paint.measureText(" ");
result.setX(width);
} else {
float width = paint.measureText(text.toString() + " ");
result.setX(w - width);
}
float selfHeight = paint.ascent() + paint.descent();
basePaint.measureText(StringUtils.getNotEmpty(baseText, "|"));
result.setY(h / 2 - selfHeight / 2);
return result;
}
@NotNull
private static Point2d getUpDownTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, float direction, int w, int h) {
final Point2d result = new Point2d();

View File

@@ -12,10 +12,7 @@ import android.view.MotionEvent;
import org.jetbrains.annotations.NotNull;
import org.solovyev.android.calculator.R;
import org.solovyev.common.NumberIntervalMapper;
import org.solovyev.common.utils.Interval;
import org.solovyev.common.utils.Mapper;
import org.solovyev.common.utils.MathUtils;
import org.solovyev.common.utils.Point2d;
import org.solovyev.common.utils.*;
import java.util.HashMap;
import java.util.Map;
@@ -53,7 +50,12 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
final Point2d endPoint = new Point2d(motionEvent.getX(), motionEvent.getY());
final float distance = MathUtils.getDistance(startPoint, endPoint);
final double angle = Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint));
final MutableObject<Boolean> right = new MutableObject<Boolean>();
final double angle = Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint, right));
Log.d(String.valueOf(dragButton.getId()), "Angle: " + angle);
Log.d(String.valueOf(dragButton.getId()), "Is right?: " + right.getObject());
final double duration = motionEvent.getEventTime() - motionEvent.getDownTime();
final Preference distancePreferences = preferences.getPreferencesMap().get(PreferenceType.distance);
@@ -66,23 +68,21 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
Log.d(String.valueOf(dragButton.getId()), "Trying direction interval: " + directionEntry.getValue().getInterval());
if (isInInterval(directionEntry.getValue().getInterval(), distance)) {
for (Map.Entry<DragDirection, DragPreference> angleEntry : anglePreferences.getDirectionPreferences().entrySet()) {
final DragPreference anglePreference = anglePreferences.getDirectionPreferences().get(directionEntry.getKey());
Log.d(String.valueOf(dragButton.getId()), "Trying angle interval: " + angleEntry.getValue().getInterval());
Log.d(String.valueOf(dragButton.getId()), "Trying angle interval: " + anglePreference.getInterval());
if (isInInterval(angleEntry.getValue().getInterval(), (float) angle)) {
Log.d(String.valueOf(dragButton.getId()), "MATCH! Direction: " + angleEntry.getKey());
direction = angleEntry.getKey();
if (directionEntry.getKey() == DragDirection.left && right.getObject()) {
} else if (directionEntry.getKey() == DragDirection.right && !right.getObject()) {
} else {
if (isInInterval(anglePreference.getInterval(), (float) angle)) {
direction = directionEntry.getKey();
Log.d(String.valueOf(dragButton.getId()), "MATCH! Direction: " + direction);
break;
}
}
}
if (direction != null) {
break;
}
}
if (direction != null) {
@@ -116,7 +116,9 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
Log.d(String.valueOf(dragButton.getId()), "Start point: " + startPoint + ", End point: " + endPoint);
Log.d(String.valueOf(dragButton.getId()), "Distance: " + MathUtils.getDistance(startPoint, endPoint));
Log.d(String.valueOf(dragButton.getId()), "Angle: " + Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint)));
final MutableObject<Boolean> right = new MutableObject<Boolean>();
Log.d(String.valueOf(dragButton.getId()), "Angle: " + Math.toDegrees(MathUtils.getAngle(startPoint, MathUtils.sum(startPoint, axis), endPoint, right)));
Log.d(String.valueOf(dragButton.getId()), "Is right angle? " + right);
Log.d(String.valueOf(dragButton.getId()), "Axis: " + axis + " Vector: " + MathUtils.subtract(endPoint, startPoint));
Log.d(String.valueOf(dragButton.getId()), "Total time: " + (motionEvent.getEventTime() - motionEvent.getDownTime()) + " ms");
}
@@ -209,11 +211,11 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
interval.setLeftBorder(180f - rightBorder);
interval.setRightBorder(180f - leftBorder);
} else if (dragDirection == DragDirection.left ) {
interval.setLeftBorder(90f - rightBorder / 2);
interval.setRightBorder(90f + rightBorder / 2);
interval.setLeftBorder(90f - rightBorder);
interval.setRightBorder(90f + rightBorder);
} else if ( dragDirection == DragDirection.right ) {
interval.setLeftBorder(180f + 90f - rightBorder / 2);
interval.setRightBorder(180f + 90f + rightBorder / 2);
interval.setLeftBorder(90f - rightBorder);
interval.setRightBorder(90f + rightBorder);
}
}