зеркало из 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;
|
int imageResource = R.drawable.ic_awesomebar_go;
|
||||||
String contentDescription = getString(R.string.go);
|
String contentDescription = getString(R.string.go);
|
||||||
int imeAction = EditorInfo.IME_ACTION_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;
|
imageResource = R.drawable.ic_awesomebar_search;
|
||||||
contentDescription = getString(R.string.search);
|
contentDescription = getString(R.string.search);
|
||||||
imeAction = EditorInfo.IME_ACTION_SEARCH;
|
imeAction = EditorInfo.IME_ACTION_SEARCH;
|
||||||
|
@ -331,12 +333,12 @@ public class AwesomeBar extends GeckoActivity {
|
||||||
if (imm == null) {
|
if (imm == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int actionBits = mText.getImeOptions() & EditorInfo.IME_MASK_ACTION;
|
|
||||||
if (actionBits != imeAction) {
|
if (actionBits != imeAction) {
|
||||||
int optionBits = mText.getImeOptions() & ~EditorInfo.IME_MASK_ACTION;
|
int optionBits = mText.getImeOptions() & ~EditorInfo.IME_MASK_ACTION;
|
||||||
mText.setImeOptions(optionBits | imeAction);
|
mText.setImeOptions(optionBits | imeAction);
|
||||||
|
|
||||||
mDelayRestartInput = InputMethods.shouldDelayAwesomebarUpdate(mText.getContext());
|
mDelayRestartInput = (imeAction == EditorInfo.IME_ACTION_GO) &&
|
||||||
|
(InputMethods.shouldDelayAwesomebarUpdate(mText.getContext()));
|
||||||
if (!mDelayRestartInput) {
|
if (!mDelayRestartInput) {
|
||||||
imm.restartInput(mText);
|
imm.restartInput(mText);
|
||||||
}
|
}
|
||||||
|
@ -453,8 +455,13 @@ public class AwesomeBar extends GeckoActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (mText != null && mText.getText() != null)
|
if (mText != null && mText.getText() != null) {
|
||||||
updateGoButton(mText.getText().toString());
|
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
|
// Invlidate the cached value that keeps track of whether or
|
||||||
// not desktop bookmarks exist
|
// not desktop bookmarks exist
|
||||||
|
|
|
@ -460,7 +460,7 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
|
||||||
// first suggestion item) and the search matches a URL
|
// first suggestion item) and the search matches a URL
|
||||||
// pattern, go to that URL. Otherwise, do a search for
|
// pattern, go to that URL. Otherwise, do a search for
|
||||||
// the term.
|
// the term.
|
||||||
if (v != viewHolder.userEnteredView && !StringUtils.isSearchQuery(suggestion)) {
|
if (v != viewHolder.userEnteredView && !StringUtils.isSearchQuery(suggestion, false)) {
|
||||||
listener.onUrlOpen(suggestion, null);
|
listener.onUrlOpen(suggestion, null);
|
||||||
} else {
|
} else {
|
||||||
listener.onSearch(engine.name, suggestion);
|
listener.onSearch(engine.name, suggestion);
|
||||||
|
|
|
@ -7,7 +7,9 @@ package org.mozilla.gecko.util;
|
||||||
|
|
||||||
public class StringUtils {
|
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:
|
* Search examples:
|
||||||
* foo
|
* foo
|
||||||
* foo bar.com
|
* foo bar.com
|
||||||
|
@ -18,19 +20,28 @@ public class StringUtils {
|
||||||
* foo.c
|
* foo.c
|
||||||
* :foo
|
* :foo
|
||||||
* http://foo.com bar
|
* 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) {
|
public static boolean isSearchQuery(String text, boolean wasSearchQuery) {
|
||||||
text = text.trim();
|
|
||||||
if (text.length() == 0)
|
if (text.length() == 0)
|
||||||
return false;
|
return wasSearchQuery;
|
||||||
|
|
||||||
int colon = text.indexOf(':');
|
int colon = text.indexOf(':');
|
||||||
int dot = text.indexOf('.');
|
int dot = text.indexOf('.');
|
||||||
int space = text.indexOf(' ');
|
int space = text.indexOf(' ');
|
||||||
|
|
||||||
// If a space is found before any dot or colon, we assume this is a search query
|
// If a space is found before any dot and colon, we assume this is a search query
|
||||||
boolean spacedOut = space > -1 && (space < colon || space < dot);
|
if (space > -1 && (colon == -1 || space < colon) && (dot == -1 || space < dot)) {
|
||||||
|
return true;
|
||||||
return spacedOut || (dot == -1 && colon == -1);
|
}
|
||||||
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче