Use Drag Button library
This commit is contained in:
parent
96ea21dd0c
commit
c2146dc0f6
@ -71,6 +71,7 @@ dependencies {
|
||||
compile('ch.acra:acra:4.5.0') {
|
||||
exclude group: 'org.json'
|
||||
}
|
||||
compile 'org.solovyev.android.views.dragbutton:drag-button:1.0@aar'
|
||||
compile 'org.solovyev.android:android-common-lists:1.1.18@aar'
|
||||
compile 'org.solovyev.android:android-common-core:1.1.18@aar'
|
||||
compile 'org.solovyev.android:android-common-other:1.1.18@aar'
|
||||
|
BIN
android-app/misc/libs/drag-button-1.0.aar
Normal file
BIN
android-app/misc/libs/drag-button-1.0.aar
Normal file
Binary file not shown.
@ -24,8 +24,8 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.calculator.units.CalculatorNumeralBase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -26,6 +26,7 @@ import android.app.Activity;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Typeface;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
@ -34,11 +35,11 @@ import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.calculator.drag.DragListener;
|
||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.DragListener;
|
||||
import org.solovyev.android.views.dragbutton.SimpleDragListener;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||
import org.solovyev.android.calculator.history.HistoryDragProcessor;
|
||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
||||
@ -310,7 +311,7 @@ public abstract class BaseUi implements SharedPreferences.OnSharedPreferenceChan
|
||||
|
||||
private static class OperatorsDragProcessor implements SimpleDragListener.DragProcessor {
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) {
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
||||
if (dragDirection == DragDirection.down) {
|
||||
App.getVibrator().vibrate();
|
||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_operators, null);
|
||||
|
@ -26,6 +26,7 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.PointF;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
@ -33,23 +34,20 @@ import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||
import org.solovyev.android.calculator.model.AndroidCalculatorEngine;
|
||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
||||
import org.solovyev.android.calculator.view.ScreenMetrics;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.SimpleDragListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/28/12
|
||||
@ -135,7 +133,7 @@ public final class CalculatorButtons {
|
||||
private final DigitButtonDragProcessor upDownProcessor = new DigitButtonDragProcessor(getKeyboard());
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) {
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
||||
final boolean result;
|
||||
|
||||
if (dragDirection == DragDirection.left) {
|
||||
@ -143,7 +141,7 @@ public final class CalculatorButtons {
|
||||
getKeyboard().roundBracketsButtonPressed();
|
||||
result = true;
|
||||
} else {
|
||||
result = upDownProcessor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||
result = upDownProcessor.processDragEvent(dragDirection, dragButton, startPoint, motionEvent);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -162,7 +160,7 @@ public final class CalculatorButtons {
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection,
|
||||
@Nonnull DragButton dragButton,
|
||||
@Nonnull Point2d startPoint2d,
|
||||
@Nonnull PointF startPoint,
|
||||
@Nonnull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
@ -195,7 +193,7 @@ public final class CalculatorButtons {
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection,
|
||||
@Nonnull DragButton dragButton,
|
||||
@Nonnull Point2d startPoint2d,
|
||||
@Nonnull PointF startPoint,
|
||||
@Nonnull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
@ -221,7 +219,7 @@ public final class CalculatorButtons {
|
||||
}
|
||||
}
|
||||
} else if (dragDirection == DragDirection.left) {
|
||||
result = processor.processDragEvent(dragDirection, dragButton, startPoint2d, motionEvent);
|
||||
result = processor.processDragEvent(dragDirection, dragButton, startPoint, motionEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,7 +239,7 @@ public final class CalculatorButtons {
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection,
|
||||
@Nonnull DragButton dragButton,
|
||||
@Nonnull Point2d startPoint2d,
|
||||
@Nonnull PointF startPoint,
|
||||
@Nonnull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
@ -283,7 +281,7 @@ public final class CalculatorButtons {
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection,
|
||||
@Nonnull DragButton dragButton,
|
||||
@Nonnull Point2d startPoint2d,
|
||||
@Nonnull PointF startPoint,
|
||||
@Nonnull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
|
@ -22,13 +22,12 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.SimpleDragListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -43,7 +42,7 @@ public class CursorDragProcessor implements SimpleDragListener.DragProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) {
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragButton instanceof DirectionDragButton) {
|
||||
|
@ -22,13 +22,12 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.SimpleDragListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -47,7 +46,7 @@ public class DigitButtonDragProcessor implements SimpleDragListener.DragProcesso
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) {
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
||||
if (!(dragButton instanceof DirectionDragButton)) throw new AssertionError();
|
||||
final String text = ((DirectionDragButton) dragButton).getText(dragDirection);
|
||||
calculatorKeyboard.buttonPressed(text);
|
||||
|
@ -22,13 +22,12 @@
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.SimpleDragListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -43,7 +42,7 @@ public class EqualsDragProcessor implements SimpleDragListener.DragProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) {
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
if (dragButton instanceof DirectionDragButton) {
|
||||
|
@ -1,417 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.common.text.NumberParser;
|
||||
import org.solovyev.common.text.StringCollections;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DirectionDragButton extends DragButton {
|
||||
|
||||
@Nonnull
|
||||
private final static Float DEFAULT_DIRECTION_TEXT_SCALE_FLOAT = 0.33f;
|
||||
|
||||
@Nonnull
|
||||
private final static Integer DEFAULT_DIRECTION_TEXT_ALPHA = 140;
|
||||
|
||||
private final static int DEFAULT_DIRECTION_TEXT_COLOR = Color.WHITE;
|
||||
|
||||
@Nonnull
|
||||
private final static String DEFAULT_DIRECTION_TEXT_SCALE = "0.33;0.33;0.33;0.33";
|
||||
@Nonnull
|
||||
private final Map<GuiDragDirection, DirectionTextData> textDataMap = new EnumMap<>(GuiDragDirection.class);
|
||||
@Nonnull
|
||||
protected String directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE;
|
||||
@Nonnull
|
||||
protected Integer directionTextAlpha = DEFAULT_DIRECTION_TEXT_ALPHA;
|
||||
protected int directionTextColor = DEFAULT_DIRECTION_TEXT_COLOR;
|
||||
private boolean initialized = false;
|
||||
|
||||
public DirectionDragButton(Context context, @Nonnull AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(@Nonnull Context context, @Nonnull AttributeSet attrs) {
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, org.solovyev.android.view.R.styleable.DirectionDragButton);
|
||||
|
||||
for (int i = 0; i < a.getIndexCount(); i++) {
|
||||
int attr = a.getIndex(i);
|
||||
|
||||
if (a.hasValue(attr)) {
|
||||
if (attr == org.solovyev.android.view.R.styleable.DirectionDragButton_directionTextColor) {
|
||||
this.directionTextColor = a.getColor(attr, DEFAULT_DIRECTION_TEXT_COLOR);
|
||||
} else if (attr == org.solovyev.android.view.R.styleable.DirectionDragButton_directionTextScale) {
|
||||
this.directionTextScale = a.getString(attr);
|
||||
} else if (attr == org.solovyev.android.view.R.styleable.DirectionDragButton_directionTextAlpha) {
|
||||
this.directionTextAlpha = a.getInt(attr, DEFAULT_DIRECTION_TEXT_ALPHA);
|
||||
} else {
|
||||
// try drag direction text
|
||||
for (GuiDragDirection guiDragDirection : GuiDragDirection.values()) {
|
||||
if (guiDragDirection.getAttributeId() == attr) {
|
||||
this.textDataMap.put(guiDragDirection, new DirectionTextData(guiDragDirection, a.getString(attr)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
a.recycle();
|
||||
|
||||
for (Map.Entry<GuiDragDirection, Float> entry : getDirectionTextScales().entrySet()) {
|
||||
final DirectionTextData td = textDataMap.get(entry.getKey());
|
||||
if (td != null) {
|
||||
td.scale = entry.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeChanged(int w, int h, int oldW, int oldH) {
|
||||
measureText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTextChanged(CharSequence text, int start, int before, int after) {
|
||||
measureText();
|
||||
}
|
||||
|
||||
protected void measureText() {
|
||||
if (initialized) {
|
||||
final Paint basePaint = getPaint();
|
||||
for (DirectionTextData textData : textDataMap.values()) {
|
||||
initDirectionTextPaint(basePaint, textData);
|
||||
textData.position = textData.direction.getTextPosition(textData.paint, basePaint, textData.text, getText(), getWidth(), getHeight());
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
protected void initDirectionTextPaint(@Nonnull Paint basePaint, @Nonnull DirectionTextData textData) {
|
||||
textData.init(basePaint, directionTextColor, directionTextAlpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
final TextPaint paint = getPaint();
|
||||
for (DirectionTextData td : textDataMap.values()) {
|
||||
if (td.show) {
|
||||
initDirectionTextPaint(paint, td);
|
||||
final String text = td.text;
|
||||
final Point2d position = td.position;
|
||||
canvas.drawText(text, 0, text.length(), position.getX(), position.getY(), td.paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Nullable
|
||||
public String getTextUp() {
|
||||
return getText(GuiDragDirection.up);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
@Nullable
|
||||
public String getTextDown() {
|
||||
return getText(GuiDragDirection.down);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getText(@Nonnull DragDirection direction) {
|
||||
final GuiDragDirection guiDragDirection = GuiDragDirection.valueOf(direction);
|
||||
return guiDragDirection == null ? null : getText(guiDragDirection);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
public void showDirectionText(boolean show, @Nonnull DragDirection direction) {
|
||||
final GuiDragDirection guiDragDirection = GuiDragDirection.valueOf(direction);
|
||||
final DirectionTextData td = this.textDataMap.get(guiDragDirection);
|
||||
if (td != null) {
|
||||
td.show = show;
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(@Nullable String text, @Nonnull GuiDragDirection direction) {
|
||||
if (!TextUtils.isEmpty(text)) {
|
||||
final DirectionTextData data = new DirectionTextData(direction, text);
|
||||
initDirectionTextPaint(getPaint(), data);
|
||||
textDataMap.put(direction, data);
|
||||
} else {
|
||||
textDataMap.remove(direction);
|
||||
}
|
||||
measureText();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getText(@Nonnull GuiDragDirection direction) {
|
||||
DirectionTextData td = textDataMap.get(direction);
|
||||
if (td == null) {
|
||||
return null;
|
||||
} else {
|
||||
if (td.show) {
|
||||
return td.text;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getDirectionTextScale() {
|
||||
return directionTextScale;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private Map<GuiDragDirection, Float> getDirectionTextScales() {
|
||||
final List<Float> scales = StringCollections.split(getDirectionTextScale(), ";", NumberParser.of(Float.class));
|
||||
|
||||
final Map<GuiDragDirection, Float> result = new HashMap<>();
|
||||
for (GuiDragDirection direction : GuiDragDirection.values()) {
|
||||
result.put(direction, DEFAULT_DIRECTION_TEXT_SCALE_FLOAT);
|
||||
}
|
||||
|
||||
if (scales.size() == 1) {
|
||||
final Float scale = scales.get(0);
|
||||
for (Map.Entry<GuiDragDirection, Float> entry : result.entrySet()) {
|
||||
entry.setValue(scale);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < scales.size(); i++) {
|
||||
for (GuiDragDirection direction : GuiDragDirection.values()) {
|
||||
if (direction.getAttributePosition() == i) {
|
||||
result.put(direction, scales.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static enum GuiDragDirection {
|
||||
up(DragDirection.up, 0) {
|
||||
@Override
|
||||
public int getAttributeId() {
|
||||
return org.solovyev.android.view.R.styleable.DirectionDragButton_textUp;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
|
||||
return getUpDownTextPosition(paint, basePaint, text, baseText, 1, w, h);
|
||||
}
|
||||
},
|
||||
down(DragDirection.down, 2) {
|
||||
@Override
|
||||
public int getAttributeId() {
|
||||
return org.solovyev.android.view.R.styleable.DirectionDragButton_textDown;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
|
||||
return getUpDownTextPosition(paint, basePaint, text, baseText, -1, w, h);
|
||||
}
|
||||
},
|
||||
left(DragDirection.left, 3) {
|
||||
@Override
|
||||
public int getAttributeId() {
|
||||
return org.solovyev.android.view.R.styleable.DirectionDragButton_textLeft;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
|
||||
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, true);
|
||||
}
|
||||
},
|
||||
|
||||
right(DragDirection.right, 1) {
|
||||
@Override
|
||||
public int getAttributeId() {
|
||||
return org.solovyev.android.view.R.styleable.DirectionDragButton_textRight;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h) {
|
||||
return getLeftRightTextPosition(paint, basePaint, text, baseText, w, h, false);
|
||||
}
|
||||
};
|
||||
|
||||
@Nonnull
|
||||
private final DragDirection dragDirection;
|
||||
|
||||
private final int attributePosition;
|
||||
|
||||
GuiDragDirection(@Nonnull DragDirection dragDirection, int attributePosition) {
|
||||
this.dragDirection = dragDirection;
|
||||
this.attributePosition = attributePosition;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static Point2d getLeftRightTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, CharSequence text, @Nonnull 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(Strings.getNotEmpty(baseText, "|"));
|
||||
|
||||
result.setY(h / 2 - selfHeight / 2);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static Point2d getUpDownTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, float direction, int w, int h) {
|
||||
final Point2d result = new Point2d();
|
||||
|
||||
float width = paint.measureText(text.toString() + " ");
|
||||
result.setX(w - width);
|
||||
|
||||
float selfHeight = paint.ascent() + paint.descent();
|
||||
|
||||
basePaint.measureText(Strings.getNotEmpty(baseText, "|"));
|
||||
|
||||
if (direction < 0) {
|
||||
result.setY(h / 2 + h / 3 - selfHeight / 2);
|
||||
} else {
|
||||
result.setY(h / 2 - h / 3 - selfHeight / 2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GuiDragDirection valueOf(@Nonnull DragDirection dragDirection) {
|
||||
for (GuiDragDirection guiDragDirection : values()) {
|
||||
if (guiDragDirection.dragDirection == dragDirection) {
|
||||
return guiDragDirection;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract int getAttributeId();
|
||||
|
||||
public int getAttributePosition() {
|
||||
return attributePosition;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public abstract Point2d getTextPosition(@Nonnull Paint paint, @Nonnull Paint basePaint, @Nonnull CharSequence text, CharSequence baseText, int w, int h);
|
||||
}
|
||||
|
||||
protected static class DirectionTextData {
|
||||
|
||||
@Nonnull
|
||||
private final GuiDragDirection direction;
|
||||
@Nonnull
|
||||
private final TextPaint paint = new TextPaint();
|
||||
@Nonnull
|
||||
private String text;
|
||||
@Nonnull
|
||||
private Point2d position;
|
||||
@Nonnull
|
||||
private Float scale = 0.5f;
|
||||
|
||||
private boolean show = true;
|
||||
|
||||
private DirectionTextData(@Nonnull GuiDragDirection direction, @Nonnull String text) {
|
||||
this.direction = direction;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
protected void init(@Nonnull Paint basePaint,
|
||||
int color,
|
||||
int alpha) {
|
||||
paint.set(basePaint);
|
||||
paint.setColor(color);
|
||||
paint.setAlpha(alpha);
|
||||
paint.setTextSize(basePaint.getTextSize() * scale);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public GuiDragDirection getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Point2d getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public TextPaint getPaint() {
|
||||
return paint;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Float getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public boolean isShow() {
|
||||
return show;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.solovyev.android.view.AndroidViewUtils;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DragButton extends Button {
|
||||
|
||||
@Nullable
|
||||
private Point2d startPoint = null;
|
||||
|
||||
@Nullable
|
||||
private DragListener onDragListener;
|
||||
|
||||
private boolean showText = true;
|
||||
|
||||
@Nullable
|
||||
private CharSequence textBackup;
|
||||
|
||||
public DragButton(@Nonnull Context context, @Nonnull AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void setOnDragListener(@Nullable DragListener onDragListener) {
|
||||
this.onDragListener = onDragListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(@Nonnull MotionEvent event) {
|
||||
boolean consumed = false;
|
||||
|
||||
// in order to avoid possible NPEs
|
||||
final Point2d localStartPoint = startPoint;
|
||||
final DragListener localOnDragListener = onDragListener;
|
||||
|
||||
if (localOnDragListener != null) {
|
||||
// only if onDrag() listener specified
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
// start tracking: set start point
|
||||
startPoint = new Point2d(event.getX(), event.getY());
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
case MotionEvent.ACTION_UP:
|
||||
// stop tracking
|
||||
|
||||
startPoint = null;
|
||||
if (localStartPoint != null) {
|
||||
consumed = localOnDragListener.onDrag(DragButton.this, new DragEvent(localStartPoint, event));
|
||||
if (consumed && localOnDragListener.isSuppressOnClickEvent()) {
|
||||
final MotionEvent newEvent = MotionEvent.obtain(event);
|
||||
newEvent.setAction(MotionEvent.ACTION_CANCEL);
|
||||
super.onTouchEvent(newEvent);
|
||||
newEvent.recycle();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return super.onTouchEvent(event) || consumed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(@Nonnull MotionEvent event) {
|
||||
return super.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
CharSequence text = getText();
|
||||
if (!Strings.isEmpty(text)) {
|
||||
super.onDraw(canvas);
|
||||
} else {
|
||||
if (!AndroidViewUtils.drawDrawables(canvas, this)) {
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isShowText() {
|
||||
return showText;
|
||||
}
|
||||
|
||||
public void setShowText(boolean showText) {
|
||||
if (this.showText != showText) {
|
||||
if (showText) {
|
||||
setText(textBackup);
|
||||
textBackup = null;
|
||||
} else {
|
||||
textBackup = this.getText();
|
||||
setText(null);
|
||||
}
|
||||
this.showText = showText;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
public enum DragDirection {
|
||||
|
||||
up,
|
||||
down,
|
||||
left,
|
||||
right;
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class DragEvent {
|
||||
|
||||
@Nonnull
|
||||
private final Point2d startPoint;
|
||||
|
||||
@Nonnull
|
||||
private final MotionEvent motionEvent;
|
||||
|
||||
public DragEvent(@Nonnull Point2d startPoint, @Nonnull MotionEvent motionEvent) {
|
||||
this.startPoint = startPoint;
|
||||
this.motionEvent = motionEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return motion event started at start point
|
||||
*/
|
||||
@Nonnull
|
||||
public MotionEvent getMotionEvent() {
|
||||
return motionEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return start point of dragging
|
||||
*/
|
||||
@Nonnull
|
||||
public Point2d getStartPoint() {
|
||||
return startPoint;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
public interface DragListener extends EventListener {
|
||||
|
||||
/**
|
||||
* @return 'true': if drag event has taken place (i.e. onDrag() method returned true) then click action will be suppresed
|
||||
*/
|
||||
boolean isSuppressOnClickEvent();
|
||||
|
||||
/**
|
||||
* @param dragButton drag button object for which onDrag listener was set
|
||||
* @param event drag event
|
||||
* @return 'true' if drag event occurred, 'false' otherwise
|
||||
*/
|
||||
boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event);
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/26/11
|
||||
* Time: 10:37 PM
|
||||
*/
|
||||
public class DragListenerWrapper implements DragListener {
|
||||
|
||||
@Nonnull
|
||||
private final DragListener dragListener;
|
||||
|
||||
public DragListenerWrapper(@Nonnull DragListener dragListener) {
|
||||
this.dragListener = dragListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressOnClickEvent() {
|
||||
return this.dragListener.isSuppressOnClickEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event) {
|
||||
return this.dragListener.onDrag(dragButton, event);
|
||||
}
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 serso aka se.solovyev
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Contact details
|
||||
*
|
||||
* Email: se.solovyev@gmail.com
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator.drag;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.MutableObject;
|
||||
import org.solovyev.common.interval.Interval;
|
||||
import org.solovyev.common.interval.Intervals;
|
||||
import org.solovyev.common.math.Maths;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SimpleDragListener implements DragListener {
|
||||
|
||||
@Nonnull
|
||||
private static final Point2d axis = new Point2d(0, 1);
|
||||
|
||||
@Nonnull
|
||||
private static final EnumMap<DragDirection, Interval<Float>> sAngleIntervals = new EnumMap<>(DragDirection.class);
|
||||
|
||||
static {
|
||||
for (DragDirection direction : DragDirection.values()) {
|
||||
sAngleIntervals.put(direction, makeAngleInterval(direction, 0, 45));
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private final DragProcessor processor;
|
||||
|
||||
private final float minDistancePxs;
|
||||
|
||||
public SimpleDragListener(@Nonnull DragProcessor processor, @Nonnull Context context) {
|
||||
this.processor = processor;
|
||||
this.minDistancePxs = context.getResources().getDimensionPixelSize(R.dimen.cpp_min_drag_distance);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static Interval<Float> makeAngleInterval(@Nonnull DragDirection direction,
|
||||
float leftLimit,
|
||||
float rightLimit) {
|
||||
final Float newLeftLimit;
|
||||
final Float newRightLimit;
|
||||
switch (direction) {
|
||||
case up:
|
||||
newLeftLimit = 180f - rightLimit;
|
||||
newRightLimit = 180f - leftLimit;
|
||||
break;
|
||||
case down:
|
||||
newLeftLimit = leftLimit;
|
||||
newRightLimit = rightLimit;
|
||||
break;
|
||||
case left:
|
||||
newLeftLimit = 90f - rightLimit;
|
||||
newRightLimit = 90f + rightLimit;
|
||||
break;
|
||||
case right:
|
||||
newLeftLimit = 90f - rightLimit;
|
||||
newRightLimit = 90f + rightLimit;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
return Intervals.newClosedInterval(newLeftLimit, newRightLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDrag(@Nonnull DragButton dragButton, @Nonnull DragEvent event) {
|
||||
boolean consumed = false;
|
||||
|
||||
final MotionEvent motionEvent = event.getMotionEvent();
|
||||
|
||||
final Point2d start = event.getStartPoint();
|
||||
final Point2d end = new Point2d(motionEvent.getX(), motionEvent.getY());
|
||||
final float distance = Maths.getDistance(start, end);
|
||||
|
||||
final MutableObject<Boolean> right = new MutableObject<>();
|
||||
final double angle = Math.toDegrees(Maths.getAngle(start, Maths.sum(start, axis), end, right));
|
||||
|
||||
final long duration = motionEvent.getEventTime() - motionEvent.getDownTime();
|
||||
final DragDirection direction = getDirection(distance, (float) angle, right.getObject());
|
||||
if (direction != null && duration > 40 && duration < 2500) {
|
||||
consumed = processor.processDragEvent(direction, dragButton, start, motionEvent);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DragDirection getDirection(float distance, float angle, boolean right) {
|
||||
if (distance > minDistancePxs) {
|
||||
for (DragDirection direction : DragDirection.values()) {
|
||||
final Interval<Float> angleInterval = sAngleIntervals.get(direction);
|
||||
final boolean wrongDirection = (direction == DragDirection.left && right) ||
|
||||
(direction == DragDirection.right && !right);
|
||||
if (!wrongDirection && angleInterval.contains(angle)) {
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressOnClickEvent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public interface DragProcessor {
|
||||
|
||||
boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent);
|
||||
}
|
||||
}
|
@ -22,16 +22,15 @@
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.SimpleDragListener;
|
||||
import org.solovyev.common.history.HistoryAction;
|
||||
import org.solovyev.common.history.HistoryControl;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -50,7 +49,7 @@ public class HistoryDragProcessor<T> implements SimpleDragListener.DragProcessor
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull Point2d startPoint2d, @Nonnull MotionEvent motionEvent) {
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection, @Nonnull DragButton dragButton, @Nonnull PointF startPoint, @Nonnull MotionEvent motionEvent) {
|
||||
boolean result = false;
|
||||
|
||||
Log.d(String.valueOf(dragButton.getId()), "History on drag event start: " + dragDirection);
|
||||
|
@ -30,7 +30,7 @@ import android.util.AttributeSet;
|
||||
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -25,10 +25,10 @@ package org.solovyev.android.calculator.view;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Vibrator;
|
||||
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragEvent;
|
||||
import org.solovyev.android.calculator.drag.DragListener;
|
||||
import org.solovyev.android.calculator.drag.DragListenerWrapper;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragEvent;
|
||||
import org.solovyev.android.views.dragbutton.DragListener;
|
||||
import org.solovyev.android.views.dragbutton.DragListenerWrapper;
|
||||
import org.solovyev.android.view.VibratorContainer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -29,7 +29,7 @@ import android.util.AttributeSet;
|
||||
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
@ -30,13 +30,16 @@ import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorApplication.getPreferences;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.engineer;
|
||||
import static org.solovyev.android.calculator.wizard.CalculatorMode.simple;
|
||||
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.down;
|
||||
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.left;
|
||||
import static org.solovyev.android.views.dragbutton.DirectionDragButton.Direction.up;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@ -72,13 +75,13 @@ public class ChooseModeWizardStep extends WizardFragment implements AdapterView.
|
||||
boolean simple = mode == CalculatorMode.simple;
|
||||
description.setText(simple ? R.string.cpp_wizard_mode_simple_description : R.string.cpp_wizard_mode_engineer_description);
|
||||
if (simple) {
|
||||
button.setText("", DirectionDragButton.GuiDragDirection.up);
|
||||
button.setText("", DirectionDragButton.GuiDragDirection.down);
|
||||
button.setText("", DirectionDragButton.GuiDragDirection.left);
|
||||
button.setText("", up);
|
||||
button.setText("", down);
|
||||
button.setText("", left);
|
||||
} else {
|
||||
button.setText("sin", DirectionDragButton.GuiDragDirection.up);
|
||||
button.setText("ln", DirectionDragButton.GuiDragDirection.down);
|
||||
button.setText("i", DirectionDragButton.GuiDragDirection.left);
|
||||
button.setText("sin", up);
|
||||
button.setText("ln", down);
|
||||
button.setText("i", left);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,23 +22,21 @@
|
||||
|
||||
package org.solovyev.android.calculator.wizard;
|
||||
|
||||
import android.graphics.PointF;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.drag.DirectionDragButton;
|
||||
import org.solovyev.android.calculator.drag.DragButton;
|
||||
import org.solovyev.android.calculator.drag.DragDirection;
|
||||
import org.solovyev.android.calculator.drag.SimpleDragListener;
|
||||
import org.solovyev.common.math.Point2d;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragButton;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.SimpleDragListener;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DragButtonWizardStep extends WizardFragment {
|
||||
|
||||
@ -174,7 +172,7 @@ public class DragButtonWizardStep extends WizardFragment {
|
||||
@Override
|
||||
public boolean processDragEvent(@Nonnull DragDirection dragDirection,
|
||||
@Nonnull DragButton dragButton,
|
||||
@Nonnull Point2d startPoint2d,
|
||||
@Nonnull PointF startPoint,
|
||||
@Nonnull MotionEvent motionEvent) {
|
||||
if (dragDirection == DragDirection.up || dragDirection == DragDirection.down) {
|
||||
App.getVibrator().vibrate();
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -21,7 +21,7 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -21,7 +21,7 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -21,4 +21,4 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton style="?attr/cpp_button_style_control" />
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton style="?attr/cpp_button_style_control" />
|
@ -21,7 +21,7 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -21,7 +21,7 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -21,7 +21,7 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
a:id="@id/cpp_button_history"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -21,7 +21,7 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
a:id="@id/cpp_button_operators"
|
||||
|
@ -21,7 +21,7 @@
|
||||
~ Email: se.solovyev@gmail.com
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -22,7 +22,7 @@
|
||||
~ Site: http://se.solovyev.org
|
||||
-->
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
xmlns:c="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
|
@ -57,7 +57,7 @@
|
||||
a:background="?attr/cpp_main_bg"
|
||||
a:padding="3dp">
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
a:id="@+id/wizard_mode_button"
|
||||
style="?attr/cpp_button_style_operation"
|
||||
a:layout_width="100dp"
|
||||
|
@ -42,7 +42,7 @@
|
||||
a:text="@string/cpp_wizard_dragbutton_action_center"
|
||||
a:textStyle="bold" />
|
||||
|
||||
<org.solovyev.android.calculator.drag.DirectionDragButton
|
||||
<org.solovyev.android.views.dragbutton.DirectionDragButton
|
||||
a:id="@+id/wizard_dragbutton"
|
||||
style="?attr/cpp_button_style_operation"
|
||||
a:layout_width="wrap_content"
|
||||
|
@ -36,6 +36,5 @@
|
||||
<dimen name="activity_horizontal_margin">5dp</dimen>
|
||||
<dimen name="activity_vertical_margin">5dp</dimen>
|
||||
<dimen name="control_margin">5dp</dimen>
|
||||
<dimen name="cpp_min_drag_distance">25dp</dimen>
|
||||
<dimen name="cpp_onscreen_main_padding">1dp</dimen>
|
||||
</resources>
|
@ -21,15 +21,6 @@
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<string name="p_drag_distance_key" translatable="false">org.solovyev.android.calculator.DragButtonCalibrationActivity_distance</string>
|
||||
<string name="p_drag_distance" translatable="false">35;350</string>
|
||||
|
||||
<string name="p_drag_angle_key" translatable="false">org.solovyev.android.calculator.DragButtonCalibrationActivity_angle</string>
|
||||
<string name="p_drag_angle" translatable="false">0;45</string>
|
||||
|
||||
<string name="p_drag_duration_key" translatable="false">org.solovyev.android.calculator.DragButtonCalibrationActivity_duration</string>
|
||||
<string name="p_drag_duration" translatable="false">40;2500</string>
|
||||
|
||||
<string name="p_calc_result_precision_key" translatable="false">org.solovyev.android.calculator.CalculatorModel_result_precision</string>
|
||||
<string name="p_calc_result_precision" translatable="false">5</string>
|
||||
|
||||
|
@ -19,9 +19,8 @@ public String android_min_sdk_version() {
|
||||
}
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.5.0'
|
||||
|
Loading…
Reference in New Issue
Block a user