Add final modifier to the classes under suggestions sub-package

Change-Id: I19fc8eaac1aebef9cf4deb004e78484ff9a1e7ca
main
Tadashi G. Takaoka 2012-10-03 14:46:47 +09:00
parent 5f5f7825e7
commit 3e5a3c18be
2 changed files with 62 additions and 54 deletions

View File

@ -56,17 +56,17 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
final KeyboardActionListener mSuggestionsPaneListener = final KeyboardActionListener mSuggestionsPaneListener =
new KeyboardActionListener.Adapter() { new KeyboardActionListener.Adapter() {
@Override @Override
public void onPressKey(int primaryCode) { public void onPressKey(final int primaryCode) {
mListener.onPressKey(primaryCode); mListener.onPressKey(primaryCode);
} }
@Override @Override
public void onReleaseKey(int primaryCode, boolean withSliding) { public void onReleaseKey(final int primaryCode, final boolean withSliding) {
mListener.onReleaseKey(primaryCode, withSliding); mListener.onReleaseKey(primaryCode, withSliding);
} }
@Override @Override
public void onCodeInput(int primaryCode, int x, int y) { public void onCodeInput(final int primaryCode, final int x, final int y) {
final int index = primaryCode - MoreSuggestions.SUGGESTION_CODE_BASE; final int index = primaryCode - MoreSuggestions.SUGGESTION_CODE_BASE;
if (index >= 0 && index < SuggestionStripView.MAX_SUGGESTIONS) { if (index >= 0 && index < SuggestionStripView.MAX_SUGGESTIONS) {
mListener.onCustomRequest(index); mListener.onCustomRequest(index);
@ -79,11 +79,12 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
} }
}; };
public MoreSuggestionsView(Context context, AttributeSet attrs) { public MoreSuggestionsView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.moreSuggestionsViewStyle); this(context, attrs, R.attr.moreSuggestionsViewStyle);
} }
public MoreSuggestionsView(Context context, AttributeSet attrs, int defStyle) { public MoreSuggestionsView(final Context context, final AttributeSet attrs,
final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
final Resources res = context.getResources(); final Resources res = context.getResources();
@ -94,7 +95,7 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
} }
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
final Keyboard keyboard = getKeyboard(); final Keyboard keyboard = getKeyboard();
if (keyboard != null) { if (keyboard != null) {
final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight(); final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight();
@ -106,7 +107,7 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
} }
@Override @Override
public void setKeyboard(Keyboard keyboard) { public void setKeyboard(final Keyboard keyboard) {
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
mModalPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop()); mModalPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop());
mSlidingPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), mSlidingPanelKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
@ -134,15 +135,16 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
} }
@Override @Override
public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { public void setKeyPreviewPopupEnabled(final boolean previewEnabled, final int delay) {
// Suggestions pane needs no pop-up key preview displayed, so we pass always false with a // Suggestions pane needs no pop-up key preview displayed, so we pass always false with a
// delay of 0. The delay does not matter actually since the popup is not shown anyway. // delay of 0. The delay does not matter actually since the popup is not shown anyway.
super.setKeyPreviewPopupEnabled(false, 0); super.setKeyPreviewPopupEnabled(false, 0);
} }
@Override @Override
public void showMoreKeysPanel(View parentView, Controller controller, int pointX, int pointY, public void showMoreKeysPanel(final View parentView, final Controller controller,
PopupWindow window, KeyboardActionListener listener) { final int pointX, final int pointY, final PopupWindow window,
final KeyboardActionListener listener) {
mController = controller; mController = controller;
mListener = listener; mListener = listener;
final View container = (View)getParent(); final View container = (View)getParent();
@ -175,12 +177,12 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
} }
@Override @Override
public int translateX(int x) { public int translateX(final int x) {
return x - mOriginX; return x - mOriginX;
} }
@Override @Override
public int translateY(int y) { public int translateY(final int y) {
return y - mOriginY; return y - mOriginY;
} }
@ -207,7 +209,7 @@ public final class MoreSuggestionsView extends KeyboardView implements MoreKeysP
}; };
@Override @Override
public boolean onTouchEvent(MotionEvent me) { public boolean onTouchEvent(final MotionEvent me) {
final int action = me.getAction(); final int action = me.getAction();
final long eventTime = me.getEventTime(); final long eventTime = me.getEventTime();
final int index = me.getActionIndex(); final int index = me.getActionIndex();

View File

@ -85,7 +85,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
static final boolean DBG = LatinImeLogger.sDBG; static final boolean DBG = LatinImeLogger.sDBG;
private final ViewGroup mSuggestionsStrip; private final ViewGroup mSuggestionsStrip;
private KeyboardView mKeyboardView; KeyboardView mKeyboardView;
private final View mMoreSuggestionsContainer; private final View mMoreSuggestionsContainer;
private final MoreSuggestionsView mMoreSuggestionsView; private final MoreSuggestionsView mMoreSuggestionsView;
@ -99,8 +99,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private final PopupWindow mPreviewPopup; private final PopupWindow mPreviewPopup;
private final TextView mPreviewText; private final TextView mPreviewText;
private Listener mListener; Listener mListener;
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
private final SuggestionStripViewParams mParams; private final SuggestionStripViewParams mParams;
private static final float MIN_TEXT_XSCALE = 0.70f; private static final float MIN_TEXT_XSCALE = 0.70f;
@ -110,12 +110,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private static final class UiHandler extends StaticInnerHandlerWrapper<SuggestionStripView> { private static final class UiHandler extends StaticInnerHandlerWrapper<SuggestionStripView> {
private static final int MSG_HIDE_PREVIEW = 0; private static final int MSG_HIDE_PREVIEW = 0;
public UiHandler(SuggestionStripView outerInstance) { public UiHandler(final SuggestionStripView outerInstance) {
super(outerInstance); super(outerInstance);
} }
@Override @Override
public void dispatchMessage(Message msg) { public void dispatchMessage(final Message msg) {
final SuggestionStripView suggestionStripView = getOuterInstance(); final SuggestionStripView suggestionStripView = getOuterInstance();
switch (msg.what) { switch (msg.what) {
case MSG_HIDE_PREVIEW: case MSG_HIDE_PREVIEW:
@ -179,8 +179,9 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private final TextView mLeftwardsArrowView; private final TextView mLeftwardsArrowView;
private final TextView mHintToSaveView; private final TextView mHintToSaveView;
public SuggestionStripViewParams(Context context, AttributeSet attrs, int defStyle, public SuggestionStripViewParams(final Context context, final AttributeSet attrs,
ArrayList<TextView> words, ArrayList<View> dividers, ArrayList<TextView> infos) { final int defStyle, final ArrayList<TextView> words, final ArrayList<View> dividers,
final ArrayList<TextView> infos) {
mWords = words; mWords = words;
mDividers = dividers; mDividers = dividers;
mInfos = infos; mInfos = infos;
@ -252,7 +253,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return mMaxMoreSuggestionsRow * mMoreSuggestionsRowHeight + mMoreSuggestionsBottomGap; return mMaxMoreSuggestionsRow * mMoreSuggestionsRowHeight + mMoreSuggestionsBottomGap;
} }
public int setMoreSuggestionsHeight(int remainingHeight) { public int setMoreSuggestionsHeight(final int remainingHeight) {
final int currentHeight = getMoreSuggestionsHeight(); final int currentHeight = getMoreSuggestionsHeight();
if (currentHeight <= remainingHeight) { if (currentHeight <= remainingHeight) {
return currentHeight; return currentHeight;
@ -264,7 +265,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return newHeight; return newHeight;
} }
private static Drawable getMoreSuggestionsHint(Resources res, float textSize, int color) { private static Drawable getMoreSuggestionsHint(final Resources res, final float textSize,
final int color) {
final Paint paint = new Paint(); final Paint paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
@ -281,7 +283,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return new BitmapDrawable(res, buffer); return new BitmapDrawable(res, buffer);
} }
private CharSequence getStyledSuggestionWord(SuggestedWords suggestedWords, int pos) { private CharSequence getStyledSuggestionWord(final SuggestedWords suggestedWords,
final int pos) {
final CharSequence word = suggestedWords.getWord(pos); final CharSequence word = suggestedWords.getWord(pos);
final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect(); final boolean isAutoCorrect = pos == 1 && suggestedWords.willAutoCorrect();
final boolean isTypedWordValid = pos == 0 && suggestedWords.mTypedWordValid; final boolean isTypedWordValid = pos == 0 && suggestedWords.mTypedWordValid;
@ -301,7 +304,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return spannedWord; return spannedWord;
} }
private int getWordPosition(int index, SuggestedWords suggestedWords) { private int getWordPosition(final int index, final SuggestedWords suggestedWords) {
// TODO: This works for 3 suggestions. Revisit this algorithm when there are 5 or more // TODO: This works for 3 suggestions. Revisit this algorithm when there are 5 or more
// suggestions. // suggestions.
final int centerPos = suggestedWords.willAutoCorrect() ? 1 : 0; final int centerPos = suggestedWords.willAutoCorrect() ? 1 : 0;
@ -314,7 +317,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
} }
private int getSuggestionTextColor(int index, SuggestedWords suggestedWords, int pos) { private int getSuggestionTextColor(final int index, final SuggestedWords suggestedWords,
final int pos) {
// TODO: Need to revisit this logic with bigram suggestions // TODO: Need to revisit this logic with bigram suggestions
final boolean isSuggested = (pos != 0); final boolean isSuggested = (pos != 0);
@ -357,8 +361,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
params.gravity = Gravity.CENTER; params.gravity = Gravity.CENTER;
} }
public void layout(SuggestedWords suggestedWords, ViewGroup stripView, ViewGroup placer, public void layout(final SuggestedWords suggestedWords, final ViewGroup stripView,
int stripWidth) { final ViewGroup placer, final int stripWidth) {
if (suggestedWords.mIsPunctuationSuggestions) { if (suggestedWords.mIsPunctuationSuggestions) {
layoutPunctuationSuggestions(suggestedWords, stripView); layoutPunctuationSuggestions(suggestedWords, stripView);
return; return;
@ -420,14 +424,14 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
} }
private int getSuggestionWidth(int index, int maxWidth) { private int getSuggestionWidth(final int index, final int maxWidth) {
final int paddings = mPadding * mSuggestionsCountInStrip; final int paddings = mPadding * mSuggestionsCountInStrip;
final int dividers = mDividerWidth * (mSuggestionsCountInStrip - 1); final int dividers = mDividerWidth * (mSuggestionsCountInStrip - 1);
final int availableWidth = maxWidth - paddings - dividers; final int availableWidth = maxWidth - paddings - dividers;
return (int)(availableWidth * getSuggestionWeight(index)); return (int)(availableWidth * getSuggestionWeight(index));
} }
private float getSuggestionWeight(int index) { private float getSuggestionWeight(final int index) {
if (index == mCenterSuggestionIndex) { if (index == mCenterSuggestionIndex) {
return mCenterSuggestionWeight; return mCenterSuggestionWeight;
} else { } else {
@ -436,7 +440,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
} }
private void setupTexts(SuggestedWords suggestedWords, int countInStrip) { private void setupTexts(final SuggestedWords suggestedWords, final int countInStrip) {
mTexts.clear(); mTexts.clear();
final int count = Math.min(suggestedWords.size(), countInStrip); final int count = Math.min(suggestedWords.size(), countInStrip);
for (int pos = 0; pos < count; pos++) { for (int pos = 0; pos < count; pos++) {
@ -449,8 +453,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
} }
private void layoutPunctuationSuggestions(SuggestedWords suggestedWords, private void layoutPunctuationSuggestions(final SuggestedWords suggestedWords,
ViewGroup stripView) { final ViewGroup stripView) {
final int countInStrip = Math.min(suggestedWords.size(), PUNCTUATIONS_IN_STRIP); final int countInStrip = Math.min(suggestedWords.size(), PUNCTUATIONS_IN_STRIP);
for (int index = 0; index < countInStrip; index++) { for (int index = 0; index < countInStrip; index++) {
if (index != 0) { if (index != 0) {
@ -471,8 +475,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mMoreSuggestionsAvailable = false; mMoreSuggestionsAvailable = false;
} }
public void layoutAddToDictionaryHint(CharSequence word, ViewGroup stripView, public void layoutAddToDictionaryHint(final CharSequence word, final ViewGroup stripView,
int stripWidth, CharSequence hintText, OnClickListener listener) { final int stripWidth, final CharSequence hintText, final OnClickListener listener) {
final int width = stripWidth - mDividerWidth - mPadding * 2; final int width = stripWidth - mDividerWidth - mPadding * 2;
final TextView wordView = mWordToSaveView; final TextView wordView = mWordToSaveView;
@ -513,11 +517,11 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return (CharSequence)mWordToSaveView.getTag(); return (CharSequence)mWordToSaveView.getTag();
} }
public boolean isAddToDictionaryShowing(View v) { public boolean isAddToDictionaryShowing(final View v) {
return v == mWordToSaveView || v == mHintToSaveView || v == mLeftwardsArrowView; return v == mWordToSaveView || v == mHintToSaveView || v == mLeftwardsArrowView;
} }
private static void setLayoutWeight(View v, float weight, int height) { private static void setLayoutWeight(final View v, final float weight, final int height) {
final ViewGroup.LayoutParams lp = v.getLayoutParams(); final ViewGroup.LayoutParams lp = v.getLayoutParams();
if (lp instanceof LinearLayout.LayoutParams) { if (lp instanceof LinearLayout.LayoutParams) {
final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)lp; final LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams)lp;
@ -527,7 +531,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
} }
private static float getTextScaleX(CharSequence text, int maxWidth, TextPaint paint) { private static float getTextScaleX(final CharSequence text, final int maxWidth,
final TextPaint paint) {
paint.setTextScaleX(1.0f); paint.setTextScaleX(1.0f);
final int width = getTextWidth(text, paint); final int width = getTextWidth(text, paint);
if (width <= maxWidth) { if (width <= maxWidth) {
@ -536,8 +541,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return maxWidth / (float)width; return maxWidth / (float)width;
} }
private static CharSequence getEllipsizedText(CharSequence text, int maxWidth, private static CharSequence getEllipsizedText(final CharSequence text, final int maxWidth,
TextPaint paint) { final TextPaint paint) {
if (text == null) return null; if (text == null) return null;
paint.setTextScaleX(1.0f); paint.setTextScaleX(1.0f);
final int width = getTextWidth(text, paint); final int width = getTextWidth(text, paint);
@ -558,7 +563,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return ellipsized; return ellipsized;
} }
private static int getTextWidth(CharSequence text, TextPaint paint) { private static int getTextWidth(final CharSequence text, final TextPaint paint) {
if (TextUtils.isEmpty(text)) return 0; if (TextUtils.isEmpty(text)) return 0;
final Typeface savedTypeface = paint.getTypeface(); final Typeface savedTypeface = paint.getTypeface();
paint.setTypeface(getTextTypeface(text)); paint.setTypeface(getTextTypeface(text));
@ -573,7 +578,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return width; return width;
} }
private static Typeface getTextTypeface(CharSequence text) { private static Typeface getTextTypeface(final CharSequence text) {
if (!(text instanceof SpannableString)) if (!(text instanceof SpannableString))
return Typeface.DEFAULT; return Typeface.DEFAULT;
@ -595,11 +600,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
* @param context * @param context
* @param attrs * @param attrs
*/ */
public SuggestionStripView(Context context, AttributeSet attrs) { public SuggestionStripView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.suggestionStripViewStyle); this(context, attrs, R.attr.suggestionStripViewStyle);
} }
public SuggestionStripView(Context context, AttributeSet attrs, int defStyle) { public SuggestionStripView(final Context context, final AttributeSet attrs,
final int defStyle) {
super(context, attrs, defStyle); super(context, attrs, defStyle);
final LayoutInflater inflater = LayoutInflater.from(context); final LayoutInflater inflater = LayoutInflater.from(context);
@ -660,12 +666,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
* A connection back to the input method. * A connection back to the input method.
* @param listener * @param listener
*/ */
public void setListener(Listener listener, View inputView) { public void setListener(final Listener listener, final View inputView) {
mListener = listener; mListener = listener;
mKeyboardView = (KeyboardView)inputView.findViewById(R.id.keyboard_view); mKeyboardView = (KeyboardView)inputView.findViewById(R.id.keyboard_view);
} }
public void setSuggestions(SuggestedWords suggestedWords) { public void setSuggestions(final SuggestedWords suggestedWords) {
if (suggestedWords == null) if (suggestedWords == null)
return; return;
@ -677,7 +683,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
} }
public int setMoreSuggestionsHeight(int remainingHeight) { public int setMoreSuggestionsHeight(final int remainingHeight) {
return mParams.setMoreSuggestionsHeight(remainingHeight); return mParams.setMoreSuggestionsHeight(remainingHeight);
} }
@ -686,7 +692,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
&& mParams.isAddToDictionaryShowing(mSuggestionsStrip.getChildAt(0)); && mParams.isAddToDictionaryShowing(mSuggestionsStrip.getChildAt(0));
} }
public void showAddToDictionaryHint(CharSequence word, CharSequence hintText) { public void showAddToDictionaryHint(final CharSequence word, final CharSequence hintText) {
clear(); clear();
mParams.layoutAddToDictionaryHint(word, mSuggestionsStrip, getWidth(), hintText, this); mParams.layoutAddToDictionaryHint(word, mSuggestionsStrip, getWidth(), hintText, this);
} }
@ -710,14 +716,14 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
dismissMoreSuggestions(); dismissMoreSuggestions();
} }
private void hidePreview() { void hidePreview() {
mPreviewPopup.dismiss(); mPreviewPopup.dismiss();
} }
private final KeyboardActionListener mMoreSuggestionsListener = private final KeyboardActionListener mMoreSuggestionsListener =
new KeyboardActionListener.Adapter() { new KeyboardActionListener.Adapter() {
@Override @Override
public boolean onCustomRequest(int requestCode) { public boolean onCustomRequest(final int requestCode) {
final int index = requestCode; final int index = requestCode;
final CharSequence word = mSuggestedWords.getWord(index); final CharSequence word = mSuggestedWords.getWord(index);
mListener.pickSuggestionManually(index, word); mListener.pickSuggestionManually(index, word);
@ -739,7 +745,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
}; };
private boolean dismissMoreSuggestions() { boolean dismissMoreSuggestions() {
if (mMoreSuggestionsWindow.isShowing()) { if (mMoreSuggestionsWindow.isShowing()) {
mMoreSuggestionsWindow.dismiss(); mMoreSuggestionsWindow.dismiss();
return true; return true;
@ -748,11 +754,11 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
@Override @Override
public boolean onLongClick(View view) { public boolean onLongClick(final View view) {
return showMoreSuggestions(); return showMoreSuggestions();
} }
private boolean showMoreSuggestions() { boolean showMoreSuggestions() {
final Keyboard parentKeyboard = KeyboardSwitcher.getInstance().getKeyboard(); final Keyboard parentKeyboard = KeyboardSwitcher.getInstance().getKeyboard();
if (parentKeyboard == null) { if (parentKeyboard == null) {
return false; return false;
@ -810,7 +816,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
}; };
@Override @Override
public boolean dispatchTouchEvent(MotionEvent me) { public boolean dispatchTouchEvent(final MotionEvent me) {
if (!mMoreSuggestionsWindow.isShowing() if (!mMoreSuggestionsWindow.isShowing()
|| mMoreSuggestionsMode == MORE_SUGGESTIONS_IN_MODAL_MODE) { || mMoreSuggestionsMode == MORE_SUGGESTIONS_IN_MODAL_MODE) {
mLastX = (int)me.getX(); mLastX = (int)me.getX();
@ -852,7 +858,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
@Override @Override
public void onClick(View view) { public void onClick(final View view) {
if (mParams.isAddToDictionaryShowing(view)) { if (mParams.isAddToDictionaryShowing(view)) {
mListener.addWordToUserDictionary(mParams.getAddToDictionaryWord().toString()); mListener.addWordToUserDictionary(mParams.getAddToDictionaryWord().toString());
clear(); clear();