mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 820576 - Part 1: Move isSearchUrl to StringUtils. r=mfinkle
This commit is contained in:
parent
bd1e47165c
commit
d0d1268c07
@ -8,6 +8,7 @@ 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;
|
||||
@ -305,34 +306,6 @@ public class AwesomeBar extends GeckoActivity {
|
||||
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);
|
||||
@ -344,7 +317,7 @@ public class AwesomeBar extends GeckoActivity {
|
||||
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;
|
||||
|
@ -32,6 +32,7 @@ UTIL_JAVA_FILES := \
|
||||
INISection.java \
|
||||
util/EventDispatcher.java \
|
||||
util/FloatUtils.java \
|
||||
util/StringUtils.java \
|
||||
$(NULL)
|
||||
|
||||
FENNEC_JAVA_FILES = \
|
||||
|
36
mobile/android/base/util/StringUtils.java
Normal file
36
mobile/android/base/util/StringUtils.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user