summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2010-10-26 17:13:42 -0700
committerJohn Reck <jreck@google.com>2010-10-27 18:13:16 -0700
commit33bbb80f17a66ba957c0ff0173ecd48ef4392080 (patch)
treeea307c02179be4dba5fe03fb949a237887e5aadf
parent286855136d5c145feb2707937d5dc7e1d92204df (diff)
downloadpackages_apps_Browser-33bbb80f17a66ba957c0ff0173ecd48ef4392080.zip
packages_apps_Browser-33bbb80f17a66ba957c0ff0173ecd48ef4392080.tar.gz
packages_apps_Browser-33bbb80f17a66ba957c0ff0173ecd48ef4392080.tar.bz2
Fixes the bug around misbehavior with empty homepage setting
Bug: 2911567 Setting the homepage to "" resulted in odd behavior. This changes it so that entering "" fails with an invalid URL error (now a toast instead of a dialog). The "Use Current" button was replaced with a "Set to..." button that allows the user to specify whether they want to set the homepage to the current page, a blank page, or the default page. Change-Id: I2d0cac158f89ace6ecab6165a3768419ba3252d4
-rw-r--r--res/values/strings.xml10
-rw-r--r--src/com/android/browser/BrowserHomepagePreference.java48
-rw-r--r--src/com/android/browser/BrowserSettings.java2
3 files changed, 47 insertions, 13 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3a3cab8..e5adc93 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -319,8 +319,14 @@
<string name="pref_content_search_engine">Set search engine</string>
<!-- Settings summary -->
<string name="pref_content_search_engine_summary">Select a search engine</string>
- <!-- Settings button label -->
- <string name="pref_use_current">Use current page</string>
+ <!-- Settings button label that to pick what to set the homepage to [CHAR LIMIT=40] -->
+ <string name="pref_set_homepage_to">Set to\u2026</string>
+ <!-- Settings button label to set the homepage to the current page [CHAR LIMIT=40] -->
+ <string name="pref_use_current">Current page</string>
+ <!-- Settings button label to set the homepage to a blank page [CHAR LIMIT=40] -->
+ <string name="pref_use_blank">Blank page</string>
+ <!-- Settings button label to set the homepage to the default page [CHAR LIMIT=40] -->
+ <string name="pref_use_default">Default page</string>
<!-- Settings label -->
<string name="pref_content_autofit">Auto-fit pages</string>
<!-- Settings summary -->
diff --git a/src/com/android/browser/BrowserHomepagePreference.java b/src/com/android/browser/BrowserHomepagePreference.java
index 057e691..fefe101 100644
--- a/src/com/android/browser/BrowserHomepagePreference.java
+++ b/src/com/android/browser/BrowserHomepagePreference.java
@@ -18,11 +18,13 @@ package com.android.browser;
import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
+import android.widget.Toast;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@@ -32,18 +34,22 @@ import android.util.AttributeSet;
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
@@ -54,10 +60,10 @@ public class BrowserHomepagePreference extends EditTextPreference {
// page.
ViewGroup parent = (ViewGroup) editText.getParent();
Button button = new Button(getContext());
- button.setText(R.string.pref_use_current);
+ button.setText(R.string.pref_set_homepage_to);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- getEditText().setText(mCurrentPage);
+ mSetHomepageTo.show();
}
});
if (parent instanceof LinearLayout) {
@@ -67,24 +73,46 @@ public class BrowserHomepagePreference extends EditTextPreference {
ViewGroup.LayoutParams.WRAP_CONTENT);
}
+ 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();
+ }
+
@Override
protected void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
String url = getEditText().getText().toString();
- if (url.length() > 0
- && !BrowserActivity.ACCEPTED_URI_SCHEMA.matcher(url)
- .matches()) {
+ if (!BrowserActivity.ACCEPTED_URI_SCHEMA.matcher(url).matches()) {
int colon = url.indexOf(':');
int space = url.indexOf(' ');
- if (colon == -1 && space == -1) {
+ 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 dialog and change the positiveResult to
+ // show an error toast and change the positiveResult to
// false so that the bad url will not override the old url
- new AlertDialog.Builder(this.getContext()).setMessage(
- R.string.bookmark_url_not_valid).setPositiveButton(
- R.string.ok, null).show();
+ Toast.makeText(getContext(), R.string.bookmark_url_not_valid,
+ Toast.LENGTH_SHORT).show();
positiveResult = false;
}
}
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 3b8aaa4..20b6003 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -678,7 +678,7 @@ public class BrowserSettings extends Observable {
appCacheMaxSize = webStorageSizeManager.getAppCacheMaxSize();
}
- private String getFactoryResetHomeUrl(Context context) {
+ /*package*/ static String getFactoryResetHomeUrl(Context context) {
String url = context.getResources().getString(R.string.homepage_base);
if (url.indexOf("{CID}") != -1) {
url = url.replace("{CID}",