Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

Commit

Permalink
Add Version Preference for Settings activity
Browse files Browse the repository at this point in the history
  • Loading branch information
vishesh committed Mar 1, 2015
1 parent 2d175b8 commit e7adca0
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.twistedplane.sealnote.internal;
package com.twistedplane.sealnote.settings;

import android.app.AlertDialog;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.twistedplane.sealnote.settings;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.preference.Preference;
import android.util.AttributeSet;
import com.twistedplane.sealnote.R;

public class VersionPreference extends Preference {
public VersionPreference(Context context, AttributeSet attrs) {
super(context, attrs);
String version = "";

final PackageManager packageManager = context.getPackageManager();
if (packageManager != null) {
try {
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
version = String.format("%s (#%d)", packageInfo.versionName, packageInfo.versionCode);
} catch (PackageManager.NameNotFoundException e) {
//
}
setSummary(version);
setTitle(R.string.version);
setPersistent(false);
}
}
}
3 changes: 3 additions & 0 deletions Sealnote/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,7 @@
<string name="add_tags">Add tags&#8230;</string>
<string name="no_tags_found">No tags found!</string>

<string name="version">Version</string>
<string name="help_and_about"><![CDATA[Help & About]]></string>

</resources>
6 changes: 5 additions & 1 deletion Sealnote/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
android:summary="@string/pref_passwordTimeoutSummary"
/>

<com.twistedplane.sealnote.internal.PasswordPreference
<com.twistedplane.sealnote.settings.PasswordPreference
android:title="@string/pref_changePassword"
android:dialogTitle="@string/pref_changePassword"
/>
Expand Down Expand Up @@ -61,4 +61,8 @@
android:summary="@string/pref_dynamicFontSizeSummary"
/>
</PreferenceCategory>

<PreferenceCategory android:title="@string/help_and_about">
<com.twistedplane.sealnote.settings.VersionPreference />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit e7adca0

Please sign in to comment.