4 * Authors: Nathaniel McCallum <npmccallum@redhat.com>
6 * Copyright (C) 2013 Nathaniel McCallum, Red Hat
7 * see file 'COPYING' for use and warranty information
9 * This program is free software you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 package org.fedorahosted.freeotp;
25 import java.security.NoSuchAlgorithmException;
27 import org.fedorahosted.freeotp.Token.TokenUriInvalidException;
29 import android.os.Bundle;
30 import android.app.ListActivity;
31 import android.content.Intent;
32 import android.view.Menu;
33 import android.view.MenuItem;
34 import android.view.MenuItem.OnMenuItemClickListener;
35 import android.widget.Toast;
37 public class MainActivity extends ListActivity {
38 private TokenAdapter ta;
41 protected void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
44 ta = new TokenAdapter(this);
49 public boolean onCreateOptionsMenu(Menu menu) {
50 getMenuInflater().inflate(R.menu.main, menu);
52 menu.findItem(R.id.action_add).setOnMenuItemClickListener(new OnMenuItemClickListener() {
53 public boolean onMenuItemClick(MenuItem item) {
54 Intent i = new Intent("com.google.zxing.client.android.SCAN");
55 i.putExtra("SCAN_MODE", "QR_CODE_MODE");
56 i.putExtra("SAVE_HISTORY", false);
57 startActivityForResult(i, 0);
65 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
66 if (resultCode == RESULT_OK) {
68 ta.add(this, intent.getStringExtra("SCAN_RESULT"));
69 } catch (NoSuchAlgorithmException e) {
70 Toast.makeText(this, R.string.token_scan_invalid, Toast.LENGTH_SHORT).show();
72 } catch (TokenUriInvalidException e) {
73 Toast.makeText(this, R.string.token_scan_invalid, Toast.LENGTH_SHORT).show();