The Android Open Source Project | ba6d7b8 | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package com.android.browser; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.content.ComponentName; |
| 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.res.Configuration; |
| 24 | import android.net.Uri; |
| 25 | import android.os.Bundle; |
| 26 | import android.util.Log; |
| 27 | import android.view.View; |
| 28 | import android.widget.Button; |
| 29 | |
| 30 | import android.graphics.Bitmap; |
| 31 | import android.graphics.BitmapFactory; |
| 32 | |
| 33 | import android.webkit.WebView; |
| 34 | import android.webkit.WebViewClient; |
| 35 | import android.webkit.WebSettings; |
| 36 | |
| 37 | import android.view.KeyEvent; |
| 38 | import android.view.ViewGroup.LayoutParams; |
| 39 | |
| 40 | import android.widget.LinearLayout; |
| 41 | |
| 42 | public 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 | } |