diff options
author | 2013-05-01 17:02:27 +0900 | |
---|---|---|
committer | 2013-05-01 18:03:37 +0900 | |
commit | 6f7905ae757c30ac0f8080f025b88afc61a6f6b1 (patch) | |
tree | c50a8e4c8fc5ce3d056dccea22dff881e5ac245b /java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java | |
parent | 17a353831ae81ba6155a87693289ca9afd7f89cb (diff) | |
download | latinime-6f7905ae757c30ac0f8080f025b88afc61a6f6b1.tar.gz latinime-6f7905ae757c30ac0f8080f025b88afc61a6f6b1.tar.xz latinime-6f7905ae757c30ac0f8080f025b88afc61a6f6b1.zip |
Introduce MoreSuggestionsListener class
Bug: 8694255
Change-Id: I9420a7cb1983c6211f58d13b3b11db4347c3f99b
Diffstat (limited to 'java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java index 6509f394b..d585b5c7f 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java @@ -18,15 +18,21 @@ package com.android.inputmethod.latin.suggestions; import android.content.Context; import android.util.AttributeSet; +import android.util.Log; +import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.MoreKeysKeyboardView; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SuggestedWords; +import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener; /** * A view that renders a virtual {@link MoreSuggestions}. It handles rendering of keys and detecting * key presses and touch movements. */ public final class MoreSuggestionsView extends MoreKeysKeyboardView { + private static final String TAG = MoreSuggestionsView.class.getSimpleName(); + public MoreSuggestionsView(final Context context, final AttributeSet attrs) { this(context, attrs, R.attr.moreSuggestionsViewStyle); } @@ -54,9 +60,24 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView { @Override public void onCodeInput(final int code, final int x, final int y) { + final Keyboard keyboard = getKeyboard(); + if (!(keyboard instanceof MoreSuggestions)) { + Log.e(TAG, "Expected keyboard is MoreSuggestions, but found " + + keyboard.getClass().getName()); + return; + } + final SuggestedWords suggestedWords = ((MoreSuggestions)keyboard).mSuggestedWords; final int index = code - MoreSuggestions.SUGGESTION_CODE_BASE; - if (index >= 0 && index < SuggestionStripView.MAX_SUGGESTIONS) { - mListener.onCustomRequest(index); + if (index < 0 || index >= suggestedWords.size()) { + Log.e(TAG, "Selected suggestion has an illegal index: " + index); + return; + } + if (!(mListener instanceof MoreSuggestionsListener)) { + Log.e(TAG, "Expected mListener is MoreSuggestionsListener, but found " + + mListener.getClass().getName()); + return; } + ((MoreSuggestionsListener)mListener).onSuggestionSelected( + index, suggestedWords.getInfo(index)); } } |