blob: 0508e67c68b827cc69ca55d78ebd86e09bb0a0ce [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
66 private static final String LOGTAG = "BaseUi";
67
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;
Michael Kolb31065b12011-10-06 13:51:32 -070094 protected FrameLayout mFullscreenContainer;
John Reck2711fab2012-05-18 21:38:59 -070095 private FrameLayout mFixedTitlebarContainer;
Michael Kolb8233fac2010-10-26 16:08:53 -070096
Michael Kolb31065b12011-10-06 13:51:32 -070097 private View mCustomView;
Bijan Amirzada9b1e9882014-02-26 17:15:46 -080098 private CustomViewCallback mCustomViewCallback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -040099 private int mOriginalOrientation;
Michael Kolb8233fac2010-10-26 16:08:53 -0700100
Michael Kolb8233fac2010-10-26 16:08:53 -0700101 private LinearLayout mErrorConsoleContainer = null;
102
John Reck718a24d2011-08-12 11:08:30 -0700103 private UrlBarAutoShowManager mUrlBarAutoShowManager;
Michael Kolb8233fac2010-10-26 16:08:53 -0700104
John Reck718a24d2011-08-12 11:08:30 -0700105 private Toast mStopToast;
Michael Kolb5a4372f2011-04-29 13:53:10 -0700106
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 // the default <video> poster
108 private Bitmap mDefaultVideoPoster;
109 // the video progress view
110 private View mVideoProgressView;
111
Michael Kolb8233fac2010-10-26 16:08:53 -0700112 private boolean mActivityPaused;
John Reck0f602f32011-07-07 15:38:43 -0700113 protected TitleBar mTitleBar;
114 private NavigationBarBase mNavigationBar;
Michael Kolbbae0cb22012-05-29 11:15:27 -0700115 private boolean mBlockFocusAnimations;
Michael Kolb8233fac2010-10-26 16:08:53 -0700116
117 public BaseUi(Activity browser, UiController controller) {
118 mActivity = browser;
119 mUiController = controller;
120 mTabControl = controller.getTabControl();
121 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800122 mInputManager = (InputMethodManager)
123 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
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) {
167 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.app_web_browser_sm);
168 }
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 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700178 cancelStopToast();
179 mActivityPaused = true;
180 }
181
182 public void onResume() {
183 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700184 // check if we exited without setting active tab
185 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700186 final Tab ct = mTabControl.getCurrentTab();
187 if (ct != null) {
188 setActiveTab(ct);
189 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700190 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700191 }
192
Michael Kolb66706532010-12-12 19:50:22 -0800193 protected boolean isActivityPaused() {
194 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700195 }
196
197 public void onConfigurationChanged(Configuration config) {
198 }
199
John Reck0f602f32011-07-07 15:38:43 -0700200 public Activity getActivity() {
201 return mActivity;
202 }
203
Michael Kolb8233fac2010-10-26 16:08:53 -0700204 // key handling
205
206 @Override
207 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700208 if (mCustomView != null) {
209 mUiController.hideCustomView();
210 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700211 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700212 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700213 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700214 }
215 return false;
216 }
217
Michael Kolb2814a362011-05-19 15:49:41 -0700218 @Override
219 public boolean onMenuKey() {
220 return false;
221 }
222
John Reck30c714c2010-12-16 17:30:34 -0800223 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700224 @Override
John Reck30c714c2010-12-16 17:30:34 -0800225 public void onTabDataChanged(Tab tab) {
226 setUrlTitle(tab);
227 setFavicon(tab);
228 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800229 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700230 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700231 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700232 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700233 }
234
235 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700236 public void onProgressChanged(Tab tab) {
237 int progress = tab.getLoadProgress();
238 if (tab.inForeground()) {
239 mTitleBar.setProgress(progress);
240 }
241 }
242
243 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500244 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800245 if (tab.inForeground()) {
246 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700247 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800248 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500249 }
250
251 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 public void onPageStopped(Tab tab) {
253 cancelStopToast();
254 if (tab.inForeground()) {
255 mStopToast = Toast
256 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
257 mStopToast.show();
258 }
259 }
260
261 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800262 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700263 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800264 }
265
266 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700267 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700268 }
269
270 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800271 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800272 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400273 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700274 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400275
Michael Kolbbae0cb22012-05-29 11:15:27 -0700276 // block unnecessary focus change animations during tab switch
277 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700278 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800279 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400280 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700281 WebView web = mActiveTab.getWebView();
282 if (web != null) {
283 web.setOnTouchListener(null);
284 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700285 }
Michael Kolb77df4562010-11-19 14:49:34 -0800286 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700287 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700288 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700289 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700290 if (web != null) {
291 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700292 web.setTitleBar(mTitleBar);
293 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700294 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700295 }
Michael Kolb4923c222012-04-02 16:18:36 -0700296 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700297 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700298 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800299 onTabDataChanged(tab);
300 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700301 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700302 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400303
Vivek Sekhar943f0672014-05-01 18:35:22 -0700304 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400305 }
306
307 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700308 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400309 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700310 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400311
Vivek Sekhar943f0672014-05-01 18:35:22 -0700312 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400313 //remove previously scehduled tab
314 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700315 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700316 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400317 removeTabFromContentView(mTabToRemove);
318 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700319 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400320 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700321 mTabToRemove = tabToRemove;
322 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400323 mNumRemoveTries = 0;
324
325 if (mTabToRemove != null) {
326 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700327 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400328 }
329 }
330
331 protected void tryRemoveTab() {
332 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700333 // Ensure the webview is still valid
334 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
335 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700336 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700337 mRunnable = new Runnable() {
338 public void run() {
339 tryRemoveTab();
340 }
341 };
342 }
343 /*if the new tab is still not ready, wait another 2 frames
344 before trying again. 1 frame for the tab to render the first
345 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700346 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400347 return;
348 }
349 }
350 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700351 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700352 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400353 removeTabFromContentView(mTabToRemove);
354 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700355 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400356 }
357 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700358 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700359 }
360
John Reck718a24d2011-08-12 11:08:30 -0700361 protected void updateUrlBarAutoShowManagerTarget() {
362 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700363 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700364 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700365 }
366 }
367
Michael Kolbcfa3af52010-12-14 10:36:11 -0800368 Tab getActiveTab() {
369 return mActiveTab;
370 }
371
Michael Kolb8233fac2010-10-26 16:08:53 -0700372 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800373 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800374 }
375
376 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700377 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800378 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700379 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800380 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700382 }
383
384 @Override
385 public void detachTab(Tab tab) {
386 removeTabFromContentView(tab);
387 }
388
389 @Override
390 public void attachTab(Tab tab) {
391 attachTabToContentView(tab);
392 }
393
Michael Kolb377ea312011-02-17 14:36:56 -0800394 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800395 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700396 return;
397 }
398 View container = tab.getViewContainer();
399 WebView mainView = tab.getWebView();
400 // Attach the WebView to the container and then attach the
401 // container to the content view.
402 FrameLayout wrapper =
403 (FrameLayout) container.findViewById(R.id.webview_wrapper);
404 ViewGroup parent = (ViewGroup) mainView.getParent();
405 if (parent != wrapper) {
406 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700407 parent.removeView(mainView);
408 }
409 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700410 }
411 parent = (ViewGroup) container.getParent();
412 if (parent != mContentView) {
413 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700414 parent.removeView(container);
415 }
416 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700417 }
418 mUiController.attachSubWindow(tab);
419 }
420
421 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800422 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700423 // Remove the container that contains the main WebView.
424 WebView mainView = tab.getWebView();
425 View container = tab.getViewContainer();
426 if (mainView == null) {
427 return;
428 }
429 // Remove the container from the content and then remove the
430 // WebView from the container. This will trigger a focus change
431 // needed by WebView.
432 FrameLayout wrapper =
433 (FrameLayout) container.findViewById(R.id.webview_wrapper);
434 wrapper.removeView(mainView);
435 mContentView.removeView(container);
436 mUiController.endActionMode();
437 mUiController.removeSubWindow(tab);
438 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
439 if (errorConsole != null) {
440 mErrorConsoleContainer.removeView(errorConsole);
441 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700442 }
443
Michael Kolba713ec82010-11-29 17:27:06 -0800444 @Override
445 public void onSetWebView(Tab tab, WebView webView) {
446 View container = tab.getViewContainer();
447 if (container == null) {
448 // The tab consists of a container view, which contains the main
449 // WebView, as well as any other UI elements associated with the tab.
450 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700451 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800452 tab.setViewContainer(container);
453 }
454 if (tab.getWebView() != webView) {
455 // Just remove the old one.
456 FrameLayout wrapper =
457 (FrameLayout) container.findViewById(R.id.webview_wrapper);
458 wrapper.removeView(tab.getWebView());
459 }
460 }
461
Michael Kolb8233fac2010-10-26 16:08:53 -0700462 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800463 * create a sub window container and webview for the tab
464 * Note: this methods operates through side-effects for now
465 * it sets both the subView and subViewContainer for the given tab
466 * @param tab tab to create the sub window for
467 * @param subView webview to be set as a subwindow for the tab
468 */
469 @Override
470 public void createSubWindow(Tab tab, WebView subView) {
471 View subViewContainer = mActivity.getLayoutInflater().inflate(
472 R.layout.browser_subwindow, null);
473 ViewGroup inner = (ViewGroup) subViewContainer
474 .findViewById(R.id.inner_container);
475 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
476 LayoutParams.MATCH_PARENT));
477 final ImageButton cancel = (ImageButton) subViewContainer
478 .findViewById(R.id.subwindow_close);
479 final WebView cancelSubView = subView;
480 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800481 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800482 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800483 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800484 }
485 });
486 tab.setSubWebView(subView);
487 tab.setSubViewContainer(subViewContainer);
488 }
489
490 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700491 * Remove the sub window from the content view.
492 */
493 @Override
494 public void removeSubWindow(View subviewContainer) {
495 mContentView.removeView(subviewContainer);
496 mUiController.endActionMode();
497 }
498
499 /**
500 * Attach the sub window to the content view.
501 */
502 @Override
503 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800504 if (container.getParent() != null) {
505 // already attached, remove first
506 ((ViewGroup) container.getParent()).removeView(container);
507 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700508 mContentView.addView(container, COVER_SCREEN_PARAMS);
509 }
510
Michael Kolb11d19782011-03-20 10:17:40 -0700511 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700512 WebView web = getWebView();
513 if (web != null) {
514 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700515 }
516 }
517
Michael Kolb1f9b3562012-04-24 14:38:34 -0700518 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700519 if (mUiController.isInCustomActionMode()) {
520 mUiController.endActionMode();
521 }
522 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700523 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700524 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700525 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700526 }
527
Michael Kolb7cdc4902011-02-03 17:54:40 -0800528 boolean canShowTitleBar() {
529 return !isTitleBarShowing()
530 && !isActivityPaused()
531 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700532 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800533 && !mUiController.isInCustomActionMode();
534 }
535
John Reck0f602f32011-07-07 15:38:43 -0700536 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700537 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700538 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700539 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700540 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800541 }
542
543 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700544 if (mTitleBar.isShowing()) {
545 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700546 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800547 }
548
549 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700550 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800551 }
552
John Reck5d43ce82011-06-21 17:16:51 -0700553 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700554 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700555 }
556
Michael Kolb80f75082012-04-10 10:50:06 -0700557 public void stopEditingUrl() {
558 mTitleBar.getNavigationBar().stopEditingUrl();
559 }
560
John Reck0f602f32011-07-07 15:38:43 -0700561 public TitleBar getTitleBar() {
562 return mTitleBar;
563 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800564
Michael Kolb66706532010-12-12 19:50:22 -0800565 @Override
John Reck2bc80422011-06-30 15:11:49 -0700566 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700567 Intent intent = new Intent(mActivity, ComboViewActivity.class);
568 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
569 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
570 Tab t = getActiveTab();
571 if (t != null) {
572 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800573 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700574 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700575 }
576
577 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400578 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800579 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700580 // if a view already exists then immediately terminate the new one
581 if (mCustomView != null) {
582 callback.onCustomViewHidden();
583 return;
584 }
585
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400586 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700587 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
588 mFullscreenContainer = new FullscreenHolder(mActivity);
589 mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
590 decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
591 mCustomView = view;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700592 setFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700593 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700594 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400595 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700596 }
597
598 @Override
599 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700600 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700601 if (mCustomView == null)
602 return;
Michael Kolbc5675ad2011-10-21 13:34:28 -0700603 setFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700604 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
605 decor.removeView(mFullscreenContainer);
606 mFullscreenContainer = null;
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;
Michael Kolbc38c6042011-04-27 10:46:06 -0700800 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700801 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700802 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700803 winParams.flags &= ~bits;
804 if (mCustomView != null) {
805 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
806 } else {
807 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
808 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700809 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700810 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700811 }
812
Sudheer Koganti24766882014-10-02 10:58:09 -0700813 //make full screen bu showing/hiding topbar and system status bar
814 public void showFullscreen(boolean fullScreen) {
815 //Hide/show system ui bar as needed
816 if (!BrowserSettings.getInstance().useFullscreen())
817 setFullscreen(fullScreen);
818
819 //Hide/show topbar as needed
820 if (getWebView() != null) {
821 if (fullScreen) {
822 //hide topbar
823 getWebView().updateTopControls(true, false, false);
824 } else {
825 //show the topbar
826 getWebView().updateTopControls(false, true, true);
827 //enable for auto-hide
828 if (!mTitleBar.isFixed())
829 getWebView().updateTopControls(true, true, false);
830 }
831 }
832 }
833
834
835
Tarun Nainani8eb00912014-07-17 12:28:32 -0700836 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700837 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700838 mTitleBar.bringToFront();
839 if (topControlsOffsetYPix != 0.0) {
840 mTitleBar.setEnabled(false);
841 } else {
842 mTitleBar.setEnabled(true);
843 }
Vivek Sekhar8a660782014-10-27 17:00:53 -0700844 if (!mTitleBar.isFixed() && !isLoading())
845 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700846 }
847 }
848
John Reck0f602f32011-07-07 15:38:43 -0700849 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700850 Drawable[] array = new Drawable[3];
851 array[0] = new PaintDrawable(Color.BLACK);
852 PaintDrawable p = new PaintDrawable(Color.WHITE);
853 array[1] = p;
854 if (icon == null) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700855 array[2] = getGenericFavicon();
Michael Kolb5a4372f2011-04-29 13:53:10 -0700856 } else {
857 array[2] = new BitmapDrawable(icon);
858 }
859 LayerDrawable d = new LayerDrawable(array);
860 d.setLayerInset(1, 1, 1, 1, 1);
861 d.setLayerInset(2, 2, 2, 2, 2);
862 return d;
863 }
864
John Reck5d43ce82011-06-21 17:16:51 -0700865 public boolean isLoading() {
866 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
867 }
868
869 /**
870 * Suggest to the UI that the title bar can be hidden. The UI will then
871 * decide whether or not to hide based off a number of factors, such
872 * as if the user is editing the URL bar or if the page is loading
873 */
874 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700875 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
876 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700877 hideTitleBar();
878 }
879 }
880
John Reckbc6adb42011-09-01 18:03:20 -0700881 protected final void showTitleBarForDuration() {
882 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
883 }
884
885 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700886 showTitleBar();
887 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700888 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700889 }
890
John Reck9c5004e2011-10-07 16:00:12 -0700891 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700892
893 @Override
894 public void handleMessage(Message msg) {
895 if (msg.what == MSG_HIDE_TITLEBAR) {
896 suggestHideTitleBar();
897 }
John Reck9c5004e2011-10-07 16:00:12 -0700898 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700899 }
900 };
John Reck3ba45532011-08-11 16:26:53 -0700901
John Reck9c5004e2011-10-07 16:00:12 -0700902 protected void handleMessage(Message msg) {}
903
John Reck3ba45532011-08-11 16:26:53 -0700904 @Override
905 public void showWeb(boolean animate) {
906 mUiController.hideCustomView();
907 }
908
Michael Kolb31065b12011-10-06 13:51:32 -0700909 static class FullscreenHolder extends FrameLayout {
Michael Kolb53ed62c2011-10-04 16:18:44 -0700910
Michael Kolb31065b12011-10-06 13:51:32 -0700911 public FullscreenHolder(Context ctx) {
912 super(ctx);
913 setBackgroundColor(ctx.getResources().getColor(R.color.black));
Michael Kolb53ed62c2011-10-04 16:18:44 -0700914 }
915
Michael Kolb31065b12011-10-06 13:51:32 -0700916 @Override
917 public boolean onTouchEvent(MotionEvent evt) {
918 return true;
Michael Kolb53ed62c2011-10-04 16:18:44 -0700919 }
Michael Kolb31065b12011-10-06 13:51:32 -0700920
Michael Kolb53ed62c2011-10-04 16:18:44 -0700921 }
John Reck2711fab2012-05-18 21:38:59 -0700922
John Reck2711fab2012-05-18 21:38:59 -0700923 public void setContentViewMarginTop(int margin) {
924 LinearLayout.LayoutParams params =
925 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
926 if (params.topMargin != margin) {
927 params.topMargin = margin;
928 mContentView.setLayoutParams(params);
929 }
930 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700931
932 @Override
933 public boolean blockFocusAnimations() {
934 return mBlockFocusAnimations;
935 }
936
Michael Kolb0b129122012-06-04 16:31:58 -0700937 @Override
938 public void onVoiceResult(String result) {
939 mNavigationBar.onVoiceResult(result);
940 }
941
kaiyizbb2db872013-08-01 22:24:07 -0400942 protected UiController getUiController() {
943 return mUiController;
944 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700945
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700946 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700947 private float getActionModeHeight() {
948 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
949 new int[] { android.R.attr.actionBarSize });
950 float size = actionBarSizeTypedArray.getDimension(0, 0f);
951 actionBarSizeTypedArray.recycle();
952 return size;
953 }
954
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700955
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700956 @Override
957 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700958 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700959
960 if (mTitleBar.isFixed()) {
961 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700962 mFixedTitlebarContainer.setY(fixedTbarHeight);
963 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700964 } else {
965 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700966 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700967 }
968
969 @Override
970 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700971 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700972 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700973 mFixedTitlebarContainer.setY(0);
974 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700975 } else {
976 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700977 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700978 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700979}