2016-08-29 12:50:41 +00:00
|
|
|
/**
|
|
|
|
* MainActivityFragment.java
|
|
|
|
* Implements the main fragment of the main activity
|
|
|
|
* This fragment displays a map using osmdroid
|
|
|
|
*
|
|
|
|
* This file is part of
|
|
|
|
* TRACKBOOK - Movement Recorder for Android
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 - Y20K.org
|
|
|
|
* Licensed under the MIT-License
|
|
|
|
* http://opensource.org/licenses/MIT
|
|
|
|
*
|
|
|
|
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
|
|
|
* https://github.com/osmdroid/osmdroid
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.y20k.trackbook;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2016-08-30 13:22:19 +00:00
|
|
|
import android.content.BroadcastReceiver;
|
2016-08-29 12:50:41 +00:00
|
|
|
import android.content.Context;
|
2016-08-30 13:22:19 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2016-08-29 12:50:41 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.location.Location;
|
|
|
|
import android.location.LocationListener;
|
|
|
|
import android.location.LocationManager;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.support.v4.app.Fragment;
|
2016-08-30 13:22:19 +00:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2016-08-29 12:50:41 +00:00
|
|
|
import android.util.DisplayMetrics;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import org.osmdroid.api.IMapController;
|
|
|
|
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
|
|
|
|
import org.osmdroid.util.GeoPoint;
|
|
|
|
import org.osmdroid.views.MapView;
|
|
|
|
import org.osmdroid.views.overlay.ItemizedIconOverlay;
|
|
|
|
import org.osmdroid.views.overlay.compass.CompassOverlay;
|
|
|
|
import org.osmdroid.views.overlay.compass.InternalCompassOrientationProvider;
|
2016-09-01 11:45:46 +00:00
|
|
|
import org.y20k.trackbook.core.Track;
|
2016-08-29 12:50:41 +00:00
|
|
|
import org.y20k.trackbook.helpers.LocationHelper;
|
|
|
|
import org.y20k.trackbook.helpers.LogHelper;
|
|
|
|
import org.y20k.trackbook.helpers.MapHelper;
|
|
|
|
import org.y20k.trackbook.helpers.TrackbookKeys;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MainActivityFragment class
|
|
|
|
*/
|
|
|
|
public class MainActivityFragment extends Fragment implements TrackbookKeys {
|
|
|
|
|
|
|
|
/* Define log tag */
|
|
|
|
private static final String LOG_TAG = MainActivityFragment.class.getSimpleName();
|
|
|
|
|
|
|
|
|
|
|
|
/* Main class variables */
|
|
|
|
private Activity mActivity;
|
2016-09-01 11:45:46 +00:00
|
|
|
private Track mTrack;
|
2016-08-30 13:22:19 +00:00
|
|
|
private boolean mFirstStart;
|
2016-09-01 11:45:46 +00:00
|
|
|
private BroadcastReceiver mTrackUpdatedReceiver;
|
2016-08-29 12:50:41 +00:00
|
|
|
private MapView mMapView;
|
|
|
|
private IMapController mController;
|
|
|
|
private LocationManager mLocationManager;
|
|
|
|
private LocationListener mGPSListener;
|
|
|
|
private LocationListener mNetworkListener;
|
|
|
|
private ItemizedIconOverlay mMyLocationOverlay;
|
2016-09-01 11:45:46 +00:00
|
|
|
private ItemizedIconOverlay mTrackOverlay;
|
2016-08-29 19:43:49 +00:00
|
|
|
private Location mCurrentBestLocation;
|
2016-09-06 15:27:04 +00:00
|
|
|
private boolean mTrackerServiceRunning;
|
|
|
|
private boolean mLocalTrackerRunning;
|
2016-08-29 12:50:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Constructor (default) */
|
|
|
|
public MainActivityFragment() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
// get activity
|
|
|
|
mActivity = getActivity();
|
|
|
|
|
|
|
|
// action bar has options menu
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
2016-08-30 13:22:19 +00:00
|
|
|
// restore first start state
|
|
|
|
mFirstStart = true;
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
mFirstStart = savedInstanceState.getBoolean(INSTANCE_FIRST_START, true);
|
|
|
|
}
|
|
|
|
|
2016-09-01 11:45:46 +00:00
|
|
|
// restore tracking state
|
2016-09-06 15:27:04 +00:00
|
|
|
mTrackerServiceRunning = false;
|
2016-09-01 11:45:46 +00:00
|
|
|
if (savedInstanceState != null) {
|
2016-09-06 15:27:04 +00:00
|
|
|
mTrackerServiceRunning = savedInstanceState.getBoolean(INSTANCE_TRACKING_STATE, false);
|
2016-09-01 11:45:46 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
// acquire reference to Location Manager
|
|
|
|
mLocationManager = (LocationManager) mActivity.getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
|
2016-08-29 19:43:49 +00:00
|
|
|
// check if location services are available
|
|
|
|
if (mLocationManager.getProviders(true).size() == 0) {
|
|
|
|
// ask user to turn on location services
|
2016-08-29 12:50:41 +00:00
|
|
|
promptUserForLocation();
|
|
|
|
}
|
|
|
|
|
2016-08-29 19:43:49 +00:00
|
|
|
// CASE 1: get saved location if possible
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
Location savedLocation = savedInstanceState.getParcelable(INSTANCE_CURRENT_LOCATION);
|
|
|
|
// check if saved location is still current
|
|
|
|
if (LocationHelper.isNewLocation(savedLocation)) {
|
|
|
|
mCurrentBestLocation = savedLocation;
|
|
|
|
} else {
|
|
|
|
mCurrentBestLocation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CASE 2: get last known location if no saved location or saved location is too old
|
|
|
|
if (mCurrentBestLocation == null && mLocationManager.getProviders(true).size() > 0) {
|
|
|
|
mCurrentBestLocation = LocationHelper.determineLastKnownLocation(mLocationManager);
|
|
|
|
}
|
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
// register broadcast receiver for new WayPoints
|
|
|
|
mTrackUpdatedReceiver = createTrackUpdatedReceiver();
|
|
|
|
IntentFilter trackUpdatedIntentFilter = new IntentFilter(ACTION_TRACK_UPDATED);
|
|
|
|
LocalBroadcastManager.getInstance(mActivity).registerReceiver(mTrackUpdatedReceiver, trackUpdatedIntentFilter);
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
// create basic map
|
|
|
|
mMapView = new MapView(inflater.getContext());
|
|
|
|
|
|
|
|
// get display metrics
|
|
|
|
final DisplayMetrics dm = mActivity.getResources().getDisplayMetrics();
|
|
|
|
|
|
|
|
// get map controller
|
|
|
|
mController = mMapView.getController();
|
|
|
|
|
|
|
|
// basic map setup
|
|
|
|
mMapView.setTileSource(TileSourceFactory.MAPNIK);
|
|
|
|
mMapView.setTilesScaledToDpi(true);
|
|
|
|
|
|
|
|
// add multi-touch capability
|
|
|
|
mMapView.setMultiTouchControls(true);
|
|
|
|
|
|
|
|
// initiate map state
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
// restore saved instance of map
|
|
|
|
GeoPoint position = new GeoPoint(savedInstanceState.getDouble(INSTANCE_LATITUDE), savedInstanceState.getDouble(INSTANCE_LONGITUDE));
|
|
|
|
mController.setCenter(position);
|
|
|
|
mController.setZoom(savedInstanceState.getInt(INSTANCE_ZOOM_LEVEL, 16));
|
|
|
|
// restore current location
|
|
|
|
mCurrentBestLocation = savedInstanceState.getParcelable(INSTANCE_CURRENT_LOCATION);
|
|
|
|
} else if (mCurrentBestLocation != null) {
|
|
|
|
// fallback or first run: set map to current position
|
2016-09-06 15:27:04 +00:00
|
|
|
GeoPoint position = convertToGeoPoint(mCurrentBestLocation);
|
2016-08-29 12:50:41 +00:00
|
|
|
mController.setCenter(position);
|
|
|
|
mController.setZoom(16);
|
|
|
|
}
|
|
|
|
|
2016-09-01 11:45:46 +00:00
|
|
|
// restore track
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
mTrack = savedInstanceState.getParcelable(INSTANCE_TRACK);
|
|
|
|
}
|
|
|
|
if (mTrack != null) {
|
|
|
|
drawTrackOverlay(mTrack);
|
|
|
|
}
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
// add compass to map
|
2016-08-29 19:43:49 +00:00
|
|
|
CompassOverlay compassOverlay = new CompassOverlay(mActivity, new InternalCompassOrientationProvider(mActivity), mMapView);
|
|
|
|
compassOverlay.enableCompass();
|
|
|
|
mMapView.getOverlays().add(compassOverlay);
|
2016-08-29 12:50:41 +00:00
|
|
|
|
|
|
|
// mark user's location on map
|
2016-09-06 15:27:04 +00:00
|
|
|
if (mCurrentBestLocation != null && !mTrackerServiceRunning) {
|
|
|
|
mMyLocationOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, LocationHelper.isNewLocation(mCurrentBestLocation));
|
2016-08-29 12:50:41 +00:00
|
|
|
mMapView.getOverlays().add(mMyLocationOverlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mMapView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
// start preliminary tracking - if no TrackerService is running
|
|
|
|
if (!mTrackerServiceRunning) {
|
|
|
|
startPreliminaryTracking();
|
|
|
|
}
|
|
|
|
|
|
|
|
// center map on current position - if TrackerService is running
|
|
|
|
if (mTrackerServiceRunning) {
|
|
|
|
mController.setCenter(convertToGeoPoint(mCurrentBestLocation));
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw track on map - if available
|
|
|
|
if (mTrack != null) {
|
|
|
|
drawTrackOverlay(mTrack);
|
|
|
|
}
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
// disable preliminary location listeners
|
|
|
|
stopPreliminaryTracking();
|
2016-08-29 12:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView(){
|
|
|
|
super.onDestroyView();
|
|
|
|
|
|
|
|
// deactivate map
|
|
|
|
mMapView.onDetach();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-30 13:22:19 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
// reset first start state
|
|
|
|
mFirstStart = true;
|
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
// disable broadcast receivers
|
|
|
|
LocalBroadcastManager.getInstance(mActivity).unregisterReceiver(mTrackUpdatedReceiver);
|
|
|
|
|
2016-08-30 13:22:19 +00:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
// handle action bar options menu selection
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
|
|
|
// CASE MY LOCATION
|
2016-09-06 15:27:04 +00:00
|
|
|
case R.id.action_bar_my_location:
|
2016-08-29 12:50:41 +00:00
|
|
|
|
|
|
|
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_my_location), Toast.LENGTH_LONG).show();
|
|
|
|
|
|
|
|
if (mLocationManager.getProviders(true).size() == 0) {
|
|
|
|
// location services are off - ask user to turn them on
|
|
|
|
promptUserForLocation();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get current position
|
|
|
|
GeoPoint position;
|
|
|
|
if (mCurrentBestLocation != null) {
|
|
|
|
// app has a current best estimate location
|
|
|
|
} else {
|
|
|
|
// app does not have any location fix
|
|
|
|
mCurrentBestLocation = LocationHelper.determineLastKnownLocation(mLocationManager);
|
|
|
|
}
|
2016-09-06 15:27:04 +00:00
|
|
|
position = convertToGeoPoint(mCurrentBestLocation);
|
2016-08-29 12:50:41 +00:00
|
|
|
|
|
|
|
// center map on current position
|
|
|
|
mController.setCenter(position);
|
|
|
|
|
|
|
|
// mark user's new location on map and remove last marker
|
2016-09-01 11:45:46 +00:00
|
|
|
updateMyLocationMarker();
|
2016-08-29 12:50:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// CASE DEFAULT
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
|
|
|
// save map position
|
2016-08-30 13:22:19 +00:00
|
|
|
outState.putBoolean(INSTANCE_FIRST_START, mFirstStart);
|
2016-08-29 12:50:41 +00:00
|
|
|
outState.putDouble(INSTANCE_LATITUDE, mMapView.getMapCenter().getLatitude());
|
|
|
|
outState.putDouble(INSTANCE_LONGITUDE, mMapView.getMapCenter().getLongitude());
|
|
|
|
outState.putInt(INSTANCE_ZOOM_LEVEL, mMapView.getZoomLevel());
|
|
|
|
outState.putParcelable(INSTANCE_CURRENT_LOCATION, mCurrentBestLocation);
|
2016-09-01 11:45:46 +00:00
|
|
|
outState.putParcelable(INSTANCE_TRACK, mTrack);
|
2016-09-06 15:27:04 +00:00
|
|
|
outState.putBoolean(INSTANCE_TRACKING_STATE, mTrackerServiceRunning);
|
2016-08-29 12:50:41 +00:00
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
/* Setter for tracking state */
|
|
|
|
public void setTrackingState (boolean trackingState) {
|
|
|
|
mTrackerServiceRunning = trackingState;
|
|
|
|
|
|
|
|
// turn on/off tracking for MainActivity Fragment - prevent double tracking
|
|
|
|
if (mTrackerServiceRunning) {
|
|
|
|
stopPreliminaryTracking();
|
|
|
|
} else if (!mLocalTrackerRunning){
|
|
|
|
startPreliminaryTracking();
|
|
|
|
if (mTrack != null) {
|
|
|
|
drawTrackOverlay(mTrack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update marker
|
2016-09-01 11:45:46 +00:00
|
|
|
updateMyLocationMarker();
|
2016-09-06 15:27:04 +00:00
|
|
|
LogHelper.v(LOG_TAG, "TrackingState: " + trackingState);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Getter for current best location */
|
|
|
|
public Location getCurrentBestLocation() {
|
|
|
|
return mCurrentBestLocation;
|
2016-09-01 11:45:46 +00:00
|
|
|
}
|
2016-08-29 19:43:49 +00:00
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
/* Start preliminary tracking for map */
|
|
|
|
private void startPreliminaryTracking() {
|
|
|
|
mLocalTrackerRunning = true;
|
2016-09-01 11:45:46 +00:00
|
|
|
// create location listeners
|
2016-08-29 12:50:41 +00:00
|
|
|
List locationProviders = mLocationManager.getProviders(true);
|
|
|
|
if (locationProviders.contains(LocationManager.GPS_PROVIDER)) {
|
2016-09-01 11:45:46 +00:00
|
|
|
mGPSListener = createLocationListener();
|
2016-08-29 12:50:41 +00:00
|
|
|
}
|
2016-09-01 11:45:46 +00:00
|
|
|
if (locationProviders.contains(LocationManager.NETWORK_PROVIDER)) {
|
|
|
|
mNetworkListener = createLocationListener();
|
2016-08-29 12:50:41 +00:00
|
|
|
}
|
2016-09-01 11:45:46 +00:00
|
|
|
|
|
|
|
// register listeners
|
|
|
|
LocationHelper.registerLocationListeners(mLocationManager, mGPSListener, mNetworkListener);
|
2016-08-29 12:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
/* Removes gps and network location listeners */
|
|
|
|
private void stopPreliminaryTracking() {
|
|
|
|
mLocalTrackerRunning = false;
|
|
|
|
// remove listeners
|
|
|
|
LocationHelper.removeLocationListeners(mLocationManager, mGPSListener, mNetworkListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
/* Creates listener for changes in location status */
|
2016-08-29 19:43:49 +00:00
|
|
|
private LocationListener createLocationListener() {
|
2016-08-29 12:50:41 +00:00
|
|
|
return new LocationListener() {
|
|
|
|
public void onLocationChanged(Location location) {
|
|
|
|
// check if the new location is better
|
|
|
|
if (LocationHelper.isBetterLocation(location, mCurrentBestLocation)) {
|
|
|
|
// save location
|
|
|
|
mCurrentBestLocation = location;
|
|
|
|
// mark user's new location on map and remove last marker
|
2016-09-01 11:45:46 +00:00
|
|
|
updateMyLocationMarker();
|
2016-08-29 12:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
|
|
|
// TODO do something
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onProviderEnabled(String provider) {
|
|
|
|
LogHelper.v(LOG_TAG, "Location provider enabled: " + provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onProviderDisabled(String provider) {
|
|
|
|
LogHelper.v(LOG_TAG, "Location provider disabled: " + provider);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-01 11:45:46 +00:00
|
|
|
/* Updates marker for current user location */
|
|
|
|
private void updateMyLocationMarker() {
|
|
|
|
mMapView.getOverlays().remove(mMyLocationOverlay);
|
2016-09-06 15:27:04 +00:00
|
|
|
// only update while not tracking
|
|
|
|
if (!mTrackerServiceRunning) {
|
|
|
|
mMyLocationOverlay = MapHelper.createMyLocationOverlay(mActivity, mCurrentBestLocation, LocationHelper.isNewLocation(mCurrentBestLocation));
|
|
|
|
mMapView.getOverlays().add(mMyLocationOverlay);
|
|
|
|
}
|
2016-09-01 11:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Draws track onto overlay */
|
|
|
|
private void drawTrackOverlay(Track track) {
|
|
|
|
mMapView.getOverlays().remove(mTrackOverlay);
|
2016-09-06 15:27:04 +00:00
|
|
|
mTrackOverlay = MapHelper.createTrackOverlay(mActivity, track, mTrackerServiceRunning);
|
2016-09-01 11:45:46 +00:00
|
|
|
mMapView.getOverlays().add(mTrackOverlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
/* Prompts user to turn on location */
|
|
|
|
private void promptUserForLocation() {
|
|
|
|
// TODO prompt user to turn on location
|
|
|
|
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_location_offline), Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-30 13:22:19 +00:00
|
|
|
/* Creates receiver for new WayPoints */
|
2016-09-01 11:45:46 +00:00
|
|
|
private BroadcastReceiver createTrackUpdatedReceiver() {
|
2016-08-30 13:22:19 +00:00
|
|
|
return new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
2016-09-06 15:27:04 +00:00
|
|
|
if (intent.hasExtra(EXTRA_TRACK) && intent.hasExtra(EXTRA_LAST_LOCATION)) {
|
|
|
|
// draw track on map
|
2016-09-01 11:45:46 +00:00
|
|
|
mTrack = intent.getParcelableExtra(EXTRA_TRACK);
|
|
|
|
drawTrackOverlay(mTrack);
|
|
|
|
Toast.makeText(mActivity, "New WayPoint.", Toast.LENGTH_LONG).show(); // TODO Remove
|
2016-09-06 15:27:04 +00:00
|
|
|
// center map over last location
|
|
|
|
mCurrentBestLocation = intent.getParcelableExtra(EXTRA_LAST_LOCATION);
|
|
|
|
mController.setCenter(convertToGeoPoint(mCurrentBestLocation));
|
|
|
|
// clear intent
|
|
|
|
intent.removeExtra(EXTRA_TRACK);
|
|
|
|
intent.removeExtra(EXTRA_LAST_LOCATION);
|
2016-08-30 13:22:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-06 15:27:04 +00:00
|
|
|
/* Converts Location to GeoPoint */
|
|
|
|
private GeoPoint convertToGeoPoint (Location location) {
|
|
|
|
return new GeoPoint(location.getLatitude(), location.getLongitude());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 12:50:41 +00:00
|
|
|
/* Saves state of map */
|
|
|
|
private void saveMaoState(Context context) {
|
|
|
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
editor.putInt(PREFS_ZOOM_LEVEL, mMapView.getZoomLevel());
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Loads app state from preferences */
|
|
|
|
private void loadMapState(Context context) {
|
|
|
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
int zoom = settings.getInt(PREFS_ZOOM_LEVEL, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|