Last big work on #1991910: Make swipes work with capacitive keys
This takes care of allowing us to cancel the back button. The back button is a bear because it is strewn all over the place -- everywhere you can close something, there is some code looking for the back button that now needs to deal with being canceled. The main things changed are activity (of course), dialog, input method, search dialog. There are some other misc places in the framework (and some I missed here that I will get in a second pass). To facility all of this, the key dispatching APIs now provide a lot more support for dealing with looking for cancelled keys, and incidentally also provide an actual API for catching long key presses. This also helped clean up the code in PhoneWindow where it deals with all of the combinations of key pressed and releases. (And also allows people to override Activity.onKeyLongPress() to provide a different long press action for a standard key like search.) And while I was doing this, I reworked how we detect long presses by having this be part of the key event delivered by the window manager. This should greatly reduce (hopefully outright eliminate) the problems with long presses being mis-detected when an application is being slow. Change-Id: Ia19066b8d588d573df3eee6d96e1c90fdc19f57d
This commit is contained in:
@@ -99,6 +99,7 @@ import android.view.RawInputEvent;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceSession;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.view.WindowManagerImpl;
|
||||
@@ -151,9 +152,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
|
||||
static final int LOG_WM_NO_SURFACE_MEMORY = 31000;
|
||||
|
||||
/** How long to wait for first key repeat, in milliseconds */
|
||||
static final int KEY_REPEAT_FIRST_DELAY = 750;
|
||||
|
||||
/** How long to wait for subsequent key repeats, in milliseconds */
|
||||
static final int KEY_REPEAT_DELAY = 50;
|
||||
|
||||
@@ -4900,6 +4898,16 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
return INJECT_SUCCEEDED;
|
||||
}
|
||||
|
||||
// Okay we have finished waiting for the last event to be processed.
|
||||
// First off, if this is a repeat event, check to see if there is
|
||||
// a corresponding up event in the queue. If there is, we will
|
||||
// just drop the repeat, because it makes no sense to repeat after
|
||||
// the user has released a key. (This is especially important for
|
||||
// long presses.)
|
||||
if (event.getRepeatCount() > 0 && mQueue.hasKeyUpEvent(event)) {
|
||||
return INJECT_SUCCEEDED;
|
||||
}
|
||||
|
||||
WindowState focus = (WindowState)focusObj;
|
||||
|
||||
if (DEBUG_INPUT) Log.v(
|
||||
@@ -6018,6 +6026,7 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
// Last keydown time for auto-repeating keys
|
||||
long lastKeyTime = SystemClock.uptimeMillis();
|
||||
long nextKeyTime = lastKeyTime+LONG_WAIT;
|
||||
long downTime = 0;
|
||||
|
||||
// How many successive repeats we generated
|
||||
int keyRepeatCount = 0;
|
||||
@@ -6088,15 +6097,17 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
KeyEvent ke = (KeyEvent)ev.event;
|
||||
if (ke.isDown()) {
|
||||
lastKey = ke;
|
||||
downTime = curTime;
|
||||
keyRepeatCount = 0;
|
||||
lastKeyTime = curTime;
|
||||
nextKeyTime = lastKeyTime
|
||||
+ KEY_REPEAT_FIRST_DELAY;
|
||||
+ ViewConfiguration.getLongPressTimeout();
|
||||
if (DEBUG_INPUT) Log.v(
|
||||
TAG, "Received key down: first repeat @ "
|
||||
+ nextKeyTime);
|
||||
} else {
|
||||
lastKey = null;
|
||||
downTime = 0;
|
||||
// Arbitrary long timeout.
|
||||
lastKeyTime = curTime;
|
||||
nextKeyTime = curTime + LONG_WAIT;
|
||||
@@ -6144,7 +6155,19 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
if (DEBUG_INPUT) Log.v(
|
||||
TAG, "Key repeat: count=" + keyRepeatCount
|
||||
+ ", next @ " + nextKeyTime);
|
||||
dispatchKey(KeyEvent.changeTimeRepeat(lastKey, curTime, keyRepeatCount), 0, 0);
|
||||
KeyEvent newEvent;
|
||||
if (downTime != 0 && (downTime
|
||||
+ ViewConfiguration.getLongPressTimeout())
|
||||
<= curTime) {
|
||||
newEvent = KeyEvent.changeTimeRepeat(lastKey,
|
||||
curTime, keyRepeatCount,
|
||||
lastKey.getFlags() | KeyEvent.FLAG_LONG_PRESS);
|
||||
downTime = 0;
|
||||
} else {
|
||||
newEvent = KeyEvent.changeTimeRepeat(lastKey,
|
||||
curTime, keyRepeatCount);
|
||||
}
|
||||
dispatchKey(newEvent, 0, 0);
|
||||
|
||||
} else {
|
||||
curTime = SystemClock.uptimeMillis();
|
||||
|
||||
Reference in New Issue
Block a user