]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/HtmlDisplayActivity.java
Auto-format everything.
[Dictionary.git] / src / com / hughes / android / dictionary / HtmlDisplayActivity.java
1 // Copyright 2011 Google Inc. All Rights Reserved.\r
2 //\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
6 //\r
7 //     http://www.apache.org/licenses/LICENSE-2.0\r
8 //\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
14 \r
15 package com.hughes.android.dictionary;\r
16 \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
24 \r
25 import com.hughes.util.StringUtil;\r
26 \r
27 public final class HtmlDisplayActivity extends Activity {\r
28 \r
29     static final String LOG = "QuickDic";\r
30 \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
35 \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
41         return intent;\r
42     }\r
43 \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
49         return intent;\r
50     }\r
51 \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
60         return intent;\r
61     }\r
62 \r
63     /** Called when the activity is first created. */\r
64     @Override\r
65     public void onCreate(final Bundle savedInstanceState) {\r
66         setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);\r
67 \r
68         super.onCreate(savedInstanceState);\r
69         setContentView(R.layout.html_display_activity);\r
70 \r
71         final int htmlRes = getIntent().getIntExtra(HTML_RES, -1);\r
72         final String html;\r
73         if (htmlRes != -1) {\r
74             html = StringUtil.readToString(getResources().openRawResource(htmlRes));\r
75         } else {\r
76             html = getIntent().getStringExtra(HTML);\r
77         }\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
81 \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
88         }\r
89 \r
90         final Button okButton = (Button) findViewById(R.id.okButton);\r
91         okButton.setOnClickListener(new OnClickListener() {\r
92             @Override\r
93             public void onClick(View v) {\r
94                 finish();\r
95             }\r
96         });\r
97         if (!getIntent().getBooleanExtra(SHOW_OK_BUTTON, true)) {\r
98             okButton.setVisibility(Button.GONE);\r
99         }\r
100     }\r
101 \r
102 }\r