aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorDan Zivkovic <zivkovic@google.com>2015-02-04 18:15:28 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-02-04 18:15:28 +0000
commitdaa3ad860532e4285551005943d0e4263a1f3d2b (patch)
tree7d616d6bc98b08bcf5b80284cc101820fe11e3e3 /java
parent449711dd199354cbeaaa6dcf767c3c29a333d18d (diff)
parent00ae43316ed33df2b845023069b0b2b578982fc8 (diff)
downloadlatinime-daa3ad860532e4285551005943d0e4263a1f3d2b.tar.gz
latinime-daa3ad860532e4285551005943d0e4263a1f3d2b.tar.xz
latinime-daa3ad860532e4285551005943d0e4263a1f3d2b.zip
Merge "Fix delete handling in Emoji keyboard."
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java57
1 files changed, 55 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
index 9ab465207..f4c4f1aab 100644
--- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
+++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
@@ -21,6 +21,7 @@ import static com.android.inputmethod.latin.common.Constants.NOT_A_COORDINATE;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.graphics.Color;
import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
@@ -73,6 +74,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
private final int mCategoryPageIndicatorBackground;
private EmojiPalettesAdapter mEmojiPalettesAdapter;
private final EmojiLayoutParams mEmojiLayoutParams;
+ private final DeleteKeyOnTouchListener mDeleteKeyOnTouchListener;
private ImageButton mDeleteKey;
private TextView mAlphabetKeyLeft;
@@ -127,6 +129,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
mCategoryPageIndicatorBackground = emojiPalettesViewAttr.getColor(
R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0);
emojiPalettesViewAttr.recycle();
+ mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener();
}
@Override
@@ -197,7 +200,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
mDeleteKey.setTag(Constants.CODE_DELETE);
- mDeleteKey.setOnTouchListener(this);
+ mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
// {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
// {@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,
- final KeyVisualAttributes keyVisualAttr, final KeyboardIconsSet iconSet) {
+ final KeyVisualAttributes keyVisualAttr,
+ final KeyboardIconsSet iconSet) {
final int deleteIconResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_DELETE_KEY);
if (deleteIconResId != 0) {
mDeleteKey.setImageResource(deleteIconResId);
@@ -392,6 +396,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
public void setKeyboardActionListener(final KeyboardActionListener listener) {
mKeyboardActionListener = listener;
+ mDeleteKeyOnTouchListener.setKeyboardActionListener(listener);
}
private void updateEmojiCategoryPageIdView() {
@@ -427,4 +432,52 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
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);
+ }
+ }
} \ No newline at end of file