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;
|
|
|
|
|
2013-05-07 10:04:11 -07:00
|
|
|
import org.mozilla.gecko.animation.PropertyAnimator;
|
|
|
|
import org.mozilla.gecko.animation.ViewHelper;
|
2013-04-02 07:03:39 -07:00
|
|
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
2013-04-11 09:33:40 -07:00
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
2013-05-13 10:20:49 -07:00
|
|
|
import org.mozilla.gecko.util.GamepadUtils;
|
2013-05-15 10:41:25 -07:00
|
|
|
import org.mozilla.gecko.menu.GeckoMenu;
|
|
|
|
import org.mozilla.gecko.menu.MenuPopup;
|
2013-07-15 17:19:05 -07:00
|
|
|
import org.mozilla.gecko.PageActionLayout;
|
|
|
|
import org.mozilla.gecko.PrefsHelper;
|
2013-06-07 13:39:37 -07:00
|
|
|
import org.mozilla.gecko.util.Clipboard;
|
2013-04-26 16:17:37 -07:00
|
|
|
import org.mozilla.gecko.util.StringUtils;
|
2013-04-02 07:03:39 -07:00
|
|
|
import org.mozilla.gecko.util.HardwareUtils;
|
2013-04-25 23:43:03 -07:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
|
|
|
import org.mozilla.gecko.util.UiAsyncTask;
|
2013-07-15 17:19:05 -07:00
|
|
|
import org.mozilla.gecko.util.GeckoEventListener;
|
2013-05-14 05:29:31 -07:00
|
|
|
|
2013-06-20 08:06:15 -07:00
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.content.Context;
|
2013-03-19 08:25:46 -07:00
|
|
|
import android.content.res.Resources;
|
2012-11-05 03:42:25 -08:00
|
|
|
import android.graphics.Bitmap;
|
2013-04-26 16:17:37 -07:00
|
|
|
import android.graphics.Color;
|
2013-04-08 00:51:56 -07:00
|
|
|
import android.graphics.Rect;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.graphics.drawable.AnimationDrawable;
|
2013-02-13 08:50:56 -08:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.graphics.drawable.Drawable;
|
2012-11-15 21:28:38 -08:00
|
|
|
import android.graphics.drawable.StateListDrawable;
|
2012-01-27 11:19:13 -08:00
|
|
|
import android.os.Build;
|
2012-01-24 12:39:23 -08:00
|
|
|
import android.os.SystemClock;
|
2013-04-26 16:17:37 -07:00
|
|
|
import android.text.style.ForegroundColorSpan;
|
2013-05-13 10:20:49 -07:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.InputType;
|
2013-04-26 16:17:37 -07:00
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableStringBuilder;
|
2013-05-13 10:20:49 -07:00
|
|
|
import android.text.Spanned;
|
2012-06-15 08:58:13 -07:00
|
|
|
import android.text.TextUtils;
|
2013-05-13 10:20:49 -07:00
|
|
|
import android.text.TextWatcher;
|
2012-10-31 22:12:02 -07:00
|
|
|
import android.util.AttributeSet;
|
2012-01-24 12:39:23 -08:00
|
|
|
import android.util.Log;
|
2012-06-07 10:13:36 -07:00
|
|
|
import android.view.ContextMenu;
|
2013-05-13 10:20:49 -07:00
|
|
|
import android.view.KeyEvent;
|
2013-06-25 16:10:52 -07:00
|
|
|
import android.view.LayoutInflater;
|
2012-06-07 10:13:36 -07:00
|
|
|
import android.view.MenuInflater;
|
2013-06-25 16:10:52 -07:00
|
|
|
import android.view.MotionEvent;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.view.View;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.view.ViewGroup;
|
2012-12-03 02:50:41 -08:00
|
|
|
import android.view.ViewGroup.MarginLayoutParams;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.view.Window;
|
2012-08-24 06:52:24 -07:00
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
2013-05-30 11:47:44 -07:00
|
|
|
import android.view.animation.AccelerateInterpolator;
|
2013-04-27 15:21:15 -07:00
|
|
|
import android.view.animation.Animation;
|
2013-08-06 16:38:00 -07:00
|
|
|
import android.view.animation.AnimationUtils;
|
2013-04-26 16:17:34 -07:00
|
|
|
import android.view.animation.AlphaAnimation;
|
2013-05-30 11:47:44 -07:00
|
|
|
import android.view.animation.Interpolator;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.view.animation.TranslateAnimation;
|
2013-05-13 10:20:49 -07:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.Button;
|
2013-05-13 10:20:49 -07:00
|
|
|
import android.widget.EditText;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.ImageButton;
|
2011-12-15 11:53:04 -08:00
|
|
|
import android.widget.ImageView;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.LinearLayout;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.widget.PopupWindow;
|
2013-03-14 15:35:38 -07:00
|
|
|
import android.widget.RelativeLayout;
|
2012-12-03 02:50:41 -08:00
|
|
|
import android.widget.RelativeLayout.LayoutParams;
|
2012-05-25 15:10:26 -07:00
|
|
|
import android.widget.ViewSwitcher;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2013-03-06 08:56:00 -08:00
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
public class BrowserToolbar extends GeckoRelativeLayout
|
2013-07-03 17:08:31 -07:00
|
|
|
implements TextWatcher,
|
2013-05-13 10:20:49 -07:00
|
|
|
AutocompleteHandler,
|
|
|
|
Tabs.OnTabsChangedListener,
|
2012-08-23 11:27:11 -07:00
|
|
|
GeckoMenu.ActionItemBarPresenter,
|
2013-07-15 17:19:05 -07:00
|
|
|
Animation.AnimationListener,
|
|
|
|
GeckoEventListener {
|
2012-03-20 17:23:06 -07:00
|
|
|
private static final String LOGTAG = "GeckoToolbar";
|
2013-05-14 05:29:31 -07:00
|
|
|
public static final String PREF_TITLEBAR_MODE = "browser.chrome.titlebarMode";
|
2013-05-13 10:20:49 -07:00
|
|
|
|
|
|
|
public interface OnActivateListener {
|
|
|
|
public void onActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnCommitListener {
|
2013-07-23 17:52:36 -07:00
|
|
|
public void onCommit();
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnDismissListener {
|
|
|
|
public void onDismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface OnFilterListener {
|
|
|
|
public void onFilter(String searchText, AutocompleteHandler handler);
|
|
|
|
}
|
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
private LayoutParams mAwesomeBarParams;
|
2013-05-13 10:08:56 -07:00
|
|
|
private View mUrlDisplayContainer;
|
2013-05-13 10:20:49 -07:00
|
|
|
private View mUrlEditContainer;
|
|
|
|
private CustomEditText mUrlEditText;
|
2013-05-28 08:48:27 -07:00
|
|
|
private View mUrlBarEntry;
|
|
|
|
private ImageView mUrlBarRightEdge;
|
|
|
|
private BrowserToolbarBackground mUrlBarBackground;
|
2012-11-15 21:40:57 -08:00
|
|
|
private GeckoTextView mTitle;
|
2012-08-23 11:27:11 -07:00
|
|
|
private int mTitlePadding;
|
2012-08-23 11:27:11 -07:00
|
|
|
private boolean mSiteSecurityVisible;
|
2013-05-01 09:32:02 -07:00
|
|
|
private boolean mSwitchingTabs;
|
2013-03-14 15:26:25 -07:00
|
|
|
private ShapedButton mTabs;
|
2012-11-30 13:16:45 -08:00
|
|
|
private ImageButton mBack;
|
|
|
|
private ImageButton mForward;
|
2011-12-07 15:12:51 -08:00
|
|
|
public ImageButton mFavicon;
|
|
|
|
public ImageButton mStop;
|
|
|
|
public ImageButton mSiteSecurity;
|
2013-05-13 10:20:49 -07:00
|
|
|
public ImageButton mGo;
|
2013-07-15 17:19:05 -07:00
|
|
|
public PageActionLayout mPageActionLayout;
|
2013-08-06 16:38:00 -07:00
|
|
|
private Animation mProgressSpinner;
|
2013-04-26 16:17:34 -07:00
|
|
|
private TabCounter mTabsCounter;
|
2011-12-15 11:53:04 -08:00
|
|
|
private ImageView mShadow;
|
2012-11-16 00:21:46 -08:00
|
|
|
private GeckoImageButton mMenu;
|
2013-05-07 10:19:19 -07:00
|
|
|
private GeckoImageView mMenuIcon;
|
2012-05-31 16:01:50 -07:00
|
|
|
private LinearLayout mActionItemBar;
|
|
|
|
private MenuPopup mMenuPopup;
|
2013-06-25 16:10:52 -07:00
|
|
|
private List<? extends View> mFocusOrder;
|
2013-05-13 10:20:49 -07:00
|
|
|
private OnActivateListener mActivateListener;
|
|
|
|
private OnCommitListener mCommitListener;
|
|
|
|
private OnDismissListener mDismissListener;
|
|
|
|
private OnFilterListener mFilterListener;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
final private BrowserApp mActivity;
|
2012-05-31 16:01:50 -07:00
|
|
|
private boolean mHasSoftMenuButton;
|
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
private boolean mShowSiteSecurity;
|
|
|
|
private boolean mShowReader;
|
2013-08-06 16:38:00 -07:00
|
|
|
private boolean mSpinnerVisible;
|
2012-06-02 11:23:45 -07:00
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
private boolean mDelayRestartInput;
|
|
|
|
// The previous autocomplete result returned to us
|
|
|
|
private String mAutoCompleteResult = "";
|
|
|
|
// The user typed part of the autocomplete result
|
|
|
|
private String mAutoCompletePrefix = null;
|
|
|
|
|
2013-07-26 11:15:10 -07:00
|
|
|
private boolean mIsEditing;
|
2013-03-13 12:57:00 -07:00
|
|
|
private boolean mAnimatingEntry;
|
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
private AlphaAnimation mLockFadeIn;
|
|
|
|
private TranslateAnimation mTitleSlideLeft;
|
|
|
|
private TranslateAnimation mTitleSlideRight;
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
private int mUrlBarViewOffset;
|
2013-01-02 17:11:15 -08:00
|
|
|
private int mDefaultForwardMargin;
|
2012-12-19 09:29:02 -08:00
|
|
|
private PropertyAnimator mForwardAnim = null;
|
|
|
|
|
2012-11-06 19:51:06 -08:00
|
|
|
private int mFaviconSize;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-03-07 02:17:32 -08:00
|
|
|
private PropertyAnimator mVisibilityAnimator;
|
2013-05-30 11:47:44 -07:00
|
|
|
private static final Interpolator sButtonsInterpolator = new AccelerateInterpolator();
|
2013-03-07 02:17:32 -08:00
|
|
|
|
2012-06-07 21:47:22 -07:00
|
|
|
private static final int TABS_CONTRACTED = 1;
|
|
|
|
private static final int TABS_EXPANDED = 2;
|
|
|
|
|
2012-12-19 09:29:02 -08:00
|
|
|
private static final int FORWARD_ANIMATION_DURATION = 450;
|
2013-04-26 16:17:37 -07:00
|
|
|
private final ForegroundColorSpan mUrlColor;
|
2013-08-19 15:14:37 -07:00
|
|
|
private final ForegroundColorSpan mBlockedColor;
|
2013-04-26 16:17:37 -07:00
|
|
|
private final ForegroundColorSpan mDomainColor;
|
|
|
|
private final ForegroundColorSpan mPrivateDomainColor;
|
2012-12-19 09:29:02 -08:00
|
|
|
|
2013-04-25 23:43:03 -07:00
|
|
|
private boolean mShowUrl;
|
|
|
|
|
2013-05-14 05:29:31 -07:00
|
|
|
private Integer mPrefObserverId;
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
public BrowserToolbar(Context context) {
|
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BrowserToolbar(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
// BrowserToolbar is attached to BrowserApp only.
|
2013-06-25 16:10:52 -07:00
|
|
|
mActivity = (BrowserApp) context;
|
|
|
|
|
|
|
|
// Inflate the content.
|
|
|
|
LayoutInflater.from(context).inflate(R.layout.browser_toolbar, this);
|
2012-05-31 16:01:50 -07:00
|
|
|
|
2012-06-13 10:52:46 -07:00
|
|
|
Tabs.registerOnTabsChangedListener(this);
|
2013-05-01 09:32:02 -07:00
|
|
|
mSwitchingTabs = true;
|
2013-03-07 02:17:32 -08:00
|
|
|
|
2013-07-26 11:15:10 -07:00
|
|
|
mIsEditing = false;
|
2013-03-13 12:57:00 -07:00
|
|
|
mAnimatingEntry = false;
|
2013-04-25 23:43:03 -07:00
|
|
|
mShowUrl = false;
|
|
|
|
|
2013-05-14 05:29:31 -07:00
|
|
|
// listen to the title bar pref.
|
|
|
|
mPrefObserverId = PrefsHelper.getPref(PREF_TITLEBAR_MODE, new PrefsHelper.PrefHandlerBase() {
|
2013-04-25 23:43:03 -07:00
|
|
|
@Override
|
2013-05-14 05:29:31 -07:00
|
|
|
public void prefValue(String pref, String str) {
|
|
|
|
int value = Integer.parseInt(str);
|
|
|
|
boolean shouldShowUrl = (value == 1);
|
|
|
|
|
|
|
|
if (shouldShowUrl == mShowUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mShowUrl = shouldShowUrl;
|
|
|
|
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2013-05-14 16:19:37 -07:00
|
|
|
updateTitle();
|
2013-05-14 05:29:31 -07:00
|
|
|
}
|
|
|
|
});
|
2013-04-25 23:43:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-05-14 05:29:31 -07:00
|
|
|
public boolean isObserver() {
|
|
|
|
// We want to be notified of changes to be able to switch mode
|
|
|
|
// without restarting.
|
|
|
|
return true;
|
2013-04-25 23:43:03 -07:00
|
|
|
}
|
2013-05-14 05:29:31 -07:00
|
|
|
});
|
2013-04-26 16:17:37 -07:00
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
Resources res = getResources();
|
2013-04-26 16:17:37 -07:00
|
|
|
mUrlColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_urltext));
|
2013-08-19 15:14:37 -07:00
|
|
|
mBlockedColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_blockedtext));
|
2013-04-26 16:17:37 -07:00
|
|
|
mDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext));
|
|
|
|
mPrivateDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext_private));
|
|
|
|
|
2013-07-15 17:19:05 -07:00
|
|
|
registerEventListener("Reader:Click");
|
|
|
|
registerEventListener("Reader:LongClick");
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
mShowSiteSecurity = false;
|
|
|
|
mShowReader = false;
|
|
|
|
|
|
|
|
mAnimatingEntry = false;
|
2012-03-20 17:23:06 -07:00
|
|
|
|
2013-07-03 17:08:31 -07:00
|
|
|
mUrlBarBackground = (BrowserToolbarBackground) findViewById(R.id.url_bar_bg);
|
|
|
|
mUrlBarViewOffset = res.getDimensionPixelSize(R.dimen.url_bar_offset_left);
|
2013-06-25 16:10:52 -07:00
|
|
|
mDefaultForwardMargin = res.getDimensionPixelSize(R.dimen.forward_default_offset);
|
2013-07-03 17:08:31 -07:00
|
|
|
mUrlDisplayContainer = findViewById(R.id.url_display_container);
|
|
|
|
mUrlBarEntry = findViewById(R.id.url_bar_entry);
|
|
|
|
|
|
|
|
mUrlEditContainer = findViewById(R.id.url_edit_container);
|
|
|
|
mUrlEditText = (CustomEditText) findViewById(R.id.url_edit_text);
|
2012-03-20 17:23:06 -07:00
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
// This will clip the right edge's image at half of its width
|
2013-07-03 17:08:31 -07:00
|
|
|
mUrlBarRightEdge = (ImageView) findViewById(R.id.url_bar_right_edge);
|
|
|
|
if (mUrlBarRightEdge != null) {
|
|
|
|
mUrlBarRightEdge.getDrawable().setLevel(5000);
|
2012-11-26 11:57:13 -08:00
|
|
|
}
|
2012-01-27 12:28:45 -08:00
|
|
|
|
2013-07-03 17:08:31 -07:00
|
|
|
mTitle = (GeckoTextView) findViewById(R.id.url_bar_title);
|
2013-06-25 16:10:52 -07:00
|
|
|
mTitlePadding = mTitle.getPaddingRight();
|
2013-04-24 14:53:31 -07:00
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
mTabs = (ShapedButton) findViewById(R.id.tabs);
|
|
|
|
mTabsCounter = (TabCounter) findViewById(R.id.tabs_counter);
|
|
|
|
mBack = (ImageButton) findViewById(R.id.back);
|
|
|
|
mForward = (ImageButton) findViewById(R.id.forward);
|
|
|
|
mForward.setEnabled(false); // initialize the forward button to not be enabled
|
|
|
|
|
|
|
|
mFavicon = (ImageButton) findViewById(R.id.favicon);
|
|
|
|
if (Build.VERSION.SDK_INT >= 16)
|
|
|
|
mFavicon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
|
|
mFaviconSize = Math.round(res.getDimension(R.dimen.browser_toolbar_favicon_size));
|
2013-04-24 14:53:31 -07:00
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
|
|
|
|
mSiteSecurityVisible = (mSiteSecurity.getVisibility() == View.VISIBLE);
|
|
|
|
mActivity.getSiteIdentityPopup().setAnchor(mSiteSecurity);
|
|
|
|
|
2013-08-06 16:38:00 -07:00
|
|
|
mProgressSpinner = AnimationUtils.loadAnimation(mActivity, R.anim.progress_spinner);
|
2013-06-25 16:10:52 -07:00
|
|
|
|
|
|
|
mStop = (ImageButton) findViewById(R.id.stop);
|
|
|
|
mShadow = (ImageView) findViewById(R.id.shadow);
|
2013-07-15 17:19:05 -07:00
|
|
|
mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
|
2013-06-25 16:10:52 -07:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
|
|
mShadow.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
|
|
}
|
|
|
|
|
|
|
|
mMenu = (GeckoImageButton) findViewById(R.id.menu);
|
|
|
|
mMenuIcon = (GeckoImageView) findViewById(R.id.menu_icon);
|
|
|
|
mActionItemBar = (LinearLayout) findViewById(R.id.menu_items);
|
|
|
|
mHasSoftMenuButton = !HardwareUtils.hasMenuButton();
|
2013-07-10 11:12:25 -07:00
|
|
|
|
|
|
|
// We use different layouts on phones and tablets, so adjust the focus
|
|
|
|
// order appropriately.
|
|
|
|
if (HardwareUtils.isTablet()) {
|
|
|
|
mFocusOrder = Arrays.asList(mTabs, mBack, mForward, this,
|
2013-07-15 17:19:05 -07:00
|
|
|
mSiteSecurity, mPageActionLayout, mStop, mActionItemBar, mMenu);
|
2013-07-10 11:12:25 -07:00
|
|
|
} else {
|
2013-07-15 17:19:05 -07:00
|
|
|
mFocusOrder = Arrays.asList(this, mSiteSecurity, mPageActionLayout, mStop,
|
2013-07-10 11:12:25 -07:00
|
|
|
mTabs, mMenu);
|
|
|
|
}
|
2013-06-25 16:10:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
|
|
|
|
setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onClick(View v) {
|
2013-05-13 10:20:49 -07:00
|
|
|
if (mActivateListener != null) {
|
|
|
|
mActivateListener.onActivate();
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
2013-03-14 15:35:38 -07:00
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-07 10:13:36 -07:00
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
2013-08-14 02:55:27 -07:00
|
|
|
// We don't the context menu while editing
|
|
|
|
if (isEditing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
MenuInflater inflater = mActivity.getMenuInflater();
|
2012-06-07 10:13:36 -07:00
|
|
|
inflater.inflate(R.menu.titlebar_contextmenu, menu);
|
|
|
|
|
2013-06-07 13:39:37 -07:00
|
|
|
String clipboard = Clipboard.getText();
|
2013-05-12 11:16:47 -07:00
|
|
|
if (TextUtils.isEmpty(clipboard)) {
|
2012-06-07 10:13:36 -07:00
|
|
|
menu.findItem(R.id.pasteandgo).setVisible(false);
|
|
|
|
menu.findItem(R.id.paste).setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
String url = tab.getURL();
|
|
|
|
if (url == null) {
|
|
|
|
menu.findItem(R.id.copyurl).setVisible(false);
|
|
|
|
menu.findItem(R.id.share).setVisible(false);
|
|
|
|
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
|
|
|
}
|
2013-04-03 12:34:51 -07:00
|
|
|
if (!tab.getFeedsEnabled()) {
|
|
|
|
menu.findItem(R.id.subscribe).setVisible(false);
|
|
|
|
}
|
2012-06-07 10:13:36 -07:00
|
|
|
} else {
|
|
|
|
// if there is no tab, remove anything tab dependent
|
|
|
|
menu.findItem(R.id.copyurl).setVisible(false);
|
|
|
|
menu.findItem(R.id.share).setVisible(false);
|
|
|
|
menu.findItem(R.id.add_to_launcher).setVisible(false);
|
2013-04-03 12:34:51 -07:00
|
|
|
menu.findItem(R.id.subscribe).setVisible(false);
|
2012-06-07 10:13:36 -07:00
|
|
|
}
|
2013-08-26 16:41:13 -07:00
|
|
|
|
|
|
|
menu.findItem(R.id.share).setVisible(!GeckoProfile.get(getContext()).inGuestMode());
|
2012-06-07 10:13:36 -07:00
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
mUrlEditText.addTextChangedListener(this);
|
|
|
|
|
|
|
|
mUrlEditText.setOnKeyPreImeListener(new CustomEditText.OnKeyPreImeListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onKeyPreIme(View v, int keyCode, KeyEvent event) {
|
|
|
|
// We only want to process one event per tap
|
|
|
|
if (event.getAction() != KeyEvent.ACTION_DOWN)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
2013-05-28 08:48:27 -07:00
|
|
|
// If the edit text has a composition string, don't submit the text yet.
|
2013-05-13 10:20:49 -07:00
|
|
|
// ENTER is needed to commit the composition string.
|
|
|
|
Editable content = mUrlEditText.getText();
|
|
|
|
if (!hasCompositionString(content)) {
|
|
|
|
if (mCommitListener != null) {
|
2013-07-23 17:52:36 -07:00
|
|
|
mCommitListener.onCommit();
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 11:15:10 -07:00
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
clearFocus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mUrlEditText.setOnKeyListener(new View.OnKeyListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_ENTER || GamepadUtils.isActionKey(event)) {
|
|
|
|
if (event.getAction() != KeyEvent.ACTION_DOWN)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (mCommitListener != null) {
|
2013-07-23 17:52:36 -07:00
|
|
|
mCommitListener.onCommit();
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (GamepadUtils.isBackKey(event)) {
|
|
|
|
if (mDismissListener != null) {
|
|
|
|
mDismissListener.onDismiss();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mUrlEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onFocusChange(View v, boolean hasFocus) {
|
2013-07-26 11:15:10 -07:00
|
|
|
if (v == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setSelected(hasFocus);
|
|
|
|
if (hasFocus) {
|
2013-05-13 10:20:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
try {
|
|
|
|
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
Log.e(LOGTAG, "InputMethodManagerService, why are you throwing"
|
|
|
|
+ " a NullPointerException? See bug 782096", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mUrlEditText.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;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
mTabs.setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onClick(View v) {
|
2012-06-07 21:47:22 -07:00
|
|
|
toggleTabs();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
2012-02-01 14:25:50 -08:00
|
|
|
mTabs.setImageLevel(0);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-05-24 15:47:49 -07:00
|
|
|
mBack.setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-05-24 15:47:49 -07:00
|
|
|
public void onClick(View view) {
|
|
|
|
Tabs.getInstance().getSelectedTab().doBack();
|
|
|
|
}
|
|
|
|
});
|
2013-02-06 19:53:01 -08:00
|
|
|
mBack.setOnLongClickListener(new Button.OnLongClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-02-06 19:53:01 -08:00
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
return Tabs.getInstance().getSelectedTab().showBackHistory();
|
|
|
|
}
|
|
|
|
});
|
2012-05-24 15:47:49 -07:00
|
|
|
|
|
|
|
mForward.setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-05-24 15:47:49 -07:00
|
|
|
public void onClick(View view) {
|
|
|
|
Tabs.getInstance().getSelectedTab().doForward();
|
|
|
|
}
|
|
|
|
});
|
2013-02-06 19:53:01 -08:00
|
|
|
mForward.setOnLongClickListener(new Button.OnLongClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2013-02-06 19:53:01 -08:00
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
return Tabs.getInstance().getSelectedTab().showForwardHistory();
|
|
|
|
}
|
|
|
|
});
|
2012-05-24 15:47:49 -07:00
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
Button.OnClickListener faviconListener = new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-05-02 09:07:58 -07:00
|
|
|
public void onClick(View view) {
|
2012-08-23 11:27:11 -07:00
|
|
|
if (mSiteSecurity.getVisibility() != View.VISIBLE)
|
|
|
|
return;
|
2012-08-23 11:27:11 -07:00
|
|
|
|
2013-06-20 08:06:15 -07:00
|
|
|
JSONObject identityData = Tabs.getInstance().getSelectedTab().getIdentityData();
|
|
|
|
if (identityData == null) {
|
|
|
|
Log.e(LOGTAG, "Selected tab has no identity data");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SiteIdentityPopup siteIdentityPopup = mActivity.getSiteIdentityPopup();
|
|
|
|
siteIdentityPopup.updateIdentity(identityData);
|
|
|
|
siteIdentityPopup.show();
|
2012-08-23 14:54:31 -07:00
|
|
|
}
|
2012-08-23 11:27:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
mFavicon.setOnClickListener(faviconListener);
|
|
|
|
mSiteSecurity.setOnClickListener(faviconListener);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
mStop.setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onClick(View v) {
|
2012-05-04 12:52:13 -07:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.doStop();
|
2012-11-21 11:38:28 -08:00
|
|
|
setProgressVisibility(false);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-03 17:08:31 -07:00
|
|
|
mGo = (ImageButton) findViewById(R.id.go);
|
2013-05-13 10:20:49 -07:00
|
|
|
mGo.setOnClickListener(new Button.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (mCommitListener != null) {
|
2013-07-23 17:52:36 -07:00
|
|
|
mCommitListener.onCommit();
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
float slideWidth = getResources().getDimension(R.dimen.browser_toolbar_lock_width);
|
2012-08-23 11:27:11 -07:00
|
|
|
|
|
|
|
LinearLayout.LayoutParams siteSecParams = (LinearLayout.LayoutParams) mSiteSecurity.getLayoutParams();
|
2013-06-25 16:10:52 -07:00
|
|
|
final float scale = getResources().getDisplayMetrics().density;
|
2012-08-23 11:27:11 -07:00
|
|
|
slideWidth += (siteSecParams.leftMargin + siteSecParams.rightMargin) * scale + 0.5f;
|
|
|
|
|
|
|
|
mLockFadeIn = new AlphaAnimation(0.0f, 1.0f);
|
|
|
|
mLockFadeIn.setAnimationListener(this);
|
|
|
|
|
|
|
|
mTitleSlideLeft = new TranslateAnimation(slideWidth, 0, 0, 0);
|
|
|
|
mTitleSlideLeft.setAnimationListener(this);
|
|
|
|
|
|
|
|
mTitleSlideRight = new TranslateAnimation(-slideWidth, 0, 0, 0);
|
|
|
|
mTitleSlideRight.setAnimationListener(this);
|
|
|
|
|
|
|
|
final int lockAnimDuration = 300;
|
|
|
|
mLockFadeIn.setDuration(lockAnimDuration);
|
|
|
|
mTitleSlideLeft.setDuration(lockAnimDuration);
|
|
|
|
mTitleSlideRight.setDuration(lockAnimDuration);
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
if (mHasSoftMenuButton) {
|
|
|
|
mMenu.setVisibility(View.VISIBLE);
|
2013-05-07 10:19:19 -07:00
|
|
|
mMenuIcon.setVisibility(View.VISIBLE);
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
mMenu.setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-05-31 16:01:50 -07:00
|
|
|
public void onClick(View view) {
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.openOptionsMenu();
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
});
|
2013-02-27 15:05:28 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
public boolean onKey(int keyCode, KeyEvent event) {
|
|
|
|
if (event.getAction() != KeyEvent.ACTION_DOWN) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DPAD_CENTER ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_DEL ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
|
|
|
|
keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
|
|
|
|
return false;
|
|
|
|
} else if (isEditing()) {
|
|
|
|
final int prevSelStart = mUrlEditText.getSelectionStart();
|
|
|
|
final int prevSelEnd = mUrlEditText.getSelectionEnd();
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
// Manually dispatch the key event to the edit text. If selection changed as
|
2013-05-13 10:20:49 -07:00
|
|
|
// a result of the key event, then give focus back to mUrlEditText
|
|
|
|
mUrlEditText.dispatchKeyEvent(event);
|
|
|
|
|
|
|
|
final int curSelStart = mUrlEditText.getSelectionStart();
|
|
|
|
final int curSelEnd = mUrlEditText.getSelectionEnd();
|
|
|
|
|
|
|
|
if (prevSelStart != curSelStart || prevSelEnd != curSelEnd) {
|
|
|
|
mUrlEditText.requestFocusFromTouch();
|
|
|
|
|
|
|
|
// Restore the selection, which gets lost due to the focus switch
|
|
|
|
mUrlEditText.setSelection(curSelStart, curSelEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
// If the motion event has occured below the toolbar (due to the scroll
|
|
|
|
// offset), let it pass through to the page.
|
|
|
|
if (event != null && event.getY() > getHeight() - getScrollY()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
|
|
super.onSizeChanged(w, h, oldw, oldh);
|
|
|
|
|
|
|
|
if (h != oldh) {
|
|
|
|
// Post this to happen outside of onSizeChanged, as this may cause
|
|
|
|
// a layout change and relayouts within a layout change don't work.
|
|
|
|
post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
mActivity.refreshToolbarHeight();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-06-12 22:47:52 -07:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
|
|
|
switch(msg) {
|
|
|
|
case TITLE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
2013-05-14 16:19:37 -07:00
|
|
|
updateTitle();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case START:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
updateBackButton(tab.canDoBack());
|
|
|
|
updateForwardButton(tab.canDoForward());
|
|
|
|
Boolean showProgress = (Boolean)data;
|
|
|
|
if (showProgress && tab.getState() == Tab.STATE_LOADING)
|
|
|
|
setProgressVisibility(true);
|
2012-08-26 16:45:07 -07:00
|
|
|
setSecurityMode(tab.getSecurityMode());
|
2013-07-15 17:19:05 -07:00
|
|
|
setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case STOP:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
updateBackButton(tab.canDoBack());
|
|
|
|
updateForwardButton(tab.canDoForward());
|
|
|
|
setProgressVisibility(false);
|
2013-02-11 16:51:02 -08:00
|
|
|
// Reset the title in case we haven't navigated to a new page yet.
|
2013-05-14 16:19:37 -07:00
|
|
|
updateTitle();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
break;
|
2013-08-19 15:14:37 -07:00
|
|
|
case LOADED:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
updateTitle();
|
|
|
|
}
|
|
|
|
break;
|
2013-06-10 03:14:43 -07:00
|
|
|
case RESTORED:
|
|
|
|
// TabCount fixup after OOM
|
2012-06-11 15:18:40 -07:00
|
|
|
case SELECTED:
|
2013-05-28 08:56:01 -07:00
|
|
|
updateTabCount(Tabs.getInstance().getDisplayCount());
|
2013-05-01 09:32:02 -07:00
|
|
|
mSwitchingTabs = true;
|
2012-09-07 12:11:42 -07:00
|
|
|
// fall through
|
2012-06-11 15:18:40 -07:00
|
|
|
case LOCATION_CHANGE:
|
|
|
|
case LOAD_ERROR:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
refresh();
|
|
|
|
}
|
2013-05-01 09:32:02 -07:00
|
|
|
mSwitchingTabs = false;
|
2012-06-11 15:18:40 -07:00
|
|
|
break;
|
|
|
|
case CLOSED:
|
|
|
|
case ADDED:
|
2013-05-28 08:56:01 -07:00
|
|
|
updateTabCount(Tabs.getInstance().getDisplayCount());
|
2012-10-01 10:04:54 -07:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
updateBackButton(tab.canDoBack());
|
|
|
|
updateForwardButton(tab.canDoForward());
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
break;
|
2013-02-26 14:38:38 -08:00
|
|
|
case FAVICON:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
setFavicon(tab.getFavicon());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SECURITY_CHANGE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
setSecurityMode(tab.getSecurityMode());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case READER_ENABLED:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
2013-07-15 17:19:05 -07:00
|
|
|
setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
|
2013-02-26 14:38:38 -08:00
|
|
|
}
|
|
|
|
break;
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
// Return early if we're backspacing through the string, or
|
|
|
|
// have no autocomplete results
|
|
|
|
@Override
|
|
|
|
public void onAutocomplete(final String result) {
|
|
|
|
final String text = mUrlEditText.getText().toString();
|
|
|
|
|
|
|
|
if (result == null) {
|
|
|
|
mAutoCompleteResult = "";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!result.startsWith(text) || text.equals(result)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAutoCompleteResult = result;
|
|
|
|
mUrlEditText.getText().append(result.substring(text.length()));
|
|
|
|
mUrlEditText.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 (TextUtils.isEmpty(mAutoCompleteResult) || !mAutoCompleteResult.equals(text)) {
|
2013-06-11 09:57:45 -07:00
|
|
|
if (isEditing() && mFilterListener != null) {
|
2013-05-13 10:20:49 -07:00
|
|
|
mFilterListener.onFilter(text, useHandler ? this : null);
|
|
|
|
}
|
|
|
|
mAutoCompletePrefix = text;
|
|
|
|
|
|
|
|
if (reuseAutocomplete) {
|
|
|
|
onAutocomplete(mAutoCompleteResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
// If the edit text has a composition string, don't call updateGoButton().
|
2013-05-13 10:20:49 -07:00
|
|
|
// That method resets IME and composition state will be broken.
|
2013-07-22 12:11:05 -07:00
|
|
|
if (!hasCompositionString(s) ||
|
|
|
|
InputMethods.isGestureKeyboard(mUrlEditText.getContext())) {
|
2013-05-13 10:20:49 -07:00
|
|
|
updateGoButton(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
}
|
|
|
|
|
2013-03-07 02:17:32 -08:00
|
|
|
public boolean isVisible() {
|
2013-06-25 16:10:52 -07:00
|
|
|
return getScrollY() == 0;
|
2013-03-07 02:17:32 -08:00
|
|
|
}
|
|
|
|
|
2013-04-01 10:55:24 -07:00
|
|
|
public void setNextFocusDownId(int nextId) {
|
2013-06-25 16:10:52 -07:00
|
|
|
super.setNextFocusDownId(nextId);
|
2013-04-01 10:55:24 -07:00
|
|
|
mTabs.setNextFocusDownId(nextId);
|
|
|
|
mBack.setNextFocusDownId(nextId);
|
|
|
|
mForward.setNextFocusDownId(nextId);
|
|
|
|
mFavicon.setNextFocusDownId(nextId);
|
|
|
|
mStop.setNextFocusDownId(nextId);
|
|
|
|
mSiteSecurity.setNextFocusDownId(nextId);
|
2013-07-15 17:19:05 -07:00
|
|
|
mPageActionLayout.setNextFocusDownId(nextId);
|
2013-04-01 10:55:24 -07:00
|
|
|
mMenu.setNextFocusDownId(nextId);
|
|
|
|
}
|
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animation animation) {
|
|
|
|
if (animation.equals(mLockFadeIn)) {
|
|
|
|
if (mSiteSecurityVisible)
|
|
|
|
mSiteSecurity.setVisibility(View.VISIBLE);
|
2012-12-19 09:29:02 -08:00
|
|
|
} else if (animation.equals(mTitleSlideLeft)) {
|
|
|
|
// These two animations may be scheduled to start while the forward
|
|
|
|
// animation is occurring. If we're showing the site security icon, make
|
|
|
|
// sure it doesn't take any space during the forward transition.
|
|
|
|
mSiteSecurity.setVisibility(View.GONE);
|
|
|
|
} else if (animation.equals(mTitleSlideRight)) {
|
|
|
|
// If we're hiding the icon, make sure that we keep its padding
|
|
|
|
// in place during the forward transition
|
|
|
|
mSiteSecurity.setVisibility(View.INVISIBLE);
|
2012-08-23 11:27:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animation animation) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animation animation) {
|
2012-12-19 09:29:02 -08:00
|
|
|
if (animation.equals(mTitleSlideRight)) {
|
2012-08-23 11:27:11 -07:00
|
|
|
mSiteSecurity.startAnimation(mLockFadeIn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
private int getUrlBarEntryTranslation() {
|
2013-07-03 17:08:31 -07:00
|
|
|
return getWidth() - mUrlBarEntry.getRight();
|
2012-12-10 05:03:56 -08:00
|
|
|
}
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
private int getUrlBarCurveTranslation() {
|
2013-06-25 16:10:52 -07:00
|
|
|
return getWidth() - mTabs.getLeft();
|
2013-05-01 09:32:01 -07:00
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -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;
|
|
|
|
}
|
2012-12-03 02:50:41 -08:00
|
|
|
}
|
2013-05-03 06:16:57 -07:00
|
|
|
}
|
2013-05-13 10:20:49 -07:00
|
|
|
return false;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addTab() {
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.addTab();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-06-07 21:47:22 -07:00
|
|
|
private void toggleTabs() {
|
2012-07-27 23:15:39 -07:00
|
|
|
if (mActivity.areTabsShown()) {
|
|
|
|
if (mActivity.hasTabsSideBar())
|
|
|
|
mActivity.hideTabs();
|
2012-06-21 11:44:35 -07:00
|
|
|
} else {
|
|
|
|
// hide the virtual keyboard
|
|
|
|
InputMethodManager imm =
|
2012-07-27 23:15:39 -07:00
|
|
|
(InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
2012-06-21 11:44:35 -07:00
|
|
|
imm.hideSoftInputFromWindow(mTabs.getWindowToken(), 0);
|
2012-12-18 17:04:39 -08:00
|
|
|
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
if (!tab.isPrivate())
|
|
|
|
mActivity.showNormalTabs();
|
|
|
|
else
|
|
|
|
mActivity.showPrivateTabs();
|
|
|
|
}
|
2012-06-21 11:44:35 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-01 14:25:50 -08:00
|
|
|
public void updateTabCountAndAnimate(int count) {
|
2013-04-02 15:55:09 -07:00
|
|
|
// Don't animate if the toolbar is hidden.
|
|
|
|
if (!isVisible()) {
|
|
|
|
updateTabCount(count);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
// If toolbar is in edit mode, this means the entry is expanded and the
|
2013-05-01 09:32:01 -07:00
|
|
|
// tabs button is translated offscreen. Don't trigger tabs counter
|
|
|
|
// updates until the tabs button is back on screen.
|
2013-05-13 10:20:49 -07:00
|
|
|
// See stopEditing()
|
|
|
|
if (!isEditing()) {
|
2013-05-01 09:32:01 -07:00
|
|
|
mTabsCounter.setCount(count);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-05-01 09:32:01 -07:00
|
|
|
mTabs.setContentDescription((count > 1) ?
|
|
|
|
mActivity.getString(R.string.num_tabs, count) :
|
|
|
|
mActivity.getString(R.string.one_tab));
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-01 14:25:50 -08:00
|
|
|
public void updateTabCount(int count) {
|
2013-05-13 10:20:49 -07:00
|
|
|
// If toolbar is in edit mode, this means the entry is expanded and the
|
2013-05-01 09:32:01 -07:00
|
|
|
// tabs button is translated offscreen. Don't trigger tabs counter
|
|
|
|
// updates until the tabs button is back on screen.
|
2013-05-13 10:20:49 -07:00
|
|
|
// See stopEditing()
|
|
|
|
if (isEditing()) {
|
2013-05-01 09:32:01 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-28 08:56:01 -07:00
|
|
|
// Set TabCounter based on visibility
|
|
|
|
if (isVisible() && ViewHelper.getAlpha(mTabsCounter) != 0) {
|
|
|
|
mTabsCounter.setCountWithAnimation(count);
|
|
|
|
} else {
|
|
|
|
mTabsCounter.setCount(count);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update A11y information
|
2012-07-11 16:11:42 -07:00
|
|
|
mTabs.setContentDescription((count > 1) ?
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.getString(R.string.num_tabs, count) :
|
|
|
|
mActivity.getString(R.string.one_tab));
|
2013-02-21 23:22:37 -08:00
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void setProgressVisibility(boolean visible) {
|
2012-10-26 15:47:35 -07:00
|
|
|
// The "Throbber start" and "Throbber stop" log messages in this method
|
|
|
|
// are needed by S1/S2 tests (http://mrcote.info/phonedash/#).
|
|
|
|
// See discussion in Bug 804457. Bug 805124 tracks paring these down.
|
2011-11-18 10:28:17 -08:00
|
|
|
if (visible) {
|
2013-08-06 16:38:00 -07:00
|
|
|
mFavicon.setImageResource(R.drawable.progress_spinner);
|
|
|
|
//To stop the glitch caused by mutiple start() calls.
|
|
|
|
if (!mSpinnerVisible) {
|
|
|
|
setPageActionVisibility(true);
|
|
|
|
mFavicon.setAnimation(mProgressSpinner);
|
|
|
|
mProgressSpinner.start();
|
|
|
|
mSpinnerVisible = true;
|
|
|
|
}
|
2012-01-24 12:39:23 -08:00
|
|
|
Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber start");
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
2012-04-23 07:47:46 -07:00
|
|
|
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (selectedTab != null)
|
|
|
|
setFavicon(selectedTab.getFavicon());
|
2013-08-06 16:38:00 -07:00
|
|
|
|
|
|
|
if (mSpinnerVisible) {
|
|
|
|
setPageActionVisibility(false);
|
|
|
|
mFavicon.setAnimation(null);
|
|
|
|
mProgressSpinner.cancel();
|
|
|
|
mSpinnerVisible = false;
|
|
|
|
}
|
2012-01-24 12:39:23 -08:00
|
|
|
Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber stop");
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 08:36:45 -07:00
|
|
|
public void setPageActionVisibility(boolean isLoading) {
|
|
|
|
// Handle the loading mode page actions
|
|
|
|
mStop.setVisibility(isLoading ? View.VISIBLE : View.GONE);
|
2012-06-02 11:23:45 -07:00
|
|
|
|
2012-07-13 08:36:45 -07:00
|
|
|
// Handle the viewing mode page actions
|
2012-08-23 11:27:11 -07:00
|
|
|
setSiteSecurityVisibility(mShowSiteSecurity && !isLoading);
|
2013-03-01 16:01:11 -08:00
|
|
|
|
2013-05-30 16:26:38 -07:00
|
|
|
boolean inReaderMode = false;
|
2013-03-01 16:01:11 -08:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
2013-05-30 16:26:38 -07:00
|
|
|
inReaderMode = ReaderModeUtils.isAboutReader(tab.getURL());
|
2012-06-02 11:23:45 -07:00
|
|
|
|
2013-07-15 17:19:05 -07:00
|
|
|
mPageActionLayout.setVisibility(!isLoading ? View.VISIBLE : View.GONE);
|
2012-08-23 11:27:11 -07:00
|
|
|
// We want title to fill the whole space available for it when there are icons
|
|
|
|
// being shown on the right side of the toolbar as the icons already have some
|
|
|
|
// padding in them. This is just to avoid wasting space when icons are shown.
|
2013-05-30 16:26:38 -07:00
|
|
|
mTitle.setPadding(0, 0, (!isLoading && !(mShowReader || inReaderMode) ? mTitlePadding : 0), 0);
|
2012-07-10 16:10:15 -07:00
|
|
|
updateFocusOrder();
|
|
|
|
}
|
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
private void setSiteSecurityVisibility(final boolean visible) {
|
|
|
|
if (visible == mSiteSecurityVisible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mSiteSecurityVisible = visible;
|
|
|
|
|
2013-05-01 09:32:02 -07:00
|
|
|
if (mSwitchingTabs) {
|
2012-09-07 12:11:42 -07:00
|
|
|
mSiteSecurity.setVisibility(visible ? View.VISIBLE : View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
mTitle.clearAnimation();
|
|
|
|
mSiteSecurity.clearAnimation();
|
|
|
|
|
|
|
|
// If any of these animations were cancelled as a result of the
|
|
|
|
// clearAnimation() calls above, we need to reset them.
|
|
|
|
mLockFadeIn.reset();
|
|
|
|
mTitleSlideLeft.reset();
|
|
|
|
mTitleSlideRight.reset();
|
|
|
|
|
2012-12-19 09:29:02 -08:00
|
|
|
if (mForwardAnim != null) {
|
|
|
|
long delay = mForwardAnim.getRemainingTime();
|
|
|
|
mTitleSlideRight.setStartOffset(delay);
|
|
|
|
mTitleSlideLeft.setStartOffset(delay);
|
|
|
|
} else {
|
|
|
|
mTitleSlideRight.setStartOffset(0);
|
|
|
|
mTitleSlideLeft.setStartOffset(0);
|
|
|
|
}
|
2012-08-23 11:27:11 -07:00
|
|
|
|
|
|
|
mTitle.startAnimation(visible ? mTitleSlideRight : mTitleSlideLeft);
|
|
|
|
}
|
|
|
|
|
2012-07-10 16:10:15 -07:00
|
|
|
private void updateFocusOrder() {
|
|
|
|
View prevView = null;
|
|
|
|
|
2013-07-03 17:42:47 -07:00
|
|
|
// If the element that has focus becomes disabled or invisible, focus
|
|
|
|
// is given to the URL bar.
|
|
|
|
boolean needsNewFocus = false;
|
|
|
|
|
2012-07-10 16:10:15 -07:00
|
|
|
for (View view : mFocusOrder) {
|
2013-07-03 17:42:47 -07:00
|
|
|
if (view.getVisibility() != View.VISIBLE || !view.isEnabled()) {
|
|
|
|
if (view.hasFocus()) {
|
|
|
|
needsNewFocus = true;
|
|
|
|
}
|
2012-07-10 16:10:15 -07:00
|
|
|
continue;
|
2013-07-03 17:42:47 -07:00
|
|
|
}
|
2012-07-10 16:10:15 -07:00
|
|
|
|
2013-07-10 11:12:25 -07:00
|
|
|
if (view == mActionItemBar) {
|
|
|
|
final int childCount = mActionItemBar.getChildCount();
|
|
|
|
for (int child = 0; child < childCount; child++) {
|
|
|
|
View childView = mActionItemBar.getChildAt(child);
|
|
|
|
if (prevView != null) {
|
|
|
|
childView.setNextFocusLeftId(prevView.getId());
|
|
|
|
prevView.setNextFocusRightId(childView.getId());
|
2013-07-03 17:42:47 -07:00
|
|
|
}
|
2013-07-10 11:12:25 -07:00
|
|
|
prevView = childView;
|
2013-07-03 17:42:47 -07:00
|
|
|
}
|
2013-07-10 11:12:25 -07:00
|
|
|
} else {
|
|
|
|
if (prevView != null) {
|
|
|
|
view.setNextFocusLeftId(prevView.getId());
|
|
|
|
prevView.setNextFocusRightId(view.getId());
|
|
|
|
}
|
|
|
|
prevView = view;
|
2013-07-03 17:42:47 -07:00
|
|
|
}
|
2013-07-10 11:12:25 -07:00
|
|
|
}
|
2013-07-03 17:42:47 -07:00
|
|
|
|
2013-07-10 11:12:25 -07:00
|
|
|
if (needsNewFocus) {
|
|
|
|
requestFocus();
|
2012-07-10 16:10:15 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-15 11:53:04 -08:00
|
|
|
public void setShadowVisibility(boolean visible) {
|
2012-11-16 13:43:33 -08:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = tab.getURL();
|
|
|
|
|
|
|
|
if ((mShadow.getVisibility() == View.VISIBLE) != visible) {
|
|
|
|
mShadow.setVisibility(visible ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
2011-12-15 11:53:04 -08:00
|
|
|
}
|
|
|
|
|
2013-06-11 10:01:35 -07:00
|
|
|
public void onEditSuggestion(String suggestion) {
|
|
|
|
if (!isEditing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUrlEditText.setText(suggestion);
|
|
|
|
mUrlEditText.setSelection(mUrlEditText.getText().length());
|
|
|
|
mUrlEditText.requestFocus();
|
|
|
|
|
|
|
|
showSoftInput();
|
|
|
|
}
|
|
|
|
|
2013-05-08 12:53:27 -07:00
|
|
|
private void setTitle(CharSequence title) {
|
2013-05-14 16:19:37 -07:00
|
|
|
mTitle.setText(title);
|
2013-06-25 16:10:52 -07:00
|
|
|
setContentDescription(title != null ? title : mTitle.getHint());
|
2013-05-14 16:19:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the toolbar title according to the selected tab, obeying the mShowUrl prference.
|
|
|
|
private void updateTitle() {
|
2012-01-17 14:57:21 -08:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
2013-05-14 16:19:37 -07:00
|
|
|
// Keep the title unchanged if there's no selected tab, or if the tab is entering reader mode.
|
|
|
|
if (tab == null || tab.isEnteringReaderMode()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-16 09:29:37 -07:00
|
|
|
|
2013-05-14 16:19:37 -07:00
|
|
|
String url = tab.getURL();
|
2013-06-13 03:44:28 -07:00
|
|
|
|
|
|
|
if (!isEditing()) {
|
|
|
|
mUrlEditText.setText(url);
|
|
|
|
}
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-05-14 16:19:37 -07:00
|
|
|
// Setting a null title will ensure we just see the "Enter Search or Address" placeholder text.
|
|
|
|
if ("about:home".equals(url) || "about:privatebrowsing".equals(url)) {
|
|
|
|
setTitle(null);
|
|
|
|
return;
|
|
|
|
}
|
2012-09-11 10:51:44 -07:00
|
|
|
|
2013-08-19 15:14:37 -07:00
|
|
|
// Show the about:blocked page title in red, regardless of prefs
|
|
|
|
if (tab.getErrorType() == Tab.ErrorType.BLOCKED) {
|
|
|
|
String title = tab.getDisplayTitle();
|
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder(title);
|
|
|
|
builder.setSpan(mBlockedColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
setTitle(builder);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-14 16:19:37 -07:00
|
|
|
// If the pref to show the URL isn't set, just use the tab's display title.
|
|
|
|
if (!mShowUrl || url == null) {
|
|
|
|
setTitle(tab.getDisplayTitle());
|
|
|
|
return;
|
|
|
|
}
|
2013-04-26 16:17:37 -07:00
|
|
|
|
2013-05-14 16:19:37 -07:00
|
|
|
url = StringUtils.stripScheme(url);
|
|
|
|
CharSequence title = StringUtils.stripCommonSubdomains(url);
|
|
|
|
|
|
|
|
String baseDomain = tab.getBaseDomain();
|
|
|
|
if (!TextUtils.isEmpty(baseDomain)) {
|
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder(title);
|
|
|
|
int index = title.toString().indexOf(baseDomain);
|
|
|
|
if (index > -1) {
|
|
|
|
builder.setSpan(mUrlColor, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
builder.setSpan(tab.isPrivate() ? mPrivateDomainColor : mDomainColor, index, index+baseDomain.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
|
|
|
|
title = builder;
|
2013-04-26 16:17:37 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-16 09:29:37 -07:00
|
|
|
|
2013-05-14 16:19:37 -07:00
|
|
|
setTitle(title);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 14:38:38 -08:00
|
|
|
private void setFavicon(Bitmap image) {
|
2012-03-07 13:58:31 -08:00
|
|
|
if (Tabs.getInstance().getSelectedTab().getState() == Tab.STATE_LOADING)
|
2011-11-18 10:28:17 -08:00
|
|
|
return;
|
|
|
|
|
2012-12-03 00:59:17 -08:00
|
|
|
if (image != null) {
|
2012-11-06 19:51:06 -08:00
|
|
|
image = Bitmap.createScaledBitmap(image, mFaviconSize, mFaviconSize, false);
|
2012-11-05 03:42:25 -08:00
|
|
|
mFavicon.setImageBitmap(image);
|
2012-11-06 19:51:06 -08:00
|
|
|
} else {
|
2011-11-18 10:28:17 -08:00
|
|
|
mFavicon.setImageResource(R.drawable.favicon);
|
2012-11-06 19:51:06 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 14:38:38 -08:00
|
|
|
private void setSecurityMode(String mode) {
|
2013-06-21 20:36:38 -07:00
|
|
|
int imageLevel = SiteIdentityPopup.getSecurityImageLevel(mode);
|
|
|
|
mSiteSecurity.setImageLevel(imageLevel);
|
|
|
|
mShowSiteSecurity = (imageLevel != SiteIdentityPopup.LEVEL_UKNOWN);
|
2012-07-13 08:36:45 -07:00
|
|
|
|
|
|
|
setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-01-30 15:10:16 -08:00
|
|
|
|
2013-05-30 11:47:44 -07:00
|
|
|
public void prepareTabsAnimation(PropertyAnimator animator, boolean tabsAreShown) {
|
2013-05-07 10:19:19 -07:00
|
|
|
if (!tabsAreShown) {
|
2013-05-30 11:47:44 -07:00
|
|
|
PropertyAnimator buttonsAnimator =
|
|
|
|
new PropertyAnimator(animator.getDuration(), sButtonsInterpolator);
|
2013-05-07 10:19:19 -07:00
|
|
|
|
2013-05-30 11:47:44 -07:00
|
|
|
buttonsAnimator.attach(mTabsCounter,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1.0f);
|
2013-05-07 10:19:19 -07:00
|
|
|
|
2013-05-30 11:47:44 -07:00
|
|
|
if (mHasSoftMenuButton && !HardwareUtils.isTablet()) {
|
|
|
|
buttonsAnimator.attach(mMenuIcon,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonsAnimator.start();
|
2013-05-07 10:19:19 -07:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewHelper.setAlpha(mTabsCounter, 0.0f);
|
|
|
|
|
|
|
|
if (mHasSoftMenuButton && !HardwareUtils.isTablet()) {
|
|
|
|
ViewHelper.setAlpha(mMenuIcon, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishTabsAnimation(boolean tabsAreShown) {
|
|
|
|
if (tabsAreShown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyAnimator animator = new PropertyAnimator(150);
|
|
|
|
|
|
|
|
animator.attach(mTabsCounter,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1.0f);
|
|
|
|
|
|
|
|
if (mHasSoftMenuButton && !HardwareUtils.isTablet()) {
|
|
|
|
animator.attach(mMenuIcon,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
animator.start();
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
public void setOnActivateListener(OnActivateListener listener) {
|
|
|
|
mActivateListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnCommitListener(OnCommitListener listener) {
|
|
|
|
mCommitListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnDismissListener(OnDismissListener listener) {
|
|
|
|
mDismissListener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOnFilterListener(OnFilterListener listener) {
|
|
|
|
mFilterListener = listener;
|
|
|
|
}
|
|
|
|
|
2013-06-11 10:01:35 -07:00
|
|
|
private void showSoftInput() {
|
|
|
|
InputMethodManager imm =
|
|
|
|
(InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
|
|
imm.showSoftInput(mUrlEditText, InputMethodManager.SHOW_IMPLICIT);
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
private void showUrlEditContainer() {
|
2013-07-26 04:46:29 -07:00
|
|
|
setUrlEditContainerVisibility(true, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showUrlEditContainer(PropertyAnimator animator) {
|
|
|
|
setUrlEditContainerVisibility(true, animator);
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void hideUrlEditContainer() {
|
2013-07-26 04:46:29 -07:00
|
|
|
setUrlEditContainerVisibility(false, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideUrlEditContainer(PropertyAnimator animator) {
|
|
|
|
setUrlEditContainerVisibility(false, animator);
|
|
|
|
}
|
|
|
|
|
2013-07-26 06:19:36 -07:00
|
|
|
private void setUrlEditContainerVisibility(final boolean showEditContainer, PropertyAnimator animator) {
|
|
|
|
final View viewToShow = (showEditContainer ? mUrlEditContainer : mUrlDisplayContainer);
|
|
|
|
final View viewToHide = (showEditContainer ? mUrlDisplayContainer : mUrlEditContainer);
|
2013-07-26 04:46:29 -07:00
|
|
|
|
|
|
|
if (animator == null) {
|
|
|
|
viewToHide.setVisibility(View.GONE);
|
|
|
|
viewToShow.setVisibility(View.VISIBLE);
|
|
|
|
|
2013-07-26 06:19:36 -07:00
|
|
|
if (showEditContainer) {
|
2013-07-26 04:46:29 -07:00
|
|
|
mUrlEditText.requestFocus();
|
|
|
|
showSoftInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewHelper.setAlpha(viewToShow, 0.0f);
|
|
|
|
animator.attach(viewToShow,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1.0f);
|
|
|
|
|
|
|
|
animator.attach(viewToHide,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0.0f);
|
|
|
|
|
|
|
|
animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
viewToShow.setVisibility(View.VISIBLE);
|
|
|
|
|
2013-07-26 06:19:36 -07:00
|
|
|
if (showEditContainer) {
|
2013-07-26 04:46:29 -07:00
|
|
|
ViewHelper.setAlpha(mGo, 0.0f);
|
|
|
|
mUrlEditText.requestFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
viewToHide.setVisibility(View.GONE);
|
2013-07-26 06:20:56 -07:00
|
|
|
ViewHelper.setAlpha(viewToHide, 1.0f);
|
2013-07-26 04:46:29 -07:00
|
|
|
|
2013-07-26 06:19:36 -07:00
|
|
|
if (showEditContainer) {
|
2013-07-26 04:46:29 -07:00
|
|
|
ViewHelper.setAlpha(mGo, 1.0f);
|
|
|
|
showSoftInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
2013-07-26 11:15:10 -07:00
|
|
|
/**
|
|
|
|
* Returns whether or not the URL bar is in editing mode (url bar is expanded, hiding the new
|
|
|
|
* tab button). Note that selection state is independent of editing mode.
|
|
|
|
*/
|
2013-05-13 10:20:49 -07:00
|
|
|
public boolean isEditing() {
|
2013-07-26 11:15:10 -07:00
|
|
|
return mIsEditing;
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
2013-07-26 04:46:28 -07:00
|
|
|
public void startEditing(String url, PropertyAnimator animator) {
|
2013-05-13 10:20:49 -07:00
|
|
|
if (isEditing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mUrlEditText.setText(url != null ? url : "");
|
2013-07-26 11:15:10 -07:00
|
|
|
mIsEditing = true;
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-08-15 12:24:05 -07:00
|
|
|
final int entryTranslation = getUrlBarEntryTranslation();
|
|
|
|
final int curveTranslation = getUrlBarCurveTranslation();
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
// This animation doesn't make much sense in a sidebar UI
|
2013-08-15 12:24:05 -07:00
|
|
|
if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
|
2013-05-13 10:20:49 -07:00
|
|
|
showUrlEditContainer();
|
2013-08-15 12:24:05 -07:00
|
|
|
|
|
|
|
if (!HardwareUtils.isTablet()) {
|
|
|
|
if (mUrlBarRightEdge != null) {
|
|
|
|
ViewHelper.setTranslationX(mUrlBarRightEdge, entryTranslation);
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewHelper.setTranslationX(mTabs, curveTranslation);
|
|
|
|
ViewHelper.setTranslationX(mTabsCounter, curveTranslation);
|
|
|
|
ViewHelper.setTranslationX(mActionItemBar, curveTranslation);
|
|
|
|
|
|
|
|
if (mHasSoftMenuButton) {
|
|
|
|
ViewHelper.setTranslationX(mMenu, curveTranslation);
|
|
|
|
ViewHelper.setTranslationX(mMenuIcon, curveTranslation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAnimatingEntry)
|
|
|
|
return;
|
|
|
|
|
2013-07-26 11:15:10 -07:00
|
|
|
// Highlight the toolbar from the start of the animation.
|
2013-07-03 17:08:31 -07:00
|
|
|
setSelected(true);
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-07-17 13:50:36 -07:00
|
|
|
// Hide page actions/stop buttons immediately
|
|
|
|
ViewHelper.setAlpha(mPageActionLayout, 0);
|
2013-05-13 10:20:49 -07:00
|
|
|
ViewHelper.setAlpha(mStop, 0);
|
|
|
|
|
|
|
|
// Slide the right side elements of the toolbar
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
if (mUrlBarRightEdge != null) {
|
2013-07-26 04:46:28 -07:00
|
|
|
animator.attach(mUrlBarRightEdge,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
entryTranslation);
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
|
|
|
|
2013-07-26 04:46:28 -07:00
|
|
|
animator.attach(mTabs,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
curveTranslation);
|
|
|
|
animator.attach(mTabsCounter,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
curveTranslation);
|
|
|
|
animator.attach(mActionItemBar,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
curveTranslation);
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-07-23 15:21:00 -07:00
|
|
|
if (mHasSoftMenuButton) {
|
2013-07-26 04:46:28 -07:00
|
|
|
animator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
curveTranslation);
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-07-26 04:46:28 -07:00
|
|
|
animator.attach(mMenuIcon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
curveTranslation);
|
2013-07-23 15:21:00 -07:00
|
|
|
}
|
|
|
|
|
2013-07-26 04:46:29 -07:00
|
|
|
showUrlEditContainer(animator);
|
|
|
|
|
2013-07-26 04:46:28 -07:00
|
|
|
animator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
2013-05-13 10:20:49 -07:00
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
mAnimatingEntry = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mAnimatingEntry = true;
|
|
|
|
}
|
|
|
|
|
2013-05-17 14:24:10 -07:00
|
|
|
/**
|
|
|
|
* Exits edit mode without updating the toolbar title.
|
|
|
|
*
|
|
|
|
* @return the url that was entered
|
|
|
|
*/
|
|
|
|
public String cancelEdit() {
|
|
|
|
return stopEditing();
|
|
|
|
}
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-05-17 14:24:10 -07:00
|
|
|
/**
|
|
|
|
* Exits edit mode, updating the toolbar title with the url that was just entered.
|
|
|
|
*
|
|
|
|
* @return the url that was entered
|
|
|
|
*/
|
|
|
|
public String commitEdit() {
|
|
|
|
final String url = stopEditing();
|
|
|
|
if (!TextUtils.isEmpty(url)) {
|
|
|
|
setTitle(url);
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
2013-05-17 14:24:10 -07:00
|
|
|
return url;
|
|
|
|
}
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-05-17 14:24:10 -07:00
|
|
|
private String stopEditing() {
|
|
|
|
final String url = mUrlEditText.getText().toString();
|
|
|
|
if (!isEditing()) {
|
|
|
|
return url;
|
2013-05-13 10:20:49 -07:00
|
|
|
}
|
2013-07-26 11:15:10 -07:00
|
|
|
mIsEditing = false;
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-08-15 12:24:05 -07:00
|
|
|
if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
|
2013-07-26 04:46:29 -07:00
|
|
|
hideUrlEditContainer();
|
2013-05-13 10:20:49 -07:00
|
|
|
updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
|
2013-08-15 12:24:05 -07:00
|
|
|
|
|
|
|
if (!HardwareUtils.isTablet()) {
|
|
|
|
if (mUrlBarRightEdge != null) {
|
|
|
|
ViewHelper.setTranslationX(mUrlBarRightEdge, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewHelper.setTranslationX(mTabs, 0);
|
|
|
|
ViewHelper.setTranslationX(mTabsCounter, 0);
|
|
|
|
ViewHelper.setTranslationX(mActionItemBar, 0);
|
|
|
|
|
|
|
|
if (mHasSoftMenuButton) {
|
|
|
|
ViewHelper.setTranslationX(mMenu, 0);
|
|
|
|
ViewHelper.setTranslationX(mMenuIcon, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 10:20:49 -07:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
final PropertyAnimator contentAnimator = new PropertyAnimator(250);
|
|
|
|
contentAnimator.setUseHardwareLayer(false);
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
// Shrink the urlbar entry back to its original size
|
2013-05-13 10:20:49 -07:00
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
if (mUrlBarRightEdge != null) {
|
|
|
|
contentAnimator.attach(mUrlBarRightEdge,
|
2013-05-13 10:20:49 -07:00
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
contentAnimator.attach(mTabs,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mTabsCounter,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mActionItemBar,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
|
2013-07-23 15:21:00 -07:00
|
|
|
if (mHasSoftMenuButton) {
|
2013-05-13 10:20:49 -07:00
|
|
|
contentAnimator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
|
2013-07-23 15:21:00 -07:00
|
|
|
contentAnimator.attach(mMenuIcon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2013-07-26 04:46:29 -07:00
|
|
|
hideUrlEditContainer(contentAnimator);
|
|
|
|
|
2013-07-26 04:46:28 -07:00
|
|
|
contentAnimator.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
2013-05-13 10:20:49 -07:00
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
PropertyAnimator buttonsAnimator = new PropertyAnimator(300);
|
|
|
|
|
2013-07-17 13:50:36 -07:00
|
|
|
// Fade toolbar buttons (page actions, stop) after the entry
|
2013-05-13 10:20:49 -07:00
|
|
|
// is schrunk back to its original size.
|
2013-07-17 13:50:36 -07:00
|
|
|
buttonsAnimator.attach(mPageActionLayout,
|
2013-05-13 10:20:49 -07:00
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1);
|
|
|
|
buttonsAnimator.attach(mStop,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1);
|
|
|
|
|
|
|
|
buttonsAnimator.start();
|
|
|
|
|
|
|
|
mAnimatingEntry = false;
|
|
|
|
|
|
|
|
// Trigger animation to update the tabs counter once the
|
|
|
|
// tabs button is back on screen.
|
|
|
|
updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mAnimatingEntry = true;
|
|
|
|
contentAnimator.start();
|
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateGoButton(String text) {
|
|
|
|
if (text.length() == 0) {
|
|
|
|
mGo.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGo.setVisibility(View.VISIBLE);
|
|
|
|
|
2013-05-28 08:48:27 -07:00
|
|
|
int imageResource = R.drawable.ic_url_bar_go;
|
2013-05-13 10:20:49 -07:00
|
|
|
String contentDescription = mActivity.getString(R.string.go);
|
|
|
|
int imeAction = EditorInfo.IME_ACTION_GO;
|
|
|
|
|
|
|
|
int actionBits = mUrlEditText.getImeOptions() & EditorInfo.IME_MASK_ACTION;
|
|
|
|
if (StringUtils.isSearchQuery(text, actionBits == EditorInfo.IME_ACTION_SEARCH)) {
|
2013-05-28 08:48:27 -07:00
|
|
|
imageResource = R.drawable.ic_url_bar_search;
|
2013-05-13 10:20:49 -07:00
|
|
|
contentDescription = mActivity.getString(R.string.search);
|
|
|
|
imeAction = EditorInfo.IME_ACTION_SEARCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
InputMethodManager imm = InputMethods.getInputMethodManager(mUrlEditText.getContext());
|
|
|
|
if (imm == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean restartInput = false;
|
|
|
|
if (actionBits != imeAction) {
|
|
|
|
int optionBits = mUrlEditText.getImeOptions() & ~EditorInfo.IME_MASK_ACTION;
|
|
|
|
mUrlEditText.setImeOptions(optionBits | imeAction);
|
|
|
|
|
|
|
|
mDelayRestartInput = (imeAction == EditorInfo.IME_ACTION_GO) &&
|
2013-05-28 08:48:27 -07:00
|
|
|
(InputMethods.shouldDelayUrlBarUpdate(mUrlEditText.getContext()));
|
2013-05-13 10:20:49 -07:00
|
|
|
if (!mDelayRestartInput) {
|
|
|
|
restartInput = true;
|
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
restartInput = true;
|
|
|
|
}
|
|
|
|
if (restartInput) {
|
|
|
|
updateKeyboardInputType();
|
|
|
|
imm.restartInput(mUrlEditText);
|
|
|
|
mGo.setImageResource(imageResource);
|
|
|
|
mGo.setContentDescription(contentDescription);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateKeyboardInputType() {
|
|
|
|
// 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.
|
|
|
|
String text = mUrlEditText.getText().toString();
|
|
|
|
int currentInputType = mUrlEditText.getInputType();
|
|
|
|
int newInputType = StringUtils.isSearchQuery(text, false)
|
|
|
|
? (currentInputType & ~InputType.TYPE_TEXT_VARIATION_URI) // Text mode
|
|
|
|
: (currentInputType | InputType.TYPE_TEXT_VARIATION_URI); // URL mode
|
|
|
|
if (newInputType != currentInputType) {
|
|
|
|
mUrlEditText.setRawInputType(newInputType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-24 15:47:49 -07:00
|
|
|
public void updateBackButton(boolean enabled) {
|
2013-02-07 14:23:33 -08:00
|
|
|
Drawable drawable = mBack.getDrawable();
|
|
|
|
if (drawable != null)
|
|
|
|
drawable.setAlpha(enabled ? 255 : 77);
|
|
|
|
|
2012-05-24 15:47:49 -07:00
|
|
|
mBack.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2012-12-19 09:29:02 -08:00
|
|
|
public void updateForwardButton(final boolean enabled) {
|
|
|
|
if (mForward.isEnabled() == enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Save the state on the forward button so that we can skip animations
|
|
|
|
// when there's nothing to change
|
|
|
|
mForward.setEnabled(enabled);
|
|
|
|
|
|
|
|
if (mForward.getVisibility() != View.VISIBLE)
|
|
|
|
return;
|
|
|
|
|
2013-05-01 09:32:02 -07:00
|
|
|
// We want the forward button to show immediately when switching tabs
|
|
|
|
mForwardAnim = new PropertyAnimator(mSwitchingTabs ? 10 : FORWARD_ANIMATION_DURATION);
|
2013-03-14 15:35:38 -07:00
|
|
|
final int width = mForward.getWidth() / 2;
|
2012-12-19 09:29:02 -08:00
|
|
|
|
2013-07-26 04:46:28 -07:00
|
|
|
mForwardAnim.addPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
2012-12-19 09:29:02 -08:00
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
if (!enabled) {
|
|
|
|
// Set the margin before the transition when hiding the forward button. We
|
|
|
|
// have to do this so that the favicon isn't clipped during the transition
|
|
|
|
ViewGroup.MarginLayoutParams layoutParams =
|
2013-05-13 10:08:56 -07:00
|
|
|
(ViewGroup.MarginLayoutParams)mUrlDisplayContainer.getLayoutParams();
|
2013-03-14 15:35:38 -07:00
|
|
|
layoutParams.leftMargin = 0;
|
2013-07-29 10:31:38 -07:00
|
|
|
|
|
|
|
// Do the same on the URL edit container
|
|
|
|
layoutParams = (ViewGroup.MarginLayoutParams)mUrlEditContainer.getLayoutParams();
|
|
|
|
layoutParams.leftMargin = 0;
|
|
|
|
|
|
|
|
requestLayout();
|
2012-12-19 09:29:02 -08:00
|
|
|
// Note, we already translated the favicon, site security, and text field
|
|
|
|
// in prepareForwardAnimation, so they should appear to have not moved at
|
|
|
|
// all at this point.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
if (enabled) {
|
|
|
|
ViewGroup.MarginLayoutParams layoutParams =
|
2013-05-13 10:08:56 -07:00
|
|
|
(ViewGroup.MarginLayoutParams)mUrlDisplayContainer.getLayoutParams();
|
2013-05-28 08:48:27 -07:00
|
|
|
layoutParams.leftMargin = mUrlBarViewOffset;
|
2012-12-19 09:29:02 -08:00
|
|
|
|
2013-07-29 10:31:38 -07:00
|
|
|
layoutParams = (ViewGroup.MarginLayoutParams)mUrlEditContainer.getLayoutParams();
|
|
|
|
layoutParams.leftMargin = mUrlBarViewOffset;
|
|
|
|
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setTranslationX(mTitle, 0);
|
|
|
|
ViewHelper.setTranslationX(mFavicon, 0);
|
|
|
|
ViewHelper.setTranslationX(mSiteSecurity, 0);
|
2012-12-19 09:29:02 -08:00
|
|
|
}
|
2013-01-02 17:11:15 -08:00
|
|
|
|
|
|
|
ViewGroup.MarginLayoutParams layoutParams =
|
|
|
|
(ViewGroup.MarginLayoutParams)mForward.getLayoutParams();
|
2013-05-28 08:43:59 -07:00
|
|
|
layoutParams.leftMargin = mDefaultForwardMargin + (mForward.isEnabled() ? width : 0);
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setTranslationX(mForward, 0);
|
2013-01-02 17:11:15 -08:00
|
|
|
|
2013-07-29 10:31:38 -07:00
|
|
|
requestLayout();
|
2012-12-19 09:29:02 -08:00
|
|
|
mForwardAnim = null;
|
|
|
|
}
|
|
|
|
});
|
2013-03-14 15:35:38 -07:00
|
|
|
|
2013-01-02 17:11:15 -08:00
|
|
|
prepareForwardAnimation(mForwardAnim, enabled, width);
|
2012-12-19 09:29:02 -08:00
|
|
|
mForwardAnim.start();
|
|
|
|
}
|
|
|
|
|
2013-01-02 17:11:15 -08:00
|
|
|
private void prepareForwardAnimation(PropertyAnimator anim, boolean enabled, int width) {
|
|
|
|
if (!enabled) {
|
2012-12-19 09:29:02 -08:00
|
|
|
anim.attach(mForward,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-03-14 15:35:38 -07:00
|
|
|
-width);
|
2012-12-19 09:29:02 -08:00
|
|
|
anim.attach(mForward,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
anim.attach(mTitle,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
anim.attach(mFavicon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
anim.attach(mSiteSecurity,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
|
|
|
|
// We're hiding the forward button. We're going to reset the margin before
|
|
|
|
// the animation starts, so we shift these items to the right so that they don't
|
|
|
|
// appear to move initially.
|
2013-05-28 08:48:27 -07:00
|
|
|
ViewHelper.setTranslationX(mTitle, mUrlBarViewOffset);
|
|
|
|
ViewHelper.setTranslationX(mFavicon, mUrlBarViewOffset);
|
|
|
|
ViewHelper.setTranslationX(mSiteSecurity, mUrlBarViewOffset);
|
2012-12-19 09:29:02 -08:00
|
|
|
} else {
|
|
|
|
anim.attach(mForward,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
anim.attach(mForward,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1);
|
|
|
|
anim.attach(mTitle,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-28 08:48:27 -07:00
|
|
|
mUrlBarViewOffset);
|
2012-12-19 09:29:02 -08:00
|
|
|
anim.attach(mFavicon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-28 08:48:27 -07:00
|
|
|
mUrlBarViewOffset);
|
2012-12-19 09:29:02 -08:00
|
|
|
anim.attach(mSiteSecurity,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-28 08:48:27 -07:00
|
|
|
mUrlBarViewOffset);
|
2012-12-19 09:29:02 -08:00
|
|
|
}
|
2012-05-24 15:47:49 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
@Override
|
|
|
|
public void addActionItem(View actionItem) {
|
|
|
|
mActionItemBar.addView(actionItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-06-05 15:28:02 -07:00
|
|
|
public void removeActionItem(View actionItem) {
|
|
|
|
mActionItemBar.removeView(actionItem);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
2012-02-15 16:14:02 -08:00
|
|
|
public void show() {
|
2013-06-25 16:10:52 -07:00
|
|
|
setVisibility(View.VISIBLE);
|
2012-02-15 16:14:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void hide() {
|
2013-06-25 16:10:52 -07:00
|
|
|
setVisibility(View.GONE);
|
2012-02-15 16:14:02 -08:00
|
|
|
}
|
|
|
|
|
2012-01-30 15:10:16 -08:00
|
|
|
public void refresh() {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
2013-05-14 16:19:37 -07:00
|
|
|
updateTitle();
|
2012-01-30 15:10:16 -08:00
|
|
|
setFavicon(tab.getFavicon());
|
2012-08-26 16:45:07 -07:00
|
|
|
setProgressVisibility(tab.getState() == Tab.STATE_LOADING);
|
2012-01-30 15:10:16 -08:00
|
|
|
setSecurityMode(tab.getSecurityMode());
|
2013-07-15 17:19:05 -07:00
|
|
|
setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
|
2012-05-24 15:47:49 -07:00
|
|
|
updateBackButton(tab.canDoBack());
|
|
|
|
updateForwardButton(tab.canDoForward());
|
2012-10-09 11:26:33 -07:00
|
|
|
|
2013-04-26 16:17:37 -07:00
|
|
|
final boolean isPrivate = tab.isPrivate();
|
2013-05-28 08:48:27 -07:00
|
|
|
mUrlBarBackground.setPrivateMode(isPrivate);
|
2013-06-25 16:10:52 -07:00
|
|
|
setPrivateMode(isPrivate);
|
2013-04-26 16:17:37 -07:00
|
|
|
mTabs.setPrivateMode(isPrivate);
|
|
|
|
mTitle.setPrivateMode(isPrivate);
|
|
|
|
mMenu.setPrivateMode(isPrivate);
|
2013-05-07 10:19:19 -07:00
|
|
|
mMenuIcon.setPrivateMode(isPrivate);
|
2013-05-13 10:20:49 -07:00
|
|
|
mUrlEditText.setPrivateMode(isPrivate);
|
2012-11-30 13:22:49 -08:00
|
|
|
|
|
|
|
if (mBack instanceof BackButton)
|
2013-04-26 16:17:37 -07:00
|
|
|
((BackButton) mBack).setPrivateMode(isPrivate);
|
2012-11-30 13:22:49 -08:00
|
|
|
|
|
|
|
if (mForward instanceof ForwardButton)
|
2013-04-26 16:17:37 -07:00
|
|
|
((ForwardButton) mForward).setPrivateMode(isPrivate);
|
2012-11-15 21:28:38 -08:00
|
|
|
}
|
2012-11-28 18:55:05 -08:00
|
|
|
}
|
|
|
|
|
2013-01-25 10:51:41 -08:00
|
|
|
public void onDestroy() {
|
2013-05-14 05:29:31 -07:00
|
|
|
if (mPrefObserverId != null) {
|
|
|
|
PrefsHelper.removeObserver(mPrefObserverId);
|
|
|
|
mPrefObserverId = null;
|
|
|
|
}
|
2013-01-25 10:51:41 -08:00
|
|
|
Tabs.unregisterOnTabsChangedListener(this);
|
2013-07-15 17:19:05 -07:00
|
|
|
|
|
|
|
unregisterEventListener("Reader:Click");
|
|
|
|
unregisterEventListener("Reader:LongClick");
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
2012-06-02 23:08:29 -07:00
|
|
|
public boolean openOptionsMenu() {
|
|
|
|
if (!mHasSoftMenuButton)
|
|
|
|
return false;
|
|
|
|
|
2013-06-25 11:39:54 -07:00
|
|
|
// Initialize the popup.
|
|
|
|
if (mMenuPopup == null) {
|
|
|
|
View panel = mActivity.getMenuPanel();
|
|
|
|
mMenuPopup = new MenuPopup(mActivity);
|
|
|
|
mMenuPopup.setPanelView(panel);
|
|
|
|
|
|
|
|
mMenuPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss() {
|
|
|
|
mActivity.onOptionsMenuClosed(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-05-24 09:21:01 -07:00
|
|
|
GeckoAppShell.getGeckoInterface().invalidateOptionsMenu();
|
2013-06-25 11:39:54 -07:00
|
|
|
if (!mMenuPopup.isShowing())
|
2012-07-09 13:23:16 -07:00
|
|
|
mMenuPopup.showAsDropDown(mMenu);
|
2012-06-02 23:08:29 -07:00
|
|
|
|
|
|
|
return true;
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
2012-06-02 23:08:29 -07:00
|
|
|
public boolean closeOptionsMenu() {
|
|
|
|
if (!mHasSoftMenuButton)
|
|
|
|
return false;
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
if (mMenuPopup != null && mMenuPopup.isShowing())
|
|
|
|
mMenuPopup.dismiss();
|
2012-06-02 23:08:29 -07:00
|
|
|
|
|
|
|
return true;
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
2013-07-15 17:19:05 -07:00
|
|
|
|
|
|
|
protected void registerEventListener(String event) {
|
|
|
|
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void unregisterEventListener(String event) {
|
|
|
|
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
if (event.equals("Reader:Click")) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
tab.toggleReaderMode();
|
|
|
|
}
|
|
|
|
} else if (event.equals("Reader:LongClick")) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
tab.addToReadingList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|