Style fixing

This commit is contained in:
serso 2016-03-13 23:45:54 +01:00
parent 4434973733
commit 1dcd43258c
32 changed files with 221 additions and 181 deletions

View File

@ -9,10 +9,7 @@ import android.widget.LinearLayout;
import org.solovyev.android.calculator.keyboard.BaseFloatingKeyboard; import org.solovyev.android.calculator.keyboard.BaseFloatingKeyboard;
import org.solovyev.android.calculator.keyboard.FloatingKeyboard; import org.solovyev.android.calculator.keyboard.FloatingKeyboard;
import org.solovyev.android.calculator.view.EditTextLongClickEraser; import org.solovyev.android.calculator.view.EditTextLongClickEraser;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.*;
import org.solovyev.android.views.dragbutton.DirectionDragListener;
import org.solovyev.android.views.dragbutton.DragDirection;
import org.solovyev.android.views.dragbutton.DragEvent;
import java.util.List; import java.util.List;
@ -35,7 +32,7 @@ public class FloatingCalculatorKeyboard extends BaseFloatingKeyboard {
this.dragListener = new DirectionDragListener(user.getContext()) { this.dragListener = new DirectionDragListener(user.getContext()) {
@Override @Override
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) { 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);
} }
}; };
} }

View File

@ -83,7 +83,6 @@ public final class Preferences {
migratePreference(preferences, editor, Gui.layout, Deleted.layout); migratePreference(preferences, editor, Gui.layout, Deleted.layout);
migratePreference(preferences, editor, Gui.useBackAsPrevious, Deleted.usePrevAsBack); migratePreference(preferences, editor, Gui.useBackAsPrevious, Deleted.usePrevAsBack);
migratePreference(preferences, editor, Gui.showReleaseNotes, Deleted.showReleaseNotes); migratePreference(preferences, editor, Gui.showReleaseNotes, Deleted.showReleaseNotes);
migratePreference(preferences, editor, Gui.showEqualsButton, Deleted.showEqualsButton);
migratePreference(preferences, editor, Gui.rotateScreen, Deleted.autoOrientation); migratePreference(preferences, editor, Gui.rotateScreen, Deleted.autoOrientation);
final Gui.Layout layout = Deleted.layout.getPreference(preferences); final Gui.Layout layout = Deleted.layout.getPreference(preferences);
if (layout == Gui.Layout.main_cellphone) { if (layout == Gui.Layout.main_cellphone) {
@ -137,7 +136,6 @@ public final class Preferences {
Gui.layout.tryPutDefault(preferences, editor); Gui.layout.tryPutDefault(preferences, editor);
Gui.showReleaseNotes.tryPutDefault(preferences, editor); Gui.showReleaseNotes.tryPutDefault(preferences, editor);
Gui.useBackAsPrevious.tryPutDefault(preferences, editor); Gui.useBackAsPrevious.tryPutDefault(preferences, editor);
Gui.showEqualsButton.tryPutDefault(preferences, editor);
Gui.rotateScreen.tryPutDefault(preferences, editor); Gui.rotateScreen.tryPutDefault(preferences, editor);
Gui.keepScreenOn.tryPutDefault(preferences, editor); Gui.keepScreenOn.tryPutDefault(preferences, editor);
Gui.language.tryPutDefault(preferences, editor); Gui.language.tryPutDefault(preferences, editor);

View File

@ -12,35 +12,20 @@ import android.util.TypedValue;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import dagger.Lazy;
import org.solovyev.android.calculator.ActivityLauncher; import org.solovyev.android.calculator.*;
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 org.solovyev.android.calculator.buttons.CppSpecialButton; 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.Adjuster;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.*;
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 javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING; import static android.view.HapticFeedbackConstants.*;
import static android.view.HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING;
import static android.view.HapticFeedbackConstants.KEYBOARD_TAP;
import static org.solovyev.android.calculator.App.cast; 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;
import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile; import static org.solovyev.android.calculator.Preferences.Gui.Layout.simple_mobile;
@ -71,6 +56,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
@Inject @Inject
ActivityLauncher launcher; ActivityLauncher launcher;
@Inject @Inject
Lazy<Memory> memory;
@Inject
PreferredPreferences preferredPreferences; PreferredPreferences preferredPreferences;
protected int orientation = ORIENTATION_PORTRAIT; protected int orientation = ORIENTATION_PORTRAIT;
private int textSize; private int textSize;
@ -81,7 +68,7 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
listener = new DirectionDragListener(application) { listener = new DirectionDragListener(application) {
@Override @Override
protected boolean onDrag(@NonNull View view, @NonNull DragEvent event, @NonNull DragDirection direction) { 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); textScale = getTextScale(application);
@ -136,6 +123,8 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
prepareButton((ImageView) button); prepareButton((ImageView) button);
button.setOnDragListener(listener); button.setOnDragListener(listener);
button.setTypeface(typeface); button.setTypeface(typeface);
button.setTextSize(textSize);
Adjuster.adjustText(button, AdjusterHelper.instance, textScale, 0);
} }
protected final void prepareButton(@Nullable DirectionDragButton button) { 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) { protected final void onClick(@Nonnull View v, @Nonnull CppSpecialButton b) {
onClick(v, b.action); 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();
}
}
} }

View File

@ -10,16 +10,15 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import butterknife.Bind;
import org.solovyev.android.calculator.ActivityLauncher; import butterknife.ButterKnife;
import org.solovyev.android.calculator.App; import jscl.AngleUnit;
import org.solovyev.android.calculator.Display; import jscl.NumeralBase;
import org.solovyev.android.calculator.DisplayState; import jscl.math.Expression;
import org.solovyev.android.calculator.Engine; import jscl.math.Generic;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.history.History; 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.AngleUnitsButton;
import org.solovyev.android.calculator.view.NumeralBasesButton; import org.solovyev.android.calculator.view.NumeralBasesButton;
import org.solovyev.android.views.dragbutton.DirectionDragButton; import org.solovyev.android.views.dragbutton.DirectionDragButton;
@ -30,20 +29,8 @@ import org.solovyev.android.views.dragbutton.DragDirection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; import javax.inject.Inject;
import butterknife.Bind; import static org.solovyev.android.calculator.Engine.Preferences.*;
import butterknife.ButterKnife; import static org.solovyev.android.views.dragbutton.DragDirection.*;
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;
public class KeyboardUi extends BaseKeyboardUi { public class KeyboardUi extends BaseKeyboardUi {
@ -76,8 +63,6 @@ public class KeyboardUi extends BaseKeyboardUi {
@Inject @Inject
Display display; Display display;
@Inject @Inject
Lazy<Memory> memory;
@Inject
PartialKeyboardUi partialUi; PartialKeyboardUi partialUi;
@Bind(R.id.cpp_button_vars) @Bind(R.id.cpp_button_vars)
DirectionDragButton variablesButton; DirectionDragButton variablesButton;
@ -108,6 +93,9 @@ public class KeyboardUi extends BaseKeyboardUi {
@Bind(R.id.cpp_button_like) @Bind(R.id.cpp_button_like)
ImageButton likeButton; ImageButton likeButton;
@Nullable @Nullable
@Bind(R.id.cpp_button_percent)
DirectionDragButton percentButton;
@Nullable
@Bind(R.id.cpp_button_memory) @Bind(R.id.cpp_button_memory)
DirectionDragButton memoryButton; DirectionDragButton memoryButton;
@ -143,6 +131,7 @@ public class KeyboardUi extends BaseKeyboardUi {
prepareButton(periodButton); prepareButton(periodButton);
prepareButton(bracketsButton); prepareButton(bracketsButton);
prepareButton(percentButton);
prepareButton(button0); prepareButton(button0);
prepareButton(button1); prepareButton(button1);
@ -163,9 +152,9 @@ public class KeyboardUi extends BaseKeyboardUi {
prepareButton(memoryButton); prepareButton(memoryButton);
if (isSimpleLayout()) { if (isSimpleLayout()) {
hideText(button1, up, down); hideText(button1, down);
hideText(button2, up, down); hideText(button2, down);
hideText(button3, up, down); hideText(button3, down);
hideText(button4, down); hideText(button4, down);
hideText(button5, down); hideText(button5, down);
hideText(button7, left, up, down); hideText(button7, left, up, down);
@ -175,6 +164,7 @@ public class KeyboardUi extends BaseKeyboardUi {
hideText(plusButton, up, down); hideText(plusButton, up, down);
hideText(copyButton, left, up, down); hideText(copyButton, left, up, down);
hideText(pasteButton, left, up, down); hideText(pasteButton, left, up, down);
hideText(functionsButton, up, down);
} }
multiplicationButton.setText(engine.getMultiplicationSign()); multiplicationButton.setText(engine.getMultiplicationSign());
toggleNumericDigits(); toggleNumericDigits();
@ -216,6 +206,7 @@ public class KeyboardUi extends BaseKeyboardUi {
case R.id.cpp_button_9: case R.id.cpp_button_9:
case R.id.cpp_button_division: case R.id.cpp_button_division:
case R.id.cpp_button_period: case R.id.cpp_button_period:
case R.id.cpp_button_percent:
case R.id.cpp_button_subtraction: case R.id.cpp_button_subtraction:
case R.id.cpp_button_multiplication: case R.id.cpp_button_multiplication:
case R.id.cpp_button_plus: case R.id.cpp_button_plus:
@ -252,13 +243,13 @@ public class KeyboardUi extends BaseKeyboardUi {
@Override @Override
protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) { protected boolean onDrag(@NonNull View view, @NonNull DragDirection direction) {
switch (view.getId()) { switch (view.getId()) {
case R.id.cpp_button_vars:
launcher.showConstantEditor();
return true;
case R.id.cpp_button_functions: case R.id.cpp_button_functions:
if (direction == up) { if (direction == up) {
launcher.showFunctionEditor(); launcher.showFunctionEditor();
return true; return true;
} else if (direction == down) {
launcher.showConstantEditor();
return true;
} }
return false; return false;
case R.id.cpp_button_history: case R.id.cpp_button_history:
@ -272,12 +263,6 @@ public class KeyboardUi extends BaseKeyboardUi {
return false; return false;
case R.id.cpp_button_memory: case R.id.cpp_button_memory:
return processMemoryButton(direction); return processMemoryButton(direction);
case R.id.cpp_button_subtraction:
if (direction == down) {
launcher.showOperators();
return true;
}
return false;
case R.id.cpp_button_copy: case R.id.cpp_button_copy:
return processNumeralBaseButton(direction, (DirectionDragView) view); return processNumeralBaseButton(direction, (DirectionDragView) view);
case R.id.cpp_button_paste: case R.id.cpp_button_paste:
@ -307,6 +292,7 @@ public class KeyboardUi extends BaseKeyboardUi {
} }
} }
if (value == null) { if (value == null) {
memory.get().show();
return false; return false;
} }
switch (direction) { switch (direction) {
@ -316,9 +302,6 @@ public class KeyboardUi extends BaseKeyboardUi {
case down: case down:
memory.get().subtract(value); memory.get().subtract(value);
return true; return true;
case left:
memory.get().clear();
return true;
} }
return false; return false;
} }

View File

@ -3,14 +3,12 @@ package org.solovyev.android.calculator.keyboard;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.View; import android.view.View;
import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import butterknife.Bind;
import org.solovyev.android.calculator.Preferences; import butterknife.ButterKnife;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.buttons.CppSpecialButton; import org.solovyev.android.calculator.buttons.CppSpecialButton;
import org.solovyev.android.calculator.view.EditorLongClickEraser; import org.solovyev.android.calculator.view.EditorLongClickEraser;
@ -21,10 +19,6 @@ import org.solovyev.android.views.dragbutton.DragDirection;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.inject.Inject; 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.calculator.Preferences.Gui.vibrateOnKeypress;
import static org.solovyev.android.views.dragbutton.DragDirection.down; import static org.solovyev.android.views.dragbutton.DragDirection.down;
import static org.solovyev.android.views.dragbutton.DragDirection.up; import static org.solovyev.android.views.dragbutton.DragDirection.up;
@ -39,7 +33,7 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
DirectionDragImageButton leftButton; DirectionDragImageButton leftButton;
@Nullable @Nullable
@Bind(R.id.cpp_button_clear) @Bind(R.id.cpp_button_clear)
Button clearButton; DirectionDragButton clearButton;
@Nullable @Nullable
@Bind(R.id.cpp_button_erase) @Bind(R.id.cpp_button_erase)
ImageButton eraseButton; ImageButton eraseButton;
@ -67,30 +61,14 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
prepareButton(eraseButton, IMAGE_SCALE_ERASE); prepareButton(eraseButton, IMAGE_SCALE_ERASE);
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator); longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator);
} }
toggleEqualsButton(); if(isSimpleLayout()) {
} hideText(equalsButton, down);
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);
} }
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
super.onSharedPreferenceChanged(preferences, key); super.onSharedPreferenceChanged(preferences, key);
if (equalsButton != null && showEqualsButton.isSameKey(key)) {
toggleEqualsButton();
}
if (longClickEraser != null && vibrateOnKeypress.isSameKey(key)) { if (longClickEraser != null && vibrateOnKeypress.isSameKey(key)) {
longClickEraser.setVibrateOnKeypress(vibrateOnKeypress.getPreference(preferences)); longClickEraser.setVibrateOnKeypress(vibrateOnKeypress.getPreference(preferences));
} }
@ -105,6 +83,12 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
case R.id.cpp_button_left: case R.id.cpp_button_left:
editor.setCursorOnStart(); editor.setCursorOnStart();
return true; return true;
case R.id.cpp_button_clear:
if(direction == up) {
memory.get().clear();
return true;
}
return false;
case R.id.cpp_button_equals: case R.id.cpp_button_equals:
if (direction == down) { if (direction == down) {
launcher.plotDisplayedExpression(); launcher.plotDisplayedExpression();

View File

@ -156,6 +156,10 @@ public class Memory {
value = numeric(newValue); value = numeric(newValue);
handler.removeCallbacks(writeTask); handler.removeCallbacks(writeTask);
handler.postDelayed(writeTask, 3000L); handler.postDelayed(writeTask, 3000L);
show();
}
public void show() {
notifier.showMessage(getValue()); notifier.showMessage(getValue());
} }

View File

@ -16,17 +16,33 @@ import static android.graphics.Matrix.MSCALE_Y;
public class Adjuster { public class Adjuster {
private static final float[] MATRIX = new float[9]; private static final float[] MATRIX = new float[9];
@NonNull
public static void adjustText(@NonNull final TextView view, final float percentage) { private static Helper<TextView> textViewHelper = new Helper<TextView>() {
adjustText(view, percentage, 0); @Override
public void apply(@NonNull TextView view, float textSize) {
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
} }
public static void adjustText(@NonNull final TextView view, final float percentage, final float minTextSizePxs) { @Override
public float getTextSize(@NonNull TextView view) {
return view.getTextSize();
}
};
public static void adjustText(@NonNull final TextView view, final float percentage) {
adjustText(view, textViewHelper, percentage, 0);
}
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); ViewTreeObserver treeObserver = getTreeObserver(view);
if (treeObserver == null) { if (treeObserver == null) {
return; return;
} }
treeObserver.addOnPreDrawListener(new TextViewAdjuster(view, percentage, minTextSizePxs)); treeObserver.addOnPreDrawListener(new TextViewAdjuster<V>(view, helper, percentage, minTextSizePxs));
} }
@Nullable @Nullable
@ -57,6 +73,12 @@ public class Adjuster {
treeObserver.addOnPreDrawListener(new MaxWidthAdjuster(view, maxWidth)); 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 { private static abstract class BaseViewAdjuster<V extends View> implements ViewTreeObserver.OnPreDrawListener {
@NonNull @NonNull
protected final V view; protected final V view;
@ -82,24 +104,26 @@ public class Adjuster {
protected abstract boolean adjust(int width, int height); 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 percentage;
private final float minTextSizePxs; 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); super(view);
this.helper = helper;
this.percentage = percentage; this.percentage = percentage;
this.minTextSizePxs = minTextSizePxs; this.minTextSizePxs = minTextSizePxs;
} }
@Override @Override
protected boolean adjust(int width, int height) { 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)); final float newTextSize = Math.max(minTextSizePxs, Math.round(height * percentage));
if (oldTextSize == newTextSize) { if (oldTextSize == newTextSize) {
return true; return true;
} }
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, newTextSize); helper.apply(view, newTextSize);
return false; return false;
} }
} }

View File

@ -41,20 +41,16 @@ public class DirectionDragButton extends DragButton implements DirectionDragView
} }
@Override @Override
public boolean onPreDraw() { protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final TextPaint paint = getPaint(); final TextPaint paint = getPaint();
if (baseTextPaint.getTextSize() != paint.getTextSize() || if (baseTextPaint.getTextSize() != paint.getTextSize() ||
baseTextPaint.getTypeface() != paint.getTypeface() ||
baseTextPaint.getColor() != paint.getColor() || baseTextPaint.getColor() != paint.getColor() ||
baseTextPaint.getAlpha() != paint.getAlpha()) { baseTextPaint.getAlpha() != paint.getAlpha()) {
baseTextPaint.set(paint); baseTextPaint.set(paint);
textView.setBaseTextPaint(paint); textView.setBaseTextPaint(paint);
} }
return super.onPreDraw();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
textView.draw(canvas); textView.draw(canvas);
} }

View File

@ -54,10 +54,19 @@ public class DirectionDragImageButton extends DragImageButton implements Directi
public void setTypeface(@Nonnull Typeface newTypeface) { public void setTypeface(@Nonnull Typeface newTypeface) {
final Typeface oldTypeface = baseTextPaint.getTypeface(); final Typeface oldTypeface = baseTextPaint.getTypeface();
if(oldTypeface == newTypeface) { if (oldTypeface == newTypeface) {
return; return;
} }
baseTextPaint.setTypeface(newTypeface); baseTextPaint.setTypeface(newTypeface);
textView.setBaseTextPaint(baseTextPaint); textView.setBaseTextPaint(baseTextPaint);
} }
public void setTextSize(float textSizePxs) {
baseTextPaint.setTextSize(textSizePxs);
textView.setBaseTextPaint(baseTextPaint);
}
public float getTextSize() {
return baseTextPaint.getTextSize();
}
} }

View File

@ -127,7 +127,10 @@ public class DirectionTextView {
paint.set(base); paint.set(base);
paint.setColor(color); paint.setColor(color);
paint.setAlpha(intAlpha()); 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 // pre-calculate fixed height
paint.setTextSize(Math.max(base.getTextSize() * DEF_SCALE, minTextSize)); paint.setTextSize(Math.max(base.getTextSize() * DEF_SCALE, minTextSize));
@ -176,7 +179,7 @@ public class DirectionTextView {
} }
public void draw(@NonNull Canvas canvas) { public void draw(@NonNull Canvas canvas) {
if (!visible || TextUtils.isEmpty(value)) { if (!hasValue()) {
return; return;
} }
if (position.x < 0 || position.y < 0) { if (position.x < 0 || position.y < 0) {
@ -222,6 +225,10 @@ public class DirectionTextView {
return visible ? value : ""; return visible ? value : "";
} }
public boolean hasValue() {
return visible && !TextUtils.isEmpty(value);
}
public void setValue(@NonNull String value) { public void setValue(@NonNull String value) {
if (TextUtils.equals(this.value, value)) { if (TextUtils.equals(this.value, value)) {
return; return;

View File

@ -3,8 +3,9 @@ package org.solovyev.android.views.dragbutton;
import android.graphics.PointF; import android.graphics.PointF;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.View;
final class Drag { public final class Drag {
private Drag() { private Drag() {
} }
@ -19,6 +20,13 @@ final class Drag {
return new PointF(p1.x - p2.x, p1.y - p2.y); 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 @NonNull
public static PointF sum(@NonNull PointF p1, @NonNull PointF p2) { public static PointF sum(@NonNull PointF p1, @NonNull PointF p2) {
return new PointF(p1.x + p2.x, p1.y + p2.y); return new PointF(p1.x + p2.x, p1.y + p2.y);

View File

@ -38,13 +38,7 @@
a:orientation="horizontal"> a:orientation="horizontal">
<include <include
layout="@layout/cpp_app_button_left" layout="@layout/cpp_app_button_equals_no_bg"
a:layout_width="0dp"
a:layout_height="match_parent"
a:layout_weight="1" />
<include
layout="@layout/cpp_app_button_erase"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="match_parent" a:layout_height="match_parent"
a:layout_weight="1" /> a:layout_weight="1" />
@ -53,17 +47,17 @@
a:id="@+id/display" a:id="@+id/display"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="match_parent" a:layout_height="match_parent"
a:layout_weight="4" a:layout_weight="5"
a:orientation="horizontal" /> a:orientation="horizontal" />
<include <include
layout="@layout/cpp_app_button_clear" layout="@layout/cpp_app_button_erase"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="match_parent" a:layout_height="match_parent"
a:layout_weight="1" /> a:layout_weight="1" />
<include <include
layout="@layout/cpp_app_button_right" layout="@layout/cpp_app_button_clear"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="match_parent" a:layout_height="match_parent"
a:layout_weight="1" /> a:layout_weight="1" />

View File

@ -34,10 +34,10 @@
a:baselineAligned="false" a:baselineAligned="false"
a:orientation="horizontal"> a:orientation="horizontal">
<include layout="@layout/cpp_app_button_vars" />
<include layout="@layout/cpp_app_button_copy" /> <include layout="@layout/cpp_app_button_copy" />
<include layout="@layout/cpp_app_button_paste" />
<include layout="@layout/cpp_app_button_7" /> <include layout="@layout/cpp_app_button_7" />
<include layout="@layout/cpp_app_button_8" /> <include layout="@layout/cpp_app_button_8" />
@ -48,7 +48,7 @@
<include layout="@layout/cpp_app_button_division" /> <include layout="@layout/cpp_app_button_division" />
<include layout="@layout/cpp_app_button_equals" /> <include layout="@layout/cpp_app_button_memory" />
</LinearLayout> </LinearLayout>
@ -59,9 +59,9 @@
a:baselineAligned="false" a:baselineAligned="false"
a:orientation="horizontal"> a:orientation="horizontal">
<include layout="@layout/cpp_app_button_functions" /> <include layout="@layout/cpp_app_button_vars" />
<include layout="@layout/cpp_app_button_paste" /> <include layout="@layout/cpp_app_button_functions" />
<include layout="@layout/cpp_app_button_4" /> <include layout="@layout/cpp_app_button_4" />
@ -84,9 +84,9 @@
a:baselineAligned="false" a:baselineAligned="false"
a:orientation="horizontal"> a:orientation="horizontal">
<include layout="@layout/cpp_app_button_operators" /> <include layout="@layout/cpp_app_button_left" />
<include layout="@layout/cpp_app_button_donate" /> <include layout="@layout/cpp_app_button_right" />
<include layout="@layout/cpp_app_button_1" /> <include layout="@layout/cpp_app_button_1" />

View File

@ -29,5 +29,6 @@
a:id="@id/cpp_button_6" a:id="@id/cpp_button_6"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="6" a:text="6"
c:directionTextUp="√"
c:directionTextLeft="F" c:directionTextLeft="F"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,5 @@
a:id="@id/cpp_button_9" a:id="@id/cpp_button_9"
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="9" a:text="9"
c:directionTextDown="e"
c:directionTextLeft="0x:" c:directionTextLeft="0x:"
c:directionTextUp="π"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -22,9 +22,12 @@
~ Site: http://se.solovyev.org ~ Site: http://se.solovyev.org
--> -->
<Button <org.solovyev.android.views.dragbutton.DirectionDragButton
a:id="@id/cpp_button_clear" a:id="@id/cpp_button_clear"
style="?attr/cpp_button_style_control_image" style="?attr/cpp_button_style_control_image"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:a="http://schemas.android.com/apk/res/android" xmlns:a="http://schemas.android.com/apk/res/android"
a:background="@color/grey_850"
a:text="@string/c_clear" a:text="@string/c_clear"
app:directionTextUp="MC"
a:textStyle="bold"/> a:textStyle="bold"/>

View File

@ -29,6 +29,4 @@
a:id="@id/cpp_button_division" a:id="@id/cpp_button_division"
style="?attr/cpp_button_style_operation" style="?attr/cpp_button_style_operation"
a:text="/" a:text="/"
c:directionTextDown="√"
c:directionTextUp="%"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,8 +29,7 @@
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:background="@drawable/button_no_bg" a:background="@drawable/button_no_bg"
a:text="=" a:text="="
a:textColor="?android:attr/textColorPrimary" a:textColor="?attr/cpp_text_color"
c:directionTextColor="?android:attr/textColorPrimary"
c:directionTextDown="@string/cpp_plot_button_text" c:directionTextDown="@string/cpp_plot_button_text"
c:directionTextUp="≡" c:directionTextUp="≡"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -25,5 +25,6 @@
<ImageButton <ImageButton
xmlns:a="http://schemas.android.com/apk/res/android" xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@id/cpp_button_erase" a:id="@id/cpp_button_erase"
a:background="@color/cpp_material_light_darker"
style="?attr/cpp_button_style_control_image" style="?attr/cpp_button_style_control_image"
a:src="@drawable/ic_backspace_white_48dp" /> a:src="@drawable/ic_backspace_white_48dp" />

View File

@ -31,4 +31,5 @@
a:text="@string/cpp_kb_functions" a:text="@string/cpp_kb_functions"
a:textStyle="italic" a:textStyle="italic"
c:directionTextUp="+ƒ" c:directionTextUp="+ƒ"
c:directionTextDown="+π"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -27,5 +27,5 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
a:text="@string/cpp_kb_memory_recall" a:text="@string/cpp_kb_memory_recall"
app:directionTextDown="@string/cpp_kb_memory_minus" app:directionTextDown="@string/cpp_kb_memory_minus"
app:directionTextLeft="@string/cpp_kb_memory_clear" app:directionTextUp="@string/cpp_kb_memory_plus"
app:directionTextUp="@string/cpp_kb_memory_plus" /> a:textStyle="bold"/>

View File

@ -28,5 +28,4 @@
a:id="@id/cpp_button_subtraction" a:id="@id/cpp_button_subtraction"
style="?attr/cpp_button_style_operation" style="?attr/cpp_button_style_operation"
a:text="" a:text=""
c:directionTextDown="@string/cpp_kb_operators"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -29,7 +29,4 @@
a:id="@id/cpp_button_multiplication" a:id="@id/cpp_button_multiplication"
style="?attr/cpp_button_style_operation" style="?attr/cpp_button_style_operation"
a:text="×" a:text="×"
c:directionTextDown="^2"
c:directionTextLeft="Π"
c:directionTextUp="^"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<org.solovyev.android.views.dragbutton.DirectionDragButton
a:id="@id/cpp_button_percent"
style="?attr/cpp_button_style_digit"
xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
a:text="%"
app:directionTextDown="^2"
app:directionTextUp="^"
tools:ignore="HardcodedText" />

View File

@ -30,6 +30,6 @@
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="( )" a:text="( )"
c:directionTextDown=")" c:directionTextDown=")"
c:directionTextLeft="(.)" c:directionTextLeft="()"
c:directionTextUp="(" c:directionTextUp="("
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -30,5 +30,6 @@
style="?attr/cpp_button_style_control" style="?attr/cpp_button_style_control"
a:text="@string/cpp_kb_variables" a:text="@string/cpp_kb_variables"
a:textStyle="italic" a:textStyle="italic"
c:directionTextUp="+π" c:directionTextDown="e"
c:directionTextUp="π"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -27,6 +27,23 @@
a:layout_height="match_parent" a:layout_height="match_parent"
a:orientation="vertical"> a:orientation="vertical">
<LinearLayout
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1">
<include layout="@layout/cpp_app_button_vars" />
<include layout="@layout/cpp_app_button_functions" />
<include layout="@layout/cpp_app_button_percent" />
<include layout="@layout/cpp_app_button_erase" />
<include layout="@layout/cpp_app_button_clear" />
</LinearLayout>
<LinearLayout <LinearLayout
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="0dp" a:layout_height="0dp"
@ -38,9 +55,10 @@
<include layout="@layout/cpp_app_button_9" /> <include layout="@layout/cpp_app_button_9" />
<include layout="@layout/cpp_app_button_multiplication" /> <include layout="@layout/cpp_app_button_division" />
<include layout="@layout/cpp_app_button_memory" />
<include layout="@layout/cpp_app_button_clear" />
</LinearLayout> </LinearLayout>
@ -55,9 +73,9 @@
<include layout="@layout/cpp_app_button_6" /> <include layout="@layout/cpp_app_button_6" />
<include layout="@layout/cpp_app_button_division" /> <include layout="@layout/cpp_app_button_multiplication" />
<include layout="@layout/cpp_app_button_erase" /> <include layout="@layout/cpp_app_button_copy" />
</LinearLayout> </LinearLayout>
@ -72,23 +90,6 @@
<include layout="@layout/cpp_app_button_3" /> <include layout="@layout/cpp_app_button_3" />
<include layout="@layout/cpp_app_button_plus" />
<include layout="@layout/cpp_app_button_copy" />
</LinearLayout>
<LinearLayout
a:layout_width="match_parent"
a:layout_height="0dp"
a:layout_weight="1">
<include layout="@layout/cpp_app_button_round_brackets" />
<include layout="@layout/cpp_app_button_0" />
<include layout="@layout/cpp_app_button_dot" />
<include layout="@layout/cpp_app_button_minus" /> <include layout="@layout/cpp_app_button_minus" />
<include layout="@layout/cpp_app_button_paste" /> <include layout="@layout/cpp_app_button_paste" />
@ -101,13 +102,13 @@
a:layout_height="0dp" a:layout_height="0dp"
a:layout_weight="1"> a:layout_weight="1">
<include layout="@layout/cpp_app_button_left" /> <include layout="@layout/cpp_app_button_round_brackets" />
<include layout="@layout/cpp_app_button_right" /> <include layout="@layout/cpp_app_button_0" />
<include layout="@layout/cpp_app_button_vars" /> <include layout="@layout/cpp_app_button_dot" />
<include layout="@layout/cpp_app_button_functions" /> <include layout="@layout/cpp_app_button_plus" />
<include layout="@layout/cpp_app_button_history" /> <include layout="@layout/cpp_app_button_history" />

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="cpp_direction_text_scale" format="float" type="dimen">0.45</item>
<item name="cpp_direction_text_scale_units" format="float" type="dimen">0.45</item>
</resources>

View File

@ -60,5 +60,6 @@
<color name="grey_900">#212121</color> <color name="grey_900">#212121</color>
<color name="grey_950">#101010</color> <color name="grey_950">#101010</color>
<color name="grey_800">#424242</color> <color name="grey_800">#424242</color>
<color name="grey_850">#313131</color>
</resources> </resources>

View File

@ -10,8 +10,8 @@
<dimen name="cpp_button_padding">1px</dimen> <dimen name="cpp_button_padding">1px</dimen>
<dimen name="cpp_direction_text_default_padding">2dp</dimen> <dimen name="cpp_direction_text_default_padding">2dp</dimen>
<dimen name="cpp_direction_text_min_size">9dp</dimen> <dimen name="cpp_direction_text_min_size">9dp</dimen>
<item name="cpp_direction_text_scale" format="float" type="dimen">0.45</item> <item name="cpp_direction_text_scale" format="float" type="dimen">0.35</item>
<item name="cpp_direction_text_scale_units" format="float" type="dimen">0.35</item> <item name="cpp_direction_text_scale_units" format="float" type="dimen">0.3</item>
<dimen name="cpp_button_corner">1dp</dimen> <dimen name="cpp_button_corner">1dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding">4dp</dimen> <dimen name="cpp_keyboard_button_direction_text_padding">4dp</dimen>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="cpp_kb_variables" translatable="false">π</string> <string name="cpp_kb_variables" translatable="false">π</string>
<string name="cpp_kb_functions" translatable="false">ƒ</string> <string name="cpp_kb_functions" translatable="false">ƒ</string>
<string name="cpp_kb_operators" translatable="false"></string> <string name="cpp_kb_operators" translatable="false"></string>
<string name="cpp_kb_undo" translatable="false"></string> <string name="cpp_kb_undo" translatable="false"></string>

View File

@ -64,13 +64,6 @@
a:key="autoOrientation" a:key="autoOrientation"
a:title="@string/cpp_prefs_auto_rotate_screen" /> a:title="@string/cpp_prefs_auto_rotate_screen" />
<android.preference.CheckBoxPreference
a:defaultValue="true"
a:key="showEqualsButton"
a:summary="@string/c_show_equals_button_summary"
a:title="@string/c_show_equals_button_title" />
<android.preference.CheckBoxPreference <android.preference.CheckBoxPreference
a:key="gui.keepScreenOn" a:key="gui.keepScreenOn"
a:title="@string/cpp_prefs_keep_screen_on" /> a:title="@string/cpp_prefs_keep_screen_on" />