blob: c8a4815641f03ea3f3a83e46f6d1c1e0ec6bb273 [file] [log] [blame]
Michael Kolba2b2ba82010-08-04 17:54:03 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolba2b2ba82010-08-04 17:54:03 -070018
Michael Kolb2d59c322011-01-25 13:18:55 -080019import android.animation.Animator;
20import android.animation.Animator.AnimatorListener;
21import android.animation.AnimatorSet;
22import android.animation.ObjectAnimator;
Michael Kolb8233fac2010-10-26 16:08:53 -070023import android.app.Activity;
Michael Kolba2b2ba82010-08-04 17:54:03 -070024import android.content.Context;
Michael Kolb678afc82011-05-17 14:52:41 -070025import android.content.res.Configuration;
Michael Kolba2b2ba82010-08-04 17:54:03 -070026import android.content.res.Resources;
27import android.graphics.Bitmap;
Michael Kolb2b5a13a2010-12-09 14:13:42 -080028import android.graphics.Canvas;
Michael Kolb467af0a2011-01-11 13:09:49 -080029import android.graphics.Matrix;
Michael Kolb2b5a13a2010-12-09 14:13:42 -080030import android.graphics.Paint;
31import android.graphics.Path;
Michael Kolba2b2ba82010-08-04 17:54:03 -070032import android.graphics.drawable.Drawable;
Michael Kolbed217742010-08-10 17:52:34 -070033import android.view.Gravity;
Michael Kolba2b2ba82010-08-04 17:54:03 -070034import android.view.LayoutInflater;
Michael Kolba2b2ba82010-08-04 17:54:03 -070035import android.view.View;
36import android.view.View.OnClickListener;
Michael Kolbed217742010-08-10 17:52:34 -070037import android.widget.ImageButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070038import android.widget.ImageView;
39import android.widget.LinearLayout;
40import android.widget.TextView;
41
Michael Kolba2b2ba82010-08-04 17:54:03 -070042import java.util.HashMap;
Michael Kolb1bf23132010-11-19 12:55:12 -080043import java.util.List;
Michael Kolba2b2ba82010-08-04 17:54:03 -070044import java.util.Map;
45
46/**
47 * tabbed title bar for xlarge screen browser
48 */
Michael Kolbb14ff2f2011-07-01 15:33:56 -070049public class TabBar extends LinearLayout implements OnClickListener {
Michael Kolba2b2ba82010-08-04 17:54:03 -070050
51 private static final int PROGRESS_MAX = 100;
52
Michael Kolb8233fac2010-10-26 16:08:53 -070053 private Activity mActivity;
54 private UiController mUiController;
55 private TabControl mTabControl;
Michael Kolb66706532010-12-12 19:50:22 -080056 private XLargeUi mUi;
Michael Kolba2b2ba82010-08-04 17:54:03 -070057
John Reck034637c2011-08-11 11:34:44 -070058 private int mTabWidth;
Michael Kolbed217742010-08-10 17:52:34 -070059
Michael Kolba2b2ba82010-08-04 17:54:03 -070060 private TabScrollView mTabs;
Michael Kolb8233fac2010-10-26 16:08:53 -070061
Michael Kolbebba8b42010-09-30 12:57:59 -070062 private ImageButton mNewTab;
63 private int mButtonWidth;
Michael Kolba2b2ba82010-08-04 17:54:03 -070064
Michael Kolb94827b62011-01-08 14:23:45 -080065 private Map<Tab, TabView> mTabMap;
Michael Kolba2b2ba82010-08-04 17:54:03 -070066
Romain Guyc8373212011-01-07 19:15:16 -080067 private int mCurrentTextureWidth = 0;
68 private int mCurrentTextureHeight = 0;
69
Enrico Ros1f5a0952014-11-18 20:15:48 -080070 ///private Drawable mActiveDrawable;
71 ///private Drawable mInactiveDrawable;
Michael Kolb2b5a13a2010-12-09 14:13:42 -080072
Romain Guyc8373212011-01-07 19:15:16 -080073 private final Paint mActiveShaderPaint = new Paint();
74 private final Paint mInactiveShaderPaint = new Paint();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -080075 private final Paint mFocusPaint = new Paint();
Romain Guyc8373212011-01-07 19:15:16 -080076 private final Matrix mActiveMatrix = new Matrix();
77 private final Matrix mInactiveMatrix = new Matrix();
78
Enrico Ros1f5a0952014-11-18 20:15:48 -080079 ///private BitmapShader mActiveShader;
80 ///private BitmapShader mInactiveShader;
Romain Guyc8373212011-01-07 19:15:16 -080081
Michael Kolb2b5a13a2010-12-09 14:13:42 -080082 private int mTabOverlap;
Michael Kolb5a72f182011-01-13 20:35:06 -080083 private int mAddTabOverlap;
Michael Kolb2b5a13a2010-12-09 14:13:42 -080084 private int mTabSliceWidth;
Michael Kolb2b5a13a2010-12-09 14:13:42 -080085
Michael Kolb66706532010-12-12 19:50:22 -080086 public TabBar(Activity activity, UiController controller, XLargeUi ui) {
Michael Kolb8233fac2010-10-26 16:08:53 -070087 super(activity);
88 mActivity = activity;
89 mUiController = controller;
90 mTabControl = mUiController.getTabControl();
91 mUi = ui;
92 Resources res = activity.getResources();
John Reck034637c2011-08-11 11:34:44 -070093 mTabWidth = (int) res.getDimension(R.dimen.tab_width);
Enrico Ros1f5a0952014-11-18 20:15:48 -080094 ///mActiveDrawable = res.getDrawable(R.drawable.bg_urlbar);
95 ///mInactiveDrawable = res.getDrawable(R.drawable.browsertab_inactive);
Michael Kolba2b2ba82010-08-04 17:54:03 -070096
Michael Kolb94827b62011-01-08 14:23:45 -080097 mTabMap = new HashMap<Tab, TabView>();
Michael Kolb8233fac2010-10-26 16:08:53 -070098 LayoutInflater factory = LayoutInflater.from(activity);
Michael Kolba2b2ba82010-08-04 17:54:03 -070099 factory.inflate(R.layout.tab_bar, this);
Michael Kolbf558f0d2011-01-13 19:24:18 -0800100 setPadding(0, (int) res.getDimension(R.dimen.tab_padding_top), 0, 0);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700101 mTabs = (TabScrollView) findViewById(R.id.tabs);
Michael Kolbebba8b42010-09-30 12:57:59 -0700102 mNewTab = (ImageButton) findViewById(R.id.newtab);
103 mNewTab.setOnClickListener(this);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700104
Michael Kolb1bf23132010-11-19 12:55:12 -0800105 updateTabs(mUiController.getTabs());
Michael Kolbebba8b42010-09-30 12:57:59 -0700106 mButtonWidth = -1;
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800107 // tab dimensions
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800108 mTabOverlap = (int) res.getDimension(R.dimen.tab_overlap);
Michael Kolb5a72f182011-01-13 20:35:06 -0800109 mAddTabOverlap = (int) res.getDimension(R.dimen.tab_addoverlap);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800110 mTabSliceWidth = (int) res.getDimension(R.dimen.tab_slice);
Romain Guyc8373212011-01-07 19:15:16 -0800111
112 mActiveShaderPaint.setStyle(Paint.Style.FILL);
113 mActiveShaderPaint.setAntiAlias(true);
114
115 mInactiveShaderPaint.setStyle(Paint.Style.FILL);
116 mInactiveShaderPaint.setAntiAlias(true);
Michael Kolbb4cafc52011-01-12 16:55:04 -0800117
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800118 mFocusPaint.setStyle(Paint.Style.STROKE);
Michael Kolbeb7001c2011-02-16 16:07:33 -0800119 mFocusPaint.setStrokeWidth(res.getDimension(R.dimen.tab_focus_stroke));
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800120 mFocusPaint.setAntiAlias(true);
121 mFocusPaint.setColor(res.getColor(R.color.tabFocusHighlight));
Michael Kolbebba8b42010-09-30 12:57:59 -0700122 }
123
Michael Kolb678afc82011-05-17 14:52:41 -0700124 @Override
125 public void onConfigurationChanged(Configuration config) {
126 super.onConfigurationChanged(config);
127 Resources res = mActivity.getResources();
John Reck034637c2011-08-11 11:34:44 -0700128 mTabWidth = (int) res.getDimension(R.dimen.tab_width);
Michael Kolb678afc82011-05-17 14:52:41 -0700129 // force update of tab bar
130 mTabs.updateLayout();
131 }
132
Michael Kolb376b5412010-12-15 11:52:57 -0800133 int getTabCount() {
134 return mTabMap.size();
135 }
136
Michael Kolb1bf23132010-11-19 12:55:12 -0800137 void updateTabs(List<Tab> tabs) {
138 mTabs.clearTabs();
139 mTabMap.clear();
140 for (Tab tab : tabs) {
Michael Kolb94827b62011-01-08 14:23:45 -0800141 TabView tv = buildTabView(tab);
Michael Kolb2d59c322011-01-25 13:18:55 -0800142 mTabs.addTab(tv);
Michael Kolb1bf23132010-11-19 12:55:12 -0800143 }
Michael Kolbc831b632011-05-11 09:30:34 -0700144 mTabs.setSelectedTab(mTabControl.getCurrentPosition());
Michael Kolb1bf23132010-11-19 12:55:12 -0800145 }
146
Michael Kolbebba8b42010-09-30 12:57:59 -0700147 @Override
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800148 protected void onMeasure(int hspec, int vspec) {
149 super.onMeasure(hspec, vspec);
150 int w = getMeasuredWidth();
151 // adjust for new tab overlap
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700152 w -= mAddTabOverlap;
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800153 setMeasuredDimension(w, getMeasuredHeight());
154 }
155
156 @Override
Michael Kolbebba8b42010-09-30 12:57:59 -0700157 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800158 // use paddingLeft and paddingTop
159 int pl = getPaddingLeft();
160 int pt = getPaddingTop();
Michael Kolbebba8b42010-09-30 12:57:59 -0700161 int sw = mTabs.getMeasuredWidth();
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800162 int w = right - left - pl;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700163 mButtonWidth = mNewTab.getMeasuredWidth() - mAddTabOverlap;
164 if (w-sw < mButtonWidth) {
165 sw = w - mButtonWidth;
Michael Kolbebba8b42010-09-30 12:57:59 -0700166 }
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800167 mTabs.layout(pl, pt, pl + sw, bottom - top);
168 // adjust for overlap
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700169 mNewTab.layout(pl + sw - mAddTabOverlap, pt,
170 pl + sw + mButtonWidth - mAddTabOverlap, bottom - top);
171
Michael Kolba2b2ba82010-08-04 17:54:03 -0700172 }
173
174 public void onClick(View view) {
Michael Kolbebba8b42010-09-30 12:57:59 -0700175 if (mNewTab == view) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700176 mUiController.openTabToHomePage();
Michael Kolbebba8b42010-09-30 12:57:59 -0700177 } else if (mTabs.getSelectedTab() == view) {
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700178 if (mUi.isTitleBarShowing() && !isLoading()) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800179 mUi.stopEditingUrl();
180 mUi.hideTitleBar();
Michael Kolbed217742010-08-10 17:52:34 -0700181 } else {
182 showUrlBar();
183 }
Michael Kolbc831b632011-05-11 09:30:34 -0700184 } else if (view instanceof TabView) {
185 final Tab tab = ((TabView) view).mTab;
Michael Kolbebba8b42010-09-30 12:57:59 -0700186 int ix = mTabs.getChildIndex(view);
187 if (ix >= 0) {
188 mTabs.setSelectedTab(ix);
Michael Kolbc831b632011-05-11 09:30:34 -0700189 mUiController.switchToTab(tab);
Michael Kolbebba8b42010-09-30 12:57:59 -0700190 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700191 }
192 }
193
Michael Kolbed217742010-08-10 17:52:34 -0700194 private void showUrlBar() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700195 mUi.stopWebViewScrolling();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800196 mUi.showTitleBar();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700197 }
198
Michael Kolb94827b62011-01-08 14:23:45 -0800199 private TabView buildTabView(Tab tab) {
200 TabView tabview = new TabView(mActivity, tab);
201 mTabMap.put(tab, tabview);
202 tabview.setOnClickListener(this);
Michael Kolb94827b62011-01-08 14:23:45 -0800203 return tabview;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700204 }
205
Romain Guyc8373212011-01-07 19:15:16 -0800206 private static Bitmap getDrawableAsBitmap(Drawable drawable, int width, int height) {
207 Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
208 Canvas c = new Canvas(b);
209 drawable.setBounds(0, 0, width, height);
210 drawable.draw(c);
Dianne Hackborn43cfe8a2011-08-02 16:59:35 -0700211 c.setBitmap(null);
Romain Guyc8373212011-01-07 19:15:16 -0800212 return b;
Michael Kolbb4cafc52011-01-12 16:55:04 -0800213 }
214
Michael Kolba2b2ba82010-08-04 17:54:03 -0700215 /**
216 * View used in the tab bar
217 */
218 class TabView extends LinearLayout implements OnClickListener {
219
Michael Kolb94827b62011-01-08 14:23:45 -0800220 Tab mTab;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700221 View mTabContent;
222 TextView mTitle;
Michael Kolbae62fd42010-08-18 16:33:28 -0700223 View mIncognito;
John Reck541f55a2011-06-07 16:34:43 -0700224 View mSnapshot;
Enrico Ros1f5a0952014-11-18 20:15:48 -0800225 ImageView mFaviconView;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700226 ImageView mLock;
227 ImageView mClose;
228 boolean mSelected;
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800229 Path mPath;
Michael Kolbeb7001c2011-02-16 16:07:33 -0800230 Path mFocusPath;
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800231 int[] mWindowPos;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700232
233 /**
234 * @param context
235 */
Michael Kolb94827b62011-01-08 14:23:45 -0800236 public TabView(Context context, Tab tab) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700237 super(context);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800238 setWillNotDraw(false);
239 mPath = new Path();
Michael Kolbeb7001c2011-02-16 16:07:33 -0800240 mFocusPath = new Path();
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800241 mWindowPos = new int[2];
Michael Kolb94827b62011-01-08 14:23:45 -0800242 mTab = tab;
Michael Kolbed217742010-08-10 17:52:34 -0700243 setGravity(Gravity.CENTER_VERTICAL);
244 setOrientation(LinearLayout.HORIZONTAL);
Michael Kolb49f15832011-01-25 15:02:27 -0800245 setPadding(mTabOverlap, 0, mTabSliceWidth, 0);
Bjorn Bringertb1402a52010-10-12 10:53:12 +0100246 LayoutInflater inflater = LayoutInflater.from(getContext());
Michael Kolbed217742010-08-10 17:52:34 -0700247 mTabContent = inflater.inflate(R.layout.tab_title, this, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700248 mTitle = (TextView) mTabContent.findViewById(R.id.title);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800249 mFaviconView = (ImageView) mTabContent.findViewById(R.id.favicon);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700250 mLock = (ImageView) mTabContent.findViewById(R.id.lock);
251 mClose = (ImageView) mTabContent.findViewById(R.id.close);
252 mClose.setOnClickListener(this);
Michael Kolbae62fd42010-08-18 16:33:28 -0700253 mIncognito = mTabContent.findViewById(R.id.incognito);
John Reck541f55a2011-06-07 16:34:43 -0700254 mSnapshot = mTabContent.findViewById(R.id.snapshot);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700255 mSelected = false;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700256 // update the status
Michael Kolb94827b62011-01-08 14:23:45 -0800257 updateFromTab();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700258 }
259
260 @Override
261 public void onClick(View v) {
262 if (v == mClose) {
263 closeTab();
264 }
265 }
266
Michael Kolb94827b62011-01-08 14:23:45 -0800267 private void updateFromTab() {
268 String displayTitle = mTab.getTitle();
John Reck30c714c2010-12-16 17:30:34 -0800269 if (displayTitle == null) {
Michael Kolb94827b62011-01-08 14:23:45 -0800270 displayTitle = mTab.getUrl();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700271 }
John Reck30c714c2010-12-16 17:30:34 -0800272 setDisplayTitle(displayTitle);
Michael Kolb94827b62011-01-08 14:23:45 -0800273 if (mTab.getFavicon() != null) {
John Reck034637c2011-08-11 11:34:44 -0700274 setFavicon(mUi.getFaviconDrawable(mTab.getFavicon()));
Michael Kolba2b2ba82010-08-04 17:54:03 -0700275 }
John Reck541f55a2011-06-07 16:34:43 -0700276 updateTabIcons();
277 }
278
279 private void updateTabIcons() {
280 mIncognito.setVisibility(
281 mTab.isPrivateBrowsingEnabled() ?
282 View.VISIBLE : View.GONE);
283 mSnapshot.setVisibility(mTab.isSnapshot()
284 ? View.VISIBLE : View.GONE);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700285 }
286
287 @Override
Michael Kolbb7b115e2010-09-25 16:59:37 -0700288 public void setActivated(boolean selected) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700289 mSelected = selected;
290 mClose.setVisibility(mSelected ? View.VISIBLE : View.GONE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800291 mFaviconView.setVisibility(mSelected ? View.GONE : View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700292 mTitle.setTextAppearance(mActivity, mSelected ?
Michael Kolbc7485ae2010-09-03 10:10:58 -0700293 R.style.TabTitleSelected : R.style.TabTitleUnselected);
294 setHorizontalFadingEdgeEnabled(!mSelected);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700295 super.setActivated(selected);
Michael Kolb678afc82011-05-17 14:52:41 -0700296 updateLayoutParams();
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800297 setFocusable(!selected);
298 postInvalidate();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700299 }
300
Michael Kolb678afc82011-05-17 14:52:41 -0700301 public void updateLayoutParams() {
302 LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams();
John Reck034637c2011-08-11 11:34:44 -0700303 lp.width = mTabWidth;
Michael Kolb678afc82011-05-17 14:52:41 -0700304 lp.height = LayoutParams.MATCH_PARENT;
305 setLayoutParams(lp);
306 }
307
Michael Kolba2b2ba82010-08-04 17:54:03 -0700308 void setDisplayTitle(String title) {
309 mTitle.setText(title);
310 }
311
312 void setFavicon(Drawable d) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800313 mFaviconView.setImageDrawable(d);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700314 }
315
316 void setLock(Drawable d) {
317 if (null == d) {
318 mLock.setVisibility(View.GONE);
319 } else {
320 mLock.setImageDrawable(d);
321 mLock.setVisibility(View.VISIBLE);
322 }
323 }
324
Michael Kolba2b2ba82010-08-04 17:54:03 -0700325 private void closeTab() {
Michael Kolb94827b62011-01-08 14:23:45 -0800326 if (mTab == mTabControl.getCurrentTab()) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700327 mUiController.closeCurrentTab();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700328 } else {
Michael Kolb94827b62011-01-08 14:23:45 -0800329 mUiController.closeTab(mTab);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700330 }
331 }
332
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800333 @Override
334 protected void onLayout(boolean changed, int l, int t, int r, int b) {
335 super.onLayout(changed, l, t, r, b);
336 setTabPath(mPath, 0, 0, r - l, b - t);
Michael Kolbeb7001c2011-02-16 16:07:33 -0800337 setFocusPath(mFocusPath, 0, 0, r - l, b - t);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800338 }
Michael Kolbb4cafc52011-01-12 16:55:04 -0800339
Enrico Ros1f5a0952014-11-18 20:15:48 -0800340 /*@Override
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800341 protected void dispatchDraw(Canvas canvas) {
Romain Guyc8373212011-01-07 19:15:16 -0800342 if (mCurrentTextureWidth != mUi.getContentWidth() ||
343 mCurrentTextureHeight != getHeight()) {
344 mCurrentTextureWidth = mUi.getContentWidth();
345 mCurrentTextureHeight = getHeight();
346
347 if (mCurrentTextureWidth > 0 && mCurrentTextureHeight > 0) {
348 Bitmap activeTexture = getDrawableAsBitmap(mActiveDrawable,
349 mCurrentTextureWidth, mCurrentTextureHeight);
350 Bitmap inactiveTexture = getDrawableAsBitmap(mInactiveDrawable,
351 mCurrentTextureWidth, mCurrentTextureHeight);
352
353 mActiveShader = new BitmapShader(activeTexture,
354 Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
355 mActiveShaderPaint.setShader(mActiveShader);
Michael Kolbb4cafc52011-01-12 16:55:04 -0800356
Romain Guyc8373212011-01-07 19:15:16 -0800357 mInactiveShader = new BitmapShader(inactiveTexture,
358 Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
359 mInactiveShaderPaint.setShader(mInactiveShader);
360 }
361 }
Michael Kolb05902aa2011-02-22 17:43:38 -0800362 // add some monkey protection
363 if ((mActiveShader != null) && (mInactiveShader != null)) {
364 int state = canvas.save();
365 getLocationInWindow(mWindowPos);
366 Paint paint = mSelected ? mActiveShaderPaint : mInactiveShaderPaint;
367 drawClipped(canvas, paint, mPath, mWindowPos[0]);
368 canvas.restoreToCount(state);
369 }
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800370 super.dispatchDraw(canvas);
371 }
372
Romain Guyc8373212011-01-07 19:15:16 -0800373 private void drawClipped(Canvas canvas, Paint paint, Path clipPath, int left) {
374 // TODO: We should change the matrix/shader only when needed
375 final Matrix matrix = mSelected ? mActiveMatrix : mInactiveMatrix;
376 matrix.setTranslate(-left, 0.0f);
377 (mSelected ? mActiveShader : mInactiveShader).setLocalMatrix(matrix);
378 canvas.drawPath(clipPath, paint);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800379 if (isFocused()) {
Michael Kolbeb7001c2011-02-16 16:07:33 -0800380 canvas.drawPath(mFocusPath, mFocusPaint);
Michael Kolbdc2ee1b2011-02-14 14:34:40 -0800381 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800382 }*/
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800383
384 private void setTabPath(Path path, int l, int t, int r, int b) {
385 path.reset();
386 path.moveTo(l, b);
387 path.lineTo(l, t);
388 path.lineTo(r - mTabSliceWidth, t);
389 path.lineTo(r, b);
390 path.close();
391 }
392
Michael Kolbeb7001c2011-02-16 16:07:33 -0800393 private void setFocusPath(Path path, int l, int t, int r, int b) {
394 path.reset();
395 path.moveTo(l, b);
396 path.lineTo(l, t);
397 path.lineTo(r - mTabSliceWidth, t);
398 path.lineTo(r, b);
399 }
400
Michael Kolba2b2ba82010-08-04 17:54:03 -0700401 }
402
Michael Kolb2d59c322011-01-25 13:18:55 -0800403 private void animateTabOut(final Tab tab, final TabView tv) {
404 ObjectAnimator scalex = ObjectAnimator.ofFloat(tv, "scaleX", 1.0f, 0.0f);
405 ObjectAnimator scaley = ObjectAnimator.ofFloat(tv, "scaleY", 1.0f, 0.0f);
Michael Kolb49f15832011-01-25 15:02:27 -0800406 ObjectAnimator alpha = ObjectAnimator.ofFloat(tv, "alpha", 1.0f, 0.0f);
Michael Kolb2d59c322011-01-25 13:18:55 -0800407 AnimatorSet animator = new AnimatorSet();
Michael Kolb49f15832011-01-25 15:02:27 -0800408 animator.playTogether(scalex, scaley, alpha);
Michael Kolb2d59c322011-01-25 13:18:55 -0800409 animator.setDuration(150);
410 animator.addListener(new AnimatorListener() {
411
412 @Override
413 public void onAnimationCancel(Animator animation) {
414 }
415
416 @Override
417 public void onAnimationEnd(Animator animation) {
418 mTabs.removeTab(tv);
419 mTabMap.remove(tab);
Michael Kolb8814d732011-01-26 11:22:30 -0800420 mUi.onRemoveTabCompleted(tab);
Michael Kolb2d59c322011-01-25 13:18:55 -0800421 }
422
423 @Override
424 public void onAnimationRepeat(Animator animation) {
425 }
426
427 @Override
428 public void onAnimationStart(Animator animation) {
429 }
430
431 });
432 animator.start();
433 }
434
435 private void animateTabIn(final Tab tab, final TabView tv) {
Michael Kolb49f15832011-01-25 15:02:27 -0800436 ObjectAnimator scalex = ObjectAnimator.ofFloat(tv, "scaleX", 0.0f, 1.0f);
Michael Kolb2d59c322011-01-25 13:18:55 -0800437 scalex.setDuration(150);
438 scalex.addListener(new AnimatorListener() {
439
440 @Override
441 public void onAnimationCancel(Animator animation) {
442 }
443
444 @Override
445 public void onAnimationEnd(Animator animation) {
Michael Kolb8814d732011-01-26 11:22:30 -0800446 mUi.onAddTabCompleted(tab);
Michael Kolb2d59c322011-01-25 13:18:55 -0800447 }
448
449 @Override
450 public void onAnimationRepeat(Animator animation) {
451 }
452
453 @Override
454 public void onAnimationStart(Animator animation) {
455 mTabs.addTab(tv);
456 }
457
458 });
459 scalex.start();
460 }
461
Michael Kolba2b2ba82010-08-04 17:54:03 -0700462 // TabChangeListener implementation
463
Michael Kolb8233fac2010-10-26 16:08:53 -0700464 public void onSetActiveTab(Tab tab) {
Michael Kolbc831b632011-05-11 09:30:34 -0700465 mTabs.setSelectedTab(mTabControl.getTabPosition(tab));
Michael Kolba2b2ba82010-08-04 17:54:03 -0700466 }
467
Michael Kolba2b2ba82010-08-04 17:54:03 -0700468 public void onFavicon(Tab tab, Bitmap favicon) {
Michael Kolb94827b62011-01-08 14:23:45 -0800469 TabView tv = mTabMap.get(tab);
470 if (tv != null) {
John Reck034637c2011-08-11 11:34:44 -0700471 tv.setFavicon(mUi.getFaviconDrawable(favicon));
Michael Kolba2b2ba82010-08-04 17:54:03 -0700472 }
473 }
474
Michael Kolba2b2ba82010-08-04 17:54:03 -0700475 public void onNewTab(Tab tab) {
Michael Kolb94827b62011-01-08 14:23:45 -0800476 TabView tv = buildTabView(tab);
Michael Kolb2d59c322011-01-25 13:18:55 -0800477 animateTabIn(tab, tv);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700478 }
479
Michael Kolba2b2ba82010-08-04 17:54:03 -0700480 public void onRemoveTab(Tab tab) {
Michael Kolb94827b62011-01-08 14:23:45 -0800481 TabView tv = mTabMap.get(tab);
482 if (tv != null) {
Michael Kolb2d59c322011-01-25 13:18:55 -0800483 animateTabOut(tab, tv);
484 } else {
485 mTabMap.remove(tab);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700486 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700487 }
488
Michael Kolba2b2ba82010-08-04 17:54:03 -0700489 public void onUrlAndTitle(Tab tab, String url, String title) {
Michael Kolb94827b62011-01-08 14:23:45 -0800490 TabView tv = mTabMap.get(tab);
491 if (tv != null) {
492 if (title != null) {
493 tv.setDisplayTitle(title);
494 } else if (url != null) {
495 tv.setDisplayTitle(UrlUtils.stripUrl(url));
496 }
John Reck541f55a2011-06-07 16:34:43 -0700497 tv.updateTabIcons();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700498 }
499 }
500
Michael Kolba2b2ba82010-08-04 17:54:03 -0700501 private boolean isLoading() {
Michael Kolb1c3a6d22011-12-15 15:28:49 -0800502 Tab tab = mTabControl.getCurrentTab();
503 if (tab != null) {
504 return tab.inPageLoad();
Michael Kolb8233fac2010-10-26 16:08:53 -0700505 } else {
506 return false;
507 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700508 }
509
Michael Kolba2b2ba82010-08-04 17:54:03 -0700510}