forked from organicmaps/organicmaps
[android] Remove usage of MwmApplication.backgroundTracker.
This commit is contained in:
parent
145e8cb10e
commit
e431935e65
9 changed files with 67 additions and 54 deletions
|
@ -2313,7 +2313,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
mNavigationController.stop(this);
|
||||
updateSearchBar();
|
||||
ThemeSwitcher.restart(isMapRendererActive());
|
||||
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
|
||||
if (mRoutingPlanInplaceController == null)
|
||||
return;
|
||||
|
||||
|
@ -2323,7 +2323,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void onNavigationStarted()
|
||||
{
|
||||
ThemeSwitcher.restart(isMapRendererActive());
|
||||
ThemeSwitcher.INSTANCE.restart(isMapRendererActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -130,16 +130,6 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
return (MwmApplication) context.getApplicationContext();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Use {@link #backgroundTracker(Context)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static AppBackgroundTracker backgroundTracker()
|
||||
{
|
||||
return sSelf.mBackgroundTracker;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static AppBackgroundTracker backgroundTracker(@NonNull Context context)
|
||||
{
|
||||
|
@ -271,11 +261,12 @@ public class MwmApplication extends Application implements AppBackgroundTracker.
|
|||
MapManager.nativeSubscribe(mStorageCallbacks);
|
||||
|
||||
initNativeStrings();
|
||||
ThemeSwitcher.INSTANCE.initialize(this);
|
||||
SearchEngine.INSTANCE.initialize(null);
|
||||
BookmarkManager.loadBookmarks();
|
||||
TtsPlayer.INSTANCE.initialize(this);
|
||||
ThemeSwitcher.restart(false);
|
||||
LocationHelper.INSTANCE.initialize(null);
|
||||
ThemeSwitcher.INSTANCE.restart(false);
|
||||
LocationHelper.INSTANCE.initialize(this);
|
||||
RoutingController.get().initialize(null);
|
||||
TrafficManager.INSTANCE.initialize(null);
|
||||
SubwayManager.from(this).initialize(null);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.mapswithme.maps.location;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.util.LocationUtils;
|
||||
|
||||
|
@ -10,9 +12,9 @@ public final class CompassData
|
|||
{
|
||||
private double mNorth;
|
||||
|
||||
public void update(double north)
|
||||
public void update(@NonNull Context context, double north)
|
||||
{
|
||||
Activity top = MwmApplication.backgroundTracker().getTopActivity();
|
||||
Activity top = MwmApplication.backgroundTracker(context).getTopActivity();
|
||||
if (top == null)
|
||||
return;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.location;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -22,7 +23,7 @@ import com.mapswithme.util.Utils;
|
|||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
public enum LocationHelper implements Initializable<Void>
|
||||
public enum LocationHelper implements Initializable<Context>
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
|
@ -42,6 +43,10 @@ public enum LocationHelper implements Initializable<Void>
|
|||
private static final long INTERVAL_NAVIGATION_BICYCLE_MS = 1000;
|
||||
private static final long INTERVAL_NAVIGATION_PEDESTRIAN_MS = 1000;
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private Context mContext;
|
||||
|
||||
@NonNull
|
||||
private final TransitionListener mOnTransition = new TransitionListener();
|
||||
|
||||
|
@ -79,7 +84,7 @@ public enum LocationHelper implements Initializable<Void>
|
|||
if (mCompassData == null)
|
||||
mCompassData = new CompassData();
|
||||
|
||||
mCompassData.update(north);
|
||||
mCompassData.update(mContext, north);
|
||||
|
||||
if (mUiCallback != null)
|
||||
mUiCallback.onCompassUpdated(mCompassData);
|
||||
|
@ -144,24 +149,20 @@ public enum LocationHelper implements Initializable<Void>
|
|||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private final LocationState.LocationPendingTimeoutListener mLocationPendingTimeoutListener =
|
||||
new LocationState.LocationPendingTimeoutListener()
|
||||
{
|
||||
@Override
|
||||
public void onLocationPendingTimeout()
|
||||
{
|
||||
stop();
|
||||
if (LocationUtils.areLocationServicesTurnedOn())
|
||||
notifyLocationNotFound();
|
||||
}
|
||||
};
|
||||
() -> {
|
||||
stop();
|
||||
if (LocationUtils.areLocationServicesTurnedOn())
|
||||
notifyLocationNotFound();
|
||||
};
|
||||
|
||||
@Override
|
||||
public void initialize(@Nullable Void aVoid)
|
||||
public void initialize(@Nullable Context context)
|
||||
{
|
||||
mContext = context;
|
||||
initProvider();
|
||||
LocationState.nativeSetListener(mMyPositionModeListener);
|
||||
LocationState.nativeSetLocationPendingTimeoutListener(mLocationPendingTimeoutListener);
|
||||
MwmApplication.backgroundTracker().addListener(mOnTransition);
|
||||
MwmApplication.backgroundTracker(context).addListener(mOnTransition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -66,7 +66,7 @@ public enum TrackRecorder implements Initializable<Context>
|
|||
LOGGER.d(TAG, "Initialization of track recorder and setting the listener for track changes");
|
||||
mContext = context;
|
||||
|
||||
MwmApplication.backgroundTracker().addListener(foreground -> {
|
||||
MwmApplication.backgroundTracker(context).addListener(foreground -> {
|
||||
LOGGER.d(TAG, "Transit to foreground: " + foreground);
|
||||
|
||||
UiThread.cancelDelayedTasks(mStartupAwaitProc);
|
||||
|
@ -148,14 +148,14 @@ public enum TrackRecorder implements Initializable<Context>
|
|||
nativeSetDuration(hours);
|
||||
}
|
||||
|
||||
void onWakeAlarm(@NonNull Context context)
|
||||
void onWakeAlarm()
|
||||
{
|
||||
LOGGER.d(TAG, "onWakeAlarm(). Enabled: " + nativeIsEnabled());
|
||||
|
||||
UiThread.cancelDelayedTasks(mStartupAwaitProc);
|
||||
|
||||
if (nativeIsEnabled() && !MwmApplication.backgroundTracker().isForeground())
|
||||
TrackRecorderWakeService.start(context);
|
||||
if (nativeIsEnabled() && !MwmApplication.backgroundTracker(mContext).isForeground())
|
||||
TrackRecorderWakeService.start(mContext);
|
||||
else
|
||||
stop();
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ public enum TrackRecorder implements Initializable<Context>
|
|||
LOGGER.d(TAG, "onServiceStopped(): actually runs here");
|
||||
LocationHelper.INSTANCE.removeListener(mLocationListener);
|
||||
|
||||
if (!MwmApplication.backgroundTracker().isForeground())
|
||||
if (!MwmApplication.backgroundTracker(mContext).isForeground())
|
||||
restartAlarmIfEnabled();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ public class TrackRecorderWakeReceiver extends BroadcastReceiver
|
|||
+ !backgroundTracker(context).isForeground();
|
||||
LOGGER.i(TAG, msg);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
TrackRecorder.INSTANCE.onWakeAlarm(context);
|
||||
TrackRecorder.INSTANCE.onWakeAlarm();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TrackRecorderWakeService extends JobIntentService
|
|||
protected void onHandleWork(@NonNull Intent intent)
|
||||
{
|
||||
String msg = "onHandleIntent: " + intent + " app in background = "
|
||||
+ !MwmApplication.backgroundTracker().isForeground();
|
||||
+ !MwmApplication.backgroundTracker(getApplicationContext()).isForeground();
|
||||
LOGGER.i(TAG, msg);
|
||||
CrashlyticsUtils.log(Log.INFO, TAG, msg);
|
||||
|
||||
|
|
|
@ -856,7 +856,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
|
|||
if (!Config.setUiThemeSettings(themeName))
|
||||
return true;
|
||||
|
||||
ThemeSwitcher.restart(false);
|
||||
ThemeSwitcher.INSTANCE.restart(false);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.Settings.MAP_STYLE,
|
||||
Statistics.params().add(Statistics.EventParam.NAME, themeName));
|
||||
ListPreference mapStyleModeList = (ListPreference) pref;
|
||||
|
|
|
@ -1,22 +1,27 @@
|
|||
package com.mapswithme.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.base.Initializable;
|
||||
import com.mapswithme.maps.downloader.DownloaderStatusIcon;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
|
||||
public final class ThemeSwitcher
|
||||
public enum ThemeSwitcher implements Initializable<Context>
|
||||
{
|
||||
private static final long CHECK_INTERVAL_MS = 30 * 60 * 1000;
|
||||
private static boolean sRendererActive = false;
|
||||
INSTANCE;
|
||||
|
||||
private static final Runnable AUTO_THEME_CHECKER = new Runnable()
|
||||
private static final long CHECK_INTERVAL_MS = 30 * 60 * 1000;
|
||||
private static boolean mRendererActive = false;
|
||||
|
||||
private final Runnable mAutoThemeChecker = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
|
@ -39,14 +44,28 @@ public final class ThemeSwitcher
|
|||
}
|
||||
|
||||
setThemeAndMapStyle(theme);
|
||||
UiThread.cancelDelayedTasks(AUTO_THEME_CHECKER);
|
||||
UiThread.cancelDelayedTasks(mAutoThemeChecker);
|
||||
|
||||
if (ThemeUtils.isAutoTheme())
|
||||
UiThread.runLater(AUTO_THEME_CHECKER, CHECK_INTERVAL_MS);
|
||||
UiThread.runLater(mAutoThemeChecker, CHECK_INTERVAL_MS);
|
||||
}
|
||||
};
|
||||
|
||||
private ThemeSwitcher() {}
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NonNull
|
||||
private Context mContext;
|
||||
|
||||
@Override
|
||||
public void initialize(@Nullable Context context)
|
||||
{
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
// No op.
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the UI theme of application and the map style if necessary. If the contract regarding
|
||||
|
@ -58,21 +77,21 @@ public final class ThemeSwitcher
|
|||
* at this moment, otherwise <code>false</code>.
|
||||
*/
|
||||
@androidx.annotation.UiThread
|
||||
public static void restart(boolean isRendererActive)
|
||||
public void restart(boolean isRendererActive)
|
||||
{
|
||||
sRendererActive = isRendererActive;
|
||||
mRendererActive = isRendererActive;
|
||||
String theme = Config.getUiThemeSettings();
|
||||
if (ThemeUtils.isAutoTheme(theme))
|
||||
{
|
||||
AUTO_THEME_CHECKER.run();
|
||||
mAutoThemeChecker.run();
|
||||
return;
|
||||
}
|
||||
|
||||
UiThread.cancelDelayedTasks(AUTO_THEME_CHECKER);
|
||||
UiThread.cancelDelayedTasks(mAutoThemeChecker);
|
||||
setThemeAndMapStyle(theme);
|
||||
}
|
||||
|
||||
private static void setThemeAndMapStyle(@NonNull String theme)
|
||||
private void setThemeAndMapStyle(@NonNull String theme)
|
||||
{
|
||||
String oldTheme = Config.getCurrentUiTheme();
|
||||
Config.setCurrentUiTheme(theme);
|
||||
|
@ -80,7 +99,7 @@ public final class ThemeSwitcher
|
|||
}
|
||||
|
||||
@androidx.annotation.UiThread
|
||||
private static void changeMapStyle(@NonNull String newTheme, @NonNull String oldTheme)
|
||||
private void changeMapStyle(@NonNull String newTheme, @NonNull String oldTheme)
|
||||
{
|
||||
@Framework.MapStyle
|
||||
int style = RoutingController.get().isVehicleNavigation()
|
||||
|
@ -95,7 +114,7 @@ public final class ThemeSwitcher
|
|||
|
||||
DownloaderStatusIcon.clearCache();
|
||||
|
||||
Activity a = MwmApplication.backgroundTracker().getTopActivity();
|
||||
Activity a = MwmApplication.backgroundTracker(mContext).getTopActivity();
|
||||
if (a != null && !a.isFinishing())
|
||||
a.recreate();
|
||||
}
|
||||
|
@ -109,11 +128,11 @@ public final class ThemeSwitcher
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetMapStyle(@Framework.MapStyle int style)
|
||||
private void SetMapStyle(@Framework.MapStyle int style)
|
||||
{
|
||||
// If rendering is not active we can mark map style, because all graphics
|
||||
// will be recreated after rendering activation.
|
||||
if (sRendererActive)
|
||||
if (mRendererActive)
|
||||
Framework.nativeSetMapStyle(style);
|
||||
else
|
||||
Framework.nativeMarkMapStyle(style);
|
||||
|
|
Loading…
Add table
Reference in a new issue