am 678b4c20: Merge change 25013 into eclair
Merge commit '678b4c20cb92ac2b86f13e52ea86d70301358680' into eclair-plus-aosp * commit '678b4c20cb92ac2b86f13e52ea86d70301358680': Various fixed for back key handling.
This commit is contained in:
@@ -34,6 +34,7 @@ import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -1752,8 +1753,16 @@ public class Activity extends ContextThemeWrapper
|
||||
*
|
||||
* <p>If the focused view didn't want this event, this method is called.
|
||||
*
|
||||
* <p>The default implementation sets up state to call
|
||||
* {@link #onKeyLongPress}, and does other default key handling
|
||||
* <p>The default implementation takes care of {@link KeyEvent#KEYCODE_BACK}
|
||||
* by calling {@link #onBackPressed()}, though the behavior varies based
|
||||
* on the application compatibility mode: for
|
||||
* {@link android.os.Build.VERSION_CODES#ECLAIR} or later applications,
|
||||
* it will set up the dispatch to call {@link #onKeyUp} where the action
|
||||
* will be performed; for earlier applications, it will perform the
|
||||
* action immediately in on-down, as those versions of the platform
|
||||
* behaved.
|
||||
*
|
||||
* <p>Other additional default key handling may be performed
|
||||
* if configured with {@link #setDefaultKeyMode}.
|
||||
*
|
||||
* @return Return <code>true</code> to prevent this event from being propagated
|
||||
@@ -1764,7 +1773,12 @@ public class Activity extends ContextThemeWrapper
|
||||
*/
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
event.startTracking();
|
||||
if (getApplicationInfo().targetSdkVersion
|
||||
>= Build.VERSION_CODES.ECLAIR) {
|
||||
event.startTracking();
|
||||
} else {
|
||||
onBackPressed();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1841,10 +1855,13 @@ public class Activity extends ContextThemeWrapper
|
||||
* @see KeyEvent
|
||||
*/
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
|
||||
&& !event.isCanceled()) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
if (getApplicationInfo().targetSdkVersion
|
||||
>= Build.VERSION_CODES.ECLAIR) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()
|
||||
&& !event.isCanceled()) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2016,11 +2033,14 @@ public class Activity extends ContextThemeWrapper
|
||||
*/
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
onUserInteraction();
|
||||
if (getWindow().superDispatchKeyEvent(event)) {
|
||||
Window win = getWindow();
|
||||
if (win.superDispatchKeyEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
return event.dispatch(this, mDecor != null
|
||||
? mDecor.getKeyDispatcherState() : null, this);
|
||||
View decor = mDecor;
|
||||
if (decor == null) decor = win.getDecorView();
|
||||
return event.dispatch(this, decor != null
|
||||
? decor.getKeyDispatcherState() : null, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,6 @@ import android.util.Log;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
@@ -1684,7 +1683,6 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
||||
public static class SearchAutoComplete extends AutoCompleteTextView {
|
||||
|
||||
private int mThreshold;
|
||||
private int mLastKeyDown;
|
||||
private SearchDialog mSearchDialog;
|
||||
|
||||
public SearchAutoComplete(Context context) {
|
||||
@@ -1765,26 +1763,26 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
||||
*/
|
||||
@Override
|
||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
||||
mLastKeyDown = keyCode;
|
||||
if (mSearchDialog.mSearchable == null) {
|
||||
return false;
|
||||
}
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
// We releae the back key, might we want to do
|
||||
// We release the back key, might we want to do
|
||||
// something before the IME?
|
||||
if (mSearchDialog.backToPreviousComponent(false)) {
|
||||
getKeyDispatcherState().startTracking(event, this);
|
||||
return true;
|
||||
}
|
||||
if (isInputMethodNotNeeded() ||
|
||||
(isEmpty() && getDropDownChildCount() >= getAdapterCount())) {
|
||||
getKeyDispatcherState().startTracking(event, this);
|
||||
return true;
|
||||
}
|
||||
mLastKeyDown = 0;
|
||||
return false; // will dismiss soft keyboard if necessary
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP
|
||||
&& mLastKeyDown == keyCode && !event.isCanceled()) {
|
||||
&& event.isTracking() && !event.isCanceled()) {
|
||||
if (mSearchDialog.backToPreviousComponent(true)) {
|
||||
return true;
|
||||
}
|
||||
@@ -1815,8 +1813,10 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
||||
|
||||
protected boolean handleBackKey(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
// Consume the event, to get an up at which point we execute.
|
||||
event.startTracking();
|
||||
return true;
|
||||
}
|
||||
if (event.getAction() == KeyEvent.ACTION_UP && event.isTracking()
|
||||
|
||||
@@ -143,6 +143,9 @@ public class Build {
|
||||
* Service.onStartCommand} function will return the new
|
||||
* {@link android.app.Service#START_STICKY} behavior instead of the
|
||||
* old compatibility {@link android.app.Service#START_STICKY_COMPATIBILITY}.
|
||||
* <li> The {@link android.app.Activity} class will now execute back
|
||||
* key presses on the key up instead of key down, to be able to detect
|
||||
* canceled presses from virtual keys.
|
||||
* </ul>
|
||||
*/
|
||||
public static final int ECLAIR = CUR_DEVELOPMENT;
|
||||
|
||||
@@ -18,6 +18,7 @@ package android.view;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyCharacterMap.KeyData;
|
||||
@@ -319,6 +320,9 @@ public class KeyEvent implements Parcelable {
|
||||
return KeyCharacterMap.getDeadChar(accent, c);
|
||||
}
|
||||
|
||||
static final boolean DEBUG = false;
|
||||
static final String TAG = "KeyEvent";
|
||||
|
||||
private int mMetaState;
|
||||
private int mAction;
|
||||
private int mKeyCode;
|
||||
@@ -1028,13 +1032,17 @@ public class KeyEvent implements Parcelable {
|
||||
switch (mAction) {
|
||||
case ACTION_DOWN: {
|
||||
mFlags &= ~FLAG_START_TRACKING;
|
||||
if (DEBUG) Log.v(TAG, "Key down to " + target + " in " + state
|
||||
+ ": " + this);
|
||||
boolean res = receiver.onKeyDown(mKeyCode, this);
|
||||
if (state != null) {
|
||||
if (res && mRepeatCount == 0 && (mFlags&FLAG_START_TRACKING) != 0) {
|
||||
if (DEBUG) Log.v(TAG, " Start tracking!");
|
||||
state.startTracking(this, target);
|
||||
} else if (isLongPress() && state.isTracking(this)) {
|
||||
try {
|
||||
if (receiver.onKeyLongPress(mKeyCode, this)) {
|
||||
if (DEBUG) Log.v(TAG, " Clear from long press!");
|
||||
state.performedLongPress(this);
|
||||
res = true;
|
||||
}
|
||||
@@ -1045,6 +1053,8 @@ public class KeyEvent implements Parcelable {
|
||||
return res;
|
||||
}
|
||||
case ACTION_UP:
|
||||
if (DEBUG) Log.v(TAG, "Key up to " + target + " in " + state
|
||||
+ ": " + this);
|
||||
if (state != null) {
|
||||
state.handleUpEvent(this);
|
||||
}
|
||||
@@ -1085,6 +1095,7 @@ public class KeyEvent implements Parcelable {
|
||||
* Reset back to initial state.
|
||||
*/
|
||||
public void reset() {
|
||||
if (DEBUG) Log.v(TAG, "Reset: " + this);
|
||||
mDownKeyCode = 0;
|
||||
mDownTarget = null;
|
||||
mActiveLongPresses.clear();
|
||||
@@ -1095,6 +1106,7 @@ public class KeyEvent implements Parcelable {
|
||||
*/
|
||||
public void reset(Object target) {
|
||||
if (mDownTarget == target) {
|
||||
if (DEBUG) Log.v(TAG, "Reset in " + target + ": " + this);
|
||||
mDownKeyCode = 0;
|
||||
mDownTarget = null;
|
||||
}
|
||||
@@ -1115,6 +1127,7 @@ public class KeyEvent implements Parcelable {
|
||||
throw new IllegalArgumentException(
|
||||
"Can only start tracking on a down event");
|
||||
}
|
||||
if (DEBUG) Log.v(TAG, "Start trackingt in " + target + ": " + this);
|
||||
mDownKeyCode = event.getKeyCode();
|
||||
mDownTarget = target;
|
||||
}
|
||||
@@ -1145,12 +1158,15 @@ public class KeyEvent implements Parcelable {
|
||||
*/
|
||||
public void handleUpEvent(KeyEvent event) {
|
||||
final int keyCode = event.getKeyCode();
|
||||
if (DEBUG) Log.v(TAG, "Handle key up " + event + ": " + this);
|
||||
int index = mActiveLongPresses.indexOfKey(keyCode);
|
||||
if (index >= 0) {
|
||||
if (DEBUG) Log.v(TAG, " Index: " + index);
|
||||
event.mFlags |= FLAG_CANCELED | FLAG_CANCELED_LONG_PRESS;
|
||||
mActiveLongPresses.removeAt(index);
|
||||
}
|
||||
if (mDownKeyCode == keyCode) {
|
||||
if (DEBUG) Log.v(TAG, " Tracking!");
|
||||
event.mFlags |= FLAG_TRACKING;
|
||||
mDownKeyCode = 0;
|
||||
mDownTarget = null;
|
||||
|
||||
@@ -2946,7 +2946,9 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
|
||||
break;
|
||||
case KeyEvent.KEYCODE_BACK:
|
||||
if (mFiltered && mPopup != null && mPopup.isShowing()) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
getKeyDispatcherState().startTracking(event, this);
|
||||
handled = true;
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP
|
||||
&& event.isTracking() && !event.isCanceled()) {
|
||||
|
||||
@@ -132,8 +132,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
|
||||
|
||||
private AutoCompleteTextView.PassThroughClickListener mPassThroughClickListener;
|
||||
|
||||
private int mDownKeyCode;
|
||||
|
||||
public AutoCompleteTextView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -605,19 +603,18 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
|
||||
|
||||
@Override
|
||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
mDownKeyCode = keyCode;
|
||||
}
|
||||
if (isPopupShowing()) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && isPopupShowing()
|
||||
&& !mDropDownAlwaysVisible) {
|
||||
// special case for the back key, we do not even try to send it
|
||||
// to the drop down list but instead, consume it immediately
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && !mDropDownAlwaysVisible) {
|
||||
if (event.getAction() == KeyEvent.ACTION_UP
|
||||
&& mDownKeyCode == keyCode && !event.isCanceled()) {
|
||||
dismissDropDown();
|
||||
return true;
|
||||
}
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
getKeyDispatcherState().startTracking(event, this);
|
||||
return true;
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP
|
||||
&& event.isTracking() && !event.isCanceled()) {
|
||||
dismissDropDown();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onKeyPreIme(keyCode, event);
|
||||
@@ -1026,7 +1023,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
super.onWindowFocusChanged(hasWindowFocus);
|
||||
mDownKeyCode = 0;
|
||||
performValidation();
|
||||
if (!hasWindowFocus && !mDropDownAlwaysVisible) {
|
||||
dismissDropDown();
|
||||
@@ -1036,7 +1032,6 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
|
||||
@Override
|
||||
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
|
||||
super.onFocusChanged(focused, direction, previouslyFocusedRect);
|
||||
mDownKeyCode = 0;
|
||||
performValidation();
|
||||
if (!focused && !mDropDownAlwaysVisible) {
|
||||
dismissDropDown();
|
||||
|
||||
@@ -1323,8 +1323,16 @@ public class PopupWindow {
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
|
||||
dismiss();
|
||||
return true;
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
getKeyDispatcherState().startTracking(event, this);
|
||||
return true;
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP
|
||||
&& event.isTracking() && !event.isCanceled()) {
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
} else {
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@@ -476,7 +476,21 @@ public class ZoomButtonsController implements View.OnTouchListener {
|
||||
if (isInterestingKey(keyCode)) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
setVisible(false);
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
if (mOwnerView != null) {
|
||||
KeyEvent.DispatcherState ds = mOwnerView.getKeyDispatcherState();
|
||||
if (ds != null) {
|
||||
ds.startTracking(event, this);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP
|
||||
&& event.isTracking() && !event.isCanceled()) {
|
||||
setVisible(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.DialogInterface;
|
||||
import android.os.IBinder;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ListAdapter;
|
||||
|
||||
@@ -86,18 +87,26 @@ public class MenuDialogHelper implements DialogInterface.OnKeyListener, DialogIn
|
||||
}
|
||||
|
||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
||||
/*
|
||||
* Close menu on key down (more responsive, and there's no way to cancel
|
||||
* a key press so no point having it on key up. Note: This is also
|
||||
* needed because when a top-level menu item that shows a submenu is
|
||||
* invoked by chording, this onKey method will be called with the menu
|
||||
* up event.
|
||||
*/
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN && (keyCode == KeyEvent.KEYCODE_MENU)
|
||||
|| (keyCode == KeyEvent.KEYCODE_BACK)) {
|
||||
mMenu.close(true);
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN
|
||||
&& event.getRepeatCount() == 0) {
|
||||
Window win = mDialog.getWindow();
|
||||
if (win != null) {
|
||||
View decor = win.getDecorView();
|
||||
if (decor != null) {
|
||||
KeyEvent.DispatcherState ds = decor.getKeyDispatcherState();
|
||||
if (ds != null) {
|
||||
ds.startTracking(event, this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP
|
||||
&& event.isTracking() && !event.isCanceled()) {
|
||||
mMenu.close(true);
|
||||
dialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Menu shortcut matching
|
||||
|
||||
Reference in New Issue
Block a user