1 // Copyright 2011 Google Inc. All Rights Reserved.
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
15 package com.hughes.android.dictionary;
\r
17 import android.app.Activity;
\r
18 import android.content.Intent;
\r
19 import android.os.Bundle;
\r
20 import android.util.Log;
\r
21 import android.view.View;
\r
22 import android.view.View.OnClickListener;
\r
23 import android.widget.Button;
\r
25 import com.hughes.util.StringUtil;
\r
27 public final class HtmlDisplayActivity extends Activity {
\r
29 static final String LOG = "QuickDic";
\r
31 static final String HTML_RES = "html_res";
\r
32 static final String HTML = "html";
\r
33 static final String TEXT_TO_HIGHLIGHT = "textToHighlight";
\r
34 static final String SHOW_OK_BUTTON = "showOKButton";
\r
36 public static Intent getHelpLaunchIntent() {
\r
37 final Intent intent = new Intent();
\r
38 intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(),
\r
39 HtmlDisplayActivity.class.getName());
\r
40 intent.putExtra(HTML_RES, R.raw.help);
\r
44 public static Intent getWhatsNewLaunchIntent() {
\r
45 final Intent intent = new Intent();
\r
46 intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(),
\r
47 HtmlDisplayActivity.class.getName());
\r
48 intent.putExtra(HTML_RES, R.raw.whats_new);
\r
52 public static Intent getHtmlIntent(final String html, final String textToHighlight,
\r
53 final boolean showOkButton) {
\r
54 final Intent intent = new Intent();
\r
55 intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(),
\r
56 HtmlDisplayActivity.class.getName());
\r
57 intent.putExtra(HTML, html);
\r
58 intent.putExtra(TEXT_TO_HIGHLIGHT, textToHighlight);
\r
59 intent.putExtra(SHOW_OK_BUTTON, showOkButton);
\r
63 /** Called when the activity is first created. */
\r
65 public void onCreate(final Bundle savedInstanceState) {
\r
66 setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);
\r
68 super.onCreate(savedInstanceState);
\r
69 setContentView(R.layout.html_display_activity);
\r
71 final int htmlRes = getIntent().getIntExtra(HTML_RES, -1);
\r
73 if (htmlRes != -1) {
\r
74 html = StringUtil.readToString(getResources().openRawResource(htmlRes));
\r
76 html = getIntent().getStringExtra(HTML);
\r
78 final MyWebView webView = (MyWebView) findViewById(R.id.webView);
\r
79 webView.loadData(html, "text/html", "utf-8");
\r
80 webView.activity = this;
\r
82 final String textToHighlight = getIntent().getStringExtra(TEXT_TO_HIGHLIGHT);
\r
83 if (textToHighlight != null && !"".equals(textToHighlight)) {
\r
84 Log.d(LOG, "NOT Highlighting text: " + textToHighlight);
\r
85 // This isn't working:
\r
86 // webView.findAll(textToHighlight);
\r
87 // webView.showFindDialog(textToHighlight, false);
\r
90 final Button okButton = (Button) findViewById(R.id.okButton);
\r
91 okButton.setOnClickListener(new OnClickListener() {
\r
93 public void onClick(View v) {
\r
97 if (!getIntent().getBooleanExtra(SHOW_OK_BUTTON, true)) {
\r
98 okButton.setVisibility(Button.GONE);
\r