forked from organicmaps/organicmaps
added MWMApplication and moved Platform and Framework initialization code into it.
This commit is contained in:
parent
783a816ad2
commit
e8c348f12a
6 changed files with 132 additions and 102 deletions
|
@ -25,8 +25,11 @@
|
|||
|
||||
<supports-screen android:largeScreens="true"/>
|
||||
|
||||
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
|
||||
<activity android:name="com.mapswithme.maps.CopyResourcesActivity"
|
||||
<application android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:name="com.mapswithme.maps.MWMApplication">
|
||||
|
||||
<activity android:name="com.mapswithme.maps.DownloadResourcesActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="behind"
|
||||
android:theme="@style/MWMNoTitle"
|
||||
|
|
|
@ -31,6 +31,7 @@ LOCAL_SRC_FILES := \
|
|||
com/mapswithme/maps/Framework.cpp \
|
||||
com/mapswithme/maps/VideoTimer.cpp \
|
||||
com/mapswithme/maps/MWMActivity.cpp \
|
||||
com/mapswithme/maps/MWMApplication.cpp \
|
||||
com/mapswithme/maps/Lifecycle.cpp \
|
||||
com/mapswithme/maps/CopyResourcesActivity.cpp \
|
||||
com/mapswithme/platform/Platform.cpp \
|
||||
|
|
|
@ -8,41 +8,9 @@
|
|||
|
||||
#include "../../../../../platform/settings.hpp"
|
||||
|
||||
android::Framework * g_framework = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_nativeInit(JNIEnv * env,
|
||||
jobject thiz,
|
||||
jint densityDpi,
|
||||
jint screenWidth,
|
||||
jint screenHeight,
|
||||
jstring apkPath,
|
||||
jstring storagePath,
|
||||
jstring tmpPath,
|
||||
jstring extTmpPath,
|
||||
jstring settingsPath,
|
||||
jstring emptyModelMessage)
|
||||
{
|
||||
android::Platform::Instance().Initialize(env,
|
||||
densityDpi,
|
||||
screenWidth,
|
||||
screenHeight,
|
||||
apkPath,
|
||||
storagePath,
|
||||
tmpPath,
|
||||
extTmpPath,
|
||||
settingsPath);
|
||||
|
||||
if (!g_framework)
|
||||
g_framework = new android::Framework();
|
||||
|
||||
g_framework->SetEmptyModelMessage(jni::ToString(env, emptyModelMessage));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_MWMActivity_nativeLocationStatusChanged(JNIEnv * env, jobject thiz,
|
||||
int status)
|
||||
|
|
38
android/jni/com/mapswithme/maps/MWMApplication.cpp
Normal file
38
android/jni/com/mapswithme/maps/MWMApplication.cpp
Normal file
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
81
android/src/com/mapswithme/maps/MWMApplication.java
Normal file
81
android/src/com/mapswithme/maps/MWMApplication.java
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Reference in a new issue