Implement delete key repeater
Bug: 10810844 Change-Id: Idbfe2196e8f0f8cf6dd1b77574eefb395c12807a
This commit is contained in:
parent
f3cd38f2c7
commit
9204d11525
3 changed files with 104 additions and 4 deletions
|
@ -40,7 +40,7 @@
|
||||||
<TabWidget
|
<TabWidget
|
||||||
android:id="@android:id/tabs"
|
android:id="@android:id/tabs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:background="@drawable/tab_selected"
|
android:background="@drawable/tab_selected"
|
||||||
android:divider="@null"
|
android:divider="@null"
|
||||||
android:tabStripEnabled="true"
|
android:tabStripEnabled="true"
|
||||||
|
@ -61,11 +61,16 @@
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</TabHost>
|
</TabHost>
|
||||||
|
<View
|
||||||
|
android:layout_width="2dip"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@drawable/suggestions_strip_divider" />
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/emoji_keyboard_delete"
|
android:id="@+id/emoji_keyboard_delete"
|
||||||
android:layout_width="0dip"
|
android:layout_width="0dip"
|
||||||
android:layout_weight="12.5"
|
android:layout_weight="12.5"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/emoji_key_background_color"
|
||||||
android:src="@drawable/sym_keyboard_delete_holo_dark" />
|
android:src="@drawable/sym_keyboard_delete_holo_dark" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<android.support.v4.view.ViewPager
|
<android.support.v4.view.ViewPager
|
||||||
|
|
|
@ -62,4 +62,8 @@
|
||||||
<color name="setup_welcome_video_margin_color">#FFCCCCCC</color>
|
<color name="setup_welcome_video_margin_color">#FFCCCCCC</color>
|
||||||
<color name="emoji_category_page_id_view_background">#FF000000</color>
|
<color name="emoji_category_page_id_view_background">#FF000000</color>
|
||||||
<color name="emoji_category_page_id_view_foreground">#80FFFFFF</color>
|
<color name="emoji_category_page_id_view_foreground">#80FFFFFF</color>
|
||||||
|
|
||||||
|
<!-- TODO: Color which should be included in the theme -->
|
||||||
|
<color name="emoji_key_background_color">#00000000</color>
|
||||||
|
<color name="emoji_key_pressed_background_color">#30FFFFFF</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -28,11 +28,13 @@ import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.view.PagerAdapter;
|
import android.support.v4.view.PagerAdapter;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
import android.util.AttributeSet;
|
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.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -76,6 +78,7 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange
|
||||||
private final int mEmojiFunctionalKeyBackgroundId;
|
private final int mEmojiFunctionalKeyBackgroundId;
|
||||||
private final KeyboardLayoutSet mLayoutSet;
|
private final KeyboardLayoutSet mLayoutSet;
|
||||||
private final ColorStateList mTabLabelColor;
|
private final ColorStateList mTabLabelColor;
|
||||||
|
private final DeleteKeyOnTouchListener mDeleteKeyOnTouchListener;
|
||||||
private EmojiKeyboardAdapter mEmojiKeyboardAdapter;
|
private EmojiKeyboardAdapter mEmojiKeyboardAdapter;
|
||||||
|
|
||||||
private TabHost mTabHost;
|
private TabHost mTabHost;
|
||||||
|
@ -395,6 +398,7 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange
|
||||||
mLayoutSet = builder.build();
|
mLayoutSet = builder.build();
|
||||||
mEmojiCategory = new EmojiCategory(PreferenceManager.getDefaultSharedPreferences(context),
|
mEmojiCategory = new EmojiCategory(PreferenceManager.getDefaultSharedPreferences(context),
|
||||||
context.getResources(), builder.build());
|
context.getResources(), builder.build());
|
||||||
|
mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -459,11 +463,9 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange
|
||||||
final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
|
final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
|
||||||
emojiLp.setActionBarProperties(actionBar);
|
emojiLp.setActionBarProperties(actionBar);
|
||||||
|
|
||||||
// TODO: Implement auto repeat, using View.OnTouchListener?
|
|
||||||
final ImageView deleteKey = (ImageView)findViewById(R.id.emoji_keyboard_delete);
|
final ImageView deleteKey = (ImageView)findViewById(R.id.emoji_keyboard_delete);
|
||||||
deleteKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
|
|
||||||
deleteKey.setTag(Constants.CODE_DELETE);
|
deleteKey.setTag(Constants.CODE_DELETE);
|
||||||
deleteKey.setOnClickListener(this);
|
deleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);
|
||||||
final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet);
|
final ImageView alphabetKey = (ImageView)findViewById(R.id.emoji_keyboard_alphabet);
|
||||||
alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
|
alphabetKey.setBackgroundResource(mEmojiFunctionalKeyBackgroundId);
|
||||||
alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
|
alphabetKey.setTag(Constants.CODE_SWITCH_ALPHA_SYMBOL);
|
||||||
|
@ -556,6 +558,7 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange
|
||||||
|
|
||||||
public void setKeyboardActionListener(final KeyboardActionListener listener) {
|
public void setKeyboardActionListener(final KeyboardActionListener listener) {
|
||||||
mKeyboardActionListener = listener;
|
mKeyboardActionListener = listener;
|
||||||
|
mDeleteKeyOnTouchListener.setKeyboardActionListener(mKeyboardActionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateEmojiCategoryPageIdView() {
|
private void updateEmojiCategoryPageIdView() {
|
||||||
|
@ -665,4 +668,92 @@ public final class EmojiKeyboardView extends LinearLayout implements OnTabChange
|
||||||
container.removeView(keyboardView);
|
container.removeView(keyboardView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Do the same things done in PointerTracker
|
||||||
|
private static class DeleteKeyOnTouchListener implements OnTouchListener {
|
||||||
|
private static final long MAX_REPEAT_COUNT_TIME = 30 * DateUtils.SECOND_IN_MILLIS;
|
||||||
|
private final int mDeleteKeyPressedBackgroundColor;
|
||||||
|
private final long mKeyRepeatStartTimeout;
|
||||||
|
private final long mKeyRepeatInterval;
|
||||||
|
|
||||||
|
public DeleteKeyOnTouchListener(Context context) {
|
||||||
|
final Resources res = context.getResources();
|
||||||
|
mDeleteKeyPressedBackgroundColor =
|
||||||
|
res.getColor(R.color.emoji_key_pressed_background_color);
|
||||||
|
mKeyRepeatStartTimeout = res.getInteger(R.integer.config_key_repeat_start_timeout);
|
||||||
|
mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeyboardActionListener mKeyboardActionListener =
|
||||||
|
KeyboardActionListener.EMPTY_LISTENER;
|
||||||
|
private DummyRepeatKeyRepeatTimer mTimer;
|
||||||
|
|
||||||
|
private synchronized void startRepeat() {
|
||||||
|
if (mTimer != null) {
|
||||||
|
abortRepeat();
|
||||||
|
}
|
||||||
|
mTimer = new DummyRepeatKeyRepeatTimer();
|
||||||
|
mTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void abortRepeat() {
|
||||||
|
mTimer.abort();
|
||||||
|
mTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove
|
||||||
|
// This function is mimicking the repeat code in PointerTracker.
|
||||||
|
// Specifically referring to PointerTracker#startRepeatKey and PointerTracker#onKeyRepeat.
|
||||||
|
private class DummyRepeatKeyRepeatTimer extends Thread {
|
||||||
|
public boolean mAborted = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int timeCount = 0;
|
||||||
|
while (timeCount < MAX_REPEAT_COUNT_TIME && !mAborted) {
|
||||||
|
if (timeCount > mKeyRepeatStartTimeout) {
|
||||||
|
pressDelete();
|
||||||
|
}
|
||||||
|
timeCount += mKeyRepeatInterval;
|
||||||
|
try {
|
||||||
|
Thread.sleep(mKeyRepeatInterval);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abort() {
|
||||||
|
mAborted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pressDelete() {
|
||||||
|
mKeyboardActionListener.onPressKey(
|
||||||
|
Constants.CODE_DELETE, 0 /* repeatCount */, true /* isSinglePointer */);
|
||||||
|
mKeyboardActionListener.onCodeInput(
|
||||||
|
Constants.CODE_DELETE, NOT_A_COORDINATE, NOT_A_COORDINATE);
|
||||||
|
mKeyboardActionListener.onReleaseKey(
|
||||||
|
Constants.CODE_DELETE, false /* withSliding */);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyboardActionListener(KeyboardActionListener listener) {
|
||||||
|
mKeyboardActionListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
switch(event.getAction()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
v.setBackgroundColor(mDeleteKeyPressedBackgroundColor);
|
||||||
|
pressDelete();
|
||||||
|
startRepeat();
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
v.setBackgroundColor(0);
|
||||||
|
abortRepeat();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue