Andrei Stingaceanu | 9d9294c | 2015-08-24 17:19:06 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
| 19 | import android.app.AlertDialog; |
| 20 | import android.app.Dialog; |
| 21 | import android.content.Context; |
| 22 | import android.graphics.drawable.ColorDrawable; |
| 23 | import android.view.Gravity; |
| 24 | import android.view.LayoutInflater; |
| 25 | import android.view.View; |
| 26 | import android.view.Window; |
| 27 | import android.view.WindowManager; |
| 28 | |
| 29 | import com.android.systemui.R; |
| 30 | |
| 31 | /** |
| 32 | * Contains functionality for handling keyboard shortcuts. |
| 33 | */ |
| 34 | public class KeyboardShortcuts { |
| 35 | private Dialog mKeyboardShortcutsDialog; |
| 36 | |
| 37 | public KeyboardShortcuts() {} |
| 38 | |
| 39 | public void toggleKeyboardShortcuts(Context context) { |
| 40 | if (mKeyboardShortcutsDialog == null) { |
| 41 | // Create dialog. |
| 42 | AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context); |
| 43 | LayoutInflater inflater = (LayoutInflater) context.getSystemService( |
| 44 | Context.LAYOUT_INFLATER_SERVICE); |
| 45 | final View keyboardShortcutsView = inflater.inflate( |
| 46 | R.layout.keyboard_shortcuts_view, null); |
| 47 | |
| 48 | populateKeyboardShortcuts(keyboardShortcutsView.findViewById( |
| 49 | R.id.keyboard_shortcuts_wrapper)); |
| 50 | dialogBuilder.setView(keyboardShortcutsView); |
| 51 | mKeyboardShortcutsDialog = dialogBuilder.create(); |
| 52 | mKeyboardShortcutsDialog.setCanceledOnTouchOutside(true); |
| 53 | |
| 54 | // Setup window. |
| 55 | Window keyboardShortcutsWindow = mKeyboardShortcutsDialog.getWindow(); |
| 56 | keyboardShortcutsWindow.setType( |
| 57 | WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); |
| 58 | keyboardShortcutsWindow.setBackgroundDrawable( |
| 59 | new ColorDrawable(android.graphics.Color.TRANSPARENT)); |
| 60 | keyboardShortcutsWindow.setGravity(Gravity.TOP); |
| 61 | mKeyboardShortcutsDialog.show(); |
| 62 | } else { |
| 63 | dismissKeyboardShortcutsDialog(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | public void dismissKeyboardShortcutsDialog() { |
| 68 | if (mKeyboardShortcutsDialog != null) { |
| 69 | mKeyboardShortcutsDialog.dismiss(); |
| 70 | mKeyboardShortcutsDialog = null; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @return {@code true} if the keyboard shortcuts have been successfully populated. |
| 76 | */ |
| 77 | private boolean populateKeyboardShortcuts(View keyboardShortcutsLayout) { |
| 78 | // TODO: Populate shortcuts. |
| 79 | return true; |
| 80 | } |
| 81 | } |