summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kolb <kolby@google.com>2011-07-11 15:26:47 -0700
committerMichael Kolb <kolby@google.com>2011-07-11 16:06:56 -0700
commit017ffabc8af29b0cf14fecc6aad4a61acb8373a2 (patch)
treead684a56d9fbcd844fbbf9ea06b787acb6d1e90f
parent0241e7556501caae1f57d2bdf3677d7e4a619eb0 (diff)
downloadpackages_apps_Browser-017ffabc8af29b0cf14fecc6aad4a61acb8373a2.zip
packages_apps_Browser-017ffabc8af29b0cf14fecc6aad4a61acb8373a2.tar.gz
packages_apps_Browser-017ffabc8af29b0cf14fecc6aad4a61acb8373a2.tar.bz2
Add overflow menu to title bar
Bug: 5011697 Change-Id: Idcd9ddc2883caa0ee0513300b8322af1c6d89423
-rw-r--r--res/layout/qc_menu_item.xml6
-rw-r--r--res/layout/title_bar.xml7
-rw-r--r--res/values/dimensions.xml1
-rw-r--r--src/com/android/browser/BaseUi.java2
-rw-r--r--src/com/android/browser/NavScreen.java99
-rw-r--r--src/com/android/browser/PhoneUi.java12
-rw-r--r--src/com/android/browser/TitleBarPhone.java53
7 files changed, 89 insertions, 91 deletions
diff --git a/res/layout/qc_menu_item.xml b/res/layout/qc_menu_item.xml
index 9e4a2e8..6c84aa6 100644
--- a/res/layout/qc_menu_item.xml
+++ b/res/layout/qc_menu_item.xml
@@ -17,12 +17,12 @@
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_width="@dimen/menu_width"
+ android:layout_height="@dimen/menu_height"
android:minHeight="44dip"
android:background="@drawable/qc_menu_selector"
android:textAppearance="?android:attr/textAppearanceMedium"
- android:gravity="center"
+ android:gravity="center_vertical"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="4dip"
diff --git a/res/layout/title_bar.xml b/res/layout/title_bar.xml
index 9096418..7789bfc 100644
--- a/res/layout/title_bar.xml
+++ b/res/layout/title_bar.xml
@@ -90,6 +90,13 @@
android:layout_height="match_parent"
android:src="@drawable/ic_windows_holo_dark"
style="@style/HoloButton" />
+ <ImageButton
+ android:id="@+id/more"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ style="@style/HoloButton"
+ android:gravity="center_vertical"
+ android:src="@*android:drawable/ic_menu_moreoverflow_normal_holo_dark" />
</LinearLayout>
<LinearLayout
android:id="@+id/autologin"
diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml
index b3236a7..62deb06 100644
--- a/res/values/dimensions.xml
+++ b/res/values/dimensions.xml
@@ -65,6 +65,7 @@
<dimen name="preference_widget_width">56dp</dimen>
<dimen name="nav_tab_spacing">8dp</dimen>
<dimen name="menu_width">240dip</dimen>
+ <dimen name="menu_height">32dip</dimen>
<dimen name="toolbar_height">52dip</dimen>
<dimen name="tab_capture_size">160dp</dimen>
<dimen name="nav_tab_width">240dip</dimen>
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java
index 3638bbf..9de2c57 100644
--- a/src/com/android/browser/BaseUi.java
+++ b/src/com/android/browser/BaseUi.java
@@ -824,7 +824,7 @@ public abstract class BaseUi implements UI, OnTouchListener {
}
}
- private void showTitleBarForDuration() {
+ protected void showTitleBarForDuration() {
mHandler.removeMessages(MSG_HIDE_TITLEBAR);
showTitleBar();
Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
diff --git a/src/com/android/browser/NavScreen.java b/src/com/android/browser/NavScreen.java
index a841989..43a38e0 100644
--- a/src/com/android/browser/NavScreen.java
+++ b/src/com/android/browser/NavScreen.java
@@ -32,16 +32,13 @@ import android.widget.Gallery;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.ListPopupWindow;
+import android.widget.PopupMenu;
+import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
-import com.android.browser.view.Gallery.OnItemSelectedListener;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class NavScreen extends RelativeLayout implements OnClickListener {
+public class NavScreen extends RelativeLayout
+ implements OnClickListener, OnMenuItemClickListener {
UiController mUiController;
PhoneUi mUi;
@@ -65,7 +62,6 @@ public class NavScreen extends RelativeLayout implements OnClickListener {
int mTabWidth;
int mTabHeight;
TabAdapter mAdapter;
- ListPopupWindow mPopup;
int mOrientation;
public NavScreen(Activity activity, UiController ctl, PhoneUi ui) {
@@ -82,30 +78,21 @@ public class NavScreen extends RelativeLayout implements OnClickListener {
}
protected void showMenu() {
- Menu menu = mUi.getMenu();
+ PopupMenu popup = new PopupMenu(mContext, mMore);
+ Menu menu = popup.getMenu();
+ popup.getMenuInflater().inflate(R.menu.browser, menu);
menu.setGroupVisible(R.id.NAV_MENU, false);
-
- MenuAdapter menuAdapter = new MenuAdapter(mContext);
- menuAdapter.setMenu(menu);
- ListPopupWindow popup = new ListPopupWindow(mContext);
- popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
- popup.setAdapter(menuAdapter);
- popup.setModal(true);
- popup.setAnchorView(mMore);
- popup.setWidth((int) mContext.getResources().getDimension(
- R.dimen.menu_width));
+ popup.setOnMenuItemClickListener(this);
popup.show();
- mPopup = popup;
}
- protected float getToolbarHeight() {
- return mActivity.getResources().getDimension(R.dimen.toolbar_height);
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ return mUiController.onOptionsItemSelected(item);
}
- protected void dismissMenu() {
- if (mPopup != null) {
- mPopup.dismiss();
- }
+ protected float getToolbarHeight() {
+ return mActivity.getResources().getDimension(R.dimen.toolbar_height);
}
// for configuration changes
@@ -284,64 +271,4 @@ public class NavScreen extends RelativeLayout implements OnClickListener {
}
- private class MenuAdapter extends BaseAdapter implements OnClickListener {
-
- List<MenuItem> mItems;
- LayoutInflater mInflater;
-
- public MenuAdapter(Context ctx) {
- mInflater = LayoutInflater.from(ctx);
- mItems = new ArrayList<MenuItem>();
- }
-
- public void setMenu(Menu menu) {
- mItems.clear();
- for (int i = 0; i < menu.size(); i++) {
- MenuItem item = menu.getItem(i);
- if (item.isEnabled() && item.isVisible()) {
- mItems.add(item);
- }
- }
- notifyDataSetChanged();
- }
-
- @Override
- public int getCount() {
- return mItems.size();
- }
-
- @Override
- public MenuItem getItem(int position) {
- return mItems.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public void onClick(View v) {
- if (v.getTag() != null) {
- dismissMenu();
- mActivity.closeOptionsMenu();
- mUi.hideNavScreen(false);
- mUiController.onOptionsItemSelected((MenuItem) v.getTag());
- }
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- final MenuItem item = mItems.get(position);
- View view = mInflater.inflate(R.layout.qc_menu_item, null);
- TextView label = (TextView) view.findViewById(R.id.title);
- label.setText(item.getTitle());
- label.setTag(item);
- label.setOnClickListener(this);
- return label;
- }
-
- }
-
-
}
diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java
index 20c90f6..d1db578 100644
--- a/src/com/android/browser/PhoneUi.java
+++ b/src/com/android/browser/PhoneUi.java
@@ -183,6 +183,18 @@ public class PhoneUi extends BaseUi {
return mTitleBar;
}
+ /**
+ * Suggest to the UI that the title bar can be hidden. The UI will then
+ * decide whether or not to hide based off a number of factors, such
+ * as if the user is editing the URL bar or if the page is loading
+ */
+ @Override
+ public void suggestHideTitleBar() {
+ if (!isLoading() && !isEditingUrl() && !mTitleBar.isMenuShowing()) {
+ hideTitleBar();
+ }
+ }
+
// active tabs page
@Override
diff --git a/src/com/android/browser/TitleBarPhone.java b/src/com/android/browser/TitleBarPhone.java
index f41eca7..66b4648 100644
--- a/src/com/android/browser/TitleBarPhone.java
+++ b/src/com/android/browser/TitleBarPhone.java
@@ -21,13 +21,18 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.ContextMenu;
+import android.view.Menu;
import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
+import android.view.ViewConfiguration;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.PopupMenu;
+import android.widget.PopupMenu.OnDismissListener;
import com.android.browser.UrlInputView.StateListener;
import com.android.browser.autocomplete.SuggestedTextController.TextChangeWatcher;
@@ -39,7 +44,7 @@ import java.util.List;
* browser.
*/
public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener,
- OnClickListener, TextChangeWatcher, StateListener {
+ OnClickListener, TextChangeWatcher, StateListener, OnDismissListener {
private Activity mActivity;
private ImageView mStopButton;
@@ -49,11 +54,15 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener
private View mTabSwitcher;
private View mComboIcon;
private View mTitleContainer;
+ private View mMore;
private Drawable mTextfieldBgDrawable;
+ private boolean mMenuShowing;
+ private boolean mNeedsMenu;
public TitleBarPhone(Activity activity, UiController controller, PhoneUi ui,
FrameLayout parent) {
super(activity, controller, ui, parent);
+ mNeedsMenu = !ViewConfiguration.get(activity).hasPermanentMenuKey();
mActivity = activity;
initLayout(activity, R.layout.title_bar);
}
@@ -69,6 +78,8 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener
mVoiceButton.setOnClickListener(this);
mTabSwitcher = findViewById(R.id.tab_switcher);
mTabSwitcher.setOnClickListener(this);
+ mMore = findViewById(R.id.more);
+ mMore.setOnClickListener(this);
mComboIcon = findViewById(R.id.iconcombo);
mTitleContainer = findViewById(R.id.title_bg);
setFocusState(false);
@@ -164,11 +175,48 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener
mUiController.startVoiceSearch();
} else if (v == mTabSwitcher) {
mBaseUi.onMenuKey();
+ } else if (mMore == v) {
+ showMenu();
} else {
super.onClick(v);
}
}
+ public boolean isMenuShowing() {
+ return mMenuShowing;
+ }
+
+ private void showMenu() {
+ mMenuShowing = true;
+ PopupMenu popup = new PopupMenu(mContext, mMore);
+ Menu menu = popup.getMenu();
+ popup.getMenuInflater().inflate(R.menu.browser, menu);
+ menu.setGroupVisible(R.id.NAV_MENU, false);
+ popup.setOnMenuItemClickListener(this);
+ popup.setOnDismissListener(this);
+ popup.show();
+ }
+
+ @Override
+ public void onDismiss(PopupMenu menu) {
+ onMenuHidden();
+ }
+
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ onMenuHidden();
+ boolean res = mUiController.onOptionsItemSelected(item);
+ if (!res) {
+ return super.onMenuItemClick(item);
+ }
+ return res;
+ }
+
+ private void onMenuHidden() {
+ mMenuShowing = false;
+ mBaseUi.showTitleBarForDuration();
+ }
+
@Override
public void onStateChanged(int state) {
switch(state) {
@@ -178,12 +226,14 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener
setSearchMode(false);
mTabSwitcher.setVisibility(View.VISIBLE);
mTitleContainer.setBackgroundDrawable(null);
+ mMore.setVisibility(mNeedsMenu ? View.VISIBLE : View.GONE);
break;
case StateListener.STATE_HIGHLIGHTED:
mComboIcon.setVisibility(View.GONE);
mStopButton.setVisibility(View.VISIBLE);
setSearchMode(true);
mTabSwitcher.setVisibility(View.GONE);
+ mMore.setVisibility(View.GONE);
mTitleContainer.setBackgroundDrawable(mTextfieldBgDrawable);
break;
case StateListener.STATE_EDITED:
@@ -191,6 +241,7 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener
mStopButton.setVisibility(View.GONE);
setSearchMode(false);
mTabSwitcher.setVisibility(View.GONE);
+ mMore.setVisibility(View.GONE);
mTitleContainer.setBackgroundDrawable(mTextfieldBgDrawable);
break;
}