Created an HTML help system, which is hooked up to the Menu/Help button. It also...
[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.os.Bundle;
21 import android.view.View;
22 import android.view.KeyEvent;
23 import android.webkit.WebView;
24 import android.webkit.WebViewClient;
25 import android.widget.Button;
26
27 /**
28  * @author dswitkin@google.com (Daniel Switkin)
29  */
30 public final class HelpActivity extends Activity {
31
32   private static final String DEFAULT_URL = "file:///android_asset/html/index.html";
33
34   private WebView mWebView;
35   private Button mBackButton;
36
37   @Override
38   protected void onCreate(Bundle icicle) {
39     super.onCreate(icicle);
40     setContentView(R.layout.help);
41
42     mWebView = (WebView)findViewById(R.id.help_contents);
43     mWebView.setWebViewClient(new HelpClient());
44     if (icicle != null) {
45       mWebView.restoreState(icicle);
46     } else {
47       mWebView.loadUrl(DEFAULT_URL);
48     }
49
50     mBackButton = (Button)findViewById(R.id.back_button);
51     mBackButton.setOnClickListener(mBackListener);
52
53     Button exitButton = (Button)findViewById(R.id.exit_button);
54     exitButton.setOnClickListener(mExitListener);
55   }
56
57   @Override
58   public void onResume() {
59     super.onResume();
60   }
61
62   @Override
63   protected void onSaveInstanceState(Bundle state) {
64     mWebView.saveState(state);
65   }
66
67   @Override
68   public boolean onKeyDown(int keyCode, KeyEvent event) {
69     if (keyCode == KeyEvent.KEYCODE_BACK) {
70       if (mWebView.canGoBack()) {
71         mWebView.goBack();
72         return true;
73       }
74     }
75     return super.onKeyDown(keyCode, event);
76   }
77
78   private final Button.OnClickListener mBackListener = new Button.OnClickListener() {
79     public void onClick(View view) {
80       mWebView.goBack();
81     }
82   };
83
84   private final Button.OnClickListener mExitListener = new Button.OnClickListener() {
85     public void onClick(View view) {
86       finish();
87     }
88   };
89
90   private final class HelpClient extends WebViewClient {
91
92     @Override
93     public void onPageFinished(WebView view, String url) {
94       setTitle(view.getTitle());
95       mBackButton.setEnabled(view.canGoBack());
96     }
97
98   }
99
100 }