blob: 92c5d46812d6e8fd66c487cf183b8dc235399bce [file] [log] [blame]
Michael Kolb8233fac2010-10-26 16:08:53 -07001/*
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 Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
Michael Kolb8233fac2010-10-26 16:08:53 -070018
Michael Kolb8233fac2010-10-26 16:08:53 -070019import android.app.Activity;
Michael Kolb53ed62c2011-10-04 16:18:44 -070020import android.content.Context;
John Reckd3e4d5b2011-07-13 15:48:43 -070021import android.content.Intent;
Michael Kolb8233fac2010-10-26 16:08:53 -070022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Bitmap;
25import android.graphics.BitmapFactory;
Michael Kolb5a4372f2011-04-29 13:53:10 -070026import android.graphics.Color;
27import android.graphics.drawable.BitmapDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070028import android.graphics.drawable.Drawable;
Michael Kolb5a4372f2011-04-29 13:53:10 -070029import android.graphics.drawable.LayerDrawable;
30import android.graphics.drawable.PaintDrawable;
Michael Kolb8233fac2010-10-26 16:08:53 -070031import android.os.Bundle;
John Reck5d43ce82011-06-21 17:16:51 -070032import android.os.Handler;
33import android.os.Message;
Michael Kolb8233fac2010-10-26 16:08:53 -070034import android.text.TextUtils;
Bijan Amirzada357ec8a2014-04-08 14:19:10 -070035import android.view.ActionMode;
Michael Kolb8233fac2010-10-26 16:08:53 -070036import android.view.Gravity;
37import android.view.LayoutInflater;
38import android.view.Menu;
Michael Kolb3ca12752011-07-20 13:52:25 -070039import android.view.MenuItem;
Michael Kolb31065b12011-10-06 13:51:32 -070040import android.view.MotionEvent;
Michael Kolb8233fac2010-10-26 16:08:53 -070041import android.view.View;
Michael Kolb1514bb72010-11-22 09:11:48 -080042import android.view.View.OnClickListener;
Michael Kolb8233fac2010-10-26 16:08:53 -070043import android.view.ViewGroup;
Michael Kolb1514bb72010-11-22 09:11:48 -080044import android.view.ViewGroup.LayoutParams;
Michael Kolbc5675ad2011-10-21 13:34:28 -070045import android.view.Window;
Michael Kolb8233fac2010-10-26 16:08:53 -070046import android.view.WindowManager;
Michael Kolb3a696282010-12-05 13:23:24 -080047import android.view.inputmethod.InputMethodManager;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080048import android.webkit.WebChromeClient.CustomViewCallback;
Michael Kolb8233fac2010-10-26 16:08:53 -070049import android.widget.FrameLayout;
Michael Kolb1514bb72010-11-22 09:11:48 -080050import android.widget.ImageButton;
Michael Kolb8233fac2010-10-26 16:08:53 -070051import android.widget.LinearLayout;
52import android.widget.Toast;
Tarun Nainani8eb00912014-07-17 12:28:32 -070053import android.content.res.TypedArray;
Bijan Amirzada41242f22014-03-21 12:12:18 -070054import com.android.browser.R;
55import com.android.browser.Tab.SecurityState;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080056
57import org.codeaurora.swe.WebView;
John Reckbf2ec202011-06-29 17:47:38 -070058
Michael Kolb1bf23132010-11-19 12:55:12 -080059import java.util.List;
60
Michael Kolb8233fac2010-10-26 16:08:53 -070061/**
62 * UI interface definitions
63 */
John Reck718a24d2011-08-12 11:08:30 -070064public abstract class BaseUi implements UI {
Michael Kolb8233fac2010-10-26 16:08:53 -070065
Enrico Ros1f5a0952014-11-18 20:15:48 -080066 protected static final boolean ENABLE_BORDER_AROUND_FAVICON = false;
Michael Kolb8233fac2010-10-26 16:08:53 -070067
Michael Kolb66706532010-12-12 19:50:22 -080068 protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
Michael Kolb8233fac2010-10-26 16:08:53 -070069 new FrameLayout.LayoutParams(
70 ViewGroup.LayoutParams.MATCH_PARENT,
71 ViewGroup.LayoutParams.MATCH_PARENT);
72
Michael Kolb66706532010-12-12 19:50:22 -080073 protected static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
Michael Kolb8233fac2010-10-26 16:08:53 -070074 new FrameLayout.LayoutParams(
75 ViewGroup.LayoutParams.MATCH_PARENT,
76 ViewGroup.LayoutParams.MATCH_PARENT,
77 Gravity.CENTER);
78
John Reck5d43ce82011-06-21 17:16:51 -070079 private static final int MSG_HIDE_TITLEBAR = 1;
John Reckef654f12011-07-12 16:42:08 -070080 public static final int HIDE_TITLEBAR_DELAY = 1500; // in ms
John Reck5d43ce82011-06-21 17:16:51 -070081
Michael Kolb8233fac2010-10-26 16:08:53 -070082 Activity mActivity;
83 UiController mUiController;
84 TabControl mTabControl;
Michael Kolb377ea312011-02-17 14:36:56 -080085 protected Tab mActiveTab;
Michael Kolb3a696282010-12-05 13:23:24 -080086 private InputMethodManager mInputManager;
Michael Kolb8233fac2010-10-26 16:08:53 -070087
Steve Block2466eff2011-10-03 15:33:09 +010088 private Drawable mLockIconSecure;
89 private Drawable mLockIconMixed;
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -070090 private Drawable mGenericFavicon;
Michael Kolb8233fac2010-10-26 16:08:53 -070091
Michael Kolb66706532010-12-12 19:50:22 -080092 protected FrameLayout mContentView;
Michael Kolbf2055602011-04-09 17:20:03 -070093 protected FrameLayout mCustomViewContainer;
John Reck2711fab2012-05-18 21:38:59 -070094 private FrameLayout mFixedTitlebarContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070095
Michael Kolb31065b12011-10-06 13:51:32 -070096 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080097 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040098 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -070099
Michael Kolb8233fac2010-10-26 16:08:53 -0700100 private LinearLayout mErrorConsoleContainer = null;
101
John Reck718a24d2011-08-12 11:08:30 -0700102 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -0700103
John Reck718a24d2011-08-12 11:08:30 -0700104 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700105
Michael Kolb8233fac2010-10-26 16:08:53 -0700106 // the default <video> poster
107 private Bitmap mDefaultVideoPoster;
108 // the video progress view
109 private View mVideoProgressView;
110
Michael Kolb8233fac2010-10-26 16:08:53 -0700111 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700112 protected TitleBar mTitleBar;
113 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700114 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700115
116 public BaseUi(Activity browser, UiController controller) {
117 mActivity = browser;
118 mUiController = controller;
119 mTabControl = controller.getTabControl();
Michael Kolb3a696282010-12-05 13:23:24 -0800120 mInputManager = (InputMethodManager)
121 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Enrico Ros1f5a0952014-11-18 20:15:48 -0800122 // This assumes that the top-level root of our layout has the 'android.R.id.content' id
123 // it's used in place of setContentView because we're attaching a <merge> here.
Michael Kolb8233fac2010-10-26 16:08:53 -0700124 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
125 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700126 LayoutInflater.from(mActivity)
127 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700128 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
129 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700130 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700131 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700132 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
133 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700134 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700135 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700136 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700137 mTitleBar = new TitleBar(mActivity, mUiController, this,
138 mContentView);
139 mTitleBar.setProgress(100);
140 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700141 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700142 }
143
Michael Kolb8233fac2010-10-26 16:08:53 -0700144 private void cancelStopToast() {
145 if (mStopToast != null) {
146 mStopToast.cancel();
147 mStopToast = null;
148 }
149 }
150
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700151 private Drawable getLockIconSecure() {
152 if (mLockIconSecure == null) {
153 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_secure_holo_dark);
154 }
155 return mLockIconSecure;
156 }
157
158 private Drawable getLockIconMixed() {
159 if (mLockIconMixed == null) {
160 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_secure_partial_holo_dark);
161 }
162 return mLockIconMixed;
163 }
164
165 protected Drawable getGenericFavicon() {
166 if (mGenericFavicon == null) {
Enrico Rosd6efa972014-12-02 19:49:59 -0800167 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.ic_deco_favicon_normal);
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700168 }
169 return mGenericFavicon;
170 }
171
Michael Kolb8233fac2010-10-26 16:08:53 -0700172 // lifecycle
173
174 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800175 if (isCustomViewShowing()) {
176 onHideCustomView();
177 }
Denise LaFayettef9ef98f2014-11-11 17:18:29 -0500178 if (mTabControl.getCurrentTab() != null) {
179 mTabControl.getCurrentTab().exitFullscreen();
180 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700181 cancelStopToast();
182 mActivityPaused = true;
183 }
184
185 public void onResume() {
186 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700187 // check if we exited without setting active tab
188 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700189 final Tab ct = mTabControl.getCurrentTab();
190 if (ct != null) {
191 setActiveTab(ct);
192 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700193 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700194 }
195
Michael Kolb66706532010-12-12 19:50:22 -0800196 protected boolean isActivityPaused() {
197 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700198 }
199
200 public void onConfigurationChanged(Configuration config) {
201 }
202
John Reck0f602f32011-07-07 15:38:43 -0700203 public Activity getActivity() {
204 return mActivity;
205 }
206
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 // key handling
208
209 @Override
210 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700211 if (mCustomView != null) {
212 mUiController.hideCustomView();
213 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700214 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700215 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700216 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 }
218 return false;
219 }
220
Michael Kolb2814a362011-05-19 15:49:41 -0700221 @Override
222 public boolean onMenuKey() {
223 return false;
224 }
225
John Reck30c714c2010-12-16 17:30:34 -0800226 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700227 @Override
John Reck30c714c2010-12-16 17:30:34 -0800228 public void onTabDataChanged(Tab tab) {
229 setUrlTitle(tab);
230 setFavicon(tab);
231 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800232 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700233 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700234 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700235 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 }
237
238 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700239 public void onProgressChanged(Tab tab) {
240 int progress = tab.getLoadProgress();
241 if (tab.inForeground()) {
242 mTitleBar.setProgress(progress);
243 }
244 }
245
246 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500247 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800248 if (tab.inForeground()) {
249 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700250 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800251 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500252 }
253
254 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700255 public void onPageStopped(Tab tab) {
256 cancelStopToast();
257 if (tab.inForeground()) {
258 mStopToast = Toast
259 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
260 mStopToast.show();
261 }
262 }
263
264 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800265 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700266 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800267 }
268
269 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700270 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700271 }
272
273 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800274 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800275 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400276 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700277 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400278
Michael Kolbbae0cb22012-05-29 11:15:27 -0700279 // block unnecessary focus change animations during tab switch
280 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700281 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800282 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400283 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700284 WebView web = mActiveTab.getWebView();
285 if (web != null) {
286 web.setOnTouchListener(null);
287 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700288 }
Michael Kolb77df4562010-11-19 14:49:34 -0800289 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700290 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700291 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700292 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700293 if (web != null) {
294 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700295 web.setTitleBar(mTitleBar);
296 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700297 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700298 }
Michael Kolb4923c222012-04-02 16:18:36 -0700299 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700300 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700301 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800302 onTabDataChanged(tab);
303 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700304 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700305 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400306
Vivek Sekhar943f0672014-05-01 18:35:22 -0700307 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400308 }
309
310 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700313 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400314
Vivek Sekhar943f0672014-05-01 18:35:22 -0700315 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400316 //remove previously scehduled tab
317 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700318 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700319 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400320 removeTabFromContentView(mTabToRemove);
321 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700322 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400323 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700324 mTabToRemove = tabToRemove;
325 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400326 mNumRemoveTries = 0;
327
328 if (mTabToRemove != null) {
329 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700330 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400331 }
332 }
333
334 protected void tryRemoveTab() {
335 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 // Ensure the webview is still valid
337 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
338 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700339 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700340 mRunnable = new Runnable() {
341 public void run() {
342 tryRemoveTab();
343 }
344 };
345 }
346 /*if the new tab is still not ready, wait another 2 frames
347 before trying again. 1 frame for the tab to render the first
348 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700349 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400350 return;
351 }
352 }
353 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700355 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400356 removeTabFromContentView(mTabToRemove);
357 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700358 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400359 }
360 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700361 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700362 }
363
John Reck718a24d2011-08-12 11:08:30 -0700364 protected void updateUrlBarAutoShowManagerTarget() {
365 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700366 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700367 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700368 }
369 }
370
Michael Kolbcfa3af52010-12-14 10:36:11 -0800371 Tab getActiveTab() {
372 return mActiveTab;
373 }
374
Michael Kolb8233fac2010-10-26 16:08:53 -0700375 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800376 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800377 }
378
379 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800381 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800383 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700384 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700385 }
386
387 @Override
388 public void detachTab(Tab tab) {
389 removeTabFromContentView(tab);
390 }
391
392 @Override
393 public void attachTab(Tab tab) {
394 attachTabToContentView(tab);
395 }
396
Michael Kolb377ea312011-02-17 14:36:56 -0800397 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800398 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700399 return;
400 }
401 View container = tab.getViewContainer();
402 WebView mainView = tab.getWebView();
403 // Attach the WebView to the container and then attach the
404 // container to the content view.
405 FrameLayout wrapper =
406 (FrameLayout) container.findViewById(R.id.webview_wrapper);
407 ViewGroup parent = (ViewGroup) mainView.getParent();
408 if (parent != wrapper) {
409 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700410 parent.removeView(mainView);
411 }
412 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700413 }
414 parent = (ViewGroup) container.getParent();
415 if (parent != mContentView) {
416 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 parent.removeView(container);
418 }
419 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700420 }
421 mUiController.attachSubWindow(tab);
422 }
423
424 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800425 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700426 // Remove the container that contains the main WebView.
427 WebView mainView = tab.getWebView();
428 View container = tab.getViewContainer();
429 if (mainView == null) {
430 return;
431 }
432 // Remove the container from the content and then remove the
433 // WebView from the container. This will trigger a focus change
434 // needed by WebView.
435 FrameLayout wrapper =
436 (FrameLayout) container.findViewById(R.id.webview_wrapper);
437 wrapper.removeView(mainView);
438 mContentView.removeView(container);
439 mUiController.endActionMode();
440 mUiController.removeSubWindow(tab);
441 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
442 if (errorConsole != null) {
443 mErrorConsoleContainer.removeView(errorConsole);
444 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700445 }
446
Michael Kolba713ec82010-11-29 17:27:06 -0800447 @Override
448 public void onSetWebView(Tab tab, WebView webView) {
449 View container = tab.getViewContainer();
450 if (container == null) {
451 // The tab consists of a container view, which contains the main
452 // WebView, as well as any other UI elements associated with the tab.
453 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700454 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800455 tab.setViewContainer(container);
456 }
457 if (tab.getWebView() != webView) {
458 // Just remove the old one.
459 FrameLayout wrapper =
460 (FrameLayout) container.findViewById(R.id.webview_wrapper);
461 wrapper.removeView(tab.getWebView());
462 }
463 }
464
Michael Kolb8233fac2010-10-26 16:08:53 -0700465 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800466 * create a sub window container and webview for the tab
467 * Note: this methods operates through side-effects for now
468 * it sets both the subView and subViewContainer for the given tab
469 * @param tab tab to create the sub window for
470 * @param subView webview to be set as a subwindow for the tab
471 */
472 @Override
473 public void createSubWindow(Tab tab, WebView subView) {
474 View subViewContainer = mActivity.getLayoutInflater().inflate(
475 R.layout.browser_subwindow, null);
476 ViewGroup inner = (ViewGroup) subViewContainer
477 .findViewById(R.id.inner_container);
478 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
479 LayoutParams.MATCH_PARENT));
480 final ImageButton cancel = (ImageButton) subViewContainer
481 .findViewById(R.id.subwindow_close);
482 final WebView cancelSubView = subView;
483 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800484 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800485 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800486 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800487 }
488 });
489 tab.setSubWebView(subView);
490 tab.setSubViewContainer(subViewContainer);
491 }
492
493 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700494 * Remove the sub window from the content view.
495 */
496 @Override
497 public void removeSubWindow(View subviewContainer) {
498 mContentView.removeView(subviewContainer);
499 mUiController.endActionMode();
500 }
501
502 /**
503 * Attach the sub window to the content view.
504 */
505 @Override
506 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800507 if (container.getParent() != null) {
508 // already attached, remove first
509 ((ViewGroup) container.getParent()).removeView(container);
510 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700511 mContentView.addView(container, COVER_SCREEN_PARAMS);
512 }
513
Michael Kolb11d19782011-03-20 10:17:40 -0700514 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700515 WebView web = getWebView();
516 if (web != null) {
517 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700518 }
519 }
520
Michael Kolb1f9b3562012-04-24 14:38:34 -0700521 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700522 if (mUiController.isInCustomActionMode()) {
523 mUiController.endActionMode();
524 }
525 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700526 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700527 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700528 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700529 }
530
Michael Kolb7cdc4902011-02-03 17:54:40 -0800531 boolean canShowTitleBar() {
532 return !isTitleBarShowing()
533 && !isActivityPaused()
534 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700535 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800536 && !mUiController.isInCustomActionMode();
537 }
538
John Reck0f602f32011-07-07 15:38:43 -0700539 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700540 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700541 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700542 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700543 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800544 }
545
546 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700547 if (mTitleBar.isShowing()) {
548 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700549 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800550 }
551
552 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700553 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800554 }
555
John Reck5d43ce82011-06-21 17:16:51 -0700556 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700557 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700558 }
559
Michael Kolb80f75082012-04-10 10:50:06 -0700560 public void stopEditingUrl() {
561 mTitleBar.getNavigationBar().stopEditingUrl();
562 }
563
John Reck0f602f32011-07-07 15:38:43 -0700564 public TitleBar getTitleBar() {
565 return mTitleBar;
566 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800567
Michael Kolb66706532010-12-12 19:50:22 -0800568 @Override
John Reck2bc80422011-06-30 15:11:49 -0700569 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700570 Intent intent = new Intent(mActivity, ComboViewActivity.class);
571 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
572 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
573 Tab t = getActiveTab();
574 if (t != null) {
575 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800576 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700577 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700578 }
579
580 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400581 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800582 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700583 // if a view already exists then immediately terminate the new one
584 if (mCustomView != null) {
585 callback.onCustomViewHidden();
586 return;
587 }
588
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400589 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700590 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400591 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700592 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400593 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700594 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700595 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400596 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700597 }
598
599 @Override
600 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700601 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700602 if (mCustomView == null)
603 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400604 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700605 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400606 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700608 mCustomViewCallback.onCustomViewHidden();
609 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400610 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700611 }
612
613 @Override
614 public boolean isCustomViewShowing() {
615 return mCustomView != null;
616 }
617
Michael Kolb66706532010-12-12 19:50:22 -0800618 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800619 if (mInputManager.isActive()) {
620 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
621 0);
622 }
623 }
624
Michael Kolb66706532010-12-12 19:50:22 -0800625 @Override
John Reck3ba45532011-08-11 16:26:53 -0700626 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700627 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800628 }
629
Michael Kolb8233fac2010-10-26 16:08:53 -0700630 // -------------------------------------------------------------------------
631
Michael Kolb5a72f182011-01-13 20:35:06 -0800632 protected void updateNavigationState(Tab tab) {
633 }
634
Michael Kolb8233fac2010-10-26 16:08:53 -0700635 /**
636 * Update the lock icon to correspond to our latest state.
637 */
Michael Kolb66706532010-12-12 19:50:22 -0800638 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800639 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100640 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700641 }
642 }
643
644 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700645 * Updates the lock-icon image in the title-bar.
646 */
Steve Block2466eff2011-10-03 15:33:09 +0100647 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700648 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100649 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700650 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100651 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
652 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
653 // TODO: It would be good to have different icons for insecure vs mixed content.
654 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700655 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700656 }
John Reck0f602f32011-07-07 15:38:43 -0700657 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700658 }
659
John Reck30c714c2010-12-16 17:30:34 -0800660 protected void setUrlTitle(Tab tab) {
661 String url = tab.getUrl();
662 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800663 if (TextUtils.isEmpty(title)) {
664 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800665 }
Michael Kolb66706532010-12-12 19:50:22 -0800666 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700667 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800668 }
669 }
670
671 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800672 protected void setFavicon(Tab tab) {
673 if (tab.inForeground()) {
674 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700675 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800676 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700677 }
678
Michael Kolb66706532010-12-12 19:50:22 -0800679 // active tabs page
680
681 public void showActiveTabsPage() {
682 }
683
684 /**
685 * Remove the active tabs page.
686 */
687 public void removeActiveTabsPage() {
688 }
689
Michael Kolb8233fac2010-10-26 16:08:53 -0700690 // menu handling callbacks
691
692 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800693 public boolean onPrepareOptionsMenu(Menu menu) {
694 return true;
695 }
696
697 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700698 public void updateMenuState(Tab tab, Menu menu) {
699 }
700
701 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700702 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700703 }
704
705 @Override
706 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700707 }
708
709 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700710 public boolean onOptionsItemSelected(MenuItem item) {
711 return false;
712 }
713
714 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700715 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700716 }
717
718 @Override
719 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700720 }
721
722 @Override
723 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700724 }
725
726 @Override
727 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700728 }
729
730 // error console
731
732 @Override
733 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800734 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700735 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
736 if (flag) {
737 // Setting the show state of the console will cause it's the layout
738 // to be inflated.
739 if (errorConsole.numberOfErrors() > 0) {
740 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
741 } else {
742 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
743 }
744 if (errorConsole.getParent() != null) {
745 mErrorConsoleContainer.removeView(errorConsole);
746 }
747 // Now we can add it to the main view.
748 mErrorConsoleContainer.addView(errorConsole,
749 new LinearLayout.LayoutParams(
750 ViewGroup.LayoutParams.MATCH_PARENT,
751 ViewGroup.LayoutParams.WRAP_CONTENT));
752 } else {
753 mErrorConsoleContainer.removeView(errorConsole);
754 }
755 }
756
Michael Kolb8233fac2010-10-26 16:08:53 -0700757 // -------------------------------------------------------------------------
758 // Helper function for WebChromeClient
759 // -------------------------------------------------------------------------
760
761 @Override
762 public Bitmap getDefaultVideoPoster() {
763 if (mDefaultVideoPoster == null) {
764 mDefaultVideoPoster = BitmapFactory.decodeResource(
765 mActivity.getResources(), R.drawable.default_video_poster);
766 }
767 return mDefaultVideoPoster;
768 }
769
770 @Override
771 public View getVideoLoadingProgressView() {
772 if (mVideoProgressView == null) {
773 LayoutInflater inflater = LayoutInflater.from(mActivity);
774 mVideoProgressView = inflater.inflate(
775 R.layout.video_loading_progress, null);
776 }
777 return mVideoProgressView;
778 }
779
Michael Kolb843510f2010-12-09 10:51:49 -0800780 @Override
781 public void showMaxTabsWarning() {
782 Toast warning = Toast.makeText(mActivity,
783 mActivity.getString(R.string.max_tabs_warning),
784 Toast.LENGTH_SHORT);
785 warning.show();
786 }
787
Michael Kolb46f987e2011-04-05 10:39:10 -0700788 protected WebView getWebView() {
789 if (mActiveTab != null) {
790 return mActiveTab.getWebView();
791 } else {
792 return null;
793 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700794 }
795
Michael Kolbc38c6042011-04-27 10:46:06 -0700796 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700797 Window win = mActivity.getWindow();
798 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800799 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Denise LaFayetted74d7022014-11-07 16:40:01 -0500800 final int fullscreenImmersiveSetting =
801 View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
802 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
803 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
804 View.SYSTEM_UI_FLAG_FULLSCREEN |
805 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
806
807 if (mCustomView != null) {
808 mCustomView.setSystemUiVisibility(enabled ?
809 fullscreenImmersiveSetting : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700810 } else {
Denise LaFayetted74d7022014-11-07 16:40:01 -0500811 mContentView.setSystemUiVisibility(enabled ?
812 View.SYSTEM_UI_FLAG_LOW_PROFILE : View.SYSTEM_UI_FLAG_VISIBLE);
Michael Kolbc38c6042011-04-27 10:46:06 -0700813 }
Denise LaFayetted74d7022014-11-07 16:40:01 -0500814 if (enabled)
815 winParams.flags |= bits;
816 else
817 winParams.flags &= ~bits;
818
Michael Kolbc5675ad2011-10-21 13:34:28 -0700819 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700820 }
821
Denise LaFayetteda31d742014-10-10 18:03:13 -0400822 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700823 public void showFullscreen(boolean fullScreen) {
824 //Hide/show system ui bar as needed
825 if (!BrowserSettings.getInstance().useFullscreen())
826 setFullscreen(fullScreen);
827
828 //Hide/show topbar as needed
829 if (getWebView() != null) {
830 if (fullScreen) {
831 //hide topbar
832 getWebView().updateTopControls(true, false, false);
833 } else {
834 //show the topbar
835 getWebView().updateTopControls(false, true, true);
836 //enable for auto-hide
837 if (!mTitleBar.isFixed())
838 getWebView().updateTopControls(true, true, false);
839 }
840 }
841 }
842
843
844
Tarun Nainani8eb00912014-07-17 12:28:32 -0700845 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700846 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700847 if (topControlsOffsetYPix != 0.0) {
848 mTitleBar.setEnabled(false);
849 } else {
850 mTitleBar.setEnabled(true);
851 }
Sudheer Koganti56cba972014-11-13 15:15:46 -0800852 if (!mTitleBar.isFixed()) {
Vivek Sekhar8a660782014-10-27 17:00:53 -0700853 mTitleBar.setTranslationY(topControlsOffsetYPix);
Sudheer Koganti56cba972014-11-13 15:15:46 -0800854 }
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700855 }
856 }
857
John Reck0f602f32011-07-07 15:38:43 -0700858 public Drawable getFaviconDrawable(Bitmap icon) {
Enrico Ros1f5a0952014-11-18 20:15:48 -0800859 if (ENABLE_BORDER_AROUND_FAVICON) {
860 Drawable[] array = new Drawable[3];
861 array[0] = new PaintDrawable(Color.BLACK);
862 PaintDrawable p = new PaintDrawable(Color.WHITE);
863 array[1] = p;
864 if (icon == null) {
865 array[2] = getGenericFavicon();
866 } else {
867 array[2] = new BitmapDrawable(mActivity.getResources(), icon);
868 }
869 LayerDrawable d = new LayerDrawable(array);
870 d.setLayerInset(1, 1, 1, 1, 1);
871 d.setLayerInset(2, 2, 2, 2, 2);
872 return d;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700873 }
Enrico Ros1f5a0952014-11-18 20:15:48 -0800874 return icon == null ? getGenericFavicon() : new BitmapDrawable(mActivity.getResources(), icon);
Michael Kolb5a4372f2011-04-29 13:53:10 -0700875 }
876
John Reck5d43ce82011-06-21 17:16:51 -0700877 public boolean isLoading() {
878 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
879 }
880
881 /**
882 * Suggest to the UI that the title bar can be hidden. The UI will then
883 * decide whether or not to hide based off a number of factors, such
884 * as if the user is editing the URL bar or if the page is loading
885 */
886 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700887 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
888 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700889 hideTitleBar();
890 }
891 }
892
John Reckbc6adb42011-09-01 18:03:20 -0700893 protected final void showTitleBarForDuration() {
894 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
895 }
896
897 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700898 showTitleBar();
899 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700900 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700901 }
902
Enrico Ros1f5a0952014-11-18 20:15:48 -0800903 protected void setMenuItemVisibility(Menu menu, int id,
904 boolean visibility) {
905 MenuItem item = menu.findItem(id);
906 if (item != null) {
907 item.setVisible(visibility);
908 }
909 }
910
John Reck9c5004e2011-10-07 16:00:12 -0700911 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700912
913 @Override
914 public void handleMessage(Message msg) {
915 if (msg.what == MSG_HIDE_TITLEBAR) {
916 suggestHideTitleBar();
917 }
John Reck9c5004e2011-10-07 16:00:12 -0700918 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700919 }
920 };
John Reck3ba45532011-08-11 16:26:53 -0700921
John Reck9c5004e2011-10-07 16:00:12 -0700922 protected void handleMessage(Message msg) {}
923
John Reck3ba45532011-08-11 16:26:53 -0700924 @Override
925 public void showWeb(boolean animate) {
926 mUiController.hideCustomView();
927 }
928
John Reck2711fab2012-05-18 21:38:59 -0700929 public void setContentViewMarginTop(int margin) {
930 LinearLayout.LayoutParams params =
931 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
932 if (params.topMargin != margin) {
933 params.topMargin = margin;
934 mContentView.setLayoutParams(params);
935 }
936 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700937
938 @Override
939 public boolean blockFocusAnimations() {
940 return mBlockFocusAnimations;
941 }
942
Michael Kolb0b129122012-06-04 16:31:58 -0700943 @Override
944 public void onVoiceResult(String result) {
945 mNavigationBar.onVoiceResult(result);
946 }
947
kaiyizbb2db872013-08-01 22:24:07 -0400948 protected UiController getUiController() {
949 return mUiController;
950 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700951
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700952 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700953 private float getActionModeHeight() {
954 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
955 new int[] { android.R.attr.actionBarSize });
956 float size = actionBarSizeTypedArray.getDimension(0, 0f);
957 actionBarSizeTypedArray.recycle();
958 return size;
959 }
960
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700961
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700962 @Override
963 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700964 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700965
966 if (mTitleBar.isFixed()) {
967 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700968 mFixedTitlebarContainer.setY(fixedTbarHeight);
969 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700970 } else {
971 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700972 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700973 }
974
975 @Override
976 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700977 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700978 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700979 mFixedTitlebarContainer.setY(0);
980 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700981 } else {
982 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700983 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700984 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700985}