diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5e6da371..f8f5147c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -86,7 +86,6 @@
-
diff --git a/app/src/main/java/mobi/maptrek/Configuration.java b/app/src/main/java/mobi/maptrek/Configuration.java
index f353e918..042c6527 100644
--- a/app/src/main/java/mobi/maptrek/Configuration.java
+++ b/app/src/main/java/mobi/maptrek/Configuration.java
@@ -509,6 +509,43 @@ public static void setHighlightedType(int type) {
saveInt(PREF_HIGHLIGHTED_TYPE, type);
}
+ public static void resetMapState() {
+ remove(PREF_LATITUDE);
+ remove(PREF_LONGITUDE);
+ remove(PREF_MAP_SCALE);
+ remove(PREF_MAP_BEARING);
+ remove(PREF_MAP_TILT);
+ remove(PREF_MAP_3D_BUILDINGS);
+ remove(PREF_MAP_CONTOURS);
+ remove(PREF_MAP_HILLSHADES);
+ remove(PREF_MAP_GRID);
+ remove(PREF_BITMAP_MAP);
+ remove(PREF_LOCATION_STATE);
+ remove(PREF_PREVIOUS_LOCATION_STATE);
+ remove(PREF_TRACKING_STATE);
+ remove(PREF_ACTION_PANEL_STATE);
+ remove(PREF_NAVIGATION_WAYPOINT);
+ remove(PREF_NAVIGATION_LATITUDE);
+ remove(PREF_NAVIGATION_LONGITUDE);
+ remove(PREF_NAVIGATION_PROXIMITY);
+ remove(PREF_NAVIGATION_ROUTE);
+ remove(PREF_NAVIGATION_ROUTE_POINT);
+ remove(PREF_NAVIGATION_ROUTE_DIRECTION);
+ remove(PREF_GAUGES);
+ remove(PREF_NIGHT_MODE_STATE);
+ remove(PREF_MAP_STYLE);
+ remove(PREF_ACTIVITY);
+ remove(PREF_MAP_FONT_SIZE);
+ remove(PREF_MAP_USER_SCALE);
+ remove(PREF_LANGUAGE);
+ remove(PREF_HIDE_MAP_OBJECTS);
+ remove(PREF_BITMAP_MAP_TRANSPARENCY);
+ remove(PREF_REMEMBERED_SCALE);
+ remove(PREF_AUTO_TILT);
+ remove(PREF_HIDE_SYSTEM_UI);
+ remove(PREF_HIGHLIGHTED_TYPE);
+ }
+
/**
Returns total running time in minutes
*/
diff --git a/app/src/main/java/mobi/maptrek/MainActivity.java b/app/src/main/java/mobi/maptrek/MainActivity.java
index 85659b53..7a56e059 100644
--- a/app/src/main/java/mobi/maptrek/MainActivity.java
+++ b/app/src/main/java/mobi/maptrek/MainActivity.java
@@ -828,11 +828,6 @@ protected void onNewIntent(Intent intent) {
setMapLocation(position.getGeoPoint());
} else if ("mobi.maptrek.action.NAVIGATE_TO_OBJECT".equals(action)) {
startNavigation(intent.getLongExtra(NavigationService.EXTRA_ID, 0L));
- } else if ("mobi.maptrek.action.RESET_ADVICES".equals(action)) {
- mBackgroundHandler.postDelayed(Configuration::resetAdviceState, 10000); // Delay reset so that advices are not shown immediately after reset
- Snackbar.make(mViews.coordinatorLayout, R.string.msgAdvicesReset, Snackbar.LENGTH_LONG)
- .setAnchorView(mViews.actionPanel)
- .show();
} else if ("geo".equals(scheme)) {
Uri uri = intent.getData();
if (uri == null)
diff --git a/app/src/main/java/mobi/maptrek/MapTrek.java b/app/src/main/java/mobi/maptrek/MapTrek.java
index efd15b9d..0556dde5 100644
--- a/app/src/main/java/mobi/maptrek/MapTrek.java
+++ b/app/src/main/java/mobi/maptrek/MapTrek.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023 Andrey Novikov
+ * Copyright 2024 Andrey Novikov
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -21,7 +21,6 @@
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
-import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -134,6 +133,7 @@ public class MapTrek extends Application {
@Override
public void onCreate() {
super.onCreate();
+ logger.info("Trekarta application starting");
mSelf = this;
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
@@ -211,22 +211,17 @@ public static MapTrek getApplication() {
}
/** @noinspection unused*/
- public void restart(@NonNull Context context, Class> cls) {
- Intent intent = new Intent(context, cls);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- /*
- PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
- AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- if (mgr != null)
- mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, pendingIntent);
- */
- if (context instanceof Activity)
- ((Activity) context).finish();
- startActivity(intent);
- /*
+ public void restart() {
+ logger.info("Application restart initiated");
Configuration.commit();
+ //Context ctx = getApplicationContext();
+ PackageManager pm = getPackageManager();
+ Intent intent = pm.getLaunchIntentForPackage(getPackageName());
+ if (intent != null) {
+ Intent mainIntent = Intent.makeRestartActivityTask(intent.getComponent());
+ startActivity(mainIntent);
+ }
Runtime.getRuntime().exit(0);
- */
}
@TargetApi(26)
@@ -437,6 +432,7 @@ public void setBitmapLayerMaps(@NonNull List bitmapLayerMaps) {
@SuppressWarnings("SameParameterValue")
private void copyAsset(String asset, File outFile) throws IOException {
+ logger.debug("copyAsset({})", asset);
InputStream in = getAssets().open(asset);
//noinspection IOStreamConstructor
OutputStream out = new FileOutputStream(outFile);
@@ -470,6 +466,24 @@ public String getUserNotification() {
return notification;
}
+ synchronized public void removeMapDatabase() {
+ // close databases
+ if (mHillshadeHelper != null) {
+ mHillshadeHelper.close();
+ mHillshadeHelper = null;
+ mHillshadeDatabase = null;
+ }
+ if (mDetailedMapHelper != null) {
+ mDetailedMapHelper.close();
+ mDetailedMapHelper = null;
+ mDetailedMapDatabase = null;
+ }
+ File dbFile = new File(getExternalFilesDir("native"), Index.WORLDMAP_FILENAME);
+ logger.info("Detailed map database deleted: {}", dbFile.delete());
+ File hsFile = new File(getExternalFilesDir("native"), Index.HILLSHADE_FILENAME);
+ logger.info("Hillshade database deleted: {}", hsFile.delete());
+ }
+
synchronized public void optionallyCloseMapDatabase(UUID id) {
WorkManager workManager = WorkManager.getInstance(this);
ListenableFuture> workInfos = workManager.getWorkInfosByTag(MapWorker.TAG);
diff --git a/app/src/main/java/mobi/maptrek/fragments/Settings.java b/app/src/main/java/mobi/maptrek/fragments/Settings.java
deleted file mode 100644
index 9f0d29fd..00000000
--- a/app/src/main/java/mobi/maptrek/fragments/Settings.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2022 Andrey Novikov
- *
- * This program is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License along with
- * this program. If not, see .
- *
- */
-
-package mobi.maptrek.fragments;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.view.View;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceFragmentCompat;
-import androidx.preference.PreferenceGroup;
-import androidx.preference.PreferenceScreen;
-
-import org.greenrobot.eventbus.EventBus;
-
-import mobi.maptrek.Configuration;
-import mobi.maptrek.R;
-
-@SuppressWarnings({"unused", "CommentedOutCode"})
-public class Settings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
- private FragmentHolder mFragmentHolder;
-
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- addPreferencesFromResource(R.xml.preferences);
-
- /*
- Preference sdcardPref = findPreference("move_data");
- sdcardPref.setOnPreferenceClickListener(preference -> {
- mFragmentHolder.popCurrent();
- return false;
- });
-
- Preference resetPref = findPreference("reset_advices");
- resetPref.setOnPreferenceClickListener(preference -> {
- mFragmentHolder.popCurrent();
- return false;
- });
- */
-
- SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
- if (sharedPreferences != null)
- sharedPreferences.registerOnSharedPreferenceChangeListener(this);
- }
-
- @Override
- public void onAttach(@NonNull Context context) {
- super.onAttach(context);
- try {
- mFragmentHolder = (FragmentHolder) context;
- } catch (ClassCastException e) {
- throw new ClassCastException(context + " must implement FragmentHolder");
- }
- }
-
- @Override
- public void onDetach() {
- super.onDetach();
- mFragmentHolder = null;
- }
-
- @Override
- public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
- PreferenceScreen preferenceScreen = getPreferenceScreen();
- for (int i = 0; i < preferenceScreen.getPreferenceCount(); i++) {
- Preference preference = preferenceScreen.getPreference(i);
- if (preference instanceof PreferenceGroup) {
- PreferenceGroup preferenceGroup = (PreferenceGroup) preference;
- for (int j = 0; j < preferenceGroup.getPreferenceCount(); j++) {
- Preference subPref = preferenceGroup.getPreference(j);
- updatePreference(subPref, subPref.getKey());
- }
- } else {
- updatePreference(preference, preference.getKey());
- }
- }
- }
-
- @Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- EventBus.getDefault().post(new Configuration.ChangedEvent(key));
- updatePreference(findPreference(key), key);
- }
-
- private void updatePreference(Preference preference, String key) {
- if (preference == null) return;
- if (preference instanceof ListPreference) {
- ListPreference listPreference = (ListPreference) preference;
- listPreference.setSummary(listPreference.getEntry());
- //return;
- }
- // SharedPreferences sharedPrefs = getPreferenceManager().getSharedPreferences();
- // preference.setSummary(sharedPrefs.getString(key, "Default"));
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/mobi/maptrek/fragments/preferences/Advanced.java b/app/src/main/java/mobi/maptrek/fragments/preferences/Advanced.java
new file mode 100644
index 00000000..cceeedfb
--- /dev/null
+++ b/app/src/main/java/mobi/maptrek/fragments/preferences/Advanced.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2024 Andrey Novikov
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along with
+ * this program. If not, see .
+ *
+ */
+
+package mobi.maptrek.fragments.preferences;
+
+import android.os.Bundle;
+import android.widget.TextView;
+
+import androidx.annotation.Nullable;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.preference.Preference;
+
+import com.google.android.material.snackbar.BaseTransientBottomBar;
+import com.google.android.material.snackbar.Snackbar;
+
+import mobi.maptrek.Configuration;
+import mobi.maptrek.MainActivity;
+import mobi.maptrek.MapTrek;
+import mobi.maptrek.R;
+
+public class Advanced extends BasePreferences {
+ @Override
+ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
+ addPreferencesFromResource(R.xml.preferences_advanced);
+
+ Preference purgeMaps = findPreference("purge_maps");
+ if (purgeMaps != null)
+ purgeMaps.setOnPreferenceClickListener(preference -> {
+ CoordinatorLayout coordinatorLayout = ((MainActivity) requireActivity()).getCoordinatorLayout();
+ Snackbar snackbar = Snackbar.make(coordinatorLayout, R.string.msgPurgeMaps, Snackbar.LENGTH_LONG)
+ .setAnchorView(getView())
+ .addCallback(new BaseTransientBottomBar.BaseCallback() {
+ public void onDismissed(Snackbar snackbar, @DismissEvent int event) {
+ super.onDismissed(snackbar, event);
+ if (event == DISMISS_EVENT_ACTION)
+ return;
+ requireActivity().finish();
+ MapTrek.getApplication().removeMapDatabase();
+ MapTrek.getApplication().restart();
+ }
+ })
+ .setAction(R.string.actionUndo, view -> {
+ // do nothing, we just do not precede with destructive operation
+ });
+ TextView snackbarTextView = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
+ snackbarTextView.setMaxLines(99);
+ snackbar.show();
+ return true;
+ });
+
+ Preference resetMap = findPreference("reset_map");
+ if (resetMap != null)
+ resetMap.setOnPreferenceClickListener(preference -> {
+ CoordinatorLayout coordinatorLayout = ((MainActivity) requireActivity()).getCoordinatorLayout();
+ Snackbar snackbar = Snackbar.make(coordinatorLayout, R.string.msgMapReset, Snackbar.LENGTH_LONG)
+ .setAnchorView(getView())
+ .addCallback(new BaseTransientBottomBar.BaseCallback() {
+ public void onDismissed(Snackbar snackbar, @DismissEvent int event) {
+ super.onDismissed(snackbar, event);
+ if (event == DISMISS_EVENT_ACTION)
+ return;
+ Configuration.resetMapState();
+ MapTrek.getApplication().restart();
+ }
+ })
+ .setAction(R.string.actionUndo, view -> {
+ // do nothing, we just do not precede with destructive operation
+ });
+ TextView snackbarTextView = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
+ snackbarTextView.setMaxLines(99);
+ snackbar.show();
+ return true;
+ });
+
+ Preference resetAdvices = findPreference("reset_advices");
+ if (resetAdvices != null)
+ resetAdvices.setOnPreferenceClickListener(preference -> {
+ Configuration.resetAdviceState();
+ CoordinatorLayout coordinatorLayout = ((MainActivity) requireActivity()).getCoordinatorLayout();
+ Snackbar.make(coordinatorLayout, R.string.msgAdvicesReset, Snackbar.LENGTH_LONG)
+ .setAnchorView(getView())
+ .show();
+ return true;
+ });
+ }
+}
diff --git a/app/src/main/java/mobi/maptrek/fragments/preferences/BasePreferences.java b/app/src/main/java/mobi/maptrek/fragments/preferences/BasePreferences.java
index 2fa91995..df150b26 100644
--- a/app/src/main/java/mobi/maptrek/fragments/preferences/BasePreferences.java
+++ b/app/src/main/java/mobi/maptrek/fragments/preferences/BasePreferences.java
@@ -56,7 +56,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
addPreferencesFromResource(R.xml.preferences);
- Preference rate = (Preference) findPreference("preferences_rate");
+ Preference rate = (Preference) findPreference("rate");
if (rate != null) {
if (Configuration.ratingActionPerformed() || (Configuration.getRunningTime() < 240)) {
getPreferenceScreen().removePreference(rate);
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index fd6f7322..95bab7d3 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -10,16 +10,21 @@
android:fragment="mobi.maptrek.fragments.preferences.Units"
android:key="preferences_units"
android:title="@string/pref_units"
+ app:iconSpaceReserved="false" />
+
\ No newline at end of file
diff --git a/app/src/main/res/xml/preferences_advanced.xml b/app/src/main/res/xml/preferences_advanced.xml
new file mode 100644
index 00000000..595aef2f
--- /dev/null
+++ b/app/src/main/res/xml/preferences_advanced.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file