Skip to content

Commit

Permalink
add undo and redo keys to toolbar, fixes #149
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Dec 20, 2023
1 parent 228f859 commit 9a62d85
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ public interface Listener {

public static boolean DEBUG_SUGGESTIONS;
private static final float DEBUG_INFO_TEXT_SIZE_IN_DIP = 6.5f;
private static final String VOICE_KEY_TAG = "voice_key";
private static final String CLIPBOARD_KEY_TAG = "clipboard_key";
private static final String SETTINGS_KEY_TAG = "settings_key";
private static final String SELECT_ALL_KEY_TAG = "select_all_key";
private static final String COPY_KEY_TAG = "copy_key";
private static final String ONE_HANDED_KEY_TAG = "one_handed_key";
private static final String LEFT_KEY_TAG = "left_key";
private static final String RIGHT_KEY_TAG = "right_key";
private static final String UP_KEY_TAG = "up_key";
private static final String DOWN_KEY_TAG = "down_key";
private static final String UNDO_TAG = "undo";
private static final String REDO_TAG = "redo";
private static final String TAG_VOICE = "voice_key";
private static final String TAG_CLIPBOARD = "clipboard_key";
private static final String TAG_SETTINGS = "settings_key";
private static final String TAG_SELECT_ALL = "select_all_key";
private static final String TAG_COPY = "copy_key";
private static final String TAG_ONE_HANDED = "one_handed_key";
private static final String TAG_LEFT = "left_key";
private static final String TAG_RIGHT = "right_key";
private static final String TAG_UP = "up_key";
private static final String TAG_DOWN = "down_key";
private static final String TAG_REDO = "undo";
private static final String TAG_UNDO = "redo";
// tags of keys to be added to toolbar, in order (all tags must be considered in getStyleableIconId)
private static final String[] toolbarKeyTags = new String[] {VOICE_KEY_TAG, CLIPBOARD_KEY_TAG,
SELECT_ALL_KEY_TAG, COPY_KEY_TAG, ONE_HANDED_KEY_TAG, SETTINGS_KEY_TAG, LEFT_KEY_TAG,
RIGHT_KEY_TAG, UP_KEY_TAG, DOWN_KEY_TAG};
private static final String[] toolbarKeyTags = new String[] {TAG_VOICE, TAG_CLIPBOARD,
TAG_SELECT_ALL, TAG_COPY, TAG_UNDO, TAG_REDO, TAG_ONE_HANDED, TAG_SETTINGS,
TAG_LEFT, TAG_RIGHT, TAG_UP, TAG_DOWN};

private final ViewGroup mSuggestionsStrip;
private final ImageButton mToolbarKey;
Expand Down Expand Up @@ -208,7 +208,7 @@ public SuggestionStripView(final Context context, final AttributeSet attrs,
button.setLayoutParams(toolbarKeyLayoutParams);
button.setTag(tag);
final Drawable icon = keyboardAttr.getDrawable(getStyleableIconId(tag));
if (tag.equals(LEFT_KEY_TAG) || tag.equals(RIGHT_KEY_TAG) || tag.equals(UP_KEY_TAG) || tag.equals(DOWN_KEY_TAG)) {
if (tag.equals(TAG_LEFT) || tag.equals(TAG_RIGHT) || tag.equals(TAG_UP) || tag.equals(TAG_DOWN)) {
// arrows look a little awkward when not scaled
button.setScaleX(1.2f);
button.setScaleY(1.2f);
Expand Down Expand Up @@ -256,8 +256,8 @@ public void updateVisibility(final boolean shouldBeVisible, final boolean isFull
final int visibility = shouldBeVisible ? VISIBLE : (isFullscreenMode ? GONE : INVISIBLE);
setVisibility(visibility);
final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
mToolbar.findViewWithTag(VOICE_KEY_TAG).setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE);
final View pinnedVoiceKey = mPinnedKeys.findViewWithTag(VOICE_KEY_TAG);
mToolbar.findViewWithTag(TAG_VOICE).setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE);
final View pinnedVoiceKey = mPinnedKeys.findViewWithTag(TAG_VOICE);
if (pinnedVoiceKey != null)
pinnedVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE);
mToolbarKey.setImageDrawable(currentSettingsValues.mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon);
Expand Down Expand Up @@ -362,7 +362,7 @@ public boolean onLongClick(final View view) {
}

private void onLongClickToolKey(final View view) {
if (CLIPBOARD_KEY_TAG.equals(view.getTag()) && view.getParent() == mPinnedKeys) {
if (TAG_CLIPBOARD.equals(view.getTag()) && view.getParent() == mPinnedKeys) {
onLongClickClipboardKey(); // long click pinned clipboard key
} else if (view.getParent() == mToolbar) {
final String tag = (String) view.getTag();
Expand Down Expand Up @@ -626,42 +626,42 @@ public void onClick(final View view) {
final Object tag = view.getTag();
if (tag instanceof String) {
switch ((String) tag) {
case VOICE_KEY_TAG:
case TAG_VOICE:
mListener.onCodeInput(Constants.CODE_SHORTCUT, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case CLIPBOARD_KEY_TAG:
case TAG_CLIPBOARD:
mListener.onCodeInput(Constants.CODE_CLIPBOARD, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case SELECT_ALL_KEY_TAG:
case TAG_SELECT_ALL:
mListener.onCodeInput(Constants.CODE_SELECT_ALL, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case COPY_KEY_TAG:
case TAG_COPY:
mListener.onCodeInput(Constants.CODE_COPY, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case ONE_HANDED_KEY_TAG:
case TAG_ONE_HANDED:
final boolean oneHandedEnabled = Settings.getInstance().getCurrent().mOneHandedModeEnabled;
mListener.onCodeInput(oneHandedEnabled ? Constants.CODE_STOP_ONE_HANDED_MODE : Constants.CODE_START_ONE_HANDED_MODE,
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case SETTINGS_KEY_TAG:
case TAG_SETTINGS:
mListener.onCodeInput(Constants.CODE_SETTINGS, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case LEFT_KEY_TAG:
case TAG_LEFT:
mListener.onCodeInput(Constants.CODE_LEFT, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case RIGHT_KEY_TAG:
case TAG_RIGHT:
mListener.onCodeInput(Constants.CODE_RIGHT, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case UP_KEY_TAG:
case TAG_UP:
mListener.onCodeInput(Constants.CODE_UP, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case DOWN_KEY_TAG:
case TAG_DOWN:
mListener.onCodeInput(Constants.CODE_DOWN, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case UNDO_TAG:
case TAG_UNDO:
mListener.onCodeInput(Constants.CODE_UNDO, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
case REDO_TAG:
case TAG_REDO:
mListener.onCodeInput(Constants.CODE_REDO, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
return;
}
Expand Down Expand Up @@ -733,16 +733,18 @@ private void setupKey(final ImageButton view, final Colors colors) {

private int getStyleableIconId(final String buttonTag) {
return switch (buttonTag) {
case VOICE_KEY_TAG -> R.styleable.Keyboard_iconShortcutKey;
case SETTINGS_KEY_TAG -> R.styleable.Keyboard_iconSettingsKey;
case CLIPBOARD_KEY_TAG -> R.styleable.Keyboard_iconClipboardNormalKey;
case SELECT_ALL_KEY_TAG -> R.styleable.Keyboard_iconSelectAll;
case COPY_KEY_TAG -> R.styleable.Keyboard_iconCopyKey;
case ONE_HANDED_KEY_TAG -> R.styleable.Keyboard_iconStartOneHandedMode;
case LEFT_KEY_TAG -> R.styleable.Keyboard_iconArrowLeft;
case RIGHT_KEY_TAG -> R.styleable.Keyboard_iconArrowRight;
case UP_KEY_TAG -> R.styleable.Keyboard_iconArrowUp;
case DOWN_KEY_TAG -> R.styleable.Keyboard_iconArrowDown;
case TAG_VOICE -> R.styleable.Keyboard_iconShortcutKey;
case TAG_SETTINGS -> R.styleable.Keyboard_iconSettingsKey;
case TAG_CLIPBOARD -> R.styleable.Keyboard_iconClipboardNormalKey;
case TAG_SELECT_ALL -> R.styleable.Keyboard_iconSelectAll;
case TAG_COPY -> R.styleable.Keyboard_iconCopyKey;
case TAG_ONE_HANDED -> R.styleable.Keyboard_iconStartOneHandedMode;
case TAG_LEFT -> R.styleable.Keyboard_iconArrowLeft;
case TAG_RIGHT -> R.styleable.Keyboard_iconArrowRight;
case TAG_UP -> R.styleable.Keyboard_iconArrowUp;
case TAG_DOWN -> R.styleable.Keyboard_iconArrowDown;
case TAG_UNDO -> R.styleable.Keyboard_iconUndo;
case TAG_REDO -> R.styleable.Keyboard_iconRedo;
default -> throw (new IllegalArgumentException("no styleable id for " + buttonTag));
};
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_redo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--
icon available in Android Studio
SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24"
android:viewportWidth="24" >
<path android:fillColor="#FFF"
android:pathData="M18.4,10.6C16.55,8.99 14.15,8 11.5,8c-4.65,0 -8.58,3.03 -9.96,7.22L3.9,16c1.05,-3.19 4.05,-5.5 7.6,-5.5 1.95,0 3.73,0.72 5.12,1.88L13,16h9V7l-3.6,3.6z"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_undo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!--
icon available in Android Studio
SPDX-License-Identifier: Apache-2.0
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportHeight="24"
android:viewportWidth="24" >
<path android:fillColor="#FFF"
android:pathData="M12.5,8c-2.65,0 -5.05,0.99 -6.9,2.6L2,7v9h9l-3.62,-3.62c1.39,-1.16 3.16,-1.88 5.12,-1.88 3.54,0 6.55,2.31 7.6,5.5l2.37,-0.78C21.08,11.03 17.15,8 12.5,8z"/>
</vector>
2 changes: 2 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@
<attr name="iconArrowUp" format="reference" />
<attr name="iconArrowDown" format="reference" />
<attr name="iconBin" format="reference" />
<attr name="iconUndo" format="reference" />
<attr name="iconRedo" format="reference" />
</declare-styleable>

<declare-styleable name="Keyboard_GridRows">
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/keyboard-icons-holo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
<item name="iconArrowUp">@drawable/ic_arrow_up</item>
<item name="iconArrowDown">@drawable/ic_arrow_down</item>
<item name="iconBin">@drawable/ic_delete</item>
<item name="iconUndo">@drawable/ic_undo</item>
<item name="iconRedo">@drawable/ic_redo</item>
</style>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/keyboard-icons-lxx-light.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@
<item name="iconArrowUp">@drawable/ic_arrow_up</item>
<item name="iconArrowDown">@drawable/ic_arrow_down</item>
<item name="iconBin">@drawable/ic_delete</item>
<item name="iconUndo">@drawable/ic_undo</item>
<item name="iconRedo">@drawable/ic_redo</item>
</style>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/keyboard-icons-rounded.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@
<item name="iconArrowUp">@drawable/ic_arrow_up_rounded</item>
<item name="iconArrowDown">@drawable/ic_arrow_down_rounded</item>
<item name="iconBin">@drawable/ic_delete_rounded</item>
<item name="iconUndo">@drawable/ic_undo</item>
<item name="iconRedo">@drawable/ic_redo</item>
</style>
</resources>

0 comments on commit 9a62d85

Please sign in to comment.