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 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 19 | import android.app.Activity; |
qqzhou | e6ff8b4 | 2013-07-23 17:28:48 +0800 | [diff] [blame] | 20 | import android.app.AlertDialog; |
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; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 28 | import android.util.Log; |
Leon Scroggins III | 8e4fbf1 | 2010-08-17 16:58:15 -0400 | [diff] [blame] | 29 | import android.view.ActionMode; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 30 | import android.view.ContextMenu; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 31 | import android.view.ContextMenu.ContextMenuInfo; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 32 | import android.view.KeyEvent; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 33 | import android.view.Menu; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 34 | import android.view.MenuItem; |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 35 | import android.view.MotionEvent; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 36 | import android.view.View; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 37 | import android.view.Window; |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 38 | import android.webkit.JavascriptInterface; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 39 | |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 40 | import com.google.common.annotations.VisibleForTesting; |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 41 | import com.android.browser.R; |
| 42 | import com.android.browser.UI.ComboViews; |
| 43 | import com.android.browser.search.DefaultSearchEngine; |
| 44 | import com.android.browser.search.SearchEngine; |
| 45 | import com.android.browser.stub.NullController; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 46 | |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 47 | import org.codeaurora.swe.WebSettings; |
| 48 | import org.codeaurora.swe.WebView; |
Tarun Nainani | ef749cb | 2014-05-19 18:16:53 -0700 | [diff] [blame^] | 49 | import org.chromium.content.browser.TracingControllerAndroid; |
John Reck | d3e4d5b | 2011-07-13 15:48:43 -0700 | [diff] [blame] | 50 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 51 | public class BrowserActivity extends Activity { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 52 | |
John Reck | 439c9a5 | 2010-12-14 10:04:39 -0800 | [diff] [blame] | 53 | public static final String ACTION_SHOW_BOOKMARKS = "show_bookmarks"; |
| 54 | public static final String ACTION_SHOW_BROWSER = "show_browser"; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 55 | public static final String ACTION_RESTART = "--restart--"; |
| 56 | private static final String EXTRA_STATE = "state"; |
John Reck | 38b3965 | 2012-06-05 09:22:59 -0700 | [diff] [blame] | 57 | public static final String EXTRA_DISABLE_URL_OVERRIDE = "disable_url_override"; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 58 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 59 | private final static String LOGTAG = "browser"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 60 | |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 61 | private final static boolean LOGV_ENABLED = Browser.LOGV_ENABLED; |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 62 | |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 63 | private ActivityController mController = NullController.INSTANCE; |
Tarun Nainani | ef749cb | 2014-05-19 18:16:53 -0700 | [diff] [blame^] | 64 | private TracingControllerAndroid mTracingController; |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 65 | |
| 66 | |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 67 | private Handler mHandler = new Handler(); |
Jeff Davidson | 4361029 | 2010-07-16 16:03:58 -0700 | [diff] [blame] | 68 | |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 69 | private UiController mUiController; |
| 70 | private Handler mHandlerEx = new Handler(); |
| 71 | private Runnable runnable = new Runnable() { |
| 72 | @Override |
| 73 | public void run() { |
| 74 | if (mUiController != null) { |
| 75 | WebView current = mUiController.getCurrentWebView(); |
| 76 | if (current != null) { |
| 77 | current.postInvalidate(); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | }; |
| 82 | |
Tarun Nainani | ef749cb | 2014-05-19 18:16:53 -0700 | [diff] [blame^] | 83 | private TracingControllerAndroid getTracingController() { |
| 84 | if (mTracingController == null) { |
| 85 | mTracingController = new TracingControllerAndroid(this); |
| 86 | } |
| 87 | return mTracingController; |
| 88 | } |
Bijan Amirzada | 9b1e988 | 2014-02-26 17:15:46 -0800 | [diff] [blame] | 89 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 90 | @Override |
| 91 | public void onCreate(Bundle icicle) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 92 | if (LOGV_ENABLED) { |
John Reck | 6c2e2f3 | 2011-08-22 13:41:23 -0700 | [diff] [blame] | 93 | Log.v(LOGTAG, this + " onStart, has state: " |
| 94 | + (icicle == null ? "false" : "true")); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 95 | } |
| 96 | super.onCreate(icicle); |
Derek Sollenberger | ffa561e | 2010-11-16 14:19:01 -0500 | [diff] [blame] | 97 | |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 98 | if (shouldIgnoreIntents()) { |
| 99 | finish(); |
| 100 | return; |
| 101 | } |
| 102 | |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 103 | // If this was a web search request, pass it on to the default web |
| 104 | // search provider and finish this activity. |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 105 | /* |
kaiyiz | a2368f1 | 2013-09-02 10:43:31 +0800 | [diff] [blame] | 106 | SearchEngine searchEngine = BrowserSettings.getInstance().getSearchEngine(); |
| 107 | boolean result = IntentHandler.handleWebSearchIntent(this, null, getIntent()); |
| 108 | if (result && (searchEngine instanceof DefaultSearchEngine)) { |
John Reck | f57c029 | 2011-07-21 18:15:39 -0700 | [diff] [blame] | 109 | finish(); |
| 110 | return; |
| 111 | } |
Bijan Amirzada | 41242f2 | 2014-03-21 12:12:18 -0700 | [diff] [blame] | 112 | */ |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 113 | mController = createController(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 114 | |
George Mount | 3636d0a | 2011-11-21 09:08:21 -0800 | [diff] [blame] | 115 | Intent intent = (icicle == null) ? getIntent() : null; |
| 116 | mController.start(intent); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 117 | } |
| 118 | |
John Reck | a5176f3 | 2011-05-17 12:35:37 -0700 | [diff] [blame] | 119 | public static boolean isTablet(Context context) { |
| 120 | return context.getResources().getBoolean(R.bool.isTablet); |
John Reck | 9d27ff5 | 2011-02-11 17:47:54 -0800 | [diff] [blame] | 121 | } |
| 122 | |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 123 | private Controller createController() { |
| 124 | Controller controller = new Controller(this); |
| 125 | boolean xlarge = isTablet(this); |
| 126 | UI ui = null; |
| 127 | if (xlarge) { |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 128 | XLargeUi tablet = new XLargeUi(this, controller); |
| 129 | ui = tablet; |
| 130 | mUiController = tablet.getUiController(); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 131 | } else { |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 132 | PhoneUi phone = new PhoneUi(this, controller); |
| 133 | ui = phone; |
| 134 | mUiController = phone.getUiController(); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 135 | } |
| 136 | controller.setUi(ui); |
| 137 | return controller; |
| 138 | } |
| 139 | |
John Reck | 4155485 | 2010-12-01 12:53:37 -0800 | [diff] [blame] | 140 | @VisibleForTesting |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 141 | Controller getController() { |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 142 | return (Controller) mController; |
Michael Kolb | a2b2ba8 | 2010-08-04 17:54:03 -0700 | [diff] [blame] | 143 | } |
| 144 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 145 | @Override |
| 146 | protected void onNewIntent(Intent intent) { |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 147 | if (shouldIgnoreIntents()) return; |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 148 | if (ACTION_RESTART.equals(intent.getAction())) { |
| 149 | Bundle outState = new Bundle(); |
John Reck | 1cf4b79 | 2011-07-26 10:22:22 -0700 | [diff] [blame] | 150 | mController.onSaveInstanceState(outState); |
John Reck | 63bb687 | 2010-12-01 19:29:32 -0800 | [diff] [blame] | 151 | finish(); |
| 152 | getApplicationContext().startActivity( |
| 153 | new Intent(getApplicationContext(), BrowserActivity.class) |
| 154 | .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) |
| 155 | .putExtra(EXTRA_STATE, outState)); |
| 156 | return; |
| 157 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 158 | mController.handleNewIntent(intent); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 159 | } |
| 160 | |
John Reck | 7878f22 | 2012-04-18 16:23:14 -0700 | [diff] [blame] | 161 | private KeyguardManager mKeyguardManager; |
| 162 | private PowerManager mPowerManager; |
| 163 | private boolean shouldIgnoreIntents() { |
| 164 | // Only process intents if the screen is on and the device is unlocked |
| 165 | // aka, if we will be user-visible |
| 166 | if (mKeyguardManager == null) { |
| 167 | mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); |
| 168 | } |
| 169 | if (mPowerManager == null) { |
| 170 | mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 171 | } |
| 172 | boolean ignore = !mPowerManager.isScreenOn(); |
| 173 | ignore |= mKeyguardManager.inKeyguardRestrictedInputMode(); |
| 174 | if (LOGV_ENABLED) { |
| 175 | Log.v(LOGTAG, "ignore intents: " + ignore); |
| 176 | } |
| 177 | return ignore; |
| 178 | } |
| 179 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 180 | @Override |
| 181 | protected void onResume() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 182 | super.onResume(); |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 183 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 184 | Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this); |
| 185 | } |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 186 | mController.onResume(); |
Tarun Nainani | ef749cb | 2014-05-19 18:16:53 -0700 | [diff] [blame^] | 187 | |
| 188 | getTracingController().registerReceiver(this); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 191 | @Override |
| 192 | public boolean onMenuOpened(int featureId, Menu menu) { |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 193 | if (Window.FEATURE_OPTIONS_PANEL == featureId) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 194 | mController.onMenuOpened(featureId, menu); |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 195 | } |
Leon Scroggins | a81a764 | 2009-08-31 17:05:41 -0400 | [diff] [blame] | 196 | return true; |
| 197 | } |
| 198 | |
Leon Scroggins | 3bbb6ca | 2009-09-09 12:51:10 -0400 | [diff] [blame] | 199 | @Override |
| 200 | public void onOptionsMenuClosed(Menu menu) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 201 | mController.onOptionsMenuClosed(menu); |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 202 | } |
| 203 | |
Leon Scroggins | b2b19f5 | 2009-10-09 16:10:00 -0400 | [diff] [blame] | 204 | @Override |
| 205 | public void onContextMenuClosed(Menu menu) { |
| 206 | super.onContextMenuClosed(menu); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 207 | mController.onContextMenuClosed(menu); |
Leon Scroggins | b2b19f5 | 2009-10-09 16:10:00 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Leon Scroggins | c6fa110 | 2009-09-21 10:40:01 -0400 | [diff] [blame] | 210 | /** |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 211 | * onSaveInstanceState(Bundle map) |
| 212 | * onSaveInstanceState is called right before onStop(). The map contains |
| 213 | * the saved state. |
| 214 | */ |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 215 | @Override |
| 216 | protected void onSaveInstanceState(Bundle outState) { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 217 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 218 | Log.v(LOGTAG, "BrowserActivity.onSaveInstanceState: this=" + this); |
| 219 | } |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 220 | mController.onSaveInstanceState(outState); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 221 | } |
| 222 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 223 | @Override |
| 224 | protected void onPause() { |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 225 | mController.onPause(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 226 | super.onPause(); |
Tarun Nainani | ef749cb | 2014-05-19 18:16:53 -0700 | [diff] [blame^] | 227 | getTracingController().unregisterReceiver(this); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 230 | @Override |
| 231 | protected void onDestroy() { |
Dave Bort | 31a6d1c | 2009-04-13 15:56:49 -0700 | [diff] [blame] | 232 | if (LOGV_ENABLED) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 233 | Log.v(LOGTAG, "BrowserActivity.onDestroy: this=" + this); |
| 234 | } |
| 235 | super.onDestroy(); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 236 | mController.onDestroy(); |
| 237 | mController = NullController.INSTANCE; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public void onConfigurationChanged(Configuration newConfig) { |
| 242 | super.onConfigurationChanged(newConfig); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 243 | mController.onConfgurationChanged(newConfig); |
kaiyiz | bb2db87 | 2013-08-01 22:24:07 -0400 | [diff] [blame] | 244 | |
| 245 | //For avoiding bug CR520353 temporarily, delay 300ms to refresh WebView. |
| 246 | mHandlerEx.postDelayed(runnable, 300); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 249 | @Override |
| 250 | public void onLowMemory() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 251 | super.onLowMemory(); |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 252 | mController.onLowMemory(); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 253 | } |
| 254 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 255 | @Override |
| 256 | public boolean onCreateOptionsMenu(Menu menu) { |
| 257 | super.onCreateOptionsMenu(menu); |
John Reck | 9c35b9c | 2012-05-30 10:08:50 -0700 | [diff] [blame] | 258 | return mController.onCreateOptionsMenu(menu); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 262 | public boolean onPrepareOptionsMenu(Menu menu) { |
| 263 | super.onPrepareOptionsMenu(menu); |
John Reck | b3417f0 | 2011-01-14 11:01:05 -0800 | [diff] [blame] | 264 | return mController.onPrepareOptionsMenu(menu); |
Cary Clark | 01cfcdd | 2010-06-04 16:36:45 -0400 | [diff] [blame] | 265 | } |
| 266 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 267 | @Override |
| 268 | public boolean onOptionsItemSelected(MenuItem item) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 269 | if (!mController.onOptionsItemSelected(item)) { |
qqzhou | e6ff8b4 | 2013-07-23 17:28:48 +0800 | [diff] [blame] | 270 | if (item.getItemId() == R.id.about_menu_id) { |
| 271 | final AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 272 | builder.setTitle(R.string.about); |
| 273 | builder.setCancelable(true); |
| 274 | String ua = ""; |
| 275 | final WebView current = getController().getCurrentWebView(); |
| 276 | if (current != null) { |
| 277 | final WebSettings s = current.getSettings(); |
| 278 | if (s != null) { |
| 279 | ua = s.getUserAgentString(); |
| 280 | } |
| 281 | } |
| 282 | builder.setMessage("Agent:" + ua); |
| 283 | builder.setPositiveButton(android.R.string.ok, null); |
| 284 | builder.create().show(); |
| 285 | } |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 286 | return super.onOptionsItemSelected(item); |
Michael Kolb | 370a4f3 | 2010-10-06 10:45:32 -0700 | [diff] [blame] | 287 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 288 | return true; |
| 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public void onCreateContextMenu(ContextMenu menu, View v, |
| 293 | ContextMenuInfo menuInfo) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 294 | mController.onCreateContextMenu(menu, v, menuInfo); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 297 | @Override |
| 298 | public boolean onContextItemSelected(MenuItem item) { |
| 299 | return mController.onContextItemSelected(item); |
Grace Kloba | 22ac16e | 2009-10-07 18:00:23 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 302 | @Override |
| 303 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 304 | return mController.onKeyDown(keyCode, event) || |
| 305 | super.onKeyDown(keyCode, event); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 308 | @Override |
John Reck | e6bf4ab | 2011-02-24 15:48:05 -0800 | [diff] [blame] | 309 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 310 | return mController.onKeyLongPress(keyCode, event) || |
| 311 | super.onKeyLongPress(keyCode, event); |
| 312 | } |
| 313 | |
| 314 | @Override |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 315 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 316 | return mController.onKeyUp(keyCode, event) || |
| 317 | super.onKeyUp(keyCode, event); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 320 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 321 | public void onActionModeStarted(ActionMode mode) { |
| 322 | super.onActionModeStarted(mode); |
| 323 | mController.onActionModeStarted(mode); |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 326 | @Override |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 327 | public void onActionModeFinished(ActionMode mode) { |
| 328 | super.onActionModeFinished(mode); |
| 329 | mController.onActionModeFinished(mode); |
Michael Kolb | e421c24 | 2010-10-04 19:29:01 -0700 | [diff] [blame] | 330 | } |
| 331 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 332 | @Override |
| 333 | protected void onActivityResult(int requestCode, int resultCode, |
Michael Kolb | 8233fac | 2010-10-26 16:08:53 -0700 | [diff] [blame] | 334 | Intent intent) { |
| 335 | mController.onActivityResult(requestCode, resultCode, intent); |
Andrei Popescu | 163ab74 | 2009-10-20 17:58:23 +0100 | [diff] [blame] | 336 | } |
| 337 | |
Michael Kolb | fbc579a | 2011-07-07 15:59:33 -0700 | [diff] [blame] | 338 | @Override |
| 339 | public boolean onSearchRequested() { |
| 340 | return mController.onSearchRequested(); |
| 341 | } |
| 342 | |
Michael Kolb | c3af067 | 2011-08-09 10:24:41 -0700 | [diff] [blame] | 343 | @Override |
| 344 | public boolean dispatchKeyEvent(KeyEvent event) { |
| 345 | return mController.dispatchKeyEvent(event) |
| 346 | || super.dispatchKeyEvent(event); |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 351 | return mController.dispatchKeyShortcutEvent(event) |
| 352 | || super.dispatchKeyShortcutEvent(event); |
| 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 357 | return mController.dispatchTouchEvent(ev) |
| 358 | || super.dispatchTouchEvent(ev); |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 363 | return mController.dispatchTrackballEvent(ev) |
| 364 | || super.dispatchTrackballEvent(ev); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 369 | return mController.dispatchGenericMotionEvent(ev) || |
| 370 | super.dispatchGenericMotionEvent(ev); |
| 371 | } |
| 372 | |
qqzhou | 8c5b0a3 | 2013-07-22 15:31:03 +0800 | [diff] [blame] | 373 | // add for carrier homepage feature |
| 374 | @JavascriptInterface |
| 375 | public void loadBookmarks() { |
| 376 | mHandler.post(new Runnable() { |
| 377 | @Override |
| 378 | public void run() { |
| 379 | if (mController instanceof Controller) { |
| 380 | ((Controller)mController).bookmarksOrHistoryPicker(ComboViews.Bookmarks); |
| 381 | } |
| 382 | } |
| 383 | }); |
| 384 | } |
| 385 | |
| 386 | // add for carrier homepage feature |
| 387 | @JavascriptInterface |
| 388 | public void loadHistory() { |
| 389 | mHandler.post(new Runnable() { |
| 390 | @Override |
| 391 | public void run() { |
| 392 | if (mController instanceof Controller) { |
| 393 | ((Controller)mController).bookmarksOrHistoryPicker(ComboViews.History); |
| 394 | } |
| 395 | } |
| 396 | }); |
| 397 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 398 | } |