Merge "Refactor MoreKeysKeyboardView to use Key class"

main
Tadashi G. Takaoka 2014-05-21 03:06:43 +00:00 committed by Android (Google) Code Review
commit 73788ea154
3 changed files with 28 additions and 12 deletions

View File

@ -130,7 +130,7 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) { public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) {
if (mCurrentKey != null && mActivePointerId == pointerId) { if (mCurrentKey != null && mActivePointerId == pointerId) {
updateReleaseKeyGraphics(mCurrentKey); updateReleaseKeyGraphics(mCurrentKey);
onCodeInput(mCurrentKey.getCode(), x, y); onKeyInput(mCurrentKey, x, y);
mCurrentKey = null; mCurrentKey = null;
} }
} }
@ -138,7 +138,8 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
/** /**
* Performs the specific action for this panel when the user presses a key on the panel. * Performs the specific action for this panel when the user presses a key on the panel.
*/ */
protected void onCodeInput(final int code, final int x, final int y) { protected void onKeyInput(final Key key, final int x, final int y) {
final int code = key.getCode();
if (code == Constants.CODE_OUTPUT_TEXT) { if (code == Constants.CODE_OUTPUT_TEXT) {
mListener.onTextInput(mCurrentKey.getOutputText()); mListener.onTextInput(mCurrentKey.getOutputText());
} else if (code != Constants.CODE_UNSPECIFIED) { } else if (code != Constants.CODE_UNSPECIFIED) {

View File

@ -27,14 +27,13 @@ import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder; import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
import com.android.inputmethod.keyboard.internal.KeyboardParams; import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.utils.TypefaceUtils; import com.android.inputmethod.latin.utils.TypefaceUtils;
public final class MoreSuggestions extends Keyboard { public final class MoreSuggestions extends Keyboard {
public static final int SUGGESTION_CODE_BASE = 1024;
public final SuggestedWords mSuggestedWords; public final SuggestedWords mSuggestedWords;
public static abstract class MoreSuggestionsListener extends KeyboardActionListener.Adapter { public static abstract class MoreSuggestionsListener extends KeyboardActionListener.Adapter {
@ -178,7 +177,7 @@ public final class MoreSuggestions extends Keyboard {
} }
} }
private static boolean isIndexSubjectToAutoCorrection(final SuggestedWords suggestedWords, static boolean isIndexSubjectToAutoCorrection(final SuggestedWords suggestedWords,
final int index) { final int index) {
return suggestedWords.mWillAutoCorrect && index == SuggestedWords.INDEX_OF_AUTO_CORRECTION; return suggestedWords.mWillAutoCorrect && index == SuggestedWords.INDEX_OF_AUTO_CORRECTION;
} }
@ -226,11 +225,7 @@ public final class MoreSuggestions extends Keyboard {
word = mSuggestedWords.getLabel(index); word = mSuggestedWords.getLabel(index);
info = mSuggestedWords.getDebugString(index); info = mSuggestedWords.getDebugString(index);
} }
final int indexInMoreSuggestions = index + SUGGESTION_CODE_BASE; final Key key = new MoreSuggestionKey(word, info, index, params);
final Key key = new Key(word, KeyboardIconsSet.ICON_UNDEFINED,
indexInMoreSuggestions, null /* outputText */, info, 0 /* labelFlags */,
Key.BACKGROUND_TYPE_NORMAL, x, y, width, params.mDefaultRowHeight,
params.mHorizontalGap, params.mVerticalGap);
params.markAsEdgeKey(key, index); params.markAsEdgeKey(key, index);
params.onAddKey(key); params.onAddKey(key);
final int columnNumber = params.getColumnNumber(index); final int columnNumber = params.getColumnNumber(index);
@ -245,6 +240,19 @@ public final class MoreSuggestions extends Keyboard {
} }
} }
static final class MoreSuggestionKey extends Key {
public final int mSuggestedWordIndex;
public MoreSuggestionKey(final String word, final String info, final int index,
final MoreSuggestionsParam params) {
super(word /* label */, KeyboardIconsSet.ICON_UNDEFINED, Constants.CODE_OUTPUT_TEXT,
word /* outputText */, info, 0 /* labelFlags */, Key.BACKGROUND_TYPE_NORMAL,
params.getX(index), params.getY(index), params.getWidth(index),
params.mDefaultRowHeight, params.mHorizontalGap, params.mVerticalGap);
mSuggestedWordIndex = index;
}
}
private static final class Divider extends Key.Spacer { private static final class Divider extends Key.Spacer {
private final Drawable mIcon; private final Drawable mIcon;

View File

@ -20,10 +20,12 @@ import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.MoreKeysKeyboardView; import com.android.inputmethod.keyboard.MoreKeysKeyboardView;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionKey;
import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener; import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
/** /**
@ -59,7 +61,12 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView {
} }
@Override @Override
public void onCodeInput(final int code, final int x, final int y) { protected void onKeyInput(final Key key, final int x, final int y) {
if (!(key instanceof MoreSuggestionKey)) {
Log.e(TAG, "Expected key is MoreSuggestionKey, but found "
+ key.getClass().getName());
return;
}
final Keyboard keyboard = getKeyboard(); final Keyboard keyboard = getKeyboard();
if (!(keyboard instanceof MoreSuggestions)) { if (!(keyboard instanceof MoreSuggestions)) {
Log.e(TAG, "Expected keyboard is MoreSuggestions, but found " Log.e(TAG, "Expected keyboard is MoreSuggestions, but found "
@ -67,7 +74,7 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView {
return; return;
} }
final SuggestedWords suggestedWords = ((MoreSuggestions)keyboard).mSuggestedWords; final SuggestedWords suggestedWords = ((MoreSuggestions)keyboard).mSuggestedWords;
final int index = code - MoreSuggestions.SUGGESTION_CODE_BASE; final int index = ((MoreSuggestionKey)key).mSuggestedWordIndex;
if (index < 0 || index >= suggestedWords.size()) { if (index < 0 || index >= suggestedWords.size()) {
Log.e(TAG, "Selected suggestion has an illegal index: " + index); Log.e(TAG, "Selected suggestion has an illegal index: " + index);
return; return;