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