<string name="algorithm">Algorithm</string>
<string name="digits">Digits</string>
+ <string name="about_title">About %1$s</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:<br/>• %1$s<br/>• %2$s</string>
+
<string name="link_website"><a href="http://freeotp.fedorahosted.org">website</a></string>
<string name="link_report_a_problem"><a href="http://fedorahosted.org/freeotp/newticket">Report a Problem</a></string>
<string name="link_ask_for_help"><a href="http://lists.fedorahosted.org/mailman/listinfo/freeotp-devel">Ask for Help</a></string>
+++ /dev/null
-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);
- }
-}
--- /dev/null
+/*
+ * FreeOTP
+ *
+ * Authors: Nathaniel McCallum <npmccallum@redhat.com>
+ *
+ * Copyright (C) 2013 Nathaniel McCallum, Red Hat
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.fedorahosted.freeotp;
+
+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 AboutDialogFragment extends BaseAlertDialogFragment {
+ public static final String FRAGMENT_TAG = "fragment_about";
+
+ public AboutDialogFragment() {
+ super(R.string.about, R.layout.about, 0, android.R.string.ok, 0);
+ }
+
+ @Override
+ protected void onViewInflated(View view) {
+ Resources res = getActivity().getResources();
+ TextView tv;
+
+ try {
+ PackageManager pm = getActivity().getPackageManager();
+ PackageInfo info = pm.getPackageInfo(getActivity().getPackageName(), 0);
+ String version = res.getString(R.string.about_version,
+ info.versionName,
+ info.versionCode);
+ tv = (TextView) view.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) view.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) view.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) view.findViewById(R.id.about_feedback);
+ tv.setMovementMethod(LinkMovementMethod.getInstance());
+ tv.setText(Html.fromHtml(feedback));
+ }
+
+ @Override
+ public void onStart() {
+ super.onStart();
+
+ Resources res = getActivity().getResources();
+ String title = res.getString(R.string.about_title,
+ res.getString(R.string.app_name));
+ getDialog().setTitle(title);
+ }
+
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ }
+}
--- /dev/null
+/*
+ * FreeOTP
+ *
+ * Authors: Nathaniel McCallum <npmccallum@redhat.com>
+ *
+ * Copyright (C) 2013 Nathaniel McCallum, Red Hat
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package org.fedorahosted.freeotp;
+
+import android.app.AlertDialog;
+import android.app.DialogFragment;
+import android.content.DialogInterface;
+import android.view.View;
+
+public abstract class BaseAlertDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
+ private final int mTitle;
+ private final int mLayout;
+ private final int mNegative;
+ private final int mNeutral;
+ private final int mPositive;
+
+ public BaseAlertDialogFragment(int title, int layout, int negative, int neutral, int positive) {
+ mTitle = title;
+ mLayout = layout;
+ mNegative = negative;
+ mNeutral = neutral;
+ mPositive = positive;
+ }
+
+ @Override
+ public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(mTitle);
+
+ if (mNegative != 0)
+ builder.setNegativeButton(mNegative, this);
+
+ if (mNeutral != 0)
+ builder.setNeutralButton(mNeutral, this);
+
+ if (mPositive != 0)
+ builder.setPositiveButton(mPositive, this);
+
+ View view = getActivity().getLayoutInflater().inflate(mLayout, null, false);
+ onViewInflated(view);
+ builder.setView(view);
+
+ return builder.create();
+ };
+
+ protected abstract void onViewInflated(View view);
+}
menu.findItem(R.id.action_about).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
- new AboutDialog(MainActivity.this).show();
+ new AboutDialogFragment().show(getFragmentManager(),
+ AboutDialogFragment.FRAGMENT_TAG);
return true;
}
});