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;
|
|
|
|
import android.graphics.Color;
|
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;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.graphics.drawable.Drawable;
|
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;
|
2012-08-19 21:45:37 -07:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.TouchDelegate;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.view.View;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
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;
|
2012-08-23 11:27:11 -07:00
|
|
|
import android.widget.FrameLayout;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.LinearLayout;
|
2012-05-31 16:01:50 -07:00
|
|
|
import android.widget.PopupWindow;
|
|
|
|
import android.widget.RelativeLayout;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.TextSwitcher;
|
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;
|
|
|
|
private View mAwesomeBarRightEdge;
|
|
|
|
private View mAddressBarBg;
|
2012-08-23 11:27:11 -07:00
|
|
|
private TextView mTitle;
|
|
|
|
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;
|
2011-12-07 15:12:51 -08:00
|
|
|
private ImageButton mTabs;
|
2012-10-12 04:57:07 -07:00
|
|
|
private int mTabsPaneWidth;
|
2012-05-24 15:47:49 -07:00
|
|
|
private ImageView mBack;
|
|
|
|
private ImageView 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;
|
|
|
|
private TextSwitcher mTabsCount;
|
2011-12-15 11:53:04 -08:00
|
|
|
private ImageView mShadow;
|
2012-05-31 16:01:50 -07:00
|
|
|
private ImageButton mMenu;
|
|
|
|
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) {
|
|
|
|
mLayout = layout;
|
2012-06-02 11:23:45 -07:00
|
|
|
|
|
|
|
mShowSiteSecurity = false;
|
|
|
|
mShowReader = false;
|
2012-01-27 12:28:45 -08:00
|
|
|
|
2012-10-12 04:57:07 -07:00
|
|
|
// Only used on tablet layout. We need a separate view for the background
|
|
|
|
// because we need to slide it left/right for hiding/shoing the tabs sidebar
|
|
|
|
// See prepareTabsAnimation().
|
|
|
|
mAddressBarBg = mLayout.findViewById(R.id.address_bar_bg);
|
|
|
|
|
|
|
|
// Only used on tablet layout. The tabs sidebar slide animation is implemented
|
|
|
|
// in terms of translating the inner elements of the tablet toolbar to give the
|
|
|
|
// impression of resizing. In order to do this, This "fake" right edge is kept
|
|
|
|
// in the same position during the animation while the elements on the left
|
|
|
|
// (favicon, back, forware, lock icon, title, ...) slide behind it.
|
|
|
|
// See prepareTabsAnimation().
|
|
|
|
mAwesomeBarRightEdge = mLayout.findViewById(R.id.awesome_bar_right_edge);
|
|
|
|
|
|
|
|
// 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-08-23 11:27:11 -07:00
|
|
|
mTitle = (TextView) mLayout.findViewById(R.id.awesome_bar_title);
|
|
|
|
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-03-20 17:23:06 -07:00
|
|
|
mTabs = (ImageButton) 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-03-20 17:23:06 -07:00
|
|
|
mTabsCount = (TextSwitcher) 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();
|
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-05-31 16:01:50 -07:00
|
|
|
mMenu = (ImageButton) mLayout.findViewById(R.id.menu);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private void onAwesomeBarSearch() {
|
2012-07-27 23:15:39 -07:00
|
|
|
mActivity.onSearchRequested();
|
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-07-27 23:15:39 -07:00
|
|
|
((TextView) mTabsCount.getCurrentView()).setTextColor(mActivity.getResources().getColor(R.color.url_bar_text_highlight));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}, mDuration);
|
|
|
|
|
|
|
|
mHandler.postDelayed(new Runnable() {
|
|
|
|
public void run() {
|
2012-07-27 23:15:39 -07:00
|
|
|
((TextView) mTabsCount.getCurrentView()).setTextColor(mActivity.getResources().getColor(R.color.tabs_counter_color));
|
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) {
|
|
|
|
mShadow.setVisibility(visible ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
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-11-06 19:51:06 -08:00
|
|
|
if (image != null) {
|
|
|
|
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 setVisibility(int visibility) {
|
|
|
|
mLayout.setVisibility(visibility);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-05 13:20:04 -08:00
|
|
|
setShadowVisibility((url == null) || !url.startsWith("about:"));
|
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
|
|
|
updateBackgroundColor(tab.isPrivate() ? 1 : 0);
|
2012-01-30 15:10:16 -08:00
|
|
|
}
|
|
|
|
}
|
2012-05-31 16:01:50 -07:00
|
|
|
|
2012-10-09 11:26:33 -07:00
|
|
|
private void updateBackgroundColor(int level) {
|
|
|
|
mAwesomeBar.getBackground().setLevel(level);
|
|
|
|
}
|
|
|
|
|
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-10-31 22:12:02 -07:00
|
|
|
public static class RightEdge extends FrameLayout
|
|
|
|
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;
|
|
|
|
|
|
|
|
int[] padding = new int[] { getPaddingLeft(),
|
|
|
|
getPaddingTop(),
|
|
|
|
getPaddingRight(),
|
|
|
|
getPaddingBottom()
|
|
|
|
};
|
|
|
|
setBackgroundDrawable(drawable);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
// MenuPopup holds the MenuPanel in Honeycomb/ICS devices with no hardware key
|
2012-09-19 10:35:35 -07:00
|
|
|
public static class MenuPopup extends PopupWindow {
|
2012-05-31 16:01:50 -07:00
|
|
|
private RelativeLayout mPanel;
|
2012-09-19 14:41:14 -07:00
|
|
|
private int mYOffset;
|
2012-05-31 16:01:50 -07:00
|
|
|
|
|
|
|
public MenuPopup(Context context) {
|
|
|
|
super(context);
|
|
|
|
setFocusable(true);
|
|
|
|
|
2012-09-19 14:41:14 -07:00
|
|
|
// The arrow height is constant for both orientations.
|
|
|
|
mYOffset = (int) (context.getResources().getDimension(R.dimen.menu_popup_offset));
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
// Setting a null background makes the popup to not close on touching outside.
|
|
|
|
setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
2012-10-05 15:14:39 -07:00
|
|
|
setWindowLayoutMode(View.MeasureSpec.makeMeasureSpec(context.getResources().getDimensionPixelSize(R.dimen.menu_popup_width), View.MeasureSpec.AT_MOST),
|
2012-05-31 16:01:50 -07:00
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
|
|
|
LayoutInflater inflater = LayoutInflater.from(context);
|
|
|
|
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.menu_popup, null);
|
|
|
|
setContentView(layout);
|
|
|
|
|
|
|
|
mPanel = (RelativeLayout) layout.findViewById(R.id.menu_panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPanelView(View view) {
|
|
|
|
mPanel.removeAllViews();
|
|
|
|
mPanel.addView(view);
|
|
|
|
}
|
2012-09-19 14:41:14 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showAsDropDown(View anchor) {
|
|
|
|
showAsDropDown(anchor, 0, -mYOffset);
|
|
|
|
}
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
2012-08-19 21:45:37 -07:00
|
|
|
|
|
|
|
private class TailTouchDelegate extends TouchDelegate {
|
|
|
|
public TailTouchDelegate(Rect bounds, View delegateView) {
|
|
|
|
super(bounds, delegateView);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
switch (event.getAction()) {
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
// Android bug 36445: Touch Delegation not reset on ACTION_DOWN.
|
|
|
|
if (!super.onTouchEvent(event)) {
|
|
|
|
MotionEvent cancelEvent = MotionEvent.obtain(event);
|
|
|
|
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
|
|
|
|
super.onTouchEvent(cancelEvent);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|