blob: 6056cf5a948fcf549f7c83595e1e1bf2214f0dca [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;
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();
120 Resources res = mActivity.getResources();
Michael Kolb3a696282010-12-05 13:23:24 -0800121 mInputManager = (InputMethodManager)
122 browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700123 FrameLayout frameLayout = (FrameLayout) mActivity.getWindow()
124 .getDecorView().findViewById(android.R.id.content);
John Reck7c6e1c92011-06-30 11:55:55 -0700125 LayoutInflater.from(mActivity)
126 .inflate(R.layout.custom_screen, frameLayout);
John Reck2711fab2012-05-18 21:38:59 -0700127 mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(
128 R.id.fixed_titlebar_container);
John Reck7c6e1c92011-06-30 11:55:55 -0700129 mContentView = (FrameLayout) frameLayout.findViewById(
Michael Kolb8233fac2010-10-26 16:08:53 -0700130 R.id.main_content);
Michael Kolb53ed62c2011-10-04 16:18:44 -0700131 mCustomViewContainer = (FrameLayout) frameLayout.findViewById(
132 R.id.fullscreen_custom_content);
John Reck7c6e1c92011-06-30 11:55:55 -0700133 mErrorConsoleContainer = (LinearLayout) frameLayout
Michael Kolb8233fac2010-10-26 16:08:53 -0700134 .findViewById(R.id.error_console);
Michael Kolbc38c6042011-04-27 10:46:06 -0700135 setFullscreen(BrowserSettings.getInstance().useFullscreen());
John Reck0f602f32011-07-07 15:38:43 -0700136 mTitleBar = new TitleBar(mActivity, mUiController, this,
137 mContentView);
138 mTitleBar.setProgress(100);
139 mNavigationBar = mTitleBar.getNavigationBar();
John Reck718a24d2011-08-12 11:08:30 -0700140 mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
Michael Kolb8233fac2010-10-26 16:08:53 -0700141 }
142
Michael Kolb8233fac2010-10-26 16:08:53 -0700143 private void cancelStopToast() {
144 if (mStopToast != null) {
145 mStopToast.cancel();
146 mStopToast = null;
147 }
148 }
149
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700150 private Drawable getLockIconSecure() {
151 if (mLockIconSecure == null) {
152 mLockIconSecure = mActivity.getResources().getDrawable(R.drawable.ic_secure_holo_dark);
153 }
154 return mLockIconSecure;
155 }
156
157 private Drawable getLockIconMixed() {
158 if (mLockIconMixed == null) {
159 mLockIconMixed = mActivity.getResources().getDrawable(R.drawable.ic_secure_partial_holo_dark);
160 }
161 return mLockIconMixed;
162 }
163
164 protected Drawable getGenericFavicon() {
165 if (mGenericFavicon == null) {
166 mGenericFavicon = mActivity.getResources().getDrawable(R.drawable.app_web_browser_sm);
167 }
168 return mGenericFavicon;
169 }
170
Michael Kolb8233fac2010-10-26 16:08:53 -0700171 // lifecycle
172
173 public void onPause() {
Michael Kolb7a5cf472010-11-30 13:23:53 -0800174 if (isCustomViewShowing()) {
175 onHideCustomView();
176 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700177 cancelStopToast();
178 mActivityPaused = true;
179 }
180
181 public void onResume() {
182 mActivityPaused = false;
Michael Kolb2ae6ef72011-08-22 14:49:34 -0700183 // check if we exited without setting active tab
184 // b: 5188145
Michael Kolb1a4625a2011-08-24 13:40:44 -0700185 final Tab ct = mTabControl.getCurrentTab();
186 if (ct != null) {
187 setActiveTab(ct);
188 }
John Reck1cc1d1d2012-09-04 18:13:51 -0700189 mTitleBar.onResume();
Michael Kolb8233fac2010-10-26 16:08:53 -0700190 }
191
Michael Kolb66706532010-12-12 19:50:22 -0800192 protected boolean isActivityPaused() {
193 return mActivityPaused;
Michael Kolb8233fac2010-10-26 16:08:53 -0700194 }
195
196 public void onConfigurationChanged(Configuration config) {
197 }
198
John Reck0f602f32011-07-07 15:38:43 -0700199 public Activity getActivity() {
200 return mActivity;
201 }
202
Michael Kolb8233fac2010-10-26 16:08:53 -0700203 // key handling
204
205 @Override
206 public boolean onBackKey() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700207 if (mCustomView != null) {
208 mUiController.hideCustomView();
209 return true;
Vivek Sekharf96064b2014-07-28 16:32:34 -0700210 } else if ((mTabControl.getCurrentTab() != null) &&
Sudheer Koganti24766882014-10-02 10:58:09 -0700211 (mTabControl.getCurrentTab().exitFullscreen())) {
Vivek Sekhar13ad9b92014-06-16 15:49:54 -0700212 return true;
Michael Kolb8233fac2010-10-26 16:08:53 -0700213 }
214 return false;
215 }
216
Michael Kolb2814a362011-05-19 15:49:41 -0700217 @Override
218 public boolean onMenuKey() {
219 return false;
220 }
221
John Reck30c714c2010-12-16 17:30:34 -0800222 // Tab callbacks
Michael Kolb8233fac2010-10-26 16:08:53 -0700223 @Override
John Reck30c714c2010-12-16 17:30:34 -0800224 public void onTabDataChanged(Tab tab) {
225 setUrlTitle(tab);
226 setFavicon(tab);
227 updateLockIconToLatest(tab);
Michael Kolb5a72f182011-01-13 20:35:06 -0800228 updateNavigationState(tab);
John Reckef654f12011-07-12 16:42:08 -0700229 mTitleBar.onTabDataChanged(tab);
John Reck419f6b42011-08-16 16:10:51 -0700230 mNavigationBar.onTabDataChanged(tab);
Michael Kolba53c9892011-10-05 13:31:40 -0700231 onProgressChanged(tab);
Michael Kolb8233fac2010-10-26 16:08:53 -0700232 }
233
234 @Override
Michael Kolbe8a82332012-04-25 14:14:26 -0700235 public void onProgressChanged(Tab tab) {
236 int progress = tab.getLoadProgress();
237 if (tab.inForeground()) {
238 mTitleBar.setProgress(progress);
239 }
240 }
241
242 @Override
Leon Scroggins4cd97792010-12-03 15:31:56 -0500243 public void bookmarkedStatusHasChanged(Tab tab) {
John Reck94b7e042011-02-15 15:02:33 -0800244 if (tab.inForeground()) {
245 boolean isBookmark = tab.isBookmarkedSite();
John Reck0f602f32011-07-07 15:38:43 -0700246 mNavigationBar.setCurrentUrlIsBookmark(isBookmark);
John Reck94b7e042011-02-15 15:02:33 -0800247 }
Leon Scroggins4cd97792010-12-03 15:31:56 -0500248 }
249
250 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700251 public void onPageStopped(Tab tab) {
252 cancelStopToast();
253 if (tab.inForeground()) {
254 mStopToast = Toast
255 .makeText(mActivity, R.string.stopping, Toast.LENGTH_SHORT);
256 mStopToast.show();
257 }
258 }
259
260 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800261 public boolean needsRestoreAllTabs() {
John Reck847b5322011-04-14 17:02:18 -0700262 return true;
Michael Kolb1bf23132010-11-19 12:55:12 -0800263 }
264
265 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700266 public void addTab(Tab tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700267 }
268
269 @Override
Michael Kolb377ea312011-02-17 14:36:56 -0800270 public void setActiveTab(final Tab tab) {
Michael Kolb7ac63b62011-12-16 09:52:29 -0800271 if (tab == null) return;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400272 Tab tabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700273 Tab tabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400274
Michael Kolbbae0cb22012-05-29 11:15:27 -0700275 // block unnecessary focus change animations during tab switch
276 mBlockFocusAnimations = true;
John Reck5d43ce82011-06-21 17:16:51 -0700277 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb77df4562010-11-19 14:49:34 -0800278 if ((tab != mActiveTab) && (mActiveTab != null)) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400279 tabToRemove = mActiveTab;
John Reckbf2ec202011-06-29 17:47:38 -0700280 WebView web = mActiveTab.getWebView();
281 if (web != null) {
282 web.setOnTouchListener(null);
283 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700284 }
Michael Kolb77df4562010-11-19 14:49:34 -0800285 mActiveTab = tab;
Michael Kolbda580632012-04-16 13:30:28 -0700286 BrowserWebView web = (BrowserWebView) mActiveTab.getWebView();
John Reck718a24d2011-08-12 11:08:30 -0700287 updateUrlBarAutoShowManagerTarget();
John Reck5d43ce82011-06-21 17:16:51 -0700288 attachTabToContentView(tab);
Michael Kolbda580632012-04-16 13:30:28 -0700289 if (web != null) {
290 // Request focus on the top window.
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700291 web.setTitleBar(mTitleBar);
292 mTitleBar.onScrollChanged();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700293 tabToWaitFor = mActiveTab;
Michael Kolbda580632012-04-16 13:30:28 -0700294 }
Michael Kolb4923c222012-04-02 16:18:36 -0700295 mTitleBar.bringToFront();
Michael Kolbf8963522012-04-10 10:52:34 -0700296 tab.getTopWindow().requestFocus();
Michael Kolb8233fac2010-10-26 16:08:53 -0700297 setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
John Reck30c714c2010-12-16 17:30:34 -0800298 onTabDataChanged(tab);
299 onProgressChanged(tab);
Michael Kolb03b6bc62011-09-02 16:19:53 -0700300 mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
Michael Kolbbae0cb22012-05-29 11:15:27 -0700301 mBlockFocusAnimations = false;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400302
Vivek Sekhar943f0672014-05-01 18:35:22 -0700303 scheduleRemoveTab(tabToRemove, tabToWaitFor);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400304 }
305
306 Tab mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700307 Tab mTabToWaitFor = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400308 int mNumRemoveTries = 0;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700309 Runnable mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400310
Vivek Sekhar943f0672014-05-01 18:35:22 -0700311 protected void scheduleRemoveTab(Tab tabToRemove, Tab tabToWaitFor) {
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400312 //remove previously scehduled tab
313 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700314 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700315 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400316 removeTabFromContentView(mTabToRemove);
317 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700318 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400319 }
Vivek Sekhar943f0672014-05-01 18:35:22 -0700320 mTabToRemove = tabToRemove;
321 mTabToWaitFor = tabToWaitFor;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400322 mNumRemoveTries = 0;
323
324 if (mTabToRemove != null) {
325 mTabToRemove.postponeDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700326 tryRemoveTab();
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400327 }
328 }
329
330 protected void tryRemoveTab() {
331 mNumRemoveTries++;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700332 // Ensure the webview is still valid
333 if (mNumRemoveTries < 20 && mTabToWaitFor.getWebView() != null) {
334 if (!mTabToWaitFor.getWebView().isReady()) {
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700335 if (mRunnable == null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700336 mRunnable = new Runnable() {
337 public void run() {
338 tryRemoveTab();
339 }
340 };
341 }
342 /*if the new tab is still not ready, wait another 2 frames
343 before trying again. 1 frame for the tab to render the first
344 frame, another 1 frame to make sure the swap is done*/
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700345 mTitleBar.postDelayed(mRunnable, 33);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400346 return;
347 }
348 }
349 if (mTabToRemove != null) {
Vivek Sekhar943f0672014-05-01 18:35:22 -0700350 if (mRunnable != null)
Axesh R. Ajmera2e241242014-05-19 15:53:38 -0700351 mTitleBar.removeCallbacks(mRunnable);
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400352 removeTabFromContentView(mTabToRemove);
353 mTabToRemove.performPostponedDestroy();
Vivek Sekhar943f0672014-05-01 18:35:22 -0700354 mRunnable = null;
Matthew Huib7f2e9c2014-04-16 11:12:37 -0400355 }
356 mTabToRemove = null;
Vivek Sekhar943f0672014-05-01 18:35:22 -0700357 mTabToWaitFor = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700358 }
359
John Reck718a24d2011-08-12 11:08:30 -0700360 protected void updateUrlBarAutoShowManagerTarget() {
361 WebView web = mActiveTab != null ? mActiveTab.getWebView() : null;
Vivek Sekhar3bec6a32014-10-22 17:03:42 -0700362 if (web instanceof BrowserWebView) {
John Reck718a24d2011-08-12 11:08:30 -0700363 mUrlBarAutoShowManager.setTarget((BrowserWebView) web);
John Reck718a24d2011-08-12 11:08:30 -0700364 }
365 }
366
Michael Kolbcfa3af52010-12-14 10:36:11 -0800367 Tab getActiveTab() {
368 return mActiveTab;
369 }
370
Michael Kolb8233fac2010-10-26 16:08:53 -0700371 @Override
Michael Kolb1bf23132010-11-19 12:55:12 -0800372 public void updateTabs(List<Tab> tabs) {
Michael Kolb1bf23132010-11-19 12:55:12 -0800373 }
374
375 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700376 public void removeTab(Tab tab) {
Michael Kolb77df4562010-11-19 14:49:34 -0800377 if (mActiveTab == tab) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700378 removeTabFromContentView(tab);
Michael Kolb77df4562010-11-19 14:49:34 -0800379 mActiveTab = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700380 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700381 }
382
383 @Override
384 public void detachTab(Tab tab) {
385 removeTabFromContentView(tab);
386 }
387
388 @Override
389 public void attachTab(Tab tab) {
390 attachTabToContentView(tab);
391 }
392
Michael Kolb377ea312011-02-17 14:36:56 -0800393 protected void attachTabToContentView(Tab tab) {
Michael Kolbd1e2ccc2011-01-24 11:38:31 -0800394 if ((tab == null) || (tab.getWebView() == null)) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700395 return;
396 }
397 View container = tab.getViewContainer();
398 WebView mainView = tab.getWebView();
399 // Attach the WebView to the container and then attach the
400 // container to the content view.
401 FrameLayout wrapper =
402 (FrameLayout) container.findViewById(R.id.webview_wrapper);
403 ViewGroup parent = (ViewGroup) mainView.getParent();
404 if (parent != wrapper) {
405 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700406 parent.removeView(mainView);
407 }
408 wrapper.addView(mainView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700409 }
410 parent = (ViewGroup) container.getParent();
411 if (parent != mContentView) {
412 if (parent != null) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700413 parent.removeView(container);
414 }
415 mContentView.addView(container, COVER_SCREEN_PARAMS);
Michael Kolb8233fac2010-10-26 16:08:53 -0700416 }
417 mUiController.attachSubWindow(tab);
418 }
419
420 private void removeTabFromContentView(Tab tab) {
Michael Kolb7cdc4902011-02-03 17:54:40 -0800421 hideTitleBar();
Michael Kolb8233fac2010-10-26 16:08:53 -0700422 // Remove the container that contains the main WebView.
423 WebView mainView = tab.getWebView();
424 View container = tab.getViewContainer();
425 if (mainView == null) {
426 return;
427 }
428 // Remove the container from the content and then remove the
429 // WebView from the container. This will trigger a focus change
430 // needed by WebView.
431 FrameLayout wrapper =
432 (FrameLayout) container.findViewById(R.id.webview_wrapper);
433 wrapper.removeView(mainView);
434 mContentView.removeView(container);
435 mUiController.endActionMode();
436 mUiController.removeSubWindow(tab);
437 ErrorConsoleView errorConsole = tab.getErrorConsole(false);
438 if (errorConsole != null) {
439 mErrorConsoleContainer.removeView(errorConsole);
440 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700441 }
442
Michael Kolba713ec82010-11-29 17:27:06 -0800443 @Override
444 public void onSetWebView(Tab tab, WebView webView) {
445 View container = tab.getViewContainer();
446 if (container == null) {
447 // The tab consists of a container view, which contains the main
448 // WebView, as well as any other UI elements associated with the tab.
449 container = mActivity.getLayoutInflater().inflate(R.layout.tab,
John Reck7c6e1c92011-06-30 11:55:55 -0700450 mContentView, false);
Michael Kolba713ec82010-11-29 17:27:06 -0800451 tab.setViewContainer(container);
452 }
453 if (tab.getWebView() != webView) {
454 // Just remove the old one.
455 FrameLayout wrapper =
456 (FrameLayout) container.findViewById(R.id.webview_wrapper);
457 wrapper.removeView(tab.getWebView());
458 }
459 }
460
Michael Kolb8233fac2010-10-26 16:08:53 -0700461 /**
Michael Kolb1514bb72010-11-22 09:11:48 -0800462 * create a sub window container and webview for the tab
463 * Note: this methods operates through side-effects for now
464 * it sets both the subView and subViewContainer for the given tab
465 * @param tab tab to create the sub window for
466 * @param subView webview to be set as a subwindow for the tab
467 */
468 @Override
469 public void createSubWindow(Tab tab, WebView subView) {
470 View subViewContainer = mActivity.getLayoutInflater().inflate(
471 R.layout.browser_subwindow, null);
472 ViewGroup inner = (ViewGroup) subViewContainer
473 .findViewById(R.id.inner_container);
474 inner.addView(subView, new LayoutParams(LayoutParams.MATCH_PARENT,
475 LayoutParams.MATCH_PARENT));
476 final ImageButton cancel = (ImageButton) subViewContainer
477 .findViewById(R.id.subwindow_close);
478 final WebView cancelSubView = subView;
479 cancel.setOnClickListener(new OnClickListener() {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800480 @Override
Michael Kolb1514bb72010-11-22 09:11:48 -0800481 public void onClick(View v) {
Jonathan Dixone1d6dfc2012-12-17 13:39:17 -0800482 ((BrowserWebView) cancelSubView).getWebChromeClient().onCloseWindow(cancelSubView);
Michael Kolb1514bb72010-11-22 09:11:48 -0800483 }
484 });
485 tab.setSubWebView(subView);
486 tab.setSubViewContainer(subViewContainer);
487 }
488
489 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700490 * Remove the sub window from the content view.
491 */
492 @Override
493 public void removeSubWindow(View subviewContainer) {
494 mContentView.removeView(subviewContainer);
495 mUiController.endActionMode();
496 }
497
498 /**
499 * Attach the sub window to the content view.
500 */
501 @Override
502 public void attachSubWindow(View container) {
Michael Kolb1514bb72010-11-22 09:11:48 -0800503 if (container.getParent() != null) {
504 // already attached, remove first
505 ((ViewGroup) container.getParent()).removeView(container);
506 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700507 mContentView.addView(container, COVER_SCREEN_PARAMS);
508 }
509
Michael Kolb11d19782011-03-20 10:17:40 -0700510 protected void refreshWebView() {
Michael Kolb46f987e2011-04-05 10:39:10 -0700511 WebView web = getWebView();
512 if (web != null) {
513 web.invalidate();
Michael Kolb11d19782011-03-20 10:17:40 -0700514 }
515 }
516
Michael Kolb1f9b3562012-04-24 14:38:34 -0700517 public void editUrl(boolean clearInput, boolean forceIME) {
Michael Kolb46f987e2011-04-05 10:39:10 -0700518 if (mUiController.isInCustomActionMode()) {
519 mUiController.endActionMode();
520 }
521 showTitleBar();
Michael Kolbace2ff82011-08-12 13:36:07 -0700522 if ((getActiveTab() != null) && !getActiveTab().isSnapshot()) {
Michael Kolb1f9b3562012-04-24 14:38:34 -0700523 mNavigationBar.startEditingUrl(clearInput, forceIME);
John Reckef654f12011-07-12 16:42:08 -0700524 }
Michael Kolb46f987e2011-04-05 10:39:10 -0700525 }
526
Michael Kolb7cdc4902011-02-03 17:54:40 -0800527 boolean canShowTitleBar() {
528 return !isTitleBarShowing()
529 && !isActivityPaused()
530 && (getActiveTab() != null)
Michael Kolb46f987e2011-04-05 10:39:10 -0700531 && (getWebView() != null)
Michael Kolb7cdc4902011-02-03 17:54:40 -0800532 && !mUiController.isInCustomActionMode();
533 }
534
John Reck0f602f32011-07-07 15:38:43 -0700535 protected void showTitleBar() {
John Reckef654f12011-07-12 16:42:08 -0700536 mHandler.removeMessages(MSG_HIDE_TITLEBAR);
Michael Kolb46f987e2011-04-05 10:39:10 -0700537 if (canShowTitleBar()) {
John Reck0f602f32011-07-07 15:38:43 -0700538 mTitleBar.show();
Michael Kolb46f987e2011-04-05 10:39:10 -0700539 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800540 }
541
542 protected void hideTitleBar() {
John Reck0f602f32011-07-07 15:38:43 -0700543 if (mTitleBar.isShowing()) {
544 mTitleBar.hide();
Michael Kolb46f987e2011-04-05 10:39:10 -0700545 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800546 }
547
548 protected boolean isTitleBarShowing() {
John Reck0f602f32011-07-07 15:38:43 -0700549 return mTitleBar.isShowing();
Michael Kolb7cdc4902011-02-03 17:54:40 -0800550 }
551
John Reck5d43ce82011-06-21 17:16:51 -0700552 public boolean isEditingUrl() {
John Reck0f602f32011-07-07 15:38:43 -0700553 return mTitleBar.isEditingUrl();
John Reck5d43ce82011-06-21 17:16:51 -0700554 }
555
Michael Kolb80f75082012-04-10 10:50:06 -0700556 public void stopEditingUrl() {
557 mTitleBar.getNavigationBar().stopEditingUrl();
558 }
559
John Reck0f602f32011-07-07 15:38:43 -0700560 public TitleBar getTitleBar() {
561 return mTitleBar;
562 }
Michael Kolb7cdc4902011-02-03 17:54:40 -0800563
Michael Kolb66706532010-12-12 19:50:22 -0800564 @Override
John Reck2bc80422011-06-30 15:11:49 -0700565 public void showComboView(ComboViews startingView, Bundle extras) {
John Reckd3e4d5b2011-07-13 15:48:43 -0700566 Intent intent = new Intent(mActivity, ComboViewActivity.class);
567 intent.putExtra(ComboViewActivity.EXTRA_INITIAL_VIEW, startingView.name());
568 intent.putExtra(ComboViewActivity.EXTRA_COMBO_ARGS, extras);
569 Tab t = getActiveTab();
570 if (t != null) {
571 intent.putExtra(ComboViewActivity.EXTRA_CURRENT_URL, t.getUrl());
John Reck439c9a52010-12-14 10:04:39 -0800572 }
John Reckd3e4d5b2011-07-13 15:48:43 -0700573 mActivity.startActivityForResult(intent, Controller.COMBO_VIEW);
Michael Kolb8233fac2010-10-26 16:08:53 -0700574 }
575
576 @Override
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400577 public void showCustomView(View view, int requestedOrientation,
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800578 CustomViewCallback callback) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700579 // if a view already exists then immediately terminate the new one
580 if (mCustomView != null) {
581 callback.onCustomViewHidden();
582 return;
583 }
584
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400585 mOriginalOrientation = mActivity.getRequestedOrientation();
Michael Kolb31065b12011-10-06 13:51:32 -0700586 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400587 decor.addView(view, COVER_SCREEN_PARAMS);
Michael Kolb31065b12011-10-06 13:51:32 -0700588 mCustomView = view;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400589 showFullscreen(true);
Michael Kolb54217b32012-05-15 13:24:24 -0700590 ((BrowserWebView) getWebView()).setVisibility(View.INVISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700591 mCustomViewCallback = callback;
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400592 mActivity.setRequestedOrientation(requestedOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700593 }
594
595 @Override
596 public void onHideCustomView() {
Michael Kolb54217b32012-05-15 13:24:24 -0700597 ((BrowserWebView) getWebView()).setVisibility(View.VISIBLE);
Michael Kolb8233fac2010-10-26 16:08:53 -0700598 if (mCustomView == null)
599 return;
Denise LaFayetteda31d742014-10-10 18:03:13 -0400600 showFullscreen(false);
Michael Kolb31065b12011-10-06 13:51:32 -0700601 FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView();
Denise LaFayetteda31d742014-10-10 18:03:13 -0400602 decor.removeView(mCustomView);
Michael Kolb8233fac2010-10-26 16:08:53 -0700603 mCustomView = null;
Michael Kolb8233fac2010-10-26 16:08:53 -0700604 mCustomViewCallback.onCustomViewHidden();
605 // Show the content view.
Derek Sollenberger2d4f1e22011-06-01 14:50:42 -0400606 mActivity.setRequestedOrientation(mOriginalOrientation);
Michael Kolb8233fac2010-10-26 16:08:53 -0700607 }
608
609 @Override
610 public boolean isCustomViewShowing() {
611 return mCustomView != null;
612 }
613
Michael Kolb66706532010-12-12 19:50:22 -0800614 protected void dismissIME() {
Michael Kolb3a696282010-12-05 13:23:24 -0800615 if (mInputManager.isActive()) {
616 mInputManager.hideSoftInputFromWindow(mContentView.getWindowToken(),
617 0);
618 }
619 }
620
Michael Kolb66706532010-12-12 19:50:22 -0800621 @Override
John Reck3ba45532011-08-11 16:26:53 -0700622 public boolean isWebShowing() {
John Reckd3e4d5b2011-07-13 15:48:43 -0700623 return mCustomView == null;
Michael Kolb66706532010-12-12 19:50:22 -0800624 }
625
Michael Kolb8233fac2010-10-26 16:08:53 -0700626 // -------------------------------------------------------------------------
627
Michael Kolb5a72f182011-01-13 20:35:06 -0800628 protected void updateNavigationState(Tab tab) {
629 }
630
Michael Kolb8233fac2010-10-26 16:08:53 -0700631 /**
632 * Update the lock icon to correspond to our latest state.
633 */
Michael Kolb66706532010-12-12 19:50:22 -0800634 protected void updateLockIconToLatest(Tab t) {
John Reck30c714c2010-12-16 17:30:34 -0800635 if (t != null && t.inForeground()) {
Steve Block2466eff2011-10-03 15:33:09 +0100636 updateLockIconImage(t.getSecurityState());
Michael Kolb8233fac2010-10-26 16:08:53 -0700637 }
638 }
639
640 /**
Michael Kolb8233fac2010-10-26 16:08:53 -0700641 * Updates the lock-icon image in the title-bar.
642 */
Steve Block2466eff2011-10-03 15:33:09 +0100643 private void updateLockIconImage(SecurityState securityState) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700644 Drawable d = null;
Steve Block2466eff2011-10-03 15:33:09 +0100645 if (securityState == SecurityState.SECURITY_STATE_SECURE) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700646 d = getLockIconSecure();
Steve Block4895b012011-10-03 16:26:46 +0100647 } else if (securityState == SecurityState.SECURITY_STATE_MIXED
648 || securityState == SecurityState.SECURITY_STATE_BAD_CERTIFICATE) {
649 // TODO: It would be good to have different icons for insecure vs mixed content.
650 // See http://b/5403800
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700651 d = getLockIconMixed();
Michael Kolb8233fac2010-10-26 16:08:53 -0700652 }
John Reck0f602f32011-07-07 15:38:43 -0700653 mNavigationBar.setLock(d);
Michael Kolb8233fac2010-10-26 16:08:53 -0700654 }
655
John Reck30c714c2010-12-16 17:30:34 -0800656 protected void setUrlTitle(Tab tab) {
657 String url = tab.getUrl();
658 String title = tab.getTitle();
Michael Kolb66706532010-12-12 19:50:22 -0800659 if (TextUtils.isEmpty(title)) {
660 title = url;
Michael Kolb81b6f832010-12-12 12:44:27 -0800661 }
Michael Kolb66706532010-12-12 19:50:22 -0800662 if (tab.inForeground()) {
John Reck0f602f32011-07-07 15:38:43 -0700663 mNavigationBar.setDisplayTitle(url);
Michael Kolb66706532010-12-12 19:50:22 -0800664 }
665 }
666
667 // Set the favicon in the title bar.
John Reck30c714c2010-12-16 17:30:34 -0800668 protected void setFavicon(Tab tab) {
669 if (tab.inForeground()) {
670 Bitmap icon = tab.getFavicon();
John Reck0f602f32011-07-07 15:38:43 -0700671 mNavigationBar.setFavicon(icon);
John Reck30c714c2010-12-16 17:30:34 -0800672 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700673 }
674
Michael Kolb66706532010-12-12 19:50:22 -0800675 // active tabs page
676
677 public void showActiveTabsPage() {
678 }
679
680 /**
681 * Remove the active tabs page.
682 */
683 public void removeActiveTabsPage() {
684 }
685
Michael Kolb8233fac2010-10-26 16:08:53 -0700686 // menu handling callbacks
687
688 @Override
Michael Kolb1acef692011-03-08 14:12:06 -0800689 public boolean onPrepareOptionsMenu(Menu menu) {
690 return true;
691 }
692
693 @Override
Michael Kolb7bdee0b2011-08-01 11:55:38 -0700694 public void updateMenuState(Tab tab, Menu menu) {
695 }
696
697 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700698 public void onOptionsMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700699 }
700
701 @Override
702 public void onExtendedMenuOpened() {
Michael Kolb8233fac2010-10-26 16:08:53 -0700703 }
704
705 @Override
Michael Kolb3ca12752011-07-20 13:52:25 -0700706 public boolean onOptionsItemSelected(MenuItem item) {
707 return false;
708 }
709
710 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700711 public void onOptionsMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700712 }
713
714 @Override
715 public void onExtendedMenuClosed(boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700716 }
717
718 @Override
719 public void onContextMenuCreated(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700720 }
721
722 @Override
723 public void onContextMenuClosed(Menu menu, boolean inLoad) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700724 }
725
726 // error console
727
728 @Override
729 public void setShouldShowErrorConsole(Tab tab, boolean flag) {
Michael Kolb9fcefd12011-02-17 10:55:59 -0800730 if (tab == null) return;
Michael Kolb8233fac2010-10-26 16:08:53 -0700731 ErrorConsoleView errorConsole = tab.getErrorConsole(true);
732 if (flag) {
733 // Setting the show state of the console will cause it's the layout
734 // to be inflated.
735 if (errorConsole.numberOfErrors() > 0) {
736 errorConsole.showConsole(ErrorConsoleView.SHOW_MINIMIZED);
737 } else {
738 errorConsole.showConsole(ErrorConsoleView.SHOW_NONE);
739 }
740 if (errorConsole.getParent() != null) {
741 mErrorConsoleContainer.removeView(errorConsole);
742 }
743 // Now we can add it to the main view.
744 mErrorConsoleContainer.addView(errorConsole,
745 new LinearLayout.LayoutParams(
746 ViewGroup.LayoutParams.MATCH_PARENT,
747 ViewGroup.LayoutParams.WRAP_CONTENT));
748 } else {
749 mErrorConsoleContainer.removeView(errorConsole);
750 }
751 }
752
Michael Kolb8233fac2010-10-26 16:08:53 -0700753 // -------------------------------------------------------------------------
754 // Helper function for WebChromeClient
755 // -------------------------------------------------------------------------
756
757 @Override
758 public Bitmap getDefaultVideoPoster() {
759 if (mDefaultVideoPoster == null) {
760 mDefaultVideoPoster = BitmapFactory.decodeResource(
761 mActivity.getResources(), R.drawable.default_video_poster);
762 }
763 return mDefaultVideoPoster;
764 }
765
766 @Override
767 public View getVideoLoadingProgressView() {
768 if (mVideoProgressView == null) {
769 LayoutInflater inflater = LayoutInflater.from(mActivity);
770 mVideoProgressView = inflater.inflate(
771 R.layout.video_loading_progress, null);
772 }
773 return mVideoProgressView;
774 }
775
Michael Kolb843510f2010-12-09 10:51:49 -0800776 @Override
777 public void showMaxTabsWarning() {
778 Toast warning = Toast.makeText(mActivity,
779 mActivity.getString(R.string.max_tabs_warning),
780 Toast.LENGTH_SHORT);
781 warning.show();
782 }
783
Michael Kolb46f987e2011-04-05 10:39:10 -0700784 protected WebView getWebView() {
785 if (mActiveTab != null) {
786 return mActiveTab.getWebView();
787 } else {
788 return null;
789 }
Michael Kolbfdb70242011-03-24 09:41:11 -0700790 }
791
Michael Kolbc38c6042011-04-27 10:46:06 -0700792 public void setFullscreen(boolean enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700793 Window win = mActivity.getWindow();
794 WindowManager.LayoutParams winParams = win.getAttributes();
Michael Kolb76dff392011-12-06 09:51:18 -0800795 final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
Michael Kolbc38c6042011-04-27 10:46:06 -0700796 if (enabled) {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700797 winParams.flags |= bits;
Michael Kolbc38c6042011-04-27 10:46:06 -0700798 } else {
Michael Kolbc5675ad2011-10-21 13:34:28 -0700799 winParams.flags &= ~bits;
800 if (mCustomView != null) {
801 mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
802 } else {
803 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
804 }
Michael Kolbc38c6042011-04-27 10:46:06 -0700805 }
Michael Kolbc5675ad2011-10-21 13:34:28 -0700806 win.setAttributes(winParams);
Michael Kolbc38c6042011-04-27 10:46:06 -0700807 }
808
Denise LaFayetteda31d742014-10-10 18:03:13 -0400809 //make full screen by showing/hiding topbar and system status bar
Sudheer Koganti24766882014-10-02 10:58:09 -0700810 public void showFullscreen(boolean fullScreen) {
811 //Hide/show system ui bar as needed
812 if (!BrowserSettings.getInstance().useFullscreen())
813 setFullscreen(fullScreen);
814
815 //Hide/show topbar as needed
816 if (getWebView() != null) {
817 if (fullScreen) {
818 //hide topbar
819 getWebView().updateTopControls(true, false, false);
820 } else {
821 //show the topbar
822 getWebView().updateTopControls(false, true, true);
823 //enable for auto-hide
824 if (!mTitleBar.isFixed())
825 getWebView().updateTopControls(true, true, false);
826 }
827 }
828 }
829
830
831
Tarun Nainani8eb00912014-07-17 12:28:32 -0700832 public void translateTitleBar(float topControlsOffsetYPix) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700833 if (mTitleBar != null && !mInActionMode) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700834 mTitleBar.bringToFront();
835 if (topControlsOffsetYPix != 0.0) {
836 mTitleBar.setEnabled(false);
837 } else {
838 mTitleBar.setEnabled(true);
839 }
Vivek Sekhar8a660782014-10-27 17:00:53 -0700840 if (!mTitleBar.isFixed() && !isLoading())
841 mTitleBar.setTranslationY(topControlsOffsetYPix);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700842 }
843 }
844
John Reck0f602f32011-07-07 15:38:43 -0700845 public Drawable getFaviconDrawable(Bitmap icon) {
Michael Kolb5a4372f2011-04-29 13:53:10 -0700846 Drawable[] array = new Drawable[3];
847 array[0] = new PaintDrawable(Color.BLACK);
848 PaintDrawable p = new PaintDrawable(Color.WHITE);
849 array[1] = p;
850 if (icon == null) {
Kulanthaivel Palanichamy3817bac2014-10-23 19:11:17 -0700851 array[2] = getGenericFavicon();
Michael Kolb5a4372f2011-04-29 13:53:10 -0700852 } else {
853 array[2] = new BitmapDrawable(icon);
854 }
855 LayerDrawable d = new LayerDrawable(array);
856 d.setLayerInset(1, 1, 1, 1, 1);
857 d.setLayerInset(2, 2, 2, 2, 2);
858 return d;
859 }
860
John Reck5d43ce82011-06-21 17:16:51 -0700861 public boolean isLoading() {
862 return mActiveTab != null ? mActiveTab.inPageLoad() : false;
863 }
864
865 /**
866 * Suggest to the UI that the title bar can be hidden. The UI will then
867 * decide whether or not to hide based off a number of factors, such
868 * as if the user is editing the URL bar or if the page is loading
869 */
870 public void suggestHideTitleBar() {
John Reck58891902011-08-11 17:48:53 -0700871 if (!isLoading() && !isEditingUrl() && !mTitleBar.wantsToBeVisible()
872 && !mNavigationBar.isMenuShowing()) {
John Reck5d43ce82011-06-21 17:16:51 -0700873 hideTitleBar();
874 }
875 }
876
John Reckbc6adb42011-09-01 18:03:20 -0700877 protected final void showTitleBarForDuration() {
878 showTitleBarForDuration(HIDE_TITLEBAR_DELAY);
879 }
880
881 protected final void showTitleBarForDuration(long duration) {
John Reck6ac5bfd2011-07-01 17:02:55 -0700882 showTitleBar();
883 Message msg = Message.obtain(mHandler, MSG_HIDE_TITLEBAR);
John Reckbc6adb42011-09-01 18:03:20 -0700884 mHandler.sendMessageDelayed(msg, duration);
John Reck6ac5bfd2011-07-01 17:02:55 -0700885 }
886
John Reck9c5004e2011-10-07 16:00:12 -0700887 protected Handler mHandler = new Handler() {
John Reck5d43ce82011-06-21 17:16:51 -0700888
889 @Override
890 public void handleMessage(Message msg) {
891 if (msg.what == MSG_HIDE_TITLEBAR) {
892 suggestHideTitleBar();
893 }
John Reck9c5004e2011-10-07 16:00:12 -0700894 BaseUi.this.handleMessage(msg);
John Reck5d43ce82011-06-21 17:16:51 -0700895 }
896 };
John Reck3ba45532011-08-11 16:26:53 -0700897
John Reck9c5004e2011-10-07 16:00:12 -0700898 protected void handleMessage(Message msg) {}
899
John Reck3ba45532011-08-11 16:26:53 -0700900 @Override
901 public void showWeb(boolean animate) {
902 mUiController.hideCustomView();
903 }
904
John Reck2711fab2012-05-18 21:38:59 -0700905 public void setContentViewMarginTop(int margin) {
906 LinearLayout.LayoutParams params =
907 (LinearLayout.LayoutParams) mContentView.getLayoutParams();
908 if (params.topMargin != margin) {
909 params.topMargin = margin;
910 mContentView.setLayoutParams(params);
911 }
912 }
Michael Kolbbae0cb22012-05-29 11:15:27 -0700913
914 @Override
915 public boolean blockFocusAnimations() {
916 return mBlockFocusAnimations;
917 }
918
Michael Kolb0b129122012-06-04 16:31:58 -0700919 @Override
920 public void onVoiceResult(String result) {
921 mNavigationBar.onVoiceResult(result);
922 }
923
kaiyizbb2db872013-08-01 22:24:07 -0400924 protected UiController getUiController() {
925 return mUiController;
926 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700927
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700928 boolean mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700929 private float getActionModeHeight() {
930 TypedArray actionBarSizeTypedArray = mActivity.obtainStyledAttributes(
931 new int[] { android.R.attr.actionBarSize });
932 float size = actionBarSizeTypedArray.getDimension(0, 0f);
933 actionBarSizeTypedArray.recycle();
934 return size;
935 }
936
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700937
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700938 @Override
939 public void onActionModeStarted(ActionMode mode) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700940 mInActionMode = true;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700941
942 if (mTitleBar.isFixed()) {
943 int fixedTbarHeight = mTitleBar.calculateEmbeddedHeight();
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700944 mFixedTitlebarContainer.setY(fixedTbarHeight);
945 setContentViewMarginTop(fixedTbarHeight);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700946 } else {
947 mTitleBar.setTranslationY(getActionModeHeight());
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700948 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700949 }
950
951 @Override
952 public void onActionModeFinished(boolean inLoad) {
Vivek Sekhar60eb9802014-07-21 19:13:33 -0700953 mInActionMode = false;
Tarun Nainani8eb00912014-07-17 12:28:32 -0700954 if (mTitleBar.isFixed()) {
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700955 mFixedTitlebarContainer.setY(0);
956 setContentViewMarginTop(0);
Tarun Nainani8eb00912014-07-17 12:28:32 -0700957 } else {
958 mTitleBar.setTranslationY(0);
Vivek Sekhar8ee3abb2014-07-14 12:32:05 -0700959 }
Bijan Amirzada357ec8a2014-04-08 14:19:10 -0700960 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700961}