blob: fd9e76246acc8d466d6cc767f8040cc608587754 [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
51 @Override
52 public void onCreate(Bundle icicle) {
53 super.onCreate(icicle);
54 webview = new WebView(this);
55 webview.getSettings().setJavaScriptEnabled(true);
56 webview.addJavascriptInterface(this, "bridge");
57
58 setContentView(webview);
59 setTitle("Gears");
60 }
61
62 @Override
63 public void onStart() {
64 super.onStart();
65 loadHTML();
66 }
67
68 @Override
69 public void onConfigurationChanged(Configuration newConfig) {
70 super.onConfigurationChanged(newConfig);
71 Intent i = getIntent();
72 boolean inSettings = i.getBooleanExtra("inSettings", false);
73 // If we are called from the settings, we
74 // dismiss ourselve upon upon rotation
75 if (inSettings) {
76 GearsDialogService.signalFinishedDialog();
77 finish();
78 }
79 }
80
81 /**
82 * Load the HTML content in the WebView
83 */
84 private void loadHTML() {
85 Intent i = getIntent();
86 htmlContent = i.getStringExtra("htmlContent");
87 dialogArguments = i.getStringExtra("dialogArguments");
88 webview.loadDataWithBaseURL("", htmlContent, "text/html", "", "");
89 }
90
91 public boolean dispatchKeyEvent(KeyEvent event) {
92 if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.isDown()) {
93 GearsDialogService.signalFinishedDialog();
94 }
95 return super.dispatchKeyEvent(event);
96 }
97
98 /**
99 * Returns a json-formatted string containing the information
100 * about the site.
101 * This method is accessible through the javascript bridge.
102 */
103 public String getDialogArguments() {
104 return dialogArguments;
105 }
106
107 /**
108 * Set the results string and closes the dialog.
109 * This method is accessible through the javascript bridge.
110 */
111 public void closeDialog(String results) {
112 GearsDialogService.closeDialog(results);
113 GearsDialogService.signalFinishedDialog();
114 finish();
115 }
116
117 /**
118 * Debug method outputting a message.
119 * This method is accessible through the javascript bridge.
120 */
121 public void log(String msg) {
122 Log.v(TAG, msg);
123 }
124}