import android.os.Bundle;\r
import android.support.v7.app.ActionBar;\r
import android.support.v7.app.ActionBarActivity;\r
+import android.util.Base64;\r
import android.util.Log;\r
import android.view.View;\r
import android.view.View.OnClickListener;\r
\r
import com.hughes.util.StringUtil;\r
\r
+import java.io.UnsupportedEncodingException;\r
+\r
public final class HtmlDisplayActivity extends ActionBarActivity {\r
\r
static final String LOG = "QuickDic";\r
actionBar.setDisplayHomeAsUpEnabled(true);\r
\r
final int htmlRes = getIntent().getIntExtra(HTML_RES, -1);\r
- final String html;\r
+ String html;\r
if (htmlRes != -1) {\r
html = StringUtil.readToString(getResources().openRawResource(htmlRes));\r
} else {\r
html = getIntent().getStringExtra(HTML);\r
}\r
final MyWebView webView = (MyWebView) findViewById(R.id.webView);\r
- webView.loadData(html, "text/html", "utf-8");\r
+ try {\r
+ // No way to get pure UTF-8 data into WebView\r
+ html = Base64.encodeToString(html.getBytes("UTF-8"), Base64.DEFAULT);\r
+ } catch (UnsupportedEncodingException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ // Use loadURL to allow specifying a charset\r
+ webView.loadUrl("data:text/html;charset=utf-8;base64," + html);\r
webView.activity = this;\r
\r
final String textToHighlight = getIntent().getStringExtra(TEXT_TO_HIGHLIGHT);\r