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);
}
}

View File

@ -1,29 +0,0 @@
<?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.DirectionDragImageButton
android:id="@id/cpp_button_copy"
style="?attr/cpp_button_style_control"
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_content_copy_white_48dp" />

View File

@ -22,8 +22,8 @@
~ Site: http://se.solovyev.org
-->
<ImageButton
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@id/cpp_button_erase"
<org.solovyev.android.views.dragbutton.DirectionDragButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/cpp_button_erase"
style="?attr/cpp_button_style_operation_highlighted"
a:src="@drawable/ic_backspace_white_48dp" />
android:text="@string/cpp_glyph_backspace"/>

View File

@ -21,12 +21,12 @@
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<org.solovyev.android.views.dragbutton.DirectionDragImageButton
<org.solovyev.android.views.dragbutton.DirectionDragButton
xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
a:id="@id/cpp_button_history"
style="?attr/cpp_button_style_control"
a:src="@drawable/ic_history_white_48dp"
a:text="@string/cpp_glyph_history"
app:directionTextScale="0.5"
app:directionTextDown="@string/cpp_glyph_redo"
app:directionTextUp="@string/cpp_glyph_undo" />

View File

@ -22,12 +22,12 @@
~ Site: http://se.solovyev.org
-->
<org.solovyev.android.views.dragbutton.DirectionDragImageButton a:id="@id/cpp_button_left"
<org.solovyev.android.views.dragbutton.DirectionDragButton a:id="@id/cpp_button_left"
style="?attr/cpp_button_style_control"
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"
a:src="@drawable/ic_keyboard_arrow_left_white_48dp"
a:text="@string/cpp_glyph_left"
c:directionTextUp="&lt;&lt;"
c:directionTextDown="@string/cpp_glyph_copy"
tools:ignore="HardcodedText" />

View File

@ -22,8 +22,8 @@
~ Site: http://se.solovyev.org
-->
<org.solovyev.android.views.dragbutton.DirectionDragImageButton
<org.solovyev.android.views.dragbutton.DirectionDragButton
android:id="@id/cpp_button_like"
style="?attr/cpp_button_style_control"
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_favorite_border_white_48dp" />
android:text="@string/cpp_glyph_heart"/>

View File

@ -1,29 +0,0 @@
<?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.DirectionDragImageButton
android:id="@id/cpp_button_paste"
style="?attr/cpp_button_style_control"
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_content_paste_white_48dp" />

View File

@ -22,12 +22,12 @@
~ Site: http://se.solovyev.org
-->
<org.solovyev.android.views.dragbutton.DirectionDragImageButton a:id="@id/cpp_button_right"
<org.solovyev.android.views.dragbutton.DirectionDragButton android:id="@id/cpp_button_right"
style="?attr/cpp_button_style_control"
xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:c="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
a:src="@drawable/ic_keyboard_arrow_right_white_48dp"
c:directionTextUp="&gt;&gt;"
c:directionTextDown="@string/cpp_glyph_paste"
android:text="@string/cpp_glyph_right"
app:directionTextUp="&gt;&gt;"
app:directionTextDown="@string/cpp_glyph_paste"
tools:ignore="HardcodedText" />