diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index ef8228d8d7..190f8bf826 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -88,7 +88,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class MapActivity extends AccessibleActivity { - private static final int SHOW_POSITION_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 1; private static final int LONG_KEYPRESS_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 2; private static final int LONG_KEYPRESS_DELAY = 500; @@ -378,6 +377,10 @@ public class MapActivity extends AccessibleActivity { if (dashboardOnMap.onBackPressed()) { return; } + if (drawerLayout.isDrawerOpen(Gravity.LEFT)) { + closeDrawer(); + return; + } super.onBackPressed(); } @@ -607,54 +610,6 @@ public class MapActivity extends AccessibleActivity { showAndHideMapPosition(); } - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && app.accessibilityEnabled()) { - if (!uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) { - Message msg = Message.obtain(uiHandler, new Runnable() { - @Override - public void run() { - app.getLocationProvider().emitNavigationHint(); - } - }); - msg.what = LONG_KEYPRESS_MSG_ID; - uiHandler.sendMessageDelayed(msg, LONG_KEYPRESS_DELAY); - } - return true; - } else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 1) { - toggleDrawer(); - return true; - } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 1) { - Intent newIntent = new Intent(MapActivity.this, getMyApplication().getAppCustomization() - .getSearchActivity()); - // causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - LatLon loc = getMapLocation(); - newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); - newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); - if (mapViewTrackingUtilities.isMapLinkedToLocation()) { - newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true); - } - startActivity(newIntent); - newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - return true; - } else if (!app.getRoutingHelper().isFollowingMode() - && OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) { - // Find more appropriate plugin for it? - if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) { - if (mapView.isZooming()) { - changeZoom(+2); - } else { - changeZoom(+1); - } - return true; - } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && event.getRepeatCount() == 0) { - changeZoom(-1); - return true; - } - } - return super.onKeyDown(keyCode, event); - } - public void setMapLocation(double lat, double lon) { mapView.setLatLon(lat, lon); mapViewTrackingUtilities.locationChanged(lat, lon, this); @@ -825,6 +780,51 @@ public class MapActivity extends AccessibleActivity { } + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER && app.accessibilityEnabled()) { + if (!uiHandler.hasMessages(LONG_KEYPRESS_MSG_ID)) { + Message msg = Message.obtain(uiHandler, new Runnable() { + @Override + public void run() { + app.getLocationProvider().emitNavigationHint(); + } + }); + msg.what = LONG_KEYPRESS_MSG_ID; + uiHandler.sendMessageDelayed(msg, LONG_KEYPRESS_DELAY); + } + return true; + } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { + Intent newIntent = new Intent(MapActivity.this, getMyApplication().getAppCustomization() + .getSearchActivity()); + // causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + LatLon loc = getMapLocation(); + newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); + newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); + if (mapViewTrackingUtilities.isMapLinkedToLocation()) { + newIntent.putExtra(SearchActivity.SEARCH_NEARBY, true); + } + startActivity(newIntent); + newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + return true; + } else if (!app.getRoutingHelper().isFollowingMode() + && OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) { + // Find more appropriate plugin for it? + if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) { + if (mapView.isZooming()) { + changeZoom(+2); + } else { + changeZoom(+1); + } + return true; + } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && event.getRepeatCount() == 0) { + changeZoom(-1); + return true; + } + } + return super.onKeyDown(keyCode, event); + } + @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { @@ -835,6 +835,9 @@ public class MapActivity extends AccessibleActivity { mapActions.contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); } return true; + } else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) { + toggleDrawer(); + return true; } else if (settings.ZOOM_BY_TRACKBALL.get()) { // Parrot device has only dpad left and right if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java index 1869b8371b..0d8339f5b4 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java @@ -110,7 +110,7 @@ public class NotesFragment extends OsmAndListFragment { @Override public void onResume() { super.onResume(); - items = new ArrayList(plugin.getAllRecordings()); + items = new ArrayList<>(plugin.getAllRecordings()); listAdapter = new NotesAdapter(items); getListView().setAdapter(listAdapter); if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java index acec769765..61e9133648 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java @@ -82,29 +82,21 @@ public class EditPoiFragment extends Fragment { @Override public void onAttach(Activity activity) { super.onAttach(activity); -// poiTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes(); -// allTranslatedSubTypes = poiTypes.getAllTranslatedNames(); - OsmandSettings settings = ((MapActivity) activity).getMyApplication().getSettings(); -// editPoiData.isLocalEdit = true; + OsmandSettings settings = getMyApplication().getSettings(); OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); -// openstreetmapUtilToLoad = mOpenstreetmapUtil; } else if (!settings.isInternetConnectionAvailable(true)) { mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); -// openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity); } else { isLocalEdit = false; mOpenstreetmapUtil = new OpenstreetmapRemoteUtil(activity); -// openstreetmapUtilToLoad = mOpenstreetmapUtil; } node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE); - allTranslatedSubTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes() + allTranslatedSubTypes = getMyApplication().getPoiTypes() .getAllTranslatedNames(); - // TODO implement normal name editPoiData.amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY); -// editPoiData.tags = new LinkedHashSet<>(); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @@ -194,7 +186,7 @@ public class EditPoiFragment extends Fragment { } }); onlineDocumentationButton.setImageDrawable( - ((MapActivity) getActivity()).getMyApplication().getIconsCache() + getMyApplication().getIconsCache() .getPaintedContentIcon(R.drawable.ic_action_help, getResources().getColor(R.color.inactive_item_orange))); final ImageButton poiTypeButton = (ImageButton) view.findViewById(R.id.poiTypeButton); @@ -455,20 +447,24 @@ public class EditPoiFragment extends Fragment { }); } + private OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + public static void showEditInstance(final Amenity amenity, - final MapActivity mapActivity) { - final OsmandSettings settings = mapActivity.getMyApplication().getSettings(); + final AppCompatActivity activity) { + final OsmandSettings settings = ((OsmandApplication) activity.getApplication()) + .getSettings(); final OpenstreetmapUtil openstreetmapUtilToLoad; if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); - openstreetmapUtilToLoad = new OpenstreetmapLocalUtil(plugin, mapActivity); + openstreetmapUtilToLoad = new OpenstreetmapLocalUtil(plugin, activity); } else if (!settings.isInternetConnectionAvailable(true)) { - openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(mapActivity); + openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity); } else { - openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(mapActivity); + openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity); } new AsyncTask() { - @Override protected Node doInBackground(Void... params) { return openstreetmapUtilToLoad.loadNode(amenity); @@ -478,18 +474,15 @@ public class EditPoiFragment extends Fragment { if (n != null) { EditPoiFragment fragment = EditPoiFragment.createInstance(n, amenity); - mapActivity.getSupportFragmentManager().beginTransaction() + activity.getSupportFragmentManager().beginTransaction() .add(R.id.fragmentContainer, fragment, "EditPoiFragment") .addToBackStack(null).commit(); } else { - AccessibleToast.makeText(mapActivity, - mapActivity.getString(R.string.poi_error_poi_not_found), + AccessibleToast.makeText(activity, + activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show(); } } - - ; - }.execute(new Void[0]); } @@ -536,6 +529,7 @@ public class EditPoiFragment extends Fragment { public static class ShowDeleteDialogAsyncTask extends AsyncTask { private final OpenstreetmapUtil openstreetmapUtil; private final AppCompatActivity activity; + public ShowDeleteDialogAsyncTask(AppCompatActivity activity) { this.activity = activity; OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings(); @@ -551,15 +545,15 @@ public class EditPoiFragment extends Fragment { protected Node doInBackground(Amenity[] params) { return openstreetmapUtil.loadNode(params[0]); - }; - - protected void onPostExecute(Node n) { - if(n == null){ - AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show(); - return; } - DeletePoiDialogFragment.createInstance(n).show(activity.getSupportFragmentManager(), - "DeletePoiDialogFragment"); - }; -} + + protected void onPostExecute(Node n) { + if (n == null) { + AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show(); + return; + } + DeletePoiDialogFragment.createInstance(n).show(activity.getSupportFragmentManager(), + "DeletePoiDialogFragment"); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index b283ce112f..74254b4cf1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -1,12 +1,15 @@ package net.osmand.plus.osmedit; import android.app.AlertDialog; +import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; import android.support.v4.view.MenuItemCompat; import android.support.v7.view.ActionMode; import android.support.v7.widget.PopupMenu; @@ -24,29 +27,6 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -import net.osmand.access.AccessibleToast; -import net.osmand.data.PointDescription; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.ProgressImplementation; -import net.osmand.plus.R; -import net.osmand.plus.activities.ActionBarProgressActivity; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.OsmAndListFragment; -import net.osmand.plus.activities.OsmandActionBarActivity; -import net.osmand.plus.dialogs.DirectionsDialogs; -import net.osmand.plus.helpers.AndroidUiHelper; -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.util.ArrayList; -import java.util.Iterator; -import java.util.List; import net.osmand.access.AccessibleToast; import net.osmand.data.PointDescription; @@ -78,7 +58,7 @@ import java.util.List; */ public class OsmEditsFragment extends OsmAndListFragment { OsmEditingPlugin plugin; - + private OsmEditsAdapter listAdapter; private boolean selectionMode = false; @@ -90,7 +70,6 @@ public class OsmEditsFragment extends OsmAndListFragment { private final static int MODE_UPLOAD = 101; private ActionMode actionMode; - protected OsmPoint[] toUpload = new OsmPoint[0]; private ArrayList osmEditsSelected = new ArrayList<>(); @@ -280,7 +259,8 @@ public class OsmEditsFragment extends OsmAndListFragment { private void updateSelectionTitle(ActionMode m) { if (osmEditsSelected.size() > 0) { - m.setTitle(osmEditsSelected.size() + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase)); + m.setTitle(osmEditsSelected.size() + " " + + getMyApplication().getString(R.string.shared_string_selected_lowercase)); } else { m.setTitle(""); } @@ -316,28 +296,8 @@ public class OsmEditsFragment extends OsmAndListFragment { } private void deleteItems(final ArrayList points) { - AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); - b.setMessage(getString(R.string.local_osm_changes_delete_all_confirm, points.size())); - b.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Iterator it = points.iterator(); - while (it.hasNext()) { - OsmPoint omsPoint = it.next(); - if (omsPoint.getGroup() == OsmPoint.Group.POI) { - plugin.getDBPOI().deletePOI((OpenstreetmapPoint) omsPoint); - } else if (omsPoint.getGroup() == OsmPoint.Group.BUG) { - plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) omsPoint); - } - it.remove(); - listAdapter.delete(omsPoint); - } - listAdapter.notifyDataSetChanged(); - - } - }); - b.setNegativeButton(R.string.shared_string_cancel, null); - b.show(); + DeleteOsmEditsConfirmDialogFragment.createInstance(points). + show(getChildFragmentManager(), DeleteOsmEditsConfirmDialogFragment.TAG); } @Override @@ -391,18 +351,18 @@ public class OsmEditsFragment extends OsmAndListFragment { protected class OsmEditsAdapter extends ArrayAdapter { private List dataPoints; - - + + public OsmEditsAdapter(List points) { super(getActivity(), net.osmand.plus.R.layout.note, points); dataPoints = points; } - + public void setNewList(List dp) { dataPoints = dp; setNotifyOnChange(false); clear(); - for(OsmPoint pnt : dp) { + for (OsmPoint pnt : dp) { add(pnt); } setNotifyOnChange(true); @@ -450,7 +410,8 @@ public class OsmEditsFragment extends OsmAndListFragment { ch.setVisibility(View.GONE); } - ((ImageView) options).setImageDrawable(getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_overflow_menu_white)); + ((ImageView) options).setImageDrawable(getMyApplication().getIconsCache() + .getContentIcon(R.drawable.ic_overflow_menu_white)); options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -527,20 +488,11 @@ public class OsmEditsFragment extends OsmAndListFragment { } private void uploadItems(final OsmPoint[] items) { - AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); - b.setMessage(getString(R.string.local_osm_changes_upload_all_confirm, items.length)); - b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - toUpload = items; - showUploadItemsProgressDialog(); - } - }); - b.setNegativeButton(R.string.shared_string_cancel, null); - b.show(); + UploadOsmEditsConfirmDialogFragment.createInstance(items).show(getChildFragmentManager(), + UploadOsmEditsConfirmDialogFragment.TAG); } - private void showUploadItemsProgressDialog() { + private void showUploadItemsProgressDialog(OsmPoint[] toUpload) { ProgressDialog dialog = ProgressImplementation.createProgressDialog( getActivity(), getString(R.string.uploading), @@ -668,4 +620,92 @@ public class OsmEditsFragment extends OsmAndListFragment { new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$ MapActivity.launchMapActivityMoveToTop(getActivity()); } + + private void deletePoint(OsmPoint osmPoint) { + listAdapter.delete(osmPoint); + } + + private void notifyDataSetChanged() { + listAdapter.notifyDataSetChanged(); + } + + public static class DeleteOsmEditsConfirmDialogFragment extends DialogFragment { + public static final String TAG = "DeleteOsmEditsConfirmDialogFragment"; + private static final String POINTS_LIST = "points_list"; + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final OsmEditsFragment parentFragment = (OsmEditsFragment) getParentFragment(); + final OsmEditingPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class); + final ArrayList points = + (ArrayList) getArguments().getSerializable(POINTS_LIST); + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(getString(R.string.local_osm_changes_delete_all_confirm, + points.size())); + builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Iterator it = points.iterator(); + while (it.hasNext()) { + OsmPoint osmPoint = it.next(); + if (osmPoint.getGroup() == OsmPoint.Group.POI) { + plugin.getDBPOI().deletePOI((OpenstreetmapPoint) osmPoint); + } else if (osmPoint.getGroup() == OsmPoint.Group.BUG) { + plugin.getDBBug().deleteAllBugModifications((OsmNotesPoint) osmPoint); + } + it.remove(); + parentFragment.deletePoint(osmPoint); + } + parentFragment.notifyDataSetChanged(); + + } + }); + builder.setNegativeButton(R.string.shared_string_cancel, null); + return builder.create(); + } + + public static DeleteOsmEditsConfirmDialogFragment createInstance( + ArrayList points) { + DeleteOsmEditsConfirmDialogFragment fragment = new DeleteOsmEditsConfirmDialogFragment(); + Bundle args = new Bundle(); + args.putSerializable(POINTS_LIST, points); + fragment.setArguments(args); + return fragment; + } + } + + public static class UploadOsmEditsConfirmDialogFragment extends DialogFragment { + public static final String TAG = "UploadOsmEditsConfirmDialogFragment"; + private static final String POINTS_ARRAY = "points_list"; + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final OsmPoint[] points = (OsmPoint[]) getArguments().getSerializable(POINTS_ARRAY); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage( + getString(R.string.local_osm_changes_upload_all_confirm, points.length)); + builder.setPositiveButton(R.string.shared_string_yes, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ((OsmEditsFragment) getParentFragment()) + .showUploadItemsProgressDialog(points); + } + }); + builder.setNegativeButton(R.string.shared_string_cancel, null); + return builder.create(); + } + + public static UploadOsmEditsConfirmDialogFragment createInstance(OsmPoint[] points) { + UploadOsmEditsConfirmDialogFragment fragment = + new UploadOsmEditsConfirmDialogFragment(); + Bundle args = new Bundle(); + args.putSerializable(POINTS_ARRAY, points); + fragment.setArguments(args); + return fragment; + } + } }