2011-11-18 10:28:17 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-09-10 10:24:38 -07:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Combined;
|
2013-04-08 00:51:56 -07:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2013-04-22 18:03:01 -07:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2013-03-27 06:36:45 -07:00
|
|
|
import org.mozilla.gecko.util.GamepadUtils;
|
2012-12-12 13:21:37 -08:00
|
|
|
import org.mozilla.gecko.util.StringUtils;
|
2013-03-15 03:52:53 -07:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
|
|
|
import org.mozilla.gecko.util.UiAsyncTask;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.app.Activity;
|
2012-03-12 13:01:09 -07:00
|
|
|
import android.app.AlertDialog;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.content.Context;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.content.res.Configuration;
|
2011-12-20 07:28:12 -08:00
|
|
|
import android.graphics.Bitmap;
|
2012-09-10 10:24:26 -07:00
|
|
|
import android.net.Uri;
|
2012-07-26 23:56:53 -07:00
|
|
|
import android.os.Build;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.Editable;
|
2012-07-22 00:17:45 -07:00
|
|
|
import android.text.InputType;
|
2012-03-11 19:30:35 -07:00
|
|
|
import android.text.Spanned;
|
2012-04-20 11:49:30 -07:00
|
|
|
import android.text.TextUtils;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.text.TextWatcher;
|
2013-04-16 14:34:46 -07:00
|
|
|
import android.util.AttributeSet;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.util.Log;
|
2011-12-20 07:28:12 -08:00
|
|
|
import android.view.ContextMenu;
|
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.view.KeyEvent;
|
2012-03-23 12:00:17 -07:00
|
|
|
import android.view.LayoutInflater;
|
2011-12-20 07:28:12 -08:00
|
|
|
import android.view.MenuItem;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.view.View;
|
2011-12-14 23:34:54 -08:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2011-11-24 08:54:39 -08:00
|
|
|
import android.widget.Button;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.EditText;
|
2011-11-24 08:54:39 -08:00
|
|
|
import android.widget.ImageButton;
|
2012-01-27 11:58:18 -08:00
|
|
|
import android.widget.TabWidget;
|
2012-01-15 13:51:23 -08:00
|
|
|
import android.widget.Toast;
|
2011-12-20 07:28:12 -08:00
|
|
|
|
2012-07-22 00:17:45 -07:00
|
|
|
import java.net.URLEncoder;
|
2012-07-17 22:39:46 -07:00
|
|
|
|
2013-04-17 09:13:49 -07:00
|
|
|
interface AutocompleteHandler {
|
|
|
|
void onAutocomplete(String res);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class AwesomeBar extends GeckoActivity
|
|
|
|
implements AutocompleteHandler,
|
|
|
|
TextWatcher {
|
2011-11-18 10:28:17 -08:00
|
|
|
private static final String LOGTAG = "GeckoAwesomeBar";
|
|
|
|
|
2013-03-25 15:44:45 -07:00
|
|
|
public static final String URL_KEY = "url";
|
|
|
|
public static final String CURRENT_URL_KEY = "currenturl";
|
|
|
|
public static final String TARGET_KEY = "target";
|
|
|
|
public static final String SEARCH_KEY = "search";
|
|
|
|
public static final String TITLE_KEY = "title";
|
|
|
|
public static final String USER_ENTERED_KEY = "user_entered";
|
|
|
|
public static final String READING_LIST_KEY = "reading_list";
|
2012-12-28 13:46:08 -08:00
|
|
|
public static enum Target { NEW_TAB, CURRENT_TAB, PICK_SITE };
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-06-07 10:13:38 -07:00
|
|
|
private String mTarget;
|
2011-11-18 10:28:17 -08:00
|
|
|
private AwesomeBarTabs mAwesomeTabs;
|
2012-07-11 16:04:49 -07:00
|
|
|
private CustomEditText mText;
|
2011-11-24 08:54:39 -08:00
|
|
|
private ImageButton mGoButton;
|
2012-03-05 13:31:55 -08:00
|
|
|
private ContextMenuSubject mContextMenuSubject;
|
2013-01-30 07:46:58 -08:00
|
|
|
private boolean mDelayRestartInput;
|
2013-04-17 09:13:49 -07:00
|
|
|
// The previous autocomplete result returned to us
|
|
|
|
private String mAutoCompleteResult = "";
|
|
|
|
// The user typed part of the autocomplete result
|
|
|
|
private String mAutoCompletePrefix = null;
|
2012-06-05 14:07:14 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2013-04-16 14:34:46 -07:00
|
|
|
LayoutInflater.from(this).setFactory(this);
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
Log.d(LOGTAG, "creating awesomebar");
|
|
|
|
|
2011-12-21 00:51:56 -08:00
|
|
|
setContentView(R.layout.awesomebar);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-12 12:15:57 -07:00
|
|
|
mGoButton = (ImageButton) findViewById(R.id.awesomebar_button);
|
2012-07-11 16:04:49 -07:00
|
|
|
mText = (CustomEditText) findViewById(R.id.awesomebar_text);
|
2011-12-15 11:53:04 -08:00
|
|
|
|
2012-01-27 11:58:18 -08:00
|
|
|
TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
|
|
|
|
tabWidget.setDividerDrawable(null);
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
mAwesomeTabs = (AwesomeBarTabs) findViewById(R.id.awesomebar_tabs);
|
|
|
|
mAwesomeTabs.setOnUrlOpenListener(new AwesomeBarTabs.OnUrlOpenListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-28 13:46:08 -08:00
|
|
|
public void onUrlOpen(String url, String title) {
|
|
|
|
openUrlAndFinish(url, title, false);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2011-12-07 17:52:07 -08:00
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-05 14:07:14 -07:00
|
|
|
public void onSearch(String engine, String text) {
|
|
|
|
openSearchAndFinish(text, engine);
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-05 14:07:14 -07:00
|
|
|
public void onEditSuggestion(final String text) {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-05 14:07:14 -07:00
|
|
|
public void run() {
|
|
|
|
mText.setText(text);
|
|
|
|
mText.setSelection(mText.getText().length());
|
|
|
|
mText.requestFocus();
|
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.showSoftInput(mText, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
}
|
|
|
|
});
|
2011-12-07 17:52:07 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
});
|
|
|
|
|
2011-11-24 08:54:39 -08:00
|
|
|
mGoButton.setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-24 08:54:39 -08:00
|
|
|
public void onClick(View v) {
|
2012-02-22 18:26:04 -08:00
|
|
|
openUserEnteredAndFinish(mText.getText().toString());
|
2011-11-24 08:54:39 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
Intent intent = getIntent();
|
|
|
|
String currentUrl = intent.getStringExtra(CURRENT_URL_KEY);
|
|
|
|
if (currentUrl != null) {
|
|
|
|
mText.setText(currentUrl);
|
|
|
|
mText.selectAll();
|
|
|
|
}
|
|
|
|
|
2012-11-16 00:41:53 -08:00
|
|
|
mTarget = intent.getStringExtra(TARGET_KEY);
|
|
|
|
if (mTarget.equals(Target.CURRENT_TAB.name())) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null && tab.isPrivate()) {
|
|
|
|
BrowserToolbarBackground mAddressBarBg = (BrowserToolbarBackground) findViewById(R.id.address_bar_bg);
|
|
|
|
mAddressBarBg.setPrivateMode(true);
|
|
|
|
|
2013-03-14 15:26:25 -07:00
|
|
|
ShapedButton mTabs = (ShapedButton) findViewById(R.id.dummy_tab);
|
2012-11-16 00:41:53 -08:00
|
|
|
if (mTabs != null)
|
|
|
|
mTabs.setPrivateMode(true);
|
|
|
|
|
|
|
|
mText.setPrivateMode(true);
|
|
|
|
}
|
|
|
|
}
|
2012-11-16 00:50:28 -08:00
|
|
|
mAwesomeTabs.setTarget(mTarget);
|
2012-11-16 00:41:53 -08:00
|
|
|
|
2012-07-11 16:04:49 -07:00
|
|
|
mText.setOnKeyPreImeListener(new CustomEditText.OnKeyPreImeListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public boolean onKeyPreIme(View v, int keyCode, KeyEvent event) {
|
2012-02-23 10:48:48 -08:00
|
|
|
// We only want to process one event per tap
|
|
|
|
if (event.getAction() != KeyEvent.ACTION_DOWN)
|
|
|
|
return false;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-02-23 10:48:48 -08:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
2012-03-22 17:37:32 -07:00
|
|
|
// If the AwesomeBar has a composition string, don't submit the text yet.
|
|
|
|
// ENTER is needed to commit the composition string.
|
|
|
|
Editable content = mText.getText();
|
|
|
|
if (!hasCompositionString(content)) {
|
|
|
|
openUserEnteredAndFinish(content.toString());
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-20 19:44:17 -08:00
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// If input method is in fullscreen mode, we want to dismiss
|
|
|
|
// it instead of closing awesomebar straight away.
|
2012-02-23 10:48:48 -08:00
|
|
|
InputMethodManager imm =
|
|
|
|
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK && !imm.isFullscreenMode()) {
|
2013-03-27 06:36:45 -07:00
|
|
|
return handleBackKey();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-17 09:13:49 -07:00
|
|
|
mText.addTextChangedListener(this);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
mText.setOnKeyListener(new View.OnKeyListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
2013-03-27 06:36:45 -07:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER || GamepadUtils.isActionKey(event)) {
|
2011-11-18 10:28:17 -08:00
|
|
|
if (event.getAction() != KeyEvent.ACTION_DOWN)
|
|
|
|
return true;
|
|
|
|
|
2012-02-22 18:26:04 -08:00
|
|
|
openUserEnteredAndFinish(mText.getText().toString());
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
2013-03-27 06:36:45 -07:00
|
|
|
} else if (GamepadUtils.isBackKey(event)) {
|
|
|
|
return handleBackKey();
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-06-28 11:21:24 -07:00
|
|
|
mText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-28 11:21:24 -07:00
|
|
|
public void onFocusChange(View v, boolean hasFocus) {
|
2012-08-29 17:19:32 -07:00
|
|
|
if (v == null || hasFocus) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
try {
|
2012-06-28 11:21:24 -07:00
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
2012-08-29 17:19:32 -07:00
|
|
|
} catch (NullPointerException e) {
|
|
|
|
Log.e(LOGTAG, "InputMethodManagerService, why are you throwing"
|
|
|
|
+ " a NullPointerException? See bug 782096", e);
|
2012-06-28 11:21:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-07-26 23:56:53 -07:00
|
|
|
|
|
|
|
mText.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
CustomEditText text = (CustomEditText) v;
|
|
|
|
|
|
|
|
if (text.getSelectionStart() == text.getSelectionEnd())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
getActionBar().show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mText.setOnSelectionChangedListener(new CustomEditText.OnSelectionChangedListener() {
|
|
|
|
@Override
|
|
|
|
public void onSelectionChanged(int selStart, int selEnd) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11 && selStart == selEnd) {
|
2012-07-30 14:21:29 -07:00
|
|
|
getActionBar().hide();
|
2012-07-26 23:56:53 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-08-07 07:23:20 -07:00
|
|
|
|
|
|
|
boolean showReadingList = intent.getBooleanExtra(READING_LIST_KEY, false);
|
|
|
|
if (showReadingList) {
|
|
|
|
BookmarksTab bookmarksTab = mAwesomeTabs.getBookmarksTab();
|
|
|
|
bookmarksTab.setShowReadingList(true);
|
2013-03-11 15:27:24 -07:00
|
|
|
mAwesomeTabs.setCurrentItemByTag(bookmarksTab.getTag());
|
2012-08-07 07:23:20 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-04-16 14:34:46 -07:00
|
|
|
/*
|
|
|
|
* Only one factory can be set on the inflater; however, we want to use two
|
|
|
|
* factories (GeckoViewsFactory and the FragmentActivity factory).
|
|
|
|
* Overriding onCreateView() here allows us to dispatch view creation to
|
|
|
|
* both factories.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public View onCreateView(String name, Context context, AttributeSet attrs) {
|
|
|
|
View view = GeckoViewsFactory.getInstance().onCreateView(name, context, attrs);
|
|
|
|
if (view == null) {
|
|
|
|
view = super.onCreateView(name, context, attrs);
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2013-03-27 06:36:45 -07:00
|
|
|
private boolean handleBackKey() {
|
|
|
|
// Let mAwesomeTabs try to handle the back press, since we may be in a
|
|
|
|
// bookmarks sub-folder.
|
|
|
|
if (mAwesomeTabs.onBackPressed())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If mAwesomeTabs.onBackPressed() returned false, we didn't move up
|
|
|
|
// a folder level, so just exit the activity.
|
|
|
|
cancelAndFinish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(Configuration newConfiguration) {
|
|
|
|
super.onConfigurationChanged(newConfiguration);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSearchRequested() {
|
|
|
|
cancelAndFinish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-24 08:54:39 -08:00
|
|
|
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;
|
2012-08-09 09:26:43 -07:00
|
|
|
String contentDescription = getString(R.string.go);
|
2011-12-14 23:34:54 -08:00
|
|
|
int imeAction = EditorInfo.IME_ACTION_GO;
|
2013-02-07 15:17:06 -08:00
|
|
|
|
|
|
|
int actionBits = mText.getImeOptions() & EditorInfo.IME_MASK_ACTION;
|
|
|
|
if (StringUtils.isSearchQuery(text, actionBits == EditorInfo.IME_ACTION_SEARCH)) {
|
2011-11-24 08:54:39 -08:00
|
|
|
imageResource = R.drawable.ic_awesomebar_search;
|
2012-08-09 09:26:43 -07:00
|
|
|
contentDescription = getString(R.string.search);
|
2011-12-14 23:34:54 -08:00
|
|
|
imeAction = EditorInfo.IME_ACTION_SEARCH;
|
|
|
|
}
|
|
|
|
|
2013-01-30 07:46:58 -08:00
|
|
|
InputMethodManager imm = InputMethods.getInputMethodManager(mText.getContext());
|
|
|
|
if (imm == null) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-11 07:54:13 -07:00
|
|
|
boolean restartInput = false;
|
2012-03-02 17:00:22 -08:00
|
|
|
if (actionBits != imeAction) {
|
|
|
|
int optionBits = mText.getImeOptions() & ~EditorInfo.IME_MASK_ACTION;
|
|
|
|
mText.setImeOptions(optionBits | imeAction);
|
2013-01-30 07:46:58 -08:00
|
|
|
|
2013-02-07 15:17:06 -08:00
|
|
|
mDelayRestartInput = (imeAction == EditorInfo.IME_ACTION_GO) &&
|
|
|
|
(InputMethods.shouldDelayAwesomebarUpdate(mText.getContext()));
|
2013-01-30 07:46:58 -08:00
|
|
|
if (!mDelayRestartInput) {
|
2013-04-11 07:54:13 -07:00
|
|
|
restartInput = true;
|
2013-01-30 07:46:58 -08:00
|
|
|
}
|
|
|
|
} else if (mDelayRestartInput) {
|
|
|
|
// Only call delayed restartInput when actionBits == imeAction
|
|
|
|
// so if there are two restarts in a row, the first restarts will
|
|
|
|
// be discarded and the second restart will be properly delayed
|
|
|
|
mDelayRestartInput = false;
|
2013-04-11 07:54:13 -07:00
|
|
|
restartInput = true;
|
|
|
|
}
|
|
|
|
if (restartInput) {
|
2013-04-06 00:24:11 -07:00
|
|
|
updateKeyboardInputType();
|
2011-12-14 23:34:54 -08:00
|
|
|
imm.restartInput(mText);
|
2013-04-11 07:54:13 -07:00
|
|
|
mGoButton.setImageResource(imageResource);
|
|
|
|
mGoButton.setContentDescription(contentDescription);
|
2011-12-14 23:34:54 -08:00
|
|
|
}
|
2011-11-24 08:54:39 -08:00
|
|
|
}
|
|
|
|
|
2013-04-06 00:24:11 -07:00
|
|
|
private void updateKeyboardInputType() {
|
2013-04-24 12:38:44 -07:00
|
|
|
// If the user enters a space, then we know they are entering search terms, not a URL.
|
|
|
|
// We can then switch to text mode so,
|
|
|
|
// 1) the IME auto-inserts spaces between words
|
|
|
|
// 2) the IME doesn't reset input keyboard to Latin keyboard.
|
2013-04-06 00:24:11 -07:00
|
|
|
String text = mText.getText().toString();
|
|
|
|
int currentInputType = mText.getInputType();
|
2013-04-24 12:38:44 -07:00
|
|
|
int newInputType = StringUtils.isSearchQuery(text, false)
|
2013-04-06 00:24:11 -07:00
|
|
|
? (currentInputType & ~InputType.TYPE_TEXT_VARIATION_URI) // Text mode
|
|
|
|
: (currentInputType | InputType.TYPE_TEXT_VARIATION_URI); // URL mode
|
|
|
|
if (newInputType != currentInputType) {
|
|
|
|
mText.setRawInputType(newInputType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private void cancelAndFinish() {
|
|
|
|
setResult(Activity.RESULT_CANCELED);
|
|
|
|
finish();
|
2012-12-05 08:46:17 -08:00
|
|
|
overridePendingTransition(R.anim.awesomebar_hold_still, R.anim.awesomebar_fade_out);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-07 17:52:07 -08:00
|
|
|
private void finishWithResult(Intent intent) {
|
|
|
|
setResult(Activity.RESULT_OK, intent);
|
|
|
|
finish();
|
2012-12-05 08:46:17 -08:00
|
|
|
overridePendingTransition(R.anim.awesomebar_hold_still, R.anim.awesomebar_fade_out);
|
2011-12-07 17:52:07 -08:00
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private void openUrlAndFinish(String url) {
|
2012-12-28 13:46:08 -08:00
|
|
|
openUrlAndFinish(url, null, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openUrlAndFinish(String url, String title, boolean userEntered) {
|
2012-02-22 18:26:04 -08:00
|
|
|
Intent resultIntent = new Intent();
|
|
|
|
resultIntent.putExtra(URL_KEY, url);
|
2012-12-28 13:46:08 -08:00
|
|
|
if (title != null && !TextUtils.isEmpty(title))
|
|
|
|
resultIntent.putExtra(TITLE_KEY, title);
|
|
|
|
if (userEntered)
|
|
|
|
resultIntent.putExtra(USER_ENTERED_KEY, userEntered);
|
2012-06-07 10:13:38 -07:00
|
|
|
resultIntent.putExtra(TARGET_KEY, mTarget);
|
2012-02-22 18:26:04 -08:00
|
|
|
finishWithResult(resultIntent);
|
|
|
|
}
|
|
|
|
|
2013-04-08 13:56:18 -07:00
|
|
|
private void openUserEnteredAndFinish(final String url) {
|
|
|
|
final int index = url.indexOf(' ');
|
2012-11-13 11:37:33 -08:00
|
|
|
|
2013-04-08 13:56:15 -07:00
|
|
|
// Check for a keyword if the URL looks like a search query
|
|
|
|
if (StringUtils.isSearchQuery(url, true)) {
|
2013-04-08 13:56:18 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
String keywordUrl = null;
|
|
|
|
String keywordSearch = "";
|
|
|
|
if (index == -1) {
|
|
|
|
keywordUrl = BrowserDB.getUrlForKeyword(getContentResolver(), url);
|
|
|
|
} else {
|
|
|
|
keywordUrl = BrowserDB.getUrlForKeyword(getContentResolver(), url.substring(0, index));
|
|
|
|
keywordSearch = url.substring(index + 1);
|
|
|
|
}
|
|
|
|
if (keywordUrl == null) {
|
|
|
|
openUrlAndFinish(url, "", true);
|
|
|
|
} else {
|
|
|
|
String search = URLEncoder.encode(keywordSearch);
|
|
|
|
openUrlAndFinish(keywordUrl.replace("%s", search), "", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
openUrlAndFinish(url, "", true);
|
2012-02-07 18:15:20 -08:00
|
|
|
}
|
2011-12-07 17:52:07 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-12-07 17:52:07 -08:00
|
|
|
private void openSearchAndFinish(String url, String engine) {
|
|
|
|
Intent resultIntent = new Intent();
|
|
|
|
resultIntent.putExtra(URL_KEY, url);
|
2012-06-07 10:13:38 -07:00
|
|
|
resultIntent.putExtra(TARGET_KEY, mTarget);
|
2011-12-07 17:52:07 -08:00
|
|
|
resultIntent.putExtra(SEARCH_KEY, engine);
|
|
|
|
finishWithResult(resultIntent);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2012-06-28 11:15:17 -07:00
|
|
|
// Galaxy Note sends key events for the stylus that are outside of the
|
|
|
|
// valid keyCode range (see bug 758427)
|
|
|
|
if (keyCode > KeyEvent.getMaxKeyCode())
|
|
|
|
return true;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// This method is called only if the key event was not handled
|
|
|
|
// by any of the views, which usually means the edit box lost focus
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_MENU ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DPAD_UP ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DPAD_DOWN ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
|
2011-11-24 18:19:52 -08:00
|
|
|
keyCode == KeyEvent.KEYCODE_DPAD_CENTER ||
|
2011-12-16 13:19:48 -08:00
|
|
|
keyCode == KeyEvent.KEYCODE_DEL ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
2011-11-18 10:28:17 -08:00
|
|
|
return super.onKeyDown(keyCode, event);
|
2012-07-05 11:11:45 -07:00
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
2012-07-03 17:26:36 -07:00
|
|
|
mText.setText("");
|
|
|
|
mText.requestFocus();
|
|
|
|
InputMethodManager imm = (InputMethodManager) mText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.showSoftInput(mText, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
return true;
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
2012-12-14 10:21:58 -08:00
|
|
|
int prevSelStart = mText.getSelectionStart();
|
|
|
|
int prevSelEnd = mText.getSelectionEnd();
|
2011-11-23 23:11:06 -08:00
|
|
|
|
2012-12-14 10:21:58 -08:00
|
|
|
// Manually dispatch the key event to the AwesomeBar. If selection changed as
|
|
|
|
// a result of the key event, then give focus back to mText
|
2011-11-18 10:28:17 -08:00
|
|
|
mText.dispatchKeyEvent(event);
|
2012-05-01 14:56:08 -07:00
|
|
|
|
2012-12-14 10:21:58 -08:00
|
|
|
int curSelStart = mText.getSelectionStart();
|
|
|
|
int curSelEnd = mText.getSelectionEnd();
|
|
|
|
if (prevSelStart != curSelStart || prevSelEnd != curSelEnd) {
|
|
|
|
mText.requestFocusFromTouch();
|
|
|
|
// Restore the selection, which gets lost due to the focus switch
|
|
|
|
mText.setSelection(curSelStart, curSelEnd);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-23 11:40:17 -08:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
2013-02-07 15:17:06 -08:00
|
|
|
if (mText != null && mText.getText() != null) {
|
2011-12-23 11:40:17 -08:00
|
|
|
updateGoButton(mText.getText().toString());
|
2013-02-07 15:17:06 -08:00
|
|
|
if (mDelayRestartInput) {
|
|
|
|
// call updateGoButton again to force a restartInput call
|
|
|
|
updateGoButton(mText.getText().toString());
|
|
|
|
}
|
|
|
|
}
|
2012-03-19 11:22:33 -07:00
|
|
|
|
|
|
|
// Invlidate the cached value that keeps track of whether or
|
|
|
|
// not desktop bookmarks exist
|
|
|
|
BrowserDB.invalidateCachedState();
|
2011-12-23 11:40:17 -08:00
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
mAwesomeTabs.destroy();
|
|
|
|
}
|
|
|
|
|
2012-03-15 10:01:11 -07:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
// Let mAwesomeTabs try to handle the back press, since we may be in a
|
|
|
|
// bookmarks sub-folder.
|
|
|
|
if (mAwesomeTabs.onBackPressed())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Otherwise, just exit the awesome screen
|
|
|
|
cancelAndFinish();
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
static public class ContextMenuSubject {
|
2012-03-05 13:31:55 -08:00
|
|
|
public int id;
|
|
|
|
public String url;
|
|
|
|
public byte[] favicon;
|
|
|
|
public String title;
|
2012-03-12 13:01:09 -07:00
|
|
|
public String keyword;
|
2012-09-10 10:24:38 -07:00
|
|
|
public int display;
|
2012-03-05 13:31:55 -08:00
|
|
|
|
2012-03-12 13:01:09 -07:00
|
|
|
public ContextMenuSubject(int id, String url, byte[] favicon, String title, String keyword) {
|
2012-09-10 10:24:38 -07:00
|
|
|
this(id, url, favicon, title, keyword, Combined.DISPLAY_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContextMenuSubject(int id, String url, byte[] favicon, String title, String keyword, int display) {
|
2012-03-05 13:31:55 -08:00
|
|
|
this.id = id;
|
|
|
|
this.url = url;
|
|
|
|
this.favicon = favicon;
|
|
|
|
this.title = title;
|
2012-03-12 13:01:09 -07:00
|
|
|
this.keyword = keyword;
|
2012-09-10 10:24:38 -07:00
|
|
|
this.display = display;
|
2012-03-05 13:31:55 -08:00
|
|
|
}
|
|
|
|
};
|
2011-12-20 07:28:12 -08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
|
|
|
|
super.onCreateContextMenu(menu, view, menuInfo);
|
2012-06-18 12:39:13 -07:00
|
|
|
AwesomeBarTab tab = mAwesomeTabs.getAwesomeBarTabForView(view);
|
|
|
|
mContextMenuSubject = tab.getSubject(menu, view, menuInfo);
|
2011-12-20 07:28:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
2011-12-26 22:07:46 -08:00
|
|
|
if (mContextMenuSubject == null)
|
2011-12-20 07:28:12 -08:00
|
|
|
return false;
|
|
|
|
|
2012-03-05 13:31:55 -08:00
|
|
|
final int id = mContextMenuSubject.id;
|
|
|
|
final String url = mContextMenuSubject.url;
|
|
|
|
final byte[] b = mContextMenuSubject.favicon;
|
|
|
|
final String title = mContextMenuSubject.title;
|
2012-03-12 13:01:09 -07:00
|
|
|
final String keyword = mContextMenuSubject.keyword;
|
2011-12-20 07:28:12 -08:00
|
|
|
|
|
|
|
switch (item.getItemId()) {
|
2012-09-10 10:24:38 -07:00
|
|
|
case R.id.open_in_reader: {
|
|
|
|
if (url == null) {
|
|
|
|
Log.e(LOGTAG, "Can't open in reader mode because URL is null");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-11 10:51:43 -07:00
|
|
|
openUrlAndFinish(ReaderModeUtils.getAboutReaderForUrl(url, true));
|
2012-09-10 10:24:38 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-03-12 13:01:09 -07:00
|
|
|
case R.id.edit_bookmark: {
|
|
|
|
AlertDialog.Builder editPrompt = new AlertDialog.Builder(this);
|
2013-02-21 12:00:52 -08:00
|
|
|
final View editView = getLayoutInflater().inflate(R.layout.bookmark_edit, null);
|
2012-03-12 13:01:09 -07:00
|
|
|
editPrompt.setTitle(R.string.bookmark_edit_title);
|
|
|
|
editPrompt.setView(editView);
|
|
|
|
|
|
|
|
final EditText nameText = ((EditText) editView.findViewById(R.id.edit_bookmark_name));
|
|
|
|
final EditText locationText = ((EditText) editView.findViewById(R.id.edit_bookmark_location));
|
|
|
|
final EditText keywordText = ((EditText) editView.findViewById(R.id.edit_bookmark_keyword));
|
|
|
|
nameText.setText(title);
|
|
|
|
locationText.setText(url);
|
|
|
|
keywordText.setText(keyword);
|
|
|
|
|
|
|
|
editPrompt.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-03-12 13:01:09 -07:00
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
2013-03-15 03:52:53 -07:00
|
|
|
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
|
2012-03-12 13:01:09 -07:00
|
|
|
@Override
|
|
|
|
public Void doInBackground(Void... params) {
|
|
|
|
String newUrl = locationText.getText().toString().trim();
|
2013-02-18 13:17:54 -08:00
|
|
|
BrowserDB.updateBookmark(getContentResolver(), id, newUrl, nameText.getText().toString(),
|
2012-03-12 13:01:09 -07:00
|
|
|
keywordText.getText().toString());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(Void result) {
|
|
|
|
Toast.makeText(AwesomeBar.this, R.string.bookmark_updated, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
editPrompt.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int whichButton) {
|
2012-03-12 13:01:09 -07:00
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final AlertDialog dialog = editPrompt.create();
|
|
|
|
|
|
|
|
// disable OK button if the URL is empty
|
|
|
|
locationText.addTextChangedListener(new TextWatcher() {
|
|
|
|
private boolean mEnabled = true;
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-03-12 13:01:09 -07:00
|
|
|
public void afterTextChanged(Editable s) {}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-03-12 13:01:09 -07:00
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-03-12 13:01:09 -07:00
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
boolean enabled = (s.toString().trim().length() > 0);
|
|
|
|
if (mEnabled != enabled) {
|
|
|
|
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(enabled);
|
|
|
|
mEnabled = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
break;
|
|
|
|
}
|
2012-01-15 13:51:23 -08:00
|
|
|
case R.id.remove_bookmark: {
|
2013-03-15 03:52:53 -07:00
|
|
|
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
|
2012-06-02 11:23:45 -07:00
|
|
|
private boolean mInReadingList;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPreExecute() {
|
|
|
|
mInReadingList = mAwesomeTabs.isInReadingList();
|
|
|
|
}
|
|
|
|
|
2012-02-14 16:23:06 -08:00
|
|
|
@Override
|
|
|
|
public Void doInBackground(Void... params) {
|
2013-02-18 13:17:54 -08:00
|
|
|
BrowserDB.removeBookmark(getContentResolver(), id);
|
2012-02-14 16:23:06 -08:00
|
|
|
return null;
|
|
|
|
}
|
2012-02-07 06:47:54 -08:00
|
|
|
|
2012-02-14 16:23:06 -08:00
|
|
|
@Override
|
|
|
|
public void onPostExecute(Void result) {
|
2012-06-02 11:23:45 -07:00
|
|
|
int messageId = R.string.bookmark_removed;
|
2012-06-12 07:03:06 -07:00
|
|
|
if (mInReadingList) {
|
2012-06-02 11:23:45 -07:00
|
|
|
messageId = R.string.reading_list_removed;
|
|
|
|
|
2012-06-12 07:03:06 -07:00
|
|
|
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", url);
|
|
|
|
GeckoAppShell.sendEventToGecko(e);
|
|
|
|
}
|
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
Toast.makeText(AwesomeBar.this, messageId, Toast.LENGTH_SHORT).show();
|
2012-02-07 06:47:54 -08:00
|
|
|
}
|
2012-02-14 16:23:06 -08:00
|
|
|
}).execute();
|
2012-01-15 13:51:23 -08:00
|
|
|
break;
|
2012-05-14 11:44:34 -07:00
|
|
|
}
|
|
|
|
case R.id.remove_history: {
|
2013-03-15 03:52:53 -07:00
|
|
|
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
|
2012-05-14 11:44:34 -07:00
|
|
|
@Override
|
|
|
|
public Void doInBackground(Void... params) {
|
2013-02-18 13:17:54 -08:00
|
|
|
BrowserDB.removeHistoryEntry(getContentResolver(), id);
|
2012-05-14 11:44:34 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(Void result) {
|
|
|
|
Toast.makeText(AwesomeBar.this, R.string.history_removed, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
break;
|
2012-01-15 13:51:23 -08:00
|
|
|
}
|
2011-12-20 07:28:12 -08:00
|
|
|
case R.id.add_to_launcher: {
|
2012-05-14 14:38:18 -07:00
|
|
|
if (url == null) {
|
|
|
|
Log.e(LOGTAG, "Can't add to home screen because URL is null");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-20 07:28:12 -08:00
|
|
|
Bitmap bitmap = null;
|
2013-04-22 18:03:01 -07:00
|
|
|
if (b != null) {
|
|
|
|
bitmap = BitmapUtils.decodeByteArray(b);
|
|
|
|
}
|
2012-04-20 11:49:30 -07:00
|
|
|
|
|
|
|
String shortcutTitle = TextUtils.isEmpty(title) ? url.replaceAll("^([a-z]+://)?(www\\.)?", "") : title;
|
|
|
|
GeckoAppShell.createShortcut(shortcutTitle, url, bitmap, "");
|
2011-12-20 07:28:12 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.share: {
|
2012-05-14 14:38:18 -07:00
|
|
|
if (url == null) {
|
|
|
|
Log.e(LOGTAG, "Can't share because URL is null");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-20 07:28:12 -08:00
|
|
|
GeckoAppShell.openUriExternal(url, "text/plain", "", "",
|
|
|
|
Intent.ACTION_SEND, title);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return super.onContextItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-10 10:24:26 -07:00
|
|
|
public static String getReaderForUrl(String url) {
|
|
|
|
// FIXME: still need to define the final way to open items from
|
|
|
|
// reading list. For now, we're using an about:reader page.
|
|
|
|
return "about:reader?url=" + Uri.encode(url) + "&readingList=1";
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:37:32 -07:00
|
|
|
private static boolean hasCompositionString(Editable content) {
|
|
|
|
Object[] spans = content.getSpans(0, content.length(), Object.class);
|
|
|
|
if (spans != null) {
|
|
|
|
for (Object span : spans) {
|
|
|
|
if ((content.getSpanFlags(span) & Spanned.SPAN_COMPOSING) != 0) {
|
|
|
|
// Found composition string.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-17 09:13:49 -07:00
|
|
|
|
|
|
|
// return early if we're backspacing through the string, or have no autocomplete results
|
|
|
|
public void onAutocomplete(final String result) {
|
|
|
|
final String text = mText.getText().toString();
|
|
|
|
|
|
|
|
if (result == null) {
|
|
|
|
mAutoCompleteResult = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.startsWith(text) || text.equals(result)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAutoCompleteResult = result;
|
|
|
|
mText.getText().append(result.substring(text.length()));
|
|
|
|
mText.setSelection(text.length(), result.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(final Editable s) {
|
|
|
|
final String text = s.toString();
|
|
|
|
boolean useHandler = false;
|
|
|
|
boolean reuseAutocomplete = false;
|
|
|
|
if (!hasCompositionString(s) && !StringUtils.isSearchQuery(text, false)) {
|
|
|
|
useHandler = true;
|
|
|
|
|
|
|
|
// If you're hitting backspace (the string is getting smaller
|
|
|
|
// or is unchanged), don't autocomplete.
|
|
|
|
if (mAutoCompletePrefix != null && (mAutoCompletePrefix.length() >= text.length())) {
|
|
|
|
useHandler = false;
|
|
|
|
} else if (mAutoCompleteResult != null && mAutoCompleteResult.startsWith(text)) {
|
|
|
|
// If this text already matches our autocomplete text, autocomplete likely
|
|
|
|
// won't change. Just reuse the old autocomplete value.
|
|
|
|
useHandler = false;
|
|
|
|
reuseAutocomplete = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is the autocomplete text being set, don't run the filter.
|
|
|
|
if (mAutoCompleteResult == null || !mAutoCompleteResult.equals(text)) {
|
|
|
|
mAwesomeTabs.filter(text, useHandler ? this : null);
|
|
|
|
mAutoCompletePrefix = text;
|
|
|
|
|
|
|
|
if (reuseAutocomplete) {
|
|
|
|
onAutocomplete(mAutoCompleteResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the AwesomeBar has a composition string, don't call updateGoButton().
|
|
|
|
// That method resets IME and composition state will be broken.
|
|
|
|
if (!hasCompositionString(s)) {
|
|
|
|
updateGoButton(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
getActionBar().hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count,
|
|
|
|
int after) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before,
|
|
|
|
int count) {
|
|
|
|
// do nothing
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|