From afb05fd523c6aacd8b44265ba0cd2f843e842f08 Mon Sep 17 00:00:00 2001 From: Dmitry Yunitsky Date: Tue, 20 Jan 2015 16:42:18 +0300 Subject: [PATCH] Renamed LocationService to avoid confusing with android services. --- .../jni/com/mapswithme/maps/MWMActivity.cpp | 2 +- .../maps/DownloadResourcesActivity.java | 14 ++++++------- .../src/com/mapswithme/maps/MWMActivity.java | 20 +++++++++---------- .../maps/bookmarks/BookmarkListAdapter.java | 10 +++++----- .../maps/location/AndroidNativeProvider.java | 20 +++++++++---------- .../maps/location/BaseLocationProvider.java | 2 +- .../location/GoogleFusedLocationProvider.java | 12 +++++------ ...cationService.java => LocationHelper.java} | 8 ++++---- .../maps/location/LocationPredictor.java | 6 +++--- .../maps/search/SearchFragment.java | 9 ++++----- .../mapswithme/maps/widget/MapInfoView.java | 7 +++---- .../com/mapswithme/util/LocationUtils.java | 4 ++-- android/src/com/mapswithme/util/Yota.java | 4 ++-- 13 files changed, 58 insertions(+), 60 deletions(-) rename android/src/com/mapswithme/maps/location/{LocationService.java => LocationHelper.java} (97%) diff --git a/android/jni/com/mapswithme/maps/MWMActivity.cpp b/android/jni/com/mapswithme/maps/MWMActivity.cpp index 2c69774f04..35a888d06c 100644 --- a/android/jni/com/mapswithme/maps/MWMActivity.cpp +++ b/android/jni/com/mapswithme/maps/MWMActivity.cpp @@ -72,7 +72,7 @@ extern "C" #pragma clang pop_options JNIEXPORT jfloatArray JNICALL - Java_com_mapswithme_maps_location_LocationService_nativeUpdateCompassSensor( + Java_com_mapswithme_maps_location_LocationHelper_nativeUpdateCompassSensor( JNIEnv * env, jobject thiz, jint ind, jfloatArray arr) { int const count = 3; diff --git a/android/src/com/mapswithme/maps/DownloadResourcesActivity.java b/android/src/com/mapswithme/maps/DownloadResourcesActivity.java index 51fc634362..7fa863d1c4 100644 --- a/android/src/com/mapswithme/maps/DownloadResourcesActivity.java +++ b/android/src/com/mapswithme/maps/DownloadResourcesActivity.java @@ -22,7 +22,7 @@ import com.mapswithme.maps.MapStorage.Index; import com.mapswithme.maps.api.Const; import com.mapswithme.maps.api.ParsedMmwRequest; import com.mapswithme.maps.base.MWMFragmentActivity; -import com.mapswithme.maps.location.LocationService; +import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.ConnectionState; import com.mapswithme.util.Constants; import com.mapswithme.util.Utils; @@ -36,7 +36,7 @@ import java.io.OutputStream; @SuppressLint("StringFormatMatches") public class DownloadResourcesActivity extends MWMFragmentActivity - implements LocationService.LocationListener, MapStorage.Listener + implements LocationHelper.LocationListener, MapStorage.Listener { private static final String TAG = DownloadResourcesActivity.class.getName(); @@ -182,7 +182,7 @@ public class DownloadResourcesActivity extends MWMFragmentActivity mBtnNames[PROCEED_TO_MAP] = getString(R.string.download_resources_continue); // Start listening the location. - LocationService.INSTANCE.addLocationListener(this); + LocationHelper.INSTANCE.addLocationListener(this); } private void setAction(int action) @@ -481,7 +481,7 @@ public class DownloadResourcesActivity extends MWMFragmentActivity { super.onDestroy(); - LocationService.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(this); if (mMapStorage != null) mMapStorage.unsubscribe(mSlotId); @@ -492,7 +492,7 @@ public class DownloadResourcesActivity extends MWMFragmentActivity { super.onPause(); - LocationService.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(this); } @Override @@ -500,7 +500,7 @@ public class DownloadResourcesActivity extends MWMFragmentActivity { super.onResume(); - LocationService.INSTANCE.addLocationListener(this); + LocationHelper.INSTANCE.addLocationListener(this); } public void onDownloadProgress(int currentTotal, int currentProgress, int globalTotal, int globalProgress) @@ -563,7 +563,7 @@ public class DownloadResourcesActivity extends MWMFragmentActivity checkBox.setText(checkBoxText); } - LocationService.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(this); } } } diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index c1ba024fcd..f751eadb4e 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -60,8 +60,8 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.bookmarks.data.MapObject.ApiPoint; import com.mapswithme.maps.bookmarks.data.ParcelablePoint; +import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.maps.location.LocationPredictor; -import com.mapswithme.maps.location.LocationService; import com.mapswithme.maps.search.SearchActivity; import com.mapswithme.maps.search.SearchController; import com.mapswithme.maps.search.SearchFragment; @@ -94,7 +94,7 @@ import java.util.Stack; import java.util.concurrent.TimeUnit; public class MWMActivity extends NvEventQueueActivity - implements LocationService.LocationListener, OnBalloonListener, OnVisibilityChangedListener, + implements LocationHelper.LocationListener, OnBalloonListener, OnVisibilityChangedListener, OnClickListener, RoutingListener { public static final String EXTRA_TASK = "map_task"; @@ -194,14 +194,14 @@ public class MWMActivity extends NvEventQueueActivity private void pauseLocation() { - LocationService.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(this); // Enable automatic turning screen off while app is idle Utils.automaticIdleScreen(true, getWindow()); } private void listenLocationUpdates() { - LocationService.INSTANCE.addLocationListener(this); + LocationHelper.INSTANCE.addLocationListener(this); // Do not turn off the screen while displaying position Utils.automaticIdleScreen(false, getWindow()); } @@ -572,7 +572,7 @@ public class MWMActivity extends NvEventQueueActivity } else { - final Location l = LocationService.INSTANCE.getLastLocation(); + final Location l = LocationHelper.INSTANCE.getLastLocation(); if (l != null && nativeIsInChina(l.getLatitude(), l.getLongitude())) return true; else @@ -752,7 +752,7 @@ public class MWMActivity extends NvEventQueueActivity private void shareMyLocation() { - final Location loc = LocationService.INSTANCE.getLastLocation(); + final Location loc = LocationHelper.INSTANCE.getLastLocation(); if (loc != null) { final String geoUrl = Framework.nativeGetGe0Url(loc.getLatitude(), loc.getLongitude(), Framework.getDrawScale(), ""); @@ -1069,7 +1069,7 @@ public class MWMActivity extends NvEventQueueActivity nativeOnLocationError(errorCode); // Notify user about turned off location services - if (errorCode == LocationService.ERROR_DENIED) + if (errorCode == LocationHelper.ERROR_DENIED) { LocationState.INSTANCE.turnOff(); @@ -1113,7 +1113,7 @@ public class MWMActivity extends NvEventQueueActivity .show(); } } - else if (errorCode == LocationService.ERROR_GPS_OFF) + else if (errorCode == LocationHelper.ERROR_GPS_OFF) { Toast.makeText(this, R.string.gps_is_disabled_long_text, Toast.LENGTH_LONG).show(); } @@ -1122,7 +1122,7 @@ public class MWMActivity extends NvEventQueueActivity @Override public void onLocationUpdated(final Location l) { - if (!l.getProvider().equals(LocationService.LOCATION_PREDICTOR_PROVIDER)) + if (!l.getProvider().equals(LocationHelper.LOCATION_PREDICTOR_PROVIDER)) mLocationPredictor.reset(l); nativeLocationUpdated( @@ -1807,7 +1807,7 @@ public class MWMActivity extends NvEventQueueActivity @Override public void onClick(DialogInterface dialog, int which) { - final Location location = LocationService.INSTANCE.getLastLocation(); + final Location location = LocationHelper.INSTANCE.getLastLocation(); if (location != null) { final Index currentIndex = Framework.nativeGetCountryIndex(location.getLatitude(), location.getLongitude()); diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java index b6cd39fc41..baba719c90 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListAdapter.java @@ -16,7 +16,7 @@ import com.mapswithme.maps.bookmarks.data.Bookmark; import com.mapswithme.maps.bookmarks.data.BookmarkCategory; import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut; import com.mapswithme.maps.bookmarks.data.Track; -import com.mapswithme.maps.location.LocationService; +import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.UiUtils; import java.util.ArrayList; @@ -26,7 +26,7 @@ import java.util.Map; public class BookmarkListAdapter extends BaseAdapter - implements LocationService.LocationListener + implements LocationHelper.LocationListener { private final Activity mActivity; private final BookmarkCategory mCategory; @@ -42,12 +42,12 @@ public class BookmarkListAdapter extends BaseAdapter public void startLocationUpdate() { - LocationService.INSTANCE.addLocationListener(this); + LocationHelper.INSTANCE.addLocationListener(this); } public void stopLocationUpdate() { - LocationService.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(this); } @Override @@ -186,7 +186,7 @@ public class BookmarkListAdapter extends BaseAdapter void setDistance(Bookmark bmk) { - final Location loc = LocationService.INSTANCE.getLastLocation(); + final Location loc = LocationHelper.INSTANCE.getLastLocation(); if (loc != null) { final DistanceAndAzimut daa = bmk.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), 0.0); diff --git a/android/src/com/mapswithme/maps/location/AndroidNativeProvider.java b/android/src/com/mapswithme/maps/location/AndroidNativeProvider.java index 12446851d3..26e8d1fb43 100644 --- a/android/src/com/mapswithme/maps/location/AndroidNativeProvider.java +++ b/android/src/com/mapswithme/maps/location/AndroidNativeProvider.java @@ -29,26 +29,26 @@ public class AndroidNativeProvider extends BaseLocationProvider implements andro final List providers = getFilteredProviders(); if (providers.size() == 0) - LocationService.INSTANCE.notifyLocationError(LocationService.ERROR_DENIED); + LocationHelper.INSTANCE.notifyLocationError(LocationHelper.ERROR_DENIED); else { for (final String provider : providers) mLocationManager.requestLocationUpdates(provider, LOCATION_UPDATE_INTERVAL, 0, this); - LocationService.INSTANCE.registerSensorListeners(); + LocationHelper.INSTANCE.registerSensorListeners(); // Choose best location from available final Location newLocation = findBestNotExpiredLocation(providers); if (isLocationBetterThanLast(newLocation)) - LocationService.INSTANCE.setLastLocation(newLocation); + LocationHelper.INSTANCE.setLastLocation(newLocation); else { - final Location lastLocation = LocationService.INSTANCE.getLastLocation(); - if (lastLocation != null && !LocationUtils.isExpired(lastLocation, LocationService.INSTANCE.getLastLocationTime(), + final Location lastLocation = LocationHelper.INSTANCE.getLastLocation(); + if (lastLocation != null && !LocationUtils.isExpired(lastLocation, LocationHelper.INSTANCE.getLastLocationTime(), LocationUtils.LOCATION_EXPIRATION_TIME_MILLIS_SHORT)) - LocationService.INSTANCE.setLastLocation(lastLocation); + LocationHelper.INSTANCE.setLastLocation(lastLocation); else - LocationService.INSTANCE.setLastLocation(null); + LocationHelper.INSTANCE.setLastLocation(null); } } } @@ -87,7 +87,7 @@ public class AndroidNativeProvider extends BaseLocationProvider implements andro if (!mLocationManager.isProviderEnabled(prov)) { if (LocationManager.GPS_PROVIDER.equals(prov)) - LocationService.INSTANCE.notifyLocationError(LocationService.ERROR_GPS_OFF); + LocationHelper.INSTANCE.notifyLocationError(LocationHelper.ERROR_GPS_OFF); continue; } @@ -111,8 +111,8 @@ public class AndroidNativeProvider extends BaseLocationProvider implements andro if (isLocationBetterThanLast(l)) { - LocationService.INSTANCE.initMagneticField(l); - LocationService.INSTANCE.setLastLocation(l); + LocationHelper.INSTANCE.initMagneticField(l); + LocationHelper.INSTANCE.setLastLocation(l); } } diff --git a/android/src/com/mapswithme/maps/location/BaseLocationProvider.java b/android/src/com/mapswithme/maps/location/BaseLocationProvider.java index c613cbae1d..defbb8b8e4 100644 --- a/android/src/com/mapswithme/maps/location/BaseLocationProvider.java +++ b/android/src/com/mapswithme/maps/location/BaseLocationProvider.java @@ -24,7 +24,7 @@ public abstract class BaseLocationProvider if (newLocation == null) return false; - final Location lastLocation = LocationService.INSTANCE.getLastLocation(); + final Location lastLocation = LocationHelper.INSTANCE.getLastLocation(); if (lastLocation == null) return true; diff --git a/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java b/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java index 8b464ec485..9f83589452 100644 --- a/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java +++ b/android/src/com/mapswithme/maps/location/GoogleFusedLocationProvider.java @@ -58,7 +58,7 @@ public class GoogleFusedLocationProvider extends BaseLocationProvider if (newLocation == null) return false; - Location lastLocation = LocationService.INSTANCE.getLastLocation(); + Location lastLocation = LocationHelper.INSTANCE.getLastLocation(); if (lastLocation == null) return true; @@ -73,10 +73,10 @@ public class GoogleFusedLocationProvider extends BaseLocationProvider { mLogger.d("Fused onConnected. Bundle " + bundle); LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); - LocationService.INSTANCE.registerSensorListeners(); + LocationHelper.INSTANCE.registerSensorListeners(); final Location l = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); if (l != null) - LocationService.INSTANCE.setLastLocation(l); + LocationHelper.INSTANCE.setLastLocation(l); } @Override @@ -90,7 +90,7 @@ public class GoogleFusedLocationProvider extends BaseLocationProvider { mLogger.d("Fused onConnectionFailed. Fall back to native provider. ConnResult " + connectionResult); // TODO handle error in a smarter way - LocationService.INSTANCE.initLocationProvider(true); + LocationHelper.INSTANCE.initLocationProvider(true); } @Override @@ -102,8 +102,8 @@ public class GoogleFusedLocationProvider extends BaseLocationProvider if (isLocationBetterThanLast(location)) { - LocationService.INSTANCE.initMagneticField(location); - LocationService.INSTANCE.setLastLocation(location); + LocationHelper.INSTANCE.initMagneticField(location); + LocationHelper.INSTANCE.setLastLocation(location); } } } diff --git a/android/src/com/mapswithme/maps/location/LocationService.java b/android/src/com/mapswithme/maps/location/LocationHelper.java similarity index 97% rename from android/src/com/mapswithme/maps/location/LocationService.java rename to android/src/com/mapswithme/maps/location/LocationHelper.java index 8d5d43ce46..a497cfaaf6 100644 --- a/android/src/com/mapswithme/maps/location/LocationService.java +++ b/android/src/com/mapswithme/maps/location/LocationHelper.java @@ -23,7 +23,7 @@ import com.mapswithme.util.log.SimpleLogger; import java.util.HashSet; -public enum LocationService implements SensorEventListener +public enum LocationHelper implements SensorEventListener { INSTANCE; @@ -62,9 +62,9 @@ public enum LocationService implements SensorEventListener private final float[] mI = new float[9]; private final float[] mOrientation = new float[3]; - private LocationService() + private LocationHelper() { - mLogger = SimpleLogger.get(LocationService.class.getName()); + mLogger = SimpleLogger.get(LocationHelper.class.getName()); initLocationProvider(false); mSensorManager = (SensorManager) MWMApplication.get().getSystemService(Context.SENSOR_SERVICE); if (mSensorManager != null) @@ -163,7 +163,7 @@ public enum LocationService implements SensorEventListener // Reset current parameters to force initialize in the next addLocationListener mMagneticField = null; if (mSensorManager != null) - mSensorManager.unregisterListener(LocationService.this); + mSensorManager.unregisterListener(LocationHelper.this); } } diff --git a/android/src/com/mapswithme/maps/location/LocationPredictor.java b/android/src/com/mapswithme/maps/location/LocationPredictor.java index e43d3cb86c..92290c534b 100644 --- a/android/src/com/mapswithme/maps/location/LocationPredictor.java +++ b/android/src/com/mapswithme/maps/location/LocationPredictor.java @@ -14,14 +14,14 @@ public class LocationPredictor private Runnable mRunnable; private Handler mHandler; - private LocationService.LocationListener mListener; + private LocationHelper.LocationListener mListener; private Location mLastLocation; private boolean mGeneratePredictions; // TODO variable ISNT really changed anywhere. private int mPredictionCount; private int mConnectionSlot; - public LocationPredictor(Handler handler, LocationService.LocationListener listener) + public LocationPredictor(Handler handler, LocationHelper.LocationListener listener) { mHandler = handler; mListener = listener; @@ -57,7 +57,7 @@ public class LocationPredictor { mLastLocation = new Location(location); mLastLocation.setTime(System.currentTimeMillis()); - mLastLocation.setProvider(LocationService.LOCATION_PREDICTOR_PROVIDER); + mLastLocation.setProvider(LocationHelper.LOCATION_PREDICTOR_PROVIDER); } else mLastLocation = null; diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 5b9147aaa2..e963f06fa8 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -18,12 +18,11 @@ import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; -import com.mapswithme.maps.BuildConfig; import com.mapswithme.maps.MWMActivity; import com.mapswithme.maps.R; import com.mapswithme.maps.base.MWMListFragment; import com.mapswithme.maps.base.OnBackPressListener; -import com.mapswithme.maps.location.LocationService; +import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.InputUtils; import com.mapswithme.util.Language; import com.mapswithme.util.UiUtils; @@ -31,7 +30,7 @@ import com.mapswithme.util.Utils; import com.mapswithme.util.statistics.Statistics; -public class SearchFragment extends MWMListFragment implements View.OnClickListener, LocationService.LocationListener, OnBackPressListener +public class SearchFragment extends MWMListFragment implements View.OnClickListener, LocationHelper.LocationListener, OnBackPressListener { // These constants should be equal with // Java_com_mapswithme_maps_SearchActivity_nativeRunSearch routine. @@ -212,7 +211,7 @@ public class SearchFragment extends MWMListFragment implements View.OnClickListe mFlags = 0; mNorth = -1.0; - LocationService.INSTANCE.addLocationListener(this); + LocationHelper.INSTANCE.addLocationListener(this); // do the search immediately after resume Utils.setTextAndCursorToEnd(mSearchEt, getLastQuery()); @@ -222,7 +221,7 @@ public class SearchFragment extends MWMListFragment implements View.OnClickListe @Override public void onPause() { - LocationService.INSTANCE.removeLocationListener(this); + LocationHelper.INSTANCE.removeLocationListener(this); super.onPause(); } diff --git a/android/src/com/mapswithme/maps/widget/MapInfoView.java b/android/src/com/mapswithme/maps/widget/MapInfoView.java index 45aed1df3c..390cd45092 100644 --- a/android/src/com/mapswithme/maps/widget/MapInfoView.java +++ b/android/src/com/mapswithme/maps/widget/MapInfoView.java @@ -39,7 +39,6 @@ import android.widget.TextView; import android.widget.ToggleButton; import com.mapswithme.maps.Framework; -import com.mapswithme.maps.MWMApplication; import com.mapswithme.maps.R; import com.mapswithme.maps.api.ParsedMmwRequest; import com.mapswithme.maps.bookmarks.BookmarkActivity; @@ -52,7 +51,7 @@ import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.bookmarks.data.MapObject.MapObjectType; import com.mapswithme.maps.bookmarks.data.MapObject.Poi; import com.mapswithme.maps.bookmarks.data.MapObject.SearchResult; -import com.mapswithme.maps.location.LocationService; +import com.mapswithme.maps.location.LocationHelper; import com.mapswithme.util.ShareAction; import com.mapswithme.util.UiUtils; import com.mapswithme.util.UiUtils.SimpleAnimationListener; @@ -531,7 +530,7 @@ public class MapInfoView extends LinearLayout implements View.OnClickListener mTvLon = (TextView) mGeoLayout.findViewById(R.id.info_box_lon); mTvLon.setOnClickListener(this); - final Location lastKnown = LocationService.INSTANCE.getLastLocation(); + final Location lastKnown = LocationHelper.INSTANCE.getLastLocation(); updateLocation(lastKnown); updateCoords(); @@ -594,7 +593,7 @@ public class MapInfoView extends LinearLayout implements View.OnClickListener { if (mGeoLayout != null && mMapObject != null && mMapObject.getType() != MapObjectType.MY_POSITION) { - final Location l = LocationService.INSTANCE.getLastLocation(); + final Location l = LocationHelper.INSTANCE.getLastLocation(); if (l != null) { final DistanceAndAzimut da = Framework.nativeGetDistanceAndAzimutFromLatLon( diff --git a/android/src/com/mapswithme/util/LocationUtils.java b/android/src/com/mapswithme/util/LocationUtils.java index 0fe7802cda..189e047df0 100644 --- a/android/src/com/mapswithme/util/LocationUtils.java +++ b/android/src/com/mapswithme/util/LocationUtils.java @@ -5,7 +5,7 @@ import android.os.Build; import android.os.SystemClock; import android.view.Surface; -import com.mapswithme.maps.location.LocationService; +import com.mapswithme.maps.location.LocationHelper; public class LocationUtils { @@ -85,7 +85,7 @@ public class LocationUtils // Do compare current and previous system times in case when // we have incorrect time settings on a device. time = System.currentTimeMillis(); - lastTime = LocationService.INSTANCE.getLastLocationTime(); + lastTime = LocationHelper.INSTANCE.getLastLocationTime(); } return (time - lastTime) * 1.0E-3; diff --git a/android/src/com/mapswithme/util/Yota.java b/android/src/com/mapswithme/util/Yota.java index 9cdfb77dd6..30ecb7b546 100644 --- a/android/src/com/mapswithme/util/Yota.java +++ b/android/src/com/mapswithme/util/Yota.java @@ -6,7 +6,7 @@ import android.location.Location; import android.os.Build; import android.text.TextUtils; -import com.mapswithme.maps.location.LocationService; +import com.mapswithme.maps.location.LocationHelper; public class Yota { @@ -59,7 +59,7 @@ public class Yota if (addLastKnow) { - final Location lastLocation = LocationService.INSTANCE.getLastLocation(); + final Location lastLocation = LocationHelper.INSTANCE.getLastLocation(); if (lastLocation != null) { i.putExtra(EXTRA_HAS_LOCATION, true)