Bug 820576 - Part 1: Move isSearchUrl to StringUtils. r=mfinkle
authorBrian Nicholson <bnicholson@mozilla.com>
Wed, 12 Dec 2012 13:21:37 -0800
changeset 115837 e14b7800ae0159f10d21ccad0d388a073c66dd8d
parent 115836 c940923e0efccaf2ab44a7228401698f92271308
child 115838 1ce57f5cca0bad1f0bd036338a3638e38cbb7e15
push id19572
push userbnicholson@mozilla.com
push dateWed, 12 Dec 2012 21:21:55 +0000
treeherdermozilla-inbound@1ce57f5cca0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs820576
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 820576 - Part 1: Move isSearchUrl to StringUtils. r=mfinkle
mobile/android/base/AwesomeBar.java
mobile/android/base/Makefile.in
mobile/android/base/util/StringUtils.java
--- a/mobile/android/base/AwesomeBar.java
+++ b/mobile/android/base/AwesomeBar.java
@@ -3,16 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.util.GeckoAsyncTask;
+import org.mozilla.gecko.util.StringUtils;
 
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.res.Configuration;
@@ -300,56 +301,28 @@ public class AwesomeBar extends GeckoAct
     }
 
     @Override
     public boolean onSearchRequested() {
         cancelAndFinish();
         return true;
     }
 
-    /*
-     * This method tries to guess if the given string could be a search query or URL
-     * Search examples:
-     *  foo
-     *  foo bar.com
-     *  foo http://bar.com
-     *
-     * URL examples
-     *  foo.com
-     *  foo.c
-     *  :foo
-     *  http://foo.com bar
-    */
-    private boolean isSearchUrl(String text) {
-        text = text.trim();
-        if (text.length() == 0)
-            return false;
-
-        int colon = text.indexOf(':');
-        int dot = text.indexOf('.');
-        int space = text.indexOf(' ');
-
-        // If a space is found before any dot or colon, we assume this is a search query
-        boolean spacedOut = space > -1 && (space < colon || space < dot);
-
-        return spacedOut || (dot == -1 && colon == -1);
-    }
-
     private void updateGoButton(String text) {
         if (text.length() == 0) {
             mGoButton.setVisibility(View.GONE);
             return;
         }
 
         mGoButton.setVisibility(View.VISIBLE);
 
         int imageResource = R.drawable.ic_awesomebar_go;
         String contentDescription = getString(R.string.go);
         int imeAction = EditorInfo.IME_ACTION_GO;
-        if (isSearchUrl(text)) {
+        if (StringUtils.isSearchQuery(text)) {
             imageResource = R.drawable.ic_awesomebar_search;
             contentDescription = getString(R.string.search);
             imeAction = EditorInfo.IME_ACTION_SEARCH;
         }
         mGoButton.setImageResource(imageResource);
         mGoButton.setContentDescription(contentDescription);
 
         int actionBits = mText.getImeOptions() & EditorInfo.IME_MASK_ACTION;
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -27,16 +27,17 @@ UTIL_JAVA_FILES := \
   GeckoBackgroundThread.java \
   GeckoEventListener.java \
   GeckoEventResponder.java \
   GeckoJarReader.java \
   INIParser.java \
   INISection.java \
   util/EventDispatcher.java \
   util/FloatUtils.java \
+  util/StringUtils.java \
   $(NULL)
 
 FENNEC_JAVA_FILES = \
   AboutHomeContent.java \
   AboutHomePromoBox.java \
   AboutHomeSection.java \
   ActivityHandlerHelper.java \
   AndroidImport.java \
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/util/StringUtils.java
@@ -0,0 +1,36 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.util;
+
+public class StringUtils {
+    /*
+     * This method tries to guess if the given string could be a search query or URL
+     * Search examples:
+     *  foo
+     *  foo bar.com
+     *  foo http://bar.com
+     *
+     * URL examples
+     *  foo.com
+     *  foo.c
+     *  :foo
+     *  http://foo.com bar
+    */
+    public static boolean isSearchQuery(String text) {
+        text = text.trim();
+        if (text.length() == 0)
+            return false;
+
+        int colon = text.indexOf(':');
+        int dot = text.indexOf('.');
+        int space = text.indexOf(' ');
+
+        // If a space is found before any dot or colon, we assume this is a search query
+        boolean spacedOut = space > -1 && (space < colon || space < dot);
+
+        return spacedOut || (dot == -1 && colon == -1);
+    }
+}