The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 17 | package com.android.browser; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 18 | |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 19 | import android.app.ActionBar; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 20 | import android.app.Activity; |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 21 | import android.app.KeyguardManager; |
John Reck | 9d27ff5 | 2011-02-11 17:47:54 -0800 | [diff] [blame] | 22 | import android.content.Context; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 24 | import android.content.res.Configuration; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 25 | import android.os.Bundle; |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 26 | import android.os.Handler; |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 27 | import android.os.PowerManager; |
Axesh R. Ajmera | cc28028 | 2015-03-25 16:31:03 -0700 | [diff] [blame] | 28 | import android.os.Process; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 30 | import android.view.ActionMode; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 31 | import android.view.ContextMenu; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 32 | import android.view.ContextMenu.ContextMenuInfo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 34 | import android.view.Menu; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 35 | import android.view.MenuItem; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 36 | import android.view.MotionEvent; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 37 | import android.view.View; |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 38 | import android.view.ViewGroup; |
| 39 | import android.view.ViewTreeObserver; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 40 | import android.view.Window; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 41 | |
Vivek Sekhar | ed791da | 2015-02-22 12:39:05 -0800 | [diff] [blame] | 42 | import org.chromium.base.VisibleForTesting; |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 43 | import com.android.browser.R; |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 44 | import com.android.browser.search.DefaultSearchEngine; |
| 45 | import com.android.browser.search.SearchEngine; |
| 46 | import com.android.browser.stub.NullController; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 47 | |
Axesh R. Ajmera | cc28028 | 2015-03-25 16:31:03 -0700 | [diff] [blame] | 48 | import java.util.Locale; |
| 49 | |
Dany Rybnikov | c912c55 | 2015-01-19 15:40:13 +0200 | [diff] [blame] | 50 | import org.codeaurora.swe.CookieManager; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 51 | import org.codeaurora.swe.WebView; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 52 | |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 53 | public class BrowserActivity extends Activity implements ViewTreeObserver.OnPreDrawListener { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 54 | |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 55 | public static final String ACTION_SHOW_BOOKMARKS = "show_bookmarks"; |
| 56 | public static final String ACTION_SHOW_BROWSER = "show_browser"; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 57 | public static final String ACTION_RESTART = "--restart--"; |
| 58 | private static final String EXTRA_STATE = "state"; |
John Reck | 38b3965 | 2012-06-05 09:22:59 -0700 | [diff] [blame] | 59 | public static final String EXTRA_DISABLE_URL_OVERRIDE = "disable_url_override"; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 60 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 61 | private final static String LOGTAG = "browser"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 62 | |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 63 | private final static boolean LOGV_ENABLED = Browser.LOGV_ENABLED; |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 64 | |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 65 | private ActivityController mController = NullController.INSTANCE; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 66 | |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 67 | private Handler mHandler = new Handler(); |
Axesh R. Ajmera | cc28028 | 2015-03-25 16:31:03 -0700 | [diff] [blame] | 68 | private final Locale mCurrentLocale = Locale.getDefault(); |
Axesh R. Ajmera | 3255876 | 2015-04-23 13:21:56 -0700 | [diff] [blame] | 69 | public static boolean killOnExitDialog = false; |
| 70 | |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 71 | |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 72 | private UiController mUiController; |
| 73 | private Handler mHandlerEx = new Handler(); |
| 74 | private Runnable runnable = new Runnable() { |
| 75 | @Override |
| 76 | public void run() { |
| 77 | if (mUiController != null) { |
| 78 | WebView current = mUiController.getCurrentWebView(); |
| 79 | if (current != null) { |
| 80 | current.postInvalidate(); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | }; |
| 85 | |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 86 | private Bundle mSavedInstanceState; |
| 87 | private EngineInitializer mEngineInitializer; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 88 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 89 | @Override |
| 90 | public void onCreate(Bundle icicle) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 91 | if (LOGV_ENABLED) { |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 92 | Log.v(LOGTAG, this + " onStart, has state: " |
| 93 | + (icicle == null ? "false" : "true")); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 94 | } |
| 95 | super.onCreate(icicle); |
Derek Sollenberger | ffa561e | 2010-11-16 14:19:01 -0500 | [diff] [blame] | 96 | |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 97 | if (shouldIgnoreIntents()) { |
| 98 | finish(); |
| 99 | return; |
| 100 | } |
| 101 | |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 102 | if (!isTablet(this)) { |
| 103 | final ActionBar bar = getActionBar(); |
| 104 | bar.hide(); |
| 105 | } |
| 106 | |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 107 | // If this was a web search request, pass it on to the default web |
| 108 | // search provider and finish this activity. |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 109 | /* |
kaiyiz | a2368f1 | 2013-09-02 10:43:31 +0800 | [diff] [blame] | 110 | SearchEngine searchEngine = BrowserSettings.getInstance().getSearchEngine(); |
| 111 | boolean result = IntentHandler.handleWebSearchIntent(this, null, getIntent()); |
| 112 | if (result && (searchEngine instanceof DefaultSearchEngine)) { |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 113 | finish(); |
| 114 | return; |
| 115 | } |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 116 | */ |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 117 | |
| 118 | mEngineInitializer = EngineInitializer.getInstance(); |
| 119 | mEngineInitializer.onActivityCreate(BrowserActivity.this); |
| 120 | |
| 121 | Thread.setDefaultUncaughtExceptionHandler(new CrashLogExceptionHandler(this)); |
| 122 | |
| 123 | mSavedInstanceState = icicle; |
| 124 | // Create the initial UI views |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 125 | mController = createController(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 126 | |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 127 | // Workaround for the black screen flicker on SurfaceView creation |
| 128 | ViewGroup topLayout = (ViewGroup) findViewById(R.id.main_content); |
| 129 | topLayout.requestTransparentRegion(topLayout); |
| 130 | |
| 131 | // Add pre-draw listener to start the controller after engine initialization. |
| 132 | final ViewTreeObserver observer = getWindow().getDecorView().getViewTreeObserver(); |
| 133 | observer.addOnPreDrawListener(this); |
| 134 | |
| 135 | mEngineInitializer.initializeResourceExtractor(this); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 138 | @Override |
| 139 | public boolean onPreDraw() |
| 140 | { |
| 141 | final ViewTreeObserver observer = getWindow().getDecorView().getViewTreeObserver(); |
| 142 | observer.removeOnPreDrawListener(this); |
| 143 | mEngineInitializer.onPreDraw(); |
| 144 | return true; |
| 145 | } |
| 146 | |
| 147 | |
John Reck | a5176f3 | 2011-05-17 12:35:37 -0700 | [diff] [blame] | 148 | public static boolean isTablet(Context context) { |
| 149 | return context.getResources().getBoolean(R.bool.isTablet); |
John Reck | 9d27ff5 | 2011-02-11 17:47:54 -0800 | [diff] [blame] | 150 | } |
| 151 | |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 152 | private Controller createController() { |
| 153 | Controller controller = new Controller(this); |
| 154 | boolean xlarge = isTablet(this); |
| 155 | UI ui = null; |
| 156 | if (xlarge) { |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 157 | XLargeUi tablet = new XLargeUi(this, controller); |
| 158 | ui = tablet; |
| 159 | mUiController = tablet.getUiController(); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 160 | } else { |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 161 | PhoneUi phone = new PhoneUi(this, controller); |
| 162 | ui = phone; |
| 163 | mUiController = phone.getUiController(); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 164 | } |
| 165 | controller.setUi(ui); |
| 166 | return controller; |
| 167 | } |
| 168 | |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 169 | public void onEngineInitializationComplete() { |
| 170 | Intent intent = (mSavedInstanceState == null) ? getIntent() : null; |
| 171 | mController.start(intent); |
| 172 | } |
| 173 | |
John Reck | 4155485 | 2010-12-01 12:53:37 -0800 | [diff] [blame] | 174 | @VisibleForTesting |
Tarun Nainani | 436b873 | 2014-06-10 13:58:41 -0700 | [diff] [blame] | 175 | //public to facilitate testing |
| 176 | public Controller getController() { |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 177 | return (Controller) mController; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 178 | } |
| 179 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 180 | @Override |
| 181 | protected void onNewIntent(Intent intent) { |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 182 | if (shouldIgnoreIntents()) return; |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 183 | mEngineInitializer.onNewIntent(intent); |
| 184 | // Note: Do not add any more application logic in this method. |
| 185 | // Move any additional app logic into handleOnNewIntent(). |
| 186 | } |
| 187 | |
| 188 | protected void handleOnNewIntent(Intent intent) { |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 189 | if (ACTION_RESTART.equals(intent.getAction())) { |
| 190 | Bundle outState = new Bundle(); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 191 | mController.onSaveInstanceState(outState); |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 192 | finish(); |
| 193 | getApplicationContext().startActivity( |
| 194 | new Intent(getApplicationContext(), BrowserActivity.class) |
| 195 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| 196 | .putExtra(EXTRA_STATE, outState)); |
| 197 | return; |
| 198 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 199 | mController.handleNewIntent(intent); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 200 | } |
| 201 | |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 202 | private KeyguardManager mKeyguardManager; |
| 203 | private PowerManager mPowerManager; |
| 204 | private boolean shouldIgnoreIntents() { |
| 205 | // Only process intents if the screen is on and the device is unlocked |
| 206 | // aka, if we will be user-visible |
| 207 | if (mKeyguardManager == null) { |
| 208 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 209 | } |
| 210 | if (mPowerManager == null) { |
| 211 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 212 | } |
| 213 | boolean ignore = !mPowerManager.isScreenOn(); |
| 214 | ignore |= mKeyguardManager.inKeyguardRestrictedInputMode(); |
| 215 | if (LOGV_ENABLED) { |
| 216 | Log.v(LOGTAG, "ignore intents: " + ignore); |
| 217 | } |
| 218 | return ignore; |
| 219 | } |
| 220 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 221 | @Override |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 222 | protected void onStart() { |
| 223 | super.onStart(); |
| 224 | mEngineInitializer.onActivityStart(); |
| 225 | } |
| 226 | |
| 227 | @Override |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 228 | protected void onResume() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 229 | super.onResume(); |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 230 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 231 | Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this); |
| 232 | } |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 233 | mEngineInitializer.onActivityResume(); |
| 234 | // Note: Do not add any more application logic in this method. |
| 235 | // Move any additional app logic into handleOnResume(). |
| 236 | } |
Tarun Nainani | ef749cb | 2014-05-19 18:16:53 -0700 | [diff] [blame] | 237 | |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 238 | protected void handleOnResume() { |
Tarun Nainani | b4a173f | 2015-01-05 09:23:08 -0800 | [diff] [blame] | 239 | // Note: Intentionally left blank. |
| 240 | } |
| 241 | |
| 242 | protected void handleOnStart() { |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 243 | mController.onResume(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 246 | @Override |
Tarun Nainani | b4a173f | 2015-01-05 09:23:08 -0800 | [diff] [blame] | 247 | protected void onStop() { |
| 248 | mEngineInitializer.onActivityStop(); |
| 249 | super.onStop(); |
| 250 | // Note: Do not add any more application logic in this method. |
| 251 | // Move any additional app logic into handleOnStop(). |
| 252 | } |
| 253 | |
| 254 | @Override |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 255 | public boolean onMenuOpened(int featureId, Menu menu) { |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 256 | if (Window.FEATURE_OPTIONS_PANEL == featureId) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 257 | mController.onMenuOpened(featureId, menu); |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 258 | } |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 259 | return true; |
| 260 | } |
| 261 | |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 262 | @Override |
| 263 | public void onOptionsMenuClosed(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 264 | mController.onOptionsMenuClosed(menu); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 265 | } |
| 266 | |
Leon Scroggins | b2b19f5 | 2009-10-09 16:10:00 -0400 | [diff] [blame] | 267 | @Override |
| 268 | public void onContextMenuClosed(Menu menu) { |
| 269 | super.onContextMenuClosed(menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 270 | mController.onContextMenuClosed(menu); |
Leon Scroggins | b2b19f5 | 2009-10-09 16:10:00 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 273 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 274 | * onSaveInstanceState(Bundle map) |
| 275 | * onSaveInstanceState is called right before onStop(). The map contains |
| 276 | * the saved state. |
| 277 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 278 | @Override |
| 279 | protected void onSaveInstanceState(Bundle outState) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 280 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 281 | Log.v(LOGTAG, "BrowserActivity.onSaveInstanceState: this=" + this); |
| 282 | } |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 283 | mController.onSaveInstanceState(outState); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 286 | @Override |
| 287 | protected void onPause() { |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 288 | mEngineInitializer.onActivityPause(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 289 | super.onPause(); |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 290 | // Note: Do not add any more application logic in this method. |
| 291 | // Move any additional app logic into handleOnPause(). |
| 292 | } |
| 293 | |
| 294 | protected void handleOnPause() { |
Tarun Nainani | b4a173f | 2015-01-05 09:23:08 -0800 | [diff] [blame] | 295 | // Note: Intentionally left blank |
| 296 | } |
| 297 | |
| 298 | protected void handleOnStop() { |
Dany Rybnikov | c912c55 | 2015-01-19 15:40:13 +0200 | [diff] [blame] | 299 | CookieManager.getInstance().flushCookieStore(); |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 300 | mController.onPause(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 303 | @Override |
| 304 | protected void onDestroy() { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 305 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 306 | Log.v(LOGTAG, "BrowserActivity.onDestroy: this=" + this); |
| 307 | } |
| 308 | super.onDestroy(); |
Enrico Ros | d6efa97 | 2014-12-02 19:49:59 -0800 | [diff] [blame] | 309 | // mEngineInitializer can be null if onCreate is not called before onDestroy |
| 310 | // it happens when starting the activity with an intent while the screen is locked. |
| 311 | if (mEngineInitializer != null) |
| 312 | mEngineInitializer.onActivityDestroy(); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 313 | mController.onDestroy(); |
| 314 | mController = NullController.INSTANCE; |
Axesh R. Ajmera | 3255876 | 2015-04-23 13:21:56 -0700 | [diff] [blame] | 315 | if (!Locale.getDefault().equals(mCurrentLocale) || killOnExitDialog) { |
| 316 | Log.i(LOGTAG,"Force Killing Browser"); |
Axesh R. Ajmera | cc28028 | 2015-03-25 16:31:03 -0700 | [diff] [blame] | 317 | Process.killProcess(Process.myPid()); |
| 318 | } |
| 319 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public void onConfigurationChanged(Configuration newConfig) { |
| 324 | super.onConfigurationChanged(newConfig); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 325 | mController.onConfgurationChanged(newConfig); |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 326 | |
| 327 | //For avoiding bug CR520353 temporarily, delay 300ms to refresh WebView. |
| 328 | mHandlerEx.postDelayed(runnable, 300); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 331 | @Override |
| 332 | public void onLowMemory() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 333 | super.onLowMemory(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 334 | mController.onLowMemory(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 335 | } |
| 336 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 337 | @Override |
Pankaj Garg | 49b7925 | 2014-11-07 17:33:41 -0800 | [diff] [blame] | 338 | public void invalidateOptionsMenu() { |
| 339 | super.invalidateOptionsMenu(); |
| 340 | mController.invalidateOptionsMenu(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 344 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 345 | super.onPrepareOptionsMenu(menu); |
Enrico Ros | 1f5a095 | 2014-11-18 20:15:48 -0800 | [diff] [blame] | 346 | return false; |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 347 | } |
| 348 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 349 | @Override |
| 350 | public boolean onOptionsItemSelected(MenuItem item) { |
Tarun Nainani | 87a8668 | 2015-02-05 11:47:35 -0800 | [diff] [blame] | 351 | if (item.getItemId() == android.R.id.home) { |
| 352 | mUiController.getUi().hideComboView(); |
| 353 | return true; |
| 354 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 355 | if (!mController.onOptionsItemSelected(item)) { |
| 356 | return super.onOptionsItemSelected(item); |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 357 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 358 | return true; |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void onCreateContextMenu(ContextMenu menu, View v, |
| 363 | ContextMenuInfo menuInfo) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 364 | mController.onCreateContextMenu(menu, v, menuInfo); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 367 | @Override |
| 368 | public boolean onContextItemSelected(MenuItem item) { |
| 369 | return mController.onContextItemSelected(item); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 372 | @Override |
| 373 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 374 | return mController.onKeyDown(keyCode, event) || |
| 375 | super.onKeyDown(keyCode, event); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 378 | @Override |
John Reck | e6bf4ab | 2011-02-24 15:48:05 -0800 | [diff] [blame] | 379 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 380 | return mController.onKeyLongPress(keyCode, event) || |
| 381 | super.onKeyLongPress(keyCode, event); |
| 382 | } |
| 383 | |
| 384 | @Override |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 385 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 386 | return mController.onKeyUp(keyCode, event) || |
| 387 | super.onKeyUp(keyCode, event); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 390 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 391 | public void onActionModeStarted(ActionMode mode) { |
| 392 | super.onActionModeStarted(mode); |
| 393 | mController.onActionModeStarted(mode); |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 396 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 397 | public void onActionModeFinished(ActionMode mode) { |
| 398 | super.onActionModeFinished(mode); |
| 399 | mController.onActionModeFinished(mode); |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 400 | } |
| 401 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 402 | @Override |
Kulanthaivel Palanichamy | 7794268 | 2014-10-28 11:52:06 -0700 | [diff] [blame] | 403 | protected void onActivityResult (int requestCode, int resultCode, |
| 404 | Intent intent) { |
| 405 | mEngineInitializer.onActivityResult(requestCode, resultCode, intent); |
| 406 | } |
| 407 | |
| 408 | protected void handleOnActivityResult (int requestCode, int resultCode, Intent intent) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 409 | mController.onActivityResult(requestCode, resultCode, intent); |
Andrei Popescu | 163ab74 | 2009-10-20 17:58:23 +0100 | [diff] [blame] | 410 | } |
| 411 | |
Michael Kolb | fbc579a | 2011-07-07 15:59:33 -0700 | [diff] [blame] | 412 | @Override |
| 413 | public boolean onSearchRequested() { |
| 414 | return mController.onSearchRequested(); |
| 415 | } |
| 416 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 417 | @Override |
| 418 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 419 | return mController.dispatchKeyEvent(event) |
| 420 | || super.dispatchKeyEvent(event); |
| 421 | } |
| 422 | |
| 423 | @Override |
| 424 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 425 | return mController.dispatchKeyShortcutEvent(event) |
| 426 | || super.dispatchKeyShortcutEvent(event); |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 431 | return mController.dispatchTouchEvent(ev) |
| 432 | || super.dispatchTouchEvent(ev); |
| 433 | } |
| 434 | |
| 435 | @Override |
| 436 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 437 | return mController.dispatchTrackballEvent(ev) |
| 438 | || super.dispatchTrackballEvent(ev); |
| 439 | } |
| 440 | |
| 441 | @Override |
| 442 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 443 | return mController.dispatchGenericMotionEvent(ev) || |
| 444 | super.dispatchGenericMotionEvent(ev); |
| 445 | } |
| 446 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 447 | } |