Fix bugs / deselect gpx from available (visible in settings)/show points and context menu for selected items

This commit is contained in:
Victor Shcherb 2014-06-25 17:30:47 +02:00
parent dcf71bf07e
commit 529b20283d
12 changed files with 227 additions and 50 deletions

View file

@ -37,6 +37,7 @@ public class IndexConstants {
public static final String MAPS_PATH = "";
public static final String BACKUP_INDEX_DIR= "backup/";
public static final String GPX_INDEX_DIR = "tracks/";
public static final String GPX_RECORDED_INDEX_DIR = GPX_INDEX_DIR + "rec/";
public static final String GPX_IMPORT_DIR = GPX_INDEX_DIR + "import/";
public static final String TILES_INDEX_DIR= "tiles/";
public static final String TOURS_INDEX_DIR= "tours/";

View file

@ -20,6 +20,7 @@ public class RenderingRuleStorageProperties {
public static final String NAME_TAG = "nameTag";
public static final String NAME_TAG2 = "nameTag2";
public static final String TEXT_SHIELD = "textShield";
public static final String SHIELD = "shield";
public static final String SHADOW_RADIUS = "shadowRadius";
public static final String SHADOW_COLOR = "shadowColor";
public static final String SHADER = "shader";
@ -81,6 +82,7 @@ public class RenderingRuleStorageProperties {
public RenderingRuleProperty R_NAME_TAG;
public RenderingRuleProperty R_NAME_TAG2;
public RenderingRuleProperty R_TEXT_SHIELD;
public RenderingRuleProperty R_SHIELD;
public RenderingRuleProperty R_SHADOW_RADIUS;
public RenderingRuleProperty R_SHADOW_COLOR;
public RenderingRuleProperty R_SHADER;
@ -199,6 +201,7 @@ public class RenderingRuleStorageProperties {
// point
R_ICON = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(ICON));
R_SHIELD = registerRuleInternal(RenderingRuleProperty.createOutputStringProperty(SHIELD));
// polygon/way
R_COLOR = registerRuleInternal(RenderingRuleProperty.createOutputColorProperty(COLOR));

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:stretchColumns="1" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/visible_element" />
<CheckBox
android:id="@+id/Visibility"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gpx_split_interval" >
</TextView>
<Spinner
android:id="@+id/Spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" >
</Spinner>
</TableRow>
</TableLayout>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="gpx_split_interval">Split interval</string>
<string name="sort_by_distance">Sort by distance</string>
<string name="sort_by_name">Sort by name</string>
<string name="visible_element">Visible</string>
@ -23,7 +24,6 @@
<string name="selected_gpx_info_show">\n\nPress and hold to see on map</string>
<string name="delay_navigation_start">Start navigation with delay</string>
<string name="selected">selected</string>
<string name="gpx_split_interval">Select split interval</string>
<string name="local_index_gpx_info_show">\n\nPress and hold for options</string>
<string name="gpx_info_subtracks">Subtracks: %1$s </string>
<string name="gpx_info_waypoints">Waypoints: %1$s </string>

View file

@ -163,6 +163,8 @@ public class GPXUtilities {
public int wptPoints = 0;
public double metricEnd;
public WptPt locationStart;
public WptPt locationEnd;
public boolean isTimeSpecified() {
return startTime != Long.MAX_VALUE && startTime != 0;
@ -206,12 +208,19 @@ public class GPXUtilities {
int speedCount = 0;
double totalSpeedSum = 0;
points = 0;
for (SplitSegment s : splitSegments) {
final int numberOfPoints = s.getNumberOfPoints();
metricEnd += s.metricEnd;
points += numberOfPoints;
for (int j = 0; j < numberOfPoints; j++) {
WptPt point = s.get(j);
if(j == 0 && locationStart == null) {
locationStart = point;
}
if(j == numberOfPoints - 1) {
locationEnd = point;
}
long time = point.time;
if (time != 0) {
startTime = Math.min(startTime, time);

View file

@ -123,14 +123,12 @@ public class GpxSelectionHelper {
GpxDisplayItem item = new GpxDisplayItem();
item.group = group;
item.description = r.desc;
item.expanded = true;
item.name = r.name;
t++;
if (Algorithms.isEmpty(item.name)) {
item.name = getString(R.string.gpx_selection_point, t + "");
}
if(Algorithms.isEmpty(item.description)) {
item.description = item.name;
}
item.locationStart = r;
item.locationEnd = r;
list.add(item);
@ -155,9 +153,7 @@ public class GpxSelectionHelper {
if (Algorithms.isEmpty(item.name)) {
item.name = getString(R.string.gpx_selection_point, k + "");
}
if(Algorithms.isEmpty(item.description)) {
item.description = item.name;
}
item.expanded = true;
item.locationStart = r;
item.locationEnd = r;
list.add(item);
@ -231,8 +227,8 @@ public class GpxSelectionHelper {
}
}
item.name = name;
item.locationStart = r.points.get(0);
item.locationEnd = r.points.get(r.points.size() - 1);
item.locationStart = analysis.locationStart;
item.locationEnd = analysis.locationEnd;
list.add(item);
}
}
@ -428,6 +424,10 @@ public class GpxSelectionHelper {
this.track = track;
}
public GPXFile getGpx() {
return gpx;
}
public Track getTrack() {
return track;
}

View file

@ -144,9 +144,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
*/
public List<String> saveDataToGpx() {
List<String> warnings = new ArrayList<String>();
File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR);
if (dir.getParentFile().canWrite()) {
File dir = ctx.getAppPath(IndexConstants.GPX_RECORDED_INDEX_DIR);
dir.mkdirs();
if (dir.getParentFile().canWrite()) {
if (dir.exists()) {
Map<String, GPXFile> data = collectRecordedData();

View file

@ -2,13 +2,15 @@ package net.osmand.plus.activities;
import gnu.trove.list.array.TIntArrayList;
import java.io.File;
import java.text.Collator;
import java.util.ArrayList;
import java.util.List;
import net.osmand.access.AccessibleToast;
import net.londatiga.android.QuickAction;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
@ -16,9 +18,10 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
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.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.activities.AvailableGPXFragment.LoadGpxTask;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.Algorithms;
import android.app.Activity;
@ -26,18 +29,24 @@ import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.SectionIndexer;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
@ -87,6 +96,60 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
selectedGpxHelper.setUiListener(null);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View vs = super.onCreateView(inflater, container, savedInstanceState);
getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
long packedPos = ((ExpandableListContextMenuInfo) menuInfo).packedPosition;
int group = ExpandableListView.getPackedPositionGroup(packedPos);
int child = ExpandableListView.getPackedPositionChild(packedPos);
if (child >= 0 && group >= 0) {
showContextMenu(adapter.getChild(group, child));
}
}
});
return vs;
}
private void showContextMenu(final GpxDisplayItem gpxDisplayItem) {
Builder builder = new AlertDialog.Builder(getActivity());
final ContextMenuAdapter adapter = new ContextMenuAdapter(getActivity());
basicFileOperation(gpxDisplayItem, adapter);
String[] values = adapter.getItemNames();
builder.setItems(values, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
OnContextMenuClick clk = adapter.getClickAdapter(which);
if (clk != null) {
clk.onContextMenuClick(adapter.getItemId(which), which, false, dialog);
}
}
});
builder.show();
}
private void basicFileOperation(final GpxDisplayItem gpxDisplayItem, ContextMenuAdapter adapter) {
OnContextMenuClick listener = new OnContextMenuClick() {
@Override
public void onContextMenuClick(int resId, int pos, boolean isChecked, DialogInterface dialog) {
if (resId == R.string.show_gpx_route) {
OsmandSettings settings = getMyApplication().getSettings();
settings.setMapLocationToShow(gpxDisplayItem.locationStart.lat, gpxDisplayItem.locationStart.lon,
settings.getLastKnownMapZoom(), gpxDisplayItem.name);
MapActivity.launchMapActivityMoveToTop(getActivity());
}
}
};
if (gpxDisplayItem.locationStart != null) {
adapter.item(R.string.show_gpx_route).listen(listener).reg();
}
OsmandPlugin.onContextMenuActivity(getSherlockActivity(), this, gpxDisplayItem, adapter);
}
@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
@ -164,7 +227,8 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
List<String> options = new ArrayList<String>();
final List<Double> distanceSplit = new ArrayList<Double>();
final TIntArrayList timeSplit = new TIntArrayList();
bld.setTitle(R.string.gpx_split_interval);
View view = getActivity().getLayoutInflater().inflate(R.layout.selected_track_edit, null);
options.add(app.getString(R.string.none));
distanceSplit.add(-1d);
timeSplit.add(-1);
@ -185,14 +249,39 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
addOptionSplit(300, false, options, distanceSplit, timeSplit, checkedItem, model);
addOptionSplit(600, false, options, distanceSplit, timeSplit, checkedItem, model);
addOptionSplit(900, false, options, distanceSplit, timeSplit, checkedItem, model);
final CheckBox vis = (CheckBox) view.findViewById(R.id.Visibility);
vis.setChecked(true);
final Spinner sp = (Spinner) view.findViewById(R.id.Spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, options);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adapter);
if(checkedItem[0] > 0) {
sp.setSelection(checkedItem[0]);
}
bld.setSingleChoiceItems(options.toArray(new String[options.size()]), checkedItem[0], new DialogInterface.OnClickListener() {
bld.setView(view);
bld.setNegativeButton(R.string.default_buttons_cancel, null);
bld.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, final int which) {
dialog.dismiss();
public void onClick(DialogInterface dialog, int which) {
if(!vis.isChecked()) {
getMyApplication().getSelectedGpxHelper().selectGpxFile(model.getGpx(), false);
SelectedGPXFragment.this.adapter.setDisplayGroups(selectedGpxHelper.getDisplayGroups());
} else {
updateSplit(model, distanceSplit, timeSplit, sp.getSelectedItemPosition() );
}
}
});
bld.show();
}
private void updateSplit(final GpxDisplayGroup model, final List<Double> distanceSplit,
final TIntArrayList timeSplit, final int which) {
new AsyncTask<Void, Void, Void>() {
protected void onPostExecute(Void result) {
@ -217,10 +306,6 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
}
}.execute((Void)null);
}
});
bld.show();
}
private void addOptionSplit(int value, boolean distance, List<String> options, List<Double> distanceSplit,
TIntArrayList timeSplit, int[] checkedItem, GpxDisplayGroup model) {
@ -452,7 +537,6 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
additional.setText(OsmAndFormatter.getFormattedRoundDistanceKm((float) child.splitMetric,
digits, app));
} else {
// TODO
additional.setText(OsmAndFormatter.getFormattedDistance((float) child.splitMetric, app));
}
} else{
@ -481,8 +565,12 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
row.setTag(child);
label.setText(Html.fromHtml(child.name.replace("\n", "<br/>")));
if(child.expanded) {
description.setText(Html.fromHtml(child.description));
if (child.expanded && !Algorithms.isEmpty(child.description)) {
String d = child.description;
if (child.group.getType() == GpxDisplayItemType.TRACK_SEGMENT) {
d += "<br/>" + getString(R.string.local_index_gpx_info_show);
}
description.setText(Html.fromHtml(d));
description.setVisibility(View.VISIBLE);
} else {
description.setVisibility(View.GONE);
@ -497,8 +585,19 @@ public class SelectedGPXFragment extends OsmandExpandableListFragment {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
GpxDisplayItem child = adapter.getChild(groupPosition, childPosition);
if(child.group.getType() == GpxDisplayItemType.TRACK_POINTS ||
child.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
QuickAction qa = new QuickAction(v);
String name = getString(R.string.favorite) + ": " + child.name;
LatLon location = new LatLon(child.locationStart.lat, child.locationStart.lon);
OsmandSettings settings = getMyApplication().getSettings();
MapActivityActions.createDirectionsActions(qa, location, child.locationStart, name, settings.getLastKnownMapZoom(), getActivity(),
true, null, false);
qa.show();
} else {
child.expanded = !child.expanded;
adapter.notifyDataSetInvalidated();
}
return true;
}

View file

@ -461,18 +461,26 @@ public class EditingPOIActivity implements DialogProvider {
String website = websiteText.getText().toString();
if (website.length() > 0 ){
n.putTag(OSMTagKey.WEBSITE.getValue(),website);
} else {
n.removeTag(OSMTagKey.WEBSITE.getValue());
}
String phone = phoneText.getText().toString();
if (phone.length() > 0 ){
n.putTag(OSMTagKey.PHONE.getValue(),phone);
} else {
n.removeTag(OSMTagKey.PHONE.getValue());
}
String str = streetNameText.getText().toString();
if (str .length() > 0 ){
n.putTag(OSMTagKey.ADDR_STREET.getValue(),str);
} else {
n.removeTag(OSMTagKey.ADDR_STREET.getValue());
}
String hno = hnoText.getText().toString();
if (hno .length() > 0 ){
n.putTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),hno);
} else {
n.removeTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue());
}
commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), closeChange.isSelected(),
new Runnable() {

View file

@ -84,6 +84,7 @@ public class OsmandRenderer {
float x = 0;
float y = 0;
String resId;
String shieldId;
int iconOrder;
float iconSize;
}
@ -332,6 +333,16 @@ public class OsmandRenderer {
}
if (!intersects) {
Bitmap shield = icon.shieldId == null ? null : RenderingIcons.getIcon(context, icon.shieldId);
if(shield != null) {
RectF shieldRf = calculateRect(rc, icon, shield.getWidth(), shield.getHeight());
if (rc.screenDensityRatio != 1f) {
Rect src = new Rect(0, 0, shield.getWidth(), shield.getHeight());
cv.drawBitmap(shield, src, shieldRf, paintIcon);
} else {
cv.drawBitmap(shield, shieldRf.left, shieldRf.top, paintIcon);
}
}
if (rc.screenDensityRatio != 1f) {
Rect src = new Rect(0, 0, ico.getWidth(), ico.getHeight());
cv.drawBitmap(ico, src, rf, paintIcon);
@ -758,6 +769,7 @@ public class OsmandRenderer {
ico.y = ps.y;
ico.iconOrder = render.getIntPropertyValue(render.ALL.R_ICON_ORDER, 100);
ico.iconSize = rc.getComplexValue(render, render.ALL.R_ICON_VISIBLE_SIZE, -1);
ico.shieldId = render.getStringPropertyValue(render.ALL.R_SHIELD);
ico.resId = resId;
rc.iconsToDraw.add(ico);
}

View file

@ -22,6 +22,7 @@ import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Html;
import android.view.Gravity;
import android.view.MotionEvent;
import android.widget.FrameLayout.LayoutParams;
@ -190,7 +191,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
description = view.getContext().getString(R.string.point_on_map,
latLon.getLatitude(), latLon.getLongitude());
}
textView.setText(description);
textView.setText(Html.fromHtml(description.replace("\n", "<br/>")));
} else {
textView.setText(""); //$NON-NLS-1$
}

View file

@ -190,7 +190,7 @@ public class MapTextLayer extends OsmandMapLayer {
@Override
public boolean drawInScreenPixels() {
return false;
return true;
}
}