From: peli0101 Date: Thu, 15 Jan 2009 20:28:54 +0000 (+0000) Subject: Obtain version number programmatically in AskPassword. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=6f8727a5fefeb7e33faa9fc9c953a9f38b0914ea;p=android-vcpass-oisafe Obtain version number programmatically in AskPassword. git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1728 72b678ce-9140-0410-bee8-679b907dd61a --- diff --git a/res/values/strings.xml b/res/values/strings.xml index 166a92d..83bf9bd 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -21,7 +21,6 @@ OI Safe Steven Osborn, Randy McEoin - 0.6.0 No Passwords present for this category. No categories present. Please add one via Menu->Add Lock diff --git a/src/org/openintents/safe/AskPassword.java b/src/org/openintents/safe/AskPassword.java index 6114117..7b7ae8c 100644 --- a/src/org/openintents/safe/AskPassword.java +++ b/src/org/openintents/safe/AskPassword.java @@ -16,6 +16,8 @@ */ package org.openintents.safe; +import org.openintents.util.VersionUtils; + import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -83,8 +85,8 @@ public class AskPassword extends Activity { ImageView icon = (ImageView) findViewById(R.id.entry_icon); icon.setImageResource(R.drawable.passicon); TextView header = (TextView) findViewById(R.id.entry_header); - String version = getString(R.string.version); - String appName = getString(R.string.app_name); + String version = VersionUtils.getVersionNumber(this); + String appName = VersionUtils.getApplicationName(this); String head = appName + " " + version + "\n"; header.setText(head); diff --git a/src/org/openintents/safe/LogOffActivity.java b/src/org/openintents/safe/LogOffActivity.java index f939e58..690d4e2 100644 --- a/src/org/openintents/safe/LogOffActivity.java +++ b/src/org/openintents/safe/LogOffActivity.java @@ -1,6 +1,7 @@ package org.openintents.safe; import org.openintents.safe.service.ServiceDispatchImpl; +import org.openintents.util.VersionUtils; import android.app.Activity; import android.content.Intent; @@ -19,8 +20,8 @@ public class LogOffActivity extends Activity { ImageView icon = (ImageView) findViewById(R.id.logoff_icon); icon.setImageResource(R.drawable.passicon); TextView header = (TextView) findViewById(R.id.logoff_header); - String version = getString(R.string.version); - String appName = getString(R.string.app_name); + String version = VersionUtils.getVersionNumber(this); + String appName = VersionUtils.getApplicationName(this); String head = appName + " " + version + "\n"; header.setText(head); Button logoffButton = (Button) findViewById(R.id.logoff_button); diff --git a/src/org/openintents/util/VersionUtils.java b/src/org/openintents/util/VersionUtils.java new file mode 100644 index 0000000..06d721f --- /dev/null +++ b/src/org/openintents/util/VersionUtils.java @@ -0,0 +1,50 @@ +package org.openintents.util; + +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.util.Log; + +/** + * + * @version 2009-01-15 + * @author Peli + * + */ +public class VersionUtils { + + private static final String TAG = "VersionUtils"; + + /** + * Get current version number. + * + * @return + */ + public static String getVersionNumber(Context context) { + String version = "?"; + try { + PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + version = pi.versionName; + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Package name not found", e); + }; + return version; + } + + /** + * Get application name. + * + * @return + */ + public static String getApplicationName(Context context) { + String name = "?"; + try { + PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + name = context.getString(pi.applicationInfo.labelRes); + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Package name not found", e); + }; + return name; + } + +}