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 | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 265 | public void onScroll(int visibleTitleHeight, boolean userInitiated) { |
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 | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 271 | if (!showsTitleBarIndicator() |
| 272 | && (!mUi.isEditingUrl() || userInitiated)) { |
Michael Kolb | 7cdc490 | 2011-02-03 17:54:40 -0800 | [diff] [blame] | 273 | mUi.hideTitleBar(); |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 274 | showTitleBarIndicator(true); |
| 275 | } |
John Reck | dcf911c | 2010-12-22 16:32:31 -0800 | [diff] [blame] | 276 | } else { |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 277 | if (showsTitleBarIndicator()) { |
| 278 | showTitleBarIndicator(false); |
| 279 | } |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 280 | } |
| 281 | } |
| 282 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 283 | |
| 284 | @Override |
| 285 | public void createContextMenu(ContextMenu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 286 | MenuInflater inflater = mActivity.getMenuInflater(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 287 | inflater.inflate(R.menu.title_context, menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 288 | mActivity.onCreateContextMenu(menu, this, null); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 291 | private TabView buildTabView(Tab tab) { |
| 292 | TabView tabview = new TabView(mActivity, tab); |
| 293 | mTabMap.put(tab, tabview); |
| 294 | tabview.setOnClickListener(this); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 295 | return tabview; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 298 | private static Bitmap getDrawableAsBitmap(Drawable drawable, int width, int height) { |
| 299 | Bitmap b = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| 300 | Canvas c = new Canvas(b); |
| 301 | drawable.setBounds(0, 0, width, height); |
| 302 | drawable.draw(c); |
| 303 | return b; |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 306 | /** |
| 307 | * View used in the tab bar |
| 308 | */ |
| 309 | class TabView extends LinearLayout implements OnClickListener { |
| 310 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 311 | Tab mTab; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 312 | View mTabContent; |
| 313 | TextView mTitle; |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 314 | View mIndicator; |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 315 | View mIncognito; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 316 | ImageView mIconView; |
| 317 | ImageView mLock; |
| 318 | ImageView mClose; |
| 319 | boolean mSelected; |
| 320 | boolean mInLoad; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 321 | Path mPath; |
Michael Kolb | eb7001c | 2011-02-16 16:07:33 -0800 | [diff] [blame] | 322 | Path mFocusPath; |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 323 | int[] mWindowPos; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 324 | |
| 325 | /** |
| 326 | * @param context |
| 327 | */ |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 328 | public TabView(Context context, Tab tab) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 329 | super(context); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 330 | setWillNotDraw(false); |
| 331 | mPath = new Path(); |
Michael Kolb | eb7001c | 2011-02-16 16:07:33 -0800 | [diff] [blame] | 332 | mFocusPath = new Path(); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 333 | mWindowPos = new int[2]; |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 334 | mTab = tab; |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 335 | setGravity(Gravity.CENTER_VERTICAL); |
| 336 | setOrientation(LinearLayout.HORIZONTAL); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 337 | setPadding(mTabOverlap, 0, mTabSliceWidth, 0); |
Bjorn Bringert | b1402a5 | 2010-10-12 10:53:12 +0100 | [diff] [blame] | 338 | LayoutInflater inflater = LayoutInflater.from(getContext()); |
Michael Kolb | ed21774 | 2010-08-10 17:52:34 -0700 | [diff] [blame] | 339 | mTabContent = inflater.inflate(R.layout.tab_title, this, true); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 340 | mTitle = (TextView) mTabContent.findViewById(R.id.title); |
| 341 | mIconView = (ImageView) mTabContent.findViewById(R.id.favicon); |
| 342 | mLock = (ImageView) mTabContent.findViewById(R.id.lock); |
| 343 | mClose = (ImageView) mTabContent.findViewById(R.id.close); |
| 344 | mClose.setOnClickListener(this); |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 345 | mIncognito = mTabContent.findViewById(R.id.incognito); |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 346 | mIndicator = mTabContent.findViewById(R.id.chevron); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 347 | mSelected = false; |
| 348 | mInLoad = false; |
| 349 | // update the status |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 350 | updateFromTab(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 353 | void showIndicator(boolean show) { |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 354 | if (mSelected) { |
| 355 | mIndicator.setVisibility(show ? View.VISIBLE : View.GONE); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 356 | LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams(); |
| 357 | if (show) { |
| 358 | lp.width = mTabWidthSelected + mIndicator.getWidth(); |
| 359 | } else { |
| 360 | lp.width = mTabWidthSelected; |
| 361 | } |
| 362 | lp.height = LayoutParams.MATCH_PARENT; |
| 363 | setLayoutParams(lp); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 364 | } else { |
| 365 | mIndicator.setVisibility(View.GONE); |
| 366 | } |
Michael Kolb | a0e2a75 | 2010-12-12 15:27:56 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Michael Kolb | 7dad8f0 | 2011-01-21 11:06:18 -0800 | [diff] [blame] | 369 | boolean showsIndicator() { |
| 370 | return (mIndicator.getVisibility() == View.VISIBLE); |
| 371 | } |
| 372 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 373 | @Override |
| 374 | public void onClick(View v) { |
| 375 | if (v == mClose) { |
| 376 | closeTab(); |
| 377 | } |
| 378 | } |
| 379 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 380 | private void updateFromTab() { |
| 381 | String displayTitle = mTab.getTitle(); |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 382 | if (displayTitle == null) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 383 | displayTitle = mTab.getUrl(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 384 | } |
John Reck | 30c714c | 2010-12-16 17:30:34 -0800 | [diff] [blame] | 385 | setDisplayTitle(displayTitle); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 386 | setProgress(mTab.getLoadProgress()); |
| 387 | if (mTab.getFavicon() != null) { |
| 388 | setFavicon(renderFavicon(mTab.getFavicon())); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 389 | } |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 390 | if (mTab != null) { |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 391 | mIncognito.setVisibility( |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 392 | mTab.isPrivateBrowsingEnabled() ? |
Michael Kolb | ae62fd4 | 2010-08-18 16:33:28 -0700 | [diff] [blame] | 393 | View.VISIBLE : View.GONE); |
| 394 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | @Override |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 398 | public void setActivated(boolean selected) { |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 399 | mSelected = selected; |
| 400 | mClose.setVisibility(mSelected ? View.VISIBLE : View.GONE); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 401 | mIndicator.setVisibility(View.GONE); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 402 | mTitle.setTextAppearance(mActivity, mSelected ? |
Michael Kolb | c7485ae | 2010-09-03 10:10:58 -0700 | [diff] [blame] | 403 | R.style.TabTitleSelected : R.style.TabTitleUnselected); |
| 404 | setHorizontalFadingEdgeEnabled(!mSelected); |
Michael Kolb | b7b115e | 2010-09-25 16:59:37 -0700 | [diff] [blame] | 405 | super.setActivated(selected); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 406 | LayoutParams lp = (LinearLayout.LayoutParams) getLayoutParams(); |
| 407 | lp.width = selected ? mTabWidthSelected : mTabWidthUnselected; |
| 408 | lp.height = LayoutParams.MATCH_PARENT; |
| 409 | setLayoutParams(lp); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 410 | setFocusable(!selected); |
| 411 | postInvalidate(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void setDisplayTitle(String title) { |
| 415 | mTitle.setText(title); |
| 416 | } |
| 417 | |
| 418 | void setFavicon(Drawable d) { |
| 419 | mIconView.setImageDrawable(d); |
| 420 | } |
| 421 | |
| 422 | void setLock(Drawable d) { |
| 423 | if (null == d) { |
| 424 | mLock.setVisibility(View.GONE); |
| 425 | } else { |
| 426 | mLock.setImageDrawable(d); |
| 427 | mLock.setVisibility(View.VISIBLE); |
| 428 | } |
| 429 | } |
| 430 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 431 | void setProgress(int newProgress) { |
| 432 | if (newProgress >= PROGRESS_MAX) { |
| 433 | mInLoad = false; |
| 434 | } else { |
| 435 | if (!mInLoad && getWindowToken() != null) { |
| 436 | mInLoad = true; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | private void closeTab() { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 442 | if (mTab == mTabControl.getCurrentTab()) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 443 | mUiController.closeCurrentTab(); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 444 | } else { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 445 | mUiController.closeTab(mTab); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 449 | @Override |
| 450 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 451 | super.onLayout(changed, l, t, r, b); |
| 452 | setTabPath(mPath, 0, 0, r - l, b - t); |
Michael Kolb | eb7001c | 2011-02-16 16:07:33 -0800 | [diff] [blame] | 453 | setFocusPath(mFocusPath, 0, 0, r - l, b - t); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 454 | } |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 455 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 456 | @Override |
| 457 | protected void dispatchDraw(Canvas canvas) { |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 458 | if (mCurrentTextureWidth != mUi.getContentWidth() || |
| 459 | mCurrentTextureHeight != getHeight()) { |
| 460 | mCurrentTextureWidth = mUi.getContentWidth(); |
| 461 | mCurrentTextureHeight = getHeight(); |
| 462 | |
| 463 | if (mCurrentTextureWidth > 0 && mCurrentTextureHeight > 0) { |
| 464 | Bitmap activeTexture = getDrawableAsBitmap(mActiveDrawable, |
| 465 | mCurrentTextureWidth, mCurrentTextureHeight); |
| 466 | Bitmap inactiveTexture = getDrawableAsBitmap(mInactiveDrawable, |
| 467 | mCurrentTextureWidth, mCurrentTextureHeight); |
| 468 | |
| 469 | mActiveShader = new BitmapShader(activeTexture, |
| 470 | Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); |
| 471 | mActiveShaderPaint.setShader(mActiveShader); |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 472 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 473 | mInactiveShader = new BitmapShader(inactiveTexture, |
| 474 | Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); |
| 475 | mInactiveShaderPaint.setShader(mInactiveShader); |
| 476 | } |
| 477 | } |
Michael Kolb | b4cafc5 | 2011-01-12 16:55:04 -0800 | [diff] [blame] | 478 | |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 479 | int state = canvas.save(); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 480 | getLocationInWindow(mWindowPos); |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 481 | Paint paint = mSelected ? mActiveShaderPaint : mInactiveShaderPaint; |
| 482 | drawClipped(canvas, paint, mPath, mWindowPos[0]); |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 483 | canvas.restoreToCount(state); |
| 484 | super.dispatchDraw(canvas); |
| 485 | } |
| 486 | |
Romain Guy | c837321 | 2011-01-07 19:15:16 -0800 | [diff] [blame] | 487 | private void drawClipped(Canvas canvas, Paint paint, Path clipPath, int left) { |
| 488 | // TODO: We should change the matrix/shader only when needed |
| 489 | final Matrix matrix = mSelected ? mActiveMatrix : mInactiveMatrix; |
| 490 | matrix.setTranslate(-left, 0.0f); |
| 491 | (mSelected ? mActiveShader : mInactiveShader).setLocalMatrix(matrix); |
| 492 | canvas.drawPath(clipPath, paint); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 493 | if (isFocused()) { |
Michael Kolb | eb7001c | 2011-02-16 16:07:33 -0800 | [diff] [blame] | 494 | canvas.drawPath(mFocusPath, mFocusPaint); |
Michael Kolb | dc2ee1b | 2011-02-14 14:34:40 -0800 | [diff] [blame] | 495 | } |
Michael Kolb | 2b5a13a | 2010-12-09 14:13:42 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | private void setTabPath(Path path, int l, int t, int r, int b) { |
| 499 | path.reset(); |
| 500 | path.moveTo(l, b); |
| 501 | path.lineTo(l, t); |
| 502 | path.lineTo(r - mTabSliceWidth, t); |
| 503 | path.lineTo(r, b); |
| 504 | path.close(); |
| 505 | } |
| 506 | |
Michael Kolb | eb7001c | 2011-02-16 16:07:33 -0800 | [diff] [blame] | 507 | private void setFocusPath(Path path, int l, int t, int r, int b) { |
| 508 | path.reset(); |
| 509 | path.moveTo(l, b); |
| 510 | path.lineTo(l, t); |
| 511 | path.lineTo(r - mTabSliceWidth, t); |
| 512 | path.lineTo(r, b); |
| 513 | } |
| 514 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 517 | static Drawable createFaviconBackground(Context context) { |
| 518 | PaintDrawable faviconBackground = new PaintDrawable(); |
| 519 | Resources res = context.getResources(); |
| 520 | faviconBackground.getPaint().setColor(context.getResources() |
| 521 | .getColor(R.color.tabFaviconBackground)); |
| 522 | faviconBackground.setCornerRadius( |
| 523 | res.getDimension(R.dimen.tab_favicon_corner_radius)); |
| 524 | return faviconBackground; |
| 525 | } |
| 526 | |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 527 | private Drawable renderFavicon(Bitmap icon) { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 528 | Drawable[] array = new Drawable[2]; |
| 529 | array[0] = createFaviconBackground(getContext()); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 530 | if (icon == null) { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 531 | array[1] = mGenericFavicon; |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 532 | } else { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 533 | array[1] = new BitmapDrawable(icon); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 534 | } |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 535 | LayerDrawable d = new LayerDrawable(array); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 536 | d.setLayerInset(1, 2, 2, 2, 2); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 537 | return d; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 540 | private void animateTabOut(final Tab tab, final TabView tv) { |
| 541 | ObjectAnimator scalex = ObjectAnimator.ofFloat(tv, "scaleX", 1.0f, 0.0f); |
| 542 | ObjectAnimator scaley = ObjectAnimator.ofFloat(tv, "scaleY", 1.0f, 0.0f); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 543 | ObjectAnimator alpha = ObjectAnimator.ofFloat(tv, "alpha", 1.0f, 0.0f); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 544 | AnimatorSet animator = new AnimatorSet(); |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 545 | animator.playTogether(scalex, scaley, alpha); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 546 | animator.setDuration(150); |
| 547 | animator.addListener(new AnimatorListener() { |
| 548 | |
| 549 | @Override |
| 550 | public void onAnimationCancel(Animator animation) { |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public void onAnimationEnd(Animator animation) { |
| 555 | mTabs.removeTab(tv); |
| 556 | mTabMap.remove(tab); |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 557 | mUi.onRemoveTabCompleted(tab); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | @Override |
| 561 | public void onAnimationRepeat(Animator animation) { |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public void onAnimationStart(Animator animation) { |
| 566 | } |
| 567 | |
| 568 | }); |
| 569 | animator.start(); |
| 570 | } |
| 571 | |
| 572 | private void animateTabIn(final Tab tab, final TabView tv) { |
Michael Kolb | 49f1583 | 2011-01-25 15:02:27 -0800 | [diff] [blame] | 573 | ObjectAnimator scalex = ObjectAnimator.ofFloat(tv, "scaleX", 0.0f, 1.0f); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 574 | scalex.setDuration(150); |
| 575 | scalex.addListener(new AnimatorListener() { |
| 576 | |
| 577 | @Override |
| 578 | public void onAnimationCancel(Animator animation) { |
| 579 | } |
| 580 | |
| 581 | @Override |
| 582 | public void onAnimationEnd(Animator animation) { |
Michael Kolb | 8814d73 | 2011-01-26 11:22:30 -0800 | [diff] [blame] | 583 | mUi.onAddTabCompleted(tab); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | @Override |
| 587 | public void onAnimationRepeat(Animator animation) { |
| 588 | } |
| 589 | |
| 590 | @Override |
| 591 | public void onAnimationStart(Animator animation) { |
| 592 | mTabs.addTab(tv); |
| 593 | } |
| 594 | |
| 595 | }); |
| 596 | scalex.start(); |
| 597 | } |
| 598 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 599 | // TabChangeListener implementation |
| 600 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 601 | public void onSetActiveTab(Tab tab) { |
| 602 | mTabs.setSelectedTab(mTabControl.getTabIndex(tab)); |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 603 | TabView tv = mTabMap.get(tab); |
| 604 | if (tv != null) { |
| 605 | tv.setProgress(tv.mTab.getLoadProgress()); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 606 | // update the scroll state |
| 607 | WebView webview = tab.getWebView(); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 608 | if (webview != null) { |
| 609 | int h = webview.getVisibleTitleHeight(); |
Michael Kolb | 5ee018e | 2011-02-18 15:47:21 -0800 | [diff] [blame] | 610 | onScroll(h, true); |
Michael Kolb | 6a85e2a | 2010-12-13 18:12:46 -0800 | [diff] [blame] | 611 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 615 | public void onFavicon(Tab tab, Bitmap favicon) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 616 | TabView tv = mTabMap.get(tab); |
| 617 | if (tv != null) { |
| 618 | tv.setFavicon(renderFavicon(favicon)); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 622 | public void onNewTab(Tab tab) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 623 | TabView tv = buildTabView(tab); |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 624 | animateTabIn(tab, tv); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 627 | public void onProgress(Tab tab, int progress) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 628 | TabView tv = mTabMap.get(tab); |
| 629 | if (tv != null) { |
| 630 | tv.setProgress(progress); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 634 | public void onRemoveTab(Tab tab) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 635 | TabView tv = mTabMap.get(tab); |
| 636 | if (tv != null) { |
Michael Kolb | 2d59c32 | 2011-01-25 13:18:55 -0800 | [diff] [blame] | 637 | animateTabOut(tab, tv); |
| 638 | } else { |
| 639 | mTabMap.remove(tab); |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 640 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 643 | public void onUrlAndTitle(Tab tab, String url, String title) { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 644 | TabView tv = mTabMap.get(tab); |
| 645 | if (tv != null) { |
| 646 | if (title != null) { |
| 647 | tv.setDisplayTitle(title); |
| 648 | } else if (url != null) { |
| 649 | tv.setDisplayTitle(UrlUtils.stripUrl(url)); |
| 650 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 654 | private boolean isLoading() { |
Michael Kolb | 94827b6 | 2011-01-08 14:23:45 -0800 | [diff] [blame] | 655 | TabView tv = mTabMap.get(mTabControl.getCurrentTab()); |
| 656 | if (tv != null) { |
| 657 | return tv.mInLoad; |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 658 | } else { |
| 659 | return false; |
| 660 | } |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 663 | } |