mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-28 11:49:56 +00:00
Display emoji descriptions in popups (#1542)
This commit is contained in:
parent
d5cd18ecaa
commit
e9e3bdac17
21 changed files with 374 additions and 99 deletions
|
@ -138,7 +138,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues,
|
||||
private void loadKeyboard(final EditorInfo editorInfo, final SettingsValues settingsValues,
|
||||
final int currentAutoCapsState, final int currentRecapitalizeState) {
|
||||
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
|
||||
mThemeContext, editorInfo);
|
||||
|
@ -527,6 +527,10 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
if (mCurrentInputView == null)
|
||||
return;
|
||||
mEmojiPalettesView.clearKeyboardCache();
|
||||
reloadMainKeyboard();
|
||||
}
|
||||
|
||||
public void reloadMainKeyboard() {
|
||||
loadKeyboard(mLatinIME.getCurrentInputEditorInfo(), Settings.getValues(),
|
||||
mLatinIME.getCurrentAutoCapsState(), mLatinIME.getCurrentRecapitalizeState());
|
||||
}
|
||||
|
|
|
@ -12,15 +12,15 @@ import android.graphics.Canvas;
|
|||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import helium314.keyboard.accessibility.AccessibilityUtils;
|
||||
import helium314.keyboard.accessibility.PopupKeysKeyboardAccessibilityDelegate;
|
||||
import helium314.keyboard.keyboard.emoji.OnKeyEventListener;
|
||||
import helium314.keyboard.keyboard.emoji.EmojiViewCallback;
|
||||
import helium314.keyboard.keyboard.internal.KeyDrawParams;
|
||||
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode;
|
||||
import helium314.keyboard.latin.R;
|
||||
|
@ -39,7 +39,7 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane
|
|||
protected final KeyDetector mKeyDetector;
|
||||
private Controller mController = EMPTY_CONTROLLER;
|
||||
protected KeyboardActionListener mListener;
|
||||
protected OnKeyEventListener mKeyEventListener;
|
||||
protected EmojiViewCallback mEmojiViewCallback;
|
||||
private int mOriginX;
|
||||
private int mOriginY;
|
||||
private Key mCurrentKey;
|
||||
|
@ -122,7 +122,7 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane
|
|||
public void showPopupKeysPanel(final View parentView, final Controller controller,
|
||||
final int pointX, final int pointY, final KeyboardActionListener listener) {
|
||||
mListener = listener;
|
||||
mKeyEventListener = null;
|
||||
mEmojiViewCallback = null;
|
||||
showPopupKeysPanelInternal(parentView, controller, pointX, pointY);
|
||||
}
|
||||
|
||||
|
@ -131,9 +131,9 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane
|
|||
*/
|
||||
@Override
|
||||
public void showPopupKeysPanel(final View parentView, final Controller controller,
|
||||
final int pointX, final int pointY, final OnKeyEventListener listener) {
|
||||
final int pointX, final int pointY, final EmojiViewCallback emojiViewCallback) {
|
||||
mListener = null;
|
||||
mKeyEventListener = listener;
|
||||
mEmojiViewCallback = emojiViewCallback;
|
||||
showPopupKeysPanelInternal(parentView, controller, pointX, pointY);
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,9 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane
|
|||
|
||||
mOriginX = x + container.getPaddingLeft();
|
||||
mOriginY = y + container.getPaddingTop();
|
||||
var center = panelX + getMeasuredWidth() / 2;
|
||||
// This is needed for cases where there's also a long text popup above this keyboard
|
||||
controller.setLayoutGravity(center < pointX? Gravity.RIGHT : center > pointX? Gravity.LEFT : Gravity.CENTER_HORIZONTAL);
|
||||
controller.onShowPopupKeysPanel(this);
|
||||
final PopupKeysKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
|
||||
if (accessibilityDelegate != null
|
||||
|
@ -222,8 +225,8 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane
|
|||
false /* isKeyRepeat */);
|
||||
}
|
||||
}
|
||||
} else if (mKeyEventListener != null) {
|
||||
mKeyEventListener.onReleaseKey(key);
|
||||
} else if (mEmojiViewCallback != null) {
|
||||
mEmojiViewCallback.onReleaseKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,28 +317,4 @@ public class PopupKeysKeyboardView extends KeyboardView implements PopupKeysPane
|
|||
}
|
||||
return super.onHoverEvent(event);
|
||||
}
|
||||
|
||||
private View getContainerView() {
|
||||
return (View)getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showInParent(final ViewGroup parentView) {
|
||||
removeFromParent();
|
||||
parentView.addView(getContainerView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromParent() {
|
||||
final View containerView = getContainerView();
|
||||
final ViewGroup currentParent = (ViewGroup)containerView.getParent();
|
||||
if (currentParent != null) {
|
||||
currentParent.removeView(containerView);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowingInParent() {
|
||||
return (getContainerView().getParent() != null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,17 @@ package helium314.keyboard.keyboard;
|
|||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import helium314.keyboard.keyboard.emoji.OnKeyEventListener;
|
||||
import helium314.keyboard.keyboard.emoji.EmojiViewCallback;
|
||||
|
||||
public interface PopupKeysPanel {
|
||||
interface Controller {
|
||||
/**
|
||||
* Set the layout gravity.
|
||||
* @param layoutGravity requested by the popup
|
||||
*/
|
||||
default void setLayoutGravity(int layoutGravity) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the {@link PopupKeysPanel} to the target view.
|
||||
* @param panel the panel to be shown.
|
||||
|
@ -59,19 +66,18 @@ public interface PopupKeysPanel {
|
|||
* Initializes the layout and event handling of this {@link PopupKeysPanel} and calls the
|
||||
* controller's onShowPopupKeysPanel to add the panel's container view.
|
||||
* Same as {@link PopupKeysPanel#showPopupKeysPanel(View, Controller, int, int, KeyboardActionListener)},
|
||||
* but with a {@link OnKeyEventListener}.
|
||||
* but with a {@link EmojiViewCallback}.
|
||||
*
|
||||
* @param parentView the parent view of this {@link PopupKeysPanel}
|
||||
* @param controller the controller that can dismiss this {@link PopupKeysPanel}
|
||||
* @param pointX x coordinate of this {@link PopupKeysPanel}
|
||||
* @param pointY y coordinate of this {@link PopupKeysPanel}
|
||||
* @param listener the listener that will receive keyboard action from this
|
||||
* {@link PopupKeysPanel}.
|
||||
* @param emojiViewCallback to receive keyboard actions from this {@link PopupKeysPanel}.
|
||||
*/
|
||||
// TODO: Currently the PopupKeysPanel is inside a container view that is added to the parent.
|
||||
// Consider the simpler approach of placing the PopupKeysPanel itself into the parent view.
|
||||
void showPopupKeysPanel(View parentView, Controller controller, int pointX,
|
||||
int pointY, OnKeyEventListener listener);
|
||||
int pointY, EmojiViewCallback emojiViewCallback);
|
||||
|
||||
/**
|
||||
* Dismisses the popup keys panel and calls the controller's onDismissPopupKeysPanel to remove
|
||||
|
@ -127,20 +133,35 @@ public interface PopupKeysPanel {
|
|||
*/
|
||||
int translateY(int y);
|
||||
|
||||
default View getContainerView() {
|
||||
return (View) ((View) this).getParent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show this {@link PopupKeysPanel} in the parent view.
|
||||
*
|
||||
* @param parentView the {@link ViewGroup} that hosts this {@link PopupKeysPanel}.
|
||||
*/
|
||||
void showInParent(ViewGroup parentView);
|
||||
default void showInParent(ViewGroup parentView) {
|
||||
removeFromParent();
|
||||
parentView.addView(getContainerView());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this {@link PopupKeysPanel} from the parent view.
|
||||
*/
|
||||
void removeFromParent();
|
||||
default void removeFromParent() {
|
||||
final View containerView = getContainerView();
|
||||
final ViewGroup currentParent = (ViewGroup)containerView.getParent();
|
||||
if (currentParent != null) {
|
||||
currentParent.removeView(containerView);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the panel is currently being shown.
|
||||
*/
|
||||
boolean isShowingInParent();
|
||||
default boolean isShowingInParent() {
|
||||
return getContainerView().getParent() != null;
|
||||
}
|
||||
}
|
||||
|
|
121
app/src/main/java/helium314/keyboard/keyboard/PopupTextView.java
Normal file
121
app/src/main/java/helium314/keyboard/keyboard/PopupTextView.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
* modified
|
||||
* SPDX-License-Identifier: Apache-2.0 AND GPL-3.0-only
|
||||
*/
|
||||
|
||||
package helium314.keyboard.keyboard;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import helium314.keyboard.keyboard.emoji.EmojiViewCallback;
|
||||
import helium314.keyboard.keyboard.internal.KeyDrawParams;
|
||||
import helium314.keyboard.latin.R;
|
||||
import helium314.keyboard.latin.common.ColorType;
|
||||
import helium314.keyboard.latin.common.CoordinateUtils;
|
||||
import helium314.keyboard.latin.settings.Settings;
|
||||
|
||||
|
||||
/**
|
||||
* A view that displays popup text.
|
||||
*/
|
||||
public class PopupTextView extends TextView implements PopupKeysPanel {
|
||||
private final int[] mCoordinates = CoordinateUtils.newInstance();
|
||||
private final Typeface mTypeface;
|
||||
private Controller mController = EMPTY_CONTROLLER;
|
||||
private int mOriginX;
|
||||
private int mOriginY;
|
||||
private Key mKey;
|
||||
private EmojiViewCallback mEmojiViewCallback;
|
||||
|
||||
public PopupTextView(final Context context, final AttributeSet attrs) {
|
||||
this(context, attrs, R.attr.popupKeysKeyboardViewStyle);
|
||||
}
|
||||
|
||||
public PopupTextView(final Context context, final AttributeSet attrs,
|
||||
final int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
mTypeface = Settings.getInstance().getCustomTypeface();
|
||||
}
|
||||
|
||||
public void setKeyDrawParams(Key key, KeyDrawParams drawParams) {
|
||||
mKey = key;
|
||||
Settings.getValues().mColors.setBackground(this, ColorType.KEY_PREVIEW_BACKGROUND);
|
||||
setTextColor(drawParams.mPreviewTextColor);
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, key.selectHintTextSize(drawParams) << 1);
|
||||
setTypeface(mTypeface == null ? key.selectTypeface(drawParams) : mTypeface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPopupKeysPanel(final View parentView, final Controller controller,
|
||||
final int pointX, final int pointY, final KeyboardActionListener listener) {
|
||||
showPopupKeysPanelInternal(parentView, controller, pointX, pointY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPopupKeysPanel(final View parentView, final Controller controller,
|
||||
final int pointX, final int pointY, final EmojiViewCallback emojiViewCallback) {
|
||||
mEmojiViewCallback = emojiViewCallback;
|
||||
showPopupKeysPanelInternal(parentView, controller, pointX, pointY);
|
||||
}
|
||||
|
||||
private void showPopupKeysPanelInternal(final View parentView, final Controller controller,
|
||||
final int pointX, final int pointY) {
|
||||
mController = controller;
|
||||
final View container = getContainerView();
|
||||
// The coordinates of panel's left-top corner in parentView's coordinate system.
|
||||
// We need to consider background drawable paddings.
|
||||
final int x = pointX - getMeasuredWidth() / 2 - container.getPaddingLeft() - getPaddingLeft();
|
||||
final int y = pointY - container.getMeasuredHeight() + container.getPaddingBottom()
|
||||
+ getPaddingBottom();
|
||||
|
||||
parentView.getLocationInWindow(mCoordinates);
|
||||
// Ensure the horizontal position of the panel does not extend past the parentView edges.
|
||||
final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
|
||||
final int panelX = Math.max(0, Math.min(maxX, x)) + CoordinateUtils.x(mCoordinates);
|
||||
final int panelY = y + CoordinateUtils.y(mCoordinates);
|
||||
container.setX(panelX);
|
||||
container.setY(panelY);
|
||||
|
||||
mOriginX = x + container.getPaddingLeft();
|
||||
mOriginY = y + container.getPaddingTop();
|
||||
controller.setLayoutGravity(Gravity.NO_GRAVITY);
|
||||
controller.onShowPopupKeysPanel(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMoveEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) {
|
||||
mEmojiViewCallback.onReleaseKey(mKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissPopupKeysPanel() {
|
||||
if (!isShowingInParent()) {
|
||||
return;
|
||||
}
|
||||
mController.onDismissPopupKeysPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int translateX(final int x) {
|
||||
return x - mOriginX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int translateY(final int y) {
|
||||
return y - mOriginY;
|
||||
}
|
||||
}
|
|
@ -13,6 +13,9 @@ import android.graphics.PorterDuff;
|
|||
import android.graphics.PorterDuffXfermode;
|
||||
import android.os.Handler;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.widget.LinearLayout;
|
||||
import helium314.keyboard.keyboard.PopupTextView;
|
||||
import helium314.keyboard.latin.utils.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
|
@ -53,14 +56,18 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
private static final long KEY_PRESS_DELAY_TIME = 250; // msec
|
||||
private static final long KEY_RELEASE_DELAY_TIME = 30; // msec
|
||||
|
||||
private static final OnKeyEventListener EMPTY_LISTENER = new OnKeyEventListener() {
|
||||
private static final EmojiViewCallback EMPTY_EMOJI_VIEW_CALLBACK = new EmojiViewCallback() {
|
||||
@Override
|
||||
public void onPressKey(final Key key) {}
|
||||
@Override
|
||||
public void onReleaseKey(final Key key) {}
|
||||
@Override
|
||||
public String getDescription(String emoji) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
private OnKeyEventListener mListener = EMPTY_LISTENER;
|
||||
private EmojiViewCallback mEmojiViewCallback = EMPTY_EMOJI_VIEW_CALLBACK;
|
||||
private final KeyDetector mKeyDetector = new KeyDetector();
|
||||
private KeyboardAccessibilityDelegate<EmojiPageKeyboardView> mAccessibilityDelegate;
|
||||
|
||||
|
@ -74,6 +81,8 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
|
||||
// More keys keyboard
|
||||
private final View mPopupKeysKeyboardContainer;
|
||||
private final PopupTextView mDescriptionView;
|
||||
private final PopupKeysKeyboardView mPopupKeysKeyboardView;
|
||||
private final WeakHashMap<Key, Keyboard> mPopupKeysKeyboardCache = new WeakHashMap<>();
|
||||
private final boolean mConfigShowPopupKeysKeyboardAtTouchedPoint;
|
||||
private final ViewGroup mPopupKeysPlacerView;
|
||||
|
@ -102,6 +111,8 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
|
||||
final LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
mPopupKeysKeyboardContainer = inflater.inflate(popupKeysKeyboardLayoutId, null);
|
||||
mDescriptionView = mPopupKeysKeyboardContainer.findViewById(R.id.description_view);
|
||||
mPopupKeysKeyboardView = mPopupKeysKeyboardContainer.findViewById(R.id.popup_keys_keyboard_view);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -146,8 +157,8 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
}
|
||||
}
|
||||
|
||||
public void setOnKeyEventListener(final OnKeyEventListener listener) {
|
||||
mListener = listener;
|
||||
public void setEmojiViewCallback(final EmojiViewCallback emojiViewCallback) {
|
||||
mEmojiViewCallback = emojiViewCallback;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -169,7 +180,8 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public PopupKeysPanel showPopupKeysKeyboard(@NonNull final Key key, final int lastX, final int lastY) {
|
||||
private PopupKeysPanel showPopupKeysKeyboard(@NonNull final Key key) {
|
||||
mPopupKeysKeyboardView.setVisibility(GONE);
|
||||
final PopupKeySpec[] popupKeys = key.getPopupKeys();
|
||||
if (popupKeys == null) {
|
||||
return null;
|
||||
|
@ -182,21 +194,9 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
mPopupKeysKeyboardCache.put(key, popupKeysKeyboard);
|
||||
}
|
||||
|
||||
final View container = mPopupKeysKeyboardContainer;
|
||||
final PopupKeysKeyboardView popupKeysKeyboardView = container.findViewById(R.id.popup_keys_keyboard_view);
|
||||
popupKeysKeyboardView.setKeyboard(popupKeysKeyboard);
|
||||
container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
final int[] lastCoords = CoordinateUtils.newCoordinateArray(1, lastX, lastY);
|
||||
// The popup keys keyboard is usually horizontally aligned with the center of the parent key.
|
||||
// If showPopupKeysKeyboardAtTouchedPoint is true and the key preview is disabled, the more
|
||||
// keys keyboard is placed at the touch point of the parent key.
|
||||
final int pointX = mConfigShowPopupKeysKeyboardAtTouchedPoint
|
||||
? CoordinateUtils.x(lastCoords)
|
||||
: key.getX() + key.getWidth() / 2;
|
||||
final int pointY = key.getY();
|
||||
popupKeysKeyboardView.showPopupKeysPanel(this, this, pointX, pointY, mListener);
|
||||
return popupKeysKeyboardView;
|
||||
mPopupKeysKeyboardView.setKeyboard(popupKeysKeyboard);
|
||||
mPopupKeysKeyboardView.setVisibility(VISIBLE);
|
||||
return mPopupKeysKeyboardView;
|
||||
}
|
||||
|
||||
private void dismissPopupKeysPanel() {
|
||||
|
@ -209,6 +209,17 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
return mPopupKeysPanel != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLayoutGravity(int layoutGravity) {
|
||||
var layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
layoutParams.gravity = mDescriptionView.getMeasuredWidth() > mPopupKeysKeyboardView.getMeasuredWidth()?
|
||||
layoutGravity : Gravity.CENTER_HORIZONTAL;
|
||||
mPopupKeysKeyboardContainer.setLayoutParams(layoutParams);
|
||||
mDescriptionView.setLayoutParams(layoutParams);
|
||||
mPopupKeysKeyboardView.setLayoutParams(layoutParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowPopupKeysPanel(final PopupKeysPanel panel) {
|
||||
// install placer view only when needed instead of when this
|
||||
|
@ -290,9 +301,11 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
return;
|
||||
}
|
||||
|
||||
var descriptionPanel = showDescription(key);
|
||||
final PopupKeysPanel popupKeysPanel = showPopupKeysKeyboard(key);
|
||||
|
||||
final int x = mLastX;
|
||||
final int y = mLastY;
|
||||
final PopupKeysPanel popupKeysPanel = showPopupKeysKeyboard(key, x, y);
|
||||
if (popupKeysPanel != null) {
|
||||
final int translatedX = popupKeysPanel.translateX(x);
|
||||
final int translatedY = popupKeysPanel.translateY(y);
|
||||
|
@ -301,6 +314,34 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
// want any scroll to append during this entire input.
|
||||
disallowParentInterceptTouchEvent(true);
|
||||
}
|
||||
|
||||
if (popupKeysPanel != null || descriptionPanel != null) {
|
||||
mPopupKeysKeyboardContainer.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
final int[] lastCoords = CoordinateUtils.newCoordinateArray(1, x, y);
|
||||
// The popup keys keyboard is usually horizontally aligned with the center of the parent key.
|
||||
// If showPopupKeysKeyboardAtTouchedPoint is true and the key preview is disabled, the more
|
||||
// keys keyboard is placed at the touch point of the parent key.
|
||||
final int pointX = mConfigShowPopupKeysKeyboardAtTouchedPoint
|
||||
? CoordinateUtils.x(lastCoords)
|
||||
: key.getX() + key.getWidth() / 2;
|
||||
final int pointY = key.getY() - getKeyboard().mVerticalGap;
|
||||
(popupKeysPanel != null? popupKeysPanel : descriptionPanel)
|
||||
.showPopupKeysPanel(this, this, pointX, pointY, mEmojiViewCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private PopupKeysPanel showDescription(Key key) {
|
||||
mDescriptionView.setVisibility(GONE);
|
||||
var description = mEmojiViewCallback.getDescription(key.getLabel());
|
||||
if (description == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
mDescriptionView.setText(description);
|
||||
mDescriptionView.setKeyDrawParams(key, getKeyDrawParams());
|
||||
mDescriptionView.setVisibility(VISIBLE);
|
||||
return mDescriptionView;
|
||||
}
|
||||
|
||||
private void registerPress(final Key key) {
|
||||
|
@ -318,7 +359,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
releasedKey.onReleased();
|
||||
invalidateKey(releasedKey);
|
||||
if (withKeyRegistering) {
|
||||
mListener.onReleaseKey(releasedKey);
|
||||
mEmojiViewCallback.onReleaseKey(releasedKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +367,7 @@ public final class EmojiPageKeyboardView extends KeyboardView implements
|
|||
mPendingKeyDown = null;
|
||||
pressedKey.onPressed();
|
||||
invalidateKey(pressedKey);
|
||||
mListener.onPressKey(pressedKey);
|
||||
mEmojiViewCallback.onPressKey(pressedKey);
|
||||
}
|
||||
|
||||
public void releaseCurrentKey(final boolean withKeyRegistering) {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package helium314.keyboard.keyboard.emoji;
|
||||
|
||||
import helium314.keyboard.latin.utils.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -23,13 +22,13 @@ final class EmojiPalettesAdapter extends RecyclerView.Adapter<EmojiPalettesAdapt
|
|||
private static final boolean DEBUG_PAGER = false;
|
||||
|
||||
private final int mCategoryId;
|
||||
private final OnKeyEventListener mListener;
|
||||
private final EmojiViewCallback mEmojiViewCallback;
|
||||
private final EmojiCategory mEmojiCategory;
|
||||
|
||||
public EmojiPalettesAdapter(final EmojiCategory emojiCategory, int categoryId, final OnKeyEventListener listener) {
|
||||
public EmojiPalettesAdapter(final EmojiCategory emojiCategory, int categoryId, final EmojiViewCallback emojiViewCallback) {
|
||||
mEmojiCategory = emojiCategory;
|
||||
mCategoryId = categoryId;
|
||||
mListener = listener;
|
||||
mEmojiViewCallback = emojiViewCallback;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -38,6 +37,7 @@ final class EmojiPalettesAdapter extends RecyclerView.Adapter<EmojiPalettesAdapt
|
|||
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
final EmojiPageKeyboardView keyboardView = (EmojiPageKeyboardView)inflater.inflate(
|
||||
R.layout.emoji_keyboard_page, parent, false);
|
||||
keyboardView.setEmojiViewCallback(mEmojiViewCallback);
|
||||
return new ViewHolder(keyboardView);
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@ final class EmojiPalettesAdapter extends RecyclerView.Adapter<EmojiPalettesAdapt
|
|||
final Keyboard keyboard =
|
||||
mEmojiCategory.getKeyboardFromAdapterPosition(mCategoryId, position);
|
||||
holder.getKeyboardView().setKeyboard(keyboard);
|
||||
holder.getKeyboardView().setOnKeyEventListener(mListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,12 +38,16 @@ import helium314.keyboard.keyboard.internal.KeyDrawParams;
|
|||
import helium314.keyboard.keyboard.internal.KeyVisualAttributes;
|
||||
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode;
|
||||
import helium314.keyboard.latin.AudioAndHapticFeedbackManager;
|
||||
import helium314.keyboard.latin.DictionaryFactory;
|
||||
import helium314.keyboard.latin.R;
|
||||
import helium314.keyboard.latin.RichInputMethodManager;
|
||||
import helium314.keyboard.latin.RichInputMethodSubtype;
|
||||
import helium314.keyboard.latin.SingleDictionaryFacilitator;
|
||||
import helium314.keyboard.latin.common.ColorType;
|
||||
import helium314.keyboard.latin.common.Colors;
|
||||
import helium314.keyboard.latin.settings.Settings;
|
||||
import helium314.keyboard.latin.settings.SettingsValues;
|
||||
import helium314.keyboard.latin.utils.DictionaryInfoUtils;
|
||||
import helium314.keyboard.latin.utils.ResourceUtils;
|
||||
|
||||
import static helium314.keyboard.latin.common.Constants.NOT_A_COORDINATE;
|
||||
|
@ -60,7 +64,7 @@ import static helium314.keyboard.latin.common.Constants.NOT_A_COORDINATE;
|
|||
* Because of the above reasons, this class doesn't extend {@link KeyboardView}.
|
||||
*/
|
||||
public final class EmojiPalettesView extends LinearLayout
|
||||
implements View.OnClickListener, OnKeyEventListener {
|
||||
implements View.OnClickListener, EmojiViewCallback {
|
||||
private static final class PagerViewHolder extends RecyclerView.ViewHolder {
|
||||
private long mCategoryId;
|
||||
|
||||
|
@ -179,15 +183,14 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
}
|
||||
}
|
||||
|
||||
private static SingleDictionaryFacilitator sDictionaryFacilitator;
|
||||
|
||||
private boolean initialized = false;
|
||||
private final Colors mColors;
|
||||
private final EmojiLayoutParams mEmojiLayoutParams;
|
||||
|
||||
private LinearLayout mTabStrip;
|
||||
private EmojiCategoryPageIndicatorView mEmojiCategoryPageIndicatorView;
|
||||
|
||||
private KeyboardActionListener mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
|
||||
|
||||
private final EmojiCategory mEmojiCategory;
|
||||
private ViewPager2 mPager;
|
||||
|
||||
|
@ -254,9 +257,7 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
mEmojiLayoutParams.setEmojiListProperties(mPager);
|
||||
mEmojiCategoryPageIndicatorView = findViewById(R.id.emoji_category_page_id_view);
|
||||
mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);
|
||||
|
||||
setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true);
|
||||
|
||||
mEmojiCategoryPageIndicatorView.setColors(mColors.get(ColorType.EMOJI_CATEGORY_SELECTED), mColors.get(ColorType.STRIP_BACKGROUND));
|
||||
initialized = true;
|
||||
}
|
||||
|
@ -280,8 +281,7 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
}
|
||||
|
||||
/**
|
||||
* Called from {@link EmojiPageKeyboardView} through
|
||||
* {@link helium314.keyboard.keyboard.emoji.OnKeyEventListener}
|
||||
* Called from {@link EmojiPageKeyboardView} through {@link EmojiViewCallback}
|
||||
* interface to handle touch events from non-View-based elements such as Emoji buttons.
|
||||
*/
|
||||
@Override
|
||||
|
@ -291,10 +291,9 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
}
|
||||
|
||||
/**
|
||||
* Called from {@link EmojiPageKeyboardView} through
|
||||
* {@link helium314.keyboard.keyboard.emoji.OnKeyEventListener}
|
||||
* Called from {@link EmojiPageKeyboardView} through {@link EmojiViewCallback}
|
||||
* interface to handle touch events from non-View-based elements such as Emoji buttons.
|
||||
* This may be called without any prior call to {@link OnKeyEventListener#onPressKey(Key)}.
|
||||
* This may be called without any prior call to {@link EmojiViewCallback#onPressKey(Key)}.
|
||||
*/
|
||||
@Override
|
||||
public void onReleaseKey(final Key key) {
|
||||
|
@ -310,6 +309,20 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
mKeyboardActionListener.onCodeInput(KeyCode.ALPHA, NOT_A_COORDINATE, NOT_A_COORDINATE, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription(String emoji) {
|
||||
if (sDictionaryFacilitator == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var wordProperty = sDictionaryFacilitator.getWordProperty(emoji);
|
||||
if (wordProperty == null || ! wordProperty.mHasShortcuts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return wordProperty.mShortcutTargets.get(0).mWord;
|
||||
}
|
||||
|
||||
public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
|
||||
if (!enabled) return;
|
||||
// TODO: Should use LAYER_TYPE_SOFTWARE when hardware acceleration is off?
|
||||
|
@ -324,6 +337,7 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
final KeyDrawParams params = new KeyDrawParams();
|
||||
params.updateParams(mEmojiLayoutParams.getBottomRowKeyboardHeight(), keyVisualAttr);
|
||||
setupSidePadding();
|
||||
initDictionaryFacilitator();
|
||||
}
|
||||
|
||||
private void addRecentKey(final Key key) {
|
||||
|
@ -430,5 +444,27 @@ public final class EmojiPalettesView extends LinearLayout
|
|||
|
||||
mEmojiCategory.clearKeyboardCache();
|
||||
mPager.getAdapter().notifyDataSetChanged();
|
||||
closeDictionaryFacilitator();
|
||||
}
|
||||
|
||||
private void initDictionaryFacilitator() {
|
||||
if (Settings.getValues().mShowEmojiDescriptions) {
|
||||
var locale = RichInputMethodManager.getInstance().getCurrentSubtype().getLocale();
|
||||
if (sDictionaryFacilitator == null || ! sDictionaryFacilitator.isForLocale(locale)) {
|
||||
closeDictionaryFacilitator();
|
||||
var dictFile = DictionaryInfoUtils.getCachedDictForLocaleAndType(locale, "emoji", getContext());
|
||||
var dictionary = dictFile != null? DictionaryFactory.getDictionary(dictFile, locale) : null;
|
||||
sDictionaryFacilitator = dictionary != null? new SingleDictionaryFacilitator(dictionary) : null;
|
||||
}
|
||||
} else {
|
||||
closeDictionaryFacilitator();
|
||||
}
|
||||
}
|
||||
|
||||
private static void closeDictionaryFacilitator() {
|
||||
if (sDictionaryFacilitator != null) {
|
||||
sDictionaryFacilitator.closeDictionaries();
|
||||
sDictionaryFacilitator = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@ package helium314.keyboard.keyboard.emoji;
|
|||
import helium314.keyboard.keyboard.Key;
|
||||
|
||||
/**
|
||||
* Interface to handle touch events from non-View-based elements
|
||||
* such as Emoji buttons.
|
||||
* Interface to handle callbacks from child elements
|
||||
* such as Emoji buttons and keyboard views.
|
||||
*/
|
||||
public interface OnKeyEventListener {
|
||||
public interface EmojiViewCallback {
|
||||
|
||||
/**
|
||||
* Called when a key is pressed by the user
|
||||
|
@ -17,8 +17,13 @@ public interface OnKeyEventListener {
|
|||
|
||||
/**
|
||||
* Called when a key is released.
|
||||
* This may be called without any prior call to {@link OnKeyEventListener#onPressKey(Key)},
|
||||
* This may be called without any prior call to {@link EmojiViewCallback#onPressKey(Key)},
|
||||
* for example when a key from a popup keys keyboard is selected by releasing touch on it.
|
||||
*/
|
||||
void onReleaseKey(Key key);
|
||||
|
||||
/**
|
||||
* Called from keyboard view to get an emoji description
|
||||
*/
|
||||
String getDescription(String emoji);
|
||||
}
|
|
@ -11,6 +11,7 @@ import java.util.Locale;
|
|||
|
||||
import helium314.keyboard.latin.SuggestedWords.SuggestedWordInfo;
|
||||
import helium314.keyboard.latin.common.ComposedData;
|
||||
import helium314.keyboard.latin.makedict.WordProperty;
|
||||
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
|
||||
|
||||
/**
|
||||
|
@ -177,6 +178,10 @@ public abstract class Dictionary {
|
|||
};
|
||||
}
|
||||
|
||||
public WordProperty getWordProperty(final String word, final boolean isBeginningOfSentence) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not a true dictionary. A placeholder used to indicate suggestions that don't come from any
|
||||
* real dictionary.
|
||||
|
|
|
@ -64,10 +64,26 @@ object DictionaryFactory {
|
|||
* if the dictionary type already exists in [dicts], the [file] is skipped
|
||||
*/
|
||||
private fun checkAndAddDictionaryToListNewType(file: File, dicts: MutableList<Dictionary>, locale: Locale) {
|
||||
if (!file.isFile) return
|
||||
val header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(file) ?: return killDictionary(file)
|
||||
val dictionary = getDictionary(file, locale) ?: return
|
||||
if (dicts.any { it.mDictType == dictionary.mDictType }) {
|
||||
dictionary.close()
|
||||
return
|
||||
}
|
||||
dicts.add(dictionary)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDictionary(
|
||||
file: File,
|
||||
locale: Locale
|
||||
): Dictionary? {
|
||||
if (!file.isFile) return null
|
||||
val header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(file)
|
||||
if (header == null) {
|
||||
killDictionary(file)
|
||||
return null
|
||||
}
|
||||
val dictType = header.mIdString.split(":").first()
|
||||
if (dicts.any { it.mDictType == dictType }) return
|
||||
val readOnlyBinaryDictionary = ReadOnlyBinaryDictionary(
|
||||
file.absolutePath, 0, file.length(), false, locale, dictType
|
||||
)
|
||||
|
@ -75,14 +91,13 @@ object DictionaryFactory {
|
|||
if (readOnlyBinaryDictionary.isValidDictionary) {
|
||||
if (locale.language == "ko") {
|
||||
// Use KoreanDictionary for Korean locale
|
||||
dicts.add(KoreanDictionary(readOnlyBinaryDictionary))
|
||||
} else {
|
||||
dicts.add(readOnlyBinaryDictionary)
|
||||
return KoreanDictionary(readOnlyBinaryDictionary)
|
||||
}
|
||||
} else {
|
||||
readOnlyBinaryDictionary.close()
|
||||
killDictionary(file)
|
||||
return readOnlyBinaryDictionary
|
||||
}
|
||||
readOnlyBinaryDictionary.close()
|
||||
killDictionary(file)
|
||||
return null
|
||||
}
|
||||
|
||||
private fun killDictionary(file: File) {
|
||||
|
|
|
@ -4,6 +4,7 @@ package helium314.keyboard.latin;
|
|||
|
||||
import helium314.keyboard.event.HangulCombiner;
|
||||
import helium314.keyboard.latin.common.ComposedData;
|
||||
import helium314.keyboard.latin.makedict.WordProperty;
|
||||
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
|
||||
|
||||
import java.text.Normalizer;
|
||||
|
@ -72,6 +73,11 @@ public class KoreanDictionary extends Dictionary {
|
|||
return mDictionary.getMaxFrequencyOfExactMatches(processInput(word));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WordProperty getWordProperty(String word, boolean isBeginningOfSentence) {
|
||||
return mDictionary.getWordProperty(processInput(word), isBeginningOfSentence);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean same(char[] word, int length, String typedWord) {
|
||||
word = processInput(new String(word)).toCharArray();
|
||||
|
|
|
@ -279,9 +279,7 @@ public class LatinIME extends InputMethodService implements
|
|||
msg.arg2 /* remainingTries */, this /* handler */)) {
|
||||
// If we were able to reset the caches, then we can reload the keyboard.
|
||||
// Otherwise, we'll do it when we can.
|
||||
latinIme.mKeyboardSwitcher.loadKeyboard(latinIme.getCurrentInputEditorInfo(),
|
||||
settingsValues, latinIme.getCurrentAutoCapsState(),
|
||||
latinIme.getCurrentRecapitalizeState());
|
||||
latinIme.mKeyboardSwitcher.reloadMainKeyboard();
|
||||
}
|
||||
break;
|
||||
case MSG_WAIT_FOR_DICTIONARY_LOAD:
|
||||
|
@ -1071,7 +1069,7 @@ public class LatinIME extends InputMethodService implements
|
|||
if (isDifferentTextField) {
|
||||
mainKeyboardView.closing();
|
||||
suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold);
|
||||
switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), getCurrentRecapitalizeState());
|
||||
switcher.reloadMainKeyboard();
|
||||
if (needToCallLoadKeyboardLater) {
|
||||
// If we need to call loadKeyboard again later, we need to save its state now. The
|
||||
// later call will be done in #retryResetCaches.
|
||||
|
@ -1763,8 +1761,7 @@ public class LatinIME extends InputMethodService implements
|
|||
loadSettings();
|
||||
if (mKeyboardSwitcher.getMainKeyboardView() != null) {
|
||||
// Reload keyboard because the current language has been changed.
|
||||
mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettings.getCurrent(),
|
||||
getCurrentAutoCapsState(), getCurrentRecapitalizeState());
|
||||
mKeyboardSwitcher.reloadMainKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.android.inputmethod.latin.BinaryDictionary;
|
|||
|
||||
import helium314.keyboard.latin.SuggestedWords.SuggestedWordInfo;
|
||||
import helium314.keyboard.latin.common.ComposedData;
|
||||
import helium314.keyboard.latin.makedict.WordProperty;
|
||||
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -107,6 +108,18 @@ public final class ReadOnlyBinaryDictionary extends Dictionary {
|
|||
return NOT_A_PROBABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WordProperty getWordProperty(String word, boolean isBeginningOfSentence) {
|
||||
if (mLock.readLock().tryLock()) {
|
||||
try {
|
||||
return mBinaryDictionary.getWordProperty(word, isBeginningOfSentence);
|
||||
} finally {
|
||||
mLock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
mLock.writeLock().lock();
|
||||
|
|
|
@ -7,6 +7,7 @@ import helium314.keyboard.keyboard.Keyboard
|
|||
import helium314.keyboard.keyboard.KeyboardSwitcher
|
||||
import helium314.keyboard.latin.DictionaryFacilitator.DictionaryInitializationListener
|
||||
import helium314.keyboard.latin.common.ComposedData
|
||||
import helium314.keyboard.latin.makedict.WordProperty
|
||||
import helium314.keyboard.latin.settings.SettingsValuesForSuggestion
|
||||
import helium314.keyboard.latin.utils.SuggestionResults
|
||||
import java.util.Locale
|
||||
|
@ -47,6 +48,8 @@ class SingleDictionaryFacilitator(private val dict: Dictionary) : DictionaryFaci
|
|||
return suggestionResults
|
||||
}
|
||||
|
||||
fun getWordProperty(word: String): WordProperty? = dict.getWordProperty(word, false)
|
||||
|
||||
// ------------ dummy functionality ----------------
|
||||
|
||||
override fun setValidSpellingWordReadCache(cache: LruCache<String, Boolean>) {}
|
||||
|
|
|
@ -58,6 +58,7 @@ object Defaults {
|
|||
const val PREF_VIBRATE_ON = false
|
||||
const val PREF_VIBRATE_IN_DND_MODE = false
|
||||
const val PREF_SOUND_ON = false
|
||||
const val PREF_SHOW_EMOJI_DESCRIPTIONS = true
|
||||
@JvmField
|
||||
var PREF_POPUP_ON = true
|
||||
const val PREF_AUTO_CORRECTION = true
|
||||
|
|
|
@ -67,6 +67,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
|
|||
public static final String PREF_VIBRATE_ON = "vibrate_on";
|
||||
public static final String PREF_VIBRATE_IN_DND_MODE = "vibrate_in_dnd_mode";
|
||||
public static final String PREF_SOUND_ON = "sound_on";
|
||||
public static final String PREF_SHOW_EMOJI_DESCRIPTIONS = "show_emoji_descriptions";
|
||||
public static final String PREF_POPUP_ON = "popup_on";
|
||||
public static final String PREF_AUTO_CORRECTION = "auto_correction";
|
||||
public static final String PREF_MORE_AUTO_CORRECTION = "more_auto_correction";
|
||||
|
|
|
@ -54,6 +54,7 @@ public class SettingsValues {
|
|||
public final boolean mVibrateOn;
|
||||
public final boolean mVibrateInDndMode;
|
||||
public final boolean mSoundOn;
|
||||
public final boolean mShowEmojiDescriptions;
|
||||
public final boolean mKeyPreviewPopupOn;
|
||||
public final boolean mShowsVoiceInputKey;
|
||||
public final boolean mLanguageSwitchKeyToOtherImes;
|
||||
|
@ -169,6 +170,7 @@ public class SettingsValues {
|
|||
mVibrateOn = Settings.readVibrationEnabled(prefs);
|
||||
mVibrateInDndMode = prefs.getBoolean(Settings.PREF_VIBRATE_IN_DND_MODE, Defaults.PREF_VIBRATE_IN_DND_MODE);
|
||||
mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, Defaults.PREF_SOUND_ON);
|
||||
mShowEmojiDescriptions = prefs.getBoolean(Settings.PREF_SHOW_EMOJI_DESCRIPTIONS, Defaults.PREF_SHOW_EMOJI_DESCRIPTIONS);
|
||||
mKeyPreviewPopupOn = prefs.getBoolean(Settings.PREF_POPUP_ON, Defaults.PREF_POPUP_ON);
|
||||
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
|
||||
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, Defaults.PREF_SLIDING_KEY_INPUT_PREVIEW);
|
||||
|
|
|
@ -101,6 +101,10 @@ object DictionaryInfoUtils {
|
|||
return absoluteDirectoryName
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getCachedDictForLocaleAndType(locale: Locale, type: String, context: Context): File? =
|
||||
getCachedDictsForLocale(locale, context).firstOrNull { it.name.substringBefore("_") == type }
|
||||
|
||||
fun getCachedDictsForLocale(locale: Locale, context: Context) =
|
||||
getCacheDirectoryForLocale(locale, context)?.let { File(it).listFiles() }.orEmpty()
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ fun PreferencesScreen(
|
|||
Settings.PREF_SOUND_ON,
|
||||
if (prefs.getBoolean(Settings.PREF_SOUND_ON, Defaults.PREF_SOUND_ON))
|
||||
Settings.PREF_KEYPRESS_SOUND_VOLUME else null,
|
||||
Settings.PREF_SHOW_EMOJI_DESCRIPTIONS,
|
||||
R.string.settings_category_additional_keys,
|
||||
Settings.PREF_SHOW_NUMBER_ROW,
|
||||
if (SubtypeSettings.getEnabledSubtypes(true).any { it.locale().language in localesWithLocalizedNumberRow })
|
||||
|
@ -111,6 +112,14 @@ fun createPreferencesSettings(context: Context) = listOf(
|
|||
Setting(context, Settings.PREF_SOUND_ON, R.string.sound_on_keypress) {
|
||||
SwitchPreference(it, Defaults.PREF_SOUND_ON)
|
||||
},
|
||||
Setting(
|
||||
context, Settings.PREF_SHOW_EMOJI_DESCRIPTIONS, R.string.show_emoji_descriptions,
|
||||
R.string.show_emoji_descriptions_summary
|
||||
) {
|
||||
SwitchPreference(it, Defaults.PREF_SHOW_EMOJI_DESCRIPTIONS) {
|
||||
KeyboardSwitcher.getInstance().reloadKeyboard()
|
||||
}
|
||||
},
|
||||
Setting(context, Settings.PREF_ENABLE_CLIPBOARD_HISTORY,
|
||||
R.string.enable_clipboard_history, R.string.enable_clipboard_history_summary)
|
||||
{
|
||||
|
|
|
@ -10,6 +10,15 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<helium314.keyboard.keyboard.PopupTextView
|
||||
android:id="@+id/description_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:visibility="gone"
|
||||
android:maxLines="1" android:ellipsize="end"
|
||||
style="?attr/popupKeysKeyboardViewStyle" />
|
||||
<helium314.keyboard.keyboard.PopupKeysKeyboardView
|
||||
android:id="@+id/popup_keys_keyboard_view"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
<string name="vibrate_in_dnd_mode">Vibrate in do not disturb mode</string>
|
||||
<!-- Option to play back sound on keypress in soft keyboard -->
|
||||
<string name="sound_on_keypress">Sound on keypress</string>
|
||||
<!-- Option to show emoji descriptions on long press -->
|
||||
<string name="show_emoji_descriptions">Show emoji description on long press</string>
|
||||
<!-- Description for option to show emoji descriptions on long press -->
|
||||
<string name="show_emoji_descriptions_summary">Requires an emoji dictionary</string>
|
||||
<!-- Option to control whether or not to show a popup with a larger font on each key press. -->
|
||||
<string name="popup_on_keypress">Popup on keypress</string>
|
||||
<!-- Settings screen title for preferences-->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue