Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Yunitsky <yunik@mapswithme.com>2015-09-10 12:32:14 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:04:29 +0300
commit9f4bb161a9d80b102863f66480cd48ad7a99afd7 (patch)
tree13da7cf87040f5263212cc8560669a1c221917af /android
parentc2e2c6aff952749e59fa2aef53292a993fcedb1a (diff)
[android] Initialize Framework from base activities & service.
Diffstat (limited to 'android')
-rw-r--r--android/src/com/mapswithme/maps/MwmApplication.java74
-rw-r--r--android/src/com/mapswithme/maps/background/WorkerService.java7
-rw-r--r--android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java1
-rw-r--r--android/src/com/mapswithme/maps/settings/SettingsActivity.java12
-rw-r--r--android/src/com/mapswithme/util/Constants.java2
-rw-r--r--android/src/com/mapswithme/util/Utils.java20
6 files changed, 71 insertions, 45 deletions
diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java
index 3d95ac21e8..eca6b8c5f9 100644
--- a/android/src/com/mapswithme/maps/MwmApplication.java
+++ b/android/src/com/mapswithme/maps/MwmApplication.java
@@ -7,6 +7,7 @@ import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
+
import com.google.gsonaltered.Gson;
import com.mapswithme.country.ActiveCountryTree;
import com.mapswithme.country.CountryItem;
@@ -28,7 +29,6 @@ import java.io.File;
public class MwmApplication extends android.app.Application implements ActiveCountryTree.ActiveCountryListener
{
private final static String TAG = "MwmApplication";
- private static final String FOREGROUND_TIME_SETTING = "AllForegroundTime";
private static final String LAUNCH_NUMBER_SETTING = "LaunchNumber"; // total number of app launches
private static final String SESSION_NUMBER_SETTING = "SessionNumber"; // session = number of days, when app was launched
private static final String LAST_SESSION_TIMESTAMP_SETTING = "LastSessionTimestamp"; // timestamp of last session
@@ -43,6 +43,7 @@ public class MwmApplication extends android.app.Application implements ActiveCou
private static SharedPreferences mPrefs;
private boolean mAreCountersInitialised;
+ private boolean mIsFrameworkInitialized;
public MwmApplication()
{
@@ -96,21 +97,37 @@ public class MwmApplication extends android.app.Application implements ActiveCou
{
super.onCreate();
+ initParse();
+ mPrefs = getSharedPreferences(getString(R.string.pref_file_name), MODE_PRIVATE);
+ }
+
+ public synchronized void initNativeCore()
+ {
+ if (mIsFrameworkInitialized)
+ return;
+
+ initPaths();
+ nativeInit(getApkPath(), getDataStoragePath(), getTempPath(), getObbGooglePath(),
+ BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE,
+ Yota.isFirstYota(), UiUtils.isSmallTablet() || UiUtils.isBigTablet());
+ ActiveCountryTree.addListener(this);
+ initNativeStrings();
+ BookmarkManager.getIcons(); // init BookmarkManager (automatically loads bookmarks)
+ mIsFrameworkInitialized = true;
+ }
+
+ @SuppressWarnings("ResultOfMethodCallIgnored")
+ private void initPaths()
+ {
final String extStoragePath = getDataStoragePath();
final String extTmpPath = getTempPath();
- // Create folders if they don't exist
new File(extStoragePath).mkdirs();
new File(extTmpPath).mkdirs();
+ }
- // init native framework
- nativeInit(getApkPath(), extStoragePath, extTmpPath, getOBBGooglePath(),
- BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE,
- Yota.isFirstYota(), UiUtils.isSmallTablet() || UiUtils.isBigTablet());
-
- ActiveCountryTree.addListener(this);
-
- // init cross-platform strings bundle
+ private void initNativeStrings()
+ {
nativeAddLocalization("country_status_added_to_queue", getString(R.string.country_status_added_to_queue));
nativeAddLocalization("country_status_downloading", getString(R.string.country_status_downloading));
nativeAddLocalization("country_status_download", getString(R.string.country_status_download));
@@ -130,11 +147,6 @@ public class MwmApplication extends android.app.Application implements ActiveCou
nativeAddLocalization("routing_failed_cross_mwm_building", getString(R.string.routing_failed_cross_mwm_building));
nativeAddLocalization("routing_failed_route_not_found", getString(R.string.routing_failed_route_not_found));
nativeAddLocalization("routing_failed_internal_error", getString(R.string.routing_failed_internal_error));
-
- // init BookmarkManager (automatically loads bookmarks)
- BookmarkManager.getIcons();
- initParse();
- mPrefs = getSharedPreferences(getString(R.string.pref_file_name), MODE_PRIVATE);
}
public String getApkPath()
@@ -156,31 +168,20 @@ public class MwmApplication extends android.app.Application implements ActiveCou
public String getTempPath()
{
- // TODO refactor
- // Can't use getExternalCacheDir() here because of API level = 7.
- return getExtAppDirectoryPath(Constants.CACHE_DIR);
- }
+ final File cacheDir = getExternalCacheDir();
+ if (cacheDir != null)
+ return cacheDir.getAbsolutePath();
- public String getExtAppDirectoryPath(String folder)
- {
- final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
- return storagePath.concat(String.format(Constants.STORAGE_PATH, BuildConfig.APPLICATION_ID, folder));
+ return Environment.getExternalStorageDirectory().getAbsolutePath() +
+ String.format(Constants.STORAGE_PATH, BuildConfig.APPLICATION_ID, Constants.CACHE_DIR);
}
- private String getOBBGooglePath()
+ private String getObbGooglePath()
{
final String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
return storagePath.concat(String.format(Constants.OBB_PATH, BuildConfig.APPLICATION_ID));
}
- // Check if we have free space on storage (writable path).
- public native boolean hasFreeSpace(long size);
-
- public double getForegroundTime()
- {
- return nativeGetDouble(FOREGROUND_TIME_SETTING, 0);
- }
-
static
{
System.loadLibrary("mapswithme");
@@ -216,6 +217,11 @@ public class MwmApplication extends android.app.Application implements ActiveCou
public native void nativeSetString(String name, String value);
+ /**
+ * Check if device have at least {@code size} bytes free.
+ */
+ public native boolean hasFreeSpace(long size);
+
/*
* init Parse SDK
*/
@@ -238,8 +244,8 @@ public class MwmApplication extends android.app.Application implements ActiveCou
org.alohalytics.Statistics.logEvent(AlohaHelper.PARSE_INSTALLATION_ID, newId);
org.alohalytics.Statistics.logEvent(AlohaHelper.PARSE_DEVICE_TOKEN, newToken);
prefs.edit()
- .putString(PREF_PARSE_INSTALLATION_ID, newId)
- .putString(PREF_PARSE_DEVICE_TOKEN, newToken).apply();
+ .putString(PREF_PARSE_INSTALLATION_ID, newId)
+ .putString(PREF_PARSE_DEVICE_TOKEN, newToken).apply();
}
}
});
diff --git a/android/src/com/mapswithme/maps/background/WorkerService.java b/android/src/com/mapswithme/maps/background/WorkerService.java
index 4c2e5c87c3..cb2cf45339 100644
--- a/android/src/com/mapswithme/maps/background/WorkerService.java
+++ b/android/src/com/mapswithme/maps/background/WorkerService.java
@@ -55,6 +55,13 @@ public class WorkerService extends IntentService
}
@Override
+ public void onCreate()
+ {
+ super.onCreate();
+ MwmApplication.get().initNativeCore();
+ }
+
+ @Override
protected void onHandleIntent(Intent intent)
{
if (intent != null)
diff --git a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java
index e68db48e9d..0cc61ee100 100644
--- a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java
+++ b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java
@@ -31,6 +31,7 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
}
MwmApplication.get().initCounters();
+ MwmApplication.get().initNativeCore();
ViewServer.get(this).addWindow(this);
attachDefaultFragment();
diff --git a/android/src/com/mapswithme/maps/settings/SettingsActivity.java b/android/src/com/mapswithme/maps/settings/SettingsActivity.java
index 85d4368f4b..a5c6997c9c 100644
--- a/android/src/com/mapswithme/maps/settings/SettingsActivity.java
+++ b/android/src/com/mapswithme/maps/settings/SettingsActivity.java
@@ -24,7 +24,6 @@ import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
-import com.mapswithme.util.ViewServer;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.mapswithme.country.ActiveCountryTree;
@@ -34,6 +33,7 @@ import com.mapswithme.maps.R;
import com.mapswithme.util.Constants;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
+import com.mapswithme.util.ViewServer;
import com.mapswithme.util.Yota;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.Statistics;
@@ -57,6 +57,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
// this initialisation is necessary hence Activity isn't extended from BaseMwmActivity
// try to prevent possible crash if this is the only activity in application
MwmApplication.get().initCounters();
+ MwmApplication.get().initNativeCore();
addPreferencesFromResource(R.xml.preferences);
initPreferences();
yotaSetup();
@@ -335,14 +336,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
{
Statistics.INSTANCE.trackSimpleNamedEvent(Statistics.EventName.SETTINGS_REPORT_BUG);
AlohaHelper.logClick(AlohaHelper.SETTINGS_REPORT_BUG);
- final Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.putExtra(Intent.EXTRA_EMAIL, new String[]{BuildConfig.SUPPORT_MAIL});
- intent.putExtra(Intent.EXTRA_SUBJECT, "[android] Bugreport from user");
- intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + Utils.saveLogToFile()));
- intent.putExtra(Intent.EXTRA_TEXT, ""); // do this so some email clients don't complain about empty body.
- intent.setType("message/rfc822");
- startActivity(intent);
+ Utils.sendSupportMail(this, "Bugreport from user");
}
else if (key.equals(getString(R.string.pref_like_fb)))
{
diff --git a/android/src/com/mapswithme/util/Constants.java b/android/src/com/mapswithme/util/Constants.java
index db456883eb..9264031a38 100644
--- a/android/src/com/mapswithme/util/Constants.java
+++ b/android/src/com/mapswithme/util/Constants.java
@@ -1,6 +1,6 @@
package com.mapswithme.util;
-public class Constants
+public final class Constants
{
public static final String STORAGE_PATH = "/Android/data/%s/%s/";
public static final String PACKAGE_STORAGES_PATH = "/Android/data/";
diff --git a/android/src/com/mapswithme/util/Utils.java b/android/src/com/mapswithme/util/Utils.java
index a18110b663..cfcc0620cf 100644
--- a/android/src/com/mapswithme/util/Utils.java
+++ b/android/src/com/mapswithme/util/Utils.java
@@ -274,7 +274,6 @@ public class Utils
/**
* @param timestamp in currentTimeMillis() format
- * @return
*/
public static boolean isInstalledAfter(long timestamp)
{
@@ -308,4 +307,23 @@ public class Utils
AlohaHelper.logException(e);
}
}
+
+ public static void sendSupportMail(Activity activity, String subject)
+ {
+ final Intent intent = new Intent(Intent.ACTION_SEND);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.putExtra(Intent.EXTRA_EMAIL, new String[]{BuildConfig.SUPPORT_MAIL});
+ intent.putExtra(Intent.EXTRA_SUBJECT, "[android] " + subject);
+ intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + Utils.saveLogToFile()));
+ intent.putExtra(Intent.EXTRA_TEXT, ""); // do this so some email clients don't complain about empty body.
+ intent.setType("message/rfc822");
+ try
+ {
+ activity.startActivity(intent);
+ }
+ catch (ActivityNotFoundException e)
+ {
+ AlohaHelper.logException(e);
+ }
+ }
}