forked from organicmaps/organicmaps
[android] Move to another pack classes, added registration and invalidate geofences (v1 - base cases)
This commit is contained in:
parent
b2c5210d8d
commit
5be2163312
7 changed files with 64 additions and 17 deletions
|
@ -569,10 +569,10 @@
|
|||
<service android:name="com.mapswithme.util.push.GcmInstanceIDListenerService"/>
|
||||
<service android:name="com.mapswithme.util.push.GcmMessageHandlerService"/>
|
||||
<service
|
||||
android:name="com.mapswithme.maps.scheduling.GeofenceTransitionsIntentService"
|
||||
android:name="com.mapswithme.maps.location.GeofenceTransitionsIntentService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
android:exported="true"/>
|
||||
<receiver android:name="com.mapswithme.maps.GeofenceReceiver"
|
||||
<receiver android:name="com.mapswithme.maps.location.GeofenceReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
</receiver>
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.mapswithme.maps;
|
|||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Location;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -19,6 +20,7 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
|||
import com.mapswithme.maps.downloader.CountryItem;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.editor.Editor;
|
||||
import com.mapswithme.maps.location.GeofenceLocation;
|
||||
import com.mapswithme.maps.location.GeofenceRegistry;
|
||||
import com.mapswithme.maps.location.GeofenceRegistryImpl;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
|
@ -69,8 +71,9 @@ public class MwmApplication extends Application
|
|||
private ConnectivityListener mConnectivityListener;
|
||||
@NonNull
|
||||
private final MapManager.StorageCallback mStorageCallbacks = new StorageCallbackImpl();
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private final AppBackgroundTracker.OnTransitionListener mBackgroundListener = new TransitionListener();
|
||||
private AppBackgroundTracker.OnTransitionListener mBackgroundListener;
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private ExternalLibrariesMediator mMediator;
|
||||
|
@ -150,6 +153,7 @@ public class MwmApplication extends Application
|
|||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
mBackgroundListener = new TransitionListener(this);
|
||||
LoggerFactory.INSTANCE.initialize(this);
|
||||
mLogger = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
mLogger.d(TAG, "Application is created");
|
||||
|
@ -400,6 +404,14 @@ public class MwmApplication extends Application
|
|||
|
||||
private static class TransitionListener implements AppBackgroundTracker.OnTransitionListener
|
||||
{
|
||||
@NonNull
|
||||
private final MwmApplication mApplication;
|
||||
|
||||
TransitionListener(@NonNull MwmApplication application)
|
||||
{
|
||||
mApplication = application;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransit(boolean foreground)
|
||||
{
|
||||
|
@ -408,6 +420,13 @@ public class MwmApplication extends Application
|
|||
Log.i(TAG, "The app goes to background. All logs are going to be zipped.");
|
||||
LoggerFactory.INSTANCE.zipLogs(null);
|
||||
}
|
||||
|
||||
Location lastKnownLocation = LocationHelper.INSTANCE.getLastKnownLocation();
|
||||
if (lastKnownLocation == null)
|
||||
return;
|
||||
GeofenceRegistry geofenceRegistry = mApplication.getGeofenceRegistry();
|
||||
geofenceRegistry.invalidateGeofences();
|
||||
geofenceRegistry.registryGeofences(GeofenceLocation.from(lastKnownLocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package com.mapswithme.maps.location;
|
||||
|
||||
import android.location.Location;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public class GeofenceLocation
|
||||
{
|
||||
private final double mLat;
|
||||
private final double mLon;
|
||||
private final int mRadiusInMeters;
|
||||
private final float mRadiusInMeters;
|
||||
|
||||
public GeofenceLocation(double lat, double lon, int radiusInMeters)
|
||||
private GeofenceLocation(double lat, double lon, float radiusInMeters)
|
||||
{
|
||||
mLat = lat;
|
||||
mLon = lon;
|
||||
|
@ -34,8 +37,14 @@ public class GeofenceLocation
|
|||
return mLon;
|
||||
}
|
||||
|
||||
public int getRadiusInMeters()
|
||||
public float getRadiusInMeters()
|
||||
{
|
||||
return mRadiusInMeters;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static GeofenceLocation from(@NonNull Location location)
|
||||
{
|
||||
return new GeofenceLocation(location.getLatitude(), location.getLongitude(), location.getAccuracy());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package com.mapswithme.maps;
|
||||
package com.mapswithme.maps.location;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.mapswithme.maps.scheduling.GeofenceTransitionsIntentService;
|
||||
|
||||
public class GeofenceReceiver extends BroadcastReceiver
|
||||
{
|
||||
@Override
|
|
@ -9,8 +9,8 @@ import com.google.android.gms.location.Geofence;
|
|||
import com.google.android.gms.location.GeofencingClient;
|
||||
import com.google.android.gms.location.GeofencingRequest;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.mapswithme.maps.GeofenceReceiver;
|
||||
import com.mapswithme.maps.LightFramework;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.geofence.GeoFenceFeature;
|
||||
import com.mapswithme.util.PermissionsUtils;
|
||||
|
||||
|
@ -70,6 +70,8 @@ public class GeofenceRegistryImpl implements GeofenceRegistry
|
|||
checkThread();
|
||||
checkPermission();
|
||||
|
||||
if (mGeofences.isEmpty())
|
||||
return;
|
||||
Iterator<GeofenceAndFeature> iterator = mGeofences.iterator();
|
||||
List<String> expiredGeofences = new ArrayList<>();
|
||||
while (iterator.hasNext())
|
||||
|
@ -142,6 +144,13 @@ public class GeofenceRegistryImpl implements GeofenceRegistry
|
|||
return geofences;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static GeofenceRegistry from(@NonNull Application application)
|
||||
{
|
||||
MwmApplication app = (MwmApplication) application;
|
||||
return app.getGeofenceRegistry();
|
||||
}
|
||||
|
||||
private static class GeofenceAndFeature
|
||||
{
|
||||
@NonNull
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.mapswithme.maps.scheduling;
|
||||
package com.mapswithme.maps.location;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
|
@ -10,8 +11,7 @@ import android.support.v4.app.JobIntentService;
|
|||
|
||||
import com.google.android.gms.location.Geofence;
|
||||
import com.google.android.gms.location.GeofencingEvent;
|
||||
import com.mapswithme.maps.LightFramework;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.scheduling.JobIdMap;
|
||||
|
||||
public class GeofenceTransitionsIntentService extends JobIntentService
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ public class GeofenceTransitionsIntentService extends JobIntentService
|
|||
if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER
|
||||
|| transitionType == Geofence.GEOFENCE_TRANSITION_EXIT)
|
||||
{
|
||||
mMainThreadHandler.post(new GeofencingEventTask(geofencingEvent));
|
||||
mMainThreadHandler.post(new GeofencingEventTask(getApplication(), geofencingEvent));
|
||||
// LightFramework.nativeLogLocalAdsEvent(1, /* myPlaceLat */, /* myPlaceLon */, /* locationProviderAccuracy */, , , );
|
||||
}
|
||||
}
|
||||
|
@ -40,11 +40,14 @@ public class GeofenceTransitionsIntentService extends JobIntentService
|
|||
|
||||
private static class GeofencingEventTask implements Runnable
|
||||
{
|
||||
@NonNull
|
||||
private final Application mApplication;
|
||||
@NonNull
|
||||
private final GeofencingEvent mGeofencingEvent;
|
||||
|
||||
GeofencingEventTask(@NonNull GeofencingEvent geofencingEvent)
|
||||
GeofencingEventTask(@NonNull Application application, @NonNull GeofencingEvent geofencingEvent)
|
||||
{
|
||||
mApplication = application;
|
||||
mGeofencingEvent = geofencingEvent;
|
||||
}
|
||||
|
||||
|
@ -52,8 +55,16 @@ public class GeofenceTransitionsIntentService extends JobIntentService
|
|||
public void run()
|
||||
{
|
||||
Location lastKnownLocation = LocationHelper.INSTANCE.getLastKnownLocation();
|
||||
double accuracy = lastKnownLocation == null ? mGeofencingEvent.getTriggeringLocation().getAccuracy()
|
||||
: lastKnownLocation.getAccuracy();
|
||||
Location currentLocation = lastKnownLocation == null ? mGeofencingEvent.getTriggeringLocation()
|
||||
: lastKnownLocation;
|
||||
|
||||
GeofenceRegistry geofenceRegistry = GeofenceRegistryImpl.from(mApplication);
|
||||
if (mGeofencingEvent.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_EXIT)
|
||||
{
|
||||
geofenceRegistry.invalidateGeofences();
|
||||
geofenceRegistry.registryGeofences(GeofenceLocation.from(currentLocation));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.mapswithme.maps.scheduling;
|
|||
import com.mapswithme.maps.background.NotificationService;
|
||||
import com.mapswithme.maps.background.WorkerService;
|
||||
import com.mapswithme.maps.bookmarks.SystemDownloadCompletedService;
|
||||
import com.mapswithme.maps.location.GeofenceTransitionsIntentService;
|
||||
import com.mapswithme.maps.location.TrackRecorderWakeService;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue