forked from organicmaps/organicmaps
Moved location state variable from MWMApplication to singleton.
This commit is contained in:
parent
ba13861718
commit
545b3b81b7
9 changed files with 39 additions and 68 deletions
|
@ -57,7 +57,6 @@ public class DownloadResourcesActivity extends MapsWithMeBaseFragmentActivity
|
|||
private ProgressBar mProgress = null;
|
||||
private Button mButton = null;
|
||||
private CheckBox mDownloadCountryCheckBox = null;
|
||||
private LocationService mLocationService = null;
|
||||
private Index mCountryIndex = null;
|
||||
|
||||
private MapTask mMapTaskToForward;
|
||||
|
@ -181,8 +180,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseFragmentActivity
|
|||
mBtnNames[PROCEED_TO_MAP] = getString(R.string.download_resources_continue);
|
||||
|
||||
// Start listening the location.
|
||||
mLocationService = mApplication.getLocationService();
|
||||
mLocationService.startUpdate(this);
|
||||
LocationService.INSTANCE.startUpdate(this);
|
||||
}
|
||||
|
||||
private void setAction(int action)
|
||||
|
@ -503,11 +501,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseFragmentActivity
|
|||
{
|
||||
super.onDestroy();
|
||||
|
||||
if (mLocationService != null)
|
||||
{
|
||||
mLocationService.stopUpdate(this);
|
||||
mLocationService = null;
|
||||
}
|
||||
LocationService.INSTANCE.stopUpdate(this);
|
||||
|
||||
if (mMapStorage != null)
|
||||
mMapStorage.unsubscribe(mSlotId);
|
||||
|
@ -518,8 +512,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseFragmentActivity
|
|||
{
|
||||
super.onPause();
|
||||
|
||||
if (mLocationService != null)
|
||||
mLocationService.stopUpdate(this);
|
||||
LocationService.INSTANCE.stopUpdate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -527,8 +520,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseFragmentActivity
|
|||
{
|
||||
super.onResume();
|
||||
|
||||
if (mLocationService != null)
|
||||
mLocationService.startUpdate(this);
|
||||
LocationService.INSTANCE.startUpdate(this);
|
||||
}
|
||||
|
||||
public void onDownloadProgress(int currentTotal, int currentProgress, int globalTotal, int globalProgress)
|
||||
|
@ -591,8 +583,7 @@ public class DownloadResourcesActivity extends MapsWithMeBaseFragmentActivity
|
|||
checkBox.setText(checkBoxText);
|
||||
}
|
||||
|
||||
mLocationService.stopUpdate(this);
|
||||
mLocationService = null;
|
||||
LocationService.INSTANCE.stopUpdate(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,14 +149,14 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
|
||||
private void pauseLocation()
|
||||
{
|
||||
MWMApplication.get().getLocationService().stopUpdate(this);
|
||||
LocationService.INSTANCE.stopUpdate(this);
|
||||
// Enable automatic turning screen off while app is idle
|
||||
Utils.automaticIdleScreen(true, getWindow());
|
||||
}
|
||||
|
||||
private void resumeLocation()
|
||||
{
|
||||
MWMApplication.get().getLocationService().startUpdate(this);
|
||||
LocationService.INSTANCE.startUpdate(this);
|
||||
// Do not turn off the screen while displaying position
|
||||
Utils.automaticIdleScreen(false, getWindow());
|
||||
}
|
||||
|
@ -456,7 +456,7 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
}
|
||||
else
|
||||
{
|
||||
final Location l = MWMApplication.get().getLocationService().getLastKnown();
|
||||
final Location l = LocationService.INSTANCE.getLastKnown();
|
||||
if (l != null && nativeIsInChina(l.getLatitude(), l.getLongitude()))
|
||||
return true;
|
||||
else
|
||||
|
@ -636,7 +636,7 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
|
||||
private void shareMyLocation()
|
||||
{
|
||||
final Location loc = MWMApplication.get().getLocationService().getLastKnown();
|
||||
final Location loc = LocationService.INSTANCE.getLastKnown();
|
||||
if (loc != null)
|
||||
{
|
||||
final String geoUrl = Framework.nativeGetGe0Url(loc.getLatitude(), loc.getLongitude(), Framework.getDrawScale(), "");
|
||||
|
@ -704,8 +704,9 @@ public class MWMActivity extends NvEventQueueActivity
|
|||
// because of bug in OS: https://code.google.com/p/android/issues/detail?id=38629
|
||||
addTask(intent);
|
||||
|
||||
// TODO test if initialization here is needed
|
||||
// Initialize location service
|
||||
MWMApplication.get().getLocationService();
|
||||
// LocationService.INSTANCE;
|
||||
|
||||
mSearchController = SearchController.getInstance();
|
||||
mSearchController.onCreate(this);
|
||||
|
|
|
@ -17,7 +17,6 @@ import com.mapswithme.maps.background.WorkerService;
|
|||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.guides.GuideInfo;
|
||||
import com.mapswithme.maps.guides.GuidesUtils;
|
||||
import com.mapswithme.maps.location.LocationService;
|
||||
import com.mapswithme.util.Constants;
|
||||
import com.mapswithme.util.FbUtil;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
@ -36,7 +35,6 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
|
||||
private static MWMApplication mSelf;
|
||||
|
||||
private LocationService mLocation = null;
|
||||
private LocationState mLocationState = null;
|
||||
private MapStorage mStorage = null;
|
||||
|
||||
|
@ -145,14 +143,6 @@ public class MWMApplication extends android.app.Application implements MapStorag
|
|||
WorkerService.startActionUpdateAds(this);
|
||||
}
|
||||
|
||||
public LocationService getLocationService()
|
||||
{
|
||||
if (mLocation == null)
|
||||
mLocation = new LocationService(this);
|
||||
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
public LocationState getLocationState()
|
||||
{
|
||||
if (mLocationState == null)
|
||||
|
|
|
@ -64,7 +64,6 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
// Handle voice recognition here
|
||||
private final static int RC_VOICE_RECOGNITION = 0xCA11;
|
||||
private static String TAG = "SearchActivity";
|
||||
private LocationService mLocation;
|
||||
// Search views
|
||||
private EditText mSearchEt;
|
||||
private ProgressBar mSearchProgress;
|
||||
|
@ -170,7 +169,7 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
// If now position detected or no country downloaded for position.
|
||||
if (mContext.mSearchMode != IN_VIEWPORT)
|
||||
{
|
||||
final Location loc = mContext.mLocation.getLastKnown();
|
||||
final Location loc = LocationService.INSTANCE.getLastKnown();
|
||||
if (loc == null)
|
||||
{
|
||||
return mContext.getString(R.string.unknown_current_position);
|
||||
|
@ -543,8 +542,6 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
actionBar.hide();
|
||||
}
|
||||
|
||||
mLocation = ((MWMApplication) getApplication()).getLocationService();
|
||||
|
||||
setContentView(R.layout.search_list_view);
|
||||
setUpView();
|
||||
// Create search list view adapter.
|
||||
|
@ -663,7 +660,7 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
mFlags = 0;
|
||||
mNorth = -1.0;
|
||||
|
||||
mLocation.startUpdate(this);
|
||||
LocationService.INSTANCE.startUpdate(this);
|
||||
|
||||
// do the search immediately after resume
|
||||
Utils.setTextAndCursorToEnd(mSearchEt, getLastQuery());
|
||||
|
@ -673,7 +670,7 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati
|
|||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
mLocation.stopUpdate(this);
|
||||
LocationService.INSTANCE.stopUpdate(this);
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
|
|
@ -106,9 +106,7 @@ public class BookmarkListActivity extends MapsWithMeBaseListActivity
|
|||
|
||||
private void createListAdapter()
|
||||
{
|
||||
mPinAdapter = new BookmarkListAdapter(this,
|
||||
((MWMApplication) getApplication()).getLocationService(),
|
||||
mEditedSet);
|
||||
mPinAdapter = new BookmarkListAdapter(this, mEditedSet);
|
||||
|
||||
setListAdapter(mPinAdapter);
|
||||
|
||||
|
|
|
@ -30,27 +30,24 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
{
|
||||
private final Activity mContext;
|
||||
private final BookmarkCategory mCategory;
|
||||
private final LocationService mLocation;
|
||||
|
||||
// reuse drawables
|
||||
private final Map<String, Drawable> mBmkToCircle = new HashMap<String, Drawable>(8);
|
||||
|
||||
public BookmarkListAdapter(Activity context, LocationService location,
|
||||
BookmarkCategory cat)
|
||||
public BookmarkListAdapter(Activity context, BookmarkCategory cat)
|
||||
{
|
||||
mContext = context;
|
||||
mLocation = location;
|
||||
mCategory = cat;
|
||||
}
|
||||
|
||||
public void startLocationUpdate()
|
||||
{
|
||||
mLocation.startUpdate(this);
|
||||
LocationService.INSTANCE.startUpdate(this);
|
||||
}
|
||||
|
||||
public void stopLocationUpdate()
|
||||
{
|
||||
mLocation.stopUpdate(this);
|
||||
LocationService.INSTANCE.stopUpdate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -196,7 +193,7 @@ public class BookmarkListAdapter extends BaseAdapter
|
|||
|
||||
void setDistance(Bookmark bmk)
|
||||
{
|
||||
final Location loc = mLocation.getLastKnown();
|
||||
final Location loc = LocationService.INSTANCE.getLastKnown();
|
||||
if (loc != null)
|
||||
{
|
||||
final DistanceAndAzimut daa = bmk.getDistanceAndAzimut(loc.getLatitude(), loc.getLongitude(), 0.0);
|
||||
|
|
|
@ -31,13 +31,13 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class LocationService implements
|
||||
public enum LocationService implements
|
||||
android.location.LocationListener, SensorEventListener, WifiLocationScanner.Listener,
|
||||
com.google.android.gms.location.LocationListener
|
||||
{
|
||||
private static final String TAG = LocationService.class.getName();
|
||||
private final Logger mLogger = SimpleLogger.get(TAG);
|
||||
INSTANCE;
|
||||
|
||||
private final Logger mLogger;
|
||||
|
||||
private static final double DEFAULT_SPEED_MPS = 5;
|
||||
private static final float DISTANCE_TO_RECREATE_MAGNETIC_FIELD_M = 1000;
|
||||
|
@ -76,8 +76,6 @@ public class LocationService implements
|
|||
private GeomagneticField mMagneticField = null;
|
||||
private LocationProvider mLocationProvider;
|
||||
|
||||
private MWMApplication mApplication = null;
|
||||
|
||||
private double mLastNorth;
|
||||
private static final double NOISE_THRESHOLD = 3;
|
||||
|
||||
|
@ -87,14 +85,13 @@ public class LocationService implements
|
|||
private final float[] mI = new float[9];
|
||||
private final float[] mOrientation = new float[3];
|
||||
|
||||
public LocationService(MWMApplication application)
|
||||
private LocationService()
|
||||
{
|
||||
mApplication = application;
|
||||
|
||||
mLogger = SimpleLogger.get(LocationService.class.getName());
|
||||
createLocationProvider();
|
||||
mLocationProvider.setUp();
|
||||
|
||||
mSensorManager = (SensorManager) mApplication.getSystemService(Context.SENSOR_SERVICE);
|
||||
mSensorManager = (SensorManager) MWMApplication.get().getSystemService(Context.SENSOR_SERVICE);
|
||||
if (mSensorManager != null)
|
||||
{
|
||||
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
|
||||
|
@ -121,15 +118,14 @@ public class LocationService implements
|
|||
{
|
||||
final int mode = Settings.Secure.getInt(resolver, Settings.Secure.LOCATION_MODE);
|
||||
isLocationTurnedOn = mode != Settings.Secure.LOCATION_MODE_OFF;
|
||||
}
|
||||
catch (Settings.SettingNotFoundException e)
|
||||
} catch (Settings.SettingNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (isLocationTurnedOn &&
|
||||
GooglePlayServicesUtil.isGooglePlayServicesAvailable(mApplication) == ConnectionResult.SUCCESS)
|
||||
GooglePlayServicesUtil.isGooglePlayServicesAvailable(MWMApplication.get().get()) == ConnectionResult.SUCCESS)
|
||||
{
|
||||
mLogger.d("Use fused provider.");
|
||||
mLocationProvider = new GoogleFusedLocationProvider();
|
||||
|
@ -180,19 +176,19 @@ public class LocationService implements
|
|||
private void startWifiLocationUpdate()
|
||||
{
|
||||
if (Statistics.INSTANCE.isStatisticsEnabled() &&
|
||||
ConnectionState.isWifiConnected(mApplication))
|
||||
ConnectionState.isWifiConnected(MWMApplication.get()))
|
||||
{
|
||||
if (mWifiScanner == null)
|
||||
mWifiScanner = new WifiLocationScanner();
|
||||
|
||||
mWifiScanner.startScan(mApplication, this);
|
||||
mWifiScanner.startScan(MWMApplication.get(), this);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopWifiLocationUpdate()
|
||||
{
|
||||
if (mWifiScanner != null)
|
||||
mWifiScanner.stopScan(mApplication);
|
||||
mWifiScanner.stopScan(MWMApplication.get());
|
||||
mWifiScanner = null;
|
||||
}
|
||||
|
||||
|
@ -472,7 +468,7 @@ public class LocationService implements
|
|||
@Override
|
||||
protected void setUp()
|
||||
{
|
||||
mLocationManager = (LocationManager) mApplication.getSystemService(Context.LOCATION_SERVICE);
|
||||
mLocationManager = (LocationManager) MWMApplication.get().getSystemService(Context.LOCATION_SERVICE);
|
||||
}
|
||||
|
||||
private Location findBestNotExpiredLocation(List<String> providers)
|
||||
|
@ -509,7 +505,7 @@ public class LocationService implements
|
|||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB &&
|
||||
LocationManager.NETWORK_PROVIDER.equals(prov) &&
|
||||
!ConnectionState.isConnected(mApplication))
|
||||
!ConnectionState.isConnected(MWMApplication.get()))
|
||||
continue;
|
||||
|
||||
acceptedProviders.add(prov);
|
||||
|
@ -534,7 +530,7 @@ public class LocationService implements
|
|||
@Override
|
||||
protected void setUp()
|
||||
{
|
||||
mLocationClient = new LocationClient(mApplication, this, this);
|
||||
mLocationClient = new LocationClient(MWMApplication.get(), this, this);
|
||||
|
||||
mLocationRequest = LocationRequest.create();
|
||||
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||
|
|
|
@ -52,6 +52,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.util.ShareAction;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.UiUtils.SimpleAnimationListener;
|
||||
|
@ -516,7 +517,7 @@ public class MapInfoView extends LinearLayout implements View.OnClickListener
|
|||
mTvLon = (TextView) mGeoLayout.findViewById(R.id.info_box_lon);
|
||||
mTvLon.setOnClickListener(this);
|
||||
|
||||
final Location lastKnown = MWMApplication.get().getLocationService().getLastKnown();
|
||||
final Location lastKnown = LocationService.INSTANCE.getLastKnown();
|
||||
updateLocation(lastKnown);
|
||||
|
||||
updateCoords();
|
||||
|
@ -579,7 +580,7 @@ public class MapInfoView extends LinearLayout implements View.OnClickListener
|
|||
{
|
||||
if (mGeoLayout != null && mMapObject != null && mMapObject.getType() != MapObjectType.MY_POSITION)
|
||||
{
|
||||
final Location l = MWMApplication.get().getLocationService().getLastKnown();
|
||||
final Location l = LocationService.INSTANCE.getLastKnown();
|
||||
if (l != null)
|
||||
{
|
||||
final DistanceAndAzimut da = Framework.nativeGetDistanceAndAzimutFromLatLon(
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.location.Location;
|
|||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mapswithme.maps.MWMApplication;
|
||||
import com.mapswithme.maps.location.LocationService;
|
||||
|
||||
public class Yota
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ public class Yota
|
|||
|
||||
if (addLastKnow)
|
||||
{
|
||||
final Location lastLocation = MWMApplication.get().getLocationService().getLastKnown();
|
||||
final Location lastLocation = LocationService.INSTANCE.getLastKnown();
|
||||
if (lastLocation != null)
|
||||
{
|
||||
i.putExtra(EXTRA_HAS_LOCATION, true)
|
||||
|
|
Loading…
Add table
Reference in a new issue