|
|
|
|
@@ -8,7 +8,6 @@ import java.util.Date;
|
|
|
|
|
import org.mapsforge.android.DebugSettings;
|
|
|
|
|
import org.mapsforge.android.MapActivity;
|
|
|
|
|
import org.mapsforge.android.MapController;
|
|
|
|
|
import org.mapsforge.android.MapScaleBar;
|
|
|
|
|
import org.mapsforge.android.MapView;
|
|
|
|
|
import org.mapsforge.android.mapgenerator.MapDatabaseFactory;
|
|
|
|
|
import org.mapsforge.android.mapgenerator.MapDatabaseInternal;
|
|
|
|
|
@@ -25,6 +24,7 @@ import org.mapsforge.tilemap.filefilter.ValidRenderTheme;
|
|
|
|
|
import org.mapsforge.tilemap.filepicker.FilePicker;
|
|
|
|
|
import org.mapsforge.tilemap.preferences.EditPreferences;
|
|
|
|
|
|
|
|
|
|
import android.app.ActionBar;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
@@ -46,8 +46,10 @@ import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.SeekBar;
|
|
|
|
|
import android.widget.SpinnerAdapter;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
import android.widget.ToggleButton;
|
|
|
|
|
@@ -57,31 +59,36 @@ import android.widget.ToggleButton;
|
|
|
|
|
* location. A simple file browser for selecting the map file is also included. Some preferences can be adjusted via the
|
|
|
|
|
* {@link EditPreferences} activity.
|
|
|
|
|
*/
|
|
|
|
|
public class TileMap extends MapActivity {
|
|
|
|
|
public class TileMap extends MapActivity implements ActionBar.OnNavigationListener {
|
|
|
|
|
private static final String BUNDLE_CENTER_AT_FIRST_FIX = "centerAtFirstFix";
|
|
|
|
|
private static final String BUNDLE_SHOW_MY_LOCATION = "showMyLocation";
|
|
|
|
|
private static final String BUNDLE_SNAP_TO_LOCATION = "snapToLocation";
|
|
|
|
|
private static final int DIALOG_ENTER_COORDINATES = 0;
|
|
|
|
|
private static final int DIALOG_INFO_MAP_FILE = 1;
|
|
|
|
|
private static final int DIALOG_LOCATION_PROVIDER_DISABLED = 2;
|
|
|
|
|
private static final FileFilter FILE_FILTER_EXTENSION_MAP = new FilterByFileExtension(".map");
|
|
|
|
|
private static final FileFilter FILE_FILTER_EXTENSION_XML = new FilterByFileExtension(".xml");
|
|
|
|
|
private static final FileFilter FILE_FILTER_EXTENSION_MAP =
|
|
|
|
|
new FilterByFileExtension(".map");
|
|
|
|
|
private static final FileFilter FILE_FILTER_EXTENSION_XML =
|
|
|
|
|
new FilterByFileExtension(".xml");
|
|
|
|
|
private static final int SELECT_MAP_FILE = 0;
|
|
|
|
|
private static final int SELECT_RENDER_THEME_FILE = 1;
|
|
|
|
|
private LocationManager locationManager;
|
|
|
|
|
private MapDatabaseInternal mapDatabaseInternal;
|
|
|
|
|
private MyLocationListener myLocationListener;
|
|
|
|
|
private boolean showMyLocation;
|
|
|
|
|
private boolean snapToLocation;
|
|
|
|
|
private ToggleButton snapToLocationView;
|
|
|
|
|
private WakeLock wakeLock;
|
|
|
|
|
MapController mapController;
|
|
|
|
|
MapView mapView;
|
|
|
|
|
private LocationManager mLocationManager;
|
|
|
|
|
private MapDatabaseInternal mMapDatabaseInternal;
|
|
|
|
|
private MyLocationListener mMyLocationListener;
|
|
|
|
|
private boolean mShowMyLocation;
|
|
|
|
|
private boolean mSnapToLocation;
|
|
|
|
|
private ToggleButton mSnapToLocationView;
|
|
|
|
|
private WakeLock mWakeLock;
|
|
|
|
|
MapController mMapController;
|
|
|
|
|
MapView mMapView;
|
|
|
|
|
private Menu mMenu = null;
|
|
|
|
|
|
|
|
|
|
SpinnerAdapter mSpinnerAdapter;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
getMenuInflater().inflate(R.menu.options_menu, menu);
|
|
|
|
|
|
|
|
|
|
mMenu = menu;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@@ -89,31 +96,37 @@ public class TileMap extends MapActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case R.id.menu_info:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_info_map_file:
|
|
|
|
|
showDialog(DIALOG_INFO_MAP_FILE);
|
|
|
|
|
return true;
|
|
|
|
|
// case R.id.menu_info_map_file:
|
|
|
|
|
// showDialog(DIALOG_INFO_MAP_FILE);
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_position:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_position_my_location_enable:
|
|
|
|
|
if (enableShowMyLocation(true)) {
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable).setVisible(false);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable).setEnabled(false);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable).setVisible(true);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable).setEnabled(true);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable)
|
|
|
|
|
.setVisible(false);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable)
|
|
|
|
|
.setEnabled(false);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable)
|
|
|
|
|
.setVisible(true);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable)
|
|
|
|
|
.setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_position_my_location_disable:
|
|
|
|
|
if (disableShowMyLocation()) {
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable).setVisible(true);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable).setEnabled(true);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable).setVisible(false);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable).setEnabled(false);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable)
|
|
|
|
|
.setVisible(true);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_enable)
|
|
|
|
|
.setEnabled(true);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable)
|
|
|
|
|
.setVisible(false);
|
|
|
|
|
mMenu.findItem(R.id.menu_position_my_location_disable)
|
|
|
|
|
.setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
@@ -128,7 +141,8 @@ public class TileMap extends MapActivity {
|
|
|
|
|
case R.id.menu_position_map_center:
|
|
|
|
|
// disable GPS follow mode if it is enabled
|
|
|
|
|
disableSnapToLocation(true);
|
|
|
|
|
this.mapController.setCenter(this.mapView.getMapDatabase().getMapFileInfo().mapCenter);
|
|
|
|
|
mMapController.setCenter(mMapView.getMapDatabase()
|
|
|
|
|
.getMapFileInfo().mapCenter);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_preferences:
|
|
|
|
|
@@ -138,8 +152,11 @@ public class TileMap extends MapActivity {
|
|
|
|
|
case R.id.menu_render_theme:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_options:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_render_theme_osmarender:
|
|
|
|
|
this.mapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
|
|
|
|
|
mMapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case R.id.menu_render_theme_select_file:
|
|
|
|
|
@@ -157,13 +174,13 @@ public class TileMap extends MapActivity {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
|
|
|
|
MapGenerator mapGenerator = this.mapView.getMapGenerator();
|
|
|
|
|
MapGenerator mapGenerator = mMapView.getMapGenerator();
|
|
|
|
|
|
|
|
|
|
if (mapGenerator.requiresInternetConnection()) {
|
|
|
|
|
menu.findItem(R.id.menu_info_map_file).setEnabled(false);
|
|
|
|
|
} else {
|
|
|
|
|
menu.findItem(R.id.menu_info_map_file).setEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
// if (mapGenerator.requiresInternetConnection()) {
|
|
|
|
|
// menu.findItem(R.id.menu_info_map_file).setEnabled(false);
|
|
|
|
|
// } else {
|
|
|
|
|
// menu.findItem(R.id.menu_info_map_file).setEnabled(true);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (isShowMyLocationEnabled()) {
|
|
|
|
|
menu.findItem(R.id.menu_position_my_location_enable).setVisible(false);
|
|
|
|
|
@@ -201,32 +218,33 @@ public class TileMap extends MapActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTrackballEvent(MotionEvent event) {
|
|
|
|
|
// forward the event to the MapView
|
|
|
|
|
return this.mapView.onTrackballEvent(event);
|
|
|
|
|
return mMapView.onTrackballEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureMapView() {
|
|
|
|
|
// configure the MapView and activate the zoomLevel buttons
|
|
|
|
|
this.mapView.setClickable(true);
|
|
|
|
|
this.mapView.setBuiltInZoomControls(true);
|
|
|
|
|
this.mapView.setFocusable(true);
|
|
|
|
|
mMapView.setClickable(true);
|
|
|
|
|
mMapView.setBuiltInZoomControls(true);
|
|
|
|
|
mMapView.setFocusable(true);
|
|
|
|
|
|
|
|
|
|
this.mapController = this.mapView.getController();
|
|
|
|
|
mMapController = mMapView.getController();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean enableShowMyLocation(boolean centerAtFirstFix) {
|
|
|
|
|
if (!this.showMyLocation) {
|
|
|
|
|
if (!mShowMyLocation) {
|
|
|
|
|
Criteria criteria = new Criteria();
|
|
|
|
|
criteria.setAccuracy(Criteria.ACCURACY_FINE);
|
|
|
|
|
String bestProvider = this.locationManager.getBestProvider(criteria, true);
|
|
|
|
|
String bestProvider = mLocationManager.getBestProvider(criteria, true);
|
|
|
|
|
if (bestProvider == null) {
|
|
|
|
|
showDialog(DIALOG_LOCATION_PROVIDER_DISABLED);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.showMyLocation = true;
|
|
|
|
|
this.myLocationListener.setCenterAtFirstFix(centerAtFirstFix);
|
|
|
|
|
this.locationManager.requestLocationUpdates(bestProvider, 1000, 0, this.myLocationListener);
|
|
|
|
|
this.snapToLocationView.setVisibility(View.VISIBLE);
|
|
|
|
|
mShowMyLocation = true;
|
|
|
|
|
mMyLocationListener.setCenterAtFirstFix(centerAtFirstFix);
|
|
|
|
|
mLocationManager.requestLocationUpdates(bestProvider, 1000, 0,
|
|
|
|
|
mMyLocationListener);
|
|
|
|
|
mSnapToLocationView.setVisibility(View.VISIBLE);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
@@ -235,16 +253,20 @@ public class TileMap extends MapActivity {
|
|
|
|
|
private void gotoLastKnownPosition() {
|
|
|
|
|
Location currentLocation;
|
|
|
|
|
Location bestLocation = null;
|
|
|
|
|
for (String provider : this.locationManager.getProviders(true)) {
|
|
|
|
|
currentLocation = this.locationManager.getLastKnownLocation(provider);
|
|
|
|
|
if (bestLocation == null || currentLocation.getAccuracy() < bestLocation.getAccuracy()) {
|
|
|
|
|
for (String provider : mLocationManager.getProviders(true)) {
|
|
|
|
|
currentLocation = mLocationManager.getLastKnownLocation(provider);
|
|
|
|
|
if (currentLocation == null)
|
|
|
|
|
continue;
|
|
|
|
|
if (bestLocation == null
|
|
|
|
|
|| currentLocation.getAccuracy() < bestLocation.getAccuracy()) {
|
|
|
|
|
bestLocation = currentLocation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bestLocation != null) {
|
|
|
|
|
GeoPoint point = new GeoPoint(bestLocation.getLatitude(), bestLocation.getLongitude());
|
|
|
|
|
this.mapController.setCenter(point);
|
|
|
|
|
GeoPoint point = new GeoPoint(bestLocation.getLatitude(),
|
|
|
|
|
bestLocation.getLongitude());
|
|
|
|
|
mMapController.setCenter(point);
|
|
|
|
|
} else {
|
|
|
|
|
showToastOnUiThread(getString(R.string.error_last_location_unknown));
|
|
|
|
|
}
|
|
|
|
|
@@ -259,25 +281,35 @@ public class TileMap extends MapActivity {
|
|
|
|
|
private void startRenderThemePicker() {
|
|
|
|
|
FilePicker.setFileDisplayFilter(FILE_FILTER_EXTENSION_XML);
|
|
|
|
|
FilePicker.setFileSelectFilter(new ValidRenderTheme());
|
|
|
|
|
startActivityForResult(new Intent(this, FilePicker.class), SELECT_RENDER_THEME_FILE);
|
|
|
|
|
startActivityForResult(new Intent(this, FilePicker.class),
|
|
|
|
|
SELECT_RENDER_THEME_FILE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
|
|
if (requestCode == SELECT_MAP_FILE) {
|
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
|
|
|
|
|
|
disableSnapToLocation(true);
|
|
|
|
|
if (intent != null && intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
|
|
|
|
this.mapView.setMapFile(intent.getStringExtra(FilePicker.SELECTED_FILE));
|
|
|
|
|
|
|
|
|
|
if (intent != null) {
|
|
|
|
|
if (intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
|
|
|
|
mMapView.setMapFile(intent
|
|
|
|
|
.getStringExtra(FilePicker.SELECTED_FILE));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (resultCode == RESULT_CANCELED && !this.mapView.getMapGenerator().requiresInternetConnection()
|
|
|
|
|
&& this.mapView.getMapFile() == null) {
|
|
|
|
|
finish();
|
|
|
|
|
} else if (resultCode == RESULT_CANCELED) {
|
|
|
|
|
startActivity(new Intent(this, EditPreferences.class));
|
|
|
|
|
// && !mapView.getMapGenerator().requiresInternetConnection()
|
|
|
|
|
// && mapView.getMapFile() == null) {
|
|
|
|
|
// finish();
|
|
|
|
|
}
|
|
|
|
|
} else if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK && intent != null
|
|
|
|
|
} else if (requestCode == SELECT_RENDER_THEME_FILE && resultCode == RESULT_OK
|
|
|
|
|
&& intent != null
|
|
|
|
|
&& intent.getStringExtra(FilePicker.SELECTED_FILE) != null) {
|
|
|
|
|
try {
|
|
|
|
|
this.mapView.setRenderTheme(intent.getStringExtra(FilePicker.SELECTED_FILE));
|
|
|
|
|
mMapView.setRenderTheme(intent
|
|
|
|
|
.getStringExtra(FilePicker.SELECTED_FILE));
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
showToastOnUiThread(e.getLocalizedMessage());
|
|
|
|
|
}
|
|
|
|
|
@@ -288,14 +320,31 @@ public class TileMap extends MapActivity {
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
|
|
mSpinnerAdapter = ArrayAdapter.createFromResource(this,
|
|
|
|
|
R.array.view_sections,
|
|
|
|
|
android.R.layout.simple_spinner_dropdown_item);
|
|
|
|
|
ActionBar actionBar = getActionBar();
|
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
|
|
|
|
|
|
|
|
|
|
actionBar.setListNavigationCallbacks(mSpinnerAdapter, this);
|
|
|
|
|
actionBar.setDisplayShowTitleEnabled(false);
|
|
|
|
|
|
|
|
|
|
// getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
|
|
|
|
|
// getActionBar().setBackgroundDrawable(
|
|
|
|
|
// getResources().getDrawable(R.drawable.action_bar));
|
|
|
|
|
// // getActionBar().setDisplayShowTitleEnabled(false);
|
|
|
|
|
// getActionBar().setIcon(R.drawable.bar_globe2);
|
|
|
|
|
|
|
|
|
|
// set up the layout views
|
|
|
|
|
setContentView(R.layout.activity_advanced_map_viewer);
|
|
|
|
|
this.mapView = (MapView) findViewById(R.id.mapView);
|
|
|
|
|
|
|
|
|
|
// getActionBar().setDisplayOptions(ActionBar.NAVIGATION_MODE_TABS);
|
|
|
|
|
|
|
|
|
|
mMapView = (MapView) findViewById(R.id.mapView);
|
|
|
|
|
configureMapView();
|
|
|
|
|
|
|
|
|
|
this.snapToLocationView = (ToggleButton) findViewById(R.id.snapToLocationView);
|
|
|
|
|
this.snapToLocationView.setOnClickListener(new OnClickListener() {
|
|
|
|
|
mSnapToLocationView = (ToggleButton) findViewById(R.id.snapToLocationView);
|
|
|
|
|
mSnapToLocationView.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
if (isSnapToLocationEnabled()) {
|
|
|
|
|
@@ -307,15 +356,21 @@ public class TileMap extends MapActivity {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// get the pointers to different system services
|
|
|
|
|
this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
|
this.myLocationListener = new MyLocationListener(this);
|
|
|
|
|
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
|
|
|
|
mMyLocationListener = new MyLocationListener(this);
|
|
|
|
|
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
|
this.wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "AMV");
|
|
|
|
|
mWakeLock = powerManager
|
|
|
|
|
.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "AMV");
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null && savedInstanceState.getBoolean(BUNDLE_SHOW_MY_LOCATION)) {
|
|
|
|
|
enableShowMyLocation(savedInstanceState.getBoolean(BUNDLE_CENTER_AT_FIRST_FIX));
|
|
|
|
|
if (savedInstanceState.getBoolean(BUNDLE_SNAP_TO_LOCATION)) {
|
|
|
|
|
enableSnapToLocation(false);
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
|
if (savedInstanceState.getBoolean(BUNDLE_SHOW_MY_LOCATION)) {
|
|
|
|
|
|
|
|
|
|
enableShowMyLocation(savedInstanceState
|
|
|
|
|
.getBoolean(BUNDLE_CENTER_AT_FIRST_FIX));
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState.getBoolean(BUNDLE_SNAP_TO_LOCATION)) {
|
|
|
|
|
enableSnapToLocation(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -329,23 +384,30 @@ public class TileMap extends MapActivity {
|
|
|
|
|
LayoutInflater factory = LayoutInflater.from(this);
|
|
|
|
|
final View view = factory.inflate(R.layout.dialog_enter_coordinates, null);
|
|
|
|
|
builder.setView(view);
|
|
|
|
|
builder.setPositiveButton(R.string.go_to_position, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
// disable GPS follow mode if it is enabled
|
|
|
|
|
disableSnapToLocation(true);
|
|
|
|
|
builder.setPositiveButton(R.string.go_to_position,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
// disable GPS follow mode if it is enabled
|
|
|
|
|
disableSnapToLocation(true);
|
|
|
|
|
|
|
|
|
|
// set the map center and zoom level
|
|
|
|
|
EditText latitudeView = (EditText) view.findViewById(R.id.latitude);
|
|
|
|
|
EditText longitudeView = (EditText) view.findViewById(R.id.longitude);
|
|
|
|
|
double latitude = Double.parseDouble(latitudeView.getText().toString());
|
|
|
|
|
double longitude = Double.parseDouble(longitudeView.getText().toString());
|
|
|
|
|
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
|
|
|
|
|
TileMap.this.mapController.setCenter(geoPoint);
|
|
|
|
|
SeekBar zoomLevelView = (SeekBar) view.findViewById(R.id.zoomLevel);
|
|
|
|
|
TileMap.this.mapController.setZoom(zoomLevelView.getProgress());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// set the map center and zoom level
|
|
|
|
|
EditText latitudeView = (EditText) view
|
|
|
|
|
.findViewById(R.id.latitude);
|
|
|
|
|
EditText longitudeView = (EditText) view
|
|
|
|
|
.findViewById(R.id.longitude);
|
|
|
|
|
double latitude = Double.parseDouble(latitudeView.getText()
|
|
|
|
|
.toString());
|
|
|
|
|
double longitude = Double.parseDouble(longitudeView.getText()
|
|
|
|
|
.toString());
|
|
|
|
|
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
|
|
|
|
|
TileMap.this.mMapController.setCenter(geoPoint);
|
|
|
|
|
SeekBar zoomLevelView = (SeekBar) view
|
|
|
|
|
.findViewById(R.id.zoomLevel);
|
|
|
|
|
TileMap.this.mMapController.setZoom(zoomLevelView
|
|
|
|
|
.getProgress());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
|
return builder.create();
|
|
|
|
|
} else if (id == DIALOG_LOCATION_PROVIDER_DISABLED) {
|
|
|
|
|
@@ -377,8 +439,8 @@ public class TileMap extends MapActivity {
|
|
|
|
|
protected void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
// release the wake lock if necessary
|
|
|
|
|
if (this.wakeLock.isHeld()) {
|
|
|
|
|
this.wakeLock.release();
|
|
|
|
|
if (mWakeLock.isHeld()) {
|
|
|
|
|
mWakeLock.release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -386,27 +448,28 @@ public class TileMap extends MapActivity {
|
|
|
|
|
protected void onPrepareDialog(int id, final Dialog dialog) {
|
|
|
|
|
if (id == DIALOG_ENTER_COORDINATES) {
|
|
|
|
|
EditText editText = (EditText) dialog.findViewById(R.id.latitude);
|
|
|
|
|
GeoPoint mapCenter = this.mapView.getMapPosition().getMapCenter();
|
|
|
|
|
GeoPoint mapCenter = mMapView.getMapPosition().getMapCenter();
|
|
|
|
|
editText.setText(Double.toString(mapCenter.getLatitude()));
|
|
|
|
|
|
|
|
|
|
editText = (EditText) dialog.findViewById(R.id.longitude);
|
|
|
|
|
editText.setText(Double.toString(mapCenter.getLongitude()));
|
|
|
|
|
|
|
|
|
|
SeekBar zoomlevel = (SeekBar) dialog.findViewById(R.id.zoomLevel);
|
|
|
|
|
zoomlevel.setMax(this.mapView.getMapGenerator().getZoomLevelMax());
|
|
|
|
|
zoomlevel.setProgress(this.mapView.getMapPosition().getZoomLevel());
|
|
|
|
|
zoomlevel.setMax(mMapView.getMapGenerator().getZoomLevelMax());
|
|
|
|
|
zoomlevel.setProgress(mMapView.getMapPosition().getZoomLevel());
|
|
|
|
|
|
|
|
|
|
final TextView textView = (TextView) dialog.findViewById(R.id.zoomlevelValue);
|
|
|
|
|
textView.setText(String.valueOf(zoomlevel.getProgress()));
|
|
|
|
|
zoomlevel.setOnSeekBarChangeListener(new SeekBarChangeListener(textView));
|
|
|
|
|
} else if (id == DIALOG_INFO_MAP_FILE) {
|
|
|
|
|
MapFileInfo mapFileInfo = this.mapView.getMapDatabase().getMapFileInfo();
|
|
|
|
|
MapFileInfo mapFileInfo = mMapView.getMapDatabase().getMapFileInfo();
|
|
|
|
|
|
|
|
|
|
TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName);
|
|
|
|
|
textView.setText(this.mapView.getMapFile());
|
|
|
|
|
textView.setText(mMapView.getMapFile());
|
|
|
|
|
|
|
|
|
|
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize);
|
|
|
|
|
textView.setText(FileUtils.formatFileSize(mapFileInfo.fileSize, getResources()));
|
|
|
|
|
textView.setText(FileUtils.formatFileSize(mapFileInfo.fileSize,
|
|
|
|
|
getResources()));
|
|
|
|
|
|
|
|
|
|
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion);
|
|
|
|
|
textView.setText(String.valueOf(mapFileInfo.fileVersion));
|
|
|
|
|
@@ -424,7 +487,8 @@ public class TileMap extends MapActivity {
|
|
|
|
|
|
|
|
|
|
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewArea);
|
|
|
|
|
BoundingBox boundingBox = mapFileInfo.boundingBox;
|
|
|
|
|
textView.setText(boundingBox.getMinLatitude() + ", " + boundingBox.getMinLongitude() + " - \n"
|
|
|
|
|
textView.setText(boundingBox.getMinLatitude() + ", "
|
|
|
|
|
+ boundingBox.getMinLongitude() + " - \n"
|
|
|
|
|
+ boundingBox.getMaxLatitude() + ", " + boundingBox.getMaxLongitude());
|
|
|
|
|
|
|
|
|
|
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartPosition);
|
|
|
|
|
@@ -432,7 +496,8 @@ public class TileMap extends MapActivity {
|
|
|
|
|
if (startPosition == null) {
|
|
|
|
|
textView.setText(null);
|
|
|
|
|
} else {
|
|
|
|
|
textView.setText(startPosition.getLatitude() + ", " + startPosition.getLongitude());
|
|
|
|
|
textView.setText(startPosition.getLatitude() + ", "
|
|
|
|
|
+ startPosition.getLongitude());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartZoomLevel);
|
|
|
|
|
@@ -443,7 +508,8 @@ public class TileMap extends MapActivity {
|
|
|
|
|
textView.setText(startZoomLevel.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewLanguagePreference);
|
|
|
|
|
textView = (TextView) dialog
|
|
|
|
|
.findViewById(R.id.infoMapFileViewLanguagePreference);
|
|
|
|
|
textView.setText(mapFileInfo.languagePreference);
|
|
|
|
|
|
|
|
|
|
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewComment);
|
|
|
|
|
@@ -460,13 +526,14 @@ public class TileMap extends MapActivity {
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
|
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
|
SharedPreferences preferences = PreferenceManager
|
|
|
|
|
.getDefaultSharedPreferences(this);
|
|
|
|
|
|
|
|
|
|
MapScaleBar mapScaleBar = this.mapView.getMapScaleBar();
|
|
|
|
|
mapScaleBar.setShowMapScaleBar(preferences.getBoolean("showScaleBar", false));
|
|
|
|
|
String scaleBarUnitDefault = getString(R.string.preferences_scale_bar_unit_default);
|
|
|
|
|
String scaleBarUnit = preferences.getString("scaleBarUnit", scaleBarUnitDefault);
|
|
|
|
|
mapScaleBar.setImperialUnits(scaleBarUnit.equals("imperial"));
|
|
|
|
|
// MapScaleBar mapScaleBar = mapView.getMapScaleBar();
|
|
|
|
|
// mapScaleBar.setShowMapScaleBar(preferences.getBoolean("showScaleBar", false));
|
|
|
|
|
// String scaleBarUnitDefault = getString(R.string.preferences_scale_bar_unit_default);
|
|
|
|
|
// String scaleBarUnit = preferences.getString("scaleBarUnit", scaleBarUnitDefault);
|
|
|
|
|
// mapScaleBar.setImperialUnits(scaleBarUnit.equals("imperial"));
|
|
|
|
|
|
|
|
|
|
// if (preferences.contains("mapGenerator")) {
|
|
|
|
|
// String name = preferences.getString("mapGenerator", MapGeneratorInternal.SW_RENDERER.name());
|
|
|
|
|
@@ -477,33 +544,41 @@ public class TileMap extends MapActivity {
|
|
|
|
|
// mapGeneratorInternalNew = MapGeneratorInternal.SW_RENDERER;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (mapGeneratorInternalNew != this.mapGeneratorInternal) {
|
|
|
|
|
// if (mapGeneratorInternalNew != mapGeneratorInternal) {
|
|
|
|
|
// MapGenerator mapGenerator = MapGeneratorFactory.createMapGenerator(mapGeneratorInternalNew);
|
|
|
|
|
// this.mapView.setMapGenerator(mapGenerator);
|
|
|
|
|
// this.mapGeneratorInternal = mapGeneratorInternalNew;
|
|
|
|
|
// mapView.setMapGenerator(mapGenerator);
|
|
|
|
|
// mapGeneratorInternal = mapGeneratorInternalNew;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if (preferences.contains("mapDatabase")) {
|
|
|
|
|
String name = preferences.getString("mapDatabase", MapDatabaseInternal.MAP_READER.name());
|
|
|
|
|
String name = preferences.getString("mapDatabase",
|
|
|
|
|
MapDatabaseInternal.POSTGIS_READER.name());
|
|
|
|
|
|
|
|
|
|
MapDatabaseInternal mapDatabaseInternalNew;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
mapDatabaseInternalNew = MapDatabaseInternal.valueOf(name);
|
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
|
mapDatabaseInternalNew = MapDatabaseInternal.MAP_READER;
|
|
|
|
|
mapDatabaseInternalNew = MapDatabaseInternal.POSTGIS_READER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d("VectorTileMap", "set map database " + mapDatabaseInternalNew);
|
|
|
|
|
|
|
|
|
|
if (mapDatabaseInternalNew != this.mapDatabaseInternal) {
|
|
|
|
|
IMapDatabase mapDatabase = MapDatabaseFactory.createMapDatabase(mapDatabaseInternalNew);
|
|
|
|
|
this.mapView.setMapDatabase(mapDatabase);
|
|
|
|
|
this.mapDatabaseInternal = mapDatabaseInternalNew;
|
|
|
|
|
if (mapDatabaseInternalNew != mMapDatabaseInternal) {
|
|
|
|
|
IMapDatabase mapDatabase = MapDatabaseFactory
|
|
|
|
|
.createMapDatabase(mapDatabaseInternalNew);
|
|
|
|
|
mMapView.setMapDatabase(mapDatabase);
|
|
|
|
|
mMapDatabaseInternal = mapDatabaseInternalNew;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String textScaleDefault = getString(R.string.preferences_text_scale_default);
|
|
|
|
|
this.mapView.setTextScale(Float.parseFloat(preferences.getString("textScale", textScaleDefault)));
|
|
|
|
|
mMapView.setTextScale(Float.parseFloat(preferences.getString("textScale",
|
|
|
|
|
textScaleDefault)));
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
this.mapView.setTextScale(1);
|
|
|
|
|
mMapView.setTextScale(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (preferences.getBoolean("fullscreen", false)) {
|
|
|
|
|
@@ -515,18 +590,27 @@ public class TileMap extends MapActivity {
|
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
|
|
|
|
}
|
|
|
|
|
if (preferences.getBoolean("wakeLock", false) && !this.wakeLock.isHeld()) {
|
|
|
|
|
this.wakeLock.acquire();
|
|
|
|
|
if (preferences.getBoolean("wakeLock", false) && !mWakeLock.isHeld()) {
|
|
|
|
|
mWakeLock.acquire();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean drawTileFrames = preferences.getBoolean("drawTileFrames", false);
|
|
|
|
|
boolean drawTileCoordinates = preferences.getBoolean("drawTileCoordinates", false);
|
|
|
|
|
boolean disablePolygons = preferences.getBoolean("disablePolygons", false);
|
|
|
|
|
DebugSettings debugSettings = new DebugSettings(drawTileCoordinates, drawTileFrames, disablePolygons);
|
|
|
|
|
this.mapView.setDebugSettings(debugSettings);
|
|
|
|
|
boolean drawTileFrames =
|
|
|
|
|
preferences.getBoolean("drawTileFrames", false);
|
|
|
|
|
boolean drawTileCoordinates =
|
|
|
|
|
preferences.getBoolean("drawTileCoordinates", false);
|
|
|
|
|
boolean disablePolygons =
|
|
|
|
|
preferences.getBoolean("disablePolygons", false);
|
|
|
|
|
|
|
|
|
|
if (!this.mapView.getMapGenerator().requiresInternetConnection() && this.mapView.getMapFile() == null) {
|
|
|
|
|
startMapFilePicker();
|
|
|
|
|
DebugSettings debugSettings = new DebugSettings(drawTileCoordinates,
|
|
|
|
|
drawTileFrames, disablePolygons);
|
|
|
|
|
|
|
|
|
|
mMapView.setDebugSettings(debugSettings);
|
|
|
|
|
|
|
|
|
|
if (mMapDatabaseInternal == MapDatabaseInternal.MAP_READER) {
|
|
|
|
|
if (mMapView.getMapFile() == null)
|
|
|
|
|
startMapFilePicker();
|
|
|
|
|
} else {
|
|
|
|
|
mMapView.setMapFile(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -534,8 +618,9 @@ public class TileMap extends MapActivity {
|
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
outState.putBoolean(BUNDLE_SHOW_MY_LOCATION, isShowMyLocationEnabled());
|
|
|
|
|
outState.putBoolean(BUNDLE_CENTER_AT_FIRST_FIX, this.myLocationListener.isCenterAtFirstFix());
|
|
|
|
|
outState.putBoolean(BUNDLE_SNAP_TO_LOCATION, this.snapToLocation);
|
|
|
|
|
outState.putBoolean(BUNDLE_CENTER_AT_FIRST_FIX,
|
|
|
|
|
mMyLocationListener.isCenterAtFirstFix());
|
|
|
|
|
outState.putBoolean(BUNDLE_SNAP_TO_LOCATION, mSnapToLocation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -544,17 +629,17 @@ public class TileMap extends MapActivity {
|
|
|
|
|
* @return ...
|
|
|
|
|
*/
|
|
|
|
|
private boolean disableShowMyLocation() {
|
|
|
|
|
if (this.showMyLocation) {
|
|
|
|
|
this.showMyLocation = false;
|
|
|
|
|
if (mShowMyLocation) {
|
|
|
|
|
mShowMyLocation = false;
|
|
|
|
|
disableSnapToLocation(false);
|
|
|
|
|
this.locationManager.removeUpdates(this.myLocationListener);
|
|
|
|
|
// if (this.circleOverlay != null) {
|
|
|
|
|
// this.mapView.getOverlays().remove(this.circleOverlay);
|
|
|
|
|
// this.mapView.getOverlays().remove(this.itemizedOverlay);
|
|
|
|
|
// this.circleOverlay = null;
|
|
|
|
|
// this.itemizedOverlay = null;
|
|
|
|
|
mLocationManager.removeUpdates(mMyLocationListener);
|
|
|
|
|
// if (circleOverlay != null) {
|
|
|
|
|
// mapView.getOverlays().remove(circleOverlay);
|
|
|
|
|
// mapView.getOverlays().remove(itemizedOverlay);
|
|
|
|
|
// circleOverlay = null;
|
|
|
|
|
// itemizedOverlay = null;
|
|
|
|
|
// }
|
|
|
|
|
this.snapToLocationView.setVisibility(View.GONE);
|
|
|
|
|
mSnapToLocationView.setVisibility(View.GONE);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
@@ -567,10 +652,10 @@ public class TileMap extends MapActivity {
|
|
|
|
|
* defines whether a toast message is displayed or not.
|
|
|
|
|
*/
|
|
|
|
|
void disableSnapToLocation(boolean showToast) {
|
|
|
|
|
if (this.snapToLocation) {
|
|
|
|
|
this.snapToLocation = false;
|
|
|
|
|
this.snapToLocationView.setChecked(false);
|
|
|
|
|
this.mapView.setClickable(true);
|
|
|
|
|
if (mSnapToLocation) {
|
|
|
|
|
mSnapToLocation = false;
|
|
|
|
|
mSnapToLocationView.setChecked(false);
|
|
|
|
|
mMapView.setClickable(true);
|
|
|
|
|
if (showToast) {
|
|
|
|
|
showToastOnUiThread(getString(R.string.snap_to_location_disabled));
|
|
|
|
|
}
|
|
|
|
|
@@ -584,9 +669,9 @@ public class TileMap extends MapActivity {
|
|
|
|
|
* defines whether a toast message is displayed or not.
|
|
|
|
|
*/
|
|
|
|
|
void enableSnapToLocation(boolean showToast) {
|
|
|
|
|
if (!this.snapToLocation) {
|
|
|
|
|
this.snapToLocation = true;
|
|
|
|
|
this.mapView.setClickable(false);
|
|
|
|
|
if (!mSnapToLocation) {
|
|
|
|
|
mSnapToLocation = true;
|
|
|
|
|
mMapView.setClickable(false);
|
|
|
|
|
if (showToast) {
|
|
|
|
|
showToastOnUiThread(getString(R.string.snap_to_location_enabled));
|
|
|
|
|
}
|
|
|
|
|
@@ -599,7 +684,7 @@ public class TileMap extends MapActivity {
|
|
|
|
|
* @return true if the "show my location" mode is enabled, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
boolean isShowMyLocationEnabled() {
|
|
|
|
|
return this.showMyLocation;
|
|
|
|
|
return mShowMyLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -608,7 +693,7 @@ public class TileMap extends MapActivity {
|
|
|
|
|
* @return true if the "snap to location" mode is enabled, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
boolean isSnapToLocationEnabled() {
|
|
|
|
|
return this.snapToLocation;
|
|
|
|
|
return mSnapToLocation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -632,4 +717,10 @@ public class TileMap extends MapActivity {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onNavigationItemSelected(int arg0, long arg1) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|