Show GPX on map dialog fix

This commit is contained in:
GaidamakUA 2015-09-11 16:35:11 +03:00
parent fa06bee75b
commit 7765383d85
4 changed files with 104 additions and 111 deletions

View file

@ -1,32 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip">
android:orientation="horizontal">
<ImageView
android:layout_marginLeft="14dip"
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="center_vertical"
android:layout_marginLeft="24dp"
android:gravity="center"
android:layout_gravity="center_vertical" />
android:visibility="gone"/>
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dip"
android:layout_marginTop="11dip"
android:layout_marginBottom="11dip"
android:layout_marginLeft="12dp"
android:layout_marginTop="11dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="@string/layer_poi"
android:textSize="@dimen/default_list_text_size"
android:layout_weight="1" />
android:textSize="@dimen/default_list_text_size"/>
<LinearLayout
android:layout_width="wrap_content"
@ -37,17 +36,17 @@
android:id="@+id/icon_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center_vertical"
android:visibility="gone"
android:focusable="false" />
android:visibility="gone"/>
<!-- android:button="@drawable/ic_btn_wocheckbox" -->
<CheckBox
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="6dip"
android:focusable="false" />
android:layout_marginRight="24dp"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>

View file

@ -2261,4 +2261,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="recent_places">Recent places</string>
<string name="favourites">Favourites</string>
<string name="saved_at_time">Successfully saved at: %1$s</string>
<string name="poi_deleted_localy">POI will be deleted once you upload your changes</string>
<string name="show_gpx">Show GPX</string>
</resources>

View file

@ -5,7 +5,6 @@ import android.app.Application;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Build;
import android.support.v7.app.AlertDialog;
import android.util.TypedValue;
import android.view.View;
@ -53,9 +52,8 @@ public class GpxUiHelper {
}
public static String getColorValue(String clr, String value, boolean html) {
if(!html) {
if (!html) {
return value;
}
return "<font color=\"" + clr + "\">" + value + "</font>";
@ -67,7 +65,7 @@ public class GpxUiHelper {
public static String getDescription(OsmandApplication app, GPXTrackAnalysis analysis, boolean html) {
StringBuilder description = new StringBuilder();
String nl = html?"<br/>":"\n";
String nl = html ? "<br/>" : "\n";
String timeSpanClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_time_span_color));
String distanceClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_distance_color));
String speedClr = Algorithms.colorToString(app.getResources().getColor(R.color.gpx_speed));
@ -76,31 +74,31 @@ public class GpxUiHelper {
// OUTPUT:
// 1. Total distance, Start time, End time
description.append(app.getString(R.string.gpx_info_distance, getColorValue(distanceClr,
OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app), html),
getColorValue(distanceClr, analysis.points+"", html) ));
if(analysis.totalTracks > 1) {
description.append(nl).append(app.getString(R.string.gpx_info_subtracks, getColorValue(speedClr, analysis.totalTracks+"", html)));
OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app), html),
getColorValue(distanceClr, analysis.points + "", html)));
if (analysis.totalTracks > 1) {
description.append(nl).append(app.getString(R.string.gpx_info_subtracks, getColorValue(speedClr, analysis.totalTracks + "", html)));
}
if(analysis.wptPoints > 0) {
description.append(nl).append(app.getString(R.string.gpx_info_waypoints, getColorValue(speedClr, analysis.wptPoints+"", html)));
if (analysis.wptPoints > 0) {
description.append(nl).append(app.getString(R.string.gpx_info_waypoints, getColorValue(speedClr, analysis.wptPoints + "", html)));
}
if(analysis.isTimeSpecified()) {
description.append(nl).append(app.getString(R.string.gpx_info_start_time, analysis.startTime));
description.append(nl).append(app.getString(R.string.gpx_info_end_time, analysis.endTime));
if (analysis.isTimeSpecified()) {
description.append(nl).append(app.getString(R.string.gpx_info_start_time, analysis.startTime));
description.append(nl).append(app.getString(R.string.gpx_info_end_time, analysis.endTime));
}
// 2. Time span
if(analysis.timeSpan > 0 && analysis.timeSpan / 1000 != analysis.timeMoving / 1000) {
final String formatDuration = Algorithms.formatDuration((int) (analysis.timeSpan/1000)
);
if (analysis.timeSpan > 0 && analysis.timeSpan / 1000 != analysis.timeMoving / 1000) {
final String formatDuration = Algorithms.formatDuration((int) (analysis.timeSpan / 1000)
);
description.append(nl).append(app.getString(R.string.gpx_timespan,
getColorValue(timeSpanClr, formatDuration, html)));
}
// 3. Time moving, if any
if(analysis.isTimeMoving()){
final String formatDuration = Algorithms.formatDuration((int) (analysis.timeMoving/1000)
);
if (analysis.isTimeMoving()) {
final String formatDuration = Algorithms.formatDuration((int) (analysis.timeMoving / 1000)
);
description.append(nl).append(app.getString(R.string.gpx_timemoving,
getColorValue(timeSpanClr, formatDuration, html)));
}
@ -115,32 +113,32 @@ public class GpxUiHelper {
String max = getColorValue(ascClr, OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app), html);
String asc = getColorValue(ascClr, OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app), html);
String desc = getColorValue(descClr, OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app), html);
description.append(app.getString(R.string.gpx_info_diff_altitude,min +" - " + max ));
description.append(app.getString(R.string.gpx_info_diff_altitude, min + " - " + max));
description.append(nl);
description.append(app.getString(R.string.gpx_info_asc_altitude,"\u2193 " + desc + " \u2191 " + asc + ""));
description.append(app.getString(R.string.gpx_info_asc_altitude, "\u2193 " + desc + " \u2191 " + asc + ""));
}
if(analysis.isSpeedSpecified()){
if (analysis.isSpeedSpecified()) {
String avg = getColorValue(speedClr, OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app), html);
String max = getColorValue(ascClr, OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app), html);
description.append(nl).append(app.getString(R.string.gpx_info_average_speed,avg));
description.append(nl).append(app.getString(R.string.gpx_info_maximum_speed,max));
description.append(nl).append(app.getString(R.string.gpx_info_average_speed, avg));
description.append(nl).append(app.getString(R.string.gpx_info_maximum_speed, max));
}
return description.toString();
}
public static AlertDialog selectGPXFile(List<String> selectedGpxList, final Activity activity,
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject){
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, false);
if(allGpxList.isEmpty()){
if (allGpxList.isEmpty()) {
AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
}
if(!allGpxList.isEmpty() || showCurrentGpx){
if(showCurrentGpx){
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,
@ -152,15 +150,15 @@ public class GpxUiHelper {
}
public static AlertDialog selectGPXFile(final Activity activity,
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject) {
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> list = getSortedGPXFilenames(dir, false);
if(list.isEmpty()){
if (list.isEmpty()) {
AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
}
if(!list.isEmpty() || showCurrentGpx){
if(showCurrentGpx){
if (!list.isEmpty() || showCurrentGpx) {
if (showCurrentGpx) {
list.add(0, activity.getString(R.string.show_current_gpx_title));
}
@ -197,9 +195,9 @@ public class GpxUiHelper {
}
protected static void updateSelection(List<String> selectedGpxList, boolean showCurrentTrack,
final ContextMenuAdapter adapter, int i, String fileName) {
if(i == 0 && showCurrentTrack) {
if(selectedGpxList.contains("")) {
final ContextMenuAdapter adapter, int i, String fileName) {
if (i == 0 && showCurrentTrack) {
if (selectedGpxList.contains("")) {
adapter.setSelection(i, 1);
}
} else {
@ -213,7 +211,7 @@ public class GpxUiHelper {
}
private static void setDescripionInDialog(final ArrayAdapter<?> adapter, final ContextMenuAdapter cmAdapter, Activity activity,
final File dir, String filename, final int position) {
final File dir, String filename, final int position) {
final Application app = activity.getApplication();
final File f = new File(dir, filename);
loadGPXFileInDifferentThread(activity, new CallbackWithObject<GPXUtilities.GPXFile[]>() {
@ -228,19 +226,14 @@ public class GpxUiHelper {
}
private static AlertDialog createDialog(final Activity activity, final boolean showCurrentGpx,
final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject,
final List<String> list, final ContextMenuAdapter adapter) {
final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject,
final List<String> list, final ContextMenuAdapter adapter) {
final OsmandApplication app = (OsmandApplication) activity.getApplication();
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
AlertDialog.Builder b = new AlertDialog.Builder(activity);
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
// final int padding = (int) (12 * activity.getResources().getDisplayMetrics().density + 0.5f);
final boolean light = app.getSettings().isLightContent();
final int layout;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
layout = R.layout.list_menu_item;
} else {
layout = R.layout.list_menu_item_native;
}
final int layout = R.layout.list_menu_item_native;
final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.title,
adapter.getItemNames()) {
@ -258,7 +251,7 @@ public class GpxUiHelper {
return;
}
int nline = adapter.getItemName(position).indexOf('\n');
if(nline == -1) {
if (nline == -1) {
setDescripionInDialog(arrayAdapter, adapter, activity, dir, list.get(position), position);
} else {
adapter.setItemName(position, adapter.getItemName(position).substring(0, nline));
@ -267,7 +260,7 @@ public class GpxUiHelper {
}
});
if(showCurrentGpx && position == 0) {
if (showCurrentGpx && position == 0) {
icon.setVisibility(View.INVISIBLE);
} else {
icon.setVisibility(View.VISIBLE);
@ -303,35 +296,37 @@ public class GpxUiHelper {
public void onClick(DialogInterface dialog, int position) {
}
};
b.setAdapter(listAdapter, onClickListener);
builder.setAdapter(listAdapter, onClickListener);
if (multipleChoice) {
b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
builder.setTitle(R.string.show_gpx)
.setPositiveButton(R.string.shared_string_ok, new OnClickListener() {
@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();
}
List<String> s = new ArrayList<String>();
for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
if (adapter.getSelection(i) > 0) {
s.add(list.get(i));
@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();
}
List<String> s = new ArrayList<>();
for (int i = (showCurrentGpx ? 1 : 0); i < adapter.length(); i++) {
if (adapter.getSelection(i) > 0) {
s.add(list.get(i));
}
}
dialog.dismiss();
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, currentGPX,
s.toArray(new String[s.size()]));
}
}
dialog.dismiss();
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, currentGPX,
s.toArray(new String[s.size()]));
}
});
})
.setNegativeButton(R.string.shared_string_cancel, null);
}
final AlertDialog dlg = b.create();
final AlertDialog dlg = builder.create();
dlg.setCanceledOnTouchOutside(true);
dlg.getListView().setOnItemClickListener(new OnItemClickListener() {
@Override
@ -360,16 +355,16 @@ public class GpxUiHelper {
}
public static List<String> getSortedGPXFilenamesByDate(File dir, boolean absolutePath) {
final Map<String, Long> mp = new HashMap<String, Long>();
final Map<String, Long> mp = new HashMap<>();
readGpxDirectory(dir, mp, "", absolutePath);
ArrayList<String> list = new ArrayList<String>(mp.keySet());
ArrayList<String> list = new ArrayList<>(mp.keySet());
Collections.sort(list, new Comparator<String>() {
@Override
public int compare(String object1, String object2) {
Long l1 = mp.get(object1);
Long l2 = mp.get(object2);
long lhs = l1 == null ? 0 : l1.longValue();
long rhs = l2 == null ? 0 : l2.longValue();
long lhs = l1 == null ? 0 : l1;
long rhs = l2 == null ? 0 : l2;
return lhs < rhs ? 1 : (lhs == rhs ? 0 : -1);
}
});
@ -378,9 +373,9 @@ public class GpxUiHelper {
public static List<String> getSortedGPXFilenames(File dir, boolean absolutePath) {
final Map<String, Long> mp = new HashMap<String, Long>();
final Map<String, Long> mp = new HashMap<>();
readGpxDirectory(dir, mp, "", absolutePath);
ArrayList<String> list = new ArrayList<String>(mp.keySet());
ArrayList<String> list = new ArrayList<>(mp.keySet());
Collections.sort(list, new Comparator<String>() {
@Override
public int compare(String object1, String object2) {
@ -392,7 +387,7 @@ public class GpxUiHelper {
}
private static void readGpxDirectory(File dir, final Map<String, Long> map, String parent,
boolean absolutePath) {
boolean absolutePath) {
if (dir != null && dir.canRead()) {
File[] files = dir.listFiles();
if (files != null) {
@ -409,7 +404,7 @@ public class GpxUiHelper {
}
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
final File dir, final GPXFile currentFile, final String... filename) {
final File dir, final GPXFile currentFile, final String... filename) {
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""),
activity.getString(R.string.loading_data));
new Thread(new Runnable() {

View file

@ -20,8 +20,6 @@ import net.osmand.plus.osmedit.OpenstreetmapUtil;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmedit.OsmPoint;
import java.text.MessageFormat;
public class DeletePoiDialogFragment extends DialogFragment {
private static final String KEY_AMENITY_NODE = "amenity_node";
@ -47,9 +45,8 @@ public class DeletePoiDialogFragment extends DialogFragment {
new Runnable() {
@Override
public void run() {
AccessibleToast.makeText(activity, MessageFormat.format(
getString(R.string.poi_action_succeded_template),
getString(R.string.poi_action_delete)),
AccessibleToast.makeText(activity,
getString(R.string.poi_deleted_localy),
Toast.LENGTH_LONG).show();
if (activity instanceof MapActivity) {
((MapActivity) activity).getMapView().refreshMap(true);