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.content.Intent;
\r
18 import android.os.Bundle;
\r
19 import android.util.Log;
\r
20 import android.view.View;
\r
21 import android.view.View.OnClickListener;
\r
22 import android.widget.Button;
\r
24 import android.support.v7.app.ActionBar;
\r
25 import android.support.v7.app.ActionBarActivity;
\r
26 import com.hughes.util.StringUtil;
\r
28 public final class HtmlDisplayActivity extends ActionBarActivity {
\r
30 static final String LOG = "QuickDic";
\r
32 static final String HTML_RES = "html_res";
\r
33 static final String HTML = "html";
\r
34 static final String TEXT_TO_HIGHLIGHT = "textToHighlight";
\r
35 static final String SHOW_OK_BUTTON = "showOKButton";
\r
37 public static Intent getHelpLaunchIntent() {
\r
38 final Intent intent = new Intent();
\r
39 intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(),
\r
40 HtmlDisplayActivity.class.getName());
\r
41 intent.putExtra(HTML_RES, R.raw.help);
\r
45 public static Intent getWhatsNewLaunchIntent() {
\r
46 final Intent intent = new Intent();
\r
47 intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(),
\r
48 HtmlDisplayActivity.class.getName());
\r
49 intent.putExtra(HTML_RES, R.raw.whats_new);
\r
53 public static Intent getHtmlIntent(final String html, final String textToHighlight,
\r
54 final boolean showOkButton) {
\r
55 final Intent intent = new Intent();
\r
56 intent.setClassName(HtmlDisplayActivity.class.getPackage().getName(),
\r
57 HtmlDisplayActivity.class.getName());
\r
58 intent.putExtra(HTML, html);
\r
59 intent.putExtra(TEXT_TO_HIGHLIGHT, textToHighlight);
\r
60 intent.putExtra(SHOW_OK_BUTTON, showOkButton);
\r
64 /** Called when the activity is first created. */
\r
66 public void onCreate(final Bundle savedInstanceState) {
\r
67 setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);
\r
69 super.onCreate(savedInstanceState);
\r
70 setContentView(R.layout.html_display_activity);
\r
72 ActionBar actionBar = getSupportActionBar();
\r
73 actionBar.setDisplayHomeAsUpEnabled(true);
\r
75 final int htmlRes = getIntent().getIntExtra(HTML_RES, -1);
\r
77 if (htmlRes != -1) {
\r
78 html = StringUtil.readToString(getResources().openRawResource(htmlRes));
\r
80 html = getIntent().getStringExtra(HTML);
\r
82 final MyWebView webView = (MyWebView) findViewById(R.id.webView);
\r
83 webView.loadData(html, "text/html", "utf-8");
\r
84 webView.activity = this;
\r
86 final String textToHighlight = getIntent().getStringExtra(TEXT_TO_HIGHLIGHT);
\r
87 if (textToHighlight != null && !"".equals(textToHighlight)) {
\r
88 Log.d(LOG, "NOT Highlighting text: " + textToHighlight);
\r
89 // This isn't working:
\r
90 // webView.findAll(textToHighlight);
\r
91 // webView.showFindDialog(textToHighlight, false);
\r
94 final Button okButton = (Button) findViewById(R.id.okButton);
\r
95 okButton.setOnClickListener(new OnClickListener() {
\r
97 public void onClick(View v) {
\r
101 if (!getIntent().getBooleanExtra(SHOW_OK_BUTTON, true)) {
\r
102 okButton.setVisibility(Button.GONE);
\r