mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-11 00:49:33 +00:00
Add toast notification when copying from clipboard (#752)
and use the toast for showing dictionary on double-long-press word: switch from one ugly workaround (popup menu) to another (hiding more suggestions panel) Co-authored-by: codokie <@> Co-authored-by: Helium314 <helium314@mailbox.org>
This commit is contained in:
parent
df6af1f07e
commit
e357f84572
11 changed files with 101 additions and 7 deletions
|
@ -10,14 +10,19 @@ import android.annotation.SuppressLint;
|
|||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import helium314.keyboard.latin.utils.Log;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
import android.widget.HorizontalScrollView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
|
@ -36,6 +41,7 @@ import helium314.keyboard.latin.settings.Settings;
|
|||
import helium314.keyboard.latin.settings.SettingsValues;
|
||||
import helium314.keyboard.latin.utils.CapsModeUtils;
|
||||
import helium314.keyboard.latin.utils.LanguageOnSpacebarUtils;
|
||||
import helium314.keyboard.latin.utils.Log;
|
||||
import helium314.keyboard.latin.utils.RecapitalizeStatus;
|
||||
import helium314.keyboard.latin.utils.ResourceUtils;
|
||||
import helium314.keyboard.latin.utils.ScriptUtils;
|
||||
|
@ -53,6 +59,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
private HorizontalScrollView mClipboardStripScrollView;
|
||||
private View mSuggestionStripView;
|
||||
private ClipboardHistoryView mClipboardHistoryView;
|
||||
private TextView mFakeToastView;
|
||||
private LatinIME mLatinIME;
|
||||
private RichInputMethodManager mRichImm;
|
||||
private boolean mIsHardwareAcceleratedDrawingEnabled;
|
||||
|
@ -467,6 +474,46 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
Settings.getInstance().writeOneHandedModeGravity(mKeyboardViewWrapper.getOneHandedGravity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a toast message.
|
||||
*
|
||||
* @param text The text to display in the toast message.
|
||||
* @param briefToast If true, the toast duration will be short; otherwise, it will last longer.
|
||||
*/
|
||||
public void showToast(final String text, final boolean briefToast){
|
||||
// In API 32 and below, toasts can be shown without a notification permission.
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||
final int toastLength = briefToast ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG;
|
||||
final Toast toast = Toast.makeText(mLatinIME, text, toastLength);
|
||||
toast.setGravity(Gravity.CENTER, 0, 0);
|
||||
toast.show();
|
||||
} else {
|
||||
final int toastLength = briefToast ? 2000 : 3500;
|
||||
showFakeToast(text, toastLength);
|
||||
}
|
||||
}
|
||||
|
||||
// Displays a toast-like message with the provided text for a specified duration.
|
||||
public void showFakeToast(final String text, final int timeMillis) {
|
||||
if (mFakeToastView.getVisibility() == View.VISIBLE) return;
|
||||
|
||||
final Drawable appIcon = mFakeToastView.getCompoundDrawables()[0];
|
||||
if (appIcon != null) {
|
||||
final int bound = mFakeToastView.getLineHeight();
|
||||
appIcon.setBounds(0, 0, bound, bound);
|
||||
mFakeToastView.setCompoundDrawables(appIcon, null, null, null);
|
||||
}
|
||||
mFakeToastView.setText(text);
|
||||
mFakeToastView.setVisibility(View.VISIBLE);
|
||||
mFakeToastView.bringToFront();
|
||||
mFakeToastView.startAnimation(AnimationUtils.loadAnimation(mLatinIME, R.anim.fade_in));
|
||||
|
||||
mFakeToastView.postDelayed(() -> {
|
||||
mFakeToastView.startAnimation(AnimationUtils.loadAnimation(mLatinIME, R.anim.fade_out));
|
||||
mFakeToastView.setVisibility(View.GONE);
|
||||
}, timeMillis);
|
||||
}
|
||||
|
||||
// Implements {@link KeyboardState.SwitchActions}.
|
||||
@Override
|
||||
public boolean isInDoubleTapShiftKeyTimeout() {
|
||||
|
@ -562,6 +609,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
|||
mMainKeyboardFrame = mCurrentInputView.findViewById(R.id.main_keyboard_frame);
|
||||
mEmojiPalettesView = mCurrentInputView.findViewById(R.id.emoji_palettes_view);
|
||||
mClipboardHistoryView = mCurrentInputView.findViewById(R.id.clipboard_history_view);
|
||||
mFakeToastView = mCurrentInputView.findViewById(R.id.fakeToast);
|
||||
|
||||
mKeyboardViewWrapper = mCurrentInputView.findViewById(R.id.keyboard_view_wrapper);
|
||||
mKeyboardViewWrapper.setKeyboardActionListener(mLatinIME.mKeyboardActionListener);
|
||||
|
|
|
@ -10,11 +10,14 @@ import android.content.ClipData;
|
|||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.CharacterStyle;
|
||||
|
||||
import helium314.keyboard.keyboard.KeyboardSwitcher;
|
||||
import helium314.keyboard.latin.utils.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.inputmethod.CompletionInfo;
|
||||
|
@ -671,6 +674,9 @@ public final class RichInputConnection implements PrivateCommandPerformer {
|
|||
if (text == null || text.length() == 0) return;
|
||||
final ClipboardManager cm = (ClipboardManager) mParent.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
cm.setPrimaryClip(ClipData.newPlainText("copied text", text));
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||
KeyboardSwitcher.getInstance().showToast(mParent.getString(R.string.toast_msg_clipboard_copy), true);
|
||||
}
|
||||
}
|
||||
|
||||
public void commitCorrection(final CorrectionInfo correctionInfo) {
|
||||
|
|
|
@ -41,6 +41,7 @@ import android.widget.TextView;
|
|||
|
||||
import helium314.keyboard.accessibility.AccessibilityUtils;
|
||||
import helium314.keyboard.keyboard.Keyboard;
|
||||
import helium314.keyboard.keyboard.KeyboardSwitcher;
|
||||
import helium314.keyboard.keyboard.MainKeyboardView;
|
||||
import helium314.keyboard.keyboard.PopupKeysPanel;
|
||||
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode;
|
||||
|
@ -445,12 +446,10 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
final SuggestedWordInfo info = mSuggestedWords.getInfo(index);
|
||||
if (!info.getWord().equals(word)) return;
|
||||
final String text = info.mSourceDict.mDictType + ":" + info.mSourceDict.mLocale;
|
||||
// apparently toast is not working on some Android versions, probably
|
||||
// Android 13 with the notification permission
|
||||
// Toast.makeText(getContext(), text, Toast.LENGTH_LONG).show();
|
||||
final PopupMenu uglyWorkaround = new PopupMenu(DialogUtilsKt.getPlatformDialogThemeContext(getContext()), wordView);
|
||||
uglyWorkaround.getMenu().add(Menu.NONE, 1, Menu.NONE, text);
|
||||
uglyWorkaround.show();
|
||||
if (isShowingMoreSuggestionPanel()) {
|
||||
mMoreSuggestionsView.dismissPopupKeysPanel();
|
||||
}
|
||||
KeyboardSwitcher.getInstance().showToast(text, true);
|
||||
}
|
||||
|
||||
private void removeSuggestion(TextView wordView) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue