diff options
| author | Karl Rosaen <krosaen@android.com> | 2009-09-04 11:15:21 -0700 |
|---|---|---|
| committer | Karl Rosaen <krosaen@android.com> | 2009-09-04 11:27:05 -0700 |
| commit | 7bafed8623d6835d0c9092ac2b852bb244a13fcf (patch) | |
| tree | 118934994c6a528627b64fb5f266f917c11c5c6f /core/java/android/app/Dialog.java | |
| parent | e5b6d02f34af2cd81615653b00c96a421d5ea819 (diff) | |
Do a better job at finding the activity associated with a dialog when triggering search.
It first looks to see if there is an activity that is managing the dialog, and if not,
follows the context / contextwrapper chain to find an activity if possible.
Fixes http://b/issue?id=2064772.
Diffstat (limited to 'core/java/android/app/Dialog.java')
| -rw-r--r-- | core/java/android/app/Dialog.java | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index 35d1004be107..1b96af9f2041 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -21,6 +21,7 @@ import com.android.internal.policy.PolicyManager; import android.content.Context; import android.content.DialogInterface; import android.content.ComponentName; +import android.content.ContextWrapper; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -801,14 +802,31 @@ public class Dialog implements DialogInterface, Window.Callback, // associate search with owner activity if possible (otherwise it will default to // global search). - final ComponentName appName = mOwnerActivity == null ? null - : mOwnerActivity.getComponentName(); + final ComponentName appName = getAssociatedActivity(); final boolean globalSearch = (appName == null); searchManager.startSearch(null, false, appName, null, globalSearch); dismiss(); return true; } + /** + * @return The activity associated with this dialog, or null if there is no assocaited activity. + */ + private ComponentName getAssociatedActivity() { + Activity activity = mOwnerActivity; + Context context = getContext(); + while (activity == null && context != null) { + if (context instanceof Activity) { + activity = (Activity) context; // found it! + } else { + context = (context instanceof ContextWrapper) ? + ((ContextWrapper) context).getBaseContext() : // unwrap one level + null; // done + } + } + return activity == null ? null : activity.getComponentName(); + } + /** * Request that key events come to this dialog. Use this if your |
