зеркало из https://github.com/mozilla/gecko-dev.git
Bug 836589 - Lazily switch between AwesomeBar search and URL modes; r=blassey
This commit is contained in:
Родитель
6f40a181a8
Коммит
8537c03508
|
@ -319,7 +319,9 @@ 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 (StringUtils.isSearchQuery(text)) {
|
||||
|
||||
int actionBits = mText.getImeOptions() & EditorInfo.IME_MASK_ACTION;
|
||||
if (StringUtils.isSearchQuery(text, actionBits == EditorInfo.IME_ACTION_SEARCH)) {
|
||||
imageResource = R.drawable.ic_awesomebar_search;
|
||||
contentDescription = getString(R.string.search);
|
||||
imeAction = EditorInfo.IME_ACTION_SEARCH;
|
||||
|
@ -331,12 +333,12 @@ public class AwesomeBar extends GeckoActivity {
|
|||
if (imm == null) {
|
||||
return;
|
||||
}
|
||||
int actionBits = mText.getImeOptions() & EditorInfo.IME_MASK_ACTION;
|
||||
if (actionBits != imeAction) {
|
||||
int optionBits = mText.getImeOptions() & ~EditorInfo.IME_MASK_ACTION;
|
||||
mText.setImeOptions(optionBits | imeAction);
|
||||
|
||||
mDelayRestartInput = InputMethods.shouldDelayAwesomebarUpdate(mText.getContext());
|
||||
mDelayRestartInput = (imeAction == EditorInfo.IME_ACTION_GO) &&
|
||||
(InputMethods.shouldDelayAwesomebarUpdate(mText.getContext()));
|
||||
if (!mDelayRestartInput) {
|
||||
imm.restartInput(mText);
|
||||
}
|
||||
|
@ -453,8 +455,13 @@ public class AwesomeBar extends GeckoActivity {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (mText != null && mText.getText() != null)
|
||||
if (mText != null && mText.getText() != null) {
|
||||
updateGoButton(mText.getText().toString());
|
||||
if (mDelayRestartInput) {
|
||||
// call updateGoButton again to force a restartInput call
|
||||
updateGoButton(mText.getText().toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Invlidate the cached value that keeps track of whether or
|
||||
// not desktop bookmarks exist
|
||||
|
|
|
@ -460,7 +460,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
|
|||
// first suggestion item) and the search matches a URL
|
||||
// pattern, go to that URL. Otherwise, do a search for
|
||||
// the term.
|
||||
if (v != viewHolder.userEnteredView && !StringUtils.isSearchQuery(suggestion)) {
|
||||
if (v != viewHolder.userEnteredView && !StringUtils.isSearchQuery(suggestion, false)) {
|
||||
listener.onUrlOpen(suggestion, null);
|
||||
} else {
|
||||
listener.onSearch(engine.name, suggestion);
|
||||
|
|
|
@ -7,7 +7,9 @@ package org.mozilla.gecko.util;
|
|||
|
||||
public class StringUtils {
|
||||
/*
|
||||
* This method tries to guess if the given string could be a search query or URL
|
||||
* This method tries to guess if the given string could be a search query or URL,
|
||||
* and returns a previous result if there is ambiguity
|
||||
*
|
||||
* Search examples:
|
||||
* foo
|
||||
* foo bar.com
|
||||
|
@ -18,19 +20,28 @@ public class StringUtils {
|
|||
* foo.c
|
||||
* :foo
|
||||
* http://foo.com bar
|
||||
*
|
||||
* wasSearchQuery specifies whether text was a search query before the latest change
|
||||
* in text. In ambiguous cases where the new text can be either a search or a URL,
|
||||
* wasSearchQuery is returned
|
||||
*/
|
||||
public static boolean isSearchQuery(String text) {
|
||||
text = text.trim();
|
||||
public static boolean isSearchQuery(String text, boolean wasSearchQuery) {
|
||||
if (text.length() == 0)
|
||||
return false;
|
||||
return wasSearchQuery;
|
||||
|
||||
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);
|
||||
// If a space is found before any dot and colon, we assume this is a search query
|
||||
if (space > -1 && (colon == -1 || space < colon) && (dot == -1 || space < dot)) {
|
||||
return true;
|
||||
}
|
||||
// Otherwise, if a dot or a colon is found, we assume this is a URL
|
||||
if (dot > -1 || colon > -1) {
|
||||
return false;
|
||||
}
|
||||
// Otherwise, text is ambiguous, and we keep its status unchanged
|
||||
return wasSearchQuery;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче