]> Pileus Git - ~andy/freeotp/blob - src/org/fedorahosted/freeotp/AboutDialogFragment.java
Migrate About dialog to use a DialogFragment
[~andy/freeotp] / src / org / fedorahosted / freeotp / AboutDialogFragment.java
1 /*
2  * FreeOTP
3  *
4  * Authors: Nathaniel McCallum <npmccallum@redhat.com>
5  *
6  * Copyright (C) 2013  Nathaniel McCallum, Red Hat
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 package org.fedorahosted.freeotp;
22
23 import android.content.DialogInterface;
24 import android.content.pm.PackageInfo;
25 import android.content.pm.PackageManager;
26 import android.content.res.Resources;
27 import android.text.Html;
28 import android.text.method.LinkMovementMethod;
29 import android.view.View;
30 import android.widget.TextView;
31
32 public class AboutDialogFragment extends BaseAlertDialogFragment {
33         public static final String FRAGMENT_TAG = "fragment_about";
34
35         public AboutDialogFragment() {
36                 super(R.string.about, R.layout.about, 0, android.R.string.ok, 0);
37         }
38
39         @Override
40         protected void onViewInflated(View view) {
41                 Resources res = getActivity().getResources();
42                 TextView tv;
43
44                 try {
45                         PackageManager pm = getActivity().getPackageManager();
46                         PackageInfo info = pm.getPackageInfo(getActivity().getPackageName(), 0);
47                         String version = res.getString(R.string.about_version,
48                                            info.versionName,
49                                            info.versionCode);
50                         tv = (TextView) view.findViewById(R.id.about_version);
51                         tv.setText(version);
52                 } catch (PackageManager.NameNotFoundException e) {
53                         e.printStackTrace();
54                 }
55
56                 String apache2 = res.getString(R.string.link_apache2);
57                 String license = res.getString(R.string.about_license, apache2);
58                 tv = (TextView) view.findViewById(R.id.about_license);
59                 tv.setMovementMethod(LinkMovementMethod.getInstance());
60                 tv.setText(Html.fromHtml(license));
61
62                 String lwebsite = res.getString(R.string.link_website);
63                 String swebsite = res.getString(R.string.about_website, lwebsite);
64                 tv = (TextView) view.findViewById(R.id.about_website);
65                 tv.setMovementMethod(LinkMovementMethod.getInstance());
66                 tv.setText(Html.fromHtml(swebsite));
67
68                 String problem = res.getString(R.string.link_report_a_problem);
69                 String help = res.getString(R.string.link_ask_for_help);
70                 String feedback = res.getString(R.string.about_feedback, problem, help);
71                 tv = (TextView) view.findViewById(R.id.about_feedback);
72                 tv.setMovementMethod(LinkMovementMethod.getInstance());
73                 tv.setText(Html.fromHtml(feedback));
74         }
75
76         @Override
77         public void onStart() {
78                 super.onStart();
79
80                 Resources res = getActivity().getResources();
81                 String title = res.getString(R.string.about_title,
82                                 res.getString(R.string.app_name));
83                 getDialog().setTitle(title);
84         }
85
86         @Override
87         public void onClick(DialogInterface arg0, int arg1) {
88         }
89 }