Merge "Keyboard shortcuts: one instance refactor" into nyc-dev
am: 671e866
* commit '671e86605c96144066c65704dbd154df5f0a0bad':
Keyboard shortcuts: one instance refactor
Change-Id: I6bcee9a2e8fad7b2aa34d9b6d904289ee0e72e3b
This commit is contained in:
@@ -1345,7 +1345,7 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
}
|
||||
|
||||
protected void toggleKeyboardShortcuts(int deviceId) {
|
||||
getKeyboardShortcuts().toggleKeyboardShortcuts(deviceId);
|
||||
KeyboardShortcuts.toggle(mContext, deviceId);
|
||||
}
|
||||
|
||||
protected void cancelPreloadingRecents() {
|
||||
@@ -1746,14 +1746,6 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
}
|
||||
}
|
||||
|
||||
protected KeyboardShortcuts getKeyboardShortcuts() {
|
||||
if (mKeyboardShortcuts == null) {
|
||||
mKeyboardShortcuts = new KeyboardShortcuts(mContext);
|
||||
}
|
||||
|
||||
return mKeyboardShortcuts;
|
||||
}
|
||||
|
||||
public void startPendingIntentDismissingKeyguard(final PendingIntent intent) {
|
||||
if (!isDeviceProvisioned()) return;
|
||||
|
||||
|
||||
@@ -70,6 +70,10 @@ import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
|
||||
*/
|
||||
public final class KeyboardShortcuts {
|
||||
private static final String TAG = KeyboardShortcuts.class.getSimpleName();
|
||||
private static final Object sLock = new Object();
|
||||
private static KeyboardShortcuts sInstance;
|
||||
private static boolean sIsShowing;
|
||||
|
||||
private final SparseArray<String> mSpecialCharacterNames = new SparseArray<>();
|
||||
private final SparseArray<String> mModifierNames = new SparseArray<>();
|
||||
private final SparseArray<Drawable> mSpecialCharacterDrawables = new SparseArray<>();
|
||||
@@ -80,7 +84,7 @@ public final class KeyboardShortcuts {
|
||||
private final IPackageManager mPackageManager;
|
||||
private final OnClickListener mDialogCloseListener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dismissKeyboardShortcutsDialog();
|
||||
dismissKeyboardShortcuts();
|
||||
}
|
||||
};
|
||||
private final Comparator<KeyboardShortcutInfo> mApplicationItemsComparator =
|
||||
@@ -108,12 +112,49 @@ public final class KeyboardShortcuts {
|
||||
private Dialog mKeyboardShortcutsDialog;
|
||||
private KeyCharacterMap mKeyCharacterMap;
|
||||
|
||||
public KeyboardShortcuts(Context context) {
|
||||
private KeyboardShortcuts(Context context) {
|
||||
this.mContext = new ContextThemeWrapper(context, android.R.style.Theme_Material_Light);
|
||||
this.mPackageManager = AppGlobals.getPackageManager();
|
||||
loadResources(context);
|
||||
}
|
||||
|
||||
private static KeyboardShortcuts getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new KeyboardShortcuts(context);
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static void show(Context context, int deviceId) {
|
||||
synchronized (sLock) {
|
||||
if (sInstance != null && !sInstance.mContext.equals(context)) {
|
||||
dismiss();
|
||||
}
|
||||
getInstance(context).showKeyboardShortcuts(deviceId);
|
||||
sIsShowing = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void toggle(Context context, int deviceId) {
|
||||
synchronized (sLock) {
|
||||
if (sIsShowing) {
|
||||
dismiss();
|
||||
} else {
|
||||
show(context, deviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void dismiss() {
|
||||
synchronized (sLock) {
|
||||
if (sInstance != null) {
|
||||
sInstance.dismissKeyboardShortcuts();
|
||||
sInstance = null;
|
||||
}
|
||||
sIsShowing = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void loadResources(Context context) {
|
||||
mSpecialCharacterNames.put(
|
||||
KeyEvent.KEYCODE_HOME, context.getString(R.string.keyboard_key_home));
|
||||
@@ -277,27 +318,6 @@ public final class KeyboardShortcuts {
|
||||
KeyEvent.META_META_ON, context.getDrawable(R.drawable.ic_ksh_key_meta));
|
||||
}
|
||||
|
||||
public void toggleKeyboardShortcuts(int deviceId) {
|
||||
retrieveKeyCharacterMap(deviceId);
|
||||
if (mKeyboardShortcutsDialog == null) {
|
||||
Recents.getSystemServices().requestKeyboardShortcuts(mContext,
|
||||
new KeyboardShortcutsReceiver() {
|
||||
@Override
|
||||
public void onKeyboardShortcutsReceived(
|
||||
final List<KeyboardShortcutGroup> result) {
|
||||
result.add(getSystemShortcuts());
|
||||
final KeyboardShortcutGroup appShortcuts = getDefaultApplicationShortcuts();
|
||||
if (appShortcuts != null) {
|
||||
result.add(appShortcuts);
|
||||
}
|
||||
showKeyboardShortcutsDialog(result);
|
||||
}
|
||||
}, deviceId);
|
||||
} else {
|
||||
dismissKeyboardShortcutsDialog();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a {@link KeyCharacterMap} and assigns it to mKeyCharacterMap. If the given id is an
|
||||
* existing device, that device's map is used. Otherwise, it checks first all available devices
|
||||
@@ -327,7 +347,24 @@ public final class KeyboardShortcuts {
|
||||
mKeyCharacterMap = inputDevice.getKeyCharacterMap();
|
||||
}
|
||||
|
||||
public void dismissKeyboardShortcutsDialog() {
|
||||
private void showKeyboardShortcuts(int deviceId) {
|
||||
retrieveKeyCharacterMap(deviceId);
|
||||
Recents.getSystemServices().requestKeyboardShortcuts(mContext,
|
||||
new KeyboardShortcutsReceiver() {
|
||||
@Override
|
||||
public void onKeyboardShortcutsReceived(
|
||||
final List<KeyboardShortcutGroup> result) {
|
||||
result.add(getSystemShortcuts());
|
||||
final KeyboardShortcutGroup appShortcuts = getDefaultApplicationShortcuts();
|
||||
if (appShortcuts != null) {
|
||||
result.add(appShortcuts);
|
||||
}
|
||||
showKeyboardShortcutsDialog(result);
|
||||
}
|
||||
}, deviceId);
|
||||
}
|
||||
|
||||
private void dismissKeyboardShortcuts() {
|
||||
if (mKeyboardShortcutsDialog != null) {
|
||||
mKeyboardShortcutsDialog.dismiss();
|
||||
mKeyboardShortcutsDialog = null;
|
||||
|
||||
@@ -26,8 +26,7 @@ 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 */);
|
||||
KeyboardShortcuts.show(context, -1 /* deviceId unknown */);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,7 @@ import com.android.systemui.statusbar.DragDownHelper;
|
||||
import com.android.systemui.statusbar.EmptyShadeView;
|
||||
import com.android.systemui.statusbar.ExpandableNotificationRow;
|
||||
import com.android.systemui.statusbar.GestureRecorder;
|
||||
import com.android.systemui.statusbar.KeyboardShortcuts;
|
||||
import com.android.systemui.statusbar.KeyguardIndicationController;
|
||||
import com.android.systemui.statusbar.NotificationData;
|
||||
import com.android.systemui.statusbar.NotificationData.Entry;
|
||||
@@ -3161,7 +3162,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();
|
||||
KeyboardShortcuts.dismiss();
|
||||
if (isCurrentProfile(getSendingUserId())) {
|
||||
int flags = CommandQueue.FLAG_EXCLUDE_NONE;
|
||||
String reason = intent.getStringExtra("reason");
|
||||
|
||||
Reference in New Issue
Block a user