From eb3c2d3e630825974e7275607558978252882204 Mon Sep 17 00:00:00 2001 From: Clara Bayarri Date: Fri, 1 Apr 2016 14:37:32 +0100 Subject: [PATCH] Expose the Keyboard Shortcuts Helper in Activity This allows apps to trigger it from their own menus Bug: 27811273 Change-Id: I028caa5a88bb0e1c51238db28bb496293b78f90b --- api/current.txt | 1 + api/system-current.txt | 1 + api/test-current.txt | 1 + core/java/android/app/Activity.java | 11 +++++++ core/java/android/content/Intent.java | 10 ++++++ packages/SystemUI/AndroidManifest.xml | 7 ++++ .../statusbar/KeyboardShortcutsReceiver.java | 33 +++++++++++++++++++ 7 files changed, 64 insertions(+) create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutsReceiver.java diff --git a/api/current.txt b/api/current.txt index 501d6b6a58ef3..a623b11999843 100644 --- a/api/current.txt +++ b/api/current.txt @@ -3578,6 +3578,7 @@ package android.app { method public final deprecated void removeDialog(int); method public void reportFullyDrawn(); method public android.view.DropPermissions requestDropPermissions(android.view.DragEvent); + method public final void requestKeyboardShortcutsHelper(); method public final void requestPermissions(java.lang.String[], int); method public boolean requestVisibleBehind(boolean); method public final boolean requestWindowFeature(int); diff --git a/api/system-current.txt b/api/system-current.txt index 113c8bccb55c9..9d8abef56dfbb 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -3696,6 +3696,7 @@ package android.app { method public final deprecated void removeDialog(int); method public void reportFullyDrawn(); method public android.view.DropPermissions requestDropPermissions(android.view.DragEvent); + method public final void requestKeyboardShortcutsHelper(); method public final void requestPermissions(java.lang.String[], int); method public boolean requestVisibleBehind(boolean); method public final boolean requestWindowFeature(int); diff --git a/api/test-current.txt b/api/test-current.txt index 3fbac02d62087..099ead307054c 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -3578,6 +3578,7 @@ package android.app { method public final deprecated void removeDialog(int); method public void reportFullyDrawn(); method public android.view.DropPermissions requestDropPermissions(android.view.DragEvent); + method public final void requestKeyboardShortcutsHelper(); method public final void requestPermissions(java.lang.String[], int); method public boolean requestVisibleBehind(boolean); method public final boolean requestWindowFeature(int); diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java index 0410a6e804cde..70357eac5c2ed 100644 --- a/core/java/android/app/Activity.java +++ b/core/java/android/app/Activity.java @@ -1675,6 +1675,17 @@ public class Activity extends ContextThemeWrapper public void onProvideAssistContent(AssistContent outContent) { } + /** + * Request the Keyboard Shortcuts screen to show up. If it succeeds, this will trigger + * {@link #onProvideKeyboardShortcuts} to retrieve the shortcuts for the foreground activity. + */ + public final void requestKeyboardShortcutsHelper() { + Intent intent = new Intent(Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS); + intent.setComponent(new ComponentName("com.android.systemui", + "com.android.systemui.statusbar.KeyboardShortcutsReceiver")); + sendBroadcast(intent); + } + @Override public void onProvideKeyboardShortcuts( List data, Menu menu, int deviceId) { diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 30f2c948df966..f060a1c17d70f 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -1403,6 +1403,16 @@ public class Intent implements Parcelable, Cloneable { @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) public static final String ACTION_UPGRADE_SETUP = "android.intent.action.UPGRADE_SETUP"; + /** + * Activity Action: Start the Keyboard Shortcuts Helper screen. + *

Input: Nothing. + *

Output: Nothing. + * @hide + */ + @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_SHOW_KEYBOARD_SHORTCUTS = + "android.intent.action.SHOW_KEYBOARD_SHORTCUTS"; + /** * Activity Action: Show settings for managing network data usage of a * specific application. Applications should define an activity that offers diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 9e2442cc23572..f5854f5f7a36f 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -488,5 +488,12 @@ + + + + + + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutsReceiver.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutsReceiver.java new file mode 100644 index 0000000000000..5d22faf2d4ce0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutsReceiver.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2016 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 com.android.systemui.statusbar; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +/** + * Receiver for the Keyboard Shortcuts Helper. + */ +public class KeyboardShortcutsReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_SHOW_KEYBOARD_SHORTCUTS.equals(intent.getAction())) { + final KeyboardShortcuts keyboardShortcuts = new KeyboardShortcuts(context); + keyboardShortcuts.toggleKeyboardShortcuts(-1 /* deviceId unknown */); + } + } +}