aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-10-05 16:05:56 +0200
committersteckbrief <steckbrief@chefmail.de>2015-10-05 16:05:56 +0200
commit383d1aa9e64a245f17dd7ec6d177bb286a489f62 (patch)
tree0b9d8a50cab4384063669b794ce91804b0a7545c /src/main/java/de/thedevstack/conversationsplus
parentc3c42e415ddd7832fea66766377fb4f0d935537a (diff)
parent1db6e6d5eadbad04768be823b8dbd32827b9b5c3 (diff)
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Manually merged conflicting files: src/main/AndroidManifest.xml src/main/java/eu/siacs/conversations/generator/AbstractGenerator.java src/main/java/eu/siacs/conversations/generator/IqGenerator.java src/main/java/eu/siacs/conversations/ui/AboutPreference.java
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
new file mode 100644
index 00000000..dfe67cb7
--- /dev/null
+++ b/src/main/java/de/thedevstack/conversationsplus/ConversationsPlusApplication.java
@@ -0,0 +1,62 @@
+package de.thedevstack.conversationsplus;
+
+import android.app.Application;
+import android.content.Context;
+import android.content.pm.PackageManager;
+
+import java.io.File;
+
+/**
+ * This class is used to provide static access to the applicationcontext.
+ */
+public class ConversationsPlusApplication extends Application {
+ /**
+ * Application instance for static access
+ */
+ private static ConversationsPlusApplication instance;
+
+ /**
+ * Initializes the application and saves its instance.
+ */
+ public void onCreate(){
+ super.onCreate();
+ ConversationsPlusApplication.instance = this;
+ }
+
+ /**
+ * Returns the application's context.
+ * @return Context the application's context
+ */
+ public static Context getAppContext() {
+ return ConversationsPlusApplication.instance.getApplicationContext();
+ }
+
+ /**
+ * Returns the application's private data directory.
+ * @return File the application's private data dir
+ */
+ public static File getPrivateFilesDir() {
+ return ConversationsPlusApplication.instance.getFilesDir();
+ }
+
+ public static String getVersion() {
+ final String packageName = ConversationsPlusApplication.getAppContext().getPackageName();
+ if (packageName != null) {
+ try {
+ return ConversationsPlusApplication.getAppContext().getPackageManager().getPackageInfo(packageName, 0).versionName;
+ } catch (final PackageManager.NameNotFoundException e) {
+ return "unknown";
+ }
+ } else {
+ return "unknown";
+ }
+ }
+
+ public static String getName() {
+ return ConversationsPlusApplication.getAppContext().getString(R.string.app_name);
+ }
+
+ public static String getNameAndVersion() {
+ return getName() + " " + getVersion();
+ }
+}