diff options
author | John Reck <jreck@google.com> | 2011-06-07 14:36:10 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-06-07 14:36:31 -0700 |
commit | 4650033a3790598316d01deef8f52d0bf39d5837 (patch) | |
tree | a9702858448dcb40c05f4a5601b847169a212b83 /src/com | |
parent | f33b1637487af3786ee30f295f2c84db6db1e6b3 (diff) | |
download | packages_apps_browser-4650033a3790598316d01deef8f52d0bf39d5837.zip packages_apps_browser-4650033a3790598316d01deef8f52d0bf39d5837.tar.gz packages_apps_browser-4650033a3790598316d01deef8f52d0bf39d5837.tar.bz2 |
New useragent switcher design
Uses a popup menu off of the globe on tablets or favicon on phones
Change-Id: Ia3634b5a218456127abb8b266a6cfc664836b037
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 16 | ||||
-rw-r--r-- | src/com/android/browser/PreferenceKeys.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarBase.java | 52 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarPhone.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/TitleBarXLarge.java | 44 | ||||
-rw-r--r-- | src/com/android/browser/preferences/LabPreferencesFragment.java | 12 |
6 files changed, 61 insertions, 65 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 46d47b0..101effa 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -16,11 +16,6 @@ package com.android.browser; -import com.android.browser.homepages.HomeProvider; -import com.android.browser.provider.BrowserProvider; -import com.android.browser.search.SearchEngine; -import com.android.browser.search.SearchEngines; - import android.app.ActivityManager; import android.content.ContentResolver; import android.content.Context; @@ -43,6 +38,11 @@ import android.webkit.WebStorage; import android.webkit.WebView; import android.webkit.WebViewDatabase; +import com.android.browser.homepages.HomeProvider; +import com.android.browser.provider.BrowserProvider; +import com.android.browser.search.SearchEngine; +import com.android.browser.search.SearchEngines; + import java.lang.ref.WeakReference; import java.util.Iterator; import java.util.LinkedList; @@ -165,7 +165,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, settings.setAutoFillProfile(getAutoFillProfile()); String ua = mCustomUserAgents.get(settings); - if (enableUseragentSwitcher() && ua != null) { + if (ua != null) { settings.setUserAgentString(ua); } else { settings.setUserAgentString(USER_AGENTS[getUserAgent()]); @@ -606,10 +606,6 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return mPrefs.getBoolean(PREF_FULLSCREEN, false); } - public boolean enableUseragentSwitcher() { - return mPrefs.getBoolean(PREF_ENABLE_USERAGENT_SWITCHER, false); - } - // ----------------------------- // getter/setters for privacy_security_preferences.xml // ----------------------------- diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java index cff9f70..f7230df 100644 --- a/src/com/android/browser/PreferenceKeys.java +++ b/src/com/android/browser/PreferenceKeys.java @@ -78,7 +78,6 @@ public interface PreferenceKeys { static final String PREF_USE_MOST_VISITED_HOMEPAGE = "use_most_visited_homepage"; static final String PREF_USE_INSTANT_SEARCH = "use_instant_search"; static final String PREF_FULLSCREEN = "fullscreen"; - static final String PREF_ENABLE_USERAGENT_SWITCHER = "enable_useragent_switcher"; // ---------------------- // Keys for privacy_security_preferences.xml diff --git a/src/com/android/browser/TitleBarBase.java b/src/com/android/browser/TitleBarBase.java index 4dc960c..b95711e 100644 --- a/src/com/android/browser/TitleBarBase.java +++ b/src/com/android/browser/TitleBarBase.java @@ -35,6 +35,8 @@ import android.view.ContextThemeWrapper; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; @@ -48,6 +50,8 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.PopupMenu; +import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.Spinner; @@ -60,7 +64,8 @@ import java.util.List; */ public class TitleBarBase extends RelativeLayout implements OnClickListener, OnFocusChangeListener, UrlInputListener, - TextChangeWatcher, DeviceAccountLogin.AutoLoginCallback { + TextChangeWatcher, DeviceAccountLogin.AutoLoginCallback, + OnMenuItemClickListener { protected static final int PROGRESS_MAX = 100; @@ -75,7 +80,7 @@ public class TitleBarBase extends RelativeLayout protected UrlInputView mUrlInput; protected boolean mInVoiceMode; protected View mContainer; - + private View mUaSwitcher; // Auto-login UI protected View mAutoLogin; @@ -385,6 +390,14 @@ public class TitleBarBase extends RelativeLayout return mAutoLoginHandler != null; } + public void setUaSwitcher(View v) { + if (mUaSwitcher != null) { + mUaSwitcher.setOnClickListener(null); + } + mUaSwitcher = v; + mUaSwitcher.setOnClickListener(this); + } + @Override public void onClick(View v) { if (mAutoLoginCancel == v) { @@ -402,7 +415,42 @@ public class TitleBarBase extends RelativeLayout mAutoLoginHandler.login( mAutoLoginAccount.getSelectedItemPosition(), this); } + } else if (mUaSwitcher == v) { + BrowserSettings settings = BrowserSettings.getInstance(); + WebView web = getCurrentWebView(); + if (web == null) return; + boolean desktop = settings.hasDesktopUseragent(web); + PopupMenu popup = new PopupMenu(mContext, mUaSwitcher); + Menu menu = popup.getMenu(); + popup.getMenuInflater().inflate(R.menu.ua_switcher, menu); + menu.findItem(R.id.ua_mobile_menu_id).setChecked(!desktop); + menu.findItem(R.id.ua_desktop_menu_id).setChecked(desktop); + popup.setOnMenuItemClickListener(this); + popup.show(); + } + } + + @Override + public boolean onMenuItemClick(MenuItem item) { + BrowserSettings settings = BrowserSettings.getInstance(); + WebView web = getCurrentWebView(); + if (web == null) return false; + boolean desktop = settings.hasDesktopUseragent(web); + switch (item.getItemId()) { + case R.id.ua_mobile_menu_id: + if (desktop) { + settings.toggleDesktopUseragent(web); + web.loadUrl(web.getOriginalUrl()); + } + return true; + case R.id.ua_desktop_menu_id: + if (!desktop) { + settings.toggleDesktopUseragent(web); + web.loadUrl(web.getOriginalUrl()); + } + return true; } + return false; } @Override diff --git a/src/com/android/browser/TitleBarPhone.java b/src/com/android/browser/TitleBarPhone.java index 97fe747..75b9fb7 100644 --- a/src/com/android/browser/TitleBarPhone.java +++ b/src/com/android/browser/TitleBarPhone.java @@ -71,6 +71,7 @@ public class TitleBarPhone extends TitleBarBase implements OnFocusChangeListener Resources res = context.getResources(); mStopDrawable = res.getDrawable(R.drawable.ic_stop_holo_dark); mRefreshDrawable = res.getDrawable(R.drawable.ic_refresh_holo_dark); + setUaSwitcher(mFavicon); } @Override diff --git a/src/com/android/browser/TitleBarXLarge.java b/src/com/android/browser/TitleBarXLarge.java index 8c03e4c..91709cc 100644 --- a/src/com/android/browser/TitleBarXLarge.java +++ b/src/com/android/browser/TitleBarXLarge.java @@ -62,8 +62,6 @@ public class TitleBarXLarge extends TitleBarBase private ImageView mVoiceSearch; private Drawable mFocusDrawable; private Drawable mUnfocusDrawable; - private boolean mHasFocus = false; - private BrowserSettings mSettings; public TitleBarXLarge(Activity activity, UiController controller, XLargeUi ui, FrameLayout parent) { @@ -77,10 +75,7 @@ public class TitleBarXLarge extends TitleBarBase mUnfocusDrawable = resources.getDrawable( R.drawable.textfield_default_holo_dark); mInVoiceMode = false; - mSettings = BrowserSettings.getInstance(); initLayout(activity, R.layout.url_bar); - PreferenceManager.getDefaultSharedPreferences(activity) - .registerOnSharedPreferenceChangeListener(mSharedPrefsListener); } @Override @@ -109,7 +104,7 @@ public class TitleBarXLarge extends TitleBarBase mGoButton.setOnClickListener(this); mClearButton.setOnClickListener(this); mVoiceSearch.setOnClickListener(this); - mUrlIcon.setOnClickListener(this); + setUaSwitcher(mUrlIcon); mUrlInput.setContainer(mUrlContainer); setFocusState(false); } @@ -187,13 +182,6 @@ public class TitleBarXLarge extends TitleBarBase clearOrClose(); } else if (mVoiceSearch == v) { mUiController.startVoiceSearch(); - } else if (mUrlIcon == v) { - WebView web = mUiController.getCurrentWebView(); - if (mSettings.enableUseragentSwitcher() && web != null) { - mSettings.toggleDesktopUseragent(web); - web.loadUrl(web.getOriginalUrl()); - updateUrlIcon(); - } } else { super.onClick(v); } @@ -213,38 +201,14 @@ public class TitleBarXLarge extends TitleBarBase } void updateUrlIcon() { - if (mHasFocus) { - return; - } - if (!mInVoiceMode && mSettings.enableUseragentSwitcher()) { - WebView web = mUiController.getCurrentWebView(); - if (mSettings.hasDesktopUseragent(web)) { - mUrlIcon.setImageResource(R.drawable.ic_ua_desktop); - } else { - mUrlIcon.setImageResource(R.drawable.ic_ua_android); - } - } else { - mUrlIcon.setImageResource(mInVoiceMode ? - R.drawable.ic_search_holo_dark - : R.drawable.ic_web_holo_dark); - } + mUrlIcon.setImageResource(mInVoiceMode ? + R.drawable.ic_search_holo_dark + : R.drawable.ic_web_holo_dark); } - private OnSharedPreferenceChangeListener mSharedPrefsListener = - new OnSharedPreferenceChangeListener() { - - @Override - public void onSharedPreferenceChanged( - SharedPreferences sharedPreferences, String key) { - updateUrlIcon(); - } - - }; - @Override protected void setFocusState(boolean focus) { super.setFocusState(focus); - mHasFocus = focus; if (focus) { mSearchButton.setVisibility(View.GONE); mStar.setVisibility(View.GONE); diff --git a/src/com/android/browser/preferences/LabPreferencesFragment.java b/src/com/android/browser/preferences/LabPreferencesFragment.java index d9ef3df..0dd8805 100644 --- a/src/com/android/browser/preferences/LabPreferencesFragment.java +++ b/src/com/android/browser/preferences/LabPreferencesFragment.java @@ -45,7 +45,6 @@ public class LabPreferencesFragment extends PreferenceFragment // Load the XML preferences file addPreferencesFromResource(R.xml.lab_preferences); registerChangeListener(PreferenceKeys.PREF_ENABLE_QUICK_CONTROLS); - registerChangeListener(PreferenceKeys.PREF_ENABLE_USERAGENT_SWITCHER); useInstantPref = findPreference(PreferenceKeys.PREF_USE_INSTANT_SEARCH); } @@ -81,17 +80,6 @@ public class LabPreferencesFragment extends PreferenceFragment startActivity(new Intent(BrowserActivity.ACTION_RESTART, null, getActivity(), BrowserActivity.class)); } - if (PreferenceKeys.PREF_ENABLE_USERAGENT_SWITCHER.equals(key)) { - if ((Boolean)newValue) { - // Show the help - LayoutInflater inflater = LayoutInflater.from(getActivity()); - View content = inflater.inflate(R.layout.help_dialog_useragent_switcher, null); - new AlertDialog.Builder(getActivity()) - .setView(content) - .setNeutralButton(android.R.string.ok, null) - .show(); - } - } return true; } } |