diff options
author | John Reck <jreck@google.com> | 2011-09-15 10:08:06 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-09-15 10:08:06 -0700 |
commit | 13ec51769c2ee9f9e189050a510103226b6241de (patch) | |
tree | c6780d6b399931742d48db39add29ecbf12807ca | |
parent | a47929ffd8bd8fdd54f45d6b147fd74a2233f8f4 (diff) | |
parent | e1a03a366ff90ebcd8568a86b84a5917610cf512 (diff) | |
download | packages_apps_Browser-13ec51769c2ee9f9e189050a510103226b6241de.zip packages_apps_Browser-13ec51769c2ee9f9e189050a510103226b6241de.tar.gz packages_apps_Browser-13ec51769c2ee9f9e189050a510103226b6241de.tar.bz2 |
Merge "Cleanup menus"
-rw-r--r-- | res/menu/browser.xml | 39 | ||||
-rw-r--r-- | res/menu/snapshot_go_live.xml | 22 | ||||
-rw-r--r-- | src/com/android/browser/Controller.java | 22 | ||||
-rw-r--r-- | src/com/android/browser/NavigationBarPhone.java | 23 | ||||
-rw-r--r-- | src/com/android/browser/PhoneUi.java | 9 | ||||
-rw-r--r-- | src/com/android/browser/SnapshotBar.java | 33 | ||||
-rw-r--r-- | src/com/android/browser/UiController.java | 3 |
7 files changed, 69 insertions, 82 deletions
diff --git a/res/menu/browser.xml b/res/menu/browser.xml index 7d288c1..2b651c3 100644 --- a/res/menu/browser.xml +++ b/res/menu/browser.xml @@ -50,21 +50,30 @@ android:icon="@drawable/ic_bookmarks_history_holo_dark" android:alphabeticShortcut="b" android:visible="@bool/menu_show_bookmarks" /> - <item - android:id="@+id/share_page_menu_id" - android:title="@string/share_page" - android:icon="@drawable/ic_share_holo_dark" - android:alphabeticShortcut="s" /> - <item - android:id="@+id/find_menu_id" - android:title="@*android:string/find_on_page"/> - <item - android:id="@+id/ua_desktop_menu_id" - android:checkable="true" - android:title="@string/ua_switcher_desktop" /> - <item - android:id="@+id/save_snapshot_menu_id" - android:title="@string/menu_save_snapshot" /> + <group + android:id="@+id/LIVE_MENU"> + <item + android:id="@+id/share_page_menu_id" + android:title="@string/share_page" + android:icon="@drawable/ic_share_holo_dark" + android:alphabeticShortcut="s" /> + <item + android:id="@+id/find_menu_id" + android:title="@*android:string/find_on_page"/> + <item + android:id="@+id/ua_desktop_menu_id" + android:checkable="true" + android:title="@string/ua_switcher_desktop" /> + <item + android:id="@+id/save_snapshot_menu_id" + android:title="@string/menu_save_snapshot" /> + </group> + <group + android:id="@+id/SNAPSHOT_MENU"> + <item + android:id="@+id/snapshot_go_live" + android:title="@string/snapshot_go_live" /> + </group> <item android:id="@+id/page_info_menu_id" android:title="@string/page_info" /> diff --git a/res/menu/snapshot_go_live.xml b/res/menu/snapshot_go_live.xml deleted file mode 100644 index aa6b38e..0000000 --- a/res/menu/snapshot_go_live.xml +++ /dev/null @@ -1,22 +0,0 @@ -<?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. ---> - -<menu xmlns:android="http://schemas.android.com/apk/res/android"> - <item - android:id="@+id/snapshot_go_live" - android:title="@string/snapshot_go_live" /> -</menu> - diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 3533bf1..0a54a89 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -1245,10 +1245,6 @@ public class Controller } MenuInflater inflater = mActivity.getMenuInflater(); inflater.inflate(R.menu.browser, menu); - updateInLoadMenuItems(menu); - // hold on to the menu reference here; it is used by the page callbacks - // to update the menu based on loading state - mCachedMenu = menu; return true; } @@ -1432,6 +1428,10 @@ public class Controller } boolean onPrepareOptionsMenu(Menu menu) { + updateInLoadMenuItems(menu); + // hold on to the menu reference here; it is used by the page callbacks + // to update the menu based on loading state + mCachedMenu = menu; // Note: setVisible will decide whether an item is visible; while // setEnabled() will decide whether an item is enabled, which also means // whether the matching shortcut key will function. @@ -1462,11 +1462,13 @@ public class Controller boolean canGoForward = false; boolean isHome = false; boolean isDesktopUa = false; + boolean isLive = false; if (tab != null) { canGoBack = tab.canGoBack(); canGoForward = tab.canGoForward(); isHome = mSettings.getHomePage().equals(tab.getUrl()); isDesktopUa = mSettings.hasDesktopUseragent(tab.getWebView()); + isLive = !tab.isSnapshot(); } final MenuItem back = menu.findItem(R.id.back_menu_id); back.setEnabled(canGoBack); @@ -1483,6 +1485,7 @@ public class Controller dest.setTitle(source.getTitle()); dest.setIcon(source.getIcon()); } + menu.setGroupVisible(R.id.NAV_MENU, isLive); // decide whether to show the share link option PackageManager pm = mActivity.getPackageManager(); @@ -1503,6 +1506,8 @@ public class Controller counter.setEnabled(showDebugSettings); final MenuItem uaSwitcher = menu.findItem(R.id.ua_desktop_menu_id); uaSwitcher.setChecked(isDesktopUa); + menu.setGroupVisible(R.id.LIVE_MENU, isLive); + menu.setGroupVisible(R.id.SNAPSHOT_MENU, !isLive); mUi.updateMenuState(tab, menu); } @@ -1620,6 +1625,10 @@ public class Controller mPageDialogsHandler.showPageInfo(mTabControl.getCurrentTab(), false, null); break; + case R.id.snapshot_go_live: + goLive(); + return true; + case R.id.classic_history_menu_id: bookmarksOrHistoryPicker(true); break; @@ -1687,6 +1696,11 @@ public class Controller return true; } + private void goLive() { + Tab t = getCurrentTab(); + t.loadUrl(t.getUrl(), null); + } + public boolean onContextItemSelected(MenuItem item) { // Let the History and Bookmark fragments handle menus they created. if (item.getGroupId() == R.id.CONTEXT_MENU) { diff --git a/src/com/android/browser/NavigationBarPhone.java b/src/com/android/browser/NavigationBarPhone.java index 7e8695b..a1e778d 100644 --- a/src/com/android/browser/NavigationBarPhone.java +++ b/src/com/android/browser/NavigationBarPhone.java @@ -15,6 +15,7 @@ */ package com.android.browser; +import android.app.Activity; import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; @@ -174,14 +175,21 @@ public class NavigationBarPhone extends NavigationBarBase implements } void showMenu(View anchor) { - mOverflowMenuShowing = true; - mPopupMenu = new PopupMenu(mContext, anchor); + Activity activity = mUiController.getActivity(); + if (mPopupMenu == null) { + mPopupMenu = new PopupMenu(mContext, anchor); + mPopupMenu.setOnMenuItemClickListener(this); + mPopupMenu.setOnDismissListener(this); + if (!activity.onCreateOptionsMenu(mPopupMenu.getMenu())) { + mPopupMenu = null; + return; + } + } Menu menu = mPopupMenu.getMenu(); - mPopupMenu.getMenuInflater().inflate(R.menu.browser, menu); - mUiController.updateMenuState(mBaseUi.getActiveTab(), menu); - mPopupMenu.setOnMenuItemClickListener(this); - mPopupMenu.setOnDismissListener(this); - mPopupMenu.show(); + if (activity.onPrepareOptionsMenu(menu)) { + mOverflowMenuShowing = true; + mPopupMenu.show(); + } } @Override @@ -193,7 +201,6 @@ public class NavigationBarPhone extends NavigationBarBase implements private void onMenuHidden() { mOverflowMenuShowing = false; - mPopupMenu = null; mBaseUi.showTitleBarForDuration(); } diff --git a/src/com/android/browser/PhoneUi.java b/src/com/android/browser/PhoneUi.java index f5a76b9..606a47d 100644 --- a/src/com/android/browser/PhoneUi.java +++ b/src/com/android/browser/PhoneUi.java @@ -162,7 +162,6 @@ public class PhoneUi extends BaseUi { @Override public void updateMenuState(Tab tab, Menu menu) { - menu.setGroupVisible(R.id.NAV_MENU, (mNavScreen == null)); MenuItem bm = menu.findItem(R.id.bookmarks_menu_id); if (bm != null) { bm.setVisible(mNavScreen == null); @@ -173,7 +172,13 @@ public class PhoneUi extends BaseUi { } MenuItem abm = menu.findItem(R.id.add_bookmark_menu_id); if (abm != null) { - abm.setVisible((tab != null) && !tab.isSnapshot()); + abm.setVisible((tab != null) && !tab.isSnapshot() && mNavScreen == null); + } + if (mNavScreen != null) { + menu.setGroupVisible(R.id.LIVE_MENU, false); + menu.setGroupVisible(R.id.SNAPSHOT_MENU, false); + menu.findItem(R.id.page_info_menu_id).setVisible(false); + menu.setGroupVisible(R.id.NAV_MENU, false); } } diff --git a/src/com/android/browser/SnapshotBar.java b/src/com/android/browser/SnapshotBar.java index 039afcf..2fb90d2 100644 --- a/src/com/android/browser/SnapshotBar.java +++ b/src/com/android/browser/SnapshotBar.java @@ -21,7 +21,6 @@ import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.util.AttributeSet; -import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; @@ -29,21 +28,18 @@ import android.view.ViewConfiguration; import android.view.ViewPropertyAnimator; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.TextView; import java.text.DateFormat; import java.util.Date; -public class SnapshotBar extends LinearLayout implements OnClickListener, - OnMenuItemClickListener { +public class SnapshotBar extends LinearLayout implements OnClickListener { private static final int MSG_SHOW_TITLE = 1; private static final long DURATION_SHOW_DATE = BaseUi.HIDE_TITLEBAR_DELAY; private ImageView mFavicon; - private View mGoLive; private TextView mDate; private TextView mTitle; private View mBookmarks; @@ -86,10 +82,7 @@ public class SnapshotBar extends LinearLayout implements OnClickListener, @Override protected void onFinishInflate() { super.onFinishInflate(); - mGoLive = mFavicon = (ImageView) findViewById(R.id.favicon); - if (mGoLive == null) { - mGoLive = findViewById(R.id.date_icon); - } + mFavicon = (ImageView) findViewById(R.id.favicon); mDate = (TextView) findViewById(R.id.date); mTitle = (TextView) findViewById(R.id.title); mBookmarks = findViewById(R.id.all_btn); @@ -113,7 +106,6 @@ public class SnapshotBar extends LinearLayout implements OnClickListener, mToggleContainer.setOnClickListener(this); resetAnimation(); } - mGoLive.setOnClickListener(this); } @Override @@ -173,12 +165,6 @@ public class SnapshotBar extends LinearLayout implements OnClickListener, public void onClick(View v) { if (mBookmarks == v) { mTitleBar.getUiController().bookmarksOrHistoryPicker(false); - } else if (mGoLive == v) { - PopupMenu popup = new PopupMenu(mContext, mGoLive); - Menu menu = popup.getMenu(); - popup.getMenuInflater().inflate(R.menu.snapshot_go_live, menu); - popup.setOnMenuItemClickListener(this); - popup.show(); } else if (mTabSwitcher == v) { ((PhoneUi) mTitleBar.getUi()).toggleNavScreen(); } else if (mOverflowMenu == v) { @@ -195,21 +181,6 @@ public class SnapshotBar extends LinearLayout implements OnClickListener, } } - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.snapshot_go_live: - goLive(); - return true; - } - return false; - } - - private void goLive() { - Tab t = mTitleBar.getUi().getActiveTab(); - t.loadUrl(t.getUrl(), null); - } - public void onTabDataChanged(Tab tab) { if (!tab.isSnapshot()) return; SnapshotTab snapshot = (SnapshotTab) tab; diff --git a/src/com/android/browser/UiController.java b/src/com/android/browser/UiController.java index 0da523a..97e99a9 100644 --- a/src/com/android/browser/UiController.java +++ b/src/com/android/browser/UiController.java @@ -16,6 +16,7 @@ package com.android.browser; +import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; @@ -100,4 +101,6 @@ public interface UiController { void setBlockEvents(boolean block); + Activity getActivity(); + } |