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