blob: 62a8aaa99710b601072e57498cc72015cf4b390b [file] [log] [blame]
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -07001/*
2 * Copyright (C) 2008 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
19import android.app.Activity;
20import android.content.ComponentName;
21import android.content.Context;
22import android.content.Intent;
23import android.content.res.Configuration;
24import android.net.Uri;
25import android.os.Bundle;
26import android.util.Log;
27import android.view.View;
28import android.widget.Button;
29
30import android.graphics.Bitmap;
31import android.graphics.BitmapFactory;
32
33import android.webkit.WebView;
34import android.webkit.WebViewClient;
35import android.webkit.WebSettings;
36
37import android.view.KeyEvent;
38import android.view.ViewGroup.LayoutParams;
39
40import android.widget.LinearLayout;
41
42public class GearsDialog extends Activity {
43
44 private static final String TAG = "GearsDialog";
45
46 private WebView webview;
47
48 private String htmlContent;
49 private String dialogArguments;
50
The Android Open Source Projected217d92008-12-17 18:05:52 -080051 private boolean dismissed = false;
52
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -070053 @Override
54 public void onCreate(Bundle icicle) {
55 super.onCreate(icicle);
56 webview = new WebView(this);
57 webview.getSettings().setJavaScriptEnabled(true);
58 webview.addJavascriptInterface(this, "bridge");
59
60 setContentView(webview);
61 setTitle("Gears");
62 }
63
64 @Override
65 public void onStart() {
66 super.onStart();
67 loadHTML();
68 }
69
70 @Override
The Android Open Source Projected217d92008-12-17 18:05:52 -080071 public void onDestroy() {
72 super.onDestroy();
73 // In case we reach this point without
74 // notifying GearsDialogService, we do it now.
75 if (!dismissed) {
76 notifyEndOfDialog();
77 }
78 }
79
80 @Override
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -070081 public void onConfigurationChanged(Configuration newConfig) {
82 super.onConfigurationChanged(newConfig);
83 Intent i = getIntent();
84 boolean inSettings = i.getBooleanExtra("inSettings", false);
85 // If we are called from the settings, we
The Android Open Source Projected217d92008-12-17 18:05:52 -080086 // dismiss ourselve upon rotation
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -070087 if (inSettings) {
The Android Open Source Projected217d92008-12-17 18:05:52 -080088 notifyEndOfDialog();
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -070089 finish();
90 }
91 }
92
93 /**
94 * Load the HTML content in the WebView
95 */
96 private void loadHTML() {
97 Intent i = getIntent();
98 htmlContent = i.getStringExtra("htmlContent");
99 dialogArguments = i.getStringExtra("dialogArguments");
100 webview.loadDataWithBaseURL("", htmlContent, "text/html", "", "");
101 }
102
The Android Open Source Projected217d92008-12-17 18:05:52 -0800103 /**
104 * Signal to GearsDialogService that we are done.
105 */
106 private void notifyEndOfDialog() {
107 GearsDialogService.signalFinishedDialog();
108 dismissed = true;
109 }
110
111 /**
112 * Intercepts the back key to immediately notify
113 * GearsDialogService that we are done.
114 */
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -0700115 public boolean dispatchKeyEvent(KeyEvent event) {
116 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.isDown()) {
The Android Open Source Projected217d92008-12-17 18:05:52 -0800117 notifyEndOfDialog();
118 }
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -0700119 return super.dispatchKeyEvent(event);
120 }
121
122 /**
123 * Returns a json-formatted string containing the information
124 * about the site.
125 * This method is accessible through the javascript bridge.
126 */
127 public String getDialogArguments() {
128 return dialogArguments;
129 }
130
131 /**
132 * Set the results string and closes the dialog.
133 * This method is accessible through the javascript bridge.
134 */
135 public void closeDialog(String results) {
136 GearsDialogService.closeDialog(results);
The Android Open Source Projected217d92008-12-17 18:05:52 -0800137 notifyEndOfDialog();
The Android Open Source Projectba6d7b82008-10-21 07:00:00 -0700138 finish();
139 }
140
141 /**
142 * Debug method outputting a message.
143 * This method is accessible through the javascript bridge.
144 */
145 public void log(String msg) {
146 Log.v(TAG, msg);
147 }
148}