Translate Google Shopper strings; untranslate app name in a few cases
[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
40   private static final String TAG = HelpActivity.class.getName();
41
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";
45
46   private WebView webView;
47   private Button backButton;
48
49   private final Button.OnClickListener backListener = new Button.OnClickListener() {
50     public void onClick(View view) {
51       webView.goBack();
52     }
53   };
54
55   private final Button.OnClickListener doneListener = new Button.OnClickListener() {
56     public void onClick(View view) {
57       finish();
58     }
59   };
60
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));
64     }
65   };
66
67   @Override
68   protected void onCreate(Bundle icicle) {
69     super.onCreate(icicle);
70     setContentView(R.layout.help);
71
72     webView = (WebView)findViewById(R.id.help_contents);
73     webView.setWebViewClient(new HelpClient());
74     if (icicle != null) {
75       webView.restoreState(icicle);
76     } else {
77       webView.loadUrl(DEFAULT_URL);
78     }
79
80     backButton = (Button)findViewById(R.id.back_button);
81     backButton.setOnClickListener(backListener);
82
83     Button doneButton = (Button)findViewById(R.id.done_button);
84     doneButton.setOnClickListener(doneListener);
85   }
86
87   @Override
88   public void onResume() {
89     super.onResume();
90     checkBuggyDevice();
91   }
92
93   private void checkBuggyDevice() {
94     String model = Build.MODEL;
95     Log.i(TAG, "Build model is " + model);
96     if (model != null) {
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();
104           break;
105         }
106       }
107     }
108   }
109
110   @Override
111   protected void onSaveInstanceState(Bundle state) {
112     webView.saveState(state);
113   }
114
115   @Override
116   public boolean onKeyDown(int keyCode, KeyEvent event) {
117     if (keyCode == KeyEvent.KEYCODE_BACK) {
118       if (webView.canGoBack()) {
119         webView.goBack();
120         return true;
121       }
122     }
123     return super.onKeyDown(keyCode, event);
124   }
125
126   private final class HelpClient extends WebViewClient {
127     @Override
128     public void onPageFinished(WebView view, String url) {
129       setTitle(view.getTitle());
130       backButton.setEnabled(view.canGoBack());
131     }
132   }
133
134 }