blob: 4f179b087c2cd99683491db26bd4df180777e9dc [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
17package com.android.browser;
18
Michael Kolbebba8b42010-09-30 12:57:59 -070019import com.android.browser.ScrollWebView.ScrollListener;
Michael Kolbebba8b42010-09-30 12:57:59 -070020
Michael Kolb8233fac2010-10-26 16:08:53 -070021import android.app.Activity;
Michael Kolba2b2ba82010-08-04 17:54:03 -070022import android.content.Context;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
Michael Kolb2b5a13a2010-12-09 14:13:42 -080025import android.graphics.BitmapShader;
26import android.graphics.Canvas;
Michael Kolba2b2ba82010-08-04 17:54:03 -070027import android.graphics.Color;
Michael Kolb2b5a13a2010-12-09 14:13:42 -080028import android.graphics.LinearGradient;
29import android.graphics.Paint;
30import android.graphics.Path;
31import android.graphics.Shader;
Michael Kolba2b2ba82010-08-04 17:54:03 -070032import android.graphics.drawable.BitmapDrawable;
33import android.graphics.drawable.Drawable;
34import android.graphics.drawable.LayerDrawable;
35import android.graphics.drawable.PaintDrawable;
36import android.view.ContextMenu;
Michael Kolbed217742010-08-10 17:52:34 -070037import android.view.Gravity;
Michael Kolba2b2ba82010-08-04 17:54:03 -070038import android.view.LayoutInflater;
39import android.view.MenuInflater;
40import android.view.View;
41import android.view.View.OnClickListener;
42import android.webkit.WebView;
Michael Kolbed217742010-08-10 17:52:34 -070043import android.widget.ImageButton;
Michael Kolba2b2ba82010-08-04 17:54:03 -070044import android.widget.ImageView;
45import android.widget.LinearLayout;
46import android.widget.TextView;
47
Michael Kolba2b2ba82010-08-04 17:54:03 -070048import java.util.HashMap;
Michael Kolb1bf23132010-11-19 12:55:12 -080049import java.util.List;
Michael Kolba2b2ba82010-08-04 17:54:03 -070050import java.util.Map;
51
52/**
53 * tabbed title bar for xlarge screen browser
54 */
55public class TabBar extends LinearLayout
Michael Kolb8233fac2010-10-26 16:08:53 -070056 implements ScrollListener, OnClickListener {
Michael Kolba2b2ba82010-08-04 17:54:03 -070057
58 private static final int PROGRESS_MAX = 100;
59
Michael Kolb8233fac2010-10-26 16:08:53 -070060 private Activity mActivity;
61 private UiController mUiController;
62 private TabControl mTabControl;
63 private BaseUi mUi;
Michael Kolba2b2ba82010-08-04 17:54:03 -070064
Michael Kolbed217742010-08-10 17:52:34 -070065 private final int mTabWidthSelected;
66 private final int mTabWidthUnselected;
67
Michael Kolba2b2ba82010-08-04 17:54:03 -070068 private TabScrollView mTabs;
Michael Kolb8233fac2010-10-26 16:08:53 -070069
Michael Kolbebba8b42010-09-30 12:57:59 -070070 private ImageButton mNewTab;
71 private int mButtonWidth;
Michael Kolba2b2ba82010-08-04 17:54:03 -070072
73 private Map<Tab, TabViewData> mTabMap;
74
Michael Kolba2b2ba82010-08-04 17:54:03 -070075 private boolean mUserRequestedUrlbar;
76 private boolean mTitleVisible;
Michael Kolbed217742010-08-10 17:52:34 -070077 private boolean mShowUrlMode;
John Reckfb3017f2010-10-26 19:01:24 -070078 private boolean mHasReceivedTitle;
Michael Kolba2b2ba82010-08-04 17:54:03 -070079
John Reckaff60fb2010-10-25 13:47:58 -070080 private Drawable mGenericFavicon;
John Reckfb3017f2010-10-26 19:01:24 -070081 private String mLoadingText;
John Reckaff60fb2010-10-25 13:47:58 -070082
Michael Kolb2b5a13a2010-12-09 14:13:42 -080083 private Drawable mActiveDrawable;
84 private Drawable mInactiveDrawable;
85
86 private Bitmap mShaderBuffer;
87 private Canvas mShaderCanvas;
88 private Paint mShaderPaint;
89 private int mTabHeight;
90 private int mTabOverlap;
91 private int mTabSliceWidth;
92 private int mTabPadding;
93
Michael Kolb8233fac2010-10-26 16:08:53 -070094 public TabBar(Activity activity, UiController controller, BaseUi ui) {
95 super(activity);
96 mActivity = activity;
97 mUiController = controller;
98 mTabControl = mUiController.getTabControl();
99 mUi = ui;
100 Resources res = activity.getResources();
Michael Kolbed217742010-08-10 17:52:34 -0700101 mTabWidthSelected = (int) res.getDimension(R.dimen.tab_width_selected);
102 mTabWidthUnselected = (int) res.getDimension(R.dimen.tab_width_unselected);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800103 mActiveDrawable = res.getDrawable(R.drawable.bg_urlbar);
104 mInactiveDrawable = res.getDrawable(R.drawable.browsertab_inactive);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700105
Michael Kolba2b2ba82010-08-04 17:54:03 -0700106 mTabMap = new HashMap<Tab, TabViewData>();
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 Resources resources = activity.getResources();
108 LayoutInflater factory = LayoutInflater.from(activity);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700109 factory.inflate(R.layout.tab_bar, this);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800110 setPadding(12, 12, 0, 0);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700111 mTabs = (TabScrollView) findViewById(R.id.tabs);
Michael Kolbebba8b42010-09-30 12:57:59 -0700112 mNewTab = (ImageButton) findViewById(R.id.newtab);
113 mNewTab.setOnClickListener(this);
John Reckaff60fb2010-10-25 13:47:58 -0700114 mGenericFavicon = res.getDrawable(R.drawable.app_web_browser_sm);
John Reckfb3017f2010-10-26 19:01:24 -0700115 mLoadingText = res.getString(R.string.title_bar_loading);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800116 setChildrenDrawingOrderEnabled(true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700117
118 // TODO: Change enabled states based on whether you can go
119 // back/forward. Probably should be done inside onPageStarted.
120
Michael Kolb1bf23132010-11-19 12:55:12 -0800121 updateTabs(mUiController.getTabs());
Michael Kolba2b2ba82010-08-04 17:54:03 -0700122
Michael Kolba2b2ba82010-08-04 17:54:03 -0700123 mUserRequestedUrlbar = false;
124 mTitleVisible = true;
Michael Kolbebba8b42010-09-30 12:57:59 -0700125 mButtonWidth = -1;
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800126 // tab dimensions
127 mTabHeight = (int) res.getDimension(R.dimen.tab_height);
128 mTabOverlap = (int) res.getDimension(R.dimen.tab_overlap);
129 mTabSliceWidth = (int) res.getDimension(R.dimen.tab_slice);
130 mTabPadding = (int) res.getDimension(R.dimen.tab_padding);
131 int maxTabWidth = (int) res.getDimension(R.dimen.max_tab_width);
132 // shader initialization
133 mShaderBuffer = Bitmap.createBitmap(maxTabWidth, mTabHeight,
134 Bitmap.Config.ARGB_8888);
135 mShaderCanvas = new Canvas(mShaderBuffer);
136 mShaderPaint = new Paint();
137 BitmapShader shader = new BitmapShader(mShaderBuffer,
138 Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
139 mShaderPaint.setShader(shader);
140 mShaderPaint.setStyle(Paint.Style.FILL);
141 mShaderPaint.setAntiAlias(true);
Michael Kolbebba8b42010-09-30 12:57:59 -0700142 }
143
Michael Kolb1bf23132010-11-19 12:55:12 -0800144 void updateTabs(List<Tab> tabs) {
145 mTabs.clearTabs();
146 mTabMap.clear();
147 for (Tab tab : tabs) {
148 TabViewData data = buildTab(tab);
149 TabView tv = buildView(data);
150 }
151 mTabs.setSelectedTab(mTabControl.getCurrentIndex());
152 }
153
Michael Kolbebba8b42010-09-30 12:57:59 -0700154 @Override
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800155 protected void onMeasure(int hspec, int vspec) {
156 super.onMeasure(hspec, vspec);
157 int w = getMeasuredWidth();
158 // adjust for new tab overlap
159 w -= mTabOverlap;
160 setMeasuredDimension(w, getMeasuredHeight());
161 }
162
163 @Override
Michael Kolbebba8b42010-09-30 12:57:59 -0700164 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800165 // use paddingLeft and paddingTop
166 int pl = getPaddingLeft();
167 int pt = getPaddingTop();
Michael Kolbebba8b42010-09-30 12:57:59 -0700168 if (mButtonWidth == -1) {
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800169 mButtonWidth = mNewTab.getMeasuredWidth() - mTabOverlap;
Michael Kolbebba8b42010-09-30 12:57:59 -0700170 }
171 int sw = mTabs.getMeasuredWidth();
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800172 int w = right - left - pl;
Michael Kolbebba8b42010-09-30 12:57:59 -0700173 if (w-sw < mButtonWidth) {
174 sw = w - mButtonWidth;
175 }
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800176 mTabs.layout(pl, pt, pl + sw, bottom - top);
177 // adjust for overlap
178 mNewTab.layout(pl + sw - mTabOverlap, pt,
179 pl + sw + mButtonWidth - mTabOverlap, bottom - top);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700180 }
181
182 public void onClick(View view) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700183 mUi.hideComboView();
Michael Kolbebba8b42010-09-30 12:57:59 -0700184 if (mNewTab == view) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700185 mUiController.openTabToHomePage();
Michael Kolbebba8b42010-09-30 12:57:59 -0700186 } else if (mTabs.getSelectedTab() == view) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 if (mUi.isFakeTitleBarShowing() && !isLoading()) {
188 mUi.hideFakeTitleBar();
Michael Kolbed217742010-08-10 17:52:34 -0700189 } else {
190 showUrlBar();
191 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700192 } else {
Michael Kolbebba8b42010-09-30 12:57:59 -0700193 int ix = mTabs.getChildIndex(view);
194 if (ix >= 0) {
195 mTabs.setSelectedTab(ix);
Michael Kolb8233fac2010-10-26 16:08:53 -0700196 mUiController.switchToTab(ix);
Michael Kolbebba8b42010-09-30 12:57:59 -0700197 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700198 }
199 }
200
Michael Kolbed217742010-08-10 17:52:34 -0700201 private void showUrlBar() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700202 mUi.stopWebViewScrolling();
203 mUi.showFakeTitleBar();
Michael Kolbed217742010-08-10 17:52:34 -0700204 mUserRequestedUrlbar = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700205 }
206
Michael Kolbed217742010-08-10 17:52:34 -0700207 private void setShowUrlMode(boolean showUrl) {
208 mShowUrlMode = showUrl;
Michael Kolbed217742010-08-10 17:52:34 -0700209 }
210
211 // callback after fake titlebar is shown
212 void onShowTitleBar() {
213 setShowUrlMode(false);
214 }
215
216 // callback after fake titlebar is hidden
Michael Kolba2b2ba82010-08-04 17:54:03 -0700217 void onHideTitleBar() {
Michael Kolbed217742010-08-10 17:52:34 -0700218 setShowUrlMode(!mTitleVisible);
Michael Kolb8233fac2010-10-26 16:08:53 -0700219 Tab tab = mTabControl.getCurrentTab();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700220 tab.getWebView().requestFocus();
221 mUserRequestedUrlbar = false;
222 }
223
Michael Kolbed217742010-08-10 17:52:34 -0700224 // webview scroll listener
225
226 @Override
227 public void onScroll(boolean titleVisible) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 // isLoading is using the current tab, which initially might not be set yet
229 if (mTabControl.getCurrentTab() != null) {
230 mTitleVisible = titleVisible;
231 if (!mShowUrlMode && !mTitleVisible && !isLoading()) {
232 if (mUserRequestedUrlbar) {
233 mUi.hideFakeTitleBar();
234 } else {
235 setShowUrlMode(true);
236 }
237 } else if (mTitleVisible && !isLoading()) {
238 if (mShowUrlMode) {
239 setShowUrlMode(false);
240 }
Michael Kolbed217742010-08-10 17:52:34 -0700241 }
242 }
243 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700244
245 @Override
246 public void createContextMenu(ContextMenu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 MenuInflater inflater = mActivity.getMenuInflater();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700248 inflater.inflate(R.menu.title_context, menu);
Michael Kolb8233fac2010-10-26 16:08:53 -0700249 mActivity.onCreateContextMenu(menu, this, null);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700250 }
251
252 private TabViewData buildTab(Tab tab) {
253 TabViewData data = new TabViewData(tab);
254 mTabMap.put(tab, data);
255 return data;
256 }
257
258 private TabView buildView(final TabViewData data) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 TabView tv = new TabView(mActivity, data);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700260 tv.setTag(data);
261 tv.setOnClickListener(this);
262 mTabs.addTab(tv);
263 return tv;
264 }
265
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800266 @Override
267 protected int getChildDrawingOrder(int count, int i) {
268 // reverse
269 return count - 1 - i;
270 }
271
Michael Kolba2b2ba82010-08-04 17:54:03 -0700272 /**
273 * View used in the tab bar
274 */
275 class TabView extends LinearLayout implements OnClickListener {
276
277 TabViewData mTabData;
278 View mTabContent;
279 TextView mTitle;
Michael Kolbae62fd42010-08-18 16:33:28 -0700280 View mIncognito;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700281 ImageView mIconView;
282 ImageView mLock;
283 ImageView mClose;
284 boolean mSelected;
285 boolean mInLoad;
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800286 Path mPath;
287 int[] mWindowPos;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700288
289 /**
290 * @param context
291 */
292 public TabView(Context context, TabViewData tab) {
293 super(context);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800294 setWillNotDraw(false);
295 mPath = new Path();
296 mWindowPos = new int[2];
Michael Kolba2b2ba82010-08-04 17:54:03 -0700297 mTabData = tab;
Michael Kolbed217742010-08-10 17:52:34 -0700298 setGravity(Gravity.CENTER_VERTICAL);
299 setOrientation(LinearLayout.HORIZONTAL);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800300 setPadding(0, 0, mTabPadding, 0);
Bjorn Bringertb1402a52010-10-12 10:53:12 +0100301 LayoutInflater inflater = LayoutInflater.from(getContext());
Michael Kolbed217742010-08-10 17:52:34 -0700302 mTabContent = inflater.inflate(R.layout.tab_title, this, true);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700303 mTitle = (TextView) mTabContent.findViewById(R.id.title);
304 mIconView = (ImageView) mTabContent.findViewById(R.id.favicon);
305 mLock = (ImageView) mTabContent.findViewById(R.id.lock);
306 mClose = (ImageView) mTabContent.findViewById(R.id.close);
307 mClose.setOnClickListener(this);
Michael Kolbae62fd42010-08-18 16:33:28 -0700308 mIncognito = mTabContent.findViewById(R.id.incognito);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700309 mSelected = false;
310 mInLoad = false;
311 // update the status
312 updateFromData();
313 }
314
315 @Override
316 public void onClick(View v) {
317 if (v == mClose) {
318 closeTab();
319 }
320 }
321
322 private void updateFromData() {
323 mTabData.mTabView = this;
324 if (mTabData.mUrl != null) {
325 setDisplayTitle(mTabData.mUrl);
326 }
327 if (mTabData.mTitle != null) {
328 setDisplayTitle(mTabData.mTitle);
329 }
330 setProgress(mTabData.mProgress);
331 if (mTabData.mIcon != null) {
332 setFavicon(mTabData.mIcon);
333 }
334 if (mTabData.mLock != null) {
335 setLock(mTabData.mLock);
336 }
Michael Kolbae62fd42010-08-18 16:33:28 -0700337 if (mTabData.mTab != null) {
338 mIncognito.setVisibility(
Michael Kolb1bf23132010-11-19 12:55:12 -0800339 mTabData.mTab.isPrivateBrowsingEnabled() ?
Michael Kolbae62fd42010-08-18 16:33:28 -0700340 View.VISIBLE : View.GONE);
341 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700342 }
343
344 @Override
Michael Kolbb7b115e2010-09-25 16:59:37 -0700345 public void setActivated(boolean selected) {
Michael Kolba2b2ba82010-08-04 17:54:03 -0700346 mSelected = selected;
347 mClose.setVisibility(mSelected ? View.VISIBLE : View.GONE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700348 mTitle.setTextAppearance(mActivity, mSelected ?
Michael Kolbc7485ae2010-09-03 10:10:58 -0700349 R.style.TabTitleSelected : R.style.TabTitleUnselected);
350 setHorizontalFadingEdgeEnabled(!mSelected);
Michael Kolbb7b115e2010-09-25 16:59:37 -0700351 super.setActivated(selected);
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800352 LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams();
353 lp.width = selected ? mTabWidthSelected : mTabWidthUnselected;
354 lp.height = LayoutParams.MATCH_PARENT;
355 setLayoutParams(lp);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700356 }
357
358 void setDisplayTitle(String title) {
359 mTitle.setText(title);
360 }
361
362 void setFavicon(Drawable d) {
363 mIconView.setImageDrawable(d);
364 }
365
366 void setLock(Drawable d) {
367 if (null == d) {
368 mLock.setVisibility(View.GONE);
369 } else {
370 mLock.setImageDrawable(d);
371 mLock.setVisibility(View.VISIBLE);
372 }
373 }
374
Michael Kolba2b2ba82010-08-04 17:54:03 -0700375 void setProgress(int newProgress) {
376 if (newProgress >= PROGRESS_MAX) {
377 mInLoad = false;
378 } else {
379 if (!mInLoad && getWindowToken() != null) {
380 mInLoad = true;
381 }
382 }
383 }
384
385 private void closeTab() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700386 if (mTabData.mTab == mTabControl.getCurrentTab()) {
387 mUiController.closeCurrentTab();
Michael Kolba2b2ba82010-08-04 17:54:03 -0700388 } else {
Michael Kolb8233fac2010-10-26 16:08:53 -0700389 mUiController.closeTab(mTabData.mTab);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700390 }
391 }
392
Michael Kolb2b5a13a2010-12-09 14:13:42 -0800393 @Override
394 protected void onLayout(boolean changed, int l, int t, int r, int b) {
395 super.onLayout(changed, l, t, r, b);
396 setTabPath(mPath, 0, 0, r - l, b - t);
397 }
398
399 @Override
400 protected void dispatchDraw(Canvas canvas) {
401 int state = canvas.save();
402 int[] pos = new int[2];
403 getLocationInWindow(mWindowPos);
404 Drawable drawable = mSelected ? mActiveDrawable : mInactiveDrawable;
405 drawable.setBounds(0, 0, mUi.getTitleBarWidth(), getHeight());
406 drawClipped(canvas, drawable, mPath, mWindowPos[0]);
407 canvas.restoreToCount(state);
408 super.dispatchDraw(canvas);
409 }
410
411 private void drawClipped(Canvas canvas, Drawable drawable,
412 Path clipPath, int left) {
413 mShaderCanvas.drawColor(Color.TRANSPARENT);
414 mShaderCanvas.translate(-left, 0);
415 drawable.draw(mShaderCanvas);
416 canvas.drawPath(clipPath, mShaderPaint);
417 mShaderCanvas.translate(left, 0);
418 }
419
420 private void setTabPath(Path path, int l, int t, int r, int b) {
421 path.reset();
422 path.moveTo(l, b);
423 path.lineTo(l, t);
424 path.lineTo(r - mTabSliceWidth, t);
425 path.lineTo(r, b);
426 path.close();
427 }
428
Michael Kolba2b2ba82010-08-04 17:54:03 -0700429 }
430
431 /**
432 * Store tab state within the title bar
433 */
434 class TabViewData {
435
436 Tab mTab;
437 TabView mTabView;
438 int mProgress;
439 Drawable mIcon;
440 Drawable mLock;
441 String mTitle;
442 String mUrl;
443
444 TabViewData(Tab tab) {
445 mTab = tab;
John Reckd8657622010-10-25 16:20:40 -0700446 WebView web = tab.getWebView();
447 if (web != null) {
448 setUrlAndTitle(web.getUrl(), web.getTitle());
449 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700450 }
451
452 void setUrlAndTitle(String url, String title) {
453 mUrl = url;
454 mTitle = title;
455 if (mTabView != null) {
456 if (title != null) {
457 mTabView.setDisplayTitle(title);
458 } else if (url != null) {
John Reckfb3017f2010-10-26 19:01:24 -0700459 mTabView.setDisplayTitle(UrlUtils.stripUrl(url));
Michael Kolba2b2ba82010-08-04 17:54:03 -0700460 }
461 }
462 }
463
464 void setProgress(int newProgress) {
465 mProgress = newProgress;
466 if (mTabView != null) {
467 mTabView.setProgress(mProgress);
468 }
469 }
470
471 void setFavicon(Bitmap icon) {
472 Drawable[] array = new Drawable[3];
473 array[0] = new PaintDrawable(Color.BLACK);
474 array[1] = new PaintDrawable(Color.WHITE);
475 if (icon == null) {
John Reckaff60fb2010-10-25 13:47:58 -0700476 array[2] = mGenericFavicon;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700477 } else {
478 array[2] = new BitmapDrawable(icon);
479 }
480 LayerDrawable d = new LayerDrawable(array);
481 d.setLayerInset(1, 1, 1, 1, 1);
482 d.setLayerInset(2, 2, 2, 2, 2);
483 mIcon = d;
484 if (mTabView != null) {
485 mTabView.setFavicon(mIcon);
486 }
487 }
488
489 }
490
491 // TabChangeListener implementation
492
Michael Kolb8233fac2010-10-26 16:08:53 -0700493 public void onSetActiveTab(Tab tab) {
494 mTabs.setSelectedTab(mTabControl.getTabIndex(tab));
Michael Kolba2b2ba82010-08-04 17:54:03 -0700495 TabViewData tvd = mTabMap.get(tab);
496 if (tvd != null) {
497 tvd.setProgress(tvd.mProgress);
498 // update the scroll state
499 WebView webview = tab.getWebView();
500 onScroll(webview.getVisibleTitleHeight() > 0);
501 }
502 }
503
Michael Kolba2b2ba82010-08-04 17:54:03 -0700504 public void onFavicon(Tab tab, Bitmap favicon) {
505 TabViewData tvd = mTabMap.get(tab);
506 if (tvd != null) {
507 tvd.setFavicon(favicon);
508 }
509 }
510
Michael Kolba2b2ba82010-08-04 17:54:03 -0700511 public void onNewTab(Tab tab) {
512 TabViewData tvd = buildTab(tab);
513 buildView(tvd);
Michael Kolba2b2ba82010-08-04 17:54:03 -0700514 }
515
Michael Kolba2b2ba82010-08-04 17:54:03 -0700516 public void onProgress(Tab tab, int progress) {
517 TabViewData tvd = mTabMap.get(tab);
518 if (tvd != null) {
519 tvd.setProgress(progress);
520 }
521 }
522
Michael Kolba2b2ba82010-08-04 17:54:03 -0700523 public void onRemoveTab(Tab tab) {
524 TabViewData tvd = mTabMap.get(tab);
Michael Kolbe2752f72010-10-25 16:50:16 -0700525 if (tvd != null) {
526 TabView tv = tvd.mTabView;
527 if (tv != null) {
528 mTabs.removeTab(tv);
529 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700530 }
531 mTabMap.remove(tab);
532 }
533
Michael Kolba2b2ba82010-08-04 17:54:03 -0700534 public void onUrlAndTitle(Tab tab, String url, String title) {
John Reckfb3017f2010-10-26 19:01:24 -0700535 mHasReceivedTitle = true;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700536 TabViewData tvd = mTabMap.get(tab);
537 if (tvd != null) {
538 tvd.setUrlAndTitle(url, title);
539 }
540 }
541
Michael Kolba2b2ba82010-08-04 17:54:03 -0700542 public void onPageFinished(Tab tab) {
John Reckfb3017f2010-10-26 19:01:24 -0700543 if (!mHasReceivedTitle) {
544 TabViewData tvd = mTabMap.get(tab);
545 if (tvd != null) {
546 tvd.setUrlAndTitle(tvd.mUrl, null);
547 }
548 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700549 }
550
John Reckfb3017f2010-10-26 19:01:24 -0700551 public void onPageStarted(Tab tab, String url, Bitmap favicon) {
552 mHasReceivedTitle = false;
John Reckaff60fb2010-10-25 13:47:58 -0700553 TabViewData tvd = mTabMap.get(tab);
554 if (tvd != null) {
555 tvd.setFavicon(favicon);
John Reckfb3017f2010-10-26 19:01:24 -0700556 tvd.setUrlAndTitle(url, mLoadingText);
John Reckaff60fb2010-10-25 13:47:58 -0700557 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700558 }
559
Michael Kolba2b2ba82010-08-04 17:54:03 -0700560 private boolean isLoading() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700561 TabViewData tvd = mTabMap.get(mTabControl.getCurrentTab());
562 if ((tvd != null) && (tvd.mTabView != null)) {
563 return tvd.mTabView.mInLoad;
564 } else {
565 return false;
566 }
Michael Kolba2b2ba82010-08-04 17:54:03 -0700567 }
568
Michael Kolba2b2ba82010-08-04 17:54:03 -0700569}