From 275e1b17b97a635ab0e88856e4952619a62c9fc3 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Tue, 3 Dec 2013 10:58:59 -0500 Subject: [PATCH] Add about dialog --- AndroidManifest.xml | 4 +- res/layout/about.xml | 40 ++++++++++ res/menu/main.xml | 7 ++ res/values/strings.xml | 11 +++ src/org/fedorahosted/freeotp/AboutDialog.java | 78 +++++++++++++++++++ .../fedorahosted/freeotp/MainActivity.java | 10 ++- 6 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 res/layout/about.xml create mode 100644 src/org/fedorahosted/freeotp/AboutDialog.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index af4a8be..8c2c602 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -21,8 +21,8 @@ + android:versionCode="4" + android:versionName="1.2" > + + + + + + + + + + + diff --git a/res/menu/main.xml b/res/menu/main.xml index 827c7d9..b189094 100644 --- a/res/menu/main.xml +++ b/res/menu/main.xml @@ -26,4 +26,11 @@ android:showAsAction="always" android:icon="@drawable/scan" android:title="@string/add" /> + + diff --git a/res/values/strings.xml b/res/values/strings.xml index fec49c5..4c4ae83 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2,6 +2,7 @@ FreeOTP Add + About The token specified was invalid! Delete Yes @@ -20,6 +21,16 @@ Algorithm Digits + Version %1$s (%2$d) + © 2013 - Red Hat, Inc., et al. + FreeOTP is licensed under %1$s. + For more information, see our %s. + We welcome your feedback:<br/>• %1$s<br/>• %2$s + <a href="http://freeotp.fedorahosted.org">website</a> + <a href="http://fedorahosted.org/freeotp/newticket">Report a Problem</a> + <a href="http://lists.fedorahosted.org/mailman/listinfo/freeotp-devel">Ask for Help</a> + <a href="http://www.apache.org/licenses/LICENSE-2.0.html">Apache 2.0</a> + %d token selected %d tokens selected diff --git a/src/org/fedorahosted/freeotp/AboutDialog.java b/src/org/fedorahosted/freeotp/AboutDialog.java new file mode 100644 index 0000000..c215099 --- /dev/null +++ b/src/org/fedorahosted/freeotp/AboutDialog.java @@ -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); + } +} diff --git a/src/org/fedorahosted/freeotp/MainActivity.java b/src/org/fedorahosted/freeotp/MainActivity.java index d8278c2..5a2f5a7 100644 --- a/src/org/fedorahosted/freeotp/MainActivity.java +++ b/src/org/fedorahosted/freeotp/MainActivity.java @@ -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; } }); -- 2.43.2