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 Intent intent = new Intent(Intent.ACTION_VIEW, BUGGY_URI);
64 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
65 HelpActivity.this.startActivity(intent);
70 protected void onCreate(Bundle icicle) {
71 super.onCreate(icicle);
72 setContentView(R.layout.help);
74 webView = (WebView)findViewById(R.id.help_contents);
75 webView.setWebViewClient(new HelpClient());
77 webView.restoreState(icicle);
79 webView.loadUrl(DEFAULT_URL);
82 backButton = (Button)findViewById(R.id.back_button);
83 backButton.setOnClickListener(backListener);
85 Button doneButton = (Button)findViewById(R.id.done_button);
86 doneButton.setOnClickListener(doneListener);
90 public void onResume() {
95 private void checkBuggyDevice() {
96 String model = Build.MODEL;
97 Log.i(TAG, "Build model is " + model);
99 for (String buggyModelSubstring : BUGGY_MODEL_SUBSTRINGS) {
100 if (model.contains(buggyModelSubstring)) {
101 AlertDialog.Builder builder = new AlertDialog.Builder(this);
102 builder.setMessage(R.string.msg_buggy);
103 builder.setPositiveButton(R.string.button_ok, groupsListener);
104 builder.setNegativeButton(R.string.button_cancel, null);
105 builder.create().show();
113 protected void onSaveInstanceState(Bundle state) {
114 webView.saveState(state);
118 public boolean onKeyDown(int keyCode, KeyEvent event) {
119 if (keyCode == KeyEvent.KEYCODE_BACK) {
120 if (webView.canGoBack()) {
125 return super.onKeyDown(keyCode, event);
128 private final class HelpClient extends WebViewClient {
130 public void onPageFinished(WebView view, String url) {
131 setTitle(view.getTitle());
132 backButton.setEnabled(view.canGoBack());