diff options
| author | Clara Bayarri <clarabayarri@google.com> | 2015-07-29 16:20:40 +0100 |
|---|---|---|
| committer | Clara Bayarri <clarabayarri@google.com> | 2016-01-13 16:56:56 +0000 |
| commit | 75e097965cc273d33192555b0e65de3dbc1753ce (patch) | |
| tree | b2258e6a51b26e342571e89f1c81b7ca5113a32f /core/java/android | |
| parent | a1771110d67fa7361f92d92f2e91019882ce3305 (diff) | |
Request Keyboard Shortcuts for SysUI Dialog via Window
Keyboard shortcuts are requested via WindowManager, and
the request pipes through to the view root and the window
callback.
Bug: 22405482
Change-Id: Ic0071e91c7b554be3ac9df71e9539ee8a60e822e
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/Activity.java | 42 | ||||
| -rw-r--r-- | core/java/android/app/Dialog.java | 14 | ||||
| -rw-r--r-- | core/java/android/service/dreams/DreamService.java | 19 | ||||
| -rw-r--r-- | core/java/android/view/IWindow.aidl | 7 | ||||
| -rw-r--r-- | core/java/android/view/IWindowManager.aidl | 8 | ||||
| -rw-r--r-- | core/java/android/view/KeyboardShortcutGroup.java | 102 | ||||
| -rw-r--r-- | core/java/android/view/KeyboardShortcutInfo.java | 134 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 12 | ||||
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 33 | ||||
| -rw-r--r-- | core/java/android/view/Window.java | 11 | ||||
| -rw-r--r-- | core/java/android/view/WindowCallbackWrapper.java | 7 | ||||
| -rw-r--r-- | core/java/android/view/WindowManager.java | 30 | ||||
| -rw-r--r-- | core/java/android/view/WindowManagerImpl.java | 25 |
13 files changed, 431 insertions, 13 deletions
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 34527c2623c6..e31259692501 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -62,6 +62,7 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; import android.media.AudioManager; import android.media.session.MediaController; import android.net.Uri; @@ -71,6 +72,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Parcelable; +import android.os.PersistableBundle; import android.os.RemoteException; import android.os.StrictMode; import android.os.UserHandle; @@ -78,23 +80,28 @@ import android.text.Selection; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.method.TextKeyListener; +import android.transition.Scene; +import android.transition.TransitionManager; +import android.util.ArrayMap; import android.util.AttributeSet; import android.util.EventLog; import android.util.Log; import android.util.PrintWriterPrinter; import android.util.Slog; import android.util.SparseArray; +import android.util.SuperNotCalledException; import android.view.ActionMode; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextThemeWrapper; import android.view.KeyEvent; +import android.view.KeyboardShortcutGroup; +import android.view.KeyboardShortcutInfo; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; -import com.android.internal.policy.PhoneWindow; import android.view.SearchEvent; import android.view.View; import android.view.View.OnCreateContextMenuListener; @@ -103,10 +110,17 @@ import android.view.ViewGroup.LayoutParams; import android.view.ViewManager; import android.view.ViewRootImpl; import android.view.Window; +import android.view.Window.WindowControllerCallback; import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.view.accessibility.AccessibilityEvent; import android.widget.AdapterView; +import android.widget.Toolbar; + +import com.android.internal.app.IVoiceInteractor; +import com.android.internal.app.ToolbarActionBar; +import com.android.internal.app.WindowDecorActionBar; +import com.android.internal.policy.PhoneWindow; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -116,6 +130,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import static java.lang.Character.MIN_VALUE; + /** * An activity is a single, focused thing that the user can do. Almost all * activities interact with the user, so the Activity class takes care of @@ -1594,6 +1610,30 @@ public class Activity extends ContextThemeWrapper public void onProvideAssistContent(AssistContent outContent) { } + @Override + public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu) { + if (menu == null) { + return; + } + KeyboardShortcutGroup group = null; + int menuSize = menu.size(); + for (int i = 0; i < menuSize; ++i) { + final MenuItem item = menu.getItem(i); + final CharSequence title = item.getTitle(); + final char alphaShortcut = item.getAlphabeticShortcut(); + if (title != null && alphaShortcut != MIN_VALUE) { + if (group == null) { + group = new KeyboardShortcutGroup(null /* no label */); + } + group.addItem(new KeyboardShortcutInfo( + title, alphaShortcut, KeyEvent.META_CTRL_ON)); + } + } + if (group != null) { + data.add(group); + } + } + /** * Ask to have the current assistant shown to the user. This only works if the calling * activity is the current foreground activity. It is the same as calling diff --git a/core/java/android/app/Dialog.java b/core/java/android/app/Dialog.java index 6e8e2c44ce37..79461b4863ef 100644 --- a/core/java/android/app/Dialog.java +++ b/core/java/android/app/Dialog.java @@ -21,9 +21,8 @@ import android.annotation.DrawableRes; import android.annotation.IdRes; import android.annotation.LayoutRes; import android.annotation.NonNull; -import android.annotation.StringRes; - import android.annotation.Nullable; +import android.annotation.StringRes; import android.annotation.StyleRes; import android.content.ComponentName; import android.content.Context; @@ -44,11 +43,11 @@ import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextThemeWrapper; import android.view.Gravity; import android.view.KeyEvent; +import android.view.KeyboardShortcutGroup; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; -import com.android.internal.policy.PhoneWindow; import android.view.SearchEvent; import android.view.View; import android.view.View.OnCreateContextMenuListener; @@ -60,8 +59,10 @@ import android.view.accessibility.AccessibilityEvent; import com.android.internal.R; import com.android.internal.app.WindowDecorActionBar; +import com.android.internal.policy.PhoneWindow; import java.lang.ref.WeakReference; +import java.util.List; /** * Base class for Dialogs. @@ -1081,6 +1082,13 @@ public class Dialog implements DialogInterface, Window.Callback, } /** + * {@inheritDoc} + */ + @Override + public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu) { + } + + /** * @return The activity associated with this dialog, or null if there is no associated activity. */ private ComponentName getAssociatedActivity() { diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java index bb46e8302de6..816ecde84377 100644 --- a/core/java/android/service/dreams/DreamService.java +++ b/core/java/android/service/dreams/DreamService.java @@ -15,9 +15,6 @@ */ package android.service.dreams; -import java.io.FileDescriptor; -import java.io.PrintWriter; - import android.annotation.IdRes; import android.annotation.LayoutRes; import android.annotation.Nullable; @@ -33,27 +30,32 @@ import android.os.IBinder; import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; +import android.util.MathUtils; import android.util.Slog; import android.view.ActionMode; import android.view.Display; import android.view.KeyEvent; +import android.view.KeyboardShortcutGroup; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; -import com.android.internal.policy.PhoneWindow; import android.view.SearchEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.view.WindowManagerGlobal; import android.view.WindowManager.LayoutParams; +import android.view.WindowManagerGlobal; import android.view.accessibility.AccessibilityEvent; -import android.util.MathUtils; +import com.android.internal.policy.PhoneWindow; import com.android.internal.util.DumpUtils; import com.android.internal.util.DumpUtils.Dump; +import java.io.FileDescriptor; +import java.io.PrintWriter; +import java.util.List; + /** * Extend this class to implement a custom dream (available to the user as a "Daydream"). * @@ -365,6 +367,11 @@ public class DreamService extends Service implements Window.Callback { @Override public void onActionModeFinished(ActionMode mode) { } + + /** {@inheritDoc} */ + @Override + public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu) { + } // end Window.Callback methods // begin public api diff --git a/core/java/android/view/IWindow.aidl b/core/java/android/view/IWindow.aidl index 9e478c1d1e73..923139406088 100644 --- a/core/java/android/view/IWindow.aidl +++ b/core/java/android/view/IWindow.aidl @@ -25,6 +25,8 @@ import android.view.DragEvent; import android.view.KeyEvent; import android.view.MotionEvent; +import com.android.internal.os.IResultReceiver; + /** * API back to a client window that the Window Manager uses to inform it of * interesting things happening. @@ -83,4 +85,9 @@ oneway interface IWindow { * Called for non-application windows when the enter animation has completed. */ void dispatchWindowShown(); + + /** + * Called when Keyboard Shortcuts are requested for the window. + */ + void requestAppKeyboardShortcuts(IResultReceiver receiver); } diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl index 84d312d59b64..b045c17a9295 100644 --- a/core/java/android/view/IWindowManager.aidl +++ b/core/java/android/view/IWindowManager.aidl @@ -17,6 +17,7 @@ package android.view; import com.android.internal.app.IAssistScreenshotReceiver; +import com.android.internal.os.IResultReceiver; import com.android.internal.view.IInputContext; import com.android.internal.view.IInputMethodClient; @@ -370,4 +371,11 @@ interface IWindowManager * @param alpha The translucency of the dim layer, between 0 and 1. */ void setResizeDimLayer(boolean visible, int targetStackId, float alpha); + + /** + * Requests Keyboard Shortcuts from the displayed window. + * + * @param receiver The receiver to deliver the results to. + */ + void requestAppKeyboardShortcuts(IResultReceiver receiver); } diff --git a/core/java/android/view/KeyboardShortcutGroup.java b/core/java/android/view/KeyboardShortcutGroup.java new file mode 100644 index 000000000000..013255b9a612 --- /dev/null +++ b/core/java/android/view/KeyboardShortcutGroup.java @@ -0,0 +1,102 @@ +/* + * 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.annotation.NonNull; +import android.annotation.Nullable; +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static com.android.internal.util.Preconditions.checkNotNull; + +/** + * A group of {@link KeyboardShortcutInfo}. + */ +public final class KeyboardShortcutGroup implements Parcelable { + private final CharSequence mLabel; + private final List<KeyboardShortcutInfo> mItems; + + /** + * @param label The title to be used for this group, or null if there is none. + * @param items The set of items to be included. + */ + public KeyboardShortcutGroup(@Nullable CharSequence label, + @NonNull List<KeyboardShortcutInfo> items) { + mLabel = label; + mItems = new ArrayList<>(checkNotNull(items)); + } + + /** + * @param label The title to be used for this group, or null if there is none. + */ + public KeyboardShortcutGroup(@Nullable CharSequence label) { + this(label, Collections.<KeyboardShortcutInfo>emptyList()); + } + + private KeyboardShortcutGroup(Parcel source) { + mItems = new ArrayList<>(); + mLabel = source.readCharSequence(); + source.readTypedList(mItems, KeyboardShortcutInfo.CREATOR); + } + + /** + * Returns the label to be used to describe this group. + */ + public CharSequence getLabel() { + return mLabel; + } + + /** + * Returns the list of items included in this group. + */ + public List<KeyboardShortcutInfo> getItems() { + return mItems; + } + + /** + * Adds an item to the existing list. + * + * @param item The item to be added. + */ + public void addItem(KeyboardShortcutInfo item) { + mItems.add(item); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeCharSequence(mLabel); + dest.writeTypedList(mItems); + } + + public static final Creator<KeyboardShortcutGroup> CREATOR = + new Creator<KeyboardShortcutGroup>() { + public KeyboardShortcutGroup createFromParcel(Parcel source) { + return new KeyboardShortcutGroup(source); + } + public KeyboardShortcutGroup[] newArray(int size) { + return new KeyboardShortcutGroup[size]; + } + }; +}
\ No newline at end of file diff --git a/core/java/android/view/KeyboardShortcutInfo.java b/core/java/android/view/KeyboardShortcutInfo.java new file mode 100644 index 000000000000..2c9006deb189 --- /dev/null +++ b/core/java/android/view/KeyboardShortcutInfo.java @@ -0,0 +1,134 @@ +/* + * 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.annotation.Nullable; +import android.graphics.drawable.Icon; +import android.os.Parcel; +import android.os.Parcelable; + +import static com.android.internal.util.Preconditions.checkArgument; +import static java.lang.Character.MIN_VALUE; + +/** + * Information about a Keyboard Shortcut. + */ +public final class KeyboardShortcutInfo implements Parcelable { + private final CharSequence mLabel; + private final Icon mIcon; + private final char mBaseCharacter; + private final int mModifiers; + + /** + * @param label The label that identifies the action performed by this shortcut. + * @param icon An icon that identifies the action performed by this shortcut. + * @param baseCharacter The character that triggers the shortcut. + * @param modifiers The set of modifiers that, combined with the key, trigger the shortcut. + * These should be a combination of {@link KeyEvent#META_CTRL_ON}, + * {@link KeyEvent#META_SHIFT_ON}, {@link KeyEvent#META_META_ON} and + * {@link KeyEvent#META_ALT_ON}. + * + * @hide + */ + public KeyboardShortcutInfo( + @Nullable CharSequence label, @Nullable Icon icon, char baseCharacter, int modifiers) { + mLabel = label; + mIcon = icon; + checkArgument(baseCharacter != MIN_VALUE); + mBaseCharacter = baseCharacter; + mModifiers = modifiers; + } + + /** + * Convenience constructor for shortcuts with a label and no icon. + * + * @param label The label that identifies the action performed by this shortcut. + * @param baseCharacter The character that triggers the shortcut. + * @param modifiers The set of modifiers that, combined with the key, trigger the shortcut. + * These should be a combination of {@link KeyEvent#META_CTRL_ON}, + * {@link KeyEvent#META_SHIFT_ON}, {@link KeyEvent#META_META_ON} and + * {@link KeyEvent#META_ALT_ON}. + */ + public KeyboardShortcutInfo(CharSequence label, char baseCharacter, int modifiers) { + mLabel = label; + checkArgument(baseCharacter != MIN_VALUE); + mBaseCharacter = baseCharacter; + mModifiers = modifiers; + mIcon = null; + } + + private KeyboardShortcutInfo(Parcel source) { + mLabel = source.readCharSequence(); + mIcon = (Icon) source.readParcelable(null); + mBaseCharacter = (char) source.readInt(); + mModifiers = source.readInt(); + } + + /** + * Returns the label to be used to describe this shortcut. + */ + @Nullable + public CharSequence getLabel() { + return mLabel; + } + + /** + * Returns the icon to be used to describe this shortcut. + * + * @hide + */ + @Nullable + public Icon getIcon() { + return mIcon; + } + + /** + * Returns the base character that, combined with the modifiers, triggers this shortcut. + */ + public char getBaseCharacter() { + return mBaseCharacter; + } + + /** + * Returns the set of modifiers that, combined with the key, trigger this shortcut. + */ + public int getModifiers() { + return mModifiers; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeCharSequence(mLabel); + dest.writeParcelable(mIcon, 0); + dest.writeInt(mBaseCharacter); + dest.writeInt(mModifiers); + } + + public static final Creator<KeyboardShortcutInfo> CREATOR = + new Creator<KeyboardShortcutInfo>() { + public KeyboardShortcutInfo createFromParcel(Parcel source) { + return new KeyboardShortcutInfo(source); + } + public KeyboardShortcutInfo[] newArray(int size) { + return new KeyboardShortcutInfo[size]; + } + }; +}
\ No newline at end of file diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 68f1ac3c1108..5559d4dbe705 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -79,10 +79,11 @@ import android.util.StateSet; import android.util.SuperNotCalledException; import android.util.TypedValue; import android.view.ContextMenu.ContextMenuInfo; -import android.view.AccessibilityIterators.TextSegmentIterator; import android.view.AccessibilityIterators.CharacterTextSegmentIterator; -import android.view.AccessibilityIterators.WordTextSegmentIterator; import android.view.AccessibilityIterators.ParagraphTextSegmentIterator; +import android.view.AccessibilityIterators.TextSegmentIterator; +import android.view.AccessibilityIterators.WordTextSegmentIterator; +import android.view.ViewGroup.LayoutParams; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEventSource; import android.view.accessibility.AccessibilityManager; @@ -21715,6 +21716,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * @hide + */ + public void requestKeyboardShortcuts(List<KeyboardShortcutGroup> data) { + // Do nothing. + } + + /** * Interface definition for a callback to be invoked when a hardware key event is * dispatched to this view. The callback will be invoked before the key event is * given to the view. This is only useful for hardware keyboards; a software input diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 3eb2e37be781..a14f0dcc2541 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -79,6 +79,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.Scroller; import com.android.internal.R; +import com.android.internal.os.IResultReceiver; import com.android.internal.os.SomeArgs; import com.android.internal.policy.PhoneFallbackEventHandler; import com.android.internal.view.BaseSurfaceHolder; @@ -3235,6 +3236,7 @@ public final class ViewRootImpl implements ViewParent, private final static int MSG_WINDOW_MOVED = 23; private final static int MSG_SYNTHESIZE_INPUT_EVENT = 24; private final static int MSG_DISPATCH_WINDOW_SHOWN = 25; + private final static int MSG_REQUEST_KEYBOARD_SHORTCUTS = 26; final class ViewRootHandler extends Handler { @Override @@ -3511,7 +3513,11 @@ public final class ViewRootImpl implements ViewParent, } break; case MSG_DISPATCH_WINDOW_SHOWN: { handleDispatchWindowShown(); - } + } break; + case MSG_REQUEST_KEYBOARD_SHORTCUTS: { + IResultReceiver receiver = (IResultReceiver) msg.obj; + handleRequestKeyboardShortcuts(receiver); + } break; } } } @@ -5404,6 +5410,19 @@ public final class ViewRootImpl implements ViewParent, mAttachInfo.mTreeObserver.dispatchOnWindowShown(); } + public void handleRequestKeyboardShortcuts(IResultReceiver receiver) { + Bundle data = new Bundle(); + ArrayList<KeyboardShortcutGroup> list = new ArrayList<>(); + if (mView != null) { + mView.requestKeyboardShortcuts(list); + } + data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list); + try { + receiver.send(0, data); + } catch (RemoteException e) { + } + } + public void getLastTouchPoint(Point outLocation) { outLocation.x = (int) mLastTouchPoint.x; outLocation.y = (int) mLastTouchPoint.y; @@ -6333,6 +6352,10 @@ public final class ViewRootImpl implements ViewParent, } } + public void dispatchRequestKeyboardShortcuts(IResultReceiver receiver) { + mHandler.obtainMessage(MSG_REQUEST_KEYBOARD_SHORTCUTS, receiver).sendToTarget(); + } + /** * Post a callback to send a * {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} event. @@ -6906,6 +6929,14 @@ public final class ViewRootImpl implements ViewParent, viewAncestor.dispatchWindowShown(); } } + + @Override + public void requestAppKeyboardShortcuts(IResultReceiver receiver) { + ViewRootImpl viewAncestor = mViewAncestor.get(); + if (viewAncestor != null) { + viewAncestor.dispatchRequestKeyboardShortcuts(receiver); + } + } } public static final class CalledFromWrongThreadException extends AndroidRuntimeException { diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java index 0b06d1591731..d89369bef170 100644 --- a/core/java/android/view/Window.java +++ b/core/java/android/view/Window.java @@ -42,6 +42,8 @@ import android.transition.Transition; import android.transition.TransitionManager; import android.view.accessibility.AccessibilityEvent; +import java.util.List; + /** * Abstract base class for a top-level window look and behavior policy. An * instance of this class should be used as the top-level view added to the @@ -556,6 +558,15 @@ public abstract class Window { * @param mode The mode that was just finished. */ public void onActionModeFinished(ActionMode mode); + + /** + * Called when Keyboard Shortcuts are requested for the current window. + * + * @param data The data list to populate with shortcuts. + * @param menu The current menu, which may be null. + */ + public void onProvideKeyboardShortcuts( + List<KeyboardShortcutGroup> data, @Nullable Menu menu); } /** @hide */ diff --git a/core/java/android/view/WindowCallbackWrapper.java b/core/java/android/view/WindowCallbackWrapper.java index 8ce1f8c7e310..bed74e95ae0a 100644 --- a/core/java/android/view/WindowCallbackWrapper.java +++ b/core/java/android/view/WindowCallbackWrapper.java @@ -19,6 +19,8 @@ package android.view; import android.view.accessibility.AccessibilityEvent; +import java.util.List; + /** * A simple decorator stub for Window.Callback that passes through any calls * to the wrapped instance as a base implementation. Call super.foo() to call into @@ -150,5 +152,10 @@ public class WindowCallbackWrapper implements Window.Callback { public void onActionModeFinished(ActionMode mode) { mWrapped.onActionModeFinished(mode); } + + @Override + public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> data, Menu menu) { + mWrapped.onProvideKeyboardShortcuts(data, menu); + } } diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java index 251f4c802ce6..772eeec880ee 100644 --- a/core/java/android/view/WindowManager.java +++ b/core/java/android/view/WindowManager.java @@ -29,6 +29,8 @@ import android.os.Parcelable; import android.text.TextUtils; import android.util.Log; +import java.util.List; + /** * The interface that apps use to talk to the window manager. @@ -118,6 +120,34 @@ public interface WindowManager extends ViewManager { */ public void removeViewImmediate(View view); + /** + * Used to asynchronously request Keyboard Shortcuts from the focused window. + * + * @hide + */ + public interface KeyboardShortcutsReceiver { + /** + * Callback used when the focused window keyboard shortcuts are ready to be displayed. + * + * @param result The keyboard shortcuts to be displayed. + */ + void onKeyboardShortcutsReceived(List<KeyboardShortcutGroup> result); + } + + /** + * @hide + */ + public static final String PARCEL_KEY_SHORTCUTS_ARRAY = "shortcuts_array"; + + /** + * Request for keyboard shortcuts to be retrieved asynchronously. + * + * @param receiver The callback to be triggered when the result is ready. + * + * @hide + */ + public void requestAppKeyboardShortcuts(final KeyboardShortcutsReceiver receiver); + public static class LayoutParams extends ViewGroup.LayoutParams implements Parcelable { /** * X position for this window. With the default gravity it is ignored. diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java index 98e9f54c13f9..6e11671016b4 100644 --- a/core/java/android/view/WindowManagerImpl.java +++ b/core/java/android/view/WindowManagerImpl.java @@ -17,7 +17,15 @@ package android.view; import android.annotation.NonNull; +import android.content.Context; +import android.os.Bundle; import android.os.IBinder; +import android.os.RemoteException; + +import com.android.internal.os.IResultReceiver; +import com.android.internal.R; + +import java.util.List; /** * Provides low-level communication with the system window manager for @@ -117,6 +125,23 @@ public final class WindowManagerImpl implements WindowManager { } @Override + public void requestAppKeyboardShortcuts(final KeyboardShortcutsReceiver receiver) { + IResultReceiver resultReceiver = new IResultReceiver.Stub() { + @Override + public void send(int resultCode, Bundle resultData) throws RemoteException { + List<KeyboardShortcutGroup> result = + resultData.getParcelableArrayList(PARCEL_KEY_SHORTCUTS_ARRAY); + receiver.onKeyboardShortcutsReceived(result); + } + }; + try { + WindowManagerGlobal.getWindowManagerService() + .requestAppKeyboardShortcuts(resultReceiver); + } catch (RemoteException e) { + } + } + + @Override public Display getDefaultDisplay() { return mDisplay; } |
