mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-21 09:21:20 +00:00
Add long press functions to more toolbar keys, and more clipboard history toolbar keys (#691)
Co-authored-by: codokie <@>
This commit is contained in:
parent
6bb49ee1a0
commit
83fc10ff02
9 changed files with 99 additions and 47 deletions
|
@ -10,8 +10,6 @@ import static helium314.keyboard.latin.utils.ToolbarUtilsKt.*;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.KeyguardManager;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
|
@ -375,10 +373,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
}
|
||||
|
||||
private void onLongClickToolKey(final View view) {
|
||||
if (ToolbarKey.CLIPBOARD == view.getTag() && view.getParent() == mPinnedKeys) {
|
||||
onLongClickClipboardKey(); // long click pinned clipboard key
|
||||
if (!(view.getTag() instanceof ToolbarKey tag)) return;
|
||||
if (view.getParent() == mPinnedKeys) {
|
||||
final int longClickCode = getCodeForToolbarKeyLongClick(tag);
|
||||
if (longClickCode != KeyCode.UNSPECIFIED) {
|
||||
mListener.onCodeInput(longClickCode, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false);
|
||||
}
|
||||
} else if (view.getParent() == mToolbar) {
|
||||
final ToolbarKey tag = (ToolbarKey) view.getTag();
|
||||
final View pinnedKeyView = mPinnedKeys.findViewWithTag(tag);
|
||||
if (pinnedKeyView == null) {
|
||||
addKeyToPinnedKeys(tag);
|
||||
|
@ -392,22 +393,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
}
|
||||
}
|
||||
|
||||
private void onLongClickClipboardKey() {
|
||||
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clipData = clipboardManager.getPrimaryClip();
|
||||
Log.d(TAG, "long click clipboard key");
|
||||
if (clipData != null && clipData.getItemCount() > 0 && clipData.getItemAt(0) != null) {
|
||||
String clipString = clipData.getItemAt(0).coerceToText(getContext()).toString();
|
||||
if (clipString.length() == 1) {
|
||||
mListener.onTextInput(clipString);
|
||||
} else if (clipString.length() > 1) {
|
||||
//awkward workaround
|
||||
mListener.onTextInput(clipString.substring(0, clipString.length() - 1));
|
||||
mListener.onTextInput(clipString.substring(clipString.length() - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility") // no need for View#performClick, we return false mostly anyway
|
||||
private boolean onLongClickSuggestion(final TextView wordView) {
|
||||
boolean showIcon = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue