summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2011-08-11 11:50:51 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-08-11 11:50:51 -0700
commit4cd56b9f51a3fb9477c58d50dcc1b1c239a5005c (patch)
treeded1079674567d9199990e9634e326bc752b5082 /src/com/android
parent8535c4e1293483c8b48f5870067de4fb918522c9 (diff)
parent434e9f83e13c0758dcdefe214357fc9cc9f104d5 (diff)
downloadpackages_apps_Browser-4cd56b9f51a3fb9477c58d50dcc1b1c239a5005c.zip
packages_apps_Browser-4cd56b9f51a3fb9477c58d50dcc1b1c239a5005c.tar.gz
packages_apps_Browser-4cd56b9f51a3fb9477c58d50dcc1b1c239a5005c.tar.bz2
Merge "Strip http://(www.)? from url input"
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/browser/NavigationBarBase.java2
-rw-r--r--src/com/android/browser/NavigationBarPhone.java15
-rw-r--r--src/com/android/browser/UrlUtils.java15
3 files changed, 23 insertions, 9 deletions
diff --git a/src/com/android/browser/NavigationBarBase.java b/src/com/android/browser/NavigationBarBase.java
index 724dcc8..e6eed18 100644
--- a/src/com/android/browser/NavigationBarBase.java
+++ b/src/com/android/browser/NavigationBarBase.java
@@ -167,7 +167,7 @@ public class NavigationBarBase extends LinearLayout implements OnClickListener,
if (mUrlInput.getText().length() == 0) {
Tab currentTab = mUiController.getTabControl().getCurrentTab();
if (currentTab != null) {
- mUrlInput.setText(currentTab.getUrl(), false);
+ setDisplayTitle(currentTab.getUrl());
}
}
mBaseUi.suggestHideTitleBar();
diff --git a/src/com/android/browser/NavigationBarPhone.java b/src/com/android/browser/NavigationBarPhone.java
index 8173377..49228db 100644
--- a/src/com/android/browser/NavigationBarPhone.java
+++ b/src/com/android/browser/NavigationBarPhone.java
@@ -128,11 +128,12 @@ public class NavigationBarPhone extends NavigationBarBase implements
*/
@Override
void setDisplayTitle(String title) {
+ mUrlInput.setTag(title);
if (!isEditingUrl()) {
if (title == null) {
mUrlInput.setText(R.string.new_tab);
} else {
- mUrlInput.setText(title);
+ mUrlInput.setText(UrlUtils.stripUrl(title), false);
}
mUrlInput.setSelection(0);
}
@@ -198,6 +199,18 @@ public class NavigationBarPhone extends NavigationBarBase implements
}
@Override
+ public void onFocusChange(View view, boolean hasFocus) {
+ if (view == mUrlInput) {
+ if (hasFocus) {
+ mUrlInput.setText((String) mUrlInput.getTag(), false);
+ } else {
+ setDisplayTitle(mUrlInput.getText().toString());
+ }
+ }
+ super.onFocusChange(view, hasFocus);
+ }
+
+ @Override
public void onStateChanged(int state) {
switch(state) {
case StateListener.STATE_NORMAL:
diff --git a/src/com/android/browser/UrlUtils.java b/src/com/android/browser/UrlUtils.java
index c922e55..681b242 100644
--- a/src/com/android/browser/UrlUtils.java
+++ b/src/com/android/browser/UrlUtils.java
@@ -40,28 +40,29 @@ public class UrlUtils {
private final static String QUICKSEARCH_G = "http://www.google.com/m?q=%s";
private final static String QUERY_PLACE_HOLDER = "%s";
- // Regular expression which matches http://, followed by some stuff, followed by
- // optionally a trailing slash, all matched as separate groups.
- private static final Pattern STRIP_URL_PATTERN = Pattern.compile("^(http://)(.*?)(/$)?");
+ // Regular expression to strip http://, optionally www., and optionally
+ // the trailing slash
+ private static final Pattern STRIP_URL_PATTERN =
+ Pattern.compile("^http://(?:www\\.)?(.*?)/?$");
private UrlUtils() { /* cannot be instantiated */ }
/**
- * Strips the provided url of preceding "http://" and any trailing "/". Does not
+ * Strips the provided url of preceding "http://", "www.", and any trailing "/". Does not
* strip "https://". If the provided string cannot be stripped, the original string
* is returned.
*
* TODO: Put this in TextUtils to be used by other packages doing something similar.
*
* @param url a url to strip, like "http://www.google.com/"
- * @return a stripped url like "www.google.com", or the original string if it could
+ * @return a stripped url like "google.com", or the original string if it could
* not be stripped
*/
public static String stripUrl(String url) {
if (url == null) return null;
Matcher m = STRIP_URL_PATTERN.matcher(url);
- if (m.matches() && m.groupCount() == 3) {
- return m.group(2);
+ if (m.matches()) {
+ return m.group(1);
} else {
return url;
}