Blacklist Evo too for camera issue
[zxing.git] / android / src / com / google / zxing / client / android / HelpActivity.java
1 /*
2  * Copyright 2008 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.android;
18
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;
32
33 /**
34  * An HTML-based help screen with Back and Done buttons at the bottom.
35  *
36  * @author dswitkin@google.com (Daniel Switkin)
37  */
38 public final class HelpActivity extends Activity {
39   private static final String TAG = HelpActivity.class.getSimpleName();
40
41   // Actually guessing at the Desire's MODEL for now:
42   private static final String[] BUGGY_MODEL_SUBSTRINGS = {
43       "Desire",
44       "Pulse", // Camera doesn't come on
45       "Geeksphone", // Doesn't support YUV?
46       "supersonic", // aka Evo
47   };
48   private static final Uri BUGGY_URI =
49       Uri.parse("http://code.google.com/p/zxing/wiki/FrequentlyAskedQuestions");
50
51   // Use this key and one of the values below when launching this activity via intent. If not
52   // present, the default page will be loaded.
53   public static final String REQUESTED_PAGE_KEY = "requested_page_key";
54   public static final String DEFAULT_PAGE = "index.html";
55   public static final String WHATS_NEW_PAGE = "whatsnew.html";
56   private static final String BASE_URL = "file:///android_asset/html/";
57
58   private static boolean initialized = false;
59   private WebView webView;
60   private Button backButton;
61
62   private final Button.OnClickListener backListener = new Button.OnClickListener() {
63     public void onClick(View view) {
64       webView.goBack();
65     }
66   };
67
68   private final Button.OnClickListener doneListener = new Button.OnClickListener() {
69     public void onClick(View view) {
70       finish();
71     }
72   };
73
74   private final DialogInterface.OnClickListener groupsListener =
75       new DialogInterface.OnClickListener() {
76     public void onClick(DialogInterface dialogInterface, int i) {
77       Intent intent = new Intent(Intent.ACTION_VIEW, BUGGY_URI);
78       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
79       HelpActivity.this.startActivity(intent);
80     }
81   };
82
83   @Override
84   protected void onCreate(Bundle icicle) {
85     super.onCreate(icicle);
86     setContentView(R.layout.help);
87
88     webView = (WebView)findViewById(R.id.help_contents);
89     webView.setWebViewClient(new HelpClient());
90
91     Intent intent = getIntent();
92     if (icicle != null) {
93       webView.restoreState(icicle);
94     } else if (intent != null) {
95       String page = intent.getStringExtra(REQUESTED_PAGE_KEY);
96       if (page != null && page.length() > 0) {
97         webView.loadUrl(BASE_URL + page);
98       } else {
99         webView.loadUrl(BASE_URL + DEFAULT_PAGE);
100       }
101     } else {
102       webView.loadUrl(BASE_URL + DEFAULT_PAGE);
103     }
104
105     backButton = (Button)findViewById(R.id.back_button);
106     backButton.setOnClickListener(backListener);
107     Button doneButton = (Button)findViewById(R.id.done_button);
108     doneButton.setOnClickListener(doneListener);
109
110     if (!initialized) {
111       initialized = true;
112       checkBuggyDevice();
113     }
114   }
115
116   private void checkBuggyDevice() {
117     String model = Build.MODEL;
118     Log.i(TAG, "Build model is " + model);
119     if (model != null) {
120       for (String buggyModelSubstring : BUGGY_MODEL_SUBSTRINGS) {
121         if (model.contains(buggyModelSubstring)) {
122           AlertDialog.Builder builder = new AlertDialog.Builder(this);
123           builder.setMessage(R.string.msg_buggy);
124           builder.setPositiveButton(R.string.button_ok, groupsListener);
125           builder.setNegativeButton(R.string.button_cancel, null);
126           builder.show();
127           break;
128         }
129       }
130     }
131   }
132
133   @Override
134   protected void onSaveInstanceState(Bundle state) {
135     webView.saveState(state);
136   }
137
138   @Override
139   public boolean onKeyDown(int keyCode, KeyEvent event) {
140     if (keyCode == KeyEvent.KEYCODE_BACK) {
141       if (webView.canGoBack()) {
142         webView.goBack();
143         return true;
144       }
145     }
146     return super.onKeyDown(keyCode, event);
147   }
148
149   private final class HelpClient extends WebViewClient {
150     @Override
151     public void onPageFinished(WebView view, String url) {
152       setTitle(view.getTitle());
153       backButton.setEnabled(view.canGoBack());
154     }
155   }
156 }