]> Pileus Git - ~andy/freeotp/commitdiff
Add about dialog
authorNathaniel McCallum <npmccallum@redhat.com>
Tue, 3 Dec 2013 15:58:59 +0000 (10:58 -0500)
committerNathaniel McCallum <npmccallum@redhat.com>
Tue, 3 Dec 2013 15:58:59 +0000 (10:58 -0500)
AndroidManifest.xml
res/layout/about.xml [new file with mode: 0644]
res/menu/main.xml
res/values/strings.xml
src/org/fedorahosted/freeotp/AboutDialog.java [new file with mode: 0644]
src/org/fedorahosted/freeotp/MainActivity.java

index af4a8bef298b8c736c6ab0ae5c89ae580c61be4d..8c2c6027a91ead42e957c3c283f25099c7e507e0 100644 (file)
@@ -21,8 +21,8 @@
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="org.fedorahosted.freeotp"
-    android:versionCode="3"
-    android:versionName="1.1" >
+    android:versionCode="4"
+    android:versionName="1.2" >
 
     <uses-sdk
         android:minSdkVersion="11"
diff --git a/res/layout/about.xml b/res/layout/about.xml
new file mode 100644 (file)
index 0000000..5eb66cf
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:padding="16dp" >
+    <TextView
+        android:id="@+id/about_version"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:textSize="18sp"
+        android:textStyle="bold"
+        android:text="@string/about_version" />
+
+    <TextView
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/about_copyright"/>
+
+    <TextView
+        android:id="@+id/about_license"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="16dp"
+        android:text="@string/about_license" />
+
+    <TextView
+        android:id="@+id/about_website"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="16dp"
+        android:text="@string/about_website" />
+
+    <TextView
+        android:id="@+id/about_feedback"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="16dp"
+        android:text="@string/about_feedback" />
+</LinearLayout>
index 827c7d9a7977853e739f54a37c9907eb0ddc419c..b189094a2cfff373f1e15b2eeedeb68e3308d13c 100644 (file)
         android:showAsAction="always"
         android:icon="@drawable/scan"
         android:title="@string/add" />
+
+    <item
+        android:id="@+id/action_about"
+        android:orderInCategory="110"
+        android:showAsAction="never"
+        android:icon="@android:drawable/ic_menu_info_details"
+        android:title="@string/about" />
 </menu>
index fec49c5b236fc97da6be04680f7ac85a350e66b5..4c4ae83bb33055c7087b52c9bf6df36546cf7a8e 100644 (file)
@@ -2,6 +2,7 @@
 <resources>
     <string name="app_name">FreeOTP</string>
     <string name="add">Add</string>
+    <string name="about">About</string>
     <string name="invalid_token">The token specified was invalid!</string>
     <string name="delete">Delete</string>
     <string name="yes">Yes</string>
     <string name="algorithm">Algorithm</string>
     <string name="digits">Digits</string>
 
+    <string name="about_version">Version %1$s (%2$d)</string>
+    <string name="about_copyright">© 2013 - Red Hat, Inc., et al.</string>
+    <string name="about_license">FreeOTP is licensed under %1$s.</string>
+    <string name="about_website">For more information, see our %s.</string>
+    <string name="about_feedback">We welcome your feedback:&lt;br/&gt;• %1$s&lt;br/&gt;• %2$s</string>
+    <string name="link_website">&lt;a href=&quot;http://freeotp.fedorahosted.org&quot;&gt;website&lt;/a&gt;</string>
+    <string name="link_report_a_problem">&lt;a href=&quot;http://fedorahosted.org/freeotp/newticket&quot;&gt;Report a Problem&lt;/a&gt;</string>
+    <string name="link_ask_for_help">&lt;a href=&quot;http://lists.fedorahosted.org/mailman/listinfo/freeotp-devel&quot;&gt;Ask for Help&lt;/a&gt;</string>
+    <string name="link_apache2">&lt;a href=&quot;http://www.apache.org/licenses/LICENSE-2.0.html&quot;&gt;Apache 2.0&lt;/a&gt;</string>
+
     <plurals name="tokens_selected">
         <item quantity="one">%d token selected</item>
         <item quantity="other">%d tokens selected</item>
diff --git a/src/org/fedorahosted/freeotp/AboutDialog.java b/src/org/fedorahosted/freeotp/AboutDialog.java
new file mode 100644 (file)
index 0000000..c215099
--- /dev/null
@@ -0,0 +1,78 @@
+package org.fedorahosted.freeotp;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.text.Html;
+import android.text.method.LinkMovementMethod;
+import android.view.View;
+import android.widget.TextView;
+
+public class AboutDialog extends AlertDialog {
+       private void init(Context ctx) {
+               Resources res = ctx.getResources();
+               View v = getLayoutInflater().inflate(R.layout.about, null, false);
+               TextView tv;
+
+               try {
+                       PackageManager pm = ctx.getPackageManager();
+                       PackageInfo info = pm.getPackageInfo(ctx.getPackageName(), 0);
+                       String version = res.getString(R.string.about_version,
+                                           info.versionName,
+                                           info.versionCode);
+                       tv = (TextView) v.findViewById(R.id.about_version);
+                       tv.setText(version);
+               } catch (PackageManager.NameNotFoundException e) {
+                       e.printStackTrace();
+               }
+
+               String apache2 = res.getString(R.string.link_apache2);
+               String license = res.getString(R.string.about_license, apache2);
+               tv = (TextView) v.findViewById(R.id.about_license);
+               tv.setMovementMethod(LinkMovementMethod.getInstance());
+               tv.setText(Html.fromHtml(license));
+
+               String lwebsite = res.getString(R.string.link_website);
+               String swebsite = res.getString(R.string.about_website, lwebsite);
+               tv = (TextView) v.findViewById(R.id.about_website);
+               tv.setMovementMethod(LinkMovementMethod.getInstance());
+               tv.setText(Html.fromHtml(swebsite));
+
+               String problem = res.getString(R.string.link_report_a_problem);
+               String help = res.getString(R.string.link_ask_for_help);
+               String feedback = res.getString(R.string.about_feedback, problem, help);
+               tv = (TextView) v.findViewById(R.id.about_feedback);
+               tv.setMovementMethod(LinkMovementMethod.getInstance());
+               tv.setText(Html.fromHtml(feedback));
+
+               String title = ctx.getResources().getString(R.string.about);
+               setTitle(title + " " + ctx.getResources().getString(R.string.app_name));
+               setView(v);
+
+               String ok = res.getString(android.R.string.ok);
+               setButton(BUTTON_POSITIVE, ok, new OnClickListener() {
+                       @Override
+                       public void onClick(DialogInterface dialog, int which) {
+                       }
+               });
+       }
+
+       public AboutDialog(Context context, boolean cancelable,
+                       OnCancelListener cancelListener) {
+               super(context, cancelable, cancelListener);
+               init(context);
+       }
+
+       public AboutDialog(Context context, int theme) {
+               super(context, theme);
+               init(context);
+       }
+
+       public AboutDialog(Context context) {
+               super(context);
+               init(context);
+       }
+}
index d8278c2430079f9de6a4031be5d4147b95535ef1..5a2f5a7289e6d95c3a45b476d179a177054f698f 100644 (file)
@@ -169,7 +169,15 @@ public class MainActivity extends Activity {
 
                                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;
                        }
                });