Style fixing
This commit is contained in:
@@ -9,10 +9,7 @@ import android.widget.LinearLayout;
|
||||
import org.solovyev.android.calculator.keyboard.BaseFloatingKeyboard;
|
||||
import org.solovyev.android.calculator.keyboard.FloatingKeyboard;
|
||||
import org.solovyev.android.calculator.view.EditTextLongClickEraser;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragListener;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.DragEvent;
|
||||
import org.solovyev.android.views.dragbutton.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -35,7 +32,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
|
||||
this.dragListener = new DirectionDragListener(user.getContext()) {
|
||||
@Override
|
||||
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) {
|
||||
return buttonHandler.onDrag(view, direction);
|
||||
return Drag.hasDirectionText(view, direction) && buttonHandler.onDrag(view, direction);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -83,7 +83,6 @@ public final class Preferences {
|
||||
migratePreference(preferences, editor, Gui.layout, Deleted.layout);
|
||||
migratePreference(preferences, editor, Gui.useBackAsPrevious, Deleted.usePrevAsBack);
|
||||
migratePreference(preferences, editor, Gui.showReleaseNotes, Deleted.showReleaseNotes);
|
||||
migratePreference(preferences, editor, Gui.showEqualsButton, Deleted.showEqualsButton);
|
||||
migratePreference(preferences, editor, Gui.rotateScreen, Deleted.autoOrientation);
|
||||
final Gui.Layout layout = Deleted.layout.getPreference(preferences);
|
||||
if (layout == Gui.Layout.main_cellphone) {
|
||||
@@ -137,7 +136,6 @@ public final class Preferences {
|
||||
Gui.layout.tryPutDefault(preferences, editor);
|
||||
Gui.showReleaseNotes.tryPutDefault(preferences, editor);
|
||||
Gui.useBackAsPrevious.tryPutDefault(preferences, editor);
|
||||
Gui.showEqualsButton.tryPutDefault(preferences, editor);
|
||||
Gui.rotateScreen.tryPutDefault(preferences, editor);
|
||||
Gui.keepScreenOn.tryPutDefault(preferences, editor);
|
||||
Gui.language.tryPutDefault(preferences, editor);
|
||||
|
@@ -12,35 +12,20 @@ import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.calculator.ActivityLauncher;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.BaseActivity;
|
||||
import org.solovyev.android.calculator.Calculator;
|
||||
import org.solovyev.android.calculator.Editor;
|
||||
import org.solovyev.android.calculator.Keyboard;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.PreferredPreferences;
|
||||
import dagger.Lazy;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.buttons.CppSpecialButton;
|
||||
import org.solovyev.android.calculator.memory.Memory;
|
||||
import org.solovyev.android.views.Adjuster;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragImageButton;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragListener;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragView;
|
||||
import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import org.solovyev.android.views.dragbutton.DragEvent;
|
||||
import org.solovyev.android.views.dragbutton.DragView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.solovyev.android.views.dragbutton.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
|
||||
import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING;
|
||||
import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING;
|
||||
import static android.view.HapticFeedbackConstants.KEYBOARD_TAP;
|
||||
import static android.view.HapticFeedbackConstants.*;
|
||||
import static org.solovyev.android.calculator.App.cast;
|
||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple;
|
||||
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
|
||||
@@ -71,6 +56,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
|
||||
@Inject
|
||||
ActivityLauncher launcher;
|
||||
@Inject
|
||||
Lazy<Memory> memory;
|
||||
@Inject
|
||||
PreferredPreferences preferredPreferences;
|
||||
protected int orientation = ORIENTATION_PORTRAIT;
|
||||
private int textSize;
|
||||
@@ -81,7 +68,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
|
||||
listener = new DirectionDragListener(application) {
|
||||
@Override
|
||||
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) {
|
||||
return BaseKeyboardUi.this.onDrag(view, direction);
|
||||
return Drag.hasDirectionText(view, direction) && BaseKeyboardUi.this.onDrag(view, direction);
|
||||
}
|
||||
};
|
||||
textScale = getTextScale(application);
|
||||
@@ -136,6 +123,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
|
||||
prepareButton((ImageView) button);
|
||||
button.setOnDragListener(listener);
|
||||
button.setTypeface(typeface);
|
||||
button.setTextSize(textSize);
|
||||
Adjuster.adjustText(button, AdjusterHelper.instance, textScale, 0);
|
||||
}
|
||||
|
||||
protected final void prepareButton(@Nullable DirectionDragButton button) {
|
||||
@@ -209,4 +198,19 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
|
||||
protected final void onClick(@Nonnull View v, @Nonnull CppSpecialButton b) {
|
||||
onClick(v, b.action);
|
||||
}
|
||||
|
||||
private static class AdjusterHelper implements Adjuster.Helper<DirectionDragImageButton> {
|
||||
|
||||
public static AdjusterHelper instance = new AdjusterHelper();
|
||||
|
||||
@Override
|
||||
public void apply(@NonNull DirectionDragImageButton view, float textSize) {
|
||||
view.setTextSize(textSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextSize(@NonNull DirectionDragImageButton view) {
|
||||
return view.getTextSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,16 +10,15 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import org.solovyev.android.calculator.ActivityLauncher;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.Display;
|
||||
import org.solovyev.android.calculator.DisplayState;
|
||||
import org.solovyev.android.calculator.Engine;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.Expression;
|
||||
import jscl.math.Generic;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.buttons.CppSpecialButton;
|
||||
import org.solovyev.android.calculator.history.History;
|
||||
import org.solovyev.android.calculator.memory.Memory;
|
||||
import org.solovyev.android.calculator.view.AngleUnitsButton;
|
||||
import org.solovyev.android.calculator.view.NumeralBasesButton;
|
||||
import org.solovyev.android.views.dragbutton.DirectionDragButton;
|
||||
@@ -30,20 +29,8 @@ import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import dagger.Lazy;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import jscl.math.Expression;
|
||||
import jscl.math.Generic;
|
||||
|
||||
import static org.solovyev.android.calculator.Engine.Preferences.angleUnit;
|
||||
import static org.solovyev.android.calculator.Engine.Preferences.multiplicationSign;
|
||||
import static org.solovyev.android.calculator.Engine.Preferences.numeralBase;
|
||||
import static org.solovyev.android.views.dragbutton.DragDirection.down;
|
||||
import static org.solovyev.android.views.dragbutton.DragDirection.left;
|
||||
import static org.solovyev.android.views.dragbutton.DragDirection.up;
|
||||
import static org.solovyev.android.calculator.Engine.Preferences.*;
|
||||
import static org.solovyev.android.views.dragbutton.DragDirection.*;
|
||||
|
||||
public class KeyboardUi extends BaseKeyboardUi {
|
||||
|
||||
@@ -76,8 +63,6 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
@Inject
|
||||
Display display;
|
||||
@Inject
|
||||
Lazy<Memory> memory;
|
||||
@Inject
|
||||
PartialKeyboardUi partialUi;
|
||||
@Bind(R.id.cpp_button_vars)
|
||||
DirectionDragButton variablesButton;
|
||||
@@ -108,6 +93,9 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
@Bind(R.id.cpp_button_like)
|
||||
ImageButton likeButton;
|
||||
@Nullable
|
||||
@Bind(R.id.cpp_button_percent)
|
||||
DirectionDragButton percentButton;
|
||||
@Nullable
|
||||
@Bind(R.id.cpp_button_memory)
|
||||
DirectionDragButton memoryButton;
|
||||
|
||||
@@ -143,6 +131,7 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
|
||||
prepareButton(periodButton);
|
||||
prepareButton(bracketsButton);
|
||||
prepareButton(percentButton);
|
||||
|
||||
prepareButton(button0);
|
||||
prepareButton(button1);
|
||||
@@ -163,9 +152,9 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
prepareButton(memoryButton);
|
||||
|
||||
if (isSimpleLayout()) {
|
||||
hideText(button1, up, down);
|
||||
hideText(button2, up, down);
|
||||
hideText(button3, up, down);
|
||||
hideText(button1, down);
|
||||
hideText(button2, down);
|
||||
hideText(button3, down);
|
||||
hideText(button4, down);
|
||||
hideText(button5, down);
|
||||
hideText(button7, left, up, down);
|
||||
@@ -175,6 +164,7 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
hideText(plusButton, up, down);
|
||||
hideText(copyButton, left, up, down);
|
||||
hideText(pasteButton, left, up, down);
|
||||
hideText(functionsButton, up, down);
|
||||
}
|
||||
multiplicationButton.setText(engine.getMultiplicationSign());
|
||||
toggleNumericDigits();
|
||||
@@ -216,6 +206,7 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
case R.id.cpp_button_9:
|
||||
case R.id.cpp_button_division:
|
||||
case R.id.cpp_button_period:
|
||||
case R.id.cpp_button_percent:
|
||||
case R.id.cpp_button_subtraction:
|
||||
case R.id.cpp_button_multiplication:
|
||||
case R.id.cpp_button_plus:
|
||||
@@ -252,13 +243,13 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
@Override
|
||||
protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) {
|
||||
switch (view.getId()) {
|
||||
case R.id.cpp_button_vars:
|
||||
launcher.showConstantEditor();
|
||||
return true;
|
||||
case R.id.cpp_button_functions:
|
||||
if (direction == up) {
|
||||
launcher.showFunctionEditor();
|
||||
return true;
|
||||
} else if (direction == down) {
|
||||
launcher.showConstantEditor();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case R.id.cpp_button_history:
|
||||
@@ -272,12 +263,6 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
return false;
|
||||
case R.id.cpp_button_memory:
|
||||
return processMemoryButton(direction);
|
||||
case R.id.cpp_button_subtraction:
|
||||
if (direction == down) {
|
||||
launcher.showOperators();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case R.id.cpp_button_copy:
|
||||
return processNumeralBaseButton(direction, (DirectionDragView) view);
|
||||
case R.id.cpp_button_paste:
|
||||
@@ -307,6 +292,7 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
}
|
||||
}
|
||||
if (value == null) {
|
||||
memory.get().show();
|
||||
return false;
|
||||
}
|
||||
switch (direction) {
|
||||
@@ -316,9 +302,6 @@ public class KeyboardUi extends BaseKeyboardUi {
|
||||
case down:
|
||||
memory.get().subtract(value);
|
||||
return true;
|
||||
case left:
|
||||
memory.get().clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -3,14 +3,12 @@ package org.solovyev.android.calculator.keyboard;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.buttons.CppSpecialButton;
|
||||
import org.solovyev.android.calculator.view.EditorLongClickEraser;
|
||||
@@ -21,10 +19,6 @@ import org.solovyev.android.views.dragbutton.DragDirection;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
import static org.solovyev.android.calculator.Preferences.Gui.showEqualsButton;
|
||||
import static org.solovyev.android.calculator.Preferences.Gui.vibrateOnKeypress;
|
||||
import static org.solovyev.android.views.dragbutton.DragDirection.down;
|
||||
import static org.solovyev.android.views.dragbutton.DragDirection.up;
|
||||
@@ -39,7 +33,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
|
||||
DirectionDragImageButton leftButton;
|
||||
@Nullable
|
||||
@Bind(R.id.cpp_button_clear)
|
||||
Button clearButton;
|
||||
DirectionDragButton clearButton;
|
||||
@Nullable
|
||||
@Bind(R.id.cpp_button_erase)
|
||||
ImageButton eraseButton;
|
||||
@@ -67,30 +61,14 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
|
||||
prepareButton(eraseButton, IMAGE_SCALE_ERASE);
|
||||
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator);
|
||||
}
|
||||
toggleEqualsButton();
|
||||
}
|
||||
|
||||
public void toggleEqualsButton() {
|
||||
if (equalsButton == null) {
|
||||
return;
|
||||
}
|
||||
if (orientation != Configuration.ORIENTATION_PORTRAIT && Preferences.Gui.rotateScreen.getPreference(preferences)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Preferences.Gui.showEqualsButton.getPreference(preferences)) {
|
||||
equalsButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
equalsButton.setVisibility(View.GONE);
|
||||
if(isSimpleLayout()) {
|
||||
hideText(equalsButton, down);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
super.onSharedPreferenceChanged(preferences, key);
|
||||
if (equalsButton != null && showEqualsButton.isSameKey(key)) {
|
||||
toggleEqualsButton();
|
||||
}
|
||||
if (longClickEraser != null && vibrateOnKeypress.isSameKey(key)) {
|
||||
longClickEraser.setVibrateOnKeypress(vibrateOnKeypress.getPreference(preferences));
|
||||
}
|
||||
@@ -105,6 +83,12 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
|
||||
case R.id.cpp_button_left:
|
||||
editor.setCursorOnStart();
|
||||
return true;
|
||||
case R.id.cpp_button_clear:
|
||||
if(direction == up) {
|
||||
memory.get().clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case R.id.cpp_button_equals:
|
||||
if (direction == down) {
|
||||
launcher.plotDisplayedExpression();
|
||||
|
@@ -156,6 +156,10 @@ public class Memory {
|
||||
value = numeric(newValue);
|
||||
handler.removeCallbacks(writeTask);
|
||||
handler.postDelayed(writeTask, 3000L);
|
||||
show();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
notifier.showMessage(getValue());
|
||||
}
|
||||
|
||||
|
@@ -16,17 +16,33 @@ import static android.graphics.Matrix.MSCALE_Y;
|
||||
public class Adjuster {
|
||||
|
||||
private static final float[] MATRIX = new float[9];
|
||||
@NonNull
|
||||
private static Helper<TextView> textViewHelper = new Helper<TextView>() {
|
||||
@Override
|
||||
public void apply(@NonNull TextView view, float textSize) {
|
||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTextSize(@NonNull TextView view) {
|
||||
return view.getTextSize();
|
||||
}
|
||||
};
|
||||
|
||||
public static void adjustText(@NonNull final TextView view, final float percentage) {
|
||||
adjustText(view, percentage, 0);
|
||||
adjustText(view, textViewHelper, percentage, 0);
|
||||
}
|
||||
|
||||
public static void adjustText(@NonNull final TextView view, final float percentage, final float minTextSizePxs) {
|
||||
public static void adjustText(@NonNull final TextView view, final float percentage, int minTextSizePxs) {
|
||||
adjustText(view, textViewHelper, percentage, minTextSizePxs);
|
||||
}
|
||||
|
||||
public static <V extends View> void adjustText(@NonNull final V view, @NonNull Helper<V> helper, final float percentage, final float minTextSizePxs) {
|
||||
ViewTreeObserver treeObserver = getTreeObserver(view);
|
||||
if (treeObserver == null) {
|
||||
return;
|
||||
}
|
||||
treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage, minTextSizePxs));
|
||||
treeObserver.addOnPreDrawListener(new TextViewAdjuster<V>(view, helper, percentage, minTextSizePxs));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -57,6 +73,12 @@ public class Adjuster {
|
||||
treeObserver.addOnPreDrawListener(new MaxWidthAdjuster(view, maxWidth));
|
||||
}
|
||||
|
||||
public interface Helper<V extends View> {
|
||||
void apply(@NonNull V view, float textSize);
|
||||
|
||||
float getTextSize(@NonNull V view);
|
||||
}
|
||||
|
||||
private static abstract class BaseViewAdjuster<V extends View> implements ViewTreeObserver.OnPreDrawListener {
|
||||
@NonNull
|
||||
protected final V view;
|
||||
@@ -82,24 +104,26 @@ public class Adjuster {
|
||||
protected abstract boolean adjust(int width, int height);
|
||||
}
|
||||
|
||||
private static class TextViewAdjuster extends BaseViewAdjuster<TextView> {
|
||||
private static class TextViewAdjuster<V extends View> extends BaseViewAdjuster<V> {
|
||||
private final float percentage;
|
||||
private final float minTextSizePxs;
|
||||
private final Helper<V> helper;
|
||||
|
||||
public TextViewAdjuster(@NonNull TextView view, float percentage, float minTextSizePxs) {
|
||||
public TextViewAdjuster(@NonNull V view, @NonNull Helper<V> helper, float percentage, float minTextSizePxs) {
|
||||
super(view);
|
||||
this.helper = helper;
|
||||
this.percentage = percentage;
|
||||
this.minTextSizePxs = minTextSizePxs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean adjust(int width, int height) {
|
||||
final float oldTextSize = Math.round(view.getTextSize());
|
||||
final float oldTextSize = Math.round(helper.getTextSize(view));
|
||||
final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage));
|
||||
if (oldTextSize == newTextSize) {
|
||||
return true;
|
||||
}
|
||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, newTextSize);
|
||||
helper.apply(view, newTextSize);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@@ -41,20 +41,16 @@ public class DirectionDragButton extends DragButton implements DirectionDragView
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
final TextPaint paint = getPaint();
|
||||
if (baseTextPaint.getTextSize() != paint.getTextSize() ||
|
||||
baseTextPaint.getTypeface() != paint.getTypeface() ||
|
||||
baseTextPaint.getColor() != paint.getColor() ||
|
||||
baseTextPaint.getAlpha() != paint.getAlpha()) {
|
||||
baseTextPaint.set(paint);
|
||||
textView.setBaseTextPaint(paint);
|
||||
}
|
||||
return super.onPreDraw();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
textView.draw(canvas);
|
||||
}
|
||||
|
||||
|
@@ -54,10 +54,19 @@ public class DirectionDragImageButton extends DragImageButton implements Directi
|
||||
|
||||
public void setTypeface(@Nonnull Typeface newTypeface) {
|
||||
final Typeface oldTypeface = baseTextPaint.getTypeface();
|
||||
if(oldTypeface == newTypeface) {
|
||||
if (oldTypeface == newTypeface) {
|
||||
return;
|
||||
}
|
||||
baseTextPaint.setTypeface(newTypeface);
|
||||
textView.setBaseTextPaint(baseTextPaint);
|
||||
}
|
||||
|
||||
public void setTextSize(float textSizePxs) {
|
||||
baseTextPaint.setTextSize(textSizePxs);
|
||||
textView.setBaseTextPaint(baseTextPaint);
|
||||
}
|
||||
|
||||
public float getTextSize() {
|
||||
return baseTextPaint.getTextSize();
|
||||
}
|
||||
}
|
||||
|
@@ -127,7 +127,10 @@ public class DirectionTextView {
|
||||
paint.set(base);
|
||||
paint.setColor(color);
|
||||
paint.setAlpha(intAlpha());
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
final Typeface typeface = base.getTypeface();
|
||||
if (typeface != null && typeface.getStyle() != Typeface.NORMAL) {
|
||||
paint.setTypeface(Typeface.create(typeface, Typeface.NORMAL));
|
||||
}
|
||||
|
||||
// pre-calculate fixed height
|
||||
paint.setTextSize(Math.max(base.getTextSize() * DEF_SCALE, minTextSize));
|
||||
@@ -176,7 +179,7 @@ public class DirectionTextView {
|
||||
}
|
||||
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
if (!visible || TextUtils.isEmpty(value)) {
|
||||
if (!hasValue()) {
|
||||
return;
|
||||
}
|
||||
if (position.x < 0 || position.y < 0) {
|
||||
@@ -222,6 +225,10 @@ public class DirectionTextView {
|
||||
return visible ? value : "";
|
||||
}
|
||||
|
||||
public boolean hasValue() {
|
||||
return visible && !TextUtils.isEmpty(value);
|
||||
}
|
||||
|
||||
public void setValue(@NonNull String value) {
|
||||
if (TextUtils.equals(this.value, value)) {
|
||||
return;
|
||||
|
@@ -3,8 +3,9 @@ package org.solovyev.android.views.dragbutton;
|
||||
import android.graphics.PointF;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
|
||||
final class Drag {
|
||||
public final class Drag {
|
||||
|
||||
private Drag() {
|
||||
}
|
||||
@@ -19,6 +20,13 @@ final class Drag {
|
||||
return new PointF(p1.x - p2.x, p1.y - p2.y);
|
||||
}
|
||||
|
||||
public static boolean hasDirectionText(@NonNull View view, @NonNull DragDirection direction) {
|
||||
if (view instanceof DirectionDragView) {
|
||||
return ((DirectionDragView) view).getText(direction).hasValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static PointF sum(@NonNull PointF p1, @NonNull PointF p2) {
|
||||
return new PointF(p1.x + p2.x, p1.y + p2.y);
|
||||
|
Reference in New Issue
Block a user