Permalink
Browse files

Launcher2: add overflow menu in app drawer view for devices w/o a har…

…dware menu key

  *needed by gnex to access launcher settings
  *based on http://review.cyanogenmod.com/#change,11217 by nebkat

Change-Id: I422a468ec207d3a199dcb52393a116ff68c1003b
  • Loading branch information...
MongooseHelix committed Apr 2, 2012
1 parent f46bc4d commit 59a18d41ff674d1c15b92d541aa8a02018ddd38d
View
@@ -7,6 +7,7 @@
public void onClickConfigureButton(android.view.View);
public void onClickAllAppsButton(android.view.View);
public void onClickAppMarketButton(android.view.View);
+ public void onClickOverflowMenuButton(android.view.View);
public void dismissWorkspaceCling(android.view.View);
public void dismissAllAppsCling(android.view.View);
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,7 +16,7 @@
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
- style="@style/MarketButton"
+ style="@style/ExtraButton"
android:onClick="onClickAppMarketButton"
android:gravity="center"
android:paddingLeft="32dp"
@@ -39,12 +39,23 @@
android:background="@drawable/tab_unselected_holo"
android:tabStripEnabled="false"
android:divider="@null" />
- <include
- android:id="@+id/market_button"
- layout="@layout/market_button"
+ <LinearLayout
+ android:id="@+id/extra_buttons"
+ android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
- android:layout_gravity="right" />
+ android:layout_gravity="right">
+ <include
+ android:id="@+id/market_button"
+ layout="@layout/market_button"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent" />
+ <include
+ android:id="@+id/overflow_menu_button"
+ layout="@layout/overflow_menu_button"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent" />
+ </LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@android:id/tabcontent"
@@ -16,7 +16,7 @@
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
- style="@style/MarketButton"
+ style="@style/ExtraButton"
android:onClick="onClickAppMarketButton"
android:gravity="center"
android:paddingLeft="16dp"
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
+ style="@style/ExtraButton"
+ android:onClick="onClickOverflowMenuButton"
+ android:drawableLeft="@drawable/ic_menu_overflow"
+ android:gravity="center"
+ android:paddingLeft="16dp"
+ android:paddingRight="16dp"
+ android:background="@drawable/tab_widget_indicator_selector"
+ android:contentDescription="@string/menu"
+ android:shadowColor="@color/workspace_all_apps_and_delete_zone_text_shadow_color"
+ android:shadowDx="0.0"
+ android:shadowDy="0.0"
+ android:shadowRadius="2.0"
+ android:focusable="true"
+ android:clickable="true" />
View
@@ -43,6 +43,8 @@
<!-- Market button text. The market button text is removed in Launcher.java
in the Phone UI. [CHAR LIMIT=32] -->
<string name="market">Shop</string>
+ <!-- Overflow menu button text. -->
+ <string name="menu">Menu</string>
<!-- The format string for the dimensions of a widget in the drawer -->
<string name="widget_dims_format" translatable="false">%1$d x %2$d</string>
View
@@ -175,7 +175,7 @@
<!-- Overridden in values-land -->
</style>
- <style name="MarketButton">
+ <style name="ExtraButton">
<item name="android:paddingLeft">5dp</item>
<item name="android:paddingRight">5dp</item>
<item name="android:textColor">@color/workspace_all_apps_and_delete_zone_text_color</item>
@@ -129,6 +129,9 @@ public View createTabContent(String tag) {
View shopButton = findViewById(R.id.market_button);
shopButton.setOnKeyListener(keyListener);
+ View overflowMenuButton = findViewById(R.id.overflow_menu_button);
+ overflowMenuButton.setOnKeyListener(keyListener);
+
// Hide the tab bar until we measure
mTabsContainer.setAlpha(0f);
}
@@ -81,31 +81,36 @@ private static TabHost findTabHostParent(View v) {
}
/**
- * Handles key events in a AppsCustomize tab between the last tab view and the shop button.
+ * Handles key events in a AppsCustomize tab between the last tab view and the menu/shop buttons.
*/
static boolean handleAppsCustomizeTabKeyEvent(View v, int keyCode, KeyEvent e) {
final TabHost tabHost = findTabHostParent(v);
final ViewGroup contents = (ViewGroup)
tabHost.findViewById(com.android.internal.R.id.tabcontent);
final View shop = tabHost.findViewById(R.id.market_button);
+ final View overflowMenu = tabHost.findViewById(R.id.overflow_menu_button);
final int action = e.getAction();
final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
boolean wasHandled = false;
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (handleKeyEvent) {
- // Select the shop button if we aren't on it
- if (v != shop) {
- shop.requestFocus();
+ // Select the shop button if we aren't on it (or menu if shop isn't visible)
+ if (v != shop || v != overflowMenu) {
+ if (shop.getVisibility() == View.VISIBLE){
+ shop.requestFocus();
+ } else if (overflowMenu.getVisibility() == View.VISIBLE) {
+ overflowMenu.requestFocus();
+ }
}
}
wasHandled = true;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
if (handleKeyEvent) {
// Select the content view (down is handled by the tab key handler otherwise)
- if (v == shop) {
+ if (v == shop || v == overflowMenu) {
contents.requestFocus();
wasHandled = true;
}
@@ -78,6 +78,7 @@
import android.view.Surface;
import android.view.View;
import android.view.View.OnLongClickListener;
+import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
@@ -89,6 +90,7 @@
import android.widget.Advanceable;
import android.widget.EditText;
import android.widget.ImageView;
+import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
@@ -1770,6 +1772,14 @@ public void onClickAppMarketButton(View v) {
}
}
+ public void onClickOverflowMenuButton(View v) {
+ final PopupMenu popupMenu = new PopupMenu(this, v);
+ final Menu menu = popupMenu.getMenu();
+ onCreateOptionsMenu(menu);
+ onPrepareOptionsMenu(menu);
+ popupMenu.show();
+ }
+
void startApplicationDetailsActivity(ComponentName componentName) {
String packageName = componentName.getPackageName();
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
@@ -2797,6 +2807,16 @@ private void updateAppMarketIcon(Drawable.ConstantState d) {
updateTextButtonWithDrawable(R.id.market_button, d);
}
+ private void updateOverflowMenuButton() {
+ View overflowMenuButton = findViewById(R.id.overflow_menu_button);
+ if (ViewConfiguration.get(this).hasPermanentMenuKey()) {
+ overflowMenuButton.setVisibility(View.GONE);
+ overflowMenuButton.setEnabled(false);
+ } else {
+ overflowMenuButton.setVisibility(View.VISIBLE);
+ }
+ }
+
/**
* Displays the shortcut creation dialog and launches, if necessary, the
* appropriate activity.
@@ -3072,6 +3092,9 @@ public void finishBindingItems() {
// package changes in bindSearchablesChanged()
updateAppMarketIcon();
+ // Hide overflow menu on devices with a hardkey
+ updateOverflowMenuButton();
+
mWorkspace.post(mBuildLayersRunnable);
}

0 comments on commit 59a18d4

Please sign in to comment.