blob: 3e0ea90f7694c368dd2fb1afbc700e9c9b9ccc69 [file] [log] [blame]
Andrei Stingaceanu9d9294c2015-08-24 17:19:06 +01001/*
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
17package com.android.systemui.statusbar;
18
19import android.app.AlertDialog;
20import android.app.Dialog;
21import android.content.Context;
22import android.graphics.drawable.ColorDrawable;
23import android.view.Gravity;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.Window;
27import android.view.WindowManager;
28
29import com.android.systemui.R;
30
31/**
32 * Contains functionality for handling keyboard shortcuts.
33 */
34public 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}