John Reck | 0f602f3 | 2011-07-07 15:38:43 -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 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 18 | |
| 19 | import android.animation.Animator; |
| 20 | import android.animation.Animator.AnimatorListener; |
| 21 | import android.animation.ObjectAnimator; |
| 22 | import android.content.Context; |
Michael Kolb | 57059a8 | 2012-04-30 14:32:03 -0700 | [diff] [blame] | 23 | import android.content.res.Configuration; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 24 | import android.content.res.Resources; |
Panos Thomas | 752ce59 | 2014-10-16 13:00:35 -0700 | [diff] [blame] | 25 | import android.graphics.Rect; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 26 | import android.view.LayoutInflater; |
| 27 | import android.view.View; |
| 28 | import android.view.ViewGroup; |
Ben Murdoch | d51bb57 | 2011-08-17 20:42:02 +0100 | [diff] [blame] | 29 | import android.view.ViewStub; |
Kulanthaivel Palanichamy | 846bb0f | 2014-12-02 13:50:34 -0800 | [diff] [blame] | 30 | import android.view.ViewTreeObserver; |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 31 | import android.view.accessibility.AccessibilityManager; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 32 | import android.view.animation.DecelerateInterpolator; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 33 | import org.codeaurora.swe.WebView; |
| 34 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 35 | import android.widget.FrameLayout; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * Base class for a title bar used by the browser. |
| 39 | */ |
Kulanthaivel Palanichamy | 846bb0f | 2014-12-02 13:50:34 -0800 | [diff] [blame] | 40 | public class TitleBar extends FrameLayout implements ViewTreeObserver.OnPreDrawListener { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 41 | |
| 42 | private static final int PROGRESS_MAX = 100; |
| 43 | private static final float ANIM_TITLEBAR_DECELERATE = 2.5f; |
| 44 | |
| 45 | private UiController mUiController; |
| 46 | private BaseUi mBaseUi; |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 47 | private FrameLayout mContentView; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 48 | private PageProgressView mProgress; |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 49 | private AccessibilityManager mAccessibilityManager; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 50 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 51 | private NavigationBarBase mNavBar; |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 52 | private SnapshotBar mSnapshotBar; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 53 | |
| 54 | //state |
| 55 | private boolean mShowing; |
| 56 | private boolean mInLoad; |
| 57 | private boolean mSkipTitleBarAnimations; |
| 58 | private Animator mTitleBarAnimator; |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 59 | private boolean mIsFixedTitleBar; |
Kulanthaivel Palanichamy | 846bb0f | 2014-12-02 13:50:34 -0800 | [diff] [blame] | 60 | private float mCurrentTranslationY; |
| 61 | private boolean mUpdateTranslationY = false; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 62 | |
| 63 | public TitleBar(Context context, UiController controller, BaseUi ui, |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 64 | FrameLayout contentView) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 65 | super(context, null); |
| 66 | mUiController = controller; |
| 67 | mBaseUi = ui; |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 68 | mContentView = contentView; |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 69 | mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 70 | initLayout(context); |
John Reck | 0f9aaeb | 2012-05-23 14:40:19 -0700 | [diff] [blame] | 71 | setFixedTitleBar(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | private void initLayout(Context context) { |
| 75 | LayoutInflater factory = LayoutInflater.from(context); |
| 76 | factory.inflate(R.layout.title_bar, this); |
| 77 | mProgress = (PageProgressView) findViewById(R.id.progress); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 78 | mNavBar = (NavigationBarBase) findViewById(R.id.taburlbar); |
| 79 | mNavBar.setTitleBar(this); |
Ben Murdoch | d51bb57 | 2011-08-17 20:42:02 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Ben Murdoch | d51bb57 | 2011-08-17 20:42:02 +0100 | [diff] [blame] | 82 | private void inflateSnapshotBar() { |
| 83 | if (mSnapshotBar != null) { |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | ViewStub stub = (ViewStub) findViewById(R.id.snapshotbar_stub); |
| 88 | mSnapshotBar = (SnapshotBar) stub.inflate(); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 89 | mSnapshotBar.setTitleBar(this); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Michael Kolb | 57059a8 | 2012-04-30 14:32:03 -0700 | [diff] [blame] | 92 | @Override |
| 93 | protected void onConfigurationChanged(Configuration config) { |
| 94 | super.onConfigurationChanged(config); |
John Reck | 0f9aaeb | 2012-05-23 14:40:19 -0700 | [diff] [blame] | 95 | setFixedTitleBar(); |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 100 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Vivek Sekhar | 8a66078 | 2014-10-27 17:00:53 -0700 | [diff] [blame] | 101 | mBaseUi.setContentViewMarginTop(0); |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Kulanthaivel Palanichamy | 846bb0f | 2014-12-02 13:50:34 -0800 | [diff] [blame] | 104 | @Override |
| 105 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 106 | super.onLayout(changed, left, top, right, bottom); |
| 107 | |
| 108 | mCurrentTranslationY = this.getTranslationY(); |
| 109 | if (mCurrentTranslationY < 0) { |
| 110 | mUpdateTranslationY = true; |
| 111 | this.setTranslationY(0); |
| 112 | |
| 113 | final ViewTreeObserver observer = this.getViewTreeObserver(); |
| 114 | observer.addOnPreDrawListener(this); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public boolean onPreDraw() { |
| 120 | if (mUpdateTranslationY) { |
| 121 | this.setTranslationY(mCurrentTranslationY); |
| 122 | mUpdateTranslationY = false; |
| 123 | } |
| 124 | final ViewTreeObserver observer = this.getViewTreeObserver(); |
| 125 | observer.removeOnPreDrawListener(this); |
| 126 | return true; |
| 127 | } |
| 128 | |
John Reck | 0f9aaeb | 2012-05-23 14:40:19 -0700 | [diff] [blame] | 129 | private void setFixedTitleBar() { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 130 | boolean isFixed = !getContext().getResources().getBoolean(R.bool.hide_title); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 131 | |
Vivek Sekhar | 8057214 | 2014-12-01 10:54:22 -0800 | [diff] [blame] | 132 | isFixed |= mAccessibilityManager.isEnabled() && |
| 133 | mAccessibilityManager.isTouchExplorationEnabled(); |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 134 | // If getParent() returns null, we are initializing |
| 135 | ViewGroup parent = (ViewGroup)getParent(); |
| 136 | if (mIsFixedTitleBar == isFixed && parent != null) return; |
| 137 | mIsFixedTitleBar = isFixed; |
| 138 | setSkipTitleBarAnimations(true); |
| 139 | show(); |
| 140 | setSkipTitleBarAnimations(false); |
| 141 | if (parent != null) { |
| 142 | parent.removeView(this); |
| 143 | } |
Vivek Sekhar | 8a66078 | 2014-10-27 17:00:53 -0700 | [diff] [blame] | 144 | mContentView.addView(this, makeLayoutParams()); |
| 145 | mBaseUi.setContentViewMarginTop(0); |
Michael Kolb | 57059a8 | 2012-04-30 14:32:03 -0700 | [diff] [blame] | 146 | } |
| 147 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 148 | public BaseUi getUi() { |
| 149 | return mBaseUi; |
| 150 | } |
| 151 | |
| 152 | public UiController getUiController() { |
| 153 | return mUiController; |
| 154 | } |
| 155 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 156 | void setShowProgressOnly(boolean progress) { |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 157 | if (progress && !wantsToBeVisible()) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 158 | mNavBar.setVisibility(View.GONE); |
| 159 | } else { |
| 160 | mNavBar.setVisibility(View.VISIBLE); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | void setSkipTitleBarAnimations(boolean skip) { |
| 165 | mSkipTitleBarAnimations = skip; |
| 166 | } |
| 167 | |
| 168 | void setupTitleBarAnimator(Animator animator) { |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 169 | Resources res = getContext().getResources(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 170 | int duration = res.getInteger(R.integer.titlebar_animation_duration); |
| 171 | animator.setInterpolator(new DecelerateInterpolator( |
| 172 | ANIM_TITLEBAR_DECELERATE)); |
| 173 | animator.setDuration(duration); |
| 174 | } |
| 175 | |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 176 | //Disable stock autohide behavior in favor of top controls |
| 177 | private static final boolean bOldStyleAutoHideDisabled = true; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 178 | void show() { |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 179 | cancelTitleBarAnimation(false); |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 180 | if (mSkipTitleBarAnimations) { |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 181 | this.setVisibility(View.VISIBLE); |
| 182 | this.setTranslationY(0); |
Vivek Sekhar | 8a66078 | 2014-10-27 17:00:53 -0700 | [diff] [blame] | 183 | // reaffirm top-controls |
| 184 | if (isFixed() || isInLoad()) |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 185 | showTopControls(false); |
Vivek Sekhar | 8a66078 | 2014-10-27 17:00:53 -0700 | [diff] [blame] | 186 | else |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 187 | enableTopControls(true); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 188 | } else if (!bOldStyleAutoHideDisabled) { |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 189 | int visibleHeight = getVisibleTitleHeight(); |
| 190 | float startPos = (-getEmbeddedHeight() + visibleHeight); |
| 191 | if (getTranslationY() != 0) { |
| 192 | startPos = Math.max(startPos, getTranslationY()); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 193 | } |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 194 | mTitleBarAnimator = ObjectAnimator.ofFloat(this, |
| 195 | "translationY", |
| 196 | startPos, 0); |
| 197 | setupTitleBarAnimator(mTitleBarAnimator); |
| 198 | mTitleBarAnimator.start(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 199 | } |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 200 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 201 | mShowing = true; |
| 202 | } |
| 203 | |
| 204 | void hide() { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 205 | if (mIsFixedTitleBar || bOldStyleAutoHideDisabled) return; |
| 206 | if (!mSkipTitleBarAnimations) { |
| 207 | cancelTitleBarAnimation(false); |
| 208 | int visibleHeight = getVisibleTitleHeight(); |
| 209 | mTitleBarAnimator = ObjectAnimator.ofFloat(this, |
| 210 | "translationY", getTranslationY(), |
| 211 | (-getEmbeddedHeight() + visibleHeight)); |
| 212 | mTitleBarAnimator.addListener(mHideTileBarAnimatorListener); |
| 213 | setupTitleBarAnimator(mTitleBarAnimator); |
| 214 | mTitleBarAnimator.start(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 215 | } else { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 216 | onScrollChanged(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 217 | } |
| 218 | mShowing = false; |
| 219 | } |
| 220 | |
| 221 | boolean isShowing() { |
| 222 | return mShowing; |
| 223 | } |
| 224 | |
| 225 | void cancelTitleBarAnimation(boolean reset) { |
| 226 | if (mTitleBarAnimator != null) { |
| 227 | mTitleBarAnimator.cancel(); |
| 228 | mTitleBarAnimator = null; |
| 229 | } |
| 230 | if (reset) { |
| 231 | setTranslationY(0); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | private AnimatorListener mHideTileBarAnimatorListener = new AnimatorListener() { |
| 236 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 237 | @Override |
| 238 | public void onAnimationStart(Animator animation) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | @Override |
| 242 | public void onAnimationRepeat(Animator animation) { |
| 243 | } |
| 244 | |
| 245 | @Override |
| 246 | public void onAnimationEnd(Animator animation) { |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 247 | // update position |
| 248 | onScrollChanged(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void onAnimationCancel(Animator animation) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 253 | } |
| 254 | }; |
| 255 | |
| 256 | private int getVisibleTitleHeight() { |
| 257 | Tab tab = mBaseUi.getActiveTab(); |
| 258 | WebView webview = tab != null ? tab.getWebView() : null; |
| 259 | return webview != null ? webview.getVisibleTitleHeight() : 0; |
| 260 | } |
| 261 | |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 262 | protected void hideTopControls(boolean animate) { |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 263 | Tab tab = mBaseUi.getActiveTab(); |
| 264 | WebView view = tab != null ? tab.getWebView() : null; |
| 265 | if (view != null) |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 266 | view.updateTopControls(true, false, animate); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 269 | protected void showTopControls(boolean animate) { |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 270 | Tab tab = mBaseUi.getActiveTab(); |
| 271 | WebView view = tab != null ? tab.getWebView() : null; |
| 272 | if (view != null) |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 273 | view.updateTopControls(false, true, animate); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 276 | protected void enableTopControls(boolean animate) { |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 277 | Tab tab = mBaseUi.getActiveTab(); |
| 278 | WebView view = tab != null ? tab.getWebView() : null; |
| 279 | if (view != null) |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 280 | view.updateTopControls(true, true, animate); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 284 | /** |
| 285 | * Update the progress, from 0 to 100. |
| 286 | */ |
| 287 | public void setProgress(int newProgress) { |
| 288 | if (newProgress >= PROGRESS_MAX) { |
| 289 | mProgress.setProgress(PageProgressView.MAX_PROGRESS); |
| 290 | mProgress.setVisibility(View.GONE); |
| 291 | mInLoad = false; |
| 292 | mNavBar.onProgressStopped(); |
| 293 | // check if needs to be hidden |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 294 | if (!isEditingUrl() && !wantsToBeVisible()) { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 295 | mBaseUi.showTitleBarForDuration(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 296 | } |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 297 | |
| 298 | //onPageFinished |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 299 | showTopControls(false); |
Vivek Sekhar | 6497d3e | 2015-03-24 12:00:06 -0700 | [diff] [blame] | 300 | if(!isFixed()) |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 301 | enableTopControls(true); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 302 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 303 | } else { |
| 304 | if (!mInLoad) { |
| 305 | mProgress.setVisibility(View.VISIBLE); |
| 306 | mInLoad = true; |
| 307 | mNavBar.onProgressStarted(); |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 308 | mProgress.onProgressStarted(); |
Tarun Nainani | 8eb0091 | 2014-07-17 12:28:32 -0700 | [diff] [blame] | 309 | //onPageStarted |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 310 | } |
| 311 | mProgress.setProgress(newProgress * PageProgressView.MAX_PROGRESS |
| 312 | / PROGRESS_MAX); |
| 313 | if (!mShowing) { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 314 | show(); |
| 315 | } |
Vivek Sekhar | e337acf | 2015-04-02 21:00:48 -0700 | [diff] [blame] | 316 | showTopControls(false); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | public int getEmbeddedHeight() { |
Vivek Sekhar | 3bec6a3 | 2014-10-22 17:03:42 -0700 | [diff] [blame] | 321 | if (mIsFixedTitleBar) return 0; |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 322 | return calculateEmbeddedHeight(); |
| 323 | } |
| 324 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 325 | public boolean isFixed() { |
| 326 | return mIsFixedTitleBar; |
| 327 | } |
| 328 | |
| 329 | int calculateEmbeddedHeight() { |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 330 | int height = mNavBar.getHeight(); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 331 | return height; |
| 332 | } |
| 333 | |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 334 | public boolean wantsToBeVisible() { |
Bijan Amirzada | 289e1e6 | 2014-04-15 11:53:48 -0700 | [diff] [blame] | 335 | return (mSnapshotBar != null && mSnapshotBar.getVisibility() == View.VISIBLE |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 336 | && mSnapshotBar.isAnimating()); |
| 337 | } |
| 338 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 339 | public boolean isEditingUrl() { |
| 340 | return mNavBar.isEditingUrl(); |
| 341 | } |
| 342 | |
| 343 | public WebView getCurrentWebView() { |
| 344 | Tab t = mBaseUi.getActiveTab(); |
| 345 | if (t != null) { |
| 346 | return t.getWebView(); |
| 347 | } else { |
| 348 | return null; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | public PageProgressView getProgressView() { |
| 353 | return mProgress; |
| 354 | } |
| 355 | |
| 356 | public NavigationBarBase getNavigationBar() { |
| 357 | return mNavBar; |
| 358 | } |
| 359 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 360 | public boolean isInLoad() { |
| 361 | return mInLoad; |
| 362 | } |
| 363 | |
| 364 | private ViewGroup.LayoutParams makeLayoutParams() { |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 365 | return new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 366 | LayoutParams.WRAP_CONTENT); |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | @Override |
Panos Thomas | 752ce59 | 2014-10-16 13:00:35 -0700 | [diff] [blame] | 370 | public boolean requestFocus(int direction, Rect previouslyFocusedRect) { |
| 371 | return mBaseUi.isCustomViewShowing() ? false : |
| 372 | super.requestFocus(direction, previouslyFocusedRect); |
| 373 | } |
| 374 | |
| 375 | @Override |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 376 | public View focusSearch(View focused, int dir) { |
John Reck | fcb6095 | 2012-05-30 09:45:28 -0700 | [diff] [blame] | 377 | WebView web = getCurrentWebView(); |
John Reck | d70419a | 2012-05-30 16:09:17 -0700 | [diff] [blame] | 378 | if (FOCUS_DOWN == dir && hasFocus() && web != null |
John Reck | fcb6095 | 2012-05-30 09:45:28 -0700 | [diff] [blame] | 379 | && web.hasFocusable() && web.getParent() != null) { |
| 380 | return web; |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 381 | } |
| 382 | return super.focusSearch(focused, dir); |
| 383 | } |
| 384 | |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 385 | public void onTabDataChanged(Tab tab) { |
Ben Murdoch | d51bb57 | 2011-08-17 20:42:02 +0100 | [diff] [blame] | 386 | if (mSnapshotBar != null) { |
| 387 | mSnapshotBar.onTabDataChanged(tab); |
| 388 | } |
| 389 | |
Ze G Riande | 2a675c2 | 2015-06-03 11:15:24 -0700 | [diff] [blame] | 390 | if (tab.isSnapshot() || tab.isDistilled()) { |
Ben Murdoch | d51bb57 | 2011-08-17 20:42:02 +0100 | [diff] [blame] | 391 | inflateSnapshotBar(); |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 392 | mSnapshotBar.setVisibility(VISIBLE); |
| 393 | mNavBar.setVisibility(GONE); |
Ze G Riande | 2a675c2 | 2015-06-03 11:15:24 -0700 | [diff] [blame] | 394 | if (tab.isDistilled()) { |
| 395 | mSnapshotBar.setTitle(tab.getWebView().getTitle()); |
| 396 | mSnapshotBar.setDate(tab.getNonDistilledUrl()); |
| 397 | mSnapshotBar.setSnapshoticonVisibility(View.GONE); |
| 398 | mSnapshotBar.setFaviconVisibility(View.GONE); |
| 399 | mSnapshotBar.setReadericonVisibility(View.VISIBLE); |
| 400 | } else { |
| 401 | mSnapshotBar.setSnapshoticonVisibility(View.VISIBLE); |
| 402 | mSnapshotBar.setFaviconVisibility(View.VISIBLE); |
| 403 | mSnapshotBar.setReadericonVisibility(View.GONE); |
| 404 | } |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 405 | } else { |
Ben Murdoch | d51bb57 | 2011-08-17 20:42:02 +0100 | [diff] [blame] | 406 | if (mSnapshotBar != null) { |
| 407 | mSnapshotBar.setVisibility(GONE); |
| 408 | } |
John Reck | ef654f1 | 2011-07-12 16:42:08 -0700 | [diff] [blame] | 409 | mNavBar.setVisibility(VISIBLE); |
| 410 | } |
| 411 | } |
| 412 | |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 413 | public void onScrollChanged() { |
John Reck | 2711fab | 2012-05-18 21:38:59 -0700 | [diff] [blame] | 414 | if (!mShowing && !mIsFixedTitleBar) { |
Michael Kolb | 4923c22 | 2012-04-02 16:18:36 -0700 | [diff] [blame] | 415 | setTranslationY(getVisibleTitleHeight() - getEmbeddedHeight()); |
| 416 | } |
| 417 | } |
| 418 | |
John Reck | 1cc1d1d | 2012-09-04 18:13:51 -0700 | [diff] [blame] | 419 | public void onResume() { |
| 420 | setFixedTitleBar(); |
| 421 | } |
| 422 | |
John Reck | 0f602f3 | 2011-07-07 15:38:43 -0700 | [diff] [blame] | 423 | } |