diff options
| author | John Reck <jreck@google.com> | 2010-12-02 16:09:14 -0800 |
|---|---|---|
| committer | John Reck <jreck@google.com> | 2010-12-03 12:52:31 -0800 |
| commit | ef0742696d31a3661414089446ff9a3ddd786639 (patch) | |
| tree | abfa278fee21281254f636653c7569de560ee855 /src/com/android/browser | |
| parent | 89f73c1146f474641881e3e20c77cfbfc18fa313 (diff) | |
| download | packages_apps_Browser-ef0742696d31a3661414089446ff9a3ddd786639.tar.gz packages_apps_Browser-ef0742696d31a3661414089446ff9a3ddd786639.tar.bz2 packages_apps_Browser-ef0742696d31a3661414089446ff9a3ddd786639.zip | |
Change homepage setting handling
Bug: 3247095
Tweaks the setting of the homepage setting. Replaces the "set to..."
dialog with 2 buttons, and user can now enter a blank url to get a
blank page with title "New Tab".
Change-Id: I95bcfcd241db4b9efbde645100d2fd44c980e061
Diffstat (limited to 'src/com/android/browser')
| -rw-r--r-- | src/com/android/browser/BaseUi.java | 16 | ||||
| -rw-r--r-- | src/com/android/browser/BrowserHomepagePreference.java | 88 | ||||
| -rw-r--r-- | src/com/android/browser/BrowserSettings.java | 2 | ||||
| -rw-r--r-- | src/com/android/browser/Controller.java | 29 | ||||
| -rw-r--r-- | src/com/android/browser/TabBar.java | 1 | ||||
| -rw-r--r-- | src/com/android/browser/TitleBar.java | 4 | ||||
| -rw-r--r-- | src/com/android/browser/preferences/PageContentPreferencesFragment.java | 25 |
7 files changed, 38 insertions, 127 deletions
diff --git a/src/com/android/browser/BaseUi.java b/src/com/android/browser/BaseUi.java index 79c3327fc..f5851df66 100644 --- a/src/com/android/browser/BaseUi.java +++ b/src/com/android/browser/BaseUi.java @@ -245,15 +245,14 @@ public class BaseUi implements UI, WebViewFactory { @Override public void onPageStarted(Tab tab, String url, Bitmap favicon) { - if (mXLargeScreenSize) { - mTabBar.onPageStarted(tab, url, favicon); - } if (tab.inForeground()) { resetLockIcon(tab, url); setUrlTitle(tab, url, null); setFavicon(tab, favicon); } - + if (mXLargeScreenSize) { + mTabBar.onPageStarted(tab, url, favicon); + } } @Override @@ -706,7 +705,7 @@ public class BaseUi implements UI, WebViewFactory { setUrlTitle(tab, item.getUrl(), item.getTitle()); setFavicon(tab, item.getFavicon()); } else { - setUrlTitle(tab, null, null); + setUrlTitle(tab, null, mActivity.getString(R.string.new_tab)); setFavicon(tab, null); } } @@ -850,12 +849,7 @@ public class BaseUi implements UI, WebViewFactory { @Override public void setUrlTitle(Tab tab, String url, String title) { if (TextUtils.isEmpty(title)) { - if (TextUtils.isEmpty(url)) { - title = mActivity.getResources() - .getString(R.string.title_bar_loading); - } else { - title = url; - } + title = url; } if (tab.isInVoiceSearchMode()) return; if (tab.inForeground()) { diff --git a/src/com/android/browser/BrowserHomepagePreference.java b/src/com/android/browser/BrowserHomepagePreference.java index 988605320..80f7ec251 100644 --- a/src/com/android/browser/BrowserHomepagePreference.java +++ b/src/com/android/browser/BrowserHomepagePreference.java @@ -22,34 +22,28 @@ import android.content.DialogInterface; import android.os.Bundle; import android.preference.EditTextPreference; import android.util.AttributeSet; -import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; -import android.widget.Button; import android.widget.EditText; -import android.widget.LinearLayout; -import android.widget.Toast; public class BrowserHomepagePreference extends EditTextPreference { private String mCurrentPage; - private AlertDialog mSetHomepageTo; public BrowserHomepagePreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - createSetHomepageToDialog(); } public BrowserHomepagePreference(Context context, AttributeSet attrs) { super(context, attrs); - createSetHomepageToDialog(); } public BrowserHomepagePreference(Context context) { super(context); - createSetHomepageToDialog(); } @Override @@ -58,66 +52,40 @@ public class BrowserHomepagePreference extends EditTextPreference { super.onAddEditTextToDialogView(dialogView, editText); // Now the EditText has a parent. Add a button to set to the current // page. - ViewGroup parent = (ViewGroup) editText.getParent(); - Button button = new Button(getContext()); - button.setText(R.string.pref_set_homepage_to); - button.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - mSetHomepageTo.show(); - } - }); - if (parent instanceof LinearLayout) { - ((LinearLayout) parent).setGravity(Gravity.CENTER_HORIZONTAL); - } - parent.addView(button, ViewGroup.LayoutParams.WRAP_CONTENT, - ViewGroup.LayoutParams.WRAP_CONTENT); + createButtons((ViewGroup) editText.getParent()); } - private void createSetHomepageToDialog() { - Context context = getContext(); - CharSequence[] setToChoices = new CharSequence[] { - context.getText(R.string.pref_use_current), - context.getText(R.string.pref_use_blank), - context.getText(R.string.pref_use_default), - }; - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(R.string.pref_set_homepage_to); - builder.setItems(setToChoices, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (which == 0) { - getEditText().setText(mCurrentPage); - } else if (which == 1) { - getEditText().setText("about:blank"); - } else if (which == 2) { - getEditText().setText(BrowserSettings - .getFactoryResetHomeUrl(getContext())); - } - } - }); - mSetHomepageTo = builder.create(); + void createButtons(ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater) getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View v = inflater.inflate(R.layout.pref_homepage_buttons, parent); + v.findViewById(R.id.use_current).setOnClickListener(mOnClick); + v.findViewById(R.id.use_default).setOnClickListener(mOnClick); } + OnClickListener mOnClick = new OnClickListener() { + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.use_current: + getEditText().setText(mCurrentPage); + break; + case R.id.use_default: + getEditText().setText( + BrowserSettings.getFactoryResetHomeUrl(getContext())); + break; + } + } + }; + @Override protected void onDialogClosed(boolean positiveResult) { if (positiveResult) { - String url = getEditText().getText().toString(); - if (url.length() > 0 - && !UrlUtils.ACCEPTED_URI_SCHEMA.matcher(url) - .matches()) { - int colon = url.indexOf(':'); - int space = url.indexOf(' '); - if (colon == -1 && space == -1 && url.length() > 0) { - // if no colon, no space, add "http://" to make it a url - getEditText().setText("http://" + url); - } else { - // show an error toast and change the positiveResult to - // false so that the bad url will not override the old url - Toast.makeText(getContext(), R.string.bookmark_url_not_valid, - Toast.LENGTH_SHORT).show(); - positiveResult = false; - } + String url = getEditText().getText().toString().trim(); + if (url.length() > 0) { + url = UrlUtils.smartUrlFilter(url); } + getEditText().setText(url); } super.onDialogClosed(positiveResult); } diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 61ef76bd9..1f091e215 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -337,7 +337,7 @@ public class BrowserSettings extends Observable implements OnSharedPreferenceCha // Set the default value for the Geolocation database path. geolocationDatabasePath = mContext.getDir("geolocation", 0).getPath(); - if (p.getString(PREF_HOMEPAGE, "") == "") { + if (p.getString(PREF_HOMEPAGE, null) == null) { // No home page preferences is set, set it to default. setHomePage(mContext, getFactoryResetHomeUrl(mContext)); } diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java index 75dd913a7..b26e9f083 100644 --- a/src/com/android/browser/Controller.java +++ b/src/com/android/browser/Controller.java @@ -108,10 +108,6 @@ public class Controller private static final int EMPTY_MENU = -1; - // Keep this initial progress in sync with initialProgressValue (* 100) - // in ProgressTracker.cpp - private final static int INITIAL_PROGRESS = 10; - // activity requestCode final static int PREFERENCES_PAGE = 3; final static int FILE_SELECTED = 4; @@ -750,10 +746,6 @@ public class Controller mUi.onPageStarted(tab, url, favicon); - // Show some progress so that the user knows the page is beginning to - // load - onProgressChanged(tab, INITIAL_PROGRESS); - // update the bookmark database for favicon maybeUpdateFavicon(tab, null, url, favicon); @@ -2247,7 +2239,6 @@ public class Controller * @param url The URL to load. */ protected void loadUrl(WebView view, String url) { - updateTitleBarForNewLoad(view, url); view.loadUrl(url); } @@ -2258,7 +2249,6 @@ public class Controller * @param data The UrlData being loaded. */ protected void loadUrlDataIn(Tab t, UrlData data) { - updateTitleBarForNewLoad(t.getWebView(), data.mUrl); data.loadIn(t); } @@ -2279,25 +2269,6 @@ public class Controller } /** - * If the WebView is the top window, update the title bar to reflect - * loading the new URL. i.e. set its text, clear the favicon (which - * will be set once the page begins loading), and set the progress to - * INITIAL_PROGRESS to show that the page has begun to load. Called - * by loadUrl and loadUrlDataIn. - * @param view The WebView that is starting a load. - * @param url The URL that is being loaded. - */ - private void updateTitleBarForNewLoad(WebView view, String url) { - if (view == getCurrentTopWebView()) { - // TODO we should come with a tab and not with a view - Tab tab = mTabControl.getTabFromView(view); - setUrlTitle(tab, url, null); - mUi.setFavicon(tab, null); - onProgressChanged(tab, INITIAL_PROGRESS); - } - } - - /** * Sets a title composed of the URL and the title string. * @param url The URL of the site being loaded. * @param title The title of the site being loaded. diff --git a/src/com/android/browser/TabBar.java b/src/com/android/browser/TabBar.java index 69e0bd2a1..14b184583 100644 --- a/src/com/android/browser/TabBar.java +++ b/src/com/android/browser/TabBar.java @@ -454,7 +454,6 @@ public class TabBar extends LinearLayout mHasReceivedTitle = false; TabViewData tvd = mTabMap.get(tab); if (tvd != null) { - tvd.setUrlAndTitle(url, null); tvd.setFavicon(favicon); tvd.setUrlAndTitle(url, mLoadingText); } diff --git a/src/com/android/browser/TitleBar.java b/src/com/android/browser/TitleBar.java index 6dabd76f2..bdef82e95 100644 --- a/src/com/android/browser/TitleBar.java +++ b/src/com/android/browser/TitleBar.java @@ -320,13 +320,13 @@ public class TitleBar extends TitleBarBase { /** * Update the text displayed in the title bar. - * @param title String to display. If null, the loading string will be + * @param title String to display. If null, the new tab string will be * shown. */ @Override void setDisplayTitle(String title) { if (title == null) { - mTitle.setText(R.string.title_bar_loading); + mTitle.setText(R.string.new_tab); } else { if (mInVoiceMode) { // Add two spaces. The second one will be replaced with an diff --git a/src/com/android/browser/preferences/PageContentPreferencesFragment.java b/src/com/android/browser/preferences/PageContentPreferencesFragment.java index 1b5d0feee..4be14a69f 100644 --- a/src/com/android/browser/preferences/PageContentPreferencesFragment.java +++ b/src/com/android/browser/preferences/PageContentPreferencesFragment.java @@ -72,29 +72,8 @@ public class PageContentPreferencesFragment extends PreferenceFragment } if (pref.getKey().equals(BrowserSettings.PREF_HOMEPAGE)) { - String value = (String) objValue; - boolean needUpdate = value.indexOf(' ') != -1; - if (needUpdate) { - value = value.trim().replace(" ", "%20"); - } - if (value.length() != 0 && Uri.parse(value).getScheme() == null) { - value = "http://" + value; - needUpdate = true; - } - // Set the summary value. - pref.setSummary(value); - if (needUpdate) { - // Update through the EditText control as it has a cached copy - // of the string and it will handle persisting the value - ((EditTextPreference) pref).setText(value); - - // as we update the value above, we need to return false - // here so that setText() is not called by EditTextPref - // with the old value. - return false; - } else { - return true; - } + pref.setSummary((String) objValue); + return true; } else if (pref.getKey().equals(BrowserSettings.PREF_TEXT_SIZE)) { pref.setSummary(getVisualTextSizeName((String) objValue)); return true; |
