Use glyphs for keyboard buttons

This commit is contained in:
serso
2016-05-11 14:25:30 +02:00
parent ba991942b1
commit ed194941c1
11 changed files with 66 additions and 141 deletions

View File

@@ -24,29 +24,30 @@ package org.solovyev.android.calculator.buttons;
import org.solovyev.android.Check;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
// see values/text_glyphs.xml for glyph constants
public enum CppSpecialButton {
history("history"),
history("history", '\ue005'),
history_undo("", '\ue007'),
history_redo("", '\ue008'),
cursor_right(""),
cursor_right("", '\ue003'),
cursor_to_end(">>"),
cursor_left(""),
cursor_left("", '\ue002'),
cursor_to_start("<<"),
settings("settings"),
settings_widget("settings_widget"),
like("like"),
like("like", '\ue006'),
memory("memory"),
memory_plus("M+"),
memory_minus("M-"),
memory_clear("MC"),
erase("erase"),
erase("erase", '\ue004'),
paste("paste", '\uE000'),
copy("copy", '\uE001'),
brackets_wrap("(…)"),

View File

@@ -12,21 +12,38 @@ import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import dagger.Lazy;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.ActivityLauncher;
import org.solovyev.android.calculator.App;
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.buttons.CppButton;
import org.solovyev.android.calculator.memory.Memory;
import org.solovyev.android.views.Adjuster;
import org.solovyev.android.views.dragbutton.*;
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.Drag;
import org.solovyev.android.views.dragbutton.DragDirection;
import org.solovyev.android.views.dragbutton.DragEvent;
import org.solovyev.android.views.dragbutton.DragView;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import dagger.Lazy;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.HapticFeedbackConstants.*;
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 org.solovyev.android.calculator.App.cast;
import static org.solovyev.android.calculator.Preferences.Gui.Mode.simple;
@@ -111,18 +128,6 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
textSize = calculateTextSize(activity);
}
protected final void prepareButton(@Nullable ImageView button) {
prepareButton(button, IMAGE_SCALE);
}
protected final void prepareButton(@Nullable ImageView button, float scale) {
if (button == null) {
return;
}
prepareButton((View) button);
Adjuster.adjustImage(button, scale);
}
protected final void prepareButton(@Nullable View button) {
if (button == null) {
return;
@@ -132,18 +137,6 @@ public abstract class BaseKeyboardUi implements SharedPreferences.OnSharedPrefer
button.setOnClickListener(this);
}
protected final void prepareButton(@Nullable DirectionDragImageButton button) {
if (button == null) {
return;
}
dragButtons.add(button);
button.setVibrateOnDrag(keyboard.isVibrateOnKeypress());
prepareButton((ImageView) button);
button.setOnDragListener(listener);
button.setTextSize(textSize);
Adjuster.adjustText(button, AdjusterHelper.instance, textScale, 0);
}
protected final void prepareButton(@Nullable DirectionDragButton button) {
if (button == null) {
return;

View File

@@ -5,22 +5,24 @@ import android.app.Application;
import android.content.SharedPreferences;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageButton;
import butterknife.Bind;
import butterknife.ButterKnife;
import jscl.NumeralBase;
import org.solovyev.android.calculator.Display;
import org.solovyev.android.calculator.Engine;
import org.solovyev.android.calculator.R;
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DirectionDragImageButton;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
import jscl.NumeralBase;
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.*;
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 {
@@ -58,7 +60,7 @@ public class KeyboardUi extends BaseKeyboardUi {
@Bind(R.id.cpp_button_functions)
DirectionDragButton functionsButton;
@Bind(R.id.cpp_button_history)
DirectionDragImageButton historyButton;
DirectionDragButton historyButton;
@Bind(R.id.cpp_button_multiplication)
DirectionDragButton multiplicationButton;
@Bind(R.id.cpp_button_plus)
@@ -72,14 +74,8 @@ public class KeyboardUi extends BaseKeyboardUi {
@Bind(R.id.cpp_button_round_brackets)
DirectionDragButton bracketsButton;
@Nullable
@Bind(R.id.cpp_button_copy)
DirectionDragImageButton copyButton;
@Nullable
@Bind(R.id.cpp_button_paste)
DirectionDragImageButton pasteButton;
@Nullable
@Bind(R.id.cpp_button_like)
ImageButton likeButton;
DirectionDragButton likeButton;
@Nullable
@Bind(R.id.cpp_button_percent)
DirectionDragButton percentButton;
@@ -132,12 +128,6 @@ public class KeyboardUi extends BaseKeyboardUi {
prepareButton(button8);
prepareButton(button9);
if (copyButton != null) {
prepareButton(copyButton);
}
if (pasteButton != null) {
prepareButton(pasteButton);
}
prepareButton(likeButton);
prepareButton(memoryButton);

View File

@@ -6,17 +6,17 @@ import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageButton;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.view.EditorLongClickEraser;
import org.solovyev.android.views.dragbutton.DirectionDragButton;
import org.solovyev.android.views.dragbutton.DirectionDragImageButton;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
import static org.solovyev.android.calculator.Preferences.Gui.vibrateOnKeypress;
import static org.solovyev.android.views.dragbutton.DragDirection.down;
@@ -24,16 +24,16 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
@Nullable
@Bind(R.id.cpp_button_right)
DirectionDragImageButton rightButton;
DirectionDragButton rightButton;
@Nullable
@Bind(R.id.cpp_button_left)
DirectionDragImageButton leftButton;
DirectionDragButton leftButton;
@Nullable
@Bind(R.id.cpp_button_clear)
DirectionDragButton clearButton;
@Nullable
@Bind(R.id.cpp_button_erase)
ImageButton eraseButton;
DirectionDragButton eraseButton;
@Nullable
@Bind(R.id.cpp_button_equals)
DirectionDragButton equalsButton;
@@ -54,11 +54,10 @@ public class PartialKeyboardUi extends BaseKeyboardUi {
prepareButton(equalsButton);
prepareButton(clearButton);
if (eraseButton != null) {
// backspace button is too big, scale it more
prepareButton(eraseButton, IMAGE_SCALE_ERASE);
prepareButton(eraseButton);
longClickEraser = EditorLongClickEraser.attachTo(eraseButton, keyboard.isVibrateOnKeypress(), editor, calculator);
}
if(isSimpleMode()) {
if (isSimpleMode()) {
hideText(equalsButton, down);
}
}