add VectorTileMap viewer
This commit is contained in:
63
src/de/sfb/tilemap/FileUtils.java
Normal file
63
src/de/sfb/tilemap/FileUtils.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import de.sfb.tilemap.R;
|
||||
|
||||
final class FileUtils {
|
||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.00 ");
|
||||
private static final double ONE_GIGABYTE = 1000000000;
|
||||
private static final double ONE_KILOBYTE = 1000;
|
||||
private static final double ONE_MEGABYTE = 1000000;
|
||||
|
||||
/**
|
||||
* Formats the given file size as a human readable string, using SI prefixes.
|
||||
*
|
||||
* @param fileSize
|
||||
* the file size to be formatted.
|
||||
* @param resources
|
||||
* a reference to the application resources.
|
||||
* @return a human readable file size.
|
||||
* @throws IllegalArgumentException
|
||||
* if the given file size is negative.
|
||||
*/
|
||||
static String formatFileSize(long fileSize, Resources resources) {
|
||||
if (fileSize < 0) {
|
||||
throw new IllegalArgumentException("invalid file size: " + fileSize);
|
||||
} else if (fileSize < 1000) {
|
||||
if (fileSize == 1) {
|
||||
// singular
|
||||
return "1 " + resources.getString(R.string.file_size_byte);
|
||||
}
|
||||
|
||||
// plural, including zero
|
||||
return fileSize + " " + resources.getString(R.string.file_size_bytes);
|
||||
} else {
|
||||
if (fileSize < ONE_MEGABYTE) {
|
||||
return DECIMAL_FORMAT.format(fileSize / ONE_KILOBYTE) + resources.getString(R.string.file_size_kb);
|
||||
} else if (fileSize < ONE_GIGABYTE) {
|
||||
return DECIMAL_FORMAT.format(fileSize / ONE_MEGABYTE) + resources.getString(R.string.file_size_mb);
|
||||
}
|
||||
return DECIMAL_FORMAT.format(fileSize / ONE_GIGABYTE) + resources.getString(R.string.file_size_gb);
|
||||
}
|
||||
}
|
||||
|
||||
private FileUtils() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
48
src/de/sfb/tilemap/InfoView.java
Normal file
48
src/de/sfb/tilemap/InfoView.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.WebView;
|
||||
import de.sfb.tilemap.R;
|
||||
|
||||
/**
|
||||
* Simple activity to display the info web page from the assets folder.
|
||||
*/
|
||||
public class InfoView extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
WebView webView = new WebView(this);
|
||||
webView.loadUrl("file:///android_asset/info.xml");
|
||||
setContentView(webView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// check if the full screen mode should be activated
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen", false)) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
71
src/de/sfb/tilemap/MyLocationListener.java
Normal file
71
src/de/sfb/tilemap/MyLocationListener.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap;
|
||||
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.os.Bundle;
|
||||
import de.sfb.tilemap.R;
|
||||
|
||||
class MyLocationListener implements LocationListener {
|
||||
private final TileMap advancedMapViewer;
|
||||
private boolean centerAtFirstFix;
|
||||
|
||||
MyLocationListener(TileMap advancedMapViewer) {
|
||||
this.advancedMapViewer = advancedMapViewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
if (!this.advancedMapViewer.isShowMyLocationEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GeoPoint point = new GeoPoint(location.getLatitude(), location.getLongitude());
|
||||
// this.advancedMapViewer.overlayCircle.setCircleData(point, location.getAccuracy());
|
||||
// this.advancedMapViewer.overlayItem.setPoint(point);
|
||||
// this.advancedMapViewer.circleOverlay.requestRedraw();
|
||||
// this.advancedMapViewer.itemizedOverlay.requestRedraw();
|
||||
if (this.centerAtFirstFix || this.advancedMapViewer.isSnapToLocationEnabled()) {
|
||||
this.centerAtFirstFix = false;
|
||||
this.advancedMapViewer.mapController.setCenter(point);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
boolean isCenterAtFirstFix() {
|
||||
return this.centerAtFirstFix;
|
||||
}
|
||||
|
||||
void setCenterAtFirstFix(boolean centerAtFirstFix) {
|
||||
this.centerAtFirstFix = centerAtFirstFix;
|
||||
}
|
||||
}
|
||||
42
src/de/sfb/tilemap/SeekBarChangeListener.java
Normal file
42
src/de/sfb/tilemap/SeekBarChangeListener.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap;
|
||||
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import de.sfb.tilemap.R;
|
||||
|
||||
class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
|
||||
private final TextView textView;
|
||||
|
||||
SeekBarChangeListener(TextView textView) {
|
||||
this.textView = textView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
this.textView.setText(String.valueOf(progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
618
src/de/sfb/tilemap/TileMap.java
Executable file
618
src/de/sfb/tilemap/TileMap.java
Executable file
@@ -0,0 +1,618 @@
|
||||
package de.sfb.tilemap;
|
||||
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mapsforge.android.maps.DebugSettings;
|
||||
import org.mapsforge.android.maps.MapActivity;
|
||||
import org.mapsforge.android.maps.MapController;
|
||||
import org.mapsforge.android.maps.MapScaleBar;
|
||||
import org.mapsforge.android.maps.MapView;
|
||||
import org.mapsforge.android.maps.mapgenerator.MapDatabaseFactory;
|
||||
import org.mapsforge.android.maps.mapgenerator.MapDatabaseInternal;
|
||||
import org.mapsforge.android.maps.mapgenerator.MapGenerator;
|
||||
import org.mapsforge.android.maps.rendertheme.InternalRenderTheme;
|
||||
import org.mapsforge.android.maps.utils.AndroidUtils;
|
||||
import org.mapsforge.core.BoundingBox;
|
||||
import org.mapsforge.core.GeoPoint;
|
||||
import org.mapsforge.map.IMapDatabase;
|
||||
import org.mapsforge.map.MapFileInfo;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Criteria;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
import de.sfb.tilemap.R;
|
||||
import de.sfb.tilemap.filefilter.FilterByFileExtension;
|
||||
import de.sfb.tilemap.filefilter.ValidMapFile;
|
||||
import de.sfb.tilemap.filefilter.ValidRenderTheme;
|
||||
import de.sfb.tilemap.filepicker.FilePicker;
|
||||
import de.sfb.tilemap.preferences.EditPreferences;
|
||||
|
||||
/**
|
||||
* A map application which uses the features from the mapsforge map library. The map can be centered to the current
|
||||
* 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 {
|
||||
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 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;
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.options_menu, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@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_position:
|
||||
return true;
|
||||
|
||||
case R.id.menu_position_my_location_enable:
|
||||
enableShowMyLocation(true);
|
||||
return true;
|
||||
|
||||
case R.id.menu_position_my_location_disable:
|
||||
disableShowMyLocation();
|
||||
return true;
|
||||
|
||||
case R.id.menu_position_last_known:
|
||||
gotoLastKnownPosition();
|
||||
return true;
|
||||
|
||||
case R.id.menu_position_enter_coordinates:
|
||||
showDialog(DIALOG_ENTER_COORDINATES);
|
||||
return true;
|
||||
|
||||
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);
|
||||
return true;
|
||||
|
||||
case R.id.menu_preferences:
|
||||
startActivity(new Intent(this, EditPreferences.class));
|
||||
return true;
|
||||
|
||||
case R.id.menu_render_theme:
|
||||
return true;
|
||||
|
||||
case R.id.menu_render_theme_osmarender:
|
||||
this.mapView.setRenderTheme(InternalRenderTheme.OSMARENDER);
|
||||
return true;
|
||||
|
||||
case R.id.menu_render_theme_select_file:
|
||||
startRenderThemePicker();
|
||||
return true;
|
||||
|
||||
case R.id.menu_mapfile:
|
||||
startMapFilePicker();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
MapGenerator mapGenerator = this.mapView.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 (isShowMyLocationEnabled()) {
|
||||
menu.findItem(R.id.menu_position_my_location_enable).setVisible(false);
|
||||
menu.findItem(R.id.menu_position_my_location_enable).setEnabled(false);
|
||||
menu.findItem(R.id.menu_position_my_location_disable).setVisible(true);
|
||||
menu.findItem(R.id.menu_position_my_location_disable).setEnabled(true);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_position_my_location_enable).setVisible(true);
|
||||
menu.findItem(R.id.menu_position_my_location_enable).setEnabled(true);
|
||||
menu.findItem(R.id.menu_position_my_location_disable).setVisible(false);
|
||||
menu.findItem(R.id.menu_position_my_location_disable).setEnabled(false);
|
||||
}
|
||||
|
||||
if (mapGenerator.requiresInternetConnection()) {
|
||||
menu.findItem(R.id.menu_position_map_center).setEnabled(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_position_map_center).setEnabled(true);
|
||||
}
|
||||
|
||||
if (mapGenerator.requiresInternetConnection()) {
|
||||
menu.findItem(R.id.menu_render_theme).setEnabled(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_render_theme).setEnabled(true);
|
||||
}
|
||||
|
||||
if (mapGenerator.requiresInternetConnection()) {
|
||||
menu.findItem(R.id.menu_mapfile).setEnabled(false);
|
||||
} else {
|
||||
menu.findItem(R.id.menu_mapfile).setEnabled(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTrackballEvent(MotionEvent event) {
|
||||
// forward the event to the MapView
|
||||
return this.mapView.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);
|
||||
|
||||
this.mapController = this.mapView.getController();
|
||||
}
|
||||
|
||||
private void enableShowMyLocation(boolean centerAtFirstFix) {
|
||||
if (!this.showMyLocation) {
|
||||
Criteria criteria = new Criteria();
|
||||
criteria.setAccuracy(Criteria.ACCURACY_FINE);
|
||||
String bestProvider = this.locationManager.getBestProvider(criteria, true);
|
||||
if (bestProvider == null) {
|
||||
showDialog(DIALOG_LOCATION_PROVIDER_DISABLED);
|
||||
return;
|
||||
}
|
||||
|
||||
this.showMyLocation = true;
|
||||
this.myLocationListener.setCenterAtFirstFix(centerAtFirstFix);
|
||||
this.locationManager.requestLocationUpdates(bestProvider, 1000, 0, this.myLocationListener);
|
||||
this.snapToLocationView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
bestLocation = currentLocation;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestLocation != null) {
|
||||
GeoPoint point = new GeoPoint(bestLocation.getLatitude(), bestLocation.getLongitude());
|
||||
this.mapController.setCenter(point);
|
||||
} else {
|
||||
showToastOnUiThread(getString(R.string.error_last_location_unknown));
|
||||
}
|
||||
}
|
||||
|
||||
private void startMapFilePicker() {
|
||||
FilePicker.setFileDisplayFilter(FILE_FILTER_EXTENSION_MAP);
|
||||
FilePicker.setFileSelectFilter(new ValidMapFile());
|
||||
startActivityForResult(new Intent(this, FilePicker.class), SELECT_MAP_FILE);
|
||||
}
|
||||
|
||||
private void startRenderThemePicker() {
|
||||
FilePicker.setFileDisplayFilter(FILE_FILTER_EXTENSION_XML);
|
||||
FilePicker.setFileSelectFilter(new ValidRenderTheme());
|
||||
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));
|
||||
}
|
||||
} else if (resultCode == RESULT_CANCELED && !this.mapView.getMapGenerator().requiresInternetConnection()
|
||||
&& this.mapView.getMapFile() == null) {
|
||||
finish();
|
||||
}
|
||||
} 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));
|
||||
} catch (FileNotFoundException e) {
|
||||
showToastOnUiThread(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
// set up the layout views
|
||||
setContentView(R.layout.activity_advanced_map_viewer);
|
||||
this.mapView = (MapView) findViewById(R.id.mapView);
|
||||
configureMapView();
|
||||
|
||||
this.snapToLocationView = (ToggleButton) findViewById(R.id.snapToLocationView);
|
||||
this.snapToLocationView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (isSnapToLocationEnabled()) {
|
||||
disableSnapToLocation(true);
|
||||
} else {
|
||||
enableSnapToLocation(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// get the pointers to different system services
|
||||
this.locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
this.myLocationListener = new MyLocationListener(this);
|
||||
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
this.wakeLock = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
if (id == DIALOG_ENTER_COORDINATES) {
|
||||
builder.setIcon(android.R.drawable.ic_menu_mylocation);
|
||||
builder.setTitle(R.string.menu_position_enter_coordinates);
|
||||
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);
|
||||
|
||||
// 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());
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
return builder.create();
|
||||
} else if (id == DIALOG_LOCATION_PROVIDER_DISABLED) {
|
||||
builder.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
builder.setTitle(R.string.error);
|
||||
builder.setMessage(R.string.no_location_provider_available);
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
return builder.create();
|
||||
} else if (id == DIALOG_INFO_MAP_FILE) {
|
||||
builder.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
builder.setTitle(R.string.menu_info_map_file);
|
||||
LayoutInflater factory = LayoutInflater.from(this);
|
||||
builder.setView(factory.inflate(R.layout.dialog_info_map_file, null));
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
return builder.create();
|
||||
} else {
|
||||
// do dialog will be created
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
disableShowMyLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
// release the wake lock if necessary
|
||||
if (this.wakeLock.isHeld()) {
|
||||
this.wakeLock.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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();
|
||||
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());
|
||||
|
||||
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();
|
||||
|
||||
TextView textView = (TextView) dialog.findViewById(R.id.infoMapFileViewName);
|
||||
textView.setText(this.mapView.getMapFile());
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewSize);
|
||||
textView.setText(FileUtils.formatFileSize(mapFileInfo.fileSize, getResources()));
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewVersion);
|
||||
textView.setText(String.valueOf(mapFileInfo.fileVersion));
|
||||
|
||||
// textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDebug);
|
||||
// if (mapFileInfo.debugFile) {
|
||||
// textView.setText(R.string.info_map_file_debug_yes);
|
||||
// } else {
|
||||
// textView.setText(R.string.info_map_file_debug_no);
|
||||
// }
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewDate);
|
||||
Date date = new Date(mapFileInfo.mapDate);
|
||||
textView.setText(DateFormat.getDateTimeInstance().format(date));
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewArea);
|
||||
BoundingBox boundingBox = mapFileInfo.boundingBox;
|
||||
textView.setText(boundingBox.getMinLatitude() + ", " + boundingBox.getMinLongitude() + " - \n"
|
||||
+ boundingBox.getMaxLatitude() + ", " + boundingBox.getMaxLongitude());
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartPosition);
|
||||
GeoPoint startPosition = mapFileInfo.startPosition;
|
||||
if (startPosition == null) {
|
||||
textView.setText(null);
|
||||
} else {
|
||||
textView.setText(startPosition.getLatitude() + ", " + startPosition.getLongitude());
|
||||
}
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewStartZoomLevel);
|
||||
Byte startZoomLevel = mapFileInfo.startZoomLevel;
|
||||
if (startZoomLevel == null) {
|
||||
textView.setText(null);
|
||||
} else {
|
||||
textView.setText(startZoomLevel.toString());
|
||||
}
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewLanguagePreference);
|
||||
textView.setText(mapFileInfo.languagePreference);
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewComment);
|
||||
textView.setText(mapFileInfo.comment);
|
||||
|
||||
textView = (TextView) dialog.findViewById(R.id.infoMapFileViewCreatedBy);
|
||||
textView.setText(mapFileInfo.createdBy);
|
||||
} else {
|
||||
super.onPrepareDialog(id, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
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"));
|
||||
|
||||
// if (preferences.contains("mapGenerator")) {
|
||||
// String name = preferences.getString("mapGenerator", MapGeneratorInternal.SW_RENDERER.name());
|
||||
// MapGeneratorInternal mapGeneratorInternalNew;
|
||||
// try {
|
||||
// mapGeneratorInternalNew = MapGeneratorInternal.valueOf(name);
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// mapGeneratorInternalNew = MapGeneratorInternal.SW_RENDERER;
|
||||
// }
|
||||
//
|
||||
// if (mapGeneratorInternalNew != this.mapGeneratorInternal) {
|
||||
// MapGenerator mapGenerator = MapGeneratorFactory.createMapGenerator(mapGeneratorInternalNew);
|
||||
// this.mapView.setMapGenerator(mapGenerator);
|
||||
// this.mapGeneratorInternal = mapGeneratorInternalNew;
|
||||
// }
|
||||
// }
|
||||
if (preferences.contains("mapDatabase")) {
|
||||
String name = preferences.getString("mapDatabase", MapDatabaseInternal.MAP_READER.name());
|
||||
MapDatabaseInternal mapDatabaseInternalNew;
|
||||
try {
|
||||
mapDatabaseInternalNew = MapDatabaseInternal.valueOf(name);
|
||||
} catch (IllegalArgumentException e) {
|
||||
mapDatabaseInternalNew = MapDatabaseInternal.MAP_READER;
|
||||
}
|
||||
Log.d("VectorTileMap", "set map database " + mapDatabaseInternalNew);
|
||||
|
||||
if (mapDatabaseInternalNew != this.mapDatabaseInternal) {
|
||||
IMapDatabase mapDatabase = MapDatabaseFactory.createMapDatabase(mapDatabaseInternalNew);
|
||||
this.mapView.setMapDatabase(mapDatabase);
|
||||
this.mapDatabaseInternal = mapDatabaseInternalNew;
|
||||
}
|
||||
}
|
||||
try {
|
||||
String textScaleDefault = getString(R.string.preferences_text_scale_default);
|
||||
this.mapView.setTextScale(Float.parseFloat(preferences.getString("textScale", textScaleDefault)));
|
||||
} catch (NumberFormatException e) {
|
||||
this.mapView.setTextScale(1);
|
||||
}
|
||||
|
||||
if (preferences.getBoolean("fullscreen", false)) {
|
||||
Log.i("mapviewer", "FULLSCREEN");
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
Log.i("mapviewer", "NO FULLSCREEN");
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!this.mapView.getMapGenerator().requiresInternetConnection() && this.mapView.getMapFile() == null) {
|
||||
startMapFilePicker();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the "show my location" mode.
|
||||
*/
|
||||
void disableShowMyLocation() {
|
||||
if (this.showMyLocation) {
|
||||
this.showMyLocation = 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;
|
||||
// }
|
||||
this.snapToLocationView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the "snap to location" mode.
|
||||
*
|
||||
* @param showToast
|
||||
* 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 (showToast) {
|
||||
showToastOnUiThread(getString(R.string.snap_to_location_disabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables the "snap to location" mode.
|
||||
*
|
||||
* @param showToast
|
||||
* defines whether a toast message is displayed or not.
|
||||
*/
|
||||
void enableSnapToLocation(boolean showToast) {
|
||||
if (!this.snapToLocation) {
|
||||
this.snapToLocation = true;
|
||||
this.mapView.setClickable(false);
|
||||
if (showToast) {
|
||||
showToastOnUiThread(getString(R.string.snap_to_location_enabled));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the "show my location" mode.
|
||||
*
|
||||
* @return true if the "show my location" mode is enabled, false otherwise.
|
||||
*/
|
||||
boolean isShowMyLocationEnabled() {
|
||||
return this.showMyLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the "snap to location" mode.
|
||||
*
|
||||
* @return true if the "snap to location" mode is enabled, false otherwise.
|
||||
*/
|
||||
boolean isSnapToLocationEnabled() {
|
||||
return this.snapToLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the UI thread to display the given text message as toast notification.
|
||||
*
|
||||
* @param text
|
||||
* the text message to display
|
||||
*/
|
||||
void showToastOnUiThread(final String text) {
|
||||
|
||||
if (AndroidUtils.currentThreadIsUiThread()) {
|
||||
Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
} else {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast toast = Toast.makeText(TileMap.this, text, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/de/sfb/tilemap/filefilter/FilterByFileExtension.java
Normal file
47
src/de/sfb/tilemap/filefilter/FilterByFileExtension.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
/**
|
||||
* Accepts all readable directories and all readable files with a given extension.
|
||||
*/
|
||||
public class FilterByFileExtension implements FileFilter {
|
||||
private final String extension;
|
||||
|
||||
/**
|
||||
* @param extension
|
||||
* the allowed file name extension.
|
||||
*/
|
||||
public FilterByFileExtension(String extension) {
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
// accept only readable files
|
||||
if (file.canRead()) {
|
||||
if (file.isDirectory()) {
|
||||
// accept all directories
|
||||
return true;
|
||||
} else if (file.isFile() && file.getName().endsWith(this.extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
29
src/de/sfb/tilemap/filefilter/ValidFileFilter.java
Normal file
29
src/de/sfb/tilemap/filefilter/ValidFileFilter.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.filefilter;
|
||||
|
||||
import java.io.FileFilter;
|
||||
|
||||
import org.mapsforge.map.FileOpenResult;
|
||||
|
||||
/**
|
||||
* An extension of the {@link FileFilter} interface.
|
||||
*/
|
||||
public interface ValidFileFilter extends FileFilter {
|
||||
/**
|
||||
* @return the result of the last {@link #accept} call (might be null).
|
||||
*/
|
||||
FileOpenResult getFileOpenResult();
|
||||
}
|
||||
41
src/de/sfb/tilemap/filefilter/ValidMapFile.java
Normal file
41
src/de/sfb/tilemap/filefilter/ValidMapFile.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.mapsforge.map.FileOpenResult;
|
||||
import org.mapsforge.map.IMapDatabase;
|
||||
import org.mapsforge.map.reader.MapDatabase;
|
||||
|
||||
/**
|
||||
* Accepts all valid map files.
|
||||
*/
|
||||
public final class ValidMapFile implements ValidFileFilter {
|
||||
private FileOpenResult fileOpenResult;
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
IMapDatabase mapDatabase = new MapDatabase();
|
||||
this.fileOpenResult = mapDatabase.openFile(file);
|
||||
mapDatabase.closeFile();
|
||||
return this.fileOpenResult.isSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult getFileOpenResult() {
|
||||
return this.fileOpenResult;
|
||||
}
|
||||
}
|
||||
71
src/de/sfb/tilemap/filefilter/ValidRenderTheme.java
Normal file
71
src/de/sfb/tilemap/filefilter/ValidRenderTheme.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.filefilter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.mapsforge.android.maps.rendertheme.RenderThemeHandler;
|
||||
import org.mapsforge.map.FileOpenResult;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
* Accepts all valid render theme XML files.
|
||||
*/
|
||||
public final class ValidRenderTheme implements ValidFileFilter {
|
||||
private FileOpenResult fileOpenResult;
|
||||
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
InputStream inputStream = null;
|
||||
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
RenderThemeHandler renderThemeHandler = new RenderThemeHandler();
|
||||
XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
|
||||
xmlReader.setContentHandler(renderThemeHandler);
|
||||
xmlReader.parse(new InputSource(inputStream));
|
||||
this.fileOpenResult = FileOpenResult.SUCCESS;
|
||||
} catch (ParserConfigurationException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
} catch (SAXException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
this.fileOpenResult = new FileOpenResult(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return this.fileOpenResult.isSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileOpenResult getFileOpenResult() {
|
||||
return this.fileOpenResult;
|
||||
}
|
||||
}
|
||||
244
src/de/sfb/tilemap/filepicker/FilePicker.java
Executable file
244
src/de/sfb/tilemap/filepicker/FilePicker.java
Executable file
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.filepicker;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.GridView;
|
||||
import de.sfb.tilemap.R;
|
||||
import de.sfb.tilemap.filefilter.ValidFileFilter;
|
||||
|
||||
/**
|
||||
* A FilePicker displays the contents of directories. The user can navigate within the file system and select a single
|
||||
* file whose path is then returned to the calling activity. The ordering of directory contents can be specified via
|
||||
* {@link #setFileComparator(Comparator)}. By default subfolders and files are grouped and each group is ordered
|
||||
* alphabetically.
|
||||
* <p>
|
||||
* A {@link FileFilter} can be activated via {@link #setFileDisplayFilter(FileFilter)} to restrict the displayed files
|
||||
* and folders. By default all files and folders are visible.
|
||||
* <p>
|
||||
* Another <code>FileFilter</code> can be applied via {@link #setFileSelectFilter(ValidFileFilter)} to check if a
|
||||
* selected file is valid before its path is returned. By default all files are considered as valid and can be selected.
|
||||
*/
|
||||
public class FilePicker extends Activity implements AdapterView.OnItemClickListener {
|
||||
/**
|
||||
* The name of the extra data in the result {@link Intent}.
|
||||
*/
|
||||
public static final String SELECTED_FILE = "selectedFile";
|
||||
|
||||
private static final String CURRENT_DIRECTORY = "currentDirectory";
|
||||
private static final String DEFAULT_DIRECTORY = "/";
|
||||
private static final int DIALOG_FILE_INVALID = 0;
|
||||
// private static final int DIALOG_FILE_SELECT = 1;
|
||||
private static Comparator<File> fileComparator = getDefaultFileComparator();
|
||||
private static FileFilter fileDisplayFilter;
|
||||
private static ValidFileFilter fileSelectFilter;
|
||||
private static final String PREFERENCES_FILE = "FilePicker";
|
||||
|
||||
/**
|
||||
* Sets the file comparator which is used to order the contents of all directories before displaying them. If set to
|
||||
* null, subfolders and files will not be ordered.
|
||||
*
|
||||
* @param fileComparator
|
||||
* the file comparator (may be null).
|
||||
*/
|
||||
public static void setFileComparator(Comparator<File> fileComparator) {
|
||||
FilePicker.fileComparator = fileComparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file display filter. This filter is used to determine which files and subfolders of directories will be
|
||||
* displayed. If set to null, all files and subfolders are shown.
|
||||
*
|
||||
* @param fileDisplayFilter
|
||||
* the file display filter (may be null).
|
||||
*/
|
||||
public static void setFileDisplayFilter(FileFilter fileDisplayFilter) {
|
||||
FilePicker.fileDisplayFilter = fileDisplayFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file select filter. This filter is used when the user selects a file to determine if it is valid. If set
|
||||
* to null, all files are considered as valid.
|
||||
*
|
||||
* @param fileSelectFilter
|
||||
* the file selection filter (may be null).
|
||||
*/
|
||||
public static void setFileSelectFilter(ValidFileFilter fileSelectFilter) {
|
||||
FilePicker.fileSelectFilter = fileSelectFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the default file comparator.
|
||||
*
|
||||
* @return the default file comparator.
|
||||
*/
|
||||
private static Comparator<File> getDefaultFileComparator() {
|
||||
// order all files by type and alphabetically by name
|
||||
return new Comparator<File>() {
|
||||
@Override
|
||||
public int compare(File file1, File file2) {
|
||||
if (file1.isDirectory() && !file2.isDirectory()) {
|
||||
return -1;
|
||||
} else if (!file1.isDirectory() && file2.isDirectory()) {
|
||||
return 1;
|
||||
} else {
|
||||
return file1.getName().compareToIgnoreCase(file2.getName());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private File currentDirectory;
|
||||
private FilePickerIconAdapter filePickerIconAdapter;
|
||||
private File[] files;
|
||||
private File[] filesWithParentFolder;
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
File selectedFile = this.files[(int) id];
|
||||
if (selectedFile.isDirectory()) {
|
||||
this.currentDirectory = selectedFile;
|
||||
browseToCurrentDirectory();
|
||||
} else if (fileSelectFilter == null || fileSelectFilter.accept(selectedFile)) {
|
||||
setResult(RESULT_OK, new Intent().putExtra(SELECTED_FILE, selectedFile.getAbsolutePath()));
|
||||
finish();
|
||||
} else {
|
||||
showDialog(DIALOG_FILE_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Browses to the current directory.
|
||||
*/
|
||||
private void browseToCurrentDirectory() {
|
||||
setTitle(this.currentDirectory.getAbsolutePath());
|
||||
|
||||
// read the subfolders and files from the current directory
|
||||
if (fileDisplayFilter == null) {
|
||||
this.files = this.currentDirectory.listFiles();
|
||||
} else {
|
||||
this.files = this.currentDirectory.listFiles(fileDisplayFilter);
|
||||
}
|
||||
|
||||
if (this.files == null) {
|
||||
this.files = new File[0];
|
||||
} else {
|
||||
// order the subfolders and files
|
||||
Arrays.sort(this.files, fileComparator);
|
||||
}
|
||||
|
||||
// if a parent directory exists, add it at the first position
|
||||
if (this.currentDirectory.getParentFile() != null) {
|
||||
this.filesWithParentFolder = new File[this.files.length + 1];
|
||||
this.filesWithParentFolder[0] = this.currentDirectory.getParentFile();
|
||||
System.arraycopy(this.files, 0, this.filesWithParentFolder, 1, this.files.length);
|
||||
this.files = this.filesWithParentFolder;
|
||||
this.filePickerIconAdapter.setFiles(this.files, true);
|
||||
} else {
|
||||
this.filePickerIconAdapter.setFiles(this.files, false);
|
||||
}
|
||||
this.filePickerIconAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_file_picker);
|
||||
|
||||
this.filePickerIconAdapter = new FilePickerIconAdapter(this);
|
||||
GridView gridView = (GridView) findViewById(R.id.filePickerView);
|
||||
gridView.setOnItemClickListener(this);
|
||||
gridView.setAdapter(this.filePickerIconAdapter);
|
||||
|
||||
// if (savedInstanceState == null) {
|
||||
// // first start of this instance
|
||||
// showDialog(DIALOG_FILE_SELECT);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
switch (id) {
|
||||
case DIALOG_FILE_INVALID:
|
||||
builder.setIcon(android.R.drawable.ic_menu_info_details);
|
||||
builder.setTitle(R.string.error);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(getString(R.string.file_invalid));
|
||||
stringBuilder.append("\n\n");
|
||||
stringBuilder.append(FilePicker.fileSelectFilter.getFileOpenResult().getErrorMessage());
|
||||
|
||||
builder.setMessage(stringBuilder.toString());
|
||||
builder.setPositiveButton(R.string.ok, null);
|
||||
return builder.create();
|
||||
// case DIALOG_FILE_SELECT:
|
||||
// builder.setMessage(R.string.file_select);
|
||||
// builder.setPositiveButton(R.string.ok, null);
|
||||
// return builder.create();
|
||||
default:
|
||||
// do dialog will be created
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
// save the current directory
|
||||
Editor editor = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE).edit();
|
||||
editor.clear();
|
||||
if (this.currentDirectory != null) {
|
||||
editor.putString(CURRENT_DIRECTORY, this.currentDirectory.getAbsolutePath());
|
||||
}
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// check if the full screen mode should be activated
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen", false)) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
|
||||
// restore the current directory
|
||||
SharedPreferences preferences = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE);
|
||||
this.currentDirectory = new File(preferences.getString(CURRENT_DIRECTORY, DEFAULT_DIRECTORY));
|
||||
if (!this.currentDirectory.exists() || !this.currentDirectory.canRead()) {
|
||||
this.currentDirectory = new File(DEFAULT_DIRECTORY);
|
||||
}
|
||||
browseToCurrentDirectory();
|
||||
}
|
||||
}
|
||||
108
src/de/sfb/tilemap/filepicker/FilePickerIconAdapter.java
Executable file
108
src/de/sfb/tilemap/filepicker/FilePickerIconAdapter.java
Executable file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.filepicker;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import de.sfb.tilemap.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* An adapter for the FilePicker GridView.
|
||||
*/
|
||||
class FilePickerIconAdapter extends BaseAdapter {
|
||||
private final Context context;
|
||||
private File currentFile;
|
||||
private File[] files;
|
||||
private boolean hasParentFolder;
|
||||
private TextView textView;
|
||||
|
||||
/**
|
||||
* Creates a new FilePickerIconAdapter with the given context.
|
||||
*
|
||||
* @param context
|
||||
* the context of this adapter, through which new Views are created.
|
||||
*/
|
||||
FilePickerIconAdapter(Context context) {
|
||||
super();
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (this.files == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.files.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int index) {
|
||||
return this.files[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int index, View convertView, ViewGroup parent) {
|
||||
if (convertView instanceof TextView) {
|
||||
// recycle the old view
|
||||
this.textView = (TextView) convertView;
|
||||
} else {
|
||||
// create a new view object
|
||||
this.textView = new TextView(this.context);
|
||||
this.textView.setLines(2);
|
||||
this.textView.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
this.textView.setPadding(5, 10, 5, 10);
|
||||
}
|
||||
|
||||
if (index == 0 && this.hasParentFolder) {
|
||||
// the parent directory of the current folder
|
||||
this.textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.file_picker_back, 0, 0);
|
||||
this.textView.setText("..");
|
||||
} else {
|
||||
this.currentFile = this.files[index];
|
||||
if (this.currentFile.isDirectory()) {
|
||||
this.textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.file_picker_folder, 0, 0);
|
||||
} else {
|
||||
this.textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.file_picker_file, 0, 0);
|
||||
}
|
||||
this.textView.setText(this.currentFile.getName());
|
||||
}
|
||||
return this.textView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data of this adapter.
|
||||
*
|
||||
* @param files
|
||||
* the new files for this adapter.
|
||||
* @param newHasParentFolder
|
||||
* true if the file array has a parent folder at index 0, false otherwise.
|
||||
*/
|
||||
void setFiles(File[] files, boolean newHasParentFolder) {
|
||||
this.files = files.clone();
|
||||
this.hasParentFolder = newHasParentFolder;
|
||||
}
|
||||
}
|
||||
45
src/de/sfb/tilemap/preferences/EditPreferences.java
Normal file
45
src/de/sfb/tilemap/preferences/EditPreferences.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.preferences;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.WindowManager;
|
||||
import de.sfb.tilemap.R;
|
||||
|
||||
/**
|
||||
* Activity to edit the application preferences.
|
||||
*/
|
||||
public class EditPreferences extends PreferenceActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// check if the full screen mode should be activated
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("fullscreen", false)) {
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
} else {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
154
src/de/sfb/tilemap/preferences/SeekBarPreference.java
Normal file
154
src/de/sfb/tilemap/preferences/SeekBarPreference.java
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.sfb.tilemap.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.preference.DialogPreference;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* This abstract class provides all code for a seek bar preference. Deriving classes only need to set the current and
|
||||
* maximum value of the seek bar. An optional text message above the seek bar is also supported as well as an optional
|
||||
* current value message below the seek bar.
|
||||
*/
|
||||
abstract class SeekBarPreference extends DialogPreference implements OnSeekBarChangeListener {
|
||||
private TextView currentValueTextView;
|
||||
private Editor editor;
|
||||
private SeekBar preferenceSeekBar;
|
||||
|
||||
/**
|
||||
* How much the value should increase when the seek bar is moved.
|
||||
*/
|
||||
int increment = 1;
|
||||
|
||||
/**
|
||||
* The maximum value of the seek bar.
|
||||
*/
|
||||
int max;
|
||||
|
||||
/**
|
||||
* Optional text message to display on top of the seek bar.
|
||||
*/
|
||||
String messageText;
|
||||
|
||||
/**
|
||||
* The SharedPreferences instance that is used.
|
||||
*/
|
||||
final SharedPreferences preferencesDefault;
|
||||
|
||||
/**
|
||||
* The current value of the seek bar.
|
||||
*/
|
||||
int seekBarCurrentValue;
|
||||
|
||||
/**
|
||||
* Create a new seek bar preference.
|
||||
*
|
||||
* @param context
|
||||
* the context of the seek bar preferences activity.
|
||||
* @param attrs
|
||||
* A set of attributes (currently ignored).
|
||||
*/
|
||||
SeekBarPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.preferencesDefault = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// check if the "OK" button was pressed and the seek bar value has changed
|
||||
if (which == DialogInterface.BUTTON_POSITIVE
|
||||
&& this.seekBarCurrentValue != this.preferenceSeekBar.getProgress()) {
|
||||
// get the value of the seek bar and save it in the preferences
|
||||
this.seekBarCurrentValue = this.preferenceSeekBar.getProgress();
|
||||
this.editor = this.preferencesDefault.edit();
|
||||
this.editor.putInt(this.getKey(), this.seekBarCurrentValue);
|
||||
this.editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
if (this.currentValueTextView != null) {
|
||||
this.currentValueTextView.setText(getCurrentValueText(progress));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View onCreateDialogView() {
|
||||
// create a layout for the optional text messageText and the seek bar
|
||||
LinearLayout linearLayout = new LinearLayout(getContext());
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
linearLayout.setPadding(20, 10, 20, 10);
|
||||
|
||||
// check if a text message should appear above the seek bar
|
||||
if (this.messageText != null) {
|
||||
// create a text view for the text messageText
|
||||
TextView messageTextView = new TextView(getContext());
|
||||
messageTextView.setText(this.messageText);
|
||||
messageTextView.setPadding(0, 0, 0, 20);
|
||||
// add the text message view to the layout
|
||||
linearLayout.addView(messageTextView);
|
||||
}
|
||||
|
||||
// create the seek bar and set the maximum and current value
|
||||
this.preferenceSeekBar = new SeekBar(getContext());
|
||||
this.preferenceSeekBar.setOnSeekBarChangeListener(this);
|
||||
this.preferenceSeekBar.setMax(this.max);
|
||||
this.preferenceSeekBar.setProgress(Math.min(this.seekBarCurrentValue, this.max));
|
||||
this.preferenceSeekBar.setKeyProgressIncrement(this.increment);
|
||||
this.preferenceSeekBar.setPadding(0, 0, 0, 10);
|
||||
// add the seek bar to the layout
|
||||
linearLayout.addView(this.preferenceSeekBar);
|
||||
|
||||
// create the text view for the current value below the seek bar
|
||||
this.currentValueTextView = new TextView(getContext());
|
||||
this.currentValueTextView.setText(getCurrentValueText(this.preferenceSeekBar.getProgress()));
|
||||
this.currentValueTextView.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||
// add the current value text view to the layout
|
||||
linearLayout.addView(this.currentValueTextView);
|
||||
|
||||
return linearLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value text.
|
||||
*
|
||||
* @param progress
|
||||
* the current progress level of the seek bar.
|
||||
* @return the new current value text
|
||||
*/
|
||||
abstract String getCurrentValueText(int progress);
|
||||
}
|
||||
Reference in New Issue
Block a user