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;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2012-11-05 03:42:25 -08:00
|
|
|
import android.graphics.Bitmap;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.graphics.drawable.AnimationDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2012-11-15 21:28:38 -08:00
|
|
|
import android.graphics.drawable.StateListDrawable;
|
2012-08-19 21:45:37 -07:00
|
|
|
import android.graphics.Rect;
|
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;
|
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;
|
2012-05-25 15:10:26 -07:00
|
|
|
import android.view.LayoutInflater;
|
2012-06-07 10:13:36 -07:00
|
|
|
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;
|
2012-08-23 11:27:11 -07:00
|
|
|
import android.view.animation.AlphaAnimation;
|
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.DecelerateInterpolator;
|
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;
|
2012-12-03 02:50:41 -08:00
|
|
|
import android.widget.RelativeLayout.LayoutParams;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.widget.TextView;
|
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;
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class BrowserToolbar implements ViewSwitcher.ViewFactory,
|
|
|
|
Tabs.OnTabsChangedListener,
|
2012-08-23 11:27:11 -07:00
|
|
|
GeckoMenu.ActionItemBarPresenter,
|
|
|
|
Animation.AnimationListener {
|
2012-03-20 17:23:06 -07:00
|
|
|
private static final String LOGTAG = "GeckoToolbar";
|
|
|
|
private LinearLayout mLayout;
|
2012-10-12 04:57:07 -07:00
|
|
|
private View mAwesomeBar;
|
2012-12-03 02:50:41 -08:00
|
|
|
private LayoutParams mAwesomeBarParams;
|
|
|
|
private View mAwesomeBarEntry;
|
|
|
|
private int mAwesomeBarEntryRightMargin;
|
2012-11-15 21:28:38 -08:00
|
|
|
private GeckoFrameLayout mAwesomeBarRightEdge;
|
|
|
|
private BrowserToolbarBackground mAddressBarBg;
|
2012-12-03 02:50:41 -08:00
|
|
|
private BrowserToolbarBackground.CurveTowards mAddressBarBgCurveTowards;
|
|
|
|
private int mAddressBarBgRightMargin;
|
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;
|
2012-09-07 12:11:42 -07:00
|
|
|
private boolean mAnimateSiteSecurity;
|
2012-11-15 23:59:25 -08:00
|
|
|
private GeckoImageButton mTabs;
|
2012-10-12 04:57:07 -07:00
|
|
|
private int mTabsPaneWidth;
|
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;
|
2012-11-15 23:59:25 -08:00
|
|
|
private GeckoTextSwitcher mTabsCount;
|
2011-12-15 11:53:04 -08:00
|
|
|
private ImageView mShadow;
|
2012-11-16 00:21:46 -08:00
|
|
|
private GeckoImageButton mMenu;
|
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;
|
2012-05-31 16:01:50 -07:00
|
|
|
private LayoutInflater mInflater;
|
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
|
|
|
|
2011-12-07 15:12:51 -08:00
|
|
|
private int mDuration;
|
|
|
|
private TranslateAnimation mSlideUpIn;
|
|
|
|
private TranslateAnimation mSlideUpOut;
|
|
|
|
private TranslateAnimation mSlideDownIn;
|
|
|
|
private TranslateAnimation mSlideDownOut;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
private AlphaAnimation mLockFadeIn;
|
|
|
|
private TranslateAnimation mTitleSlideLeft;
|
|
|
|
private TranslateAnimation mTitleSlideRight;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private int mCount;
|
2012-11-06 19:51:06 -08:00
|
|
|
private int mFaviconSize;
|
2011-11-18 10:28:17 -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-07-27 23:15:39 -07:00
|
|
|
public BrowserToolbar(BrowserApp activity) {
|
|
|
|
// BrowserToolbar is attached to BrowserApp only.
|
|
|
|
mActivity = activity;
|
|
|
|
mInflater = LayoutInflater.from(activity);
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
sActionItems = new ArrayList<View>();
|
2012-06-13 10:52:46 -07:00
|
|
|
Tabs.registerOnTabsChangedListener(this);
|
2012-09-07 12:11:42 -07:00
|
|
|
mAnimateSiteSecurity = true;
|
2012-03-20 17:23:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void from(LinearLayout 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-03-20 17:23:06 -07:00
|
|
|
mLayout = layout;
|
2012-06-02 11:23:45 -07:00
|
|
|
|
|
|
|
mShowSiteSecurity = false;
|
|
|
|
mShowReader = false;
|
2012-01-27 12:28:45 -08:00
|
|
|
|
2012-11-15 21:28:38 -08:00
|
|
|
mAddressBarBg = (BrowserToolbarBackground) mLayout.findViewById(R.id.address_bar_bg);
|
|
|
|
mAwesomeBarRightEdge = (GeckoFrameLayout) mLayout.findViewById(R.id.awesome_bar_right_edge);
|
2012-12-03 02:50:41 -08:00
|
|
|
mAwesomeBarEntry = mLayout.findViewById(R.id.awesome_bar_entry);
|
2012-10-12 04:57:07 -07:00
|
|
|
|
|
|
|
// This will hold the translation width inside the toolbar when the tabs
|
|
|
|
// pane is visible. It will affect the padding applied to the title TextView.
|
|
|
|
mTabsPaneWidth = 0;
|
|
|
|
|
2012-11-15 21:40:57 -08:00
|
|
|
mTitle = (GeckoTextView) mLayout.findViewById(R.id.awesome_bar_title);
|
2012-08-23 11:27:11 -07:00
|
|
|
mTitlePadding = mTitle.getPaddingRight();
|
|
|
|
if (Build.VERSION.SDK_INT >= 16)
|
|
|
|
mTitle.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
|
|
|
|
2012-10-12 04:57:07 -07:00
|
|
|
mAwesomeBar = mLayout.findViewById(R.id.awesome_bar);
|
2011-11-18 10:28:17 -08:00
|
|
|
mAwesomeBar.setOnClickListener(new Button.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.autoHideTabs();
|
2011-11-18 10:28:17 -08:00
|
|
|
onAwesomeBarSearch();
|
|
|
|
}
|
|
|
|
});
|
2012-06-07 10:13:36 -07:00
|
|
|
mAwesomeBar.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-11-15 23:59:25 -08:00
|
|
|
mTabs = (GeckoImageButton) mLayout.findViewById(R.id.tabs);
|
2011-11-18 10:28:17 -08:00
|
|
|
mTabs.setOnClickListener(new Button.OnClickListener() {
|
|
|
|
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-11-15 23:59:25 -08:00
|
|
|
mTabsCount = (GeckoTextSwitcher) mLayout.findViewById(R.id.tabs_count);
|
2011-12-07 15:12:51 -08:00
|
|
|
mTabsCount.removeAllViews();
|
2012-05-25 15:10:26 -07:00
|
|
|
mTabsCount.setFactory(this);
|
2012-06-07 21:47:22 -07:00
|
|
|
mTabsCount.setText("");
|
2011-12-07 15:12:51 -08:00
|
|
|
mCount = 0;
|
2012-08-24 06:52:24 -07:00
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
|
|
// This adds the TextSwitcher to the a11y node tree, where we in turn
|
|
|
|
// could make it return an empty info node. If we don't do this the
|
|
|
|
// TextSwitcher's child TextViews get picked up, and we don't want
|
|
|
|
// that since the tabs ImageButton is already properly labeled for
|
|
|
|
// accessibility.
|
|
|
|
mTabsCount.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
|
|
|
|
mTabsCount.setAccessibilityDelegate(new View.AccessibilityDelegate() {
|
|
|
|
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {}
|
|
|
|
});
|
|
|
|
}
|
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() {
|
|
|
|
public void onClick(View view) {
|
|
|
|
Tabs.getInstance().getSelectedTab().doBack();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mForward = (ImageButton) mLayout.findViewById(R.id.forward);
|
|
|
|
mForward.setOnClickListener(new Button.OnClickListener() {
|
|
|
|
public void onClick(View view) {
|
|
|
|
Tabs.getInstance().getSelectedTab().doForward();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
Button.OnClickListener faviconListener = new Button.OnClickListener() {
|
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() {
|
|
|
|
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() {
|
|
|
|
public void onClick(View view) {
|
2012-06-20 11:10:08 -07:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.readerMode();
|
2012-06-02 11:23:45 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-20 17:23:06 -07:00
|
|
|
mShadow = (ImageView) mLayout.findViewById(R.id.shadow);
|
2011-12-15 11:53:04 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
mHandler = new Handler();
|
2012-01-27 11:19:13 -08:00
|
|
|
mSlideUpIn = new TranslateAnimation(0, 0, 40, 0);
|
|
|
|
mSlideUpOut = new TranslateAnimation(0, 0, 0, -40);
|
|
|
|
mSlideDownIn = new TranslateAnimation(0, 0, -40, 0);
|
|
|
|
mSlideDownOut = new TranslateAnimation(0, 0, 0, 40);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
mDuration = 750;
|
|
|
|
mSlideUpIn.setDuration(mDuration);
|
|
|
|
mSlideUpOut.setDuration(mDuration);
|
|
|
|
mSlideDownIn.setDuration(mDuration);
|
|
|
|
mSlideDownOut.setDuration(mDuration);
|
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);
|
2012-05-31 16:01:50 -07:00
|
|
|
mActionItemBar = (LinearLayout) mLayout.findViewById(R.id.menu_items);
|
2012-07-27 23:15:39 -07:00
|
|
|
mHasSoftMenuButton = !mActivity.hasPermanentMenuKey();
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
if (mHasSoftMenuButton) {
|
|
|
|
mMenu.setVisibility(View.VISIBLE);
|
|
|
|
mMenu.setOnClickListener(new Button.OnClickListener() {
|
|
|
|
public void onClick(View view) {
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.openOptionsMenu();
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
});
|
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;
|
|
|
|
Rect bounds = new Rect(width - tail, 0, width, height);
|
|
|
|
mTabs.setTouchDelegate(new TailTouchDelegate(bounds, mMenu));
|
|
|
|
}
|
|
|
|
});
|
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() {
|
|
|
|
public void onDismiss() {
|
|
|
|
mActivity.onOptionsMenuClosed(null);
|
|
|
|
}
|
|
|
|
});
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-10 16:10:15 -07:00
|
|
|
|
|
|
|
mFocusOrder = Arrays.asList(mBack, mForward, mAwesomeBar, 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;
|
|
|
|
}
|
|
|
|
|
2012-10-31 22:12:02 -07:00
|
|
|
public void refreshBackground() {
|
|
|
|
mAddressBarBg.requestLayout();
|
|
|
|
|
|
|
|
if (mAwesomeBarRightEdge != null)
|
|
|
|
mAwesomeBarRightEdge.requestLayout();
|
2012-06-07 21:47:22 -07:00
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
setTitle(tab.getDisplayTitle());
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RESTORED:
|
2012-11-07 18:34:54 -08:00
|
|
|
updateTabCount(Tabs.getInstance().getCount());
|
|
|
|
break;
|
2012-06-11 15:18:40 -07:00
|
|
|
case SELECTED:
|
2012-09-07 12:11:42 -07:00
|
|
|
mAnimateSiteSecurity = false;
|
|
|
|
// fall through
|
2012-06-11 15:18:40 -07:00
|
|
|
case LOCATION_CHANGE:
|
|
|
|
case LOAD_ERROR:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
refresh();
|
|
|
|
}
|
2012-09-07 12:11:42 -07:00
|
|
|
mAnimateSiteSecurity = true;
|
2012-06-11 15:18:40 -07:00
|
|
|
break;
|
|
|
|
case CLOSED:
|
|
|
|
case ADDED:
|
|
|
|
updateTabCountAndAnimate(Tabs.getInstance().getCount());
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animation animation) {
|
|
|
|
if (animation.equals(mLockFadeIn)) {
|
|
|
|
if (mSiteSecurityVisible)
|
|
|
|
mSiteSecurity.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationRepeat(Animation animation) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animation animation) {
|
|
|
|
if (animation.equals(mTitleSlideLeft)) {
|
|
|
|
mSiteSecurity.setVisibility(View.GONE);
|
|
|
|
} else if (animation.equals(mTitleSlideRight)) {
|
|
|
|
mSiteSecurity.startAnimation(mLockFadeIn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 15:10:26 -07:00
|
|
|
@Override
|
|
|
|
public View makeView() {
|
|
|
|
// This returns a TextView for the TextSwitcher.
|
|
|
|
return mInflater.inflate(R.layout.tabs_counter, null);
|
|
|
|
}
|
|
|
|
|
2012-12-03 02:50:41 -08:00
|
|
|
public void fromAwesomeBarSearch() {
|
|
|
|
if (mActivity.hasTabsSideBar() || Build.VERSION.SDK_INT < 11) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore opacity of content elements in the toolbar immediatelly
|
|
|
|
// so that the response is immediate from user interaction in the
|
|
|
|
// awesome screen.
|
|
|
|
AnimatorProxy proxy = AnimatorProxy.create(mFavicon);
|
|
|
|
proxy.setAlpha(1);
|
|
|
|
proxy = AnimatorProxy.create(mSiteSecurity);
|
|
|
|
proxy.setAlpha(1);
|
|
|
|
proxy = AnimatorProxy.create(mTitle);
|
|
|
|
proxy.setAlpha(1);
|
|
|
|
proxy = AnimatorProxy.create(mForward);
|
|
|
|
proxy.setAlpha(1);
|
|
|
|
proxy = AnimatorProxy.create(mBack);
|
|
|
|
proxy.setAlpha(1);
|
|
|
|
|
|
|
|
final PropertyAnimator contentAnimator = new PropertyAnimator(250);
|
|
|
|
|
|
|
|
// Shrink the awesome entry back to its original size
|
|
|
|
contentAnimator.attach(mAwesomeBarRightEdge,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mTabs,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mTabsCount,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mActionItemBar,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
0);
|
|
|
|
|
|
|
|
contentAnimator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
mTabs.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
// Turn off selected state on the entry
|
|
|
|
mAwesomeBar.setSelected(false);
|
|
|
|
|
|
|
|
// Restore entry state
|
|
|
|
MarginLayoutParams entryParams = (MarginLayoutParams) mAwesomeBarEntry.getLayoutParams();
|
|
|
|
entryParams.rightMargin = mAwesomeBarEntryRightMargin;
|
|
|
|
mAwesomeBarEntry.requestLayout();
|
|
|
|
|
|
|
|
// Restore the background state
|
|
|
|
MarginLayoutParams barParams = (MarginLayoutParams) mAddressBarBg.getLayoutParams();
|
|
|
|
barParams.rightMargin = mAddressBarBgRightMargin;
|
|
|
|
mAddressBarBg.setCurveTowards(mAddressBarBgCurveTowards);
|
|
|
|
mAddressBarBg.requestLayout();
|
|
|
|
|
|
|
|
// If there are action bar items in the toolbar, we have to restore the
|
|
|
|
// alignment of the entry in relation to them.
|
|
|
|
if (mActionItemBar.getVisibility() == View.VISIBLE)
|
|
|
|
((View) mAwesomeBar.getParent()).setLayoutParams(mAwesomeBarParams);
|
|
|
|
|
|
|
|
// Hide fake right edge, we only use for the animation
|
|
|
|
mAwesomeBarRightEdge.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
|
PropertyAnimator buttonsAnimator = new PropertyAnimator(150);
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
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
|
|
|
|
if (mActivity.hasTabsSideBar() || Build.VERSION.SDK_INT < 11) {
|
|
|
|
mActivity.onSearchRequested();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final PropertyAnimator contentAnimator = new PropertyAnimator(250);
|
|
|
|
|
|
|
|
// Keep the entry highlighted during the animation
|
|
|
|
mAwesomeBar.setSelected(true);
|
|
|
|
|
|
|
|
// Expand the entry to fill all the horizontal space available during the
|
|
|
|
// animation. The fake right edge will slide on top of it to give the effect
|
|
|
|
// of expanding the entry.
|
|
|
|
MarginLayoutParams entryParams = (MarginLayoutParams) mAwesomeBarEntry.getLayoutParams();
|
|
|
|
mAwesomeBarEntryRightMargin = entryParams.rightMargin;
|
|
|
|
entryParams.rightMargin = 0;
|
|
|
|
mAwesomeBarEntry.requestLayout();
|
|
|
|
|
|
|
|
// Remove any curves from the toolbar background and expand it to fill all
|
|
|
|
// the horizontal space.
|
|
|
|
MarginLayoutParams barParams = (MarginLayoutParams) mAddressBarBg.getLayoutParams();
|
|
|
|
mAddressBarBgRightMargin = barParams.rightMargin;
|
|
|
|
barParams.rightMargin = 0;
|
|
|
|
mAddressBarBgCurveTowards = mAddressBarBg.getCurveTowards();
|
|
|
|
mAddressBarBg.setCurveTowards(BrowserToolbarBackground.CurveTowards.NONE);
|
|
|
|
mAddressBarBg.requestLayout();
|
|
|
|
|
|
|
|
// If we don't have any menu_items, then we simply slide all elements on the
|
|
|
|
// rigth side of the toolbar out of screen.
|
|
|
|
int translation = mAwesomeBarEntryRightMargin;
|
|
|
|
|
|
|
|
if (mActionItemBar.getVisibility() == View.VISIBLE) {
|
|
|
|
// If the toolbar has action items (e.g. on the tablet UI), the translation will
|
|
|
|
// be in relation to the left side of their container (i.e. mActionItemBar).
|
|
|
|
MarginLayoutParams itemBarParams = (MarginLayoutParams) mActionItemBar.getLayoutParams();
|
|
|
|
translation = itemBarParams.rightMargin + mActionItemBar.getWidth() - entryParams.leftMargin;
|
|
|
|
|
|
|
|
// Expand the whole entry container to fill all the horizontal space available
|
|
|
|
View awesomeBarParent = (View) mAwesomeBar.getParent();
|
|
|
|
mAwesomeBarParams = (LayoutParams) awesomeBarParent.getLayoutParams();
|
|
|
|
awesomeBarParent.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
|
|
|
|
// Align the fake right edge to the right side of the entry bar
|
|
|
|
MarginLayoutParams rightEdgeParams = (MarginLayoutParams) mAwesomeBarRightEdge.getLayoutParams();
|
|
|
|
rightEdgeParams.rightMargin = itemBarParams.rightMargin + mActionItemBar.getWidth() - 100;
|
|
|
|
mAwesomeBarRightEdge.requestLayout();
|
|
|
|
|
|
|
|
contentAnimator.attach(mFavicon,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mSiteSecurity,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mTitle,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make the right edge visible to start the animation
|
|
|
|
mAwesomeBarRightEdge.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
// Fade out all controls inside the toolbar
|
|
|
|
contentAnimator.attach(mForward,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mBack,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mReader,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
contentAnimator.attach(mStop,
|
|
|
|
PropertyAnimator.Property.ALPHA,
|
|
|
|
0);
|
|
|
|
|
|
|
|
// Slide the right side elements of the toolbar
|
|
|
|
contentAnimator.attach(mAwesomeBarRightEdge,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translation);
|
|
|
|
contentAnimator.attach(mTabs,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translation);
|
|
|
|
contentAnimator.attach(mTabsCount,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translation);
|
|
|
|
contentAnimator.attach(mMenu,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translation);
|
|
|
|
contentAnimator.attach(mActionItemBar,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
translation);
|
|
|
|
|
|
|
|
contentAnimator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() {
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
|
|
|
mTabs.setVisibility(View.INVISIBLE);
|
|
|
|
|
|
|
|
// Once the entry is fully expanded, start awesome screen
|
|
|
|
mActivity.onSearchRequested();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
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-07-27 23:15:39 -07:00
|
|
|
mActivity.showLocalTabs();
|
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) {
|
2011-11-18 10:28:17 -08:00
|
|
|
if (mCount > count) {
|
|
|
|
mTabsCount.setInAnimation(mSlideDownIn);
|
|
|
|
mTabsCount.setOutAnimation(mSlideDownOut);
|
|
|
|
} else if (mCount < count) {
|
|
|
|
mTabsCount.setInAnimation(mSlideUpIn);
|
|
|
|
mTabsCount.setOutAnimation(mSlideUpOut);
|
2012-06-07 21:47:22 -07:00
|
|
|
} else {
|
|
|
|
return;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
mTabsCount.setText(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));
|
2011-11-18 10:28:17 -08:00
|
|
|
mCount = count;
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
public void run() {
|
2012-11-15 23:59:25 -08:00
|
|
|
GeckoTextView view = (GeckoTextView) mTabsCount.getCurrentView();
|
|
|
|
view.setSelected(true);
|
|
|
|
view.setPrivateMode(false);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}, mDuration);
|
|
|
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
public void run() {
|
2012-11-15 23:59:25 -08:00
|
|
|
GeckoTextView view = (GeckoTextView) mTabsCount.getCurrentView();
|
|
|
|
view.setSelected(false);
|
|
|
|
view.setPrivateMode(Tabs.getInstance().getSelectedTab().isPrivate());
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}, 2 * mDuration);
|
|
|
|
}
|
|
|
|
|
2012-02-01 14:25:50 -08:00
|
|
|
public void updateTabCount(int count) {
|
|
|
|
mTabsCount.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));
|
2012-06-07 21:47:22 -07:00
|
|
|
mCount = count;
|
2012-07-27 23:15:39 -07:00
|
|
|
updateTabs(mActivity.areTabsShown());
|
2012-06-07 21:47:22 -07:00
|
|
|
}
|
|
|
|
|
2012-10-12 04:57:07 -07:00
|
|
|
public void prepareTabsAnimation(PropertyAnimator animator, int width) {
|
|
|
|
// This is negative before we want to keep the right edge in the same
|
|
|
|
// position while animating the left-most elements below.
|
|
|
|
animator.attach(mAwesomeBarRightEdge,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
-width);
|
|
|
|
|
|
|
|
animator.attach(mAwesomeBar,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mAddressBarBg,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mTabs,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mTabsCount,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mBack,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mForward,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mTitle,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mFavicon,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
animator.attach(mSiteSecurity,
|
|
|
|
PropertyAnimator.Property.TRANSLATION_X,
|
|
|
|
width);
|
|
|
|
|
2012-10-31 22:07:49 -07:00
|
|
|
// Uses the old mTabsPaneWidth.
|
|
|
|
adjustTabsAnimation(false);
|
|
|
|
|
2012-10-12 04:57:07 -07:00
|
|
|
mTabsPaneWidth = width;
|
|
|
|
|
|
|
|
// Only update title padding immediatelly when shrinking the browser
|
|
|
|
// toolbar. Leave the padding update to the end of the animation when
|
|
|
|
// expanding (see finishTabsAnimation()).
|
|
|
|
if (mTabsPaneWidth > 0)
|
|
|
|
setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2012-10-31 22:07:49 -07:00
|
|
|
public void adjustTabsAnimation(boolean reset) {
|
|
|
|
int width = reset ? 0 : mTabsPaneWidth;
|
|
|
|
mAwesomeBarRightEdge.setTranslationX(-width);
|
|
|
|
mAwesomeBar.setTranslationX(width);
|
|
|
|
mAddressBarBg.setTranslationX(width);
|
|
|
|
mTabs.setTranslationX(width);
|
|
|
|
mTabsCount.setTranslationX(width);
|
|
|
|
mBack.setTranslationX(width);
|
|
|
|
mForward.setTranslationX(width);
|
|
|
|
mTitle.setTranslationX(width);
|
|
|
|
mFavicon.setTranslationX(width);
|
|
|
|
mSiteSecurity.setTranslationX(width);
|
|
|
|
|
|
|
|
((ViewGroup.MarginLayoutParams) mLayout.getLayoutParams()).leftMargin = reset ? mTabsPaneWidth : 0;
|
|
|
|
}
|
|
|
|
|
2012-10-12 04:57:07 -07:00
|
|
|
public void finishTabsAnimation() {
|
|
|
|
setPageActionVisibility(mStop.getVisibility() == View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2012-06-07 21:47:22 -07:00
|
|
|
public void updateTabs(boolean areTabsShown) {
|
2012-06-14 11:14:00 -07:00
|
|
|
if (areTabsShown) {
|
|
|
|
mTabs.getBackground().setLevel(TABS_EXPANDED);
|
2012-07-09 13:21:20 -07:00
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
if (!mActivity.hasTabsSideBar()) {
|
2012-07-09 13:21:20 -07:00
|
|
|
mTabs.setImageLevel(0);
|
|
|
|
mTabsCount.setVisibility(View.GONE);
|
|
|
|
mMenu.setImageLevel(TABS_EXPANDED);
|
|
|
|
mMenu.getBackground().setLevel(TABS_EXPANDED);
|
|
|
|
} else {
|
|
|
|
mTabs.setImageLevel(TABS_EXPANDED);
|
|
|
|
}
|
2012-06-14 11:14:00 -07:00
|
|
|
} else {
|
2012-06-07 21:47:22 -07:00
|
|
|
mTabs.setImageLevel(TABS_CONTRACTED);
|
2012-06-14 11:14:00 -07:00
|
|
|
mTabs.getBackground().setLevel(TABS_CONTRACTED);
|
2012-07-09 13:21:20 -07:00
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
if (!mActivity.hasTabsSideBar()) {
|
2012-07-09 13:21:20 -07:00
|
|
|
mTabsCount.setVisibility(View.VISIBLE);
|
|
|
|
mMenu.setImageLevel(TABS_CONTRACTED);
|
|
|
|
mMenu.getBackground().setLevel(TABS_CONTRACTED);
|
|
|
|
}
|
2012-06-14 11:14:00 -07:00
|
|
|
}
|
2012-10-31 22:07:49 -07:00
|
|
|
|
|
|
|
// A level change will not trigger onMeasure() for the tabs, where the path is created.
|
|
|
|
// Manually requesting a layout to re-calculate the path.
|
|
|
|
mTabs.requestLayout();
|
2012-02-01 14:25:50 -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);
|
2012-07-13 08:36:45 -07:00
|
|
|
mReader.setVisibility(mShowReader && !isLoading ? 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.
|
2012-10-31 22:07:49 -07:00
|
|
|
mTitle.setPadding(0, 0, (!mShowReader && !isLoading ? 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;
|
|
|
|
|
2012-09-07 12:11:42 -07:00
|
|
|
if (!mAnimateSiteSecurity) {
|
|
|
|
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();
|
|
|
|
|
|
|
|
if (visible)
|
|
|
|
mSiteSecurity.setVisibility(View.INVISIBLE);
|
|
|
|
else
|
|
|
|
mSiteSecurity.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Only set shadow to visible when not on about screens.
|
|
|
|
visible &= !(url == null || url.startsWith("about:"));
|
|
|
|
|
|
|
|
if ((mShadow.getVisibility() == View.VISIBLE) != visible) {
|
|
|
|
mShadow.setVisibility(visible ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
2011-12-15 11:53:04 -08:00
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public 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
|
|
|
|
2012-09-11 10:51:44 -07:00
|
|
|
// Keep the title unchanged if the tab is entering reader mode
|
|
|
|
if (tab != null && tab.isEnteringReaderMode())
|
|
|
|
return;
|
|
|
|
|
2012-01-17 14:57:21 -08:00
|
|
|
// Setting a null title for about:home will ensure we just see
|
|
|
|
// the "Enter Search or Address" placeholder text
|
2012-03-05 13:20:04 -08:00
|
|
|
if (tab != null && "about:home".equals(tab.getURL()))
|
2012-01-17 14:57:21 -08:00
|
|
|
title = null;
|
2012-03-16 09:29:37 -07:00
|
|
|
|
2012-08-23 11:27:11 -07:00
|
|
|
mTitle.setText(title);
|
|
|
|
mAwesomeBar.setContentDescription(title != null ? title : mTitle.getHint());
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-11-05 03:42:25 -08:00
|
|
|
public 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
|
|
|
}
|
|
|
|
|
|
|
|
public 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
|
|
|
|
2012-07-13 08:36:45 -07:00
|
|
|
public 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() {
|
|
|
|
mLayout.requestFocusFromTouch();
|
|
|
|
}
|
|
|
|
|
2012-05-24 15:47:49 -07:00
|
|
|
public void updateBackButton(boolean enabled) {
|
|
|
|
mBack.setColorFilter(enabled ? 0 : 0xFF999999);
|
|
|
|
mBack.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateForwardButton(boolean enabled) {
|
|
|
|
mForward.setColorFilter(enabled ? 0 : 0xFF999999);
|
|
|
|
mForward.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
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();
|
2012-01-30 15:10:16 -08:00
|
|
|
setTitle(tab.getDisplayTitle());
|
|
|
|
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-02-07 11:37:36 -08:00
|
|
|
updateTabCount(Tabs.getInstance().getCount());
|
2012-05-24 15:47:49 -07:00
|
|
|
updateBackButton(tab.canDoBack());
|
|
|
|
updateForwardButton(tab.canDoForward());
|
2012-10-09 11:26:33 -07:00
|
|
|
|
2012-11-15 21:28:38 -08:00
|
|
|
mAddressBarBg.setPrivateMode(tab.isPrivate());
|
|
|
|
|
2012-11-15 21:40:57 -08:00
|
|
|
if (mAwesomeBar instanceof GeckoButton)
|
|
|
|
((GeckoButton) mAwesomeBar).setPrivateMode(tab.isPrivate());
|
|
|
|
else if (mAwesomeBar instanceof GeckoRelativeLayout)
|
|
|
|
((GeckoRelativeLayout) mAwesomeBar).setPrivateMode(tab.isPrivate());
|
|
|
|
|
2012-11-15 23:59:25 -08:00
|
|
|
mTabs.setPrivateMode(tab.isPrivate());
|
|
|
|
mTabsCount.setPrivateMode(tab.isPrivate());
|
|
|
|
((GeckoTextView) mTabsCount.getCurrentView()).setPrivateMode(tab.isPrivate());
|
2012-11-15 21:40:57 -08:00
|
|
|
mTitle.setPrivateMode(tab.isPrivate());
|
2012-11-16 00:21:46 -08:00
|
|
|
mMenu.setPrivateMode(tab.isPrivate());
|
2012-11-30 13:22:49 -08:00
|
|
|
|
|
|
|
if (mBack instanceof BackButton)
|
|
|
|
((BackButton) mBack).setPrivateMode(tab.isPrivate());
|
|
|
|
|
|
|
|
if (mForward instanceof ForwardButton)
|
|
|
|
((ForwardButton) mForward).setPrivateMode(tab.isPrivate());
|
2012-11-15 21:28:38 -08:00
|
|
|
}
|
2012-11-28 18:55:05 -08:00
|
|
|
}
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
public void destroy() {
|
|
|
|
// The action-items views are reused on rotation.
|
|
|
|
// Remove them from their parent, so they can be re-attached to new parent.
|
|
|
|
mActionItemBar.removeAllViews();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-15 21:28:38 -08:00
|
|
|
public static class RightEdge extends GeckoFrameLayout
|
2012-10-31 22:12:02 -07:00
|
|
|
implements LightweightTheme.OnChangeListener {
|
|
|
|
private BrowserApp mActivity;
|
|
|
|
|
|
|
|
public RightEdge(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
mActivity = (BrowserApp) context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
mActivity.getLightweightTheme().addListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
mActivity.getLightweightTheme().removeListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLightweightThemeChanged() {
|
|
|
|
Drawable drawable = mActivity.getLightweightTheme().getDrawable(this);
|
|
|
|
if (drawable == null)
|
|
|
|
return;
|
|
|
|
|
2012-11-15 21:28:38 -08:00
|
|
|
StateListDrawable stateList = new StateListDrawable();
|
|
|
|
stateList.addState(new int[] { R.attr.state_private }, mActivity.getResources().getDrawable(R.drawable.address_bar_bg_private));
|
|
|
|
stateList.addState(new int[] {}, drawable);
|
|
|
|
|
2012-10-31 22:12:02 -07:00
|
|
|
int[] padding = new int[] { getPaddingLeft(),
|
|
|
|
getPaddingTop(),
|
|
|
|
getPaddingRight(),
|
|
|
|
getPaddingBottom()
|
|
|
|
};
|
2012-11-15 21:28:38 -08:00
|
|
|
setBackgroundDrawable(stateList);
|
2012-10-31 22:12:02 -07:00
|
|
|
setPadding(padding[0], padding[1], padding[2], padding[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLightweightThemeReset() {
|
|
|
|
int[] padding = new int[] { getPaddingLeft(),
|
|
|
|
getPaddingTop(),
|
|
|
|
getPaddingRight(),
|
|
|
|
getPaddingBottom()
|
|
|
|
};
|
|
|
|
setBackgroundResource(R.drawable.address_bar_bg);
|
|
|
|
setPadding(padding[0], padding[1], padding[2], padding[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
onLightweightThemeChanged();
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|