am daa3ad86: Merge "Fix delete handling in Emoji keyboard."

* commit 'daa3ad860532e4285551005943d0e4263a1f3d2b':
  Fix delete handling in Emoji keyboard.
main
Dan Zivkovic 2015-02-04 18:20:49 +00:00 committed by Android Git Automerger
commit 0a404b5176
1 changed files with 55 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import static com.android.inputmethod.latin.common.Constants.NOT_A_COORDINATE;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Color;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -73,6 +74,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
private final int mCategoryPageIndicatorBackground; private final int mCategoryPageIndicatorBackground;
private EmojiPalettesAdapter mEmojiPalettesAdapter; private EmojiPalettesAdapter mEmojiPalettesAdapter;
private final EmojiLayoutParams mEmojiLayoutParams; private final EmojiLayoutParams mEmojiLayoutParams;
private final DeleteKeyOnTouchListener mDeleteKeyOnTouchListener;
private ImageButton mDeleteKey; private ImageButton mDeleteKey;
private TextView mAlphabetKeyLeft; private TextView mAlphabetKeyLeft;
@ -127,6 +129,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
mCategoryPageIndicatorBackground = emojiPalettesViewAttr.getColor( mCategoryPageIndicatorBackground = emojiPalettesViewAttr.getColor(
R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0); R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0);
emojiPalettesViewAttr.recycle(); emojiPalettesViewAttr.recycle();
mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener();
} }
@Override @Override
@ -197,7 +200,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete); mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId); mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
mDeleteKey.setTag(Constants.CODE_DELETE); mDeleteKey.setTag(Constants.CODE_DELETE);
mDeleteKey.setOnTouchListener(this); mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
// {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
// {@link View.OnClickListener} as well as {@link View.OnTouchListener}. // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
@ -366,7 +369,8 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
} }
public void startEmojiPalettes(final String switchToAlphaLabel, public void startEmojiPalettes(final String switchToAlphaLabel,
final KeyVisualAttributes keyVisualAttr, final KeyboardIconsSet iconSet) { final KeyVisualAttributes keyVisualAttr,
final KeyboardIconsSet iconSet) {
final int deleteIconResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_DELETE_KEY); final int deleteIconResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_DELETE_KEY);
if (deleteIconResId != 0) { if (deleteIconResId != 0) {
mDeleteKey.setImageResource(deleteIconResId); mDeleteKey.setImageResource(deleteIconResId);
@ -392,6 +396,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
public void setKeyboardActionListener(final KeyboardActionListener listener) { public void setKeyboardActionListener(final KeyboardActionListener listener) {
mKeyboardActionListener = listener; mKeyboardActionListener = listener;
mDeleteKeyOnTouchListener.setKeyboardActionListener(listener);
} }
private void updateEmojiCategoryPageIdView() { private void updateEmojiCategoryPageIdView() {
@ -427,4 +432,52 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
mTabHost.setCurrentTab(newTabId); mTabHost.setCurrentTab(newTabId);
} }
} }
private static class DeleteKeyOnTouchListener implements OnTouchListener {
private KeyboardActionListener mKeyboardActionListener =
KeyboardActionListener.EMPTY_LISTENER;
public void setKeyboardActionListener(final KeyboardActionListener listener) {
mKeyboardActionListener = listener;
}
@Override
public boolean onTouch(final View v, final MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
onTouchDown(v);
return true;
case MotionEvent.ACTION_MOVE:
final float x = event.getX();
final float y = event.getY();
if (x < 0.0f || v.getWidth() < x || y < 0.0f || v.getHeight() < y) {
// Stop generating key events once the finger moves away from the view area.
onTouchCanceled(v);
}
return true;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
onTouchUp(v);
return true;
}
return false;
}
private void onTouchDown(final View v) {
mKeyboardActionListener.onPressKey(Constants.CODE_DELETE,
0 /* repeatCount */, true /* isSinglePointer */);
v.setPressed(true /* pressed */);
}
private void onTouchUp(final View v) {
mKeyboardActionListener.onCodeInput(Constants.CODE_DELETE,
NOT_A_COORDINATE, NOT_A_COORDINATE, false /* isKeyRepeat */);
mKeyboardActionListener.onReleaseKey(Constants.CODE_DELETE, false /* withSliding */);
v.setPressed(false /* pressed */);
}
private void onTouchCanceled(final View v) {
v.setBackgroundColor(Color.TRANSPARENT);
}
}
} }