From e8b434c53c980b4b0add79e1aa13c756e02b2ca0 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 11 Mar 2015 16:47:29 +0200 Subject: [PATCH 1/7] Added card for osm edits. --- .../src/net/osmand/data/PointDescription.java | 1 + .../DashAudioVideoNotesFragment.java | 9 +- .../plus/dashboard/DashBaseFragment.java | 13 + .../plus/dashboard/DashFavoritesFragment.java | 10 +- .../osmand/plus/dashboard/DashboardOnMap.java | 2 + .../plus/myplaces/FavoritesActivity.java | 13 +- .../plus/osmedit/DashOsmEditsFragment.java | 127 ++++++++- .../osmedit/LocalOpenstreetmapActivity.java | 6 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 268 ++++++++++++++++-- .../plus/osmedit/OsmEditsUploadListener.java | 12 + .../UploadOpenstreetmapPointAsyncTask.java | 127 +++++++++ 11 files changed, 536 insertions(+), 52 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListener.java create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index edd7c33250..9082f007ed 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -32,6 +32,7 @@ public class PointDescription { public static final String POINT_TYPE_LOCATION = "location"; public static final String POINT_TYPE_ALARM = "alarm"; public static final String POINT_TYPE_TARGET = "destination"; + public static final String POINT_TYPE_OSM_BUG = "bug"; public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, ""); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java index 12de9be350..758964d1e1 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import net.osmand.data.PointDescription; +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -45,13 +46,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Activity activity = getActivity(); - Class fa = getMyApplication().getAppCustomization().getFavoritesActivity(); - final Intent favorites = new Intent(activity, fa); - favorites.putExtra("TAB", "AUDIO"); - favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - getMyApplication().getSettings().FAVORITES_TAB.set(FavoritesActivity.NOTES_TAB); - activity.startActivity(favorites); + startFavoritesActivity(FavoritesActivity.NOTES_TAB); } }); return view; diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java index 805c34e466..21aaa81a10 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java @@ -1,10 +1,14 @@ package net.osmand.plus.dashboard; import android.app.Activity; +import android.content.Intent; import android.location.Location; import android.support.v4.app.Fragment; + +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.myplaces.FavoritesActivity; /** * Created by Denis on 24.11.2014. @@ -63,4 +67,13 @@ public abstract class DashBaseFragment extends Fragment { } } + protected void startFavoritesActivity(int tab) { + Activity activity = getActivity(); + OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization(); + final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity()); + favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + getMyApplication().getSettings().FAVORITES_TAB.set(tab); + activity.startActivity(favorites); + } + } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 664eb2c241..489c405c07 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -31,7 +31,8 @@ import android.widget.LinearLayout; import android.widget.TextView; /** - * Created by Denis on 24.11.2014. + * Created by Denis + * on 24.11.2014. */ public class DashFavoritesFragment extends DashLocationFragment { public static final String TAG = "DASH_FAVORITES_FRAGMENT"; @@ -47,12 +48,7 @@ public class DashFavoritesFragment extends DashLocationFragment { (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Activity activity = getActivity(); - OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization(); - final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity()); - favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - getMyApplication().getSettings().FAVORITES_TAB.set(FavoritesActivity.FAVORITES_TAB); - activity.startActivity(favorites); + startFavoritesActivity(FavoritesActivity.FAVORITES_TAB); } }); return view; diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 42cc7353df..035265cd51 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -16,6 +16,7 @@ import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.helpers.ScreenOrientationHelper; import net.osmand.plus.monitoring.DashTrackFragment; +import net.osmand.plus.osmedit.DashOsmEditsFragment; import net.osmand.plus.parkingpoint.DashParkingFragment; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.DownloadedRegionsLayer; @@ -350,6 +351,7 @@ public class DashboardOnMap { showFragment(manager, fragmentTransaction, DashFavoritesFragment.TAG, DashFavoritesFragment.class); showFragment(manager, fragmentTransaction, DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class); showFragment(manager, fragmentTransaction, DashTrackFragment.TAG, DashTrackFragment.class); + showFragment(manager, fragmentTransaction, DashOsmEditsFragment.TAG, DashOsmEditsFragment.class); // showFragment(manager, fragmentTransaction, DashUpdatesFragment.TAG, DashUpdatesFragment.class); showFragment(manager, fragmentTransaction, DashPluginsFragment.TAG, DashPluginsFragment.class); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java index cadb37ea1c..60dab63922 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java @@ -16,6 +16,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.FavoritesTreeFragment; import net.osmand.plus.activities.TabActivity; import net.osmand.plus.myplaces.AvailableGPXFragment; +import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.views.controls.PagerSlidingTabStrip; import android.app.Activity; import android.graphics.drawable.Drawable; @@ -73,7 +74,6 @@ public class FavoritesActivity extends TabActivity { ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); List mTabs = new ArrayList(); -// mTabs.add(new TabItem("\t\t\t", FavoritesTreeFragment.class)); mTabs.add(getTabIndicator(R.string.shared_string_my_favorites, FavoritesTreeFragment.class)); if (hasGpx) { mTabs.add(getTabIndicator(R.string.shared_string_my_tracks, AvailableGPXFragment.class)); @@ -82,9 +82,14 @@ public class FavoritesActivity extends TabActivity { Integer tab = settings.FAVORITES_TAB.get(); if (tab == NOTES_TAB) { - tab = mTabs.size() -1; + if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null){ + tab = mTabs.size() - 2; + } else { + tab = mTabs.size() - 1; + } + } else if (tab == OSM_EDITS_TAB) { - //TODO implement method of counting position for other plugins + tab = mTabs.size() - 1; } setViewPagerAdapter(mViewPager, mTabs); @@ -93,7 +98,7 @@ public class FavoritesActivity extends TabActivity { if (tab > mTabs.size() - 1){ tab = 0; } - mViewPager.setCurrentItem(tab ); + mViewPager.setCurrentItem(tab); // setupHomeButton(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java index c92065fd5d..54b98eef4c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java @@ -1,22 +1,38 @@ package net.osmand.plus.osmedit; +import net.osmand.data.PointDescription; +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.ProgressImplementation; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashBaseFragment; import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.myplaces.FavoritesActivity; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; +import android.widget.ImageButton; +import android.widget.LinearLayout; import android.widget.TextView; +import java.util.ArrayList; +import java.util.List; + /** * Created by Denis * on 20.01.2015. */ -public class DashOsmEditsFragment extends DashBaseFragment { +public class DashOsmEditsFragment extends DashBaseFragment implements OsmEditsUploadListener { + public static final String TAG = "DASH_OSM_EDITS_FRAGMENT"; + OsmEditingPlugin plugin; @Override @@ -31,6 +47,12 @@ public class DashOsmEditsFragment extends DashBaseFragment { Button manage = ((Button) view.findViewById(R.id.show_all)); manage.setTypeface(typeface); manage.setText(R.string.osm_editing_manage); + (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + startFavoritesActivity(FavoritesActivity.OSM_EDITS_TAB); + } + }); return view; } @@ -44,12 +66,113 @@ public class DashOsmEditsFragment extends DashBaseFragment { setupEditings(); } - private void setupEditings() { View mainView = getView(); if (plugin == null){ mainView.setVisibility(View.GONE); return; } + + ArrayList dataPoints = new ArrayList<>(); + getOsmPoints(dataPoints); + if (dataPoints.size() == 0){ + mainView.setVisibility(View.GONE); + return; + } else { + mainView.setVisibility(View.VISIBLE); + } + + LinearLayout osmLayout = (LinearLayout) mainView.findViewById(R.id.notes); + osmLayout.removeAllViews(); + + for (final OsmPoint point : dataPoints){ + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.note, null, false); + + OsmEditsFragment.getOsmEditView(view, point, getMyApplication()); + ImageButton send =(ImageButton) view.findViewById(R.id.play); + send.setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_gup_dark)); + send.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OpenstreetmapRemoteUtil remotepoi = new OpenstreetmapRemoteUtil(getActivity(), getActivity().getWindow().getDecorView()); + OsmPoint[] toUpload = new OsmPoint[]{point}; + OsmBugsRemoteUtil remotebug = new OsmBugsRemoteUtil(getMyApplication()); + ProgressDialog dialog = ProgressImplementation.createProgressDialog( + getActivity(), + getString(R.string.uploading), + getString(R.string.local_openstreetmap_uploading), + ProgressDialog.STYLE_HORIZONTAL).getDialog(); + UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog,DashOsmEditsFragment.this, remotepoi, + remotebug, toUpload.length); + uploadTask.execute(toUpload); + dialog.show(); + } + }); + view.findViewById(R.id.options).setVisibility(View.GONE); + view.findViewById(R.id.divider).setVisibility(View.VISIBLE); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean poi = point.getGroup() == OsmPoint.Group.POI; + String name = poi ? + ((OpenstreetmapPoint) point).getName() : ((OsmNotesPoint) point).getText(); + getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), + 15, new PointDescription(poi ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG, name), true, + point); //$NON-NLS-1$ + MapActivity.launchMapActivityMoveToTop(getActivity()); + } + }); + osmLayout.addView(view); + } + } + + private void getOsmPoints(ArrayList dataPoints) { + OpenstreetmapsDbHelper dbpoi = new OpenstreetmapsDbHelper(getActivity()); + OsmBugsDbHelper dbbug = new OsmBugsDbHelper(getActivity()); + + List l1 = dbpoi.getOpenstreetmapPoints(); + List l2 = dbbug.getOsmbugsPoints(); + if (l1.isEmpty()){ + int i = 0; + for(OsmPoint point : l2){ + if (i > 2) { + break; + } + dataPoints.add(point); + i++; + } + } else if (l2.isEmpty()) { + int i = 0; + for(OsmPoint point : l1){ + if (i > 2) { + break; + } + dataPoints.add(point); + i++; + } + } else { + dataPoints.add(l1.get(0)); + dataPoints.add(l2.get(0)); + if (l1.size() > 1){ + dataPoints.add(l1.get(1)); + } else if (l2.size() > 1){ + dataPoints.add(l2.get(1)); + } + } + } + + @Override + public void uploadUpdated(OsmPoint point) { + if (!this.isDetached()){ + onOpenDash(); + } + } + + @Override + public void uploadEnded(Integer result) { + if (!this.isDetached()){ + onOpenDash(); + } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java index d14226de1f..242c7daaaa 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/LocalOpenstreetmapActivity.java @@ -88,11 +88,11 @@ public class LocalOpenstreetmapActivity extends OsmandListActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - createMenuItem(menu, UPLOAD_ID, R.string.local_openstreetmap_uploadall, R.drawable.ic_action_gup_light, R.drawable.ic_action_gup_dark, + createMenuItem(menu, UPLOAD_ID, R.string.local_openstreetmap_uploadall, R.drawable.ic_action_gup_dark, R.drawable.ic_action_gup_dark, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); - createMenuItem(menu, BACKUP_ID, R.string.local_osm_changes_backup, R.drawable.ic_action_gsave_light, R.drawable.ic_action_gsave_dark, + createMenuItem(menu, BACKUP_ID, R.string.local_osm_changes_backup, R.drawable.ic_action_gsave_dark, R.drawable.ic_action_gsave_dark, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); - createMenuItem(menu, DELETE_ID, R.string.shared_string_delete_all, R.drawable.ic_action_gdiscard_light, R.drawable.ic_action_gdiscard_dark, + createMenuItem(menu, DELETE_ID, R.string.shared_string_delete_all, R.drawable.ic_action_gdiscard_dark, R.drawable.ic_action_gdiscard_dark, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT); return super.onCreateOptionsMenu(menu); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 9433a7d378..63c15a6f7a 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -1,9 +1,14 @@ package net.osmand.plus.osmedit; +import android.app.AlertDialog; import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.ListFragment; +import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.PopupMenu; +import android.util.Xml; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -15,6 +20,9 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; + +import net.osmand.access.AccessibleToast; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -22,16 +30,24 @@ import net.osmand.plus.ProgressImplementation; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.DirectionsDialogs; +import net.osmand.plus.helpers.ScreenOrientationHelper; import net.osmand.plus.myplaces.FavoritesActivity; +import org.xmlpull.v1.XmlSerializer; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; /** * Created by Denis * on 06.03.2015. */ -public class OsmEditsFragment extends ListFragment { +public class OsmEditsFragment extends ListFragment implements OsmEditsUploadListener { OsmEditingPlugin plugin; private ArrayList dataPoints; private OsmEditsAdapter listAdapter; @@ -39,8 +55,13 @@ public class OsmEditsFragment extends ListFragment { private OpenstreetmapsDbHelper dbpoi; private OsmBugsDbHelper dbbug; + private OpenstreetmapRemoteUtil remotepoi; + private OsmBugsRemoteUtil remotebug; + protected OsmPoint[] toUpload = new OsmPoint[0]; + ProgressDialog dialog; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); @@ -51,13 +72,73 @@ public class OsmEditsFragment extends ListFragment { dbpoi = new OpenstreetmapsDbHelper(getActivity()); dbbug = new OsmBugsDbHelper(getActivity()); + remotepoi = new OpenstreetmapRemoteUtil(getActivity(), getActivity().getWindow().getDecorView()); + remotebug = new OsmBugsRemoteUtil(getMyApplication()); + return view; } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); - ((FavoritesActivity) getActivity()).getClearToolbar(false); + + if (ScreenOrientationHelper.isOrientationPortrait(getActivity())) { + menu = ((FavoritesActivity) getActivity()).getClearToolbar(true).getMenu(); + } else { + ((FavoritesActivity) getActivity()).getClearToolbar(false); + } + MenuItem item = menu.add(R.string.local_openstreetmap_uploadall). + setIcon(R.drawable.ic_action_gup_dark); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + toUpload = dataPoints.toArray(new OsmPoint[0]); + showUploadItemsDialog(); + return true; + } + }); + MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + + item = menu.add(R.string.local_osm_changes_backup). + setIcon(R.drawable.ic_action_gsave_dark); + MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + new BackupOpenstreetmapPointAsyncTask().execute(dataPoints.toArray(new OsmPoint[0])); + return true; + } + }); + item = menu.add(R.string.shared_string_delete_all). + setIcon(R.drawable.ic_action_gdiscard_dark); + MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); + b.setMessage(getString(R.string.local_osm_changes_delete_all_confirm, dataPoints.size())); + b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Iterator it = dataPoints.iterator(); + while(it.hasNext()) { + OsmPoint info = it.next(); + if (info.getGroup() == OsmPoint.Group.POI) { + dbpoi.deletePOI((OpenstreetmapPoint) info); + } else if (info.getGroup() == OsmPoint.Group.BUG) { + dbbug.deleteAllBugModifications((OsmNotesPoint) info); + } + it.remove(); + listAdapter.delete(info); + } + listAdapter.notifyDataSetChanged(); + } + }); + b.setNegativeButton(R.string.shared_string_cancel, null); + b.show(); + return true; + } + }); } @Override @@ -76,12 +157,36 @@ public class OsmEditsFragment extends ListFragment { public void onItemClick(AdapterView parent, View view, int position, long id) { OsmPoint it = listAdapter.getItem(position); openPopUpMenu(view, it); - + } }); } + public static void getOsmEditView(View v, OsmPoint child, OsmandApplication app){ + TextView viewName = ((TextView) v.findViewById(R.id.name)); + ImageView icon = (ImageView) v.findViewById(R.id.icon); + String idPrefix = (child.getGroup() == OsmPoint.Group.POI ? "POI " : "Bug ") + " id: " + child.getId(); + if (child.getGroup() == OsmPoint.Group.POI) { + viewName.setText(idPrefix + " (" + ((OpenstreetmapPoint) child).getSubtype() + ") " + ((OpenstreetmapPoint) child).getName()); + icon.setImageDrawable(app.getIconsCache(). + getIcon(R.drawable.ic_type_info, R.color.color_distance)); + } else if (child.getGroup() == OsmPoint.Group.BUG) { + viewName.setText(idPrefix + " (" + ((OsmNotesPoint) child).getAuthor() + ") " + ((OsmNotesPoint) child).getText()); + icon.setImageDrawable(app.getIconsCache(). + getIcon(R.drawable.ic_type_bug, R.color.color_distance)); + } + + TextView descr = (TextView) v.findViewById(R.id.descr); + if (child.getAction() == OsmPoint.Action.CREATE) { + descr.setText(R.string.action_create); + } else if (child.getAction() == OsmPoint.Action.MODIFY) { + descr.setText(R.string.action_modify); + } else if (child.getAction() == OsmPoint.Action.DELETE) { + descr.setText(R.string.action_delete); + } + } + protected class OsmEditsAdapter extends ArrayAdapter { public OsmEditsAdapter(List points) { @@ -102,29 +207,10 @@ public class OsmEditsFragment extends ListFragment { LayoutInflater inflater = getActivity().getLayoutInflater(); v = inflater.inflate(net.osmand.plus.R.layout.note, parent, false); } - TextView viewName = ((TextView) v.findViewById(R.id.name)); - ImageView icon = (ImageView) v.findViewById(R.id.icon); + getOsmEditView(v, child, getMyApplication()); v.findViewById(R.id.play).setVisibility(View.GONE); - String idPrefix = (child.getGroup() == OsmPoint.Group.POI ? "POI " : "Bug ") + " id: " + child.getId(); - if (child.getGroup() == OsmPoint.Group.POI) { - viewName.setText(idPrefix + " (" + ((OpenstreetmapPoint) child).getSubtype() + ") " + ((OpenstreetmapPoint) child).getName()); - icon.setImageDrawable(getMyApplication().getIconsCache(). - getIcon(R.drawable.ic_type_info, R.color.color_distance)); - } else if (child.getGroup() == OsmPoint.Group.BUG) { - viewName.setText(idPrefix + " (" + ((OsmNotesPoint) child).getAuthor() + ") " + ((OsmNotesPoint) child).getText()); - icon.setImageDrawable(getMyApplication().getIconsCache(). - getIcon(R.drawable.ic_type_bug, R.color.color_distance)); - } - TextView descr = (TextView) v.findViewById(R.id.descr); - if (child.getAction() == OsmPoint.Action.CREATE) { - descr.setText(R.string.action_create); - } else if (child.getAction() == OsmPoint.Action.MODIFY) { - descr.setText(R.string.action_modify); - } else if (child.getAction() == OsmPoint.Action.DELETE) { - descr.setText(R.string.action_delete); - } v.findViewById(R.id.options).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -171,12 +257,7 @@ public class OsmEditsFragment extends ListFragment { @Override public boolean onMenuItemClick(MenuItem item) { toUpload = new OsmPoint[]{info}; - ProgressDialog implementation = ProgressImplementation.createProgressDialog( - getActivity(), - getString(R.string.uploading), - getString(R.string.local_openstreetmap_uploading), - ProgressDialog.STYLE_HORIZONTAL).getDialog(); - implementation.show(); + showUploadItemsDialog(); return true; } }); @@ -187,4 +268,133 @@ public class OsmEditsFragment extends ListFragment { return (OsmandApplication) getActivity().getApplication(); } + private void showUploadItemsDialog(){ + dialog = ProgressImplementation.createProgressDialog( + getActivity(), + getString(R.string.uploading), + getString(R.string.local_openstreetmap_uploading), + ProgressDialog.STYLE_HORIZONTAL).getDialog(); + UploadOpenstreetmapPointAsyncTask uploadTask = new UploadOpenstreetmapPointAsyncTask(dialog, this, remotepoi, + remotebug, toUpload.length); + uploadTask.execute(toUpload); + + dialog.show(); + } + + + public class BackupOpenstreetmapPointAsyncTask extends AsyncTask { + + + private File osmchange; + + public BackupOpenstreetmapPointAsyncTask() { + OsmandApplication app = (OsmandApplication) getActivity().getApplication(); + osmchange = app.getAppPath("poi_modification.osc"); + } + + + @Override + protected String doInBackground(OsmPoint... points) { + FileOutputStream out = null; + try { + out = new FileOutputStream(osmchange); + XmlSerializer sz = Xml.newSerializer(); + + sz.setOutput(out, "UTF-8"); + sz.startDocument("UTF-8", true); + sz.startTag("", "osmChange"); + sz.attribute("", "generator", "OsmAnd"); + sz.attribute("", "version", "0.6"); + sz.startTag("", "create"); + writeContent(sz, points, OsmPoint.Action.CREATE); + sz.endTag("", "create"); + sz.startTag("", "modify"); + writeContent(sz, points, OsmPoint.Action.MODIFY); + sz.endTag("", "modify"); + sz.startTag("", "delete"); + writeContent(sz, points, OsmPoint.Action.DELETE); + sz.endTag("", "delete"); + sz.endTag("", "osmChange"); + sz.endDocument(); + } catch (Exception e) { + return e.getMessage(); + } finally { + try { + if(out!= null) out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + return null; + } + + private void writeContent(XmlSerializer sz, OsmPoint[] points, OsmPoint.Action a) throws IllegalArgumentException, IllegalStateException, IOException { + for (OsmPoint point : points) { + if (point.getGroup() == OsmPoint.Group.POI) { + OpenstreetmapPoint p = (OpenstreetmapPoint) point; + if (p.getAction() == a) { + sz.startTag("", "node"); + sz.attribute("", "lat", p.getLatitude() + ""); + sz.attribute("", "lon", p.getLongitude() + ""); + sz.attribute("", "id", p.getId() + ""); + sz.attribute("", "version", "1"); + for (String tag : p.getEntity().getTagKeySet()) { + String val = p.getEntity().getTag(tag); + sz.startTag("", "tag"); + sz.attribute("", "k", tag); + sz.attribute("", "v", val); + sz.endTag("", "tag"); + } + sz.endTag("", "node"); + } + } else if (point.getGroup() == OsmPoint.Group.BUG) { + OsmNotesPoint p = (OsmNotesPoint) point; + if (p.getAction() == a) { + sz.startTag("", "note"); + sz.attribute("", "lat", p.getLatitude() + ""); + sz.attribute("", "lon", p.getLongitude() + ""); + sz.attribute("", "id", p.getId() + ""); + sz.startTag("", "comment"); + sz.attribute("", "text", p.getText() +""); + sz.endTag("", "comment"); + sz.endTag("", "note"); + } + } + } + } + + + @Override + protected void onPreExecute() { + getActivity().setProgressBarIndeterminateVisibility(true); + } + + @Override + protected void onPostExecute(String result) { + getActivity().setProgressBarIndeterminateVisibility(false); + if (result != null) { + AccessibleToast.makeText(getActivity(), getString(R.string.local_osm_changes_backup_failed) + " " + result, Toast.LENGTH_LONG).show(); + } else { + AccessibleToast.makeText(getActivity(), getString(R.string.local_osm_changes_backup_successful, osmchange.getAbsolutePath()), Toast.LENGTH_LONG).show(); + } + } + } + + @Override + public void uploadUpdated(OsmPoint point){ + listAdapter.delete(point); + } + + @Override + public void uploadEnded(Integer result){ + listAdapter.notifyDataSetChanged(); + if (result != null) { + AccessibleToast.makeText(getActivity(), + MessageFormat.format(getString(R.string.local_openstreetmap_were_uploaded), result), Toast.LENGTH_LONG) + .show(); + } + dialog.dismiss(); + } + } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListener.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListener.java new file mode 100644 index 0000000000..2edf57a300 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListener.java @@ -0,0 +1,12 @@ +package net.osmand.plus.osmedit; + +/** + * Created by Denis + * on 11.03.2015. + */ +public interface OsmEditsUploadListener { + + public void uploadUpdated(OsmPoint point); + + public void uploadEnded(Integer result); +} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java b/OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java new file mode 100644 index 0000000000..cdd2f2b035 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/UploadOpenstreetmapPointAsyncTask.java @@ -0,0 +1,127 @@ +package net.osmand.plus.osmedit; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.os.AsyncTask; +import android.support.v4.app.Fragment; +import android.widget.Toast; + +import net.osmand.access.AccessibleToast; +import net.osmand.osm.edit.EntityInfo; +import net.osmand.osm.edit.Node; +import net.osmand.plus.R; + +import java.text.MessageFormat; + +/** + * Created by Denis + * on 11.03.2015. + */ +public class UploadOpenstreetmapPointAsyncTask extends AsyncTask { + + private ProgressDialog progress; + + private OpenstreetmapRemoteUtil remotepoi; + + private OsmBugsRemoteUtil remotebug; + + private OpenstreetmapsDbHelper dbpoi; + private OsmBugsDbHelper dbbug; + + private int listSize = 0; + + private boolean interruptUploading = false; + + private Fragment ctx; + + public UploadOpenstreetmapPointAsyncTask(ProgressDialog progress,Fragment ctx, OpenstreetmapRemoteUtil remotepoi, OsmBugsRemoteUtil remotebug, + int listSize) { + this.progress = progress; + this.remotepoi = remotepoi; + this.remotebug = remotebug; + this.listSize = listSize; + dbpoi = new OpenstreetmapsDbHelper(ctx.getActivity()); + dbbug = new OsmBugsDbHelper(ctx.getActivity()); + } + + @Override + protected Integer doInBackground(OsmPoint... points) { + int uploaded = 0; + + for (OsmPoint point : points) { + if (interruptUploading) + break; + + if (point.getGroup() == OsmPoint.Group.POI) { + OpenstreetmapPoint p = (OpenstreetmapPoint) point; + EntityInfo entityInfo = null; + if (OsmPoint.Action.CREATE != p.getAction()) { + entityInfo = remotepoi.loadNode(p.getEntity()); + } + Node n = remotepoi.commitNodeImpl(p.getAction(), p.getEntity(), entityInfo, p.getComment(), false); + if (n != null) { + dbpoi.deletePOI(p); + publishProgress(p); + uploaded++; + } + } else if (point.getGroup() == OsmPoint.Group.BUG) { + OsmNotesPoint p = (OsmNotesPoint) point; + boolean success = false; + if (p.getAction() == OsmPoint.Action.CREATE) { + success = remotebug.createNewBug(p.getLatitude(), p.getLongitude(), p.getText()) == null; + } else if (p.getAction() == OsmPoint.Action.MODIFY) { + success = remotebug.addingComment(p.getId(), p.getText()) == null; + } else if (p.getAction() == OsmPoint.Action.DELETE) { + success = remotebug.closingBug(p.getId(), p.getText()) == null; + } + if (success) { + dbbug.deleteAllBugModifications(p); + uploaded++; + publishProgress(p); + } + + } + } + + return uploaded; + } + + @Override + protected void onPreExecute() { + interruptUploading = false; + + progress.setOnCancelListener(new DialogInterface.OnCancelListener() { + @Override + public void onCancel(DialogInterface dialog) { + UploadOpenstreetmapPointAsyncTask.this.setInterruptUploading(true); + } + }); + progress.setIndeterminate(false); + progress.setMax(listSize); + progress.setProgress(0); + } + + @Override + protected void onPostExecute(Integer result) { + if (ctx instanceof OsmEditsUploadListener){ + ((OsmEditsUploadListener)ctx).uploadEnded(result); + } + } + + public void setInterruptUploading(boolean b) { + interruptUploading = b; + } + + @Override + protected void onProgressUpdate(OsmPoint... points) { + for(OsmPoint p : points) { + if (ctx instanceof OsmEditsUploadListener){ + ((OsmEditsUploadListener)ctx).uploadUpdated(p); + } + progress.incrementProgressBy(1); + } + } + +} + From 3f5123c19125143137a83b7a10574e774ea48845 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 11 Mar 2015 18:09:05 +0200 Subject: [PATCH 2/7] Updated parking card --- OsmAnd/res/drawable/dash_parking_dark.xml | 7 +++ OsmAnd/res/drawable/dash_parking_light.xml | 7 +++ OsmAnd/res/layout/dash_parking_fragment.xml | 1 + OsmAnd/res/values/attrs.xml | 2 +- OsmAnd/res/values/colors.xml | 6 +- OsmAnd/res/values/styles.xml | 4 +- OsmAnd/src/net/osmand/plus/IconsCache.java | 3 +- .../plus/dashboard/DashLocationFragment.java | 58 +++++++++++-------- .../parkingpoint/DashParkingFragment.java | 40 ++++++++++--- .../parkingpoint/ParkingPositionLayer.java | 41 ++----------- .../parkingpoint/ParkingPositionPlugin.java | 41 +++++++++++++ .../osmand/plus/views/DirectionDrawable.java | 5 ++ 12 files changed, 140 insertions(+), 75 deletions(-) create mode 100644 OsmAnd/res/drawable/dash_parking_dark.xml create mode 100644 OsmAnd/res/drawable/dash_parking_light.xml diff --git a/OsmAnd/res/drawable/dash_parking_dark.xml b/OsmAnd/res/drawable/dash_parking_dark.xml new file mode 100644 index 0000000000..b416e9a9b7 --- /dev/null +++ b/OsmAnd/res/drawable/dash_parking_dark.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/dash_parking_light.xml b/OsmAnd/res/drawable/dash_parking_light.xml new file mode 100644 index 0000000000..36da79539a --- /dev/null +++ b/OsmAnd/res/drawable/dash_parking_light.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/dash_parking_fragment.xml b/OsmAnd/res/layout/dash_parking_fragment.xml index 8f867bb58d..17dac2fa86 100644 --- a/OsmAnd/res/layout/dash_parking_fragment.xml +++ b/OsmAnd/res/layout/dash_parking_fragment.xml @@ -7,6 +7,7 @@ android:orientation="vertical"> - + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index d4661f41de..c1e3add23f 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -1,6 +1,10 @@ + #234DDE + #54778c + #446072 + #1f2326 @color/color_white #292f33 @@ -33,7 +37,7 @@ #212121 #ff8f00 #536DFE - #54778c + #00000000 #ffC8C8C8 diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 9a61d1c1c5..33bd4a6b2f 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -165,7 +165,7 @@ @color/color_white @drawable/ic_overflow_menu_light @drawable/size_progressbar_light - @color/dashboard_blue + @drawable/dash_parking_light