diff options
-rw-r--r-- | api/current.txt | 10 | ||||
-rw-r--r-- | api/system-current.txt | 10 | ||||
-rw-r--r-- | core/java/android/app/Activity.java | 25 | ||||
-rw-r--r-- | core/java/android/app/Dialog.java | 22 | ||||
-rw-r--r-- | core/java/android/service/dreams/DreamService.java | 7 | ||||
-rw-r--r-- | core/java/android/view/PhoneWindow.java | 11 | ||||
-rw-r--r-- | core/java/android/view/SearchEvent.java | 40 | ||||
-rw-r--r-- | core/java/android/view/Window.java | 9 | ||||
-rw-r--r-- | core/java/android/view/WindowCallbackWrapper.java | 5 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/android/view/WindowCallback.java | 5 |
10 files changed, 141 insertions, 3 deletions
diff --git a/api/current.txt b/api/current.txt index 937cd19..66c0447 100644 --- a/api/current.txt +++ b/api/current.txt @@ -3353,6 +3353,7 @@ package android.app { method public android.content.SharedPreferences getPreferences(int); method public android.net.Uri getReferrer(); method public int getRequestedOrientation(); + method public final android.view.SearchEvent getSearchEvent(); method public int getTaskId(); method public final java.lang.CharSequence getTitle(); method public final int getTitleColor(); @@ -3435,6 +3436,7 @@ package android.app { method public deprecated java.lang.Object onRetainNonConfigurationInstance(); method protected void onSaveInstanceState(android.os.Bundle); method public void onSaveInstanceState(android.os.Bundle, android.os.PersistableBundle); + method public boolean onSearchRequested(android.view.SearchEvent); method public boolean onSearchRequested(); method protected void onStart(); method protected void onStop(); @@ -4112,6 +4114,7 @@ package android.app { method public android.view.View getCurrentFocus(); method public android.view.LayoutInflater getLayoutInflater(); method public final android.app.Activity getOwnerActivity(); + method public final android.view.SearchEvent getSearchEvent(); method public final int getVolumeControlStream(); method public android.view.Window getWindow(); method public void hide(); @@ -4145,6 +4148,7 @@ package android.app { method public boolean onPreparePanel(int, android.view.View, android.view.Menu); method public void onRestoreInstanceState(android.os.Bundle); method public android.os.Bundle onSaveInstanceState(); + method public boolean onSearchRequested(android.view.SearchEvent); method public boolean onSearchRequested(); method protected void onStart(); method protected void onStop(); @@ -28214,6 +28218,7 @@ package android.service.dreams { method public boolean onMenuOpened(int, android.view.Menu); method public void onPanelClosed(int, android.view.Menu); method public boolean onPreparePanel(int, android.view.View, android.view.Menu); + method public boolean onSearchRequested(android.view.SearchEvent); method public boolean onSearchRequested(); method public void onWakeUp(); method public void onWindowAttributesChanged(android.view.WindowManager.LayoutParams); @@ -34556,6 +34561,10 @@ package android.view { method public void onScaleEnd(android.view.ScaleGestureDetector); } + public class SearchEvent { + method public android.view.InputDevice getInputDevice(); + } + public class SoundEffectConstants { method public static int getContantForFocusDirection(int); field public static final int CLICK = 0; // 0x0 @@ -36078,6 +36087,7 @@ package android.view { method public abstract void onPanelClosed(int, android.view.Menu); method public abstract boolean onPreparePanel(int, android.view.View, android.view.Menu); method public abstract boolean onSearchRequested(); + method public abstract boolean onSearchRequested(android.view.SearchEvent); method public abstract void onWindowAttributesChanged(android.view.WindowManager.LayoutParams); method public abstract void onWindowFocusChanged(boolean); method public abstract android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback); diff --git a/api/system-current.txt b/api/system-current.txt index 2117602..7694bf5 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -3435,6 +3435,7 @@ package android.app { method public android.content.SharedPreferences getPreferences(int); method public android.net.Uri getReferrer(); method public int getRequestedOrientation(); + method public final android.view.SearchEvent getSearchEvent(); method public int getTaskId(); method public final java.lang.CharSequence getTitle(); method public final int getTitleColor(); @@ -3519,6 +3520,7 @@ package android.app { method public deprecated java.lang.Object onRetainNonConfigurationInstance(); method protected void onSaveInstanceState(android.os.Bundle); method public void onSaveInstanceState(android.os.Bundle, android.os.PersistableBundle); + method public boolean onSearchRequested(android.view.SearchEvent); method public boolean onSearchRequested(); method protected void onStart(); method protected void onStop(); @@ -4203,6 +4205,7 @@ package android.app { method public android.view.View getCurrentFocus(); method public android.view.LayoutInflater getLayoutInflater(); method public final android.app.Activity getOwnerActivity(); + method public final android.view.SearchEvent getSearchEvent(); method public final int getVolumeControlStream(); method public android.view.Window getWindow(); method public void hide(); @@ -4236,6 +4239,7 @@ package android.app { method public boolean onPreparePanel(int, android.view.View, android.view.Menu); method public void onRestoreInstanceState(android.os.Bundle); method public android.os.Bundle onSaveInstanceState(); + method public boolean onSearchRequested(android.view.SearchEvent); method public boolean onSearchRequested(); method protected void onStart(); method protected void onStop(); @@ -30214,6 +30218,7 @@ package android.service.dreams { method public boolean onMenuOpened(int, android.view.Menu); method public void onPanelClosed(int, android.view.Menu); method public boolean onPreparePanel(int, android.view.View, android.view.Menu); + method public boolean onSearchRequested(android.view.SearchEvent); method public boolean onSearchRequested(); method public void onWakeUp(); method public void onWindowAttributesChanged(android.view.WindowManager.LayoutParams); @@ -37178,6 +37183,10 @@ package android.view { method public void onScaleEnd(android.view.ScaleGestureDetector); } + public class SearchEvent { + method public android.view.InputDevice getInputDevice(); + } + public class SoundEffectConstants { method public static int getContantForFocusDirection(int); field public static final int CLICK = 0; // 0x0 @@ -38701,6 +38710,7 @@ package android.view { method public abstract void onPanelClosed(int, android.view.Menu); method public abstract boolean onPreparePanel(int, android.view.View, android.view.Menu); method public abstract boolean onSearchRequested(); + method public abstract boolean onSearchRequested(android.view.SearchEvent); method public abstract void onWindowAttributesChanged(android.view.WindowManager.LayoutParams); method public abstract void onWindowFocusChanged(boolean); method public abstract android.view.ActionMode onWindowStartingActionMode(android.view.ActionMode.Callback); 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.</p> * + * @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. * * <p>It is typically called from onSearchRequested(), either directly from diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index 786a52f..d049104 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -49,6 +49,7 @@ import android.view.Menu; 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; @@ -123,6 +124,8 @@ public class Dialog implements DialogInterface, Window.Callback, private Handler mListenersHandler; + private SearchEvent mSearchEvent; + private ActionMode mActionMode; private int mActionModeTypeStarting = ActionMode.TYPE_PRIMARY; @@ -995,6 +998,14 @@ public class Dialog implements DialogInterface, Window.Callback, /** * This hook is called when the user signals the desire to start a search. */ + public boolean onSearchRequested(SearchEvent searchEvent) { + mSearchEvent = searchEvent; + return onSearchRequested(); + } + + /** + * This hook is called when the user signals the desire to start a search. + */ public boolean onSearchRequested() { final SearchManager searchManager = (SearchManager) mContext .getSystemService(Context.SEARCH_SERVICE); @@ -1011,6 +1022,17 @@ public class Dialog implements DialogInterface, Window.Callback, } /** + * 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; + } + + /** * {@inheritDoc} */ @Override diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java index 822bfcc..29aaf30 100644 --- a/core/java/android/service/dreams/DreamService.java +++ b/core/java/android/service/dreams/DreamService.java @@ -41,6 +41,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.PhoneWindow; +import android.view.SearchEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -332,6 +333,12 @@ public class DreamService extends Service implements Window.Callback { /** {@inheritDoc} */ @Override + public boolean onSearchRequested(SearchEvent event) { + return onSearchRequested(); + } + + /** {@inheritDoc} */ + @Override public boolean onSearchRequested() { return false; } diff --git a/core/java/android/view/PhoneWindow.java b/core/java/android/view/PhoneWindow.java index 38f4d1c..5af2832 100644 --- a/core/java/android/view/PhoneWindow.java +++ b/core/java/android/view/PhoneWindow.java @@ -1916,7 +1916,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { break; } if (event.isTracking() && !event.isCanceled()) { - launchDefaultSearch(); + launchDefaultSearch(event); } return true; } @@ -4245,14 +4245,19 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { * * @return true if search window opened */ - private boolean launchDefaultSearch() { + private boolean launchDefaultSearch(KeyEvent event) { boolean result; final Callback cb = getCallback(); if (cb == null || isDestroyed()) { result = false; } else { sendCloseSystemWindows("search"); - result = cb.onSearchRequested(); + int deviceId = event.getDeviceId(); + SearchEvent searchEvent = null; + if (deviceId != 0) { + searchEvent = new SearchEvent(InputDevice.getDevice(deviceId)); + } + result = cb.onSearchRequested(searchEvent); } if (!result && (getContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) { diff --git a/core/java/android/view/SearchEvent.java b/core/java/android/view/SearchEvent.java new file mode 100644 index 0000000..ef51e7d --- /dev/null +++ b/core/java/android/view/SearchEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.view; + +import android.view.InputDevice; + +/** + * Class that contains information about an event that triggers a search. + */ +public class SearchEvent { + + private InputDevice mInputDevice; + + /** @hide */ + public SearchEvent(InputDevice inputDevice) { + mInputDevice = inputDevice; + } + + /** + * Returns the {@link InputDevice} that triggered the search. + * @return InputDevice the InputDevice that triggered the search. + */ + public InputDevice getInputDevice() { + return mInputDevice; + } +} diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 36f047e..9d0d5ff 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -414,6 +414,15 @@ public abstract class Window { public boolean onSearchRequested(); /** + * Called when the user signals the desire to start a search. + * + * @param searchEvent A {@link SearchEvent} describing the signal to + * start a search. + * @return true if search launched, false if activity refuses (blocks) + */ + public boolean onSearchRequested(SearchEvent searchEvent); + + /** * Called when an action mode is being started for this window. Gives the * callback an opportunity to handle the action mode in its own unique and * beautiful way. If this method returns null the system can choose a way diff --git a/core/java/android/view/WindowCallbackWrapper.java b/core/java/android/view/WindowCallbackWrapper.java index 979ee95..8ce1f8c 100644 --- a/core/java/android/view/WindowCallbackWrapper.java +++ b/core/java/android/view/WindowCallbackWrapper.java @@ -122,6 +122,11 @@ public class WindowCallbackWrapper implements Window.Callback { } @Override + public boolean onSearchRequested(SearchEvent searchEvent) { + return mWrapped.onSearchRequested(searchEvent); + } + + @Override public boolean onSearchRequested() { return mWrapped.onSearchRequested(); } diff --git a/tools/layoutlib/bridge/src/android/view/WindowCallback.java b/tools/layoutlib/bridge/src/android/view/WindowCallback.java index 823b247..d691c8e 100644 --- a/tools/layoutlib/bridge/src/android/view/WindowCallback.java +++ b/tools/layoutlib/bridge/src/android/view/WindowCallback.java @@ -110,6 +110,11 @@ public class WindowCallback implements Window.Callback { } @Override + public boolean onSearchRequested(SearchEvent searchEvent) { + return onSearchRequested(); + } + + @Override public boolean onSearchRequested() { return false; } |