Merge pull request #730 from Bars107/master

Added settings buttons for Gpx and POI in layot menu. Created straight route service.
This commit is contained in:
vshcherb 2014-07-04 17:05:08 +02:00
commit b4872ff81a
6 changed files with 182 additions and 55 deletions

View file

@ -31,18 +31,24 @@
android:textColor="@color/color_black" android:layout_weight="1"/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:gravity="center_vertical">
<ImageView android:id="@+id/icon_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone"
android:focusable="false"/>
<CheckBox
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dip"
android:layout_marginRight="2dip"
android:button="@drawable/ic_btn_wocheckbox"
android:focusable="false"
android:gravity="center_vertical" />
/>
</LinearLayout>
</LinearLayout>

View file

@ -30,17 +30,23 @@
android:layout_weight="1"/>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:gravity="center_vertical">
<ImageView android:id="@+id/icon_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:visibility="gone"
android:focusable="false"/>
<!-- android:button="@drawable/ic_btn_wocheckbox" -->
<CheckBox
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dip"
android:layout_marginRight="2dip"
android:focusable="false"
android:gravity="center_vertical" />
android:focusable="false" />
</LinearLayout>
</LinearLayout>

View file

@ -6,6 +6,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import android.widget.*;
import net.osmand.CallbackWithObject;
import net.osmand.ResultMatcher;
import net.osmand.StateChangedListener;
@ -13,20 +14,12 @@ import net.osmand.access.AccessibleToast;
import net.osmand.data.AmenityType;
import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.*;
import net.osmand.plus.ContextMenuAdapter.Item;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.MapVectorLayer;
@ -55,15 +48,8 @@ import android.content.Intent;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
/**
* Object is responsible to maintain layers using by map activity
@ -90,9 +76,11 @@ public class MapActivityLayers {
private ContextMenuLayer contextMenuLayer;
private MapControlsLayer mapControlsLayer;
private DownloadedRegionsLayer downloadedRegionsLayer;
private GpxSelectionHelper gpxSelectionHelper;
public MapActivityLayers(MapActivity activity) {
this.activity = activity;
gpxSelectionHelper = getApplication().getSelectedGpxHelper();
}
public OsmandApplication getApplication(){
@ -261,7 +249,7 @@ public class MapActivityLayers {
getApplication().getSelectedGpxHelper().clearAllGpxFileToShow();
} else {
dialog.dismiss();
showGPXFileLayer(mapView);
showGPXFileLayer(getAlreadySelectedGpx(), mapView);
}
} else if(itemId == R.string.layer_transport_route){
transportInfoLayer.setVisible(isChecked);
@ -321,6 +309,41 @@ public class MapActivityLayers {
TextView tv = (TextView)v.findViewById(R.id.title);
tv.setText(adapter.getItemName(position));
//if it's gpx or poi layer - need to show settings icon
//need imageview and specialItemId o
final ImageView settingsImage = (ImageView) v.findViewById(R.id.icon_settings);
final int specialItemId = adapter.getItemId(position);
if ((specialItemId == R.string.layer_poi || specialItemId == R.string.layer_gpx_layer)
&& adapter.getSelection(position) > 0) {
settingsImage.setVisibility(View.VISIBLE);
//setting icon depending on theme
if(light){
settingsImage.setImageResource(R.drawable.ic_action_settings_light);
} else {
settingsImage.setImageResource(R.drawable.ic_action_settings_dark);
}
if (specialItemId == R.string.layer_poi){
settingsImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
selectPOIFilterLayer(mapView);
}
});
} else if (specialItemId == R.string.layer_gpx_layer) {
settingsImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener.dialog != null) {
listener.dialog.dismiss();
}
showGPXFileLayer(getAlreadySelectedGpx(), mapView);
}
});
}
}
//Put the image on the TextView
if(adapter.getImageId(position, light) != 0) {
tv.setCompoundDrawablesWithIntrinsicBounds(adapter.getImageId(position, light), 0, 0, 0);
@ -338,6 +361,13 @@ public class MapActivityLayers {
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (specialItemId == R.string.layer_poi){
if (isChecked){
settingsImage.setVisibility(View.VISIBLE);
} else {
settingsImage.setVisibility(View.GONE);
}
}
listener.onClick(position, isChecked);
}
});
@ -373,9 +403,9 @@ public class MapActivityLayers {
dlg.show();
}
public void showGPXFileLayer(final OsmandMapTileView mapView){
public void showGPXFileLayer(List<String> files, final OsmandMapTileView mapView) {
final OsmandSettings settings = getApplication().getSettings();
GpxUiHelper.selectGPXFile(activity, true, true, new CallbackWithObject<GPXFile[]>() {
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
@Override
public boolean processResult(GPXFile[] result) {
WptPt locToShow = null;
@ -398,11 +428,27 @@ public class MapActivityLayers {
mapView.refreshMap();
return true;
}
});
};
if (files == null) {
GpxUiHelper.selectGPXFile(activity, true, true, callbackWithObject);
} else {
GpxUiHelper.selectGPXFile(files, activity, true, true, callbackWithObject);
}
}
private List<String> getAlreadySelectedGpx(){
if (gpxSelectionHelper == null){
return null;
}
List<GpxSelectionHelper.SelectedGpxFile> selectedGpxFiles = gpxSelectionHelper.getSelectedGPXFiles();
List<String> files = new ArrayList<String>();
for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) {
files.add(file.getGpxFile().path);
}
return files;
}
private void selectPOIFilterLayer(final OsmandMapTileView mapView){

View file

@ -128,6 +128,24 @@ public class GpxUiHelper {
return description.toString();
}
public static void selectGPXFile(List<String> selectedGpxList, final Activity activity,
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject){
OsmandApplication app = (OsmandApplication) activity.getApplication();
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
final List<String> allGpxList = getSortedGPXFilenames(dir);
if(allGpxList.isEmpty()){
AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
}
if(!allGpxList.isEmpty() || showCurrentGpx){
if(showCurrentGpx){
allGpxList.add(0, activity.getString(R.string.show_current_gpx_title));
}
final ContextMenuAdapter adapter = createGpxContextMenuAdapter(activity,allGpxList, selectedGpxList, multipleChoice);
createDialog(activity, showCurrentGpx, multipleChoice, callbackWithObject, allGpxList, adapter);
}
}
public static void selectGPXFile(final Activity activity,
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
@ -137,22 +155,42 @@ public class GpxUiHelper {
AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
}
if(!list.isEmpty() || showCurrentGpx){
final ContextMenuAdapter adapter = new ContextMenuAdapter(activity);
if(showCurrentGpx){
list.add(0, activity.getString(R.string.show_current_gpx_title));
}
for(String s : list) {
final ContextMenuAdapter adapter = createGpxContextMenuAdapter(activity, list, null, multipleChoice);
createDialog(activity, showCurrentGpx, multipleChoice, callbackWithObject, list, adapter);
}
}
private static ContextMenuAdapter createGpxContextMenuAdapter(Activity activity, List<String> allGpxList, List<String> selectedGpxList, boolean multipleChoice) {
final ContextMenuAdapter adapter = new ContextMenuAdapter(activity);
//element position in adapter
int i = 0;
for (String s : allGpxList) {
String fileName = s;
if (s.endsWith(".gpx")) {
s = s.substring(0, s.length() - ".gpx".length());
}
s = s.replace('_', ' ');
adapter.item(s).selected(multipleChoice ? 0 : -1)
.icons(R.drawable.ic_action_info_dark, R.drawable.ic_action_info_light).reg();
//if there's some selected files - need to mark them as selected
if (selectedGpxList != null) {
for (String file : selectedGpxList) {
if (file.endsWith(fileName)) {
adapter.setSelection(i, 1);
break;
}
createDialog(activity, showCurrentGpx, multipleChoice, callbackWithObject, list, adapter);
}
}
i++;
}
return adapter;
}
private static void setDescripionInDialog(final ArrayAdapter<?> adapter, final ContextMenuAdapter cmAdapter, Activity activity,
final File dir, String filename, final int position) {
@ -252,6 +290,11 @@ public class GpxUiHelper {
@Override
public void onClick(DialogInterface dialog, int which) {
GPXFile currentGPX = null;
//clear all previously selected files before adding new one
OsmandApplication app = (OsmandApplication) activity.getApplication();
if(app != null && app.getSelectedGpxHelper() != null){
app.getSelectedGpxHelper().clearAllGpxFileToShow();
}
if (showCurrentGpx && adapter.getSelection(0) > 0) {
currentGPX = app.getSavingTrackHelper().getCurrentGpx();
}

View file

@ -77,7 +77,7 @@ public class RouteProvider {
public enum RouteService {
OSMAND("OsmAnd (offline)"), YOURS("YOURS"),
ORS("OpenRouteService"), OSRM("OSRM (only car)"),
BROUTER("BRouter (offline)");
BROUTER("BRouter (offline)"), STRAIGHT("Straight line");
private final String name;
private RouteService(String name){
this.name = name;
@ -324,7 +324,10 @@ public class RouteProvider {
res = findORSRoute(params);
} else if (params.type == RouteService.OSRM) {
res = findOSRMRoute(params);
} else {
} else if (params.type == RouteService.STRAIGHT){
res = findStraightRoute(params);
}
else {
res = new RouteCalculationResult("Selected route service is not available");
}
if(log.isInfoEnabled() ){
@ -344,7 +347,6 @@ public class RouteProvider {
return new RouteCalculationResult(null);
}
public RouteCalculationResult recalculatePartOfflineRoute(RouteCalculationResult res, RouteCalculationParams params) {
RouteCalculationResult rcr = params.previousToRecalculate;
List<Location> locs = new ArrayList<Location>(rcr.getRouteLocations());
@ -1206,6 +1208,30 @@ public class RouteProvider {
return new RouteCalculationResult(res, null, params, null);
}
private RouteCalculationResult findStraightRoute(RouteCalculationParams params) {
double[] lats = new double[] { params.start.getLatitude(), params.end.getLatitude() };
double[] lons = new double[] { params.start.getLongitude(), params.end.getLongitude() };
List<LatLon> intermediates = params.intermediates;
List<Location> dots = new ArrayList<Location>();
//writing start location
Location location = new Location(String.valueOf("start"));
location.setLatitude(lats[0]);
location.setLongitude(lons[0]);
//adding intermediate dots if they exists
if (intermediates != null){
for(int i =0; i<intermediates.size();i++){
location = new Location(String.valueOf(i));
location.setLatitude(intermediates.get(i).getLatitude());
location.setLongitude(intermediates.get(i).getLongitude());
dots.add(location);
}
}
//writing end location
location = new Location(String.valueOf("end"));
location.setLatitude(lats[1]);
location.setLongitude(lons[1]);
dots.add(location);
return new RouteCalculationResult(dots,null,params,null);
}
}