Skip to content

Commit

Permalink
Added the application's version number and build date to the About sc…
Browse files Browse the repository at this point in the history
…reen.
  • Loading branch information
artob committed Sep 24, 2010
1 parent 822e73b commit 7619c29
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencoinage.android"
android:versionCode="1"
android:versionName="0.0.0">
android:versionName="0.0.0.20100924">
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity
android:name=".MainActivity"
Expand Down
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<string name="app_name">OpenCoinage</string>
<string name="app_title">OpenCoinage Wallet</string>
<string name="app_version">x.y.z</string>
<string name="app_date">yyyy/mm/dd</string>
<string name="app_date">yyyy-mm-dd</string>
<string name="about">About</string>
<string name="about_app_title">About OpenCoinage Wallet</string>
<string name="amount">Amount</string>
Expand Down
50 changes: 40 additions & 10 deletions src/org/opencoinage/android/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import android.app.Activity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import java.util.GregorianCalendar;

public class AboutActivity extends Activity {
private Button closeButton;
private String versionName;

/**
* Called when the activity is first created.
Expand All @@ -18,8 +21,11 @@ public class AboutActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.about);
this.closeButton = (Button)this.findViewById(R.id.close);
this.closeButton.setOnClickListener(new OnClickListener() {

((TextView)this.findViewById(R.id.app_version)).setText(getVersionNumber());
((TextView)this.findViewById(R.id.app_date)).setText(getBuildDate());

((Button)this.findViewById(R.id.close)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
finish();
Expand All @@ -28,14 +34,38 @@ public void onClick(View view) {
}

/**
* Returns the application version number string.
* Returns the application's version number.
*/
public String getVersionNumber() {
String versionName = getVersionName();
return versionName.substring(0, versionName.lastIndexOf(".")); // cut off ".yyyymmdd"
}

/**
* Returns the application's build date.
*/
public String getVersion() {
String version = "x.y.z";
try {
version = getPackageManager().getPackageInfo("org.opencoinage.android", 0).versionName;
public String getBuildDate() {
String versionName = getVersionName();
String versionDate = versionName.substring(versionName.lastIndexOf(".") + 1); // "yyyymmdd"
int year = Integer.parseInt(versionDate.substring(0, 4)); // "yyyy"
int month = Integer.parseInt(versionDate.substring(4, 6)); // "mm"
int day = Integer.parseInt(versionDate.substring(6, 8)); // "dd"
return DateFormat.getDateFormat(this).format(new GregorianCalendar(year, month - 1, day).getTime()).toString();
}

/**
* Returns the manifest's `android:versionName` string.
*
* @see http://developer.android.com/guide/topics/manifest/manifest-element.html#vname
*/
public String getVersionName() {
if (this.versionName == null) {
this.versionName = "x.y.z.yyyymmdd";
try {
this.versionName = getPackageManager().getPackageInfo("org.opencoinage.android", 0).versionName;
}
catch (android.content.pm.PackageManager.NameNotFoundException e) {}
}
catch (android.content.pm.PackageManager.NameNotFoundException e) {}
return version;
return this.versionName;
}
}

0 comments on commit 7619c29

Please sign in to comment.