diff options
author | David 'Digit' Turner <digit@google.com> | 2011-09-15 16:18:38 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-09-15 16:18:38 -0700 |
commit | b68db35d469fae510c35ef9ab0da7fe25fc88836 (patch) | |
tree | 8ec726131278ae5dfb1b52085573f2ca1d5fcc1d | |
parent | 3a20b79392e1d984b4a8c6299d249ddccbce192b (diff) | |
parent | eb117233adb17f67625c0409c32332591bf36485 (diff) | |
download | packages_apps_Browser-b68db35d469fae510c35ef9ab0da7fe25fc88836.zip packages_apps_Browser-b68db35d469fae510c35ef9ab0da7fe25fc88836.tar.gz packages_apps_Browser-b68db35d469fae510c35ef9ab0da7fe25fc88836.tar.bz2 |
Merge branch 'master' of ssh://android-git:29418/platform/packages/apps/Browser
-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/BrowserSettings.java | 8 | ||||
-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 | ||||
-rw-r--r-- | src/com/android/browser/UrlBarAutoShowManager.java | 2 | ||||
-rw-r--r-- | src/com/android/browser/WebStorageSizeManager.java | 4 | ||||
-rw-r--r-- | src/com/android/browser/preferences/AccessibilityPreferencesFragment.java | 3 | ||||
-rw-r--r-- | tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java | 6 |
12 files changed, 82 insertions, 92 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/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 6b8daec..cfaa18a 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -25,6 +25,7 @@ import android.os.Build; import android.os.Message; import android.preference.PreferenceManager; import android.provider.Browser; +import android.util.DisplayMetrics; import android.webkit.CookieManager; import android.webkit.GeolocationPermissions; import android.webkit.WebIconDatabase; @@ -104,6 +105,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, private WeakHashMap<WebSettings, String> mCustomUserAgents; private static boolean sInitialized = false; private boolean mNeedsSharedSync = true; + private float mFontSizeMult = 1.0f; // Cached values private int mPageCacheCapacity = 1; @@ -158,6 +160,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, @Override public void run() { + DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); + mFontSizeMult = metrics.scaledDensity / metrics.density; // the cost of one cached page is ~3M (measured using nytimes.com). For // low end devices, we only cache one page. For high end devices, we try // to cache more pages, currently choose 5. @@ -522,9 +526,9 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return rawValue; } - public static int getAdjustedTextZoom(int rawValue) { + public int getAdjustedTextZoom(int rawValue) { rawValue = (rawValue - TEXT_ZOOM_START_VAL) * TEXT_ZOOM_STEP; - return rawValue + 100; + return (int) ((rawValue + 100) * mFontSizeMult); } static int getRawTextZoom(int percent) { 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(); + } diff --git a/src/com/android/browser/UrlBarAutoShowManager.java b/src/com/android/browser/UrlBarAutoShowManager.java index b491e0b..f1bbe7f 100644 --- a/src/com/android/browser/UrlBarAutoShowManager.java +++ b/src/com/android/browser/UrlBarAutoShowManager.java @@ -103,7 +103,7 @@ public class UrlBarAutoShowManager implements OnTouchListener, case MotionEvent.ACTION_DOWN: if (!mIsTracking && event.getPointerCount() == 1) { long sinceLastScroll = - System.currentTimeMillis() - mLastScrollTime; + SystemClock.uptimeMillis() - mLastScrollTime; if (sinceLastScroll < IGNORE_INTERVAL) { break; } diff --git a/src/com/android/browser/WebStorageSizeManager.java b/src/com/android/browser/WebStorageSizeManager.java index 109a02b..73a3bfb 100644 --- a/src/com/android/browser/WebStorageSizeManager.java +++ b/src/com/android/browser/WebStorageSizeManager.java @@ -392,10 +392,6 @@ public class WebStorageSizeManager { if(LOGV_ENABLED) { Log.v(LOGTAG, "scheduleOutOfSpaceNotification called."); } - if (mContext == null) { - // mContext can be null if we're running unit tests. - return; - } if ((mLastOutOfSpaceNotificationTime == -1) || (System.currentTimeMillis() - mLastOutOfSpaceNotificationTime > NOTIFICATION_INTERVAL)) { // setup the notification boilerplate. diff --git a/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java b/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java index 312a61e..6adfd23 100644 --- a/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java +++ b/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java @@ -76,7 +76,8 @@ public class AccessibilityPreferencesFragment extends PreferenceFragment .getAdjustedMinimumFontSize((Integer) objValue)); } if (PreferenceKeys.PREF_TEXT_ZOOM.equals(pref.getKey())) { - updateTextZoomSummary(pref, BrowserSettings + BrowserSettings settings = BrowserSettings.getInstance(); + updateTextZoomSummary(pref, settings .getAdjustedTextZoom((Integer) objValue)); } if (PreferenceKeys.PREF_INVERTED_CONTRAST.equals(pref.getKey())) { diff --git a/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java b/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java index 354c4da..2beedf8 100644 --- a/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java +++ b/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java @@ -90,7 +90,8 @@ public class WebStorageSizeManagerUnitTests extends AndroidTestCase { // We have an appcache file size of 0 MB. mAppCacheInfo.setAppCacheSizeBytes(0); // Create the manager. - WebStorageSizeManager manager = new WebStorageSizeManager(null, mDiskInfo, mAppCacheInfo); + WebStorageSizeManager manager = new WebStorageSizeManager(getContext(), mDiskInfo, + mAppCacheInfo); // We add origin 1. long origin1Quota = 0; long origin1EstimatedSize = bytes(3.5); @@ -247,7 +248,8 @@ public class WebStorageSizeManagerUnitTests extends AndroidTestCase { mAppCacheInfo.setAppCacheSizeBytes(0); // Create the manager. - WebStorageSizeManager manager = new WebStorageSizeManager(null, mDiskInfo, mAppCacheInfo); + WebStorageSizeManager manager = new WebStorageSizeManager(getContext(), mDiskInfo, + mAppCacheInfo); // We add an origin. long originQuota = 0; |