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-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;
|
|
|
|
|
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;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.os.Handler;
|
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;
|
|
|
|
import android.view.MenuInflater;
|
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-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;
|
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-04-26 16:17:34 -07:00
|
|
|
public class BrowserToolbar 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";
|
2013-03-14 15:35:38 -07:00
|
|
|
private GeckoRelativeLayout mLayout;
|
2012-12-03 02:50:41 -08:00
|
|
|
private LayoutParams mAwesomeBarParams;
|
2013-03-14 15:35:38 -07:00
|
|
|
private View mAwesomeBarContent;
|
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;
|
2012-07-10 16:10:15 -07:00
|
|
|
private List<View> mFocusOrder;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
final private BrowserApp mActivity;
|
2011-12-07 15:12:51 -08:00
|
|
|
private Handler mHandler;
|
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;
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
private static List<View> sActionItems;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
public BrowserToolbar(BrowserApp activity) {
|
|
|
|
// BrowserToolbar is attached to BrowserApp only.
|
|
|
|
mActivity = activity;
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
sActionItems = new ArrayList<View>();
|
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() {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
setTitle(tab.getDisplayTitle());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
|
|
|
|
Resources res = mActivity.getResources();
|
|
|
|
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));
|
|
|
|
|
2012-03-20 17:23:06 -07:00
|
|
|
}
|
|
|
|
|
2013-03-14 15:35:38 -07:00
|
|
|
public void from(RelativeLayout layout) {
|
2012-11-26 11:57:13 -08:00
|
|
|
if (mLayout != null) {
|
|
|
|
// make sure we retain the visibility property on rotation
|
|
|
|
layout.setVisibility(mLayout.getVisibility());
|
|
|
|
}
|
2012-01-27 12:28:45 -08:00
|
|
|
|
2013-03-14 15:35:38 -07:00
|
|
|
mLayout = (GeckoRelativeLayout) layout;
|
2013-04-24 14:53:31 -07:00
|
|
|
|
2013-03-14 15:35:38 -07:00
|
|
|
mLayout.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
|
|
|
|
|
|
|
mLayout.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);
|
|
|
|
|
|
|
|
String clipboard = GeckoAppShell.getClipboardText();
|
2012-06-15 08:58:13 -07:00
|
|
|
if (clipboard == null || 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
|
|
|
|
2013-03-14 15:35:38 -07:00
|
|
|
mShowSiteSecurity = false;
|
|
|
|
mShowReader = false;
|
|
|
|
|
|
|
|
mAnimatingEntry = false;
|
|
|
|
|
|
|
|
mAddressBarBg = (BrowserToolbarBackground) mLayout.findViewById(R.id.address_bar_bg);
|
|
|
|
mAddressBarViewOffset = mActivity.getResources().getDimensionPixelSize(R.dimen.addressbar_offset_left);
|
|
|
|
mDefaultForwardMargin = mActivity.getResources().getDimensionPixelSize(R.dimen.forward_default_offset);
|
|
|
|
mAwesomeBarContent = mLayout.findViewById(R.id.awesome_bar_content);
|
|
|
|
mAwesomeBarEntry = mLayout.findViewById(R.id.awesome_bar_entry);
|
|
|
|
|
|
|
|
// This will clip the right edge's image at half of its width
|
|
|
|
mAwesomeBarRightEdge = (ImageView) mLayout.findViewById(R.id.awesome_bar_right_edge);
|
2013-05-03 06:16:57 -07:00
|
|
|
if (mAwesomeBarRightEdge != null) {
|
|
|
|
mAwesomeBarRightEdge.getDrawable().setLevel(5000);
|
|
|
|
}
|
2013-03-14 15:35:38 -07:00
|
|
|
|
|
|
|
mTitle = (GeckoTextView) mLayout.findViewById(R.id.awesome_bar_title);
|
|
|
|
mTitlePadding = mTitle.getPaddingRight();
|
|
|
|
if (Build.VERSION.SDK_INT >= 16)
|
|
|
|
mTitle.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
|
|
|
2013-03-14 15:26:25 -07:00
|
|
|
mTabs = (ShapedButton) mLayout.findViewById(R.id.tabs);
|
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
|
|
|
|
2013-04-26 16:17:34 -07:00
|
|
|
mTabsCounter = (TabCounter) mLayout.findViewById(R.id.tabs_counter);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-05-24 15:47:49 -07:00
|
|
|
mBack = (ImageButton) mLayout.findViewById(R.id.back);
|
|
|
|
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 = (ImageButton) mLayout.findViewById(R.id.forward);
|
2012-12-19 09:29:02 -08:00
|
|
|
mForward.setEnabled(false); // initialize the forward button to not be enabled
|
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
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
SiteIdentityPopup.getInstance().show(mSiteSecurity);
|
2012-08-23 14:54:31 -07:00
|
|
|
}
|
2012-08-23 11:27:11 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
mFavicon = (ImageButton) mLayout.findViewById(R.id.favicon);
|
|
|
|
mFavicon.setOnClickListener(faviconListener);
|
|
|
|
if (Build.VERSION.SDK_INT >= 16)
|
|
|
|
mFavicon.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
2012-11-06 19:51:06 -08:00
|
|
|
mFaviconSize = Math.round(mActivity.getResources().getDimension(R.dimen.browser_toolbar_favicon_size));
|
2012-08-23 11:27:11 -07:00
|
|
|
|
|
|
|
mSiteSecurity = (ImageButton) mLayout.findViewById(R.id.site_security);
|
|
|
|
mSiteSecurity.setOnClickListener(faviconListener);
|
2012-08-23 11:27:11 -07:00
|
|
|
mSiteSecurityVisible = (mSiteSecurity.getVisibility() == View.VISIBLE);
|
2012-05-02 09:07:58 -07:00
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
mProgressSpinner = (AnimationDrawable) mActivity.getResources().getDrawable(R.drawable.progress_spinner);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-20 17:23:06 -07:00
|
|
|
mStop = (ImageButton) mLayout.findViewById(R.id.stop);
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
mReader = (ImageButton) mLayout.findViewById(R.id.reader);
|
|
|
|
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) {
|
|
|
|
if (ReaderModeUtils.isAboutReader(tab.getURL())) {
|
|
|
|
tab.doBack();
|
|
|
|
} else {
|
|
|
|
tab.readerMode();
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-20 17:23:06 -07:00
|
|
|
mShadow = (ImageView) mLayout.findViewById(R.id.shadow);
|
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
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
mHandler = new Handler();
|
2012-05-31 16:01:50 -07:00
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
float slideWidth = mActivity.getResources().getDimension(R.dimen.browser_toolbar_lock_width);
|
|
|
|
|
|
|
|
LinearLayout.LayoutParams siteSecParams = (LinearLayout.LayoutParams) mSiteSecurity.getLayoutParams();
|
|
|
|
final float scale = mActivity.getResources().getDisplayMetrics().density;
|
|
|
|
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-11-16 00:21:46 -08:00
|
|
|
mMenu = (GeckoImageButton) mLayout.findViewById(R.id.menu);
|
2013-05-07 10:19:19 -07:00
|
|
|
mMenuIcon = (GeckoImageView) mLayout.findViewById(R.id.menu_icon);
|
2012-05-31 16:01:50 -07:00
|
|
|
mActionItemBar = (LinearLayout) mLayout.findViewById(R.id.menu_items);
|
2013-04-02 07:04:21 -07:00
|
|
|
mHasSoftMenuButton = !HardwareUtils.hasMenuButton();
|
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.
|
|
|
|
mLayout.post(new Runnable() {
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
2012-07-27 23:15:39 -07:00
|
|
|
View panel = mActivity.getMenuPanel();
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
// If panel is null, the app is starting up for the first time;
|
|
|
|
// add this to the popup only if we have a soft menu button.
|
|
|
|
// else, browser-toolbar is initialized on rotation,
|
|
|
|
// and we need to re-attach action-bar items.
|
|
|
|
|
|
|
|
if (panel == null) {
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
|
|
|
|
panel = mActivity.getMenuPanel();
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
if (mHasSoftMenuButton) {
|
2012-07-27 23:15:39 -07:00
|
|
|
mMenuPopup = new MenuPopup(mActivity);
|
2012-05-31 16:01:50 -07:00
|
|
|
mMenuPopup.setPanelView(panel);
|
2012-09-19 10:35:35 -07:00
|
|
|
|
|
|
|
mMenuPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-09-19 10:35:35 -07:00
|
|
|
public void onDismiss() {
|
|
|
|
mActivity.onOptionsMenuClosed(null);
|
|
|
|
}
|
|
|
|
});
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-10 16:10:15 -07:00
|
|
|
|
2013-03-14 15:35:38 -07:00
|
|
|
mFocusOrder = Arrays.asList(mBack, mForward, mLayout, mReader, mSiteSecurity, mStop, mTabs);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-06-12 22:47:52 -07:00
|
|
|
public View getLayout() {
|
|
|
|
return mLayout;
|
|
|
|
}
|
|
|
|
|
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-04-26 16:17:37 -07:00
|
|
|
setTitle(tab.getDisplayTitle());
|
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-04-26 16:17:37 -07:00
|
|
|
setTitle(tab.getDisplayTitle());
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESTORED:
|
2013-03-11 16:09:14 -07:00
|
|
|
updateTabCount(Tabs.getInstance().getDisplayCount());
|
2012-11-07 18:34:54 -08:00
|
|
|
break;
|
2012-06-11 15:18:40 -07:00
|
|
|
case SELECTED:
|
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-03-11 16:09:14 -07:00
|
|
|
updateTabCountAndAnimate(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-04-25 10:47:08 -07:00
|
|
|
return mLayout.getScrollY() == 0;
|
2013-03-07 02:17:32 -08:00
|
|
|
}
|
|
|
|
|
2013-04-01 10:55:24 -07:00
|
|
|
public void setNextFocusDownId(int nextId) {
|
2013-03-14 15:35:38 -07:00
|
|
|
mLayout.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-03-14 15:35:38 -07:00
|
|
|
return mLayout.getWidth() - mAwesomeBarEntry.getRight();
|
2012-12-10 05:03:56 -08:00
|
|
|
}
|
|
|
|
|
2013-05-01 09:32:01 -07:00
|
|
|
private int getAwesomeBarCurveTranslation() {
|
|
|
|
return mLayout.getWidth() - mTabs.getLeft();
|
|
|
|
}
|
|
|
|
|
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-03-14 15:35:38 -07:00
|
|
|
if (!mLayout.isSelected()) {
|
|
|
|
// Keep the entry highlighted during the animation
|
|
|
|
mLayout.setSelected(true);
|
|
|
|
|
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-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-02-27 14:18:28 -08:00
|
|
|
if (mHasSoftMenuButton)
|
|
|
|
contentAnimator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
|
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-03-14 15:35:38 -07:00
|
|
|
mLayout.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.
|
|
|
|
updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
|
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
|
|
|
mHandler.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
|
|
|
|
mLayout.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-02-27 14:18:28 -08:00
|
|
|
if (mHasSoftMenuButton)
|
|
|
|
contentAnimator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
2013-05-01 09:32:01 -07:00
|
|
|
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 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-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()
|
|
|
|
if (!mLayout.isSelected()) {
|
|
|
|
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-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()
|
|
|
|
if (mLayout.isSelected()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-26 16:17:34 -07:00
|
|
|
mTabsCounter.setCurrentText(String.valueOf(count));
|
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
|
|
|
|
// enter reader mode for current page or 2) if you're already in reader mode and can exit back,
|
|
|
|
// in which case we show the reader mode "close" (reader_active) icon.
|
|
|
|
boolean exitableReaderMode = false;
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
exitableReaderMode = ReaderModeUtils.isAboutReader(tab.getURL()) && tab.canDoBack();
|
|
|
|
mReader.setImageResource(exitableReaderMode ? R.drawable.reader_active : R.drawable.reader);
|
|
|
|
mReader.setVisibility(!isLoading && (mShowReader || exitableReaderMode) ? 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-03-01 16:01:11 -08:00
|
|
|
mTitle.setPadding(0, 0, (!isLoading && !(mShowReader || exitableReaderMode) ? 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) {
|
2012-01-17 14:57:21 -08:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
2012-03-16 09:29:37 -07:00
|
|
|
|
2013-05-08 12:53:24 -07:00
|
|
|
if (tab != null) {
|
|
|
|
// Keep the title unchanged if the tab is entering reader mode
|
|
|
|
if (tab.isEnteringReaderMode()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-11 10:51:44 -07:00
|
|
|
|
2013-05-08 12:53:24 -07:00
|
|
|
// Setting a null title will ensure we just see the "Enter Search or Address"
|
|
|
|
// placeholder text. Because "about:home" and "about:privatebrowsing" don't
|
|
|
|
// have titles, their display titles will always match their URLs.
|
|
|
|
if ("about:home".equals(title) || "about:privatebrowsing".equals(title)) {
|
2013-05-08 12:53:27 -07:00
|
|
|
title = null;
|
2013-05-08 12:53:24 -07:00
|
|
|
}
|
2013-04-26 16:17:37 -07:00
|
|
|
|
2013-05-08 12:53:27 -07:00
|
|
|
if (mShowUrl && title != null) {
|
2013-05-08 12:53:24 -07:00
|
|
|
title = StringUtils.stripScheme(tab.getURL());
|
2013-05-08 12:53:27 -07:00
|
|
|
title = StringUtils.stripCommonSubdomains(title.toString());
|
2013-05-08 12:53:24 -07:00
|
|
|
|
|
|
|
// highlight the domain name if we find one
|
|
|
|
String baseDomain = tab.getBaseDomain();
|
|
|
|
if (!TextUtils.isEmpty(baseDomain)) {
|
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder(title);
|
2013-05-08 12:53:27 -07:00
|
|
|
int index = title.toString().indexOf(baseDomain);
|
2013-05-08 12:53:24 -07:00
|
|
|
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);
|
|
|
|
|
2013-05-08 12:53:27 -07:00
|
|
|
title = builder;
|
2013-05-08 12:53:24 -07:00
|
|
|
}
|
2013-04-26 16:17:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-16 09:29:37 -07:00
|
|
|
|
2013-05-08 12:53:27 -07:00
|
|
|
mTitle.setText(title);
|
2013-03-14 15:35:38 -07:00
|
|
|
mLayout.setContentDescription(title != null ? title : mTitle.getHint());
|
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) {
|
2012-06-02 11:23:45 -07:00
|
|
|
mShowSiteSecurity = true;
|
2012-02-06 11:44:37 -08:00
|
|
|
|
2012-05-02 09:07:58 -07:00
|
|
|
if (mode.equals(SiteIdentityPopup.IDENTIFIED)) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mSiteSecurity.setImageLevel(1);
|
2012-05-02 09:07:58 -07:00
|
|
|
} else if (mode.equals(SiteIdentityPopup.VERIFIED)) {
|
2011-12-15 11:53:04 -08:00
|
|
|
mSiteSecurity.setImageLevel(2);
|
2012-02-06 11:44:37 -08:00
|
|
|
} else {
|
2011-11-18 10:28:17 -08:00
|
|
|
mSiteSecurity.setImageLevel(0);
|
2012-06-02 11:23:45 -07:00
|
|
|
mShowSiteSecurity = false;
|
2012-02-06 11:44:37 -08:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2012-03-20 17:23:06 -07:00
|
|
|
public void requestFocusFromTouch() {
|
2013-03-14 15:35:38 -07:00
|
|
|
mLayout.requestFocusFromTouch();
|
2012-03-20 17:23:06 -07:00
|
|
|
}
|
|
|
|
|
2013-05-07 10:19:19 -07:00
|
|
|
public void prepareTabsAnimation(boolean tabsAreShown) {
|
|
|
|
if (!tabsAreShown) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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-03-14 15:35:38 -07:00
|
|
|
(ViewGroup.MarginLayoutParams)mAwesomeBarContent.getLayoutParams();
|
|
|
|
layoutParams.leftMargin = 0;
|
|
|
|
mAwesomeBarContent.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-03-14 15:35:38 -07:00
|
|
|
(ViewGroup.MarginLayoutParams)mAwesomeBarContent.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-03-14 15:35:38 -07:00
|
|
|
layoutParams.leftMargin = mDefaultForwardMargin + (mForward.isEnabled() ? mForward.getWidth() / 2 : 0);
|
2013-05-07 10:04:10 -07:00
|
|
|
ViewHelper.setTranslationX(mForward, 0);
|
2013-01-02 17:11:15 -08:00
|
|
|
|
2013-03-14 15:35:38 -07:00
|
|
|
mAwesomeBarContent.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);
|
|
|
|
|
|
|
|
if (!sActionItems.contains(actionItem))
|
|
|
|
sActionItems.add(actionItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-02 23:09:55 -07:00
|
|
|
public void removeActionItem(int index) {
|
|
|
|
mActionItemBar.removeViewAt(index);
|
|
|
|
sActionItems.remove(index);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getActionItemsCount() {
|
|
|
|
return sActionItems.size();
|
|
|
|
}
|
|
|
|
|
2012-02-15 16:14:02 -08:00
|
|
|
public void show() {
|
2012-06-07 21:47:22 -07:00
|
|
|
mLayout.setVisibility(View.VISIBLE);
|
2012-02-15 16:14:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void hide() {
|
2012-06-07 21:47:22 -07:00
|
|
|
mLayout.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) {
|
2012-03-05 13:20:04 -08:00
|
|
|
String url = tab.getURL();
|
2013-04-26 16:17:37 -07:00
|
|
|
setTitle(tab.getDisplayTitle());
|
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);
|
|
|
|
mLayout.setPrivateMode(isPrivate);
|
|
|
|
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;
|
|
|
|
|
2012-07-24 16:12:12 -07:00
|
|
|
GeckoApp.mAppContext.invalidateOptionsMenu();
|
2012-05-31 16:01:50 -07:00
|
|
|
if (mMenuPopup != null && !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
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|