]> Pileus Git - ~andy/freeotp/blobdiff - src/org/fedorahosted/freeotp/MainActivity.java
Add about dialog
[~andy/freeotp] / src / org / fedorahosted / freeotp / MainActivity.java
index 9a31a94592d7353f6408a464bed48368b5ee5f43..5a2f5a7289e6d95c3a45b476d179a177054f698f 100644 (file)
@@ -4,20 +4,18 @@
  * Authors: Nathaniel McCallum <npmccallum@redhat.com>
  *
  * Copyright (C) 2013  Nathaniel McCallum, Red Hat
- * see file 'COPYING' for use and warranty information
  *
- * This program is free software you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ *     http://www.apache.org/licenses/LICENSE-2.0
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 /*
@@ -42,23 +40,27 @@ import java.util.Arrays;
 import java.util.List;
 
 import org.fedorahosted.freeotp.Token.TokenUriInvalidException;
+import org.fedorahosted.freeotp.adapters.TokenAdapter;
 
+import android.app.Activity;
 import android.app.AlertDialog;
-import android.app.ListActivity;
 import android.content.ActivityNotFoundException;
 import android.content.DialogInterface;
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.database.DataSetObserver;
 import android.net.Uri;
 import android.os.Bundle;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.MenuItem.OnMenuItemClickListener;
+import android.view.View;
+import android.widget.GridView;
 import android.widget.Toast;
 
-public class MainActivity extends ListActivity {
+public class MainActivity extends Activity {
        private static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";
        private static final List<String> PROVIDERS = Arrays.asList(new String[] {
                "com.google.zxing.client.android", // Barcode Scanner
@@ -84,10 +86,24 @@ public class MainActivity extends ListActivity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.main);
-        ta = new TokenAdapter(this);
-        setListAdapter(ta);
+               super.onCreate(savedInstanceState);
+               setContentView(R.layout.main);
+
+               ta = new TokenAdapter(this);
+               ((GridView) findViewById(R.id.grid)).setAdapter(ta);
+
+               DataSetObserver dso = new DataSetObserver() {
+                       @Override
+                       public void onChanged() {
+                               super.onChanged();
+                               if (ta.getCount() == 0)
+                                       findViewById(android.R.id.empty).setVisibility(View.VISIBLE);
+                               else
+                                       findViewById(android.R.id.empty).setVisibility(View.GONE);
+                       }
+               };
+               ta.registerDataSetObserver(dso);
+               dso.onChanged();
     }
 
     @Override
@@ -101,7 +117,7 @@ public class MainActivity extends ListActivity {
                                        @Override
                                        public void addToken(String uri) {
                                                try {
-                                                       ta.add(MainActivity.this, uri);
+                                                       ta.add(uri);
                                                } catch (TokenUriInvalidException e) {
                                                        Toast.makeText(MainActivity.this, R.string.invalid_token, Toast.LENGTH_SHORT).show();
                                                        e.printStackTrace();
@@ -153,7 +169,15 @@ public class MainActivity extends ListActivity {
 
                                ad.show();
 
-                       return false;
+                       return true;
+                       }
+               });
+
+               menu.findItem(R.id.action_about).setOnMenuItemClickListener(new OnMenuItemClickListener() {
+                       @Override
+                       public boolean onMenuItemClick(MenuItem item) {
+                               new AboutDialog(MainActivity.this).show();
+                               return true;
                        }
                });
 
@@ -164,7 +188,7 @@ public class MainActivity extends ListActivity {
        public void onActivityResult(int requestCode, int resultCode, Intent intent) {
                if (resultCode == RESULT_OK) {
                        try {
-                               ta.add(this, intent.getStringExtra("SCAN_RESULT"));
+                               ta.add(intent.getStringExtra("SCAN_RESULT"));
                        } catch (TokenUriInvalidException e) {
                                Toast.makeText(this, R.string.invalid_token, Toast.LENGTH_SHORT).show();
                                e.printStackTrace();