diff options
author | Android (Google) Code Review <android-gerrit@google.com> | 2009-09-11 13:17:20 -0400 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2009-09-11 13:17:20 -0400 |
commit | 819a7f0ae1183c10384df378df266ed31349a83f (patch) | |
tree | 6daa7980bf6a87b22ccc6f3426d6e523663f0761 | |
parent | 652ff87f0905abd11f2fdb6cb4de7840985a0810 (diff) | |
parent | 7ec2ba3c9dd906af98e78a6df14697d435d11eea (diff) | |
download | packages_apps_browser-819a7f0ae1183c10384df378df266ed31349a83f.zip packages_apps_browser-819a7f0ae1183c10384df378df266ed31349a83f.tar.gz packages_apps_browser-819a7f0ae1183c10384df378df266ed31349a83f.tar.bz2 |
Merge change 24651 into eclair
* changes:
Always enable "OK" in the homepage dialog. If it is like "cnn.com", make it "http://cnn.com". If it has space or has colon, but doesn't match the acceptable schema, show an error dialog and don't take the invalid result.
-rw-r--r-- | src/com/android/browser/BrowserHomepagePreference.java | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/com/android/browser/BrowserHomepagePreference.java b/src/com/android/browser/BrowserHomepagePreference.java index 7324f24..be96db3 100644 --- a/src/com/android/browser/BrowserHomepagePreference.java +++ b/src/com/android/browser/BrowserHomepagePreference.java @@ -18,47 +18,46 @@ package com.android.browser; import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.preference.EditTextPreference; -import android.text.Editable; -import android.text.TextWatcher; -import android.text.util.Regex; import android.util.AttributeSet; -public class BrowserHomepagePreference extends EditTextPreference implements - TextWatcher { +public class BrowserHomepagePreference extends EditTextPreference { public BrowserHomepagePreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - getEditText().addTextChangedListener(this); } public BrowserHomepagePreference(Context context, AttributeSet attrs) { super(context, attrs); - getEditText().addTextChangedListener(this); } public BrowserHomepagePreference(Context context) { super(context); - getEditText().addTextChangedListener(this); } - public void afterTextChanged(Editable s) { - AlertDialog dialog = (AlertDialog) getDialog(); - // This callback is called before the dialog has been fully constructed - if (dialog != null) { - String url = s.toString(); - dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled( - url.length() == 0 || - BrowserActivity.ACCEPTED_URI_SCHEMA.matcher(url).matches()); + @Override + protected void onDialogClosed(boolean positiveResult) { + if (positiveResult) { + String url = getEditText().getText().toString(); + if (url.length() > 0 + && !BrowserActivity.ACCEPTED_URI_SCHEMA.matcher(url) + .matches()) { + int colon = url.indexOf(':'); + int space = url.indexOf(' '); + if (colon == -1 && space == -1) { + // 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 + // 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(); + positiveResult = false; + } + } } - } - - public void beforeTextChanged(CharSequence s, int start, int count, - int after) { - } - - public void onTextChanged(CharSequence s, int start, int before, int count) { + super.onDialogClosed(positiveResult); } } |