blob: 6ec6071a98eb0c9fc4bf7377d01ce2981c6068fc [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;
31import android.view.View;
The Android Open Source Project0c908882009-03-03 19:32:16 -080032import android.view.Window;
33import android.view.WindowManager;
Svetoslav Ganov2b345992010-05-06 06:13:54 -070034import android.view.accessibility.AccessibilityManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080035
John Reckd3e4d5b2011-07-13 15:48:43 -070036import com.google.common.annotations.VisibleForTesting;
37
Michael Kolb8233fac2010-10-26 16:08:53 -070038public class BrowserActivity extends Activity {
The Android Open Source Project0c908882009-03-03 19:32:16 -080039
John Reck439c9a52010-12-14 10:04:39 -080040 public static final String ACTION_SHOW_BOOKMARKS = "show_bookmarks";
41 public static final String ACTION_SHOW_BROWSER = "show_browser";
John Reck63bb6872010-12-01 19:29:32 -080042 public static final String ACTION_RESTART = "--restart--";
43 private static final String EXTRA_STATE = "state";
44
Michael Kolb8233fac2010-10-26 16:08:53 -070045 private final static String LOGTAG = "browser";
The Android Open Source Project0c908882009-03-03 19:32:16 -080046
Michael Kolb8233fac2010-10-26 16:08:53 -070047 private final static boolean LOGV_ENABLED =
48 com.android.browser.Browser.LOGV_ENABLED;
Dave Bort31a6d1c2009-04-13 15:56:49 -070049
Michael Kolb8233fac2010-10-26 16:08:53 -070050 private Controller mController;
51 private UI mUi;
Jeff Davidson43610292010-07-16 16:03:58 -070052
Grace Kloba22ac16e2009-10-07 18:00:23 -070053 @Override
54 public void onCreate(Bundle icicle) {
Dave Bort31a6d1c2009-04-13 15:56:49 -070055 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -080056 Log.v(LOGTAG, this + " onStart");
57 }
58 super.onCreate(icicle);
Derek Sollenbergerffa561e2010-11-16 14:19:01 -050059
John Reckf57c0292011-07-21 18:15:39 -070060 // If this was a web search request, pass it on to the default web
61 // search provider and finish this activity.
62 if (IntentHandler.handleWebSearchIntent(this, null, getIntent())) {
63 finish();
64 return;
65 }
66
Patrick Scott539e2ec2011-01-13 11:27:38 -050067 BrowserSettings settings = BrowserSettings.getInstance();
68
Derek Sollenbergerffa561e2010-11-16 14:19:01 -050069 // render the browser in OpenGL
Patrick Scott539e2ec2011-01-13 11:27:38 -050070 if (settings.isHardwareAccelerated()) {
Derek Sollenbergerffa561e2010-11-16 14:19:01 -050071 // Set the flag in the activity's window
72 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
73 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
74 } else {
75 // Clear the flag in the activity's window
76 this.getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
77 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080078
John Reckd156adf2011-07-17 12:35:21 -070079 AccessibilityManager accessibilityManager = (AccessibilityManager)
80 getSystemService(ACCESSIBILITY_SERVICE);
81 if (accessibilityManager != null && accessibilityManager.isEnabled()) {
Svetoslav Ganov2b345992010-05-06 06:13:54 -070082 setDefaultKeyMode(DEFAULT_KEYS_DISABLE);
Svetoslav Ganov2b345992010-05-06 06:13:54 -070083 }
The Android Open Source Project0c908882009-03-03 19:32:16 -080084
John Reckbc490d22011-07-22 15:04:59 -070085 mController = new Controller(this, icicle == null);
John Recka5176f32011-05-17 12:35:37 -070086 boolean xlarge = isTablet(this);
Michael Kolb66706532010-12-12 19:50:22 -080087 if (xlarge) {
88 mUi = new XLargeUi(this, mController);
89 } else {
90 mUi = new PhoneUi(this, mController);
91 }
Michael Kolb8233fac2010-10-26 16:08:53 -070092 mController.setUi(mUi);
The Android Open Source Project0c908882009-03-03 19:32:16 -080093
John Reck63bb6872010-12-01 19:29:32 -080094 Bundle state = getIntent().getBundleExtra(EXTRA_STATE);
95 if (state != null && icicle == null) {
96 icicle = state;
97 }
Patrick Scott539e2ec2011-01-13 11:27:38 -050098
Patrick Scott7d50a932011-02-04 09:27:26 -050099 mController.start(icicle, getIntent());
The Android Open Source Project0c908882009-03-03 19:32:16 -0800100 }
101
John Recka5176f32011-05-17 12:35:37 -0700102 public static boolean isTablet(Context context) {
103 return context.getResources().getBoolean(R.bool.isTablet);
John Reck9d27ff52011-02-11 17:47:54 -0800104 }
105
John Reck41554852010-12-01 12:53:37 -0800106 @VisibleForTesting
Michael Kolb8233fac2010-10-26 16:08:53 -0700107 Controller getController() {
108 return mController;
Michael Kolba2b2ba82010-08-04 17:54:03 -0700109 }
110
The Android Open Source Project0c908882009-03-03 19:32:16 -0800111 @Override
112 protected void onNewIntent(Intent intent) {
John Reck63bb6872010-12-01 19:29:32 -0800113 if (ACTION_RESTART.equals(intent.getAction())) {
114 Bundle outState = new Bundle();
John Reck1cf4b792011-07-26 10:22:22 -0700115 mController.onSaveInstanceState(outState);
John Reck63bb6872010-12-01 19:29:32 -0800116 finish();
117 getApplicationContext().startActivity(
118 new Intent(getApplicationContext(), BrowserActivity.class)
119 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
120 .putExtra(EXTRA_STATE, outState));
121 return;
122 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700123 mController.handleNewIntent(intent);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800124 }
125
Grace Kloba22ac16e2009-10-07 18:00:23 -0700126 @Override
127 protected void onResume() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800128 super.onResume();
Dave Bort31a6d1c2009-04-13 15:56:49 -0700129 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800130 Log.v(LOGTAG, "BrowserActivity.onResume: this=" + this);
131 }
Michael Kolb06f03e42010-12-06 10:18:26 -0800132 if (mController != null) {
133 mController.onResume();
134 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800135 }
136
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400137 @Override
138 public boolean onMenuOpened(int featureId, Menu menu) {
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400139 if (Window.FEATURE_OPTIONS_PANEL == featureId) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700140 mController.onMenuOpened(featureId, menu);
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400141 }
Leon Scrogginsa81a7642009-08-31 17:05:41 -0400142 return true;
143 }
144
Leon Scroggins3bbb6ca2009-09-09 12:51:10 -0400145 @Override
146 public void onOptionsMenuClosed(Menu menu) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700147 mController.onOptionsMenuClosed(menu);
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400148 }
149
Leon Scrogginsb2b19f52009-10-09 16:10:00 -0400150 @Override
151 public void onContextMenuClosed(Menu menu) {
152 super.onContextMenuClosed(menu);
Michael Kolb8233fac2010-10-26 16:08:53 -0700153 mController.onContextMenuClosed(menu);
Leon Scrogginsb2b19f52009-10-09 16:10:00 -0400154 }
155
Leon Scrogginsc6fa1102009-09-21 10:40:01 -0400156 /**
The Android Open Source Project0c908882009-03-03 19:32:16 -0800157 * onSaveInstanceState(Bundle map)
158 * onSaveInstanceState is called right before onStop(). The map contains
159 * the saved state.
160 */
Grace Kloba22ac16e2009-10-07 18:00:23 -0700161 @Override
162 protected void onSaveInstanceState(Bundle outState) {
Dave Bort31a6d1c2009-04-13 15:56:49 -0700163 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800164 Log.v(LOGTAG, "BrowserActivity.onSaveInstanceState: this=" + this);
165 }
John Reck1cf4b792011-07-26 10:22:22 -0700166 mController.onSaveInstanceState(outState);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800167 }
168
Grace Kloba22ac16e2009-10-07 18:00:23 -0700169 @Override
170 protected void onPause() {
Michael Kolb06f03e42010-12-06 10:18:26 -0800171 if (mController != null) {
172 mController.onPause();
173 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800174 super.onPause();
The Android Open Source Project0c908882009-03-03 19:32:16 -0800175 }
176
Grace Kloba22ac16e2009-10-07 18:00:23 -0700177 @Override
178 protected void onDestroy() {
Dave Bort31a6d1c2009-04-13 15:56:49 -0700179 if (LOGV_ENABLED) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800180 Log.v(LOGTAG, "BrowserActivity.onDestroy: this=" + this);
181 }
182 super.onDestroy();
Michael Kolb06f03e42010-12-06 10:18:26 -0800183 if (mController != null) {
184 mController.onDestroy();
185 }
Michael Kolb8233fac2010-10-26 16:08:53 -0700186 mUi = null;
187 mController = null;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800188 }
189
190 @Override
191 public void onConfigurationChanged(Configuration newConfig) {
192 super.onConfigurationChanged(newConfig);
Michael Kolb8233fac2010-10-26 16:08:53 -0700193 mController.onConfgurationChanged(newConfig);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800194 }
195
Grace Kloba22ac16e2009-10-07 18:00:23 -0700196 @Override
197 public void onLowMemory() {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800198 super.onLowMemory();
Michael Kolb8233fac2010-10-26 16:08:53 -0700199 mController.onLowMemory();
Grace Kloba22ac16e2009-10-07 18:00:23 -0700200 }
201
The Android Open Source Project0c908882009-03-03 19:32:16 -0800202 @Override
203 public boolean onCreateOptionsMenu(Menu menu) {
204 super.onCreateOptionsMenu(menu);
Michael Kolb8233fac2010-10-26 16:08:53 -0700205 return mController.onCreateOptionsMenu(menu);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800206 }
207
208 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700209 public boolean onPrepareOptionsMenu(Menu menu) {
210 super.onPrepareOptionsMenu(menu);
John Reckb3417f02011-01-14 11:01:05 -0800211 return mController.onPrepareOptionsMenu(menu);
Cary Clark01cfcdd2010-06-04 16:36:45 -0400212 }
213
The Android Open Source Project0c908882009-03-03 19:32:16 -0800214 @Override
215 public boolean onOptionsItemSelected(MenuItem item) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700216 if (!mController.onOptionsItemSelected(item)) {
217 return super.onOptionsItemSelected(item);
Michael Kolb370a4f32010-10-06 10:45:32 -0700218 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800219 return true;
220 }
221
222 @Override
223 public void onCreateContextMenu(ContextMenu menu, View v,
224 ContextMenuInfo menuInfo) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700225 mController.onCreateContextMenu(menu, v, menuInfo);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800226 }
227
Michael Kolb8233fac2010-10-26 16:08:53 -0700228 @Override
229 public boolean onContextItemSelected(MenuItem item) {
230 return mController.onContextItemSelected(item);
Grace Kloba22ac16e2009-10-07 18:00:23 -0700231 }
232
Grace Kloba5942df02009-09-18 11:48:29 -0700233 @Override
234 public boolean onKeyDown(int keyCode, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700235 return mController.onKeyDown(keyCode, event) ||
236 super.onKeyDown(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800237 }
238
Grace Kloba5942df02009-09-18 11:48:29 -0700239 @Override
John Recke6bf4ab2011-02-24 15:48:05 -0800240 public boolean onKeyLongPress(int keyCode, KeyEvent event) {
241 return mController.onKeyLongPress(keyCode, event) ||
242 super.onKeyLongPress(keyCode, event);
243 }
244
245 @Override
Grace Kloba5942df02009-09-18 11:48:29 -0700246 public boolean onKeyUp(int keyCode, KeyEvent event) {
Michael Kolb8233fac2010-10-26 16:08:53 -0700247 return mController.onKeyUp(keyCode, event) ||
248 super.onKeyUp(keyCode, event);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800249 }
250
Michael Kolbe421c242010-10-04 19:29:01 -0700251 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700252 public void onActionModeStarted(ActionMode mode) {
253 super.onActionModeStarted(mode);
254 mController.onActionModeStarted(mode);
Michael Kolbe421c242010-10-04 19:29:01 -0700255 }
256
Michael Kolbe421c242010-10-04 19:29:01 -0700257 @Override
Michael Kolb8233fac2010-10-26 16:08:53 -0700258 public void onActionModeFinished(ActionMode mode) {
259 super.onActionModeFinished(mode);
260 mController.onActionModeFinished(mode);
Michael Kolbe421c242010-10-04 19:29:01 -0700261 }
262
The Android Open Source Project0c908882009-03-03 19:32:16 -0800263 @Override
264 protected void onActivityResult(int requestCode, int resultCode,
Michael Kolb8233fac2010-10-26 16:08:53 -0700265 Intent intent) {
266 mController.onActivityResult(requestCode, resultCode, intent);
Andrei Popescu163ab742009-10-20 17:58:23 +0100267 }
268
Michael Kolbfbc579a2011-07-07 15:59:33 -0700269 @Override
270 public boolean onSearchRequested() {
271 return mController.onSearchRequested();
272 }
273
The Android Open Source Project0c908882009-03-03 19:32:16 -0800274}