diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index aa3b4bc90d..6e94a4ac56 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -25,8 +25,11 @@
-
-
+
+ SetEmptyModelMessage(jni::ToString(env, emptyModelMessage));
- }
-
-////////////////////////////////////////////////////////////////////////////////////////////
-
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_MWMActivity_nativeLocationStatusChanged(JNIEnv * env, jobject thiz,
int status)
diff --git a/android/jni/com/mapswithme/maps/MWMApplication.cpp b/android/jni/com/mapswithme/maps/MWMApplication.cpp
new file mode 100644
index 0000000000..a5f47d8d64
--- /dev/null
+++ b/android/jni/com/mapswithme/maps/MWMApplication.cpp
@@ -0,0 +1,38 @@
+/*
+ * MWMService.cpp
+ *
+ * Created on: May 11, 2012
+ * Author: siarheirachytski
+ */
+
+#include "Framework.hpp"
+
+#include "../core/jni_helper.hpp"
+
+#include "../platform/Platform.hpp"
+
+extern "C"
+{
+ JNIEXPORT void JNICALL
+ Java_com_mapswithme_maps_MWMApplication_nativeInit(JNIEnv * env,
+ jobject thiz,
+ jstring apkPath,
+ jstring storagePath,
+ jstring tmpPath,
+ jstring extTmpPath,
+ jstring settingsPath,
+ jstring emptyModelMessage)
+ {
+ android::Platform::Instance().Initialize(env,
+ apkPath,
+ storagePath,
+ tmpPath,
+ extTmpPath,
+ settingsPath);
+
+ if (!g_framework)
+ g_framework = new android::Framework();
+
+ g_framework->SetEmptyModelMessage(jni::ToString(env, emptyModelMessage));
+ }
+}
diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java
index a2a12b71e9..0f47d044da 100644
--- a/android/src/com/mapswithme/maps/MWMActivity.java
+++ b/android/src/com/mapswithme/maps/MWMActivity.java
@@ -32,7 +32,6 @@ public class MWMActivity extends NvEventQueueActivity implements
//VideoTimer m_timer;
private static String TAG = "MWMActivity";
- private final static String PACKAGE_NAME = "com.mapswithme.maps";
private LocationService m_locationService = null;
@@ -43,40 +42,6 @@ public class MWMActivity extends NvEventQueueActivity implements
private static Context m_context = null;
public static Context getCurrentContext() { return m_context; }
- public static String getApkPath(Activity activity)
- {
- try
- {
- return activity.getApplication().getPackageManager().getApplicationInfo(PACKAGE_NAME, 0).sourceDir;
- } catch (NameNotFoundException e)
- {
- e.printStackTrace();
- }
- return "";
- }
-
- public static String getDataStoragePath()
- {
- return Environment.getExternalStorageDirectory().getAbsolutePath() + "/MapsWithMe/";
- }
-
- public static String getExtAppDirectoryPath(String folder)
- {
- final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
- return storagePath.concat(String.format("/Android/data/%s/%s/", PACKAGE_NAME, folder));
- }
-
- // Note: local storage memory is limited on some devices!
- private String getTmpPath()
- {
- return getCacheDir().getAbsolutePath() + "/";
- }
-
- private String getSettingsPath()
- {
- return getFilesDir().getAbsolutePath() + "/";
- }
-
public void checkShouldStartLocationService()
{
if (m_shouldStartLocationService)
@@ -208,7 +173,7 @@ public class MWMActivity extends NvEventQueueActivity implements
m_locationService.startUpdate(this, this);
v.setSelected(!isLocationActive);
// Store active state of My Position
- SharedPreferences.Editor prefsEdit = getSharedPreferences(PACKAGE_NAME, MODE_PRIVATE).edit();
+ SharedPreferences.Editor prefsEdit = getSharedPreferences(mApplication.getPackageName(), MODE_PRIVATE).edit();
prefsEdit.putBoolean(PREFERENCES_MYPOSITION, !isLocationActive);
prefsEdit.commit();
}
@@ -217,6 +182,8 @@ public class MWMActivity extends NvEventQueueActivity implements
{
startActivity(new Intent(this, DownloadUI.class));
}
+
+ private MWMApplication mApplication;
@Override
public void onCreate(Bundle savedInstanceState)
@@ -231,27 +198,13 @@ public class MWMActivity extends NvEventQueueActivity implements
super.onCreate(savedInstanceState);
m_context = this;
-
- final String extStoragePath = getDataStoragePath();
- final String extTmpPath = getExtAppDirectoryPath("caches");
- // Create folders if they don't exist
- new File(extStoragePath).mkdirs();
- new File(extTmpPath).mkdirs();
+
+ mApplication = (MWMApplication)getApplication();
// Get screen density
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
- nativeInit(metrics.densityDpi,
- metrics.widthPixels,
- metrics.heightPixels,
- getApkPath(this),
- extStoragePath,
- getTmpPath(),
- extTmpPath,
- getSettingsPath(),
- getString(R.string.empty_model));
-
//m_timer = new VideoTimer();
m_locationService = new LocationService(this);
@@ -283,7 +236,7 @@ public class MWMActivity extends NvEventQueueActivity implements
{
super.onStart();
// Restore My Position state on startup/activity recreation
- SharedPreferences prefs = getSharedPreferences(PACKAGE_NAME, MODE_PRIVATE);
+ SharedPreferences prefs = getSharedPreferences(mApplication.getPackageName(), MODE_PRIVATE);
final boolean isMyPositionEnabled = prefs.getBoolean(PREFERENCES_MYPOSITION, false);
findViewById(R.id.map_button_myposition).setSelected(isMyPositionEnabled);
}
@@ -451,23 +404,9 @@ public class MWMActivity extends NvEventQueueActivity implements
}
}
- static
- {
- System.loadLibrary("mapswithme");
- }
-
private native void nativeStorageConnected();
private native void nativeStorageDisconnected();
- private native void nativeInit(int densityDpi,
- int screenWidth,
- int screenHeight,
- String apkPath,
- String storagePath,
- String tmpPath,
- String extTmpPath,
- String settingsPath,
- String emptyModelMessage);
private native void nativeDestroy();
private native void nativeLocationStatusChanged(int newStatus);
private native void nativeLocationUpdated(long time, double lat, double lon, float accuracy);
diff --git a/android/src/com/mapswithme/maps/MWMApplication.java b/android/src/com/mapswithme/maps/MWMApplication.java
new file mode 100644
index 0000000000..3ed9c375f1
--- /dev/null
+++ b/android/src/com/mapswithme/maps/MWMApplication.java
@@ -0,0 +1,81 @@
+package com.mapswithme.maps;
+
+import java.io.File;
+
+import android.app.Application;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.os.Environment;
+
+public class MWMApplication extends Application
+{
+ public final static String PACKAGE_NAME = "com.mapswithme.maps";
+
+ public void onCreate()
+ {
+ final String extStoragePath = getDataStoragePath();
+ final String extTmpPath = getExtAppDirectoryPath("caches");
+ // Create folders if they don't exist
+ new File(extStoragePath).mkdirs();
+ new File(extTmpPath).mkdirs();
+
+ nativeInit(getApkPath(),
+ extStoragePath,
+ getTmpPath(),
+ extTmpPath,
+ getSettingsPath(),
+ getString(R.string.empty_model));
+
+ super.onCreate();
+ }
+
+ public String getApkPath()
+ {
+ try
+ {
+ return getPackageManager().getApplicationInfo(PACKAGE_NAME, 0).sourceDir;
+ }
+ catch (NameNotFoundException e)
+ {
+ e.printStackTrace();
+ return "";
+ }
+ }
+
+ public String getDataStoragePath()
+ {
+ return Environment.getExternalStorageDirectory().getAbsolutePath() + "/MapsWithMe/";
+ }
+
+ public String getExtAppDirectoryPath(String folder)
+ {
+ final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
+ return storagePath.concat(String.format("/Android/data/%s/%s/", PACKAGE_NAME, folder));
+ }
+
+ private String getTmpPath()
+ {
+ return getCacheDir().getAbsolutePath() + "/";
+ }
+
+ private String getSettingsPath()
+ {
+ return getFilesDir().getAbsolutePath() + "/";
+ }
+
+ public String getPackageName()
+ {
+ return PACKAGE_NAME;
+ }
+
+ static
+ {
+ System.loadLibrary("mapswithme");
+ }
+
+ private native void nativeInit(String apkPath,
+ String storagePath,
+ String tmpPath,
+ String extTmpPath,
+ String settingsPath,
+ String emptyModelMessage);
+}