Remove hack from EmojiPalettesView.startEmojiPalettes

Bug: 12115967
Change-Id: I91c567a9577012ec28c08430c55e56e9c2e25b5f
main
Tadashi G. Takaoka 2014-02-24 17:24:49 +09:00
parent b08a9e021c
commit d227b00a72
5 changed files with 33 additions and 21 deletions

View File

@ -25,7 +25,6 @@ import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build; import android.os.Build;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -49,6 +48,8 @@ import android.widget.TextView;
import com.android.inputmethod.keyboard.internal.DynamicGridKeyboard; import com.android.inputmethod.keyboard.internal.DynamicGridKeyboard;
import com.android.inputmethod.keyboard.internal.EmojiLayoutParams; import com.android.inputmethod.keyboard.internal.EmojiLayoutParams;
import com.android.inputmethod.keyboard.internal.EmojiPageKeyboardView; import com.android.inputmethod.keyboard.internal.EmojiPageKeyboardView;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher;
@ -634,20 +635,23 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
// TODO: // TODO:
} }
// Hack: These parameters are hacky. private static void setupAlphabetKey(final TextView alphabetKey, final String label,
public void startEmojiPalettes(final String switchToAlphaLabel, final int switchToAlphaColor, final KeyDrawParams params) {
final float switchToAlphaSize, final Typeface switchToAlphaTypeface) { alphabetKey.setText(label);
alphabetKey.setTextColor(params.mTextColor);
alphabetKey.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mLabelSize);
alphabetKey.setTypeface(params.mTypeface);
}
public void startEmojiPalettes(final String switchToAlphaLabel,
final KeyVisualAttributes keyVisualAttr) {
if (DEBUG_PAGER) { if (DEBUG_PAGER) {
Log.d(TAG, "allocate emoji palettes memory " + mCurrentPagerPosition); Log.d(TAG, "allocate emoji palettes memory " + mCurrentPagerPosition);
} }
mAlphabetKeyLeft.setText(switchToAlphaLabel); final KeyDrawParams params = new KeyDrawParams();
mAlphabetKeyLeft.setTextColor(switchToAlphaColor); params.updateParams(mEmojiLayoutParams.getActionBarHeight(), keyVisualAttr);
mAlphabetKeyLeft.setTextSize(TypedValue.COMPLEX_UNIT_PX, switchToAlphaSize); setupAlphabetKey(mAlphabetKeyLeft, switchToAlphaLabel, params);
mAlphabetKeyLeft.setTypeface(switchToAlphaTypeface); setupAlphabetKey(mAlphabetKeyRight, switchToAlphaLabel, params);
mAlphabetKeyRight.setText(switchToAlphaLabel);
mAlphabetKeyRight.setTextColor(switchToAlphaColor);
mAlphabetKeyRight.setTextSize(TypedValue.COMPLEX_UNIT_PX, switchToAlphaSize);
mAlphabetKeyRight.setTypeface(switchToAlphaTypeface);
mEmojiPager.setAdapter(mEmojiPalettesAdapter); mEmojiPager.setAdapter(mEmojiPalettesAdapter);
mEmojiPager.setCurrentItem(mCurrentPagerPosition); mEmojiPager.setCurrentItem(mCurrentPagerPosition);
} }

View File

@ -19,7 +19,6 @@ package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Paint;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
@ -31,7 +30,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException; import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
import com.android.inputmethod.keyboard.internal.KeyboardState; import com.android.inputmethod.keyboard.internal.KeyboardState;
import com.android.inputmethod.latin.Constants; import com.android.inputmethod.keyboard.internal.KeyboardTextsSet;
import com.android.inputmethod.latin.InputView; import com.android.inputmethod.latin.InputView;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
@ -81,8 +80,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private KeyboardState mState; private KeyboardState mState;
private KeyboardLayoutSet mKeyboardLayoutSet; private KeyboardLayoutSet mKeyboardLayoutSet;
// TODO: The following {@link KeyboardTextsSet} should be in {@link KeyboardLayoutSet}.
private final KeyboardTextsSet mKeyboardTextsSet = new KeyboardTextsSet();
private SettingsValues mCurrentSettingsValues; private SettingsValues mCurrentSettingsValues;
private Key mSwitchToAlphaKey;
/** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of /** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
* what user actually typed. */ * what user actually typed. */
@ -163,8 +163,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mCurrentSettingsValues = settingsValues; mCurrentSettingsValues = settingsValues;
try { try {
mState.onLoadKeyboard(); mState.onLoadKeyboard();
final Keyboard symbols = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS); mKeyboardTextsSet.setLocale(mSubtypeSwitcher.getCurrentSubtypeLocale());
mSwitchToAlphaKey = symbols.getKey(Constants.CODE_SWITCH_ALPHA_SYMBOL);
} catch (KeyboardLayoutSetException e) { } catch (KeyboardLayoutSetException e) {
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause()); Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause()); LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause());
@ -290,10 +289,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
@Override @Override
public void setEmojiKeyboard() { public void setEmojiKeyboard() {
mMainKeyboardFrame.setVisibility(View.GONE); mMainKeyboardFrame.setVisibility(View.GONE);
final Paint paint = mKeyboardView.newLabelPaint(mSwitchToAlphaKey);
mEmojiPalettesView.startEmojiPalettes( mEmojiPalettesView.startEmojiPalettes(
mSwitchToAlphaKey.getLabel(), paint.getColor(), paint.getTextSize(), mKeyboardTextsSet.getText(KeyboardTextsSet.SWITCH_TO_ALPHA_KEY_LABEL),
paint.getTypeface()); mKeyboardView.getKeyVisualAttribute());
mEmojiPalettesView.setVisibility(View.VISIBLE); mEmojiPalettesView.setVisibility(View.VISIBLE);
} }

View File

@ -146,6 +146,10 @@ public class KeyboardView extends View {
mPaint.setAntiAlias(true); mPaint.setAntiAlias(true);
} }
public KeyVisualAttributes getKeyVisualAttribute() {
return mKeyVisualAttributes;
}
private static void blendAlpha(final Paint paint, final int alpha) { private static void blendAlpha(final Paint paint, final int alpha) {
final int color = paint.getColor(); final int color = paint.getColor();
paint.setARGB((paint.getAlpha() * alpha) / Constants.Color.ALPHA_OPAQUE, paint.setARGB((paint.getAlpha() * alpha) / Constants.Color.ALPHA_OPAQUE,

View File

@ -73,9 +73,13 @@ public class EmojiLayoutParams {
ll.setLayoutParams(lp); ll.setLayoutParams(lp);
} }
public int getActionBarHeight() {
return mEmojiActionBarHeight - mBottomPadding;
}
public void setActionBarProperties(final LinearLayout ll) { public void setActionBarProperties(final LinearLayout ll) {
final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams(); final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
lp.height = mEmojiActionBarHeight - mBottomPadding; lp.height = getActionBarHeight();
ll.setLayoutParams(lp); ll.setLayoutParams(lp);
} }

View File

@ -29,6 +29,8 @@ import java.util.Locale;
public final class KeyboardTextsSet { public final class KeyboardTextsSet {
public static final String PREFIX_TEXT = "!text/"; public static final String PREFIX_TEXT = "!text/";
public static final String SWITCH_TO_ALPHA_KEY_LABEL = "label_to_alpha_key";
private static final char BACKSLASH = Constants.CODE_BACKSLASH; private static final char BACKSLASH = Constants.CODE_BACKSLASH;
private static final int MAX_STRING_REFERENCE_INDIRECTION = 10; private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;