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.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;
28 * An HTML-based help screen with Back and Done buttons at the bottom.
30 * @author dswitkin@google.com (Daniel Switkin)
32 public final class HelpActivity extends Activity {
33 private static final String DEFAULT_URL = "file:///android_asset/html/index.html";
35 private WebView webView;
36 private Button backButton;
38 private final Button.OnClickListener backListener = new Button.OnClickListener() {
39 public void onClick(View view) {
44 private final Button.OnClickListener doneListener = new Button.OnClickListener() {
45 public void onClick(View view) {
51 protected void onCreate(Bundle icicle) {
52 super.onCreate(icicle);
53 setContentView(R.layout.help);
55 webView = (WebView)findViewById(R.id.help_contents);
56 webView.setWebViewClient(new HelpClient());
58 webView.restoreState(icicle);
60 webView.loadUrl(DEFAULT_URL);
63 backButton = (Button)findViewById(R.id.back_button);
64 backButton.setOnClickListener(backListener);
66 Button doneButton = (Button)findViewById(R.id.done_button);
67 doneButton.setOnClickListener(doneListener);
71 public void onResume() {
76 protected void onSaveInstanceState(Bundle state) {
77 webView.saveState(state);
81 public boolean onKeyDown(int keyCode, KeyEvent event) {
82 if (keyCode == KeyEvent.KEYCODE_BACK) {
83 if (webView.canGoBack()) {
88 return super.onKeyDown(keyCode, event);
91 private final class HelpClient extends WebViewClient {
93 public void onPageFinished(WebView view, String url) {
94 setTitle(view.getTitle());
95 backButton.setEnabled(view.canGoBack());