From 6a975b3c3597a4ad9202432f3c3d867a03d43fa4 Mon Sep 17 00:00:00 2001
From: Tim Kilbourn
Date: Thu, 9 Apr 2015 17:14:34 -0700
Subject: Save search context when dispatching onSearchRequested.
The InputDevice used to trigger the search is saved in a SearchEvent
so an application implementing onSearchRequested determine the device
triggering the search.
Bug: 15374820
Change-Id: If2cd14f77ce572a5ee131697cd63145fbea63f27
---
core/java/android/app/Activity.java | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
(limited to 'core/java/android/app/Activity.java')
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index a0d59d9..6cf6481 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -89,6 +89,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.PhoneWindow;
+import android.view.SearchEvent;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
@@ -787,6 +788,8 @@ public class Activity extends ContextThemeWrapper
private TranslucentConversionListener mTranslucentCallback;
private boolean mChangeCanvasToTranslucent;
+ private SearchEvent mSearchEvent;
+
private boolean mTitleReady = false;
private int mActionModeTypeStarting = ActionMode.TYPE_PRIMARY;
@@ -3547,12 +3550,23 @@ public class Activity extends ContextThemeWrapper
* implementation changes to simply return false and you must supply your own custom
* implementation if you want to support search.
*
+ * @param searchEvent The {@link SearchEvent} that signaled this search.
* @return Returns {@code true} if search launched, and {@code false} if the activity does
* not respond to search. The default implementation always returns {@code true}, except
* when in {@link Configuration#UI_MODE_TYPE_TELEVISION} mode where it returns false.
*
* @see android.app.SearchManager
*/
+ public boolean onSearchRequested(@Nullable SearchEvent searchEvent) {
+ mSearchEvent = searchEvent;
+ boolean result = onSearchRequested();
+ mSearchEvent = null;
+ return result;
+ }
+
+ /**
+ * @see #onSearchRequested(SearchEvent)
+ */
public boolean onSearchRequested() {
if ((getResources().getConfiguration().uiMode&Configuration.UI_MODE_TYPE_MASK)
!= Configuration.UI_MODE_TYPE_TELEVISION) {
@@ -3564,6 +3578,17 @@ public class Activity extends ContextThemeWrapper
}
/**
+ * During the onSearchRequested() callbacks, this function will return the
+ * {@link SearchEvent} that triggered the callback, if it exists.
+ *
+ * @return SearchEvent The SearchEvent that triggered the {@link
+ * #onSearchRequested} callback.
+ */
+ public final SearchEvent getSearchEvent() {
+ return mSearchEvent;
+ }
+
+ /**
* This hook is called to launch the search UI.
*
* It is typically called from onSearchRequested(), either directly from
--
cgit v1.1