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-15 10:41:25 -07:00
|
|
|
import org.mozilla.gecko.menu.GeckoMenu;
|
|
|
|
import org.mozilla.gecko.menu.MenuPopup;
|
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-05-14 05:29:31 -07:00
|
|
|
import org.mozilla.gecko.PrefsHelper;
|
|
|
|
|
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;
|
|
|
|
import android.text.Spannable;
|
|
|
|
import android.text.SpannableStringBuilder;
|
2012-06-15 08:58:13 -07:00
|
|
|
import android.text.TextUtils;
|
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-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-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;
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.Button;
|
|
|
|
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.ArrayList;
|
|
|
|
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
|
|
|
|
implements Tabs.OnTabsChangedListener,
|
2012-08-23 11:27:11 -07:00
|
|
|
GeckoMenu.ActionItemBarPresenter,
|
2013-05-14 05:29:31 -07:00
|
|
|
Animation.AnimationListener {
|
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";
|
2012-12-03 02:50:41 -08:00
|
|
|
private LayoutParams mAwesomeBarParams;
|
2013-05-13 10:08:56 -07:00
|
|
|
private View mUrlDisplayContainer;
|
2012-12-03 02:50:41 -08:00
|
|
|
private View mAwesomeBarEntry;
|
2013-03-14 15:35:38 -07:00
|
|
|
private ImageView mAwesomeBarRightEdge;
|
2012-11-15 21:28:38 -08:00
|
|
|
private BrowserToolbarBackground mAddressBarBg;
|
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;
|
2012-06-02 11:23:45 -07:00
|
|
|
public ImageButton mReader;
|
2011-12-07 15:12:51 -08:00
|
|
|
private AnimationDrawable 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;
|
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-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;
|
|
|
|
|
2012-12-19 09:29:02 -08:00
|
|
|
private int mAddressBarViewOffset;
|
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;
|
|
|
|
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-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));
|
|
|
|
mDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext));
|
|
|
|
mPrivateDomainColor = new ForegroundColorSpan(res.getColor(R.color.url_bar_domaintext_private));
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
mShowSiteSecurity = false;
|
|
|
|
mShowReader = false;
|
|
|
|
|
|
|
|
mAnimatingEntry = false;
|
|
|
|
|
|
|
|
mAddressBarBg = (BrowserToolbarBackground) findViewById(R.id.address_bar_bg);
|
|
|
|
mAddressBarViewOffset = res.getDimensionPixelSize(R.dimen.addressbar_offset_left);
|
|
|
|
mDefaultForwardMargin = res.getDimensionPixelSize(R.dimen.forward_default_offset);
|
|
|
|
mUrlDisplayContainer = findViewById(R.id.awesome_bar_display_container);
|
|
|
|
mAwesomeBarEntry = findViewById(R.id.awesome_bar_entry);
|
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
|
|
|
|
mAwesomeBarRightEdge = (ImageView) findViewById(R.id.awesome_bar_right_edge);
|
|
|
|
if (mAwesomeBarRightEdge != null) {
|
|
|
|
mAwesomeBarRightEdge.getDrawable().setLevel(5000);
|
2012-11-26 11:57:13 -08:00
|
|
|
}
|
2012-01-27 12:28:45 -08:00
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
mTitle = (GeckoTextView) findViewById(R.id.awesome_bar_title);
|
|
|
|
mTitlePadding = mTitle.getPaddingRight();
|
|
|
|
if (Build.VERSION.SDK_INT >= 16)
|
|
|
|
mTitle.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
mStop = (ImageButton) findViewById(R.id.stop);
|
|
|
|
mReader = (ImageButton) findViewById(R.id.reader);
|
|
|
|
mShadow = (ImageView) findViewById(R.id.shadow);
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.autoHideTabs();
|
2011-11-18 10:28:17 -08:00
|
|
|
onAwesomeBarSearch();
|
|
|
|
}
|
|
|
|
});
|
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) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
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-06-25 16:10:52 -07:00
|
|
|
mProgressSpinner = (AnimationDrawable) getResources().getDrawable(R.drawable.progress_spinner);
|
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
mReader.setOnClickListener(new Button.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-02 11:23:45 -07:00
|
|
|
public void onClick(View view) {
|
2012-06-20 11:10:08 -07:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
2013-03-01 16:01:11 -08:00
|
|
|
if (tab != null) {
|
2013-05-20 10:35:03 -07:00
|
|
|
tab.toggleReaderMode();
|
2013-03-01 16:01:11 -08:00
|
|
|
}
|
2012-06-02 11:23:45 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-17 03:43:30 -07:00
|
|
|
mReader.setOnLongClickListener(new Button.OnLongClickListener() {
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
tab.addToReadingList();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-14 15:35:38 -07:00
|
|
|
mShadow.setOnClickListener(new Button.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
}
|
|
|
|
});
|
2011-12-15 11:53:04 -08: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
|
|
|
}
|
2012-08-19 21:45:37 -07:00
|
|
|
|
2013-04-02 07:03:39 -07:00
|
|
|
if (!HardwareUtils.isTablet()) {
|
2012-08-19 21:45:37 -07:00
|
|
|
// Set a touch delegate to Tabs button, so the touch events on its tail
|
|
|
|
// are passed to the menu button.
|
2013-06-25 16:10:52 -07:00
|
|
|
post(new Runnable() {
|
2012-08-19 21:45:37 -07:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
int height = mTabs.getHeight();
|
|
|
|
int width = mTabs.getWidth();
|
|
|
|
int tail = (width - height) / 2;
|
2013-02-27 15:05:28 -08:00
|
|
|
|
2013-04-04 23:03:48 -07:00
|
|
|
Rect bounds = new Rect(0, 0, tail, height);
|
2013-03-14 15:35:38 -07:00
|
|
|
TailTouchDelegate delegate = new TailTouchDelegate(bounds, mShadow);
|
2013-02-27 15:05:28 -08:00
|
|
|
mTabs.setTouchDelegate(delegate);
|
2012-08-19 21:45:37 -07:00
|
|
|
}
|
|
|
|
});
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
mFocusOrder = Arrays.asList(mBack, mForward, mReader, mSiteSecurity, mStop, mTabs);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
setReaderMode(tab.getReaderEnabled());
|
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-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)) {
|
|
|
|
setReaderMode(tab.getReaderEnabled());
|
|
|
|
}
|
|
|
|
break;
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
mReader.setNextFocusDownId(nextId);
|
|
|
|
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-01 09:32:01 -07:00
|
|
|
private int getAwesomeBarEntryTranslation() {
|
2013-06-25 16:10:52 -07:00
|
|
|
return getWidth() - mAwesomeBarEntry.getRight();
|
2012-12-10 05:03:56 -08:00
|
|
|
}
|
|
|
|
|
2013-05-01 09:32:01 -07:00
|
|
|
private int getAwesomeBarCurveTranslation() {
|
2013-06-25 16:10:52 -07:00
|
|
|
return getWidth() - mTabs.getLeft();
|
2013-05-01 09:32:01 -07:00
|
|
|
}
|
|
|
|
|
2013-02-11 16:51:02 -08:00
|
|
|
public void fromAwesomeBarSearch(String url) {
|
|
|
|
// Update the title with the url that was just entered. Don't update the title if
|
|
|
|
// the AwesomeBar activity was cancelled, or if the user entered an empty string.
|
|
|
|
if (url != null && url.length() > 0) {
|
|
|
|
setTitle(url);
|
|
|
|
}
|
|
|
|
|
2013-04-02 07:03:39 -07:00
|
|
|
if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
|
2012-12-03 02:50:41 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-10 05:03:56 -08:00
|
|
|
// If the awesomebar entry is not selected at this point, this means that
|
|
|
|
// we had to reinflate the toolbar layout for some reason (device rotation
|
|
|
|
// while in awesome screen, activity was killed in background, etc). In this
|
|
|
|
// case, we have to ensure the toolbar is in the correct initial state to
|
|
|
|
// shrink back.
|
2013-06-25 16:10:52 -07:00
|
|
|
if (!isSelected()) {
|
2013-03-14 15:35:38 -07:00
|
|
|
// Keep the entry highlighted during the animation
|
2013-06-25 16:10:52 -07:00
|
|
|
setSelected(true);
|
2013-03-14 15:35:38 -07:00
|
|
|
|
2013-05-01 09:32:01 -07:00
|
|
|
final int entryTranslation = getAwesomeBarEntryTranslation();
|
|
|
|
final int curveTranslation = getAwesomeBarCurveTranslation();
|
2012-12-10 05:03:56 -08:00
|
|
|
|
2013-05-03 06:16:57 -07:00
|
|
|
if (mAwesomeBarRightEdge != null) {
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setTranslationX(mAwesomeBarRightEdge, entryTranslation);
|
2013-05-03 06:16:57 -07:00
|
|
|
}
|
|
|
|
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setTranslationX(mTabs, curveTranslation);
|
|
|
|
ViewHelper.setTranslationX(mTabsCounter, curveTranslation);
|
|
|
|
ViewHelper.setTranslationX(mActionItemBar, curveTranslation);
|
2013-02-27 14:18:28 -08:00
|
|
|
|
|
|
|
if (mHasSoftMenuButton) {
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setTranslationX(mMenu, curveTranslation);
|
2013-05-30 11:47:44 -07:00
|
|
|
ViewHelper.setTranslationX(mMenuIcon, curveTranslation);
|
2013-02-27 14:18:28 -08:00
|
|
|
}
|
2013-05-01 09:32:02 -07:00
|
|
|
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setAlpha(mReader, 0);
|
|
|
|
ViewHelper.setAlpha(mStop, 0);
|
2012-12-10 05:03:56 -08:00
|
|
|
}
|
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
final PropertyAnimator contentAnimator = new PropertyAnimator(250);
|
2013-03-01 13:30:07 -08:00
|
|
|
contentAnimator.setUseHardwareLayer(false);
|
2012-12-03 02:50:41 -08:00
|
|
|
|
|
|
|
// Shrink the awesome entry back to its original size
|
2013-05-03 06:16:57 -07:00
|
|
|
|
|
|
|
if (mAwesomeBarRightEdge != null) {
|
|
|
|
contentAnimator.attach(mAwesomeBarRightEdge,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
contentAnimator.attach(mTabs,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
2013-04-26 16:17:34 -07:00
|
|
|
contentAnimator.attach(mTabsCounter,
|
2012-12-03 02:50:41 -08:00
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mActionItemBar,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
|
2013-05-30 11:47:44 -07:00
|
|
|
if (mHasSoftMenuButton) {
|
2013-02-27 14:18:28 -08:00
|
|
|
contentAnimator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
2013-05-30 11:47:44 -07:00
|
|
|
contentAnimator.attach(mMenuIcon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
}
|
2013-02-27 14:18:28 -08:00
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
contentAnimator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
// Turn off selected state on the entry
|
2013-06-25 16:10:52 -07:00
|
|
|
setSelected(false);
|
2012-12-03 02:50:41 -08:00
|
|
|
|
2013-05-01 09:32:02 -07:00
|
|
|
PropertyAnimator buttonsAnimator = new PropertyAnimator(300);
|
2012-12-03 02:50:41 -08:00
|
|
|
|
|
|
|
// Fade toolbar buttons (reader, stop) after the entry
|
|
|
|
// is schrunk back to its original size.
|
|
|
|
buttonsAnimator.attach(mReader,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1);
|
|
|
|
buttonsAnimator.attach(mStop,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
1);
|
|
|
|
|
|
|
|
buttonsAnimator.start();
|
2013-03-13 12:57:00 -07:00
|
|
|
|
|
|
|
mAnimatingEntry = false;
|
2013-05-01 09:32:01 -07:00
|
|
|
|
|
|
|
// Trigger animation to update the tabs counter once the
|
|
|
|
// tabs button is back on screen.
|
2013-05-28 08:56:01 -07:00
|
|
|
updateTabCount(Tabs.getInstance().getDisplayCount());
|
2012-12-03 02:50:41 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-13 12:57:00 -07:00
|
|
|
mAnimatingEntry = true;
|
|
|
|
|
2013-06-25 16:10:52 -07:00
|
|
|
postDelayed(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-12-03 02:50:41 -08:00
|
|
|
public void run() {
|
|
|
|
contentAnimator.start();
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private void onAwesomeBarSearch() {
|
2012-12-03 02:50:41 -08:00
|
|
|
// This animation doesn't make much sense in a sidebar UI
|
2013-04-02 07:03:39 -07:00
|
|
|
if (HardwareUtils.isTablet() || Build.VERSION.SDK_INT < 11) {
|
2012-12-03 02:50:41 -08:00
|
|
|
mActivity.onSearchRequested();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-13 12:57:00 -07:00
|
|
|
if (mAnimatingEntry)
|
|
|
|
return;
|
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
final PropertyAnimator contentAnimator = new PropertyAnimator(250);
|
2013-03-01 13:30:07 -08:00
|
|
|
contentAnimator.setUseHardwareLayer(false);
|
2012-12-03 02:50:41 -08:00
|
|
|
|
2013-05-01 09:32:01 -07:00
|
|
|
final int entryTranslation = getAwesomeBarEntryTranslation();
|
|
|
|
final int curveTranslation = getAwesomeBarCurveTranslation();
|
2013-03-14 15:35:38 -07:00
|
|
|
|
|
|
|
// Keep the entry highlighted during the animation
|
2013-06-25 16:10:52 -07:00
|
|
|
setSelected(true);
|
2012-12-03 02:50:41 -08:00
|
|
|
|
2013-05-01 09:32:02 -07:00
|
|
|
// Hide stop/reader buttons immediately
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setAlpha(mReader, 0);
|
|
|
|
ViewHelper.setAlpha(mStop, 0);
|
2012-12-03 02:50:41 -08:00
|
|
|
|
|
|
|
// Slide the right side elements of the toolbar
|
2013-05-03 06:16:57 -07:00
|
|
|
|
|
|
|
if (mAwesomeBarRightEdge != null) {
|
|
|
|
contentAnimator.attach(mAwesomeBarRightEdge,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
entryTranslation);
|
|
|
|
}
|
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
contentAnimator.attach(mTabs,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-01 09:32:01 -07:00
|
|
|
curveTranslation);
|
2013-04-26 16:17:34 -07:00
|
|
|
contentAnimator.attach(mTabsCounter,
|
2012-12-03 02:50:41 -08:00
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-01 09:32:01 -07:00
|
|
|
curveTranslation);
|
2012-12-03 02:50:41 -08:00
|
|
|
contentAnimator.attach(mActionItemBar,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-01 09:32:01 -07:00
|
|
|
curveTranslation);
|
2012-12-03 02:50:41 -08:00
|
|
|
|
2013-05-30 11:47:44 -07:00
|
|
|
if (mHasSoftMenuButton) {
|
2013-02-27 14:18:28 -08:00
|
|
|
contentAnimator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-01 09:32:01 -07:00
|
|
|
curveTranslation);
|
2013-05-30 11:47:44 -07:00
|
|
|
contentAnimator.attach(mMenuIcon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
curveTranslation);
|
|
|
|
}
|
2013-02-27 14:18:28 -08:00
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
contentAnimator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
// Once the entry is fully expanded, start awesome screen
|
|
|
|
mActivity.onSearchRequested();
|
2013-03-13 12:57:00 -07:00
|
|
|
mAnimatingEntry = false;
|
2012-12-03 02:50:41 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-13 12:57:00 -07:00
|
|
|
mAnimatingEntry = true;
|
2012-12-03 02:50:41 -08:00
|
|
|
contentAnimator.start();
|
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 updateTabCount(int count) {
|
2013-05-01 09:32:01 -07:00
|
|
|
// If toolbar is selected, this means the entry is expanded and the
|
|
|
|
// tabs button is translated offscreen. Don't trigger tabs counter
|
|
|
|
// updates until the tabs button is back on screen.
|
|
|
|
// See fromAwesomeBarSearch()
|
2013-06-25 16:10:52 -07:00
|
|
|
if (isSelected()) {
|
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) {
|
|
|
|
mFavicon.setImageDrawable(mProgressSpinner);
|
|
|
|
mProgressSpinner.start();
|
2012-07-13 08:36:45 -07:00
|
|
|
setPageActionVisibility(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 {
|
|
|
|
mProgressSpinner.stop();
|
2012-07-13 08:36:45 -07:00
|
|
|
setPageActionVisibility(false);
|
2012-04-23 07:47:46 -07:00
|
|
|
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (selectedTab != null)
|
|
|
|
setFavicon(selectedTab.getFavicon());
|
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
|
|
|
|
|
|
|
// Handle the readerMode image and visibility: We show the reader mode button if 1) you can
|
2013-05-30 16:26:38 -07:00
|
|
|
// enter reader mode for current page or 2) if you're already in reader mode,
|
2013-03-01 16:01:11 -08:00
|
|
|
// in which case we show the reader mode "close" (reader_active) icon.
|
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());
|
|
|
|
mReader.setImageResource(inReaderMode ? R.drawable.reader_active : R.drawable.reader);
|
|
|
|
|
|
|
|
mReader.setVisibility(!isLoading && (mShowReader || inReaderMode) ? View.VISIBLE : View.GONE);
|
2012-06-02 11:23:45 -07:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (View view : mFocusOrder) {
|
|
|
|
if (view.getVisibility() != View.VISIBLE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (prevView != null) {
|
|
|
|
view.setNextFocusLeftId(prevView.getId());
|
|
|
|
prevView.setNextFocusRightId(view.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
prevView = view;
|
|
|
|
}
|
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();
|
|
|
|
|
2013-01-09 12:04:13 -08:00
|
|
|
// Only set shadow to visible when not on about screens except about:blank.
|
|
|
|
visible &= !(url == null || (url.startsWith("about:") &&
|
|
|
|
!url.equals("about:blank")));
|
2012-11-16 13:43:33 -08:00
|
|
|
|
|
|
|
if ((mShadow.getVisibility() == View.VISIBLE) != visible) {
|
|
|
|
mShadow.setVisibility(visible ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
2011-12-15 11:53:04 -08:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
// 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-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-02-26 14:38:38 -08:00
|
|
|
private void setReaderMode(boolean showReader) {
|
2012-06-02 11:23:45 -07:00
|
|
|
mShowReader = showReader;
|
2012-07-13 08:36:45 -07:00
|
|
|
setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
|
2012-06-02 11:23:45 -07: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;
|
|
|
|
}
|
|
|
|
|
2013-05-30 11:47:44 -07:00
|
|
|
ViewHelper.setAlpha(mTabsCounter, 0.0f);
|
2013-05-07 10:19:19 -07:00
|
|
|
|
|
|
|
if (mHasSoftMenuButton && !HardwareUtils.isTablet()) {
|
2013-05-30 11:47:44 -07:00
|
|
|
ViewHelper.setAlpha(mMenuIcon, 0.0f);
|
2013-05-07 10:19:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
mForwardAnim.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
|
|
|
@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-05-13 10:08:56 -07:00
|
|
|
mUrlDisplayContainer.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();
|
2012-12-19 09:29:02 -08:00
|
|
|
layoutParams.leftMargin = mAddressBarViewOffset;
|
|
|
|
|
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-05-13 10:08:56 -07:00
|
|
|
mUrlDisplayContainer.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-07 10:04:10 -07:00
|
|
|
ViewHelper.setTranslationX(mTitle, mAddressBarViewOffset);
|
|
|
|
ViewHelper.setTranslationX(mFavicon, mAddressBarViewOffset);
|
|
|
|
ViewHelper.setTranslationX(mSiteSecurity, mAddressBarViewOffset);
|
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-03-14 15:35:38 -07:00
|
|
|
mAddressBarViewOffset);
|
2012-12-19 09:29:02 -08:00
|
|
|
anim.attach(mFavicon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-03-14 15:35:38 -07:00
|
|
|
mAddressBarViewOffset);
|
2012-12-19 09:29:02 -08:00
|
|
|
anim.attach(mSiteSecurity,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-03-14 15:35:38 -07:00
|
|
|
mAddressBarViewOffset);
|
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());
|
2012-07-13 08:36:45 -07:00
|
|
|
setReaderMode(tab.getReaderEnabled());
|
2012-11-16 13:43:33 -08:00
|
|
|
setShadowVisibility(true);
|
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();
|
|
|
|
mAddressBarBg.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);
|
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);
|
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;
|
|
|
|
|
2013-06-25 11:39:54 -07:00
|
|
|
if (mMenuPopup.isShowing())
|
2012-05-31 16:01:50 -07:00
|
|
|
mMenuPopup.dismiss();
|
2012-06-02 23:08:29 -07:00
|
|
|
|
|
|
|
return true;
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|