Use the same label of switch-to-alphabet key on Emoji palette

Bug: 12115967
Change-Id: I61cf80db933aa2ab220ddcaa88a4c9af7beeb35c
main
Tadashi G. Takaoka 2014-02-06 18:14:26 +09:00
parent b136b7dd6f
commit fe39aec08a
4 changed files with 50 additions and 26 deletions

View File

@ -89,22 +89,22 @@
android:layout_height="0dip" android:layout_height="0dip"
android:layout_weight="1" android:layout_weight="1"
> >
<ImageButton <TextView
android:id="@+id/emoji_keyboard_alphabet" android:id="@+id/emoji_keyboard_alphabet_left"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="0.15" android:layout_weight="0.15"
android:layout_height="match_parent" android:gravity="center"
android:src="@drawable/ic_ime_switcher_dark" /> android:layout_height="match_parent" />
<ImageButton <ImageButton
android:id="@+id/emoji_keyboard_space" android:id="@+id/emoji_keyboard_space"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="0.70" android:layout_weight="0.70"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<ImageButton <TextView
android:id="@+id/emoji_keyboard_alphabet2" android:id="@+id/emoji_keyboard_alphabet_right"
android:layout_width="0dip" android:layout_width="0dip"
android:layout_weight="0.15" android:layout_weight="0.15"
android:layout_height="match_parent" android:gravity="center"
android:src="@drawable/ic_ime_switcher_dark" /> android:layout_height="match_parent" />
</LinearLayout> </LinearLayout>
</com.android.inputmethod.keyboard.EmojiPalettesView> </com.android.inputmethod.keyboard.EmojiPalettesView>

View File

@ -25,6 +25,7 @@ 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;
@ -34,6 +35,7 @@ import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -84,6 +86,8 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
private EmojiPalettesAdapter mEmojiPalettesAdapter; private EmojiPalettesAdapter mEmojiPalettesAdapter;
private final EmojiLayoutParams mEmojiLayoutParams; private final EmojiLayoutParams mEmojiLayoutParams;
private TextView mAlphabetKeyLeft;
private TextView mAlphabetKeyRight;
private TabHost mTabHost; private TabHost mTabHost;
private ViewPager mEmojiPager; private ViewPager mEmojiPager;
private int mCurrentPagerPosition = 0; private int mCurrentPagerPosition = 0;
@ -487,20 +491,23 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
deleteKey.setTag(Constants.CODE_DELETE); deleteKey.setTag(Constants.CODE_DELETE);
deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener); deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
// alphabetKey, alphabetKey2, and spaceKey depend on {@link View.OnClickListener} as well as // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
// {@link View.OnTouchListener}. {@link View.OnTouchListener} is used as the trigger of // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
// key-press, while {@link View.OnClickListener} is used as the trigger of key-release which // {@link View.OnTouchListener} is used as the trigger of key-press, while
// does not occur if the event is canceled by moving off the finger from the view. // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet); // if the event is canceled by moving off the finger from the view.
alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); // The text on alphabet keys are set at
alphabetKey.setTag(Constants.CODE_ALPHA_FROM_EMOJI); // {@link #startEmojiPalettes(String,int,float,Typeface)}.
alphabetKey.setOnTouchListener(this); mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
alphabetKey.setOnClickListener(this); mAlphabetKeyLeft.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
final ImageView alphabetKey2 = (ImageView)findViewById(R.id.emoji_keyboard_alphabet2); mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId); mAlphabetKeyLeft.setOnTouchListener(this);
alphabetKey2.setTag(Constants.CODE_ALPHA_FROM_EMOJI); mAlphabetKeyLeft.setOnClickListener(this);
alphabetKey2.setOnTouchListener(this); mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
alphabetKey2.setOnClickListener(this); mAlphabetKeyRight.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
mAlphabetKeyRight.setOnTouchListener(this);
mAlphabetKeyRight.setOnClickListener(this);
final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space); final ImageView spaceKey = (ImageView)findViewById(R.id.emoji_keyboard_space);
spaceKey.setBackgroundResource(mKeyBackgroundId); spaceKey.setBackgroundResource(mKeyBackgroundId);
spaceKey.setTag(Constants.CODE_SPACE); spaceKey.setTag(Constants.CODE_SPACE);
@ -627,10 +634,20 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
// TODO: // TODO:
} }
public void startEmojiPalettes() { // Hack: These parameters are hacky.
public void startEmojiPalettes(final String switchToAlphaLabel, final int switchToAlphaColor,
final float switchToAlphaSize, final Typeface switchToAlphaTypeface) {
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);
mAlphabetKeyLeft.setTextColor(switchToAlphaColor);
mAlphabetKeyLeft.setTextSize(TypedValue.COMPLEX_UNIT_PX, switchToAlphaSize);
mAlphabetKeyLeft.setTypeface(switchToAlphaTypeface);
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,6 +19,7 @@ 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;
@ -30,6 +31,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.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;
@ -74,13 +76,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private MainKeyboardView mKeyboardView; private MainKeyboardView mKeyboardView;
private EmojiPalettesView mEmojiPalettesView; private EmojiPalettesView mEmojiPalettesView;
private LatinIME mLatinIME; private LatinIME mLatinIME;
private Resources mResources;
private boolean mIsHardwareAcceleratedDrawingEnabled; private boolean mIsHardwareAcceleratedDrawingEnabled;
private KeyboardState mState; private KeyboardState mState;
private KeyboardLayoutSet mKeyboardLayoutSet; private KeyboardLayoutSet mKeyboardLayoutSet;
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. */
@ -106,7 +108,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) { private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) {
mLatinIME = latinIme; mLatinIME = latinIme;
mResources = latinIme.getResources();
mPrefs = prefs; mPrefs = prefs;
mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mState = new KeyboardState(this); mState = new KeyboardState(this);
@ -162,6 +163,8 @@ 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);
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());
@ -287,7 +290,10 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
@Override @Override
public void setEmojiKeyboard() { public void setEmojiKeyboard() {
mMainKeyboardFrame.setVisibility(View.GONE); mMainKeyboardFrame.setVisibility(View.GONE);
mEmojiPalettesView.startEmojiPalettes(); final Paint paint = mKeyboardView.newLabelPaint(mSwitchToAlphaKey);
mEmojiPalettesView.startEmojiPalettes(
mSwitchToAlphaKey.getLabel(), paint.getColor(), paint.getTextSize(),
paint.getTypeface());
mEmojiPalettesView.setVisibility(View.VISIBLE); mEmojiPalettesView.setVisibility(View.VISIBLE);
} }

View File

@ -582,6 +582,7 @@ public class KeyboardView extends View {
paint.setTypeface(mKeyDrawParams.mTypeface); paint.setTypeface(mKeyDrawParams.mTypeface);
paint.setTextSize(mKeyDrawParams.mLabelSize); paint.setTextSize(mKeyDrawParams.mLabelSize);
} else { } else {
paint.setColor(key.selectTextColor(mKeyDrawParams));
paint.setTypeface(key.selectTypeface(mKeyDrawParams)); paint.setTypeface(key.selectTypeface(mKeyDrawParams));
paint.setTextSize(key.selectTextSize(mKeyDrawParams)); paint.setTextSize(key.selectTextSize(mKeyDrawParams));
} }