diff --git a/OsmAnd/build.xml b/OsmAnd/build.xml index 2d82012656..7627f7472d 100644 --- a/OsmAnd/build.xml +++ b/OsmAnd/build.xml @@ -259,6 +259,13 @@ + + + + + + + diff --git a/OsmAnd/res/layout/local_openstreetmap.xml b/OsmAnd/res/layout/local_openstreetmap.xml index 9759093947..12d4346e6f 100644 --- a/OsmAnd/res/layout/local_openstreetmap.xml +++ b/OsmAnd/res/layout/local_openstreetmap.xml @@ -9,7 +9,7 @@ android:layout_marginLeft = "3dp" android:layout_marginTop ="3dp" android:layout_marginRight = "3dp"/> - + diff --git a/OsmAnd/res/menu/localosm_child.xml b/OsmAnd/res/menu/localosm_child.xml index 79ee1b1dcf..d2e7362ce0 100644 --- a/OsmAnd/res/menu/localosm_child.xml +++ b/OsmAnd/res/menu/localosm_child.xml @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/OsmAnd/res/menu/localosm_group.xml b/OsmAnd/res/menu/localosm_group.xml deleted file mode 100644 index aa55b21ce0..0000000000 --- a/OsmAnd/res/menu/localosm_group.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/values-es/strings.xml b/OsmAnd/res/values-es/strings.xml index 163d92fe71..b87bae58fe 100644 --- a/OsmAnd/res/values-es/strings.xml +++ b/OsmAnd/res/values-es/strings.xml @@ -1,4 +1,4 @@ - + Iniciar\n seguimiento en directo Parar\n seguimiento en directo Configura pantalla… diff --git a/OsmAnd/res/values-hu/strings.xml b/OsmAnd/res/values-hu/strings.xml index e6be031c8d..f977c28de9 100644 --- a/OsmAnd/res/values-hu/strings.xml +++ b/OsmAnd/res/values-hu/strings.xml @@ -1,4 +1,4 @@ - + A 0.7.2 kiadás változásai: \n\t- Natív renderelő minden eszközre \n\t- Offline POI szerkesztés \n\t- Akadálymentesítés \n\t- Sok egyéb hibajavítás GPX fájl küldése OSM-re? Láthatóság diff --git a/OsmAnd/res/values-it/strings.xml b/OsmAnd/res/values-it/strings.xml index c429fd3136..d5642a6157 100644 --- a/OsmAnd/res/values-it/strings.xml +++ b/OsmAnd/res/values-it/strings.xml @@ -1,5 +1,6 @@ - -Sovrapposizioni fluorescenti + + + Sovrapposizioni fluorescenti Usa colori fluorescenti per mostrare tracce e percorsi Modifiche offline Usa sempre la modifica offline diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index ed425625f8..2824fde04b 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,4 +1,4 @@ - + Загрузите или обновите локальные данные. \nЧтобы получить дополнительную информацию о карте, выделите ее в списке. Удерживайте карту, если вы хотите удалить или деактивировать. \nДанные на устройстве (%1$s свободно): Начальное местоположение еще не определено Местоположение еще не определено diff --git a/OsmAnd/res/values-sk/strings.xml b/OsmAnd/res/values-sk/strings.xml index 27dbfda53d..43cec57c29 100644 --- a/OsmAnd/res/values-sk/strings.xml +++ b/OsmAnd/res/values-sk/strings.xml @@ -1,4 +1,4 @@ - + Zmeny vo verzii 0.8.3 : \n\t* Vylepšená navigácia \n\t* Voľba obídenia diaľnic diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a047dac26b..92bff43739 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,4 +1,4 @@ - + - Show alarms… Show speed limits, speed cameras, speed bumps, and other warnings Use the compass when no heading is detected otherwise diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index e252ae3539..12bbcb8827 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1215,8 +1215,7 @@ public class OsmandSettings { //public final OsmandPreference USE_COMPASS_IN_NAVIGATION = new BooleanPreference("use_compass_navigation", true).makeProfile().cache(); public final CommonPreference USE_COMPASS_IN_NAVIGATION = new BooleanPreference("use_compass_navigation", true).makeProfile().cache(); { - //Issue 1346 - USE_COMPASS_IN_NAVIGATION.setModeDefaultValue(ApplicationMode.CAR, false); + USE_COMPASS_IN_NAVIGATION.setModeDefaultValue(ApplicationMode.CAR, true); } // this value string is synchronized with settings_pref.xml preference name diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 09035696df..8f310e69c6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -884,7 +884,9 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe int currentMapRotation = settings.ROTATE_MAP.get(); if (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) { if (location.hasBearing()) { - mapView.setRotate(-location.getBearing()); + if(location.getBearing() != 0f) { + mapView.setRotate(-location.getBearing()); + } } else if (routingHelper.isFollowingMode() && settings.USE_COMPASS_IN_NAVIGATION.get()) { if (previousSensorValue != 0 && Math.abs(MapUtils.degreesDiff(mapView.getRotate(), -previousSensorValue)) > 15) { if(now - lastTimeSensorRotation > 1500 && now - lastTimeSensorRotation < 15000) { diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 599fc806fa..5f1dd7ebaf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -165,6 +165,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper { // db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ // db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ } + distance = 0; return warnings; } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 9a98b6f0a3..8090632adc 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -125,7 +125,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements LockInfoCont cat.addPreference(activity.createCheckBoxPreference(settings.SAVE_TRACK_TO_GPX, R.string.save_track_to_gpx, R.string.save_track_to_gpx_descrp)); cat.addPreference(activity.createTimeListPreference(settings.SAVE_TRACK_INTERVAL, SECONDS, - MINUTES, 1, R.string.save_track_interval, R.string.save_track_interval_descr)); + MINUTES, 1000, R.string.save_track_interval, R.string.save_track_interval_descr)); cat = new PreferenceCategory(activity); cat.setTitle(R.string.live_monitoring); @@ -134,7 +134,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements LockInfoCont cat.addPreference(activity.createCheckBoxPreference(settings.LIVE_MONITORING, R.string.live_monitoring, R.string.live_monitoring_descr)); cat.addPreference(activity.createTimeListPreference(settings.LIVE_MONITORING_INTERVAL, SECONDS, - MINUTES, 1, R.string.live_monitoring_interval, R.string.live_monitoring_interval_descr)); + MINUTES, 1000, R.string.live_monitoring_interval, R.string.live_monitoring_interval_descr)); cat = new PreferenceCategory(activity); cat.setTitle(R.string.monitor_preferences); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AbstractOpenstreetmapUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/AbstractOpenstreetmapUtil.java index 441e3f5a0d..83f51bcad5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AbstractOpenstreetmapUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AbstractOpenstreetmapUtil.java @@ -4,33 +4,21 @@ package net.osmand.plus.osmedit; import java.util.ArrayList; import java.util.List; -import net.osmand.access.AccessibleToast; import net.osmand.data.Amenity; import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.Node; import net.osmand.plus.AmenityIndexRepositoryOdb; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; import android.app.Activity; -import android.widget.Toast; public abstract class AbstractOpenstreetmapUtil implements OpenstreetmapUtil { + @Override public void updateNodeInIndexes(Activity ctx, OsmPoint.Action action, Node n, Node oldNode) { final OsmandApplication app = (OsmandApplication) ctx.getApplication(); final AmenityIndexRepositoryOdb repo = app.getResourceManager().getUpdatablePoiDb(); - ctx.runOnUiThread(new Runnable() { - - @Override - public void run() { - if (repo == null) { - AccessibleToast.makeText(app, app.getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_LONG).show(); - } else { - AccessibleToast.makeText(app, app.getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_LONG).show(); - } - } - }); + showMessageAfterCommit(ctx, app, repo); if (repo == null) { return; @@ -55,4 +43,8 @@ public abstract class AbstractOpenstreetmapUtil implements OpenstreetmapUtil { } } } + + protected void showMessageAfterCommit(Activity ctx, final OsmandApplication app, final AmenityIndexRepositoryOdb repo) { + + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java index f77b29e345..9ed05d8adc 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditingPOIActivity.java @@ -2,11 +2,11 @@ package net.osmand.plus.osmedit; import java.text.MessageFormat; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import net.osmand.OsmAndFormatter; import net.osmand.access.AccessibleToast; @@ -54,6 +54,7 @@ public class EditingPOIActivity implements DialogProvider { private final MapActivity ctx; private final OpenstreetmapUtil openstreetmapUtil; + private final OpenstreetmapUtil openstreetmapUtilToLoad; private AutoCompleteTextView typeText; private EditText nameText; private Button typeButton; @@ -83,15 +84,21 @@ public class EditingPOIActivity implements DialogProvider { this.ctx = uiContext; settings = ((OsmandApplication) uiContext.getApplication()).getSettings(); - if(settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)){ + if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { this.openstreetmapUtil = new OpenstreetmapLocalUtil(ctx); + if (settings.isInternetConnectionAvailable(true)) { + this.openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(ctx, ctx.getMapView()); + } else { + this.openstreetmapUtilToLoad = openstreetmapUtil; + } } else { this.openstreetmapUtil = new OpenstreetmapRemoteUtil(ctx, ctx.getMapView()); + this.openstreetmapUtilToLoad= openstreetmapUtil; } } public void showEditDialog(Amenity editA){ - Node n = openstreetmapUtil.loadNode(editA); + Node n = openstreetmapUtilToLoad.loadNode(editA); if(n != null){ showPOIDialog(DIALOG_EDIT_POI, n, editA.getType(), editA.getSubType()); } else { @@ -166,9 +173,105 @@ public class EditingPOIActivity implements DialogProvider { phoneText.setText(a.getPhone()); EditText websiteText = ((EditText)dlg.findViewById(R.id.Website)); websiteText.setText(a.getSite()); + final TableLayout layout = ((TableLayout)dlg.findViewById(R.id.advancedModeTable)); + layout.setVisibility(View.GONE); updateType(a); } + private void addTagValueRow(final Node n, final TableLayout layout, String tg, String vl) { + final TableRow newTagRow = new TableRow(ctx); + TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); + tlp.leftMargin = 5; + newTagRow.setLayoutParams(tlp); + + final AutoCompleteTextView tag = new AutoCompleteTextView(ctx); + final AutoCompleteTextView value = new AutoCompleteTextView(ctx); + final Button delete = new Button(ctx); + + tag.setLayoutParams(tlp); + if(tg != null) { + tag.setText(tg); + } else { + tag.setHint("Tag"); + } + + final Set tagKeys = new TreeSet(); + for (OSMTagKey t : OSMTagKey.values()) { + if ((t != OSMTagKey.NAME) && (t != OSMTagKey.OPENING_HOURS) && (t != OSMTagKey.PHONE) + && (t != OSMTagKey.WEBSITE)) { + tagKeys.add(t.getValue()); + } + } + ArrayAdapter adapter = new ArrayAdapter(ctx, R.layout.list_textview, tagKeys.toArray()); + tag.setAdapter(adapter); + tag.setThreshold(1); + tag.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Builder builder = new AlertDialog.Builder(ctx); + final String[] tags = tagKeys.toArray(new String[tagKeys.size()]); + builder.setItems(tags, new Dialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + tag.setText(tags[which]); + } + + }); + builder.create(); + builder.show(); + } + }); + tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.FILL_PARENT); + tlp.leftMargin = 5; + tlp.rightMargin = 5; + tlp.width = 80; + value.setLayoutParams(tlp); + if(vl != null) { + value.setText(vl); + } else { + value.setHint("Value"); + } + Set subCategories = MapRenderingTypes.getDefault().getAmenityNameToType().keySet(); + ArrayAdapter valueAdapter = new ArrayAdapter(ctx, R.layout.list_textview, subCategories.toArray()); + value.setThreshold(1); + value.setAdapter(valueAdapter); + value.addTextChangedListener(new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + if ((newTagRow != null) && (tag != null) && (value != null) && (tag.getText() != null) + && (value.getText() != null) && (!tag.getText().equals("")) && (!value.getText().equals(""))) { + n.putTag(tag.getText().toString(), value.getText().toString()); + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }); + tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); + tlp.gravity = Gravity.CENTER; + tlp.rightMargin = 5; + delete.setLayoutParams(tlp); + delete.setText("X"); + delete.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + layout.removeView(newTagRow); + layout.invalidate(); + n.removeTag(tag.getText().toString()); + } + }); + newTagRow.addView(tag); + newTagRow.addView(value); + newTagRow.addView(delete); + layout.addView(newTagRow); + layout.invalidate(); + } + private Dialog createPOIDialog(final int dialogID, final Bundle args) { final Dialog dlg = new Dialog(ctx); dlg.setContentView(R.layout.editing_poi); @@ -248,14 +351,15 @@ public class EditingPOIActivity implements DialogProvider { }); final Button advancedModeButton = ((Button)dlg.findViewById(R.id.advancedMode)); - final Map additionalTags = new HashMap(); advancedModeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - final TableLayout layout = ((TableLayout)dlg.findViewById(R.id.advancedModeTable)); - TableLayout.LayoutParams tlParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); - layout.setLayoutParams(tlParams); - layout.setColumnStretchable(1, true); + final Node n = (Node) args.getSerializable(KEY_AMENITY_NODE); + final TableLayout layout = ((TableLayout) dlg.findViewById(R.id.advancedModeTable)); + TableLayout.LayoutParams tlParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, + TableLayout.LayoutParams.WRAP_CONTENT); + layout.setLayoutParams(tlParams); + layout.setColumnStretchable(1, true); layout.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE); Button addTag = (Button) dlg.findViewById(R.id.addTag); addTag.setVisibility((layout.getVisibility() == View.VISIBLE) ? View.VISIBLE : View.GONE); @@ -263,93 +367,23 @@ public class EditingPOIActivity implements DialogProvider { addTag.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - final TableRow newTagRow = new TableRow(ctx); - TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); - tlp.leftMargin = 5; - newTagRow.setLayoutParams(tlp); - - final AutoCompleteTextView tag = new AutoCompleteTextView(ctx); - final AutoCompleteTextView value = new AutoCompleteTextView(ctx); - final Button delete = new Button(ctx); - - tag.setLayoutParams(tlp); - tag.setHint("Tag"); - - final Set tagKeys = new LinkedHashSet(); - for (OSMTagKey t : OSMTagKey.values()) { - if ((t != OSMTagKey.NAME) && (t != OSMTagKey.OPENING_HOURS) && (t != OSMTagKey.PHONE) - && (t != OSMTagKey.WEBSITE)) { - tagKeys.add(t.getValue()); - } - } - ArrayAdapter adapter = new ArrayAdapter(ctx, R.layout.list_textview, tagKeys.toArray()); - tag.setAdapter(adapter); - tag.setThreshold(1); - tag.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Builder builder = new AlertDialog.Builder(ctx); - final String[] tags = tagKeys.toArray(new String[tagKeys.size()]); - builder.setItems(tags, new Dialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - tag.setText(tags[which]); - } - - }); - builder.create(); - builder.show(); - } - }); - tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.FILL_PARENT); - tlp.leftMargin = 5; - tlp.rightMargin = 5; - tlp.width = 80; - value.setLayoutParams(tlp); - value.setHint("Value"); - Set subCategories = MapRenderingTypes.getDefault().getAmenityNameToType().keySet(); - ArrayAdapter valueAdapter = new ArrayAdapter(ctx, R.layout.list_textview, subCategories.toArray()); - value.setThreshold(1); - value.setAdapter(valueAdapter); - value.addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable s) { - if ((newTagRow != null) && (tag != null) && (value != null) && (tag.getText() != null) - && (value.getText() != null) && (!tag.getText().equals("")) && (!value.getText().equals(""))) { - additionalTags.put(tag.getText().toString(), value.getText().toString()); - } - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - }); - tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); - tlp.gravity = Gravity.CENTER; - tlp.rightMargin = 5; - delete.setLayoutParams(tlp); - delete.setText("X"); - delete.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - layout.removeView(newTagRow); - layout.invalidate(); - additionalTags.remove(tag.getText().toString()); - } - }); - newTagRow.addView(tag); - newTagRow.addView(value); - newTagRow.addView(delete); - layout.addView(newTagRow); - layout.invalidate(); + addTagValueRow(n, layout, null, null); } }); } + while (layout.getChildCount() > 0) { + layout.removeViewAt(0); + } layout.requestLayout(); + Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); + for (String tg : n.getTagKeySet()) { + if (!tg.equals(OSMTagKey.NAME.getValue()) && !tg.equals(OSMTagKey.OPENING_HOURS.getValue()) + && !tg.equals(OSMTagKey.PHONE.getValue()) && !tg.equals(OSMTagKey.WEBSITE.getValue())) { + if(a == null || a.getType() == null || !a.getType().getDefaultTag().equals(tg)) { + addTagValueRow(n, layout, tg, n.getTag(tg)); + } + } + } } }); @@ -407,11 +441,6 @@ public class EditingPOIActivity implements DialogProvider { if (phone.length() > 0 ){ n.putTag(OSMTagKey.PHONE.getValue(),phone); } - if ((additionalTags != null) && (!additionalTags.isEmpty())) { - for (String tk : additionalTags.keySet()) { - n.putTag(tk, additionalTags.get(tk)); - } - } commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), new Runnable() { @Override public void run() { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java index 37d9e8dfb7..2ceab6a5d8 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java @@ -2,21 +2,20 @@ package net.osmand.plus.osmedit; import java.text.MessageFormat; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import net.osmand.access.AccessibleToast; import net.osmand.osm.EntityInfo; import net.osmand.osm.Node; import net.osmand.plus.AmenityIndexRepositoryOdb; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.ProgressDialogImplementation; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; -import net.osmand.plus.activities.OsmandExpandableListActivity; +import net.osmand.plus.osmedit.OsmPoint.Action; import android.app.Dialog; +import android.app.ListActivity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.AsyncTask; @@ -28,12 +27,12 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ExpandableListView; -import android.widget.ExpandableListView.ExpandableListContextMenuInfo; +import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.ArrayAdapter; import android.widget.TextView; import android.widget.Toast; -public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { +public class LocalOpenstreetmapActivity extends ListActivity { /** dialogs **/ protected static final int DIALOG_PROGRESS_UPLOAD = 0; @@ -48,6 +47,10 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { private OsmBugsRemoteUtil remotebug; protected OsmPoint[] toUpload; + private ArrayList dataPoints; + + + @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,18 +59,11 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { setContentView(R.layout.local_openstreetmap); listAdapter = new LocalOpenstreetmapAdapter(); - getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { + getListView().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); MenuInflater inflater = getMenuInflater(); - if (child >= 0 && group >= 0) { - inflater.inflate(R.menu.localosm_child, menu); - } else if (group >= 0) { //group menu - inflater.inflate(R.menu.localosm_group, menu); - } + inflater.inflate(R.menu.localosm_child, menu); } }); setListAdapter(listAdapter); @@ -79,12 +75,9 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { remotebug = new OsmBugsRemoteUtil(); findViewById(R.id.UploadAllButton).setOnClickListener(new View.OnClickListener() { - - @Override public void onClick(View v) { - //NOTE, the order of upload is important, there can be more edits per one POI!! - toUpload = listAdapter.values().toArray(new OsmPoint[0]); + toUpload = dataPoints.toArray(new OsmPoint[0]); showDialog(DIALOG_PROGRESS_UPLOAD); } }); @@ -93,51 +86,59 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { @Override protected void onResume() { super.onResume(); - listAdapter.clear(); + + dataPoints = new ArrayList(); List l1 = dbpoi.getOpenstreetmapPoints(); List l2 = dbbug.getOsmbugsPoints(); + dataPoints.addAll(l1); + dataPoints.addAll(l2); + listAdapter.clear(); for (OpenstreetmapPoint p : l1) { - listAdapter.addOsmPoint(p); + listAdapter.add(p); } for (OsmbugsPoint p : l2) { - listAdapter.addOsmPoint(p); + listAdapter.add(p); } listAdapter.notifyDataSetChanged(); } @Override public boolean onContextItemSelected(MenuItem item) { - long packedPos = ((ExpandableListContextMenuInfo)item.getMenuInfo()).packedPosition; - int group = ExpandableListView.getPackedPositionGroup(packedPos); - int child = ExpandableListView.getPackedPositionChild(packedPos); + int pos = ((AdapterContextMenuInfo)item.getMenuInfo()).position; int itemId = item.getItemId(); if(itemId == R.id.showmod) { OsmandSettings settings = getMyApplication().getSettings(); - OsmPoint info = (OsmPoint) listAdapter.getChild(group, child); + OsmPoint info = (OsmPoint) listAdapter.getItem(pos); settings.setMapLocationToShow(info.getLatitude(), info.getLongitude(), settings.getLastKnownMapZoom()); MapActivity.launchMapActivityMoveToTop(LocalOpenstreetmapActivity.this); return true; } else if(itemId == R.id.deletemod) { - OsmPoint info = (OsmPoint) listAdapter.getChild(group, child); + OsmPoint info = (OsmPoint) listAdapter.getItem(pos); if (info.getGroup() == OsmPoint.Group.POI) { dbpoi.deletePOI((OpenstreetmapPoint) info); + if (info.getAction() == Action.CREATE) { + AmenityIndexRepositoryOdb repo = getMyApplication().getResourceManager().getUpdatablePoiDb(); + repo.deleteAmenities(info.getId() << 1); + repo.clearCache(); + } } else if (info.getGroup() == OsmPoint.Group.BUG) { dbbug.deleteAllBugModifications((OsmbugsPoint) info); } listAdapter.delete(info); return true; - } else if(itemId == R.id.uploadmods) { - List list = listAdapter.data.get(listAdapter.category.get(group)); - if (list != null) { - toUpload = list.toArray(new OsmPoint[] {}); - showDialog(DIALOG_PROGRESS_UPLOAD); - return true; - } - } + } else if (itemId == R.id.uploadmods) { + toUpload = new OsmPoint[]{ listAdapter.getItem(pos)}; + showDialog(DIALOG_PROGRESS_UPLOAD); + return true; + } return super.onContextItemSelected(item); } + private OsmandApplication getMyApplication() { + return (OsmandApplication) getApplication(); + } + @Override protected void onDestroy() { super.onDestroy(); @@ -209,10 +210,6 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { } Node n; if ((n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment())) != null) { - if (point.getId() != n.getId()) { - // change all category points... - listAdapter.categoryIdChanged(point.getId(), n.getId()); - } remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), n, p.getEntity()); dbpoi.deletePOI(p); publishProgress(p); @@ -225,7 +222,7 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { } else if (p.getAction() == OsmPoint.Action.MODIFY) { remotebug.addingComment(p.getId(), p.getText(), p.getAuthor()); } else if (p.getAction() == OsmPoint.Action.DELETE) { - remotebug.closingBug(p.getId()); + remotebug.closingBug(p.getId(), p.getText(), p.getAuthor()); } dbbug.deleteAllBugModifications(p); publishProgress(p); @@ -268,68 +265,25 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { @Override protected void onProgressUpdate(OsmPoint... points) { - listAdapter.delete(points[0]); - progress.incrementProgressBy(1); + for(OsmPoint p : points) { + listAdapter.delete(p); + progress.incrementProgressBy(1); + } } } - protected class LocalOpenstreetmapAdapter extends OsmandBaseExpandableListAdapter { - Map> data = new LinkedHashMap>(); - List category = new ArrayList(); - + protected class LocalOpenstreetmapAdapter extends ArrayAdapter { public LocalOpenstreetmapAdapter() { + super(LocalOpenstreetmapActivity.this, net.osmand.plus.R.layout.local_openstreetmap_list_item); } - public void categoryIdChanged(long oldID, long newID) { - int index = category.indexOf(oldID); - if (index != -1) { - category.set(index, newID); - List list = data.remove(oldID); - if (list != null) { - for (OsmPoint point : list) { - point.updateID(newID); - } - data.put(newID, list); - } - } - } - public void clear() { - data.clear(); - category.clear(); - notifyDataSetChanged(); - } - - public List values() { - List values = new ArrayList(); - for (List v : data.values()) { - values.addAll(v); - } - return values; - } public void delete(OsmPoint i) { - final AmenityIndexRepositoryOdb repo = getMyApplication().getResourceManager().getUpdatablePoiDb(); - Long c = i.getId(); - if(c != null){ - List list = data.get(c); - list.remove(i); - if (list.isEmpty()) { - data.remove(c); - category.remove(c); - } - repo.deleteAmenities(i.getId() << 1); - // We need to re-insert the POI if it is a delete or modify - for (OsmPoint point : list) { - if (point.getGroup() == OsmPoint.Group.POI) { - OpenstreetmapPoint p = (OpenstreetmapPoint) point; - remotepoi.updateNodeInIndexes(LocalOpenstreetmapActivity.this, p.getAction(), p.getEntity(), p.getEntity()); - } - } - repo.clearCache(); - } + dataPoints.remove(i); + remove(i); listAdapter.notifyDataSetChanged(); } @@ -337,51 +291,20 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { notifyDataSetChanged(); } - public void addOsmPoint(OsmPoint info) { - int found = -1; - // search from end - for (int i = category.size() - 1; i >= 0; i--) { - Long cat = category.get(i); - if (cat.compareTo(info.getId()) == 0) { - found = i; - break; - } - } - if (found == -1) { - found = category.size(); - category.add(info.getId()); - } - if (!data.containsKey(category.get(found))) { - data.put(category.get(found), new ArrayList()); - } - data.get(category.get(found)).add(info); - } - @Override - public OsmPoint getChild(int groupPosition, int childPosition) { - Long cat = category.get(groupPosition); - return data.get(cat).get(childPosition); - } - - @Override - public long getChildId(int groupPosition, int childPosition) { - // it would be unusable to have 10000 local categories - return groupPosition * 10000 + childPosition; - } - - @Override - public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { + public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; - final OsmPoint child = (OsmPoint) getChild(groupPosition, childPosition); + final OsmPoint child = getItem(position); if (v == null ) { LayoutInflater inflater = getLayoutInflater(); v = inflater.inflate(net.osmand.plus.R.layout.local_openstreetmap_list_item, parent, false); } TextView viewName = ((TextView) v.findViewById(R.id.local_openstreetmap_name)); + String idPrefix = (child.getGroup() == OsmPoint.Group.POI ? "POI " : "Bug ") + " id: " + child.getId(); if (child.getGroup() == OsmPoint.Group.POI) - viewName.setText("(" + ((OpenstreetmapPoint) child).getSubtype() + ") " + ((OpenstreetmapPoint) child).getName()); + viewName.setText(idPrefix + " (" + ((OpenstreetmapPoint) child).getSubtype() + ") " + ((OpenstreetmapPoint) child).getName()); else if (child.getGroup() == OsmPoint.Group.BUG) - viewName.setText("(" + ((OsmbugsPoint) child).getAuthor() + ") " + ((OsmbugsPoint) child).getText()); + viewName.setText(idPrefix + " (" + ((OsmbugsPoint) child).getAuthor() + ") " + ((OsmbugsPoint) child).getText()); if (child.getAction() == OsmPoint.Action.CREATE) { viewName.setTextColor(getResources().getColor(R.color.osm_create)); } else if (child.getAction() == OsmPoint.Action.MODIFY) { @@ -393,61 +316,5 @@ public class LocalOpenstreetmapActivity extends OsmandExpandableListActivity { return v; } - @Override - public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { - View v = convertView; - Long group = getGroup(groupPosition); - if (v == null) { - LayoutInflater inflater = getLayoutInflater(); - v = inflater.inflate(net.osmand.plus.R.layout.local_openstreetmap_list_item_category, parent, false); - } - adjustIndicator(groupPosition, isExpanded, v); - StringBuilder t = new StringBuilder(); - t.append(" id:").append(group); - t.append(" [").append(getChildrenCount(groupPosition)); - if(getString(R.string.local_openstreetmap_items).length() > 0){ - t.append(" ").append(getString(R.string.local_openstreetmap_items)); - } - if(getString(R.string.local_openstreetmap_items).length() > 0){ - t.append(" ").append(getString(R.string.local_openstreetmap_items)); - } - t.append("]"); - TextView nameView = ((TextView) v.findViewById(R.id.local_openstreetmap_category_name)); - nameView.setText(t.toString()); - - - return v; - } - - @Override - public int getChildrenCount(int groupPosition) { - Long cat = category.get(groupPosition); - return data.get(cat).size(); - } - - @Override - public Long getGroup(int groupPosition) { - return category.get(groupPosition); - } - - @Override - public int getGroupCount() { - return category.size(); - } - - @Override - public long getGroupId(int groupPosition) { - return groupPosition; - } - - @Override - public boolean hasStableIds() { - return false; - } - - @Override - public boolean isChildSelectable(int groupPosition, int childPosition) { - return true; - } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java index 9cbcaa11b3..bd98ad4184 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java @@ -4,6 +4,7 @@ import java.util.Map; import net.osmand.LogUtil; +import net.osmand.access.AccessibleToast; import net.osmand.data.Amenity; import net.osmand.data.AmenityType; import net.osmand.osm.EntityInfo; @@ -11,10 +12,15 @@ import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.MapUtils; import net.osmand.osm.Node; import net.osmand.osm.OSMSettings.OSMTagKey; +import net.osmand.plus.AmenityIndexRepositoryOdb; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; import org.apache.commons.logging.Log; +import android.app.Activity; import android.content.Context; +import android.widget.Toast; public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil { @@ -25,10 +31,10 @@ public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil { public final static Log log = LogUtil.getLog(OpenstreetmapLocalUtil.class); - public OpenstreetmapLocalUtil(Context uiContext){ + public OpenstreetmapLocalUtil(Context uiContext) { this.ctx = uiContext; this.db = new OpenstreetmapsDbHelper(ctx); - this.nextid = Math.min(-2,db.getMinID()); + this.nextid = Math.min(-2, db.getMinID()); } @Override @@ -54,6 +60,21 @@ public class OpenstreetmapLocalUtil extends AbstractOpenstreetmapUtil { return newNode; } + @Override + protected void showMessageAfterCommit(Activity ctx, final OsmandApplication app, final AmenityIndexRepositoryOdb repo) { + ctx.runOnUiThread(new Runnable() { + + @Override + public void run() { + if (repo == null) { + AccessibleToast.makeText(app, app.getString(R.string.update_poi_no_offline_poi_index), Toast.LENGTH_LONG).show(); + } else { + AccessibleToast.makeText(app, app.getString(R.string.update_poi_does_not_change_indexes), Toast.LENGTH_LONG).show(); + } + } + }); + } + @Override public Node loadNode(Amenity n) { if(n.getId() % 2 == 1){ diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java index c3542348b9..36c91d66e9 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapsDbHelper.java @@ -5,9 +5,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map.Entry; -import com.ibm.icu.impl.locale.StringTokenIterator; -import com.ibm.icu.util.StringTokenizer; - import net.osmand.osm.Node; import android.content.Context; import android.database.Cursor; @@ -16,7 +13,7 @@ import android.database.sqlite.SQLiteOpenHelper; public class OpenstreetmapsDbHelper extends SQLiteOpenHelper { - private static final int DATABASE_VERSION = 2; + private static final int DATABASE_VERSION = 4; public static final String OPENSTREETMAP_DB_NAME = "openstreetmap"; //$NON-NLS-1$ private static final String OPENSTREETMAP_TABLE_NAME = "openstreetmaptable"; //$NON-NLS-1$ private static final String OPENSTREETMAP_COL_ID = "id"; //$NON-NLS-1$ @@ -40,11 +37,11 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper { public void onCreate(SQLiteDatabase db) { db.execSQL(OPENSTREETMAP_TABLE_CREATE); } - + @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - if(newVersion == 2) { - // db.execSQL("DROP TABLE " + OPENSTREETMAP_TABLE_NAME); + if(newVersion == 4) { + db.execSQL("DROP TABLE IF EXISTS " + OPENSTREETMAP_TABLE_NAME); db.execSQL(OPENSTREETMAP_TABLE_CREATE); } } @@ -75,6 +72,8 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper { return false; } + + public boolean deletePOI(OpenstreetmapPoint p) { checkOpenstreetmapPoints(); SQLiteDatabase db = getWritableDatabase(); @@ -85,6 +84,7 @@ public class OpenstreetmapsDbHelper extends SQLiteOpenHelper { } return false; } + private List checkOpenstreetmapPoints(){ SQLiteDatabase db = getWritableDatabase(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index ff8a5afefc..75c198e55c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -20,7 +20,6 @@ import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.R.drawable; import net.osmand.plus.activities.DialogProvider; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; @@ -399,7 +398,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider @Override public void onClick(DialogInterface dialog, int which) { OpenStreetBug bug = (OpenStreetBug) args.getSerializable(KEY_BUG); - boolean closed = osmbugsUtil.closingBug(bug.getId()); + boolean closed = osmbugsUtil.closingBug(bug.getId(), "", ((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_OSM_BUG_NAME.get()); if (closed) { AccessibleToast.makeText(activity, activity.getString(R.string.osb_close_dialog_success), Toast.LENGTH_LONG).show(); clearCache(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java index 74c2a8ea4f..5d5cb32fe7 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLocalUtil.java @@ -1,14 +1,11 @@ package net.osmand.plus.osmedit; -import net.osmand.LogUtil; -import org.apache.commons.logging.Log; import android.content.Context; public class OsmBugsLocalUtil implements OsmBugsUtil { - private static final Log log = LogUtil.getLog(OsmBugsLocalUtil.class); private final Context ctx; private final OsmBugsDbHelper db; @@ -41,9 +38,11 @@ public class OsmBugsLocalUtil implements OsmBugsUtil { } @Override - public boolean closingBug(long id){ + public boolean closingBug(long id, String text, String authorName){ OsmbugsPoint p = new OsmbugsPoint(); p.setId(id); + p.setAuthor(authorName); + p.setText(text); p.setAction(OsmPoint.Action.DELETE); return db.addOsmbugs(p); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java index 3680a790fe..9eb00af12b 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsRemoteUtil.java @@ -41,10 +41,15 @@ public class OsmBugsRemoteUtil implements OsmBugsUtil { } @Override - public boolean closingBug(long id){ + public boolean closingBug(long id, String text, String authorName){ StringBuilder b = new StringBuilder(); b.append(SITE_API).append("closePOIexec?"); //$NON-NLS-1$ b.append("id=").append(id); //$NON-NLS-1$ + if(text != null) { + b.append("&text=").append(URLEncoder.encode(text)); //$NON-NLS-1$ + } + b.append("&name=").append(URLEncoder.encode(authorName)); //$NON-NLS-1$ + return editingPOI(b.toString(),"closing bug"); //$NON-NLS-1$ } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsUtil.java index e334e058e3..e20dcdb4b2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsUtil.java @@ -8,5 +8,5 @@ public interface OsmBugsUtil { public boolean addingComment(long id, String text, String authorName); - public boolean closingBug(long id); + public boolean closingBug(long id, String text, String authorName); } diff --git a/OsmAnd/src/net/osmand/plus/views/LockInfoControl.java b/OsmAnd/src/net/osmand/plus/views/LockInfoControl.java index ad3fb8ed96..56229fcad0 100644 --- a/OsmAnd/src/net/osmand/plus/views/LockInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/LockInfoControl.java @@ -187,19 +187,19 @@ public class LockInfoControl { } }); - for(int i=0; i