Merge "Allow disabling the Options Pannel feature for TVs" into lmp-mr1-dev

This commit is contained in:
Jose Lima
2015-01-27 02:53:21 +00:00
committed by Android (Google) Code Review
4 changed files with 71 additions and 24 deletions

View File

@@ -2377,8 +2377,10 @@ public class Activity extends ContextThemeWrapper
if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) { if (mDefaultKeyMode == DEFAULT_KEYS_DISABLE) {
return false; return false;
} else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) { } else if (mDefaultKeyMode == DEFAULT_KEYS_SHORTCUT) {
if (getWindow().performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, Window w = getWindow();
keyCode, event, Menu.FLAG_ALWAYS_PERFORM_CLOSE)) { if (w.hasFeature(Window.FEATURE_OPTIONS_PANEL) &&
w.performPanelShortcut(Window.FEATURE_OPTIONS_PANEL, keyCode, event,
Menu.FLAG_ALWAYS_PERFORM_CLOSE)) {
return true; return true;
} }
return false; return false;
@@ -2943,7 +2945,8 @@ public class Activity extends ContextThemeWrapper
* time it needs to be displayed. * time it needs to be displayed.
*/ */
public void invalidateOptionsMenu() { public void invalidateOptionsMenu() {
if (mActionBar == null || !mActionBar.invalidateOptionsMenu()) { if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) &&
(mActionBar == null || !mActionBar.invalidateOptionsMenu())) {
mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL); mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL);
} }
} }
@@ -3155,7 +3158,8 @@ public class Activity extends ContextThemeWrapper
* open, this method does nothing. * open, this method does nothing.
*/ */
public void openOptionsMenu() { public void openOptionsMenu() {
if (mActionBar == null || !mActionBar.openOptionsMenu()) { if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL) &&
(mActionBar == null || !mActionBar.openOptionsMenu())) {
mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null); mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null);
} }
} }
@@ -3165,8 +3169,10 @@ public class Activity extends ContextThemeWrapper
* closed, this method does nothing. * closed, this method does nothing.
*/ */
public void closeOptionsMenu() { public void closeOptionsMenu() {
if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL); mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL);
} }
}
/** /**
* Called when a context menu for the {@code view} is about to be shown. * Called when a context menu for the {@code view} is about to be shown.

View File

@@ -910,22 +910,28 @@ public class Dialog implements DialogInterface, Window.Callback,
* @see Activity#openOptionsMenu() * @see Activity#openOptionsMenu()
*/ */
public void openOptionsMenu() { public void openOptionsMenu() {
if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null); mWindow.openPanel(Window.FEATURE_OPTIONS_PANEL, null);
} }
}
/** /**
* @see Activity#closeOptionsMenu() * @see Activity#closeOptionsMenu()
*/ */
public void closeOptionsMenu() { public void closeOptionsMenu() {
if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL); mWindow.closePanel(Window.FEATURE_OPTIONS_PANEL);
} }
}
/** /**
* @see Activity#invalidateOptionsMenu() * @see Activity#invalidateOptionsMenu()
*/ */
public void invalidateOptionsMenu() { public void invalidateOptionsMenu() {
if (mWindow.hasFeature(Window.FEATURE_OPTIONS_PANEL)) {
mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL); mWindow.invalidatePanelMenu(Window.FEATURE_OPTIONS_PANEL);
} }
}
/** /**
* @see Activity#onCreateContextMenu(ContextMenu, View, ContextMenuInfo) * @see Activity#onCreateContextMenu(ContextMenu, View, ContextMenuInfo)

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2015, 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.
*/
-->
<!-- These resources are around just to allow their values to be customized
for TV products. Do not translate. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Flags enabling default window features. See Window.java -->
<bool name="config_defaultWindowFeatureOptionsPanel">false</bool>
</resources>

View File

@@ -894,7 +894,10 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
} }
void doInvalidatePanelMenu(int featureId) { void doInvalidatePanelMenu(int featureId) {
PanelFeatureState st = getPanelState(featureId, true); PanelFeatureState st = getPanelState(featureId, false);
if (st == null) {
return;
}
Bundle savedActionViewStates = null; Bundle savedActionViewStates = null;
if (st.menu != null) { if (st.menu != null) {
savedActionViewStates = new Bundle(); savedActionViewStates = new Bundle();
@@ -933,8 +936,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
// The panel key was pushed, so set the chording key // The panel key was pushed, so set the chording key
mPanelChordingKey = keyCode; mPanelChordingKey = keyCode;
PanelFeatureState st = getPanelState(featureId, true); PanelFeatureState st = getPanelState(featureId, false);
if (!st.isOpen) { if (st != null && !st.isOpen) {
return preparePanel(st, event); return preparePanel(st, event);
} }
} }
@@ -952,12 +955,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
if (mPanelChordingKey != 0) { if (mPanelChordingKey != 0) {
mPanelChordingKey = 0; mPanelChordingKey = 0;
if (event.isCanceled() || (mDecor != null && mDecor.mActionMode != null)) { final PanelFeatureState st = getPanelState(featureId, false);
if (event.isCanceled() || (mDecor != null && mDecor.mActionMode != null) ||
(st == null)) {
return; return;
} }
boolean playSoundEffect = false; boolean playSoundEffect = false;
final PanelFeatureState st = getPanelState(featureId, true);
if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null &&
mDecorContentParent.canShowOverflowMenu() && mDecorContentParent.canShowOverflowMenu() &&
!ViewConfiguration.get(getContext()).hasPermanentMenuKey()) { !ViewConfiguration.get(getContext()).hasPermanentMenuKey()) {
@@ -1056,7 +1061,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override @Override
public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) { public boolean performPanelShortcut(int featureId, int keyCode, KeyEvent event, int flags) {
return performPanelShortcut(getPanelState(featureId, true), keyCode, event, flags); return performPanelShortcut(getPanelState(featureId, false), keyCode, event, flags);
} }
private boolean performPanelShortcut(PanelFeatureState st, int keyCode, KeyEvent event, private boolean performPanelShortcut(PanelFeatureState st, int keyCode, KeyEvent event,
@@ -1149,11 +1154,11 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mInvalidatePanelMenuRunnable.run(); mInvalidatePanelMenuRunnable.run();
} }
final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false);
// If we don't have a menu or we're waiting for a full content refresh, // If we don't have a menu or we're waiting for a full content refresh,
// forget it. This is a lingering event that no longer matters. // forget it. This is a lingering event that no longer matters.
if (st.menu != null && !st.refreshMenuContent && if (st != null && st.menu != null && !st.refreshMenuContent &&
cb.onPreparePanel(FEATURE_OPTIONS_PANEL, st.createdPanelView, st.menu)) { cb.onPreparePanel(FEATURE_OPTIONS_PANEL, st.createdPanelView, st.menu)) {
cb.onMenuOpened(FEATURE_ACTION_BAR, st.menu); cb.onMenuOpened(FEATURE_ACTION_BAR, st.menu);
mDecorContentParent.showOverflowMenu(); mDecorContentParent.showOverflowMenu();
@@ -1161,15 +1166,19 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
} }
} else { } else {
mDecorContentParent.hideOverflowMenu(); mDecorContentParent.hideOverflowMenu();
if (cb != null && !isDestroyed()) { final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false);
final PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); if (st != null && cb != null && !isDestroyed()) {
cb.onPanelClosed(FEATURE_ACTION_BAR, st.menu); cb.onPanelClosed(FEATURE_ACTION_BAR, st.menu);
} }
} }
return; return;
} }
PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false);
if (st == null) {
return;
}
// Save the future expanded mode state since closePanel will reset it // Save the future expanded mode state since closePanel will reset it
boolean newExpandedMode = toggleMenuMode ? !st.isInExpandedMode : st.isInExpandedMode; boolean newExpandedMode = toggleMenuMode ? !st.isInExpandedMode : st.isInExpandedMode;
@@ -2302,8 +2311,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
// combination such as Control+C. Temporarily prepare the panel then mark it // combination such as Control+C. Temporarily prepare the panel then mark it
// unprepared again when finished to ensure that the panel will again be prepared // unprepared again when finished to ensure that the panel will again be prepared
// the next time it is shown for real. // the next time it is shown for real.
if (mPreparedPanel == null) { PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false);
PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); if (st != null && mPreparedPanel == null) {
preparePanel(st, ev); preparePanel(st, ev);
handled = performPanelShortcut(st, ev.getKeyCode(), ev, handled = performPanelShortcut(st, ev.getKeyCode(), ev,
Menu.FLAG_PERFORM_NO_CLOSE); Menu.FLAG_PERFORM_NO_CLOSE);
@@ -3906,8 +3915,8 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
@Override @Override
public boolean isShortcutKey(int keyCode, KeyEvent event) { public boolean isShortcutKey(int keyCode, KeyEvent event) {
PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, true); PanelFeatureState st = getPanelState(FEATURE_OPTIONS_PANEL, false);
return st.menu != null && st.menu.isShortcutKey(keyCode, event); return st != null && st.menu != null && st.menu.isShortcutKey(keyCode, event);
} }
private void updateDrawable(int featureId, DrawableFeatureState st, boolean fromResume) { private void updateDrawable(int featureId, DrawableFeatureState st, boolean fromResume) {