blob: 084ace082b651cf20db4f8fc2edd4670aa76df91 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
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
17package com.android.browser;
18
The Android Open Source Project0c908882009-03-03 19:32:16 -080019import android.app.Activity;
John Reck9d27ff52011-02-11 17:47:54 -080020import android.content.Context;
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.content.Intent;
The Android Open Source Project0c908882009-03-03 19:32:16 -080022import android.content.res.Configuration;
The Android Open Source Project0c908882009-03-03 19:32:16 -080023import android.os.Bundle;
The Android Open Source Project0c908882009-03-03 19:32:16 -080024import android.util.Log;
Leon Scroggins III8e4fbf12010-08-17 16:58:15 -040025import android.view.ActionMode;
The Android Open Source Project0c908882009-03-03 19:32:16 -080026import android.view.ContextMenu;
Michael Kolba2b2ba82010-08-04 17:54:03 -070027import android.view.ContextMenu.ContextMenuInfo;
The Android Open Source Project0c908882009-03-03 19:32:16 -080028import android.view.KeyEvent;
The Android Open Source Project0c908882009-03-03 19:32:16 -080029import android.view.Menu;
The Android Open Source Project0c908882009-03-03 19:32:16 -080030import android.view.MenuItem;
Michael Kolbc3af0672011-08-09 10:24:41 -070031import android.view.MotionEvent;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032import android.view.View;
The Android Open Source Project0c908882009-03-03 19:32:16 -080033import android.view.Window;
34import android.view.WindowManager;
Svetoslav Ganov2b345992010-05-06 06:13:54 -070035import android.view.accessibility.AccessibilityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080036
John Reckd3e4d5b2011-07-13 15:48:43 -070037import com.google.common.annotations.VisibleForTesting;
38
Michael Kolb8233fac2010-10-26 16:08:53 -070039public class BrowserActivity extends Activity {
The Android Open Source Project0c908882009-03-03 19:32:16 -080040
John Reck439c9a52010-12-14 10:04:39 -080041 public static final String ACTION_SHOW_BOOKMARKS = "show_bookmarks";
42 public static final String ACTION_SHOW_BROWSER = "show_browser";
John Reck63bb6872010-12-01 19:29:32 -080043 public static final String ACTION_RESTART = "--restart--";
44 private static final String EXTRA_STATE = "state";
45
Michael Kolb8233fac2010-10-26 16:08:53 -070046 private final static String LOGTAG = "browser";
The Android Open Source Project0c908882009-03-03 19:32:16 -080047
Michael Kolb8233fac2010-10-26 16:08:53 -070048 private final static boolean LOGV_ENABLED =
49 com.android.browser.Browser.LOGV_ENABLED;
Dave Bort31a6d1c2009-04-13 15:56:49 -070050
Michael Kolb8233fac2010-10-26 16:08:53 -070051 private Controller mController;
52 private UI mUi;
Jeff Davidson43610292010-07-16 16:03:58 -070053
Grace Kloba22ac16e2009-10-07 18:00:23 -070054 @Override
55 public void onCreate(Bundle icicle) {
Dave Bort31a6d1c2009-04-13 15:56:49 -070056 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -080057 Log.v(LOGTAG, this + " onStart");
58 }
59 super.onCreate(icicle);
Derek Sollenbergerffa561e2010-11-16 14:19:01 -050060
John Reckf57c0292011-07-21 18:15:39 -070061 // If this was a web search request, pass it on to the default web
62 // search provider and finish this activity.
63 if (IntentHandler.handleWebSearchIntent(this, null, getIntent())) {
64 finish();
65 return;
66 }
67
Patrick Scott539e2ec2011-01-13 11:27:38 -050068 BrowserSettings settings = BrowserSettings.getInstance();
69
Derek Sollenbergerffa561e2010-11-16 14:19:01 -050070 // render the browser in OpenGL
Patrick Scott539e2ec2011-01-13 11:27:38 -050071 if (settings.isHardwareAccelerated()) {
Derek Sollenbergerffa561e2010-11-16 14:19:01 -050072 // Set the flag in the activity's window
73 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
74 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
75 } else {
76 // Clear the flag in the activity's window
77 this.getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
78 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080079
John Reckd156adf2011-07-17 12:35:21 -070080 AccessibilityManager accessibilityManager = (AccessibilityManager)
81 getSystemService(ACCESSIBILITY_SERVICE);
82 if (accessibilityManager != null && accessibilityManager.isEnabled()) {
Svetoslav Ganov2b345992010-05-06 06:13:54 -070083 setDefaultKeyMode(DEFAULT_KEYS_DISABLE);
Svetoslav Ganov2b345992010-05-06 06:13:54 -070084 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080085
John Reckbc490d22011-07-22 15:04:59 -070086 mController = new Controller(this, icicle == null);
John Recka5176f32011-05-17 12:35:37 -070087 boolean xlarge = isTablet(this);
Michael Kolb66706532010-12-12 19:50:22 -080088 if (xlarge) {
89 mUi = new XLargeUi(this, mController);
90 } else {
91 mUi = new PhoneUi(this, mController);
92 }
Michael Kolb8233fac2010-10-26 16:08:53 -070093 mController.setUi(mUi);
The Android Open Source Project0c908882009-03-03 19:32:16 -080094
John Reck63bb6872010-12-01 19:29:32 -080095 Bundle state = getIntent().getBundleExtra(EXTRA_STATE);
96 if (state != null && icicle == null) {
97 icicle = state;
98 }
Patrick Scott539e2ec2011-01-13 11:27:38 -050099
Patrick Scott7d50a932011-02-04 09:27:26 -0500100 mController.start(icicle, getIntent());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800101 }
102
John Recka5176f32011-05-17 12:35:37 -0700103 public static boolean isTablet(Context context) {
104 return context.getResources().getBoolean(R.bool.isTablet);
John Reck9d27ff52011-02-11 17:47:54 -0800105 }
106
John Reck41554852010-12-01 12:53:37 -0800107 @VisibleForTesting
Michael Kolb8233fac2010-10-26 16:08:53 -0700108 Controller getController() {
109 return mController;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700110 }
111
The Android Open Source Project0c908882009-03-03 19:32:16 -0800112 @Override
113 protected void onNewIntent(Intent intent) {
John Reck63bb6872010-12-01 19:29:32 -0800114 if (ACTION_RESTART.equals(intent.getAction())) {
115 Bundle outState = new Bundle();
John Reck1cf4b792011-07-26 10:22:22 -0700116 mController.onSaveInstanceState(outState);
John Reck63bb6872010-12-01 19:29:32 -0800117 finish();
118 getApplicationContext().startActivity(
119 new Intent(getApplicationContext(), BrowserActivity.class)
120 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
121 .putExtra(EXTRA_STATE, outState));
122 return;
123 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700124 mController.handleNewIntent(intent);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800125 }
126
Grace Kloba22ac16e2009-10-07 18:00:23 -0700127 @Override
128 protected void onResume() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800129 super.onResume();
Dave Bort31a6d1c2009-04-13 15:56:49 -0700130 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800131 Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this);
132 }
Michael Kolb06f03e42010-12-06 10:18:26 -0800133 if (mController != null) {
134 mController.onResume();
135 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800136 }
137
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400138 @Override
139 public boolean onMenuOpened(int featureId, Menu menu) {
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400140 if (Window.FEATURE_OPTIONS_PANEL == featureId) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700141 mController.onMenuOpened(featureId, menu);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400142 }
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400143 return true;
144 }
145
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400146 @Override
147 public void onOptionsMenuClosed(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700148 mController.onOptionsMenuClosed(menu);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400149 }
150
Leon Scrogginsb2b19f52009-10-09 16:10:00 -0400151 @Override
152 public void onContextMenuClosed(Menu menu) {
153 super.onContextMenuClosed(menu);
Michael Kolb8233fac2010-10-26 16:08:53 -0700154 mController.onContextMenuClosed(menu);
Leon Scrogginsb2b19f52009-10-09 16:10:00 -0400155 }
156
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400157 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -0800158 * onSaveInstanceState(Bundle map)
159 * onSaveInstanceState is called right before onStop(). The map contains
160 * the saved state.
161 */
Grace Kloba22ac16e2009-10-07 18:00:23 -0700162 @Override
163 protected void onSaveInstanceState(Bundle outState) {
Dave Bort31a6d1c2009-04-13 15:56:49 -0700164 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800165 Log.v(LOGTAG, "BrowserActivity.onSaveInstanceState: this=" + this);
166 }
John Reck1cf4b792011-07-26 10:22:22 -0700167 mController.onSaveInstanceState(outState);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800168 }
169
Grace Kloba22ac16e2009-10-07 18:00:23 -0700170 @Override
171 protected void onPause() {
Michael Kolb06f03e42010-12-06 10:18:26 -0800172 if (mController != null) {
173 mController.onPause();
174 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800175 super.onPause();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800176 }
177
Grace Kloba22ac16e2009-10-07 18:00:23 -0700178 @Override
179 protected void onDestroy() {
Dave Bort31a6d1c2009-04-13 15:56:49 -0700180 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800181 Log.v(LOGTAG, "BrowserActivity.onDestroy: this=" + this);
182 }
183 super.onDestroy();
Michael Kolb06f03e42010-12-06 10:18:26 -0800184 if (mController != null) {
185 mController.onDestroy();
186 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700187 mUi = null;
188 mController = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800189 }
190
191 @Override
192 public void onConfigurationChanged(Configuration newConfig) {
193 super.onConfigurationChanged(newConfig);
Michael Kolb8233fac2010-10-26 16:08:53 -0700194 mController.onConfgurationChanged(newConfig);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800195 }
196
Grace Kloba22ac16e2009-10-07 18:00:23 -0700197 @Override
198 public void onLowMemory() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800199 super.onLowMemory();
Michael Kolb8233fac2010-10-26 16:08:53 -0700200 mController.onLowMemory();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700201 }
202
The Android Open Source Project0c908882009-03-03 19:32:16 -0800203 @Override
204 public boolean onCreateOptionsMenu(Menu menu) {
205 super.onCreateOptionsMenu(menu);
Michael Kolb8233fac2010-10-26 16:08:53 -0700206 return mController.onCreateOptionsMenu(menu);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800207 }
208
209 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700210 public boolean onPrepareOptionsMenu(Menu menu) {
211 super.onPrepareOptionsMenu(menu);
John Reckb3417f02011-01-14 11:01:05 -0800212 return mController.onPrepareOptionsMenu(menu);
Cary Clark01cfcdd2010-06-04 16:36:45 -0400213 }
214
The Android Open Source Project0c908882009-03-03 19:32:16 -0800215 @Override
216 public boolean onOptionsItemSelected(MenuItem item) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700217 if (!mController.onOptionsItemSelected(item)) {
218 return super.onOptionsItemSelected(item);
Michael Kolb370a4f32010-10-06 10:45:32 -0700219 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800220 return true;
221 }
222
223 @Override
224 public void onCreateContextMenu(ContextMenu menu, View v,
225 ContextMenuInfo menuInfo) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700226 mController.onCreateContextMenu(menu, v, menuInfo);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800227 }
228
Michael Kolb8233fac2010-10-26 16:08:53 -0700229 @Override
230 public boolean onContextItemSelected(MenuItem item) {
231 return mController.onContextItemSelected(item);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700232 }
233
Grace Kloba5942df02009-09-18 11:48:29 -0700234 @Override
235 public boolean onKeyDown(int keyCode, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700236 return mController.onKeyDown(keyCode, event) ||
237 super.onKeyDown(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800238 }
239
Grace Kloba5942df02009-09-18 11:48:29 -0700240 @Override
John Recke6bf4ab2011-02-24 15:48:05 -0800241 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
242 return mController.onKeyLongPress(keyCode, event) ||
243 super.onKeyLongPress(keyCode, event);
244 }
245
246 @Override
Grace Kloba5942df02009-09-18 11:48:29 -0700247 public boolean onKeyUp(int keyCode, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700248 return mController.onKeyUp(keyCode, event) ||
249 super.onKeyUp(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800250 }
251
Michael Kolbe421c242010-10-04 19:29:01 -0700252 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700253 public void onActionModeStarted(ActionMode mode) {
254 super.onActionModeStarted(mode);
255 mController.onActionModeStarted(mode);
Michael Kolbe421c242010-10-04 19:29:01 -0700256 }
257
Michael Kolbe421c242010-10-04 19:29:01 -0700258 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700259 public void onActionModeFinished(ActionMode mode) {
260 super.onActionModeFinished(mode);
261 mController.onActionModeFinished(mode);
Michael Kolbe421c242010-10-04 19:29:01 -0700262 }
263
The Android Open Source Project0c908882009-03-03 19:32:16 -0800264 @Override
265 protected void onActivityResult(int requestCode, int resultCode,
Michael Kolb8233fac2010-10-26 16:08:53 -0700266 Intent intent) {
267 mController.onActivityResult(requestCode, resultCode, intent);
Andrei Popescu163ab742009-10-20 17:58:23 +0100268 }
269
Michael Kolbfbc579a2011-07-07 15:59:33 -0700270 @Override
271 public boolean onSearchRequested() {
272 return mController.onSearchRequested();
273 }
274
Michael Kolbc3af0672011-08-09 10:24:41 -0700275 @Override
276 public boolean dispatchKeyEvent(KeyEvent event) {
277 return mController.dispatchKeyEvent(event)
278 || super.dispatchKeyEvent(event);
279 }
280
281 @Override
282 public boolean dispatchKeyShortcutEvent(KeyEvent event) {
283 return mController.dispatchKeyShortcutEvent(event)
284 || super.dispatchKeyShortcutEvent(event);
285 }
286
287 @Override
288 public boolean dispatchTouchEvent(MotionEvent ev) {
289 return mController.dispatchTouchEvent(ev)
290 || super.dispatchTouchEvent(ev);
291 }
292
293 @Override
294 public boolean dispatchTrackballEvent(MotionEvent ev) {
295 return mController.dispatchTrackballEvent(ev)
296 || super.dispatchTrackballEvent(ev);
297 }
298
299 @Override
300 public boolean dispatchGenericMotionEvent(MotionEvent ev) {
301 return mController.dispatchGenericMotionEvent(ev) ||
302 super.dispatchGenericMotionEvent(ev);
303 }
304
The Android Open Source Project0c908882009-03-03 19:32:16 -0800305}