From 9d9294cc680e258d1370ca355f45d449eed2e984 Mon Sep 17 00:00:00 2001 From: Andrei Stingaceanu Date: Mon, 24 Aug 2015 17:19:06 +0100 Subject: [PATCH] Keyboard shortcuts: initial view. Initial view and functionality for showing/hiding it. Change-Id: I0e365ecc3ba19110b87b020ff53a6318a7304ce8 --- .../res/layout/keyboard_shortcuts_view.xml | 24 ++++++ .../systemui/statusbar/BaseStatusBar.java | 23 ++++-- .../systemui/statusbar/KeyboardShortcuts.java | 81 +++++++++++++++++++ .../statusbar/phone/PhoneStatusBar.java | 1 + 4 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 packages/SystemUI/res/layout/keyboard_shortcuts_view.xml create mode 100644 packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java diff --git a/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml b/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml new file mode 100644 index 0000000000000..460433ea1c214 --- /dev/null +++ b/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml @@ -0,0 +1,24 @@ + + + + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 5906bdac45230..f0a395333ccb0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -16,8 +16,6 @@ package com.android.systemui.statusbar; -import static android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_MAX; - import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.TimeInterpolator; @@ -80,11 +78,8 @@ import android.view.WindowManager; import android.view.WindowManagerGlobal; import android.view.accessibility.AccessibilityManager; import android.view.animation.AnimationUtils; -import android.widget.DateTimeView; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.RemoteViews; -import android.widget.SeekBar; import android.widget.TextView; import android.widget.Toast; @@ -116,6 +111,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import static android.service.notification.NotificationListenerService.Ranking.IMPORTANCE_MAX; import static com.android.keyguard.KeyguardHostView.OnDismissAction; public abstract class BaseStatusBar extends SystemUI implements @@ -237,6 +233,8 @@ public abstract class BaseStatusBar extends SystemUI implements private TimeInterpolator mLinearOutSlowIn, mFastOutLinearIn; + private KeyboardShortcuts mKeyboardShortcuts; + /** * The {@link StatusBarState} of the status bar. */ @@ -1142,7 +1140,7 @@ public abstract class BaseStatusBar extends SystemUI implements return new H(); } - static void sendCloseSystemWindows(Context context, String reason) { + protected void sendCloseSystemWindows(String reason) { if (ActivityManagerNative.isSystemReady()) { try { ActivityManagerNative.getDefault().closeSystemDialogs(reason); @@ -1177,7 +1175,7 @@ public abstract class BaseStatusBar extends SystemUI implements protected void showRecents(boolean triggeredFromAltTab) { if (mRecents != null) { - sendCloseSystemWindows(mContext, SYSTEM_DIALOG_REASON_RECENT_APPS); + sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); mRecents.showRecents(triggeredFromAltTab, getStatusBarView()); } } @@ -1200,8 +1198,9 @@ public abstract class BaseStatusBar extends SystemUI implements } } + // TODO: this (and maybe a few layers above) should be called toggle instead of show. protected void showKeyboardShortcuts() { - Toast.makeText(mContext, "Show keyboard shortcuts screen", Toast.LENGTH_LONG).show(); + getKeyboardShortcuts().toggleKeyboardShortcuts(mContext); } protected void cancelPreloadingRecents() { @@ -1531,6 +1530,14 @@ public abstract class BaseStatusBar extends SystemUI implements } } + protected KeyboardShortcuts getKeyboardShortcuts() { + if (mKeyboardShortcuts == null) { + mKeyboardShortcuts = new KeyboardShortcuts(); + } + + return mKeyboardShortcuts; + } + public void startPendingIntentDismissingKeyguard(final PendingIntent intent) { if (!isDeviceProvisioned()) return; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java new file mode 100644 index 0000000000000..3e0ea90f7694c --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java @@ -0,0 +1,81 @@ +/* + * 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.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.graphics.drawable.ColorDrawable; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; + +import com.android.systemui.R; + +/** + * Contains functionality for handling keyboard shortcuts. + */ +public class KeyboardShortcuts { + private Dialog mKeyboardShortcutsDialog; + + public KeyboardShortcuts() {} + + public void toggleKeyboardShortcuts(Context context) { + if (mKeyboardShortcutsDialog == null) { + // Create dialog. + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context); + LayoutInflater inflater = (LayoutInflater) context.getSystemService( + Context.LAYOUT_INFLATER_SERVICE); + final View keyboardShortcutsView = inflater.inflate( + R.layout.keyboard_shortcuts_view, null); + + populateKeyboardShortcuts(keyboardShortcutsView.findViewById( + R.id.keyboard_shortcuts_wrapper)); + dialogBuilder.setView(keyboardShortcutsView); + mKeyboardShortcutsDialog = dialogBuilder.create(); + mKeyboardShortcutsDialog.setCanceledOnTouchOutside(true); + + // Setup window. + Window keyboardShortcutsWindow = mKeyboardShortcutsDialog.getWindow(); + keyboardShortcutsWindow.setType( + WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); + keyboardShortcutsWindow.setBackgroundDrawable( + new ColorDrawable(android.graphics.Color.TRANSPARENT)); + keyboardShortcutsWindow.setGravity(Gravity.TOP); + mKeyboardShortcutsDialog.show(); + } else { + dismissKeyboardShortcutsDialog(); + } + } + + public void dismissKeyboardShortcutsDialog() { + if (mKeyboardShortcutsDialog != null) { + mKeyboardShortcutsDialog.dismiss(); + mKeyboardShortcutsDialog = null; + } + } + + /** + * @return {@code true} if the keyboard shortcuts have been successfully populated. + */ + private boolean populateKeyboardShortcuts(View keyboardShortcutsLayout) { + // TODO: Populate shortcuts. + return true; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 78d09e3e03a4e..fffeb296c7f89 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -2987,6 +2987,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (DEBUG) Log.v(TAG, "onReceive: " + intent); String action = intent.getAction(); if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) { + getKeyboardShortcuts().dismissKeyboardShortcutsDialog(); if (isCurrentProfile(getSendingUserId())) { int flags = CommandQueue.FLAG_EXCLUDE_NONE; String reason = intent.getStringExtra("reason");