mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-17 15:32:48 +00:00
Show delete button when long-pressing suggestion (#148)
remove old style of removing suggestions via popup menu
This commit is contained in:
parent
8fbb0ce0c7
commit
81d422fdc6
4 changed files with 83 additions and 66 deletions
|
@ -23,6 +23,7 @@ import android.content.res.Resources;
|
|||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.GestureDetector;
|
||||
|
@ -58,8 +59,10 @@ import org.dslul.openboard.inputmethod.latin.suggestions.MoreSuggestionsView.Mor
|
|||
import org.dslul.openboard.inputmethod.latin.utils.DialogUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
|
||||
public final class SuggestionStripView extends RelativeLayout implements OnClickListener,
|
||||
|
@ -305,71 +308,89 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
|||
}
|
||||
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
|
||||
Constants.NOT_A_CODE, this);
|
||||
if (isShowingMoreSuggestionPanel() || !showMoreSuggestions()) {
|
||||
for (int i = 0; i <= mStartIndexOfMoreSuggestions; i++) {
|
||||
if (view == mWordViews.get(i)) {
|
||||
showDeleteSuggestionDialog(mWordViews.get(i));
|
||||
return true;
|
||||
if (view instanceof TextView && mWordViews.contains(view)) {
|
||||
final Drawable icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_delete);
|
||||
icon.setColorFilter(Settings.getInstance().getCurrent().mColors.getKeyTextFilter());
|
||||
int w = icon.getIntrinsicWidth();
|
||||
int h = icon.getIntrinsicWidth();
|
||||
final TextView wordView = (TextView) view;
|
||||
wordView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||
wordView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
AtomicBoolean downOk = new AtomicBoolean(false);
|
||||
wordView.setOnTouchListener((view1, motionEvent) -> {
|
||||
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
|
||||
final float x = motionEvent.getX();
|
||||
final float y = motionEvent.getY();
|
||||
if (0 < x && x < w && 0 < y && y < h) {
|
||||
removeSuggestion(wordView);
|
||||
wordView.cancelLongPress();
|
||||
wordView.setPressed(false);
|
||||
return true;
|
||||
}
|
||||
} else if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
final float x = motionEvent.getX();
|
||||
final float y = motionEvent.getY();
|
||||
if (0 < x && x < w && 0 < y && y < h) {
|
||||
downOk.set(true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
if (BuildConfig.DEBUG && (isShowingMoreSuggestionPanel() || !showMoreSuggestions())) {
|
||||
showSourceDict(wordView);
|
||||
return true;
|
||||
} else return showMoreSuggestions();
|
||||
} else return showMoreSuggestions();
|
||||
}
|
||||
|
||||
private void showSourceDict(final TextView wordView) {
|
||||
final String word = wordView.getText().toString();
|
||||
final int index;
|
||||
if (wordView.getTag() instanceof Integer) {
|
||||
index = (int) wordView.getTag();
|
||||
} else return;
|
||||
if (index >= mSuggestedWords.size()) return;
|
||||
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(DialogUtils.getPlatformDialogThemeContext(getContext()), wordView);
|
||||
uglyWorkaround.getMenu().add(Menu.NONE, 1, Menu.NONE, text);
|
||||
uglyWorkaround.show();
|
||||
}
|
||||
|
||||
private void removeSuggestion(TextView wordView) {
|
||||
final String word = wordView.getText().toString();
|
||||
mListener.removeSuggestion(word);
|
||||
mMoreSuggestionsView.dismissMoreKeysPanel();
|
||||
// show suggestions, but without the removed word
|
||||
final ArrayList<SuggestedWordInfo> sw = new ArrayList<>();
|
||||
for (int i = 0; i < mSuggestedWords.size(); i ++) {
|
||||
final SuggestedWordInfo info = mSuggestedWords.getInfo(i);
|
||||
if (!info.getWord().equals(word))
|
||||
sw.add(info);
|
||||
}
|
||||
ArrayList<SuggestedWordInfo> rs = null;
|
||||
if (mSuggestedWords.mRawSuggestions != null) {
|
||||
rs = mSuggestedWords.mRawSuggestions;
|
||||
for (int i = 0; i < rs.size(); i ++) {
|
||||
if (rs.get(i).getWord().equals(word)) {
|
||||
rs.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showDeleteSuggestionDialog(final TextView wordView) {
|
||||
final String word = wordView.getText().toString();
|
||||
|
||||
final PopupMenu menu = new PopupMenu(DialogUtils.getPlatformDialogThemeContext(getContext()), wordView);
|
||||
menu.getMenu().add(Menu.NONE, 1, Menu.NONE, R.string.remove_suggestions);
|
||||
if (BuildConfig.DEBUG)
|
||||
menu.getMenu().add(Menu.NONE, 2, Menu.NONE, "Show source dictionary");
|
||||
menu.setOnMenuItemClickListener(menuItem -> {
|
||||
if (menuItem.getItemId() == 2) {
|
||||
for (int i = 0; i < mSuggestedWords.size(); i ++) {
|
||||
final SuggestedWordInfo info = mSuggestedWords.getInfo(i);
|
||||
if (info.getWord().equals(word)) {
|
||||
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(DialogUtils.getPlatformDialogThemeContext(getContext()), wordView);
|
||||
uglyWorkaround.getMenu().add(Menu.NONE, 1, Menu.NONE, text);
|
||||
uglyWorkaround.show();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
mListener.removeSuggestion(word);
|
||||
mMoreSuggestionsView.dismissMoreKeysPanel();
|
||||
// show suggestions, but without the removed word
|
||||
final ArrayList<SuggestedWordInfo> sw = new ArrayList<>();
|
||||
for (int i = 0; i < mSuggestedWords.size(); i ++) {
|
||||
final SuggestedWordInfo info = mSuggestedWords.getInfo(i);
|
||||
if (!info.getWord().equals(word))
|
||||
sw.add(info);
|
||||
}
|
||||
ArrayList<SuggestedWordInfo> rs = null;
|
||||
if (mSuggestedWords.mRawSuggestions != null) {
|
||||
rs = mSuggestedWords.mRawSuggestions;
|
||||
for (int i = 0; i < rs.size(); i ++) {
|
||||
if (rs.get(i).getWord().equals(word)) {
|
||||
rs.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// copied code from setSuggestions, but without the Rtl part
|
||||
clear();
|
||||
mSuggestedWords = new SuggestedWords(sw, rs, mSuggestedWords.getTypedWordInfo(),
|
||||
mSuggestedWords.mTypedWordValid, mSuggestedWords.mWillAutoCorrect,
|
||||
mSuggestedWords.mIsObsoleteSuggestions, mSuggestedWords.mInputStyle,
|
||||
mSuggestedWords.mSequenceNumber);
|
||||
mStartIndexOfMoreSuggestions = mLayoutHelper.layoutAndReturnStartIndexOfMoreSuggestions(
|
||||
getContext(), mSuggestedWords, mSuggestionsStrip, SuggestionStripView.this);
|
||||
mStripVisibilityGroup.showSuggestionsStrip();
|
||||
return true;
|
||||
});
|
||||
menu.show();
|
||||
// copied code from setSuggestions, but without the Rtl part
|
||||
clear();
|
||||
mSuggestedWords = new SuggestedWords(sw, rs, mSuggestedWords.getTypedWordInfo(),
|
||||
mSuggestedWords.mTypedWordValid, mSuggestedWords.mWillAutoCorrect,
|
||||
mSuggestedWords.mIsObsoleteSuggestions, mSuggestedWords.mInputStyle,
|
||||
mSuggestedWords.mSequenceNumber);
|
||||
mStartIndexOfMoreSuggestions = mLayoutHelper.layoutAndReturnStartIndexOfMoreSuggestions(
|
||||
getContext(), mSuggestedWords, mSuggestionsStrip, SuggestionStripView.this);
|
||||
mStripVisibilityGroup.showSuggestionsStrip();
|
||||
}
|
||||
|
||||
boolean showMoreSuggestions() {
|
||||
|
|
|
@ -75,7 +75,6 @@
|
|||
<string name="auto_correction_threshold_mode_very_aggressive">অতি আগ্রাসী</string>
|
||||
<string name="bigram_prediction">পরবর্তী শব্দের পরামর্শ</string>
|
||||
<string name="bigram_prediction_summary">পরামর্শ দিতে পূর্ববর্তী শব্দ ব্যবহার</string>
|
||||
<string name="remove_suggestions">শব্দের প্রস্তাবনা অপসারণ</string>
|
||||
<string name="gesture_input">অঙ্গুলিহেলন টাইপিং সক্ষম করুন</string>
|
||||
<string name="gesture_input_summary">বর্ণের মাঝে স্লাইড করে শব্দ সন্নিবেশ</string>
|
||||
<string name="gesture_preview_trail">অঙ্গুলিহেলনের শেষাংশ প্রদর্শন</string>
|
||||
|
|
|
@ -60,7 +60,6 @@
|
|||
<string name="auto_correction_threshold_mode_very_aggressive" msgid="1853309024129480416">"Très proactive"</string>
|
||||
<string name="bigram_prediction" msgid="1084449187723948550">"Suggestions pour le mot suivant"</string>
|
||||
<string name="bigram_prediction_summary" msgid="3896362682751109677">"Utilise le mot précédent pour les suggestions"</string>
|
||||
<string name="remove_suggestions">Supprimer suggestion</string>
|
||||
<string name="gesture_input" msgid="826951152254563827">"Activer la saisie gestuelle"</string>
|
||||
<string name="gesture_input_summary" msgid="9180350639305731231">"Saisit un mot en faisant glisser le doigt sur les lettres"</string>
|
||||
<string name="gesture_preview_trail" msgid="3802333369335722221">"Afficher le tracé du geste"</string>
|
||||
|
|
|
@ -138,8 +138,6 @@
|
|||
<string name="bigram_prediction">Next-word suggestions</string>
|
||||
<!-- Description for "next word suggestion" option. This displays suggestions even when there is no input, based on the previous word. -->
|
||||
<string name="bigram_prediction_summary">Use the previous word in making suggestions</string>
|
||||
<!-- Menu item for removing a suggestion-->
|
||||
<string name="remove_suggestions">Remove suggestion</string>
|
||||
<!-- Option to enable gesture input. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=30]-->
|
||||
<string name="gesture_input">Enable gesture typing</string>
|
||||
<!-- Description for "gesture_input" option. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=65]-->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue