1package eu.siacs.conversations.ui;
2
3import android.content.Context;
4import android.content.Intent;
5import android.content.pm.PackageManager;
6import android.preference.Preference;
7import android.util.AttributeSet;
8
9public class AboutPreference extends Preference {
10 public AboutPreference(final Context context, final AttributeSet attrs, final int defStyle) {
11 super(context, attrs, defStyle);
12 setSummary();
13 }
14
15 public AboutPreference(final Context context, final AttributeSet attrs) {
16 super(context, attrs);
17 setSummary();
18 }
19
20 @Override
21 protected void onClick() {
22 super.onClick();
23 final Intent intent = new Intent(getContext(), AboutActivity.class);
24 getContext().startActivity(intent);
25 }
26
27 private void setSummary() {
28 if (getContext() != null && getContext().getPackageManager() != null) {
29 final String packageName = getContext().getPackageName();
30 final String versionName;
31 try {
32 versionName = getContext().getPackageManager().getPackageInfo(packageName, 0).versionName;
33 setSummary("Conversations " + versionName);
34 } catch (final PackageManager.NameNotFoundException e) {
35 // Using try/catch as part of the logic is sort of like this:
36 // https://xkcd.com/292/
37 }
38 }
39 }
40}
41