Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 19 | import com.android.browser.ScrollWebView.ScrollListener; |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 20 | |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.Animator.AnimatorListener; |
| 23 | import android.animation.AnimatorSet; |
| 24 | import android.animation.ObjectAnimator; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 25 | import android.app.Activity; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 26 | import android.content.Context; |
| 27 | import android.content.res.Resources; |
| 28 | import android.graphics.Bitmap; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 29 | import android.graphics.BitmapShader; |
| 30 | import android.graphics.Canvas; |
Michael Kolb | 467af0a | 2011-01-11 13:09:49 -0800 | [diff] [blame] | 31 | import android.graphics.Matrix; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 32 | import android.graphics.Paint; |
| 33 | import android.graphics.Path; |
| 34 | import android.graphics.Shader; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 35 | import android.graphics.drawable.BitmapDrawable; |
| 36 | import android.graphics.drawable.Drawable; |
| 37 | import android.graphics.drawable.LayerDrawable; |
| 38 | import android.graphics.drawable.PaintDrawable; |
| 39 | import android.view.ContextMenu; |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 40 | import android.view.Gravity; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 41 | import android.view.LayoutInflater; |
| 42 | import android.view.MenuInflater; |
| 43 | import android.view.View; |
| 44 | import android.view.View.OnClickListener; |
| 45 | import android.webkit.WebView; |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 46 | import android.widget.ImageButton; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 47 | import android.widget.ImageView; |
| 48 | import android.widget.LinearLayout; |
| 49 | import android.widget.TextView; |
| 50 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 51 | import java.util.HashMap; |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 52 | import java.util.List; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 53 | import java.util.Map; |
| 54 | |
| 55 | /** |
| 56 | * tabbed title bar for xlarge screen browser |
| 57 | */ |
| 58 | public class TabBar extends LinearLayout |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 59 | implements ScrollListener, OnClickListener { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 60 | |
| 61 | private static final int PROGRESS_MAX = 100; |
| 62 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 63 | private Activity mActivity; |
| 64 | private UiController mUiController; |
| 65 | private TabControl mTabControl; |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 66 | private XLargeUi mUi; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 67 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 68 | private final int mTabWidthSelected; |
| 69 | private final int mTabWidthUnselected; |
| 70 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 71 | private TabScrollView mTabs; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 72 | |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 73 | private ImageButton mNewTab; |
| 74 | private int mButtonWidth; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 75 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 76 | private Map<Tab, TabView> mTabMap; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 77 | |
John Reck | aff60fb | 2010-10-25 13:47:58 -0700 | [diff] [blame] | 78 | private Drawable mGenericFavicon; |
| 79 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 80 | private int mCurrentTextureWidth = 0; |
| 81 | private int mCurrentTextureHeight = 0; |
| 82 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 83 | private Drawable mActiveDrawable; |
| 84 | private Drawable mInactiveDrawable; |
| 85 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 86 | private final Paint mActiveShaderPaint = new Paint(); |
| 87 | private final Paint mInactiveShaderPaint = new Paint(); |
| 88 | private final Matrix mActiveMatrix = new Matrix(); |
| 89 | private final Matrix mInactiveMatrix = new Matrix(); |
| 90 | |
| 91 | private BitmapShader mActiveShader; |
| 92 | private BitmapShader mInactiveShader; |
| 93 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 94 | private int mTabOverlap; |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 95 | private int mAddTabOverlap; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 96 | private int mTabSliceWidth; |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 97 | private boolean mUseQuickControls; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 98 | |
Michael Kolb | 6670653 | 2010-12-12 19:50:22 -0800 | [diff] [blame] | 99 | public TabBar(Activity activity, UiController controller, XLargeUi ui) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 100 | super(activity); |
| 101 | mActivity = activity; |
| 102 | mUiController = controller; |
| 103 | mTabControl = mUiController.getTabControl(); |
| 104 | mUi = ui; |
| 105 | Resources res = activity.getResources(); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 106 | mTabWidthSelected = (int) res.getDimension(R.dimen.tab_width_selected); |
| 107 | mTabWidthUnselected = (int) res.getDimension(R.dimen.tab_width_unselected); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 108 | mActiveDrawable = res.getDrawable(R.drawable.bg_urlbar); |
| 109 | mInactiveDrawable = res.getDrawable(R.drawable.browsertab_inactive); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 110 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 111 | mTabMap = new HashMap<Tab, TabView>(); |
| 112 | Resources resources = activity.getResources(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 113 | LayoutInflater factory = LayoutInflater.from(activity); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 114 | factory.inflate(R.layout.tab_bar, this); |
Michael Kolb | f558f0d | 2011-01-13 19:24:18 -0800 | [diff] [blame] | 115 | setPadding(0, (int) res.getDimension(R.dimen.tab_padding_top), 0, 0); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 116 | mTabs = (TabScrollView) findViewById(R.id.tabs); |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 117 | mNewTab = (ImageButton) findViewById(R.id.newtab); |
| 118 | mNewTab.setOnClickListener(this); |
John Reck | aff60fb | 2010-10-25 13:47:58 -0700 | [diff] [blame] | 119 | mGenericFavicon = res.getDrawable(R.drawable.app_web_browser_sm); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 120 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 121 | updateTabs(mUiController.getTabs()); |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 122 | mButtonWidth = -1; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 123 | // tab dimensions |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 124 | mTabOverlap = (int) res.getDimension(R.dimen.tab_overlap); |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 125 | mAddTabOverlap = (int) res.getDimension(R.dimen.tab_addoverlap); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 126 | mTabSliceWidth = (int) res.getDimension(R.dimen.tab_slice); |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 127 | |
| 128 | mActiveShaderPaint.setStyle(Paint.Style.FILL); |
| 129 | mActiveShaderPaint.setAntiAlias(true); |
| 130 | |
| 131 | mInactiveShaderPaint.setStyle(Paint.Style.FILL); |
| 132 | mInactiveShaderPaint.setAntiAlias(true); |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 133 | |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 136 | void setUseQuickControls(boolean useQuickControls) { |
| 137 | mUseQuickControls = useQuickControls; |
Michael Kolb | 467af0a | 2011-01-11 13:09:49 -0800 | [diff] [blame] | 138 | mNewTab.setVisibility(mUseQuickControls ? View.GONE |
| 139 | : View.VISIBLE); |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | int getTabCount() { |
| 143 | return mTabMap.size(); |
| 144 | } |
| 145 | |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 146 | void updateTabs(List<Tab> tabs) { |
| 147 | mTabs.clearTabs(); |
| 148 | mTabMap.clear(); |
| 149 | for (Tab tab : tabs) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 150 | TabView tv = buildTabView(tab); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 151 | mTabs.addTab(tv); |
Michael Kolb | 1bf2313 | 2010-11-19 12:55:12 -0800 | [diff] [blame] | 152 | } |
| 153 | mTabs.setSelectedTab(mTabControl.getCurrentIndex()); |
| 154 | } |
| 155 | |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 156 | @Override |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 157 | protected void onMeasure(int hspec, int vspec) { |
| 158 | super.onMeasure(hspec, vspec); |
| 159 | int w = getMeasuredWidth(); |
| 160 | // adjust for new tab overlap |
Michael Kolb | 467af0a | 2011-01-11 13:09:49 -0800 | [diff] [blame] | 161 | if (!mUseQuickControls) { |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 162 | w -= mAddTabOverlap; |
Michael Kolb | 467af0a | 2011-01-11 13:09:49 -0800 | [diff] [blame] | 163 | } |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 164 | setMeasuredDimension(w, getMeasuredHeight()); |
| 165 | } |
| 166 | |
| 167 | @Override |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 168 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 169 | // use paddingLeft and paddingTop |
| 170 | int pl = getPaddingLeft(); |
| 171 | int pt = getPaddingTop(); |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 172 | int sw = mTabs.getMeasuredWidth(); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 173 | int w = right - left - pl; |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 174 | if (mUseQuickControls) { |
| 175 | mButtonWidth = 0; |
| 176 | } else { |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 177 | mButtonWidth = mNewTab.getMeasuredWidth() - mAddTabOverlap; |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 178 | if (w-sw < mButtonWidth) { |
| 179 | sw = w - mButtonWidth; |
| 180 | } |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 181 | } |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 182 | mTabs.layout(pl, pt, pl + sw, bottom - top); |
| 183 | // adjust for overlap |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 184 | if (!mUseQuickControls) { |
Michael Kolb | 5a72f18 | 2011-01-13 20:35:06 -0800 | [diff] [blame] | 185 | mNewTab.layout(pl + sw - mAddTabOverlap, pt, |
| 186 | pl + sw + mButtonWidth - mAddTabOverlap, bottom - top); |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 187 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | public void onClick(View view) { |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 191 | if (mNewTab == view) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 192 | mUiController.openTabToHomePage(); |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 193 | } else if (mTabs.getSelectedTab() == view) { |
Michael Kolb | 467af0a | 2011-01-11 13:09:49 -0800 | [diff] [blame] | 194 | if (mUseQuickControls) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 195 | if (mUi.isTitleBarShowing() && !isLoading()) { |
| 196 | mUi.stopEditingUrl(); |
| 197 | mUi.hideTitleBar(); |
Michael Kolb | 467af0a | 2011-01-11 13:09:49 -0800 | [diff] [blame] | 198 | } else { |
| 199 | mUi.stopWebViewScrolling(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 200 | mUi.showTitleBarAndEdit(); |
Michael Kolb | 467af0a | 2011-01-11 13:09:49 -0800 | [diff] [blame] | 201 | } |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 202 | } else if (mUi.isTitleBarShowing() && !isLoading()) { |
| 203 | mUi.stopEditingUrl(); |
| 204 | mUi.hideTitleBar(); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 205 | } else { |
| 206 | showUrlBar(); |
| 207 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 208 | } else { |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 209 | int ix = mTabs.getChildIndex(view); |
| 210 | if (ix >= 0) { |
| 211 | mTabs.setSelectedTab(ix); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 212 | mUiController.switchToTab(ix); |
Michael Kolb | ebba8b4 | 2010-09-30 12:57:59 -0700 | [diff] [blame] | 213 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 217 | private void showUrlBar() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 218 | mUi.stopWebViewScrolling(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 219 | mUi.showTitleBar(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 222 | void showTitleBarIndicator(boolean show) { |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 223 | Tab tab = mTabControl.getCurrentTab(); |
| 224 | if (tab != null) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 225 | TabView tv = mTabMap.get(tab); |
| 226 | if (tv != null) { |
| 227 | tv.showIndicator(show); |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 228 | } |
| 229 | } |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 232 | boolean showsTitleBarIndicator() { |
| 233 | Tab tab = mTabControl.getCurrentTab(); |
| 234 | if (tab != null) { |
| 235 | TabView tv = mTabMap.get(tab); |
| 236 | if (tv != null) { |
| 237 | return tv.showsIndicator(); |
| 238 | } |
| 239 | } |
| 240 | return false; |
| 241 | } |
| 242 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 243 | // callback after fake titlebar is shown |
| 244 | void onShowTitleBar() { |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 245 | showTitleBarIndicator(false); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | // callback after fake titlebar is hidden |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 249 | void onHideTitleBar() { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 250 | Tab tab = mTabControl.getCurrentTab(); |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 251 | WebView w = tab.getWebView(); |
| 252 | if (w != null) { |
| 253 | showTitleBarIndicator(w.getVisibleTitleHeight() == 0); |
| 254 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 257 | // webview scroll listener |
| 258 | |
| 259 | @Override |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 260 | public void onScroll(int visibleTitleHeight) { |
Michael Kolb | 376b541 | 2010-12-15 11:52:57 -0800 | [diff] [blame] | 261 | if (mUseQuickControls) return; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 262 | // isLoading is using the current tab, which initially might not be set yet |
John Reck | dcf911c | 2010-12-22 16:32:31 -0800 | [diff] [blame] | 263 | if (mTabControl.getCurrentTab() != null |
| 264 | && !isLoading()) { |
| 265 | if (visibleTitleHeight == 0) { |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 266 | if (!showsTitleBarIndicator()) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame^] | 267 | mUi.hideTitleBar(); |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 268 | showTitleBarIndicator(true); |
| 269 | } |
John Reck | dcf911c | 2010-12-22 16:32:31 -0800 | [diff] [blame] | 270 | } else { |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 271 | if (showsTitleBarIndicator()) { |
| 272 | showTitleBarIndicator(false); |
| 273 | } |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 277 | |
| 278 | @Override |
| 279 | public void createContextMenu(ContextMenu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 280 | MenuInflater inflater = mActivity.getMenuInflater(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 281 | inflater.inflate(R.menu.title_context, menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 282 | mActivity.onCreateContextMenu(menu, this, null); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 285 | private TabView buildTabView(Tab tab) { |
| 286 | TabView tabview = new TabView(mActivity, tab); |
| 287 | mTabMap.put(tab, tabview); |
| 288 | tabview.setOnClickListener(this); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 289 | return tabview; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 292 | private static Bitmap getDrawableAsBitmap(Drawable drawable, int width, int height) { |
| 293 | Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 294 | Canvas c = new Canvas(b); |
| 295 | drawable.setBounds(0, 0, width, height); |
| 296 | drawable.draw(c); |
| 297 | return b; |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 300 | /** |
| 301 | * View used in the tab bar |
| 302 | */ |
| 303 | class TabView extends LinearLayout implements OnClickListener { |
| 304 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 305 | Tab mTab; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 306 | View mTabContent; |
| 307 | TextView mTitle; |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 308 | View mIndicator; |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 309 | View mIncognito; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 310 | ImageView mIconView; |
| 311 | ImageView mLock; |
| 312 | ImageView mClose; |
| 313 | boolean mSelected; |
| 314 | boolean mInLoad; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 315 | Path mPath; |
| 316 | int[] mWindowPos; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 317 | |
| 318 | /** |
| 319 | * @param context |
| 320 | */ |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 321 | public TabView(Context context, Tab tab) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 322 | super(context); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 323 | setWillNotDraw(false); |
| 324 | mPath = new Path(); |
| 325 | mWindowPos = new int[2]; |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 326 | mTab = tab; |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 327 | setGravity(Gravity.CENTER_VERTICAL); |
| 328 | setOrientation(LinearLayout.HORIZONTAL); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 329 | setPadding(mTabOverlap, 0, mTabSliceWidth, 0); |
Bjorn Bringert | b1402a5 | 2010-10-12 10:53:12 +0100 | [diff] [blame] | 330 | LayoutInflater inflater = LayoutInflater.from(getContext()); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 331 | mTabContent = inflater.inflate(R.layout.tab_title, this, true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 332 | mTitle = (TextView) mTabContent.findViewById(R.id.title); |
| 333 | mIconView = (ImageView) mTabContent.findViewById(R.id.favicon); |
| 334 | mLock = (ImageView) mTabContent.findViewById(R.id.lock); |
| 335 | mClose = (ImageView) mTabContent.findViewById(R.id.close); |
| 336 | mClose.setOnClickListener(this); |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 337 | mIncognito = mTabContent.findViewById(R.id.incognito); |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 338 | mIndicator = mTabContent.findViewById(R.id.chevron); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 339 | mSelected = false; |
| 340 | mInLoad = false; |
| 341 | // update the status |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 342 | updateFromTab(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 345 | void showIndicator(boolean show) { |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 346 | if (mSelected) { |
| 347 | mIndicator.setVisibility(show ? View.VISIBLE : View.GONE); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 348 | LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams(); |
| 349 | if (show) { |
| 350 | lp.width = mTabWidthSelected + mIndicator.getWidth(); |
| 351 | } else { |
| 352 | lp.width = mTabWidthSelected; |
| 353 | } |
| 354 | lp.height = LayoutParams.MATCH_PARENT; |
| 355 | setLayoutParams(lp); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 356 | } else { |
| 357 | mIndicator.setVisibility(View.GONE); |
| 358 | } |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 361 | boolean showsIndicator() { |
| 362 | return (mIndicator.getVisibility() == View.VISIBLE); |
| 363 | } |
| 364 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 365 | @Override |
| 366 | public void onClick(View v) { |
| 367 | if (v == mClose) { |
| 368 | closeTab(); |
| 369 | } |
| 370 | } |
| 371 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 372 | private void updateFromTab() { |
| 373 | String displayTitle = mTab.getTitle(); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 374 | if (displayTitle == null) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 375 | displayTitle = mTab.getUrl(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 376 | } |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 377 | setDisplayTitle(displayTitle); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 378 | setProgress(mTab.getLoadProgress()); |
| 379 | if (mTab.getFavicon() != null) { |
| 380 | setFavicon(renderFavicon(mTab.getFavicon())); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 381 | } |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 382 | if (mTab != null) { |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 383 | mIncognito.setVisibility( |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 384 | mTab.isPrivateBrowsingEnabled() ? |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 385 | View.VISIBLE : View.GONE); |
| 386 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | @Override |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 390 | public void setActivated(boolean selected) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 391 | mSelected = selected; |
| 392 | mClose.setVisibility(mSelected ? View.VISIBLE : View.GONE); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 393 | mIndicator.setVisibility(View.GONE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 394 | mTitle.setTextAppearance(mActivity, mSelected ? |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 395 | R.style.TabTitleSelected : R.style.TabTitleUnselected); |
| 396 | setHorizontalFadingEdgeEnabled(!mSelected); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 397 | super.setActivated(selected); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 398 | LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams(); |
| 399 | lp.width = selected ? mTabWidthSelected : mTabWidthUnselected; |
| 400 | lp.height = LayoutParams.MATCH_PARENT; |
| 401 | setLayoutParams(lp); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void setDisplayTitle(String title) { |
| 405 | mTitle.setText(title); |
| 406 | } |
| 407 | |
| 408 | void setFavicon(Drawable d) { |
| 409 | mIconView.setImageDrawable(d); |
| 410 | } |
| 411 | |
| 412 | void setLock(Drawable d) { |
| 413 | if (null == d) { |
| 414 | mLock.setVisibility(View.GONE); |
| 415 | } else { |
| 416 | mLock.setImageDrawable(d); |
| 417 | mLock.setVisibility(View.VISIBLE); |
| 418 | } |
| 419 | } |
| 420 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 421 | void setProgress(int newProgress) { |
| 422 | if (newProgress >= PROGRESS_MAX) { |
| 423 | mInLoad = false; |
| 424 | } else { |
| 425 | if (!mInLoad && getWindowToken() != null) { |
| 426 | mInLoad = true; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | private void closeTab() { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 432 | if (mTab == mTabControl.getCurrentTab()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 433 | mUiController.closeCurrentTab(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 434 | } else { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 435 | mUiController.closeTab(mTab); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 439 | @Override |
| 440 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 441 | super.onLayout(changed, l, t, r, b); |
| 442 | setTabPath(mPath, 0, 0, r - l, b - t); |
| 443 | } |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 444 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 445 | @Override |
| 446 | protected void dispatchDraw(Canvas canvas) { |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 447 | if (mCurrentTextureWidth != mUi.getContentWidth() || |
| 448 | mCurrentTextureHeight != getHeight()) { |
| 449 | mCurrentTextureWidth = mUi.getContentWidth(); |
| 450 | mCurrentTextureHeight = getHeight(); |
| 451 | |
| 452 | if (mCurrentTextureWidth > 0 && mCurrentTextureHeight > 0) { |
| 453 | Bitmap activeTexture = getDrawableAsBitmap(mActiveDrawable, |
| 454 | mCurrentTextureWidth, mCurrentTextureHeight); |
| 455 | Bitmap inactiveTexture = getDrawableAsBitmap(mInactiveDrawable, |
| 456 | mCurrentTextureWidth, mCurrentTextureHeight); |
| 457 | |
| 458 | mActiveShader = new BitmapShader(activeTexture, |
| 459 | Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); |
| 460 | mActiveShaderPaint.setShader(mActiveShader); |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 461 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 462 | mInactiveShader = new BitmapShader(inactiveTexture, |
| 463 | Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); |
| 464 | mInactiveShaderPaint.setShader(mInactiveShader); |
| 465 | } |
| 466 | } |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 467 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 468 | int state = canvas.save(); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 469 | getLocationInWindow(mWindowPos); |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 470 | Paint paint = mSelected ? mActiveShaderPaint : mInactiveShaderPaint; |
| 471 | drawClipped(canvas, paint, mPath, mWindowPos[0]); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 472 | canvas.restoreToCount(state); |
| 473 | super.dispatchDraw(canvas); |
| 474 | } |
| 475 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 476 | private void drawClipped(Canvas canvas, Paint paint, Path clipPath, int left) { |
| 477 | // TODO: We should change the matrix/shader only when needed |
| 478 | final Matrix matrix = mSelected ? mActiveMatrix : mInactiveMatrix; |
| 479 | matrix.setTranslate(-left, 0.0f); |
| 480 | (mSelected ? mActiveShader : mInactiveShader).setLocalMatrix(matrix); |
| 481 | canvas.drawPath(clipPath, paint); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | private void setTabPath(Path path, int l, int t, int r, int b) { |
| 485 | path.reset(); |
| 486 | path.moveTo(l, b); |
| 487 | path.lineTo(l, t); |
| 488 | path.lineTo(r - mTabSliceWidth, t); |
| 489 | path.lineTo(r, b); |
| 490 | path.close(); |
| 491 | } |
| 492 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 495 | static Drawable createFaviconBackground(Context context) { |
| 496 | PaintDrawable faviconBackground = new PaintDrawable(); |
| 497 | Resources res = context.getResources(); |
| 498 | faviconBackground.getPaint().setColor(context.getResources() |
| 499 | .getColor(R.color.tabFaviconBackground)); |
| 500 | faviconBackground.setCornerRadius( |
| 501 | res.getDimension(R.dimen.tab_favicon_corner_radius)); |
| 502 | return faviconBackground; |
| 503 | } |
| 504 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 505 | private Drawable renderFavicon(Bitmap icon) { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 506 | Drawable[] array = new Drawable[2]; |
| 507 | array[0] = createFaviconBackground(getContext()); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 508 | if (icon == null) { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 509 | array[1] = mGenericFavicon; |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 510 | } else { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 511 | array[1] = new BitmapDrawable(icon); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 512 | } |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 513 | LayerDrawable d = new LayerDrawable(array); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 514 | d.setLayerInset(1, 2, 2, 2, 2); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 515 | return d; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 518 | private void animateTabOut(final Tab tab, final TabView tv) { |
| 519 | ObjectAnimator scalex = ObjectAnimator.ofFloat(tv, "scaleX", 1.0f, 0.0f); |
| 520 | ObjectAnimator scaley = ObjectAnimator.ofFloat(tv, "scaleY", 1.0f, 0.0f); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 521 | ObjectAnimator alpha = ObjectAnimator.ofFloat(tv, "alpha", 1.0f, 0.0f); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 522 | AnimatorSet animator = new AnimatorSet(); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 523 | animator.playTogether(scalex, scaley, alpha); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 524 | animator.setDuration(150); |
| 525 | animator.addListener(new AnimatorListener() { |
| 526 | |
| 527 | @Override |
| 528 | public void onAnimationCancel(Animator animation) { |
| 529 | } |
| 530 | |
| 531 | @Override |
| 532 | public void onAnimationEnd(Animator animation) { |
| 533 | mTabs.removeTab(tv); |
| 534 | mTabMap.remove(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 535 | mUi.onRemoveTabCompleted(tab); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | @Override |
| 539 | public void onAnimationRepeat(Animator animation) { |
| 540 | } |
| 541 | |
| 542 | @Override |
| 543 | public void onAnimationStart(Animator animation) { |
| 544 | } |
| 545 | |
| 546 | }); |
| 547 | animator.start(); |
| 548 | } |
| 549 | |
| 550 | private void animateTabIn(final Tab tab, final TabView tv) { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 551 | ObjectAnimator scalex = ObjectAnimator.ofFloat(tv, "scaleX", 0.0f, 1.0f); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 552 | scalex.setDuration(150); |
| 553 | scalex.addListener(new AnimatorListener() { |
| 554 | |
| 555 | @Override |
| 556 | public void onAnimationCancel(Animator animation) { |
| 557 | } |
| 558 | |
| 559 | @Override |
| 560 | public void onAnimationEnd(Animator animation) { |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 561 | mUi.onAddTabCompleted(tab); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public void onAnimationRepeat(Animator animation) { |
| 566 | } |
| 567 | |
| 568 | @Override |
| 569 | public void onAnimationStart(Animator animation) { |
| 570 | mTabs.addTab(tv); |
| 571 | } |
| 572 | |
| 573 | }); |
| 574 | scalex.start(); |
| 575 | } |
| 576 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 577 | // TabChangeListener implementation |
| 578 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 579 | public void onSetActiveTab(Tab tab) { |
| 580 | mTabs.setSelectedTab(mTabControl.getTabIndex(tab)); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 581 | TabView tv = mTabMap.get(tab); |
| 582 | if (tv != null) { |
| 583 | tv.setProgress(tv.mTab.getLoadProgress()); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 584 | // update the scroll state |
| 585 | WebView webview = tab.getWebView(); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 586 | if (webview != null) { |
| 587 | int h = webview.getVisibleTitleHeight(); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 588 | onScroll(h); |
| 589 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 593 | public void onFavicon(Tab tab, Bitmap favicon) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 594 | TabView tv = mTabMap.get(tab); |
| 595 | if (tv != null) { |
| 596 | tv.setFavicon(renderFavicon(favicon)); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 600 | public void onNewTab(Tab tab) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 601 | TabView tv = buildTabView(tab); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 602 | animateTabIn(tab, tv); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 605 | public void onProgress(Tab tab, int progress) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 606 | TabView tv = mTabMap.get(tab); |
| 607 | if (tv != null) { |
| 608 | tv.setProgress(progress); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 612 | public void onRemoveTab(Tab tab) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 613 | TabView tv = mTabMap.get(tab); |
| 614 | if (tv != null) { |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 615 | animateTabOut(tab, tv); |
| 616 | } else { |
| 617 | mTabMap.remove(tab); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 618 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 621 | public void onUrlAndTitle(Tab tab, String url, String title) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 622 | TabView tv = mTabMap.get(tab); |
| 623 | if (tv != null) { |
| 624 | if (title != null) { |
| 625 | tv.setDisplayTitle(title); |
| 626 | } else if (url != null) { |
| 627 | tv.setDisplayTitle(UrlUtils.stripUrl(url)); |
| 628 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 632 | private boolean isLoading() { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 633 | TabView tv = mTabMap.get(mTabControl.getCurrentTab()); |
| 634 | if (tv != null) { |
| 635 | return tv.mInLoad; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 636 | } else { |
| 637 | return false; |
| 638 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 641 | } |