2 * Copyright 2008 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.client.android;
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.content.DialogInterface;
22 import android.content.Intent;
23 import android.net.Uri;
24 import android.os.Build;
25 import android.os.Bundle;
26 import android.util.Log;
27 import android.view.View;
28 import android.view.KeyEvent;
29 import android.webkit.WebView;
30 import android.webkit.WebViewClient;
31 import android.widget.Button;
34 * An HTML-based help screen with Back and Done buttons at the bottom.
36 * @author dswitkin@google.com (Daniel Switkin)
38 public final class HelpActivity extends Activity {
40 private static final String TAG = HelpActivity.class.getName();
42 private static final String[] BUGGY_MODEL_SUBSTRINGS = {"Behold II", "Pulse"};
43 private static final Uri BUGGY_URI = Uri.parse("http://code.google.com/p/zxing/wiki/FrequentlyAskedQuestions");
44 private static final String DEFAULT_URL = "file:///android_asset/html/index.html";
46 private WebView webView;
47 private Button backButton;
49 private final Button.OnClickListener backListener = new Button.OnClickListener() {
50 public void onClick(View view) {
55 private final Button.OnClickListener doneListener = new Button.OnClickListener() {
56 public void onClick(View view) {
61 private final DialogInterface.OnClickListener groupsListener = new DialogInterface.OnClickListener() {
62 public void onClick(DialogInterface dialogInterface, int i) {
63 HelpActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, BUGGY_URI));
68 protected void onCreate(Bundle icicle) {
69 super.onCreate(icicle);
70 setContentView(R.layout.help);
72 webView = (WebView)findViewById(R.id.help_contents);
73 webView.setWebViewClient(new HelpClient());
75 webView.restoreState(icicle);
77 webView.loadUrl(DEFAULT_URL);
80 backButton = (Button)findViewById(R.id.back_button);
81 backButton.setOnClickListener(backListener);
83 Button doneButton = (Button)findViewById(R.id.done_button);
84 doneButton.setOnClickListener(doneListener);
88 public void onResume() {
93 private void checkBuggyDevice() {
94 String model = Build.MODEL;
95 Log.i(TAG, "Build model is " + model);
97 for (String buggyModelSubstring : BUGGY_MODEL_SUBSTRINGS) {
98 if (model.contains(buggyModelSubstring)) {
99 AlertDialog.Builder builder = new AlertDialog.Builder(this);
100 builder.setMessage(R.string.msg_buggy);
101 builder.setPositiveButton(R.string.button_ok, groupsListener);
102 builder.setNegativeButton(R.string.button_cancel, null);
103 builder.create().show();
111 protected void onSaveInstanceState(Bundle state) {
112 webView.saveState(state);
116 public boolean onKeyDown(int keyCode, KeyEvent event) {
117 if (keyCode == KeyEvent.KEYCODE_BACK) {
118 if (webView.canGoBack()) {
123 return super.onKeyDown(keyCode, event);
126 private final class HelpClient extends WebViewClient {
128 public void onPageFinished(WebView view, String url) {
129 setTitle(view.getTitle());
130 backButton.setEnabled(view.canGoBack());