diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-11-04 22:56:33 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-11-04 22:56:33 +0100 |
commit | 39183418ab133f14bddc389dea8419980538f629 (patch) | |
tree | af4e2af1606c1d87c97382f0281ca7c3777e62e0 /src/main/java/eu/siacs/conversations/ui/AboutPreference.java | |
parent | ff10b094a0a210bb1c7745bd0e0f92e9a7e3ec2d (diff) | |
parent | df786cbf0114d49974f46433740e5ac89a00d63a (diff) |
Merge pull request #616 from SamWhited/license-compliance
License compliance via an "about" menu item
Diffstat (limited to 'src/main/java/eu/siacs/conversations/ui/AboutPreference.java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/AboutPreference.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/ui/AboutPreference.java b/src/main/java/eu/siacs/conversations/ui/AboutPreference.java new file mode 100644 index 00000000..804b4e23 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/AboutPreference.java @@ -0,0 +1,41 @@ +package eu.siacs.conversations.ui; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.preference.Preference; +import android.util.AttributeSet; + +public class AboutPreference extends Preference { + public AboutPreference(final Context context, final AttributeSet attrs, final int defStyle) { + super(context, attrs, defStyle); + setSummary(); + } + + public AboutPreference(final Context context, final AttributeSet attrs) { + super(context, attrs); + setSummary(); + } + + @Override + protected void onClick() { + super.onClick(); + final Intent intent = new Intent(getContext(), AboutActivity.class); + getContext().startActivity(intent); + } + + private void setSummary() { + if (getContext() != null && getContext().getPackageManager() != null) { + final String packageName = getContext().getPackageName(); + final String versionName; + try { + versionName = getContext().getPackageManager().getPackageInfo(packageName, 0).versionName; + setSummary("Conversations " + versionName); + } catch (final PackageManager.NameNotFoundException e) { + // Using try/catch as part of the logic is sort of like this: + // https://xkcd.com/292/ + } + } + } +} + |