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