2 * Copyright (C) 2009 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.history;
19 import java.util.List;
21 import android.app.AlertDialog;
22 import android.content.DialogInterface;
23 import android.content.Intent;
24 import android.net.Uri;
25 import android.os.Message;
26 import com.google.zxing.Result;
27 import com.google.zxing.client.android.CaptureActivity;
28 import com.google.zxing.client.android.R;
30 final class HistoryClickListener implements DialogInterface.OnClickListener {
32 private final HistoryManager historyManager;
33 private final CaptureActivity activity;
34 private final String[] dialogItems;
35 private final List<Result> items;
37 HistoryClickListener(HistoryManager historyManager,
38 CaptureActivity activity,
41 this.historyManager = historyManager;
42 this.activity = activity;
43 this.dialogItems = dialogItems;
47 public void onClick(DialogInterface dialogInterface, int i) {
48 if (i == dialogItems.length - 1) {
49 historyManager.clearHistory();
50 } else if (i == dialogItems.length - 2) {
51 CharSequence history = historyManager.buildHistory();
52 Uri historyFile = HistoryManager.saveHistory(history.toString());
53 if (historyFile == null) {
54 AlertDialog.Builder builder = new AlertDialog.Builder(activity);
55 builder.setMessage(R.string.msg_unmount_usb);
56 builder.setPositiveButton(R.string.button_ok, null);
60 Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse("mailto:"));
61 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
62 String subject = activity.getResources().getString(R.string.history_email_title);
63 intent.putExtra(Intent.EXTRA_SUBJECT, subject);
64 intent.putExtra(Intent.EXTRA_TEXT, subject);
65 intent.putExtra(Intent.EXTRA_STREAM, historyFile);
66 intent.setType("text/csv");
67 activity.startActivity(intent);
69 Result result = items.get(i);
70 Message message = Message.obtain(activity.getHandler(), R.id.decode_succeeded, result);
71 message.sendToTarget();