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

View File

@ -25,6 +25,7 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
@ -34,6 +35,7 @@ import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -84,6 +86,8 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
private EmojiPalettesAdapter mEmojiPalettesAdapter;
private final EmojiLayoutParams mEmojiLayoutParams;
private TextView mAlphabetKeyLeft;
private TextView mAlphabetKeyRight;
private TabHost mTabHost;
private ViewPager mEmojiPager;
private int mCurrentPagerPosition = 0;
@ -487,20 +491,23 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
deleteKey.setTag(Constants.CODE_DELETE);
deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
// alphabetKey, alphabetKey2, and spaceKey depend on {@link View.OnClickListener} as well as
// {@link View.OnTouchListener}. {@link View.OnTouchListener} is used as the trigger of
// key-press, while {@link View.OnClickListener} is used as the trigger of key-release which
// does not occur if the event is canceled by moving off the finger from the view.
final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet);
alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
alphabetKey.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
alphabetKey.setOnTouchListener(this);
alphabetKey.setOnClickListener(this);
final ImageView alphabetKey2 = (ImageView)findViewById(R.id.emoji_keyboard_alphabet2);
alphabetKey2.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
alphabetKey2.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
alphabetKey2.setOnTouchListener(this);
alphabetKey2.setOnClickListener(this);
// {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
// {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
// {@link View.OnTouchListener} is used as the trigger of key-press, while
// {@link View.OnClickListener} is used as the trigger of key-release which does not occur
// if the event is canceled by moving off the finger from the view.
// The text on alphabet keys are set at
// {@link #startEmojiPalettes(String,int,float,Typeface)}.
mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
mAlphabetKeyLeft.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
mAlphabetKeyLeft.setOnTouchListener(this);
mAlphabetKeyLeft.setOnClickListener(this);
mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
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);
spaceKey.setBackgroundResource(mKeyBackgroundId);
spaceKey.setTag(Constants.CODE_SPACE);
@ -627,10 +634,20 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
// 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) {
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.setCurrentItem(mCurrentPagerPosition);
}

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Paint;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.ContextThemeWrapper;
@ -30,6 +31,7 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
import com.android.inputmethod.keyboard.internal.KeyboardState;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputView;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
@ -74,13 +76,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private MainKeyboardView mKeyboardView;
private EmojiPalettesView mEmojiPalettesView;
private LatinIME mLatinIME;
private Resources mResources;
private boolean mIsHardwareAcceleratedDrawingEnabled;
private KeyboardState mState;
private KeyboardLayoutSet mKeyboardLayoutSet;
private SettingsValues mCurrentSettingsValues;
private Key mSwitchToAlphaKey;
/** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of
* what user actually typed. */
@ -106,7 +108,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private void initInternal(final LatinIME latinIme, final SharedPreferences prefs) {
mLatinIME = latinIme;
mResources = latinIme.getResources();
mPrefs = prefs;
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mState = new KeyboardState(this);
@ -162,6 +163,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mCurrentSettingsValues = settingsValues;
try {
mState.onLoadKeyboard();
final Keyboard symbols = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS);
mSwitchToAlphaKey = symbols.getKey(Constants.CODE_SWITCH_ALPHA_SYMBOL);
} catch (KeyboardLayoutSetException e) {
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());
LatinImeLogger.logOnException(e.mKeyboardId.toString(), e.getCause());
@ -287,7 +290,10 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
@Override
public void setEmojiKeyboard() {
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);
}

View File

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