summaryrefslogtreecommitdiffstats
path: root/core/java/android/server
diff options
context:
space:
mode:
authorKarl Rosaen <krosaen@google.com>2009-07-20 09:26:10 -0700
committerKarl Rosaen <krosaen@google.com>2009-07-20 14:08:24 -0700
commitea52d29bc46c306f3607d121aa1ad84f0e9eb473 (patch)
tree9da84f5d18f0f336509e5594185a0c6e3f02f8e6 /core/java/android/server
parent5f6133a100d4477dfcea919e81ff301f9352cd32 (diff)
downloadframeworks_base-ea52d29bc46c306f3607d121aa1ad84f0e9eb473.zip
frameworks_base-ea52d29bc46c306f3607d121aa1ad84f0e9eb473.tar.gz
frameworks_base-ea52d29bc46c306f3607d121aa1ad84f0e9eb473.tar.bz2
Fix back key handling for search dialog.
Now that the search manager service handles hiding (not dismissing) and reshowing it when the user hits back after launching a result, search manager can't cache "mShowing". Also noticed a few other minor problems that was hosing the handling of pause / resume to reshow the dialog, like moving some logic to onHide instead of onDismiss.
Diffstat (limited to 'core/java/android/server')
-rw-r--r--core/java/android/server/search/SearchDialogWrapper.java102
-rw-r--r--core/java/android/server/search/SearchManagerService.java4
2 files changed, 62 insertions, 44 deletions
diff --git a/core/java/android/server/search/SearchDialogWrapper.java b/core/java/android/server/search/SearchDialogWrapper.java
index 70c7d73..d3ef5de 100644
--- a/core/java/android/server/search/SearchDialogWrapper.java
+++ b/core/java/android/server/search/SearchDialogWrapper.java
@@ -45,8 +45,6 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
private static final String TAG = "SearchManagerService";
private static final boolean DBG = false;
- private static final String DISABLE_SEARCH_PROPERTY = "dev.disablesearchdialog";
-
private static final String SEARCH_UI_THREAD_NAME = "SearchDialog";
private static final int SEARCH_UI_THREAD_PRIORITY =
android.os.Process.THREAD_PRIORITY_DEFAULT;
@@ -88,12 +86,11 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
// Identity of currently resumed activity.
private int mResumedIdent = 0;
-
- // Allows disabling of search dialog for stress testing runs
- private final boolean mDisabledOnBoot;
// True if we have registered our receivers.
private boolean mReceiverRegistered;
+
+ private volatile boolean mVisible = false;
/**
* Creates a new search dialog wrapper and a search UI thread. The search dialog itself will
@@ -104,8 +101,6 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
public SearchDialogWrapper(Context context) {
mContext = context;
- mDisabledOnBoot = !TextUtils.isEmpty(SystemProperties.get(DISABLE_SEARCH_PROPERTY));
-
// Create the search UI thread
HandlerThread t = new HandlerThread(SEARCH_UI_THREAD_NAME, SEARCH_UI_THREAD_PRIORITY);
t.start();
@@ -115,6 +110,10 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
mSearchUiThread.sendEmptyMessage(MSG_INIT);
}
+ public boolean isVisible() {
+ return mVisible;
+ }
+
/**
* Initializes the search UI.
* Must be called from the search UI thread.
@@ -151,8 +150,10 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
- if (DBG) debug(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
- performStopSearch();
+ if (!"search".equals(intent.getStringExtra("reason"))) {
+ if (DBG) debug(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+ performStopSearch();
+ }
} else if (Intent.ACTION_CONFIGURATION_CHANGED.equals(action)) {
if (DBG) debug(Intent.ACTION_CONFIGURATION_CHANGED);
performOnConfigurationChanged();
@@ -205,7 +206,7 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
* Can be called from any thread.
*/
public void activityResuming(int ident) {
- if (DBG) debug("startSearch()");
+ if (DBG) debug("activityResuming(ident=" + ident + ")");
Message msg = Message.obtain();
msg.what = MSG_ACTIVITY_RESUMING;
msg.arg1 = ident;
@@ -256,20 +257,6 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
}
- void updateDialogVisibility() {
- if (mStartedIdent != 0) {
- // mResumedIdent == 0 means we have just booted and the user
- // hasn't yet gone anywhere.
- if (mResumedIdent == 0 || mStartedIdent == mResumedIdent) {
- if (DBG) Log.v(TAG, "******************* DIALOG: show");
- mSearchDialog.show();
- } else {
- if (DBG) Log.v(TAG, "******************* DIALOG: hide");
- mSearchDialog.hide();
- }
- }
- }
-
/**
* Actually launches the search UI.
* This must be called on the search UI thread.
@@ -283,19 +270,20 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
int ident) {
if (DBG) debug("performStartSearch()");
- if (mDisabledOnBoot) {
- Log.d(TAG, "ignoring start search request because " + DISABLE_SEARCH_PROPERTY
- + " system property is set.");
- return;
- }
-
registerBroadcastReceiver();
mCallback = searchManagerCallback;
+
+ // clean up any hidden dialog that we were waiting to resume
+ if (mStartedIdent != 0) {
+ mSearchDialog.dismiss();
+ }
+
mStartedIdent = ident;
if (DBG) Log.v(TAG, "******************* DIALOG: start");
+
mSearchDialog.show(initialQuery, selectInitialQuery, launchActivity, appSearchData,
globalSearch);
- updateDialogVisibility();
+ mVisible = true;
}
/**
@@ -306,6 +294,7 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
if (DBG) debug("performStopSearch()");
if (DBG) Log.v(TAG, "******************* DIALOG: cancel");
mSearchDialog.cancel();
+ mVisible = false;
mStartedIdent = 0;
}
@@ -317,7 +306,21 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
if (DBG) debug("performResumingActivity(): mStartedIdent="
+ mStartedIdent + ", resuming: " + ident);
this.mResumedIdent = ident;
- updateDialogVisibility();
+ if (mStartedIdent != 0) {
+ if (mStartedIdent == mResumedIdent) {
+ // we are resuming into the activity where we previously hid the dialog, bring it
+ // back
+ if (DBG) Log.v(TAG, "******************* DIALOG: show");
+ mSearchDialog.show();
+ mVisible = true;
+ } else {
+ // resuming into some other activity; hide ourselves in case we ever come back
+ // so we can show ourselves quickly again
+ if (DBG) Log.v(TAG, "******************* DIALOG: hide");
+ mSearchDialog.hide();
+ mVisible = false;
+ }
+ }
}
/**
@@ -333,27 +336,38 @@ implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
*/
public void onDismiss(DialogInterface dialog) {
if (DBG) debug("onDismiss()");
- if (mCallback != null) {
- try {
- // should be safe to do on the search UI thread, since it's a oneway interface
- mCallback.onDismiss();
- } catch (DeadObjectException ex) {
- // The process that hosted the callback has died, do nothing
- } catch (RemoteException ex) {
- Log.e(TAG, "onDismiss() failed: " + ex);
- }
- // we don't need the callback anymore, release it
- mCallback = null;
- }
+ mStartedIdent = 0;
+ mVisible = false;
+ callOnDismiss();
+
+ // we don't need the callback anymore, release it
+ mCallback = null;
unregisterBroadcastReceiver();
}
+
/**
* Called by {@link SearchDialog} when the user or activity cancels search.
* Whenever this method is called, {@link #onDismiss} is always called afterwards.
*/
public void onCancel(DialogInterface dialog) {
if (DBG) debug("onCancel()");
+ callOnCancel();
+ }
+
+ private void callOnDismiss() {
+ if (mCallback == null) return;
+ try {
+ // should be safe to do on the search UI thread, since it's a oneway interface
+ mCallback.onDismiss();
+ } catch (DeadObjectException ex) {
+ // The process that hosted the callback has died, do nothing
+ } catch (RemoteException ex) {
+ Log.e(TAG, "onDismiss() failed: " + ex);
+ }
+ }
+
+ private void callOnCancel() {
if (mCallback != null) {
try {
// should be safe to do on the search UI thread, since it's a oneway interface
diff --git a/core/java/android/server/search/SearchManagerService.java b/core/java/android/server/search/SearchManagerService.java
index 7629912..fdeb8f9 100644
--- a/core/java/android/server/search/SearchManagerService.java
+++ b/core/java/android/server/search/SearchManagerService.java
@@ -238,4 +238,8 @@ public class SearchManagerService extends ISearchManager.Stub {
getSearchDialog().stopSearch();
}
+ public boolean isVisible() {
+ return mSearchDialog != null && mSearchDialog.isVisible();
+ }
+
}