Fix waypoints
This commit is contained in:
parent
f1c576f2a3
commit
135d01b7c7
5 changed files with 120 additions and 70 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/MainLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
@ -25,4 +25,4 @@
|
|||
|
||||
<include layout="@layout/my_places_fabs"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.design.widget.CoordinatorLayout>
|
|
@ -9,6 +9,8 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="view">View</string>
|
||||
<string name="waypoints_added_to_map_markers">Waypoints added to map markers</string>
|
||||
<string name="wrong_format">Wrong format</string>
|
||||
<string name="shared_string_road">Road</string>
|
||||
<string name="show_map">Show map</string>
|
||||
|
|
|
@ -144,6 +144,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
MapMarkerChangedListener, OnDismissDialogFragmentListener, OnDrawMapListener {
|
||||
public static final String INTENT_KEY_PARENT_MAP_ACTIVITY = "intent_parent_map_activity_key";
|
||||
|
||||
public static final String OPEN_MAP_MARKERS_GROUPS = "open_map_markers_groups";
|
||||
|
||||
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;
|
||||
|
@ -680,6 +682,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
}
|
||||
}
|
||||
if (intent.hasExtra(OPEN_MAP_MARKERS_GROUPS)) {
|
||||
MapMarkersDialogFragment.showInstance(this, true);
|
||||
}
|
||||
}
|
||||
mapView.refreshMap(true);
|
||||
if (atlasMapRendererView != null) {
|
||||
|
@ -1378,7 +1383,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
return mapLayers;
|
||||
}
|
||||
|
||||
public static void launchMapActivityMoveToTop(Context activity) {
|
||||
public static void launchMapActivityMoveToTop(Context activity, String openMarkersAction) {
|
||||
if (activity instanceof MapActivity) {
|
||||
if (((MapActivity) activity).getDashboard().isVisible()) {
|
||||
((MapActivity) activity).getDashboard().hideDashboard();
|
||||
|
@ -1400,10 +1405,17 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
Intent newIntent = new Intent(activity, ((OsmandApplication) activity.getApplicationContext())
|
||||
.getAppCustomization().getMapActivity());
|
||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
if (openMarkersAction != null) {
|
||||
newIntent.putExtra(openMarkersAction, true);
|
||||
}
|
||||
activity.startActivity(newIntent);
|
||||
}
|
||||
}
|
||||
|
||||
public static void launchMapActivityMoveToTop(Context activity) {
|
||||
launchMapActivityMoveToTop(activity, null);
|
||||
}
|
||||
|
||||
public static void clearPrevActivityIntent() {
|
||||
prevActivityIntent = null;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,11 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
Bundle args = getArguments();
|
||||
boolean openGroups = false;
|
||||
if (args != null && args.getBoolean(MapActivity.OPEN_MAP_MARKERS_GROUPS)) {
|
||||
openGroups = true;
|
||||
}
|
||||
List<Fragment> fragments = getChildFragmentManager().getFragments();
|
||||
if (fragments != null) {
|
||||
for (Fragment fragment : fragments) {
|
||||
|
@ -144,6 +149,12 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
bottomNav.setItemIconTintList(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
|
||||
bottomNav.setItemTextColor(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
|
||||
}
|
||||
if (openGroups) {
|
||||
activeFragment.stopLocationUpdate();
|
||||
groupsFragment.startLocationUpdate();
|
||||
groupsFragment.updateAdapter();
|
||||
viewPager.setCurrentItem(GROUPS_POSITION, false);
|
||||
}
|
||||
bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
|
@ -350,11 +361,20 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
}
|
||||
|
||||
public static boolean showInstance(@NonNull MapActivity mapActivity) {
|
||||
return showInstance(mapActivity, false);
|
||||
}
|
||||
|
||||
public static boolean showInstance(@NonNull MapActivity mapActivity, boolean openGroups) {
|
||||
try {
|
||||
if (mapActivity.isActivityDestroyed()) {
|
||||
return false;
|
||||
}
|
||||
MapMarkersDialogFragment fragment = new MapMarkersDialogFragment();
|
||||
if (openGroups) {
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean(MapActivity.OPEN_MAP_MARKERS_GROUPS, true);
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.os.Handler;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
@ -91,7 +92,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
final private PointGPXAdapter adapter = new PointGPXAdapter();
|
||||
private GpxDisplayItemType[] filterTypes = {GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS};
|
||||
private boolean selectionMode = false;
|
||||
private boolean addToMapMarkersMode = false;
|
||||
private LinkedHashMap<GpxDisplayItemType, Set<GpxDisplayItem>> selectedItems = new LinkedHashMap<>();
|
||||
private Set<Integer> selectedGroups = new LinkedHashSet<>();
|
||||
private ActionMode actionMode;
|
||||
|
@ -105,6 +105,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
private FloatingActionButton lineFab;
|
||||
private View lineTextLayout;
|
||||
private View overlayView;
|
||||
private View mainView;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -179,29 +180,29 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.track_points_tree, container, false);
|
||||
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
|
||||
mainView = inflater.inflate(R.layout.track_points_tree, container, false);
|
||||
ExpandableListView listView = (ExpandableListView) mainView.findViewById(android.R.id.list);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
overlayView = view.findViewById(R.id.overlay_view);
|
||||
overlayView = mainView.findViewById(R.id.overlay_view);
|
||||
overlayView.setOnClickListener(onFabClickListener);
|
||||
|
||||
menuFab = (FloatingActionButton) view.findViewById(R.id.menu_fab);
|
||||
menuFab = (FloatingActionButton) mainView.findViewById(R.id.menu_fab);
|
||||
menuFab.setOnClickListener(onFabClickListener);
|
||||
|
||||
waypointFab = (FloatingActionButton) view.findViewById(R.id.waypoint_fab);
|
||||
waypointFab = (FloatingActionButton) mainView.findViewById(R.id.waypoint_fab);
|
||||
waypointFab.setOnClickListener(onFabClickListener);
|
||||
waypointTextLayout = view.findViewById(R.id.waypoint_text_layout);
|
||||
waypointTextLayout = mainView.findViewById(R.id.waypoint_text_layout);
|
||||
waypointTextLayout.setOnClickListener(onFabClickListener);
|
||||
|
||||
routePointFab = (FloatingActionButton) view.findViewById(R.id.route_fab);
|
||||
routePointFab = (FloatingActionButton) mainView.findViewById(R.id.route_fab);
|
||||
routePointFab.setOnClickListener(onFabClickListener);
|
||||
routePointTextLayout = view.findViewById(R.id.route_text_layout);
|
||||
routePointTextLayout = mainView.findViewById(R.id.route_text_layout);
|
||||
routePointTextLayout.setOnClickListener(onFabClickListener);
|
||||
|
||||
lineFab = (FloatingActionButton) view.findViewById(R.id.line_fab);
|
||||
lineFab = (FloatingActionButton) mainView.findViewById(R.id.line_fab);
|
||||
lineFab.setOnClickListener(onFabClickListener);
|
||||
lineTextLayout = view.findViewById(R.id.line_text_layout);
|
||||
lineTextLayout = mainView.findViewById(R.id.line_text_layout);
|
||||
lineTextLayout.setOnClickListener(onFabClickListener);
|
||||
|
||||
TextView tv = new TextView(getActivity());
|
||||
|
@ -212,7 +213,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
setContent(listView);
|
||||
setListView(listView);
|
||||
expandAllGroups();
|
||||
return view;
|
||||
return mainView;
|
||||
}
|
||||
|
||||
private int getSelectedItemsCount() {
|
||||
|
@ -469,10 +470,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
this.selectionMode = selectionMode;
|
||||
}
|
||||
|
||||
private void enableAddToMapMarkersMode(boolean addToMapMarkersMode) {
|
||||
this.addToMapMarkersMode = addToMapMarkersMode;
|
||||
}
|
||||
|
||||
private void enterDeleteMode() {
|
||||
|
||||
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
|
||||
|
@ -588,50 +585,83 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
|
||||
private void enterMapMarkersMode() {
|
||||
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
|
||||
if (getSettings().USE_MAP_MARKERS.get()) {
|
||||
addMapMarkersSyncGroup();
|
||||
} else {
|
||||
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
if (getSettings().USE_MAP_MARKERS.get()) {
|
||||
enableAddToMapMarkersMode(true);
|
||||
createMenuItem(menu, SELECT_MAP_MARKERS_ACTION_MODE_ID, R.string.shared_string_add_to_map_markers,
|
||||
R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_dark,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
} else {
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
enableSelectionMode(true);
|
||||
createMenuItem(menu, SELECT_MAP_MARKERS_ACTION_MODE_ID, R.string.select_destination_and_intermediate_points,
|
||||
R.drawable.ic_action_intermediate, R.drawable.ic_action_intermediate,
|
||||
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
|
||||
selectedItems.clear();
|
||||
selectedGroups.clear();
|
||||
adapter.notifyDataSetInvalidated();
|
||||
updateSelectionMode(mode);
|
||||
return true;
|
||||
}
|
||||
selectedItems.clear();
|
||||
selectedGroups.clear();
|
||||
adapter.notifyDataSetInvalidated();
|
||||
updateSelectionMode(mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
enableSelectionMode(false);
|
||||
enableAddToMapMarkersMode(false);
|
||||
adapter.notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if (item.getItemId() == SELECT_MAP_MARKERS_ACTION_MODE_ID) {
|
||||
mode.finish();
|
||||
selectMapMarkersImpl();
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
enableSelectionMode(false);
|
||||
adapter.notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if (item.getItemId() == SELECT_MAP_MARKERS_ACTION_MODE_ID) {
|
||||
mode.finish();
|
||||
selectMapMarkersImpl();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void addMapMarkersSyncGroup() {
|
||||
MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
File gpx = getGpxDataItem().getFile();
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroup(syncGroup);
|
||||
GPXFile gpxFile = getTrackActivity().getGpx();
|
||||
if (gpxFile != null) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
|
||||
}
|
||||
hideTransparentOverlay();
|
||||
closeMenu();
|
||||
updateMenuFabVisibility(false);
|
||||
Snackbar snackbar = Snackbar.make(mainView, getResources().getString(R.string.waypoints_added_to_map_markers), Snackbar.LENGTH_LONG)
|
||||
.setAction(getResources().getString(R.string.view), new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MapActivity.launchMapActivityMoveToTop(getTrackActivity(), MapActivity.OPEN_MAP_MARKERS_GROUPS);
|
||||
}
|
||||
});
|
||||
snackbar.addCallback(new Snackbar.Callback() {
|
||||
@Override
|
||||
public void onDismissed(Snackbar transientBottomBar, int event) {
|
||||
updateMenuFabVisibility(true);
|
||||
super.onDismissed(transientBottomBar, event);
|
||||
}
|
||||
});
|
||||
View snackBarView = snackbar.getView();
|
||||
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
|
||||
tv.setTextColor(ContextCompat.getColor(getContext(), R.color.color_dialog_buttons_dark));
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
private void updateMenuFabVisibility(boolean visible) {
|
||||
menuFab.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private void selectMapMarkersImpl() {
|
||||
|
@ -641,17 +671,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
List<LatLon> points = new LinkedList<>();
|
||||
List<PointDescription> names = new LinkedList<>();
|
||||
for (Map.Entry<GpxDisplayItemType, Set<GpxDisplayItem>> entry : selectedItems.entrySet()) {
|
||||
if (entry.getKey() == GpxDisplayItemType.TRACK_POINTS) {
|
||||
File gpx = getGpxDataItem().getFile();
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroup(syncGroup);
|
||||
GPXFile gpxFile = getTrackActivity().getGpx();
|
||||
if (gpxFile != null) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
|
||||
}
|
||||
} else {
|
||||
if (entry.getKey() != GpxDisplayItemType.TRACK_POINTS) {
|
||||
for (GpxDisplayItem i : entry.getValue()) {
|
||||
if (i.locationStart != null) {
|
||||
points.add(new LatLon(i.locationStart.lat, i.locationStart.lon));
|
||||
|
@ -788,7 +808,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
}
|
||||
updateSelectionMode(actionMode);
|
||||
} else if (!addToMapMarkersMode) {
|
||||
} else {
|
||||
final GpxDisplayItem item = adapter.getChild(groupPosition, childPosition);
|
||||
if (item != null) {
|
||||
if (item.group.getGpx() != null) {
|
||||
|
@ -897,8 +917,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
View row = convertView;
|
||||
final GpxDisplayGroup group = getGroup(groupPosition);
|
||||
boolean checkBox = row != null && row.findViewById(R.id.toggle_item) instanceof CheckBox;
|
||||
boolean showCheckBox = selectionMode || (addToMapMarkersMode && group.getType() == GpxDisplayItemType.TRACK_POINTS);
|
||||
boolean same = (showCheckBox && checkBox) || (!showCheckBox && !checkBox);
|
||||
boolean same = (selectionMode && checkBox) || (!selectionMode && !checkBox);
|
||||
if (row == null || !same) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
row = inflater.inflate(R.layout.wpt_list_item_category, parent, false);
|
||||
|
@ -915,7 +934,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
description.setText(getString(R.string.route_points_category_name));
|
||||
}
|
||||
|
||||
if (showCheckBox) {
|
||||
if (selectionMode) {
|
||||
final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item);
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setChecked(selectedGroups.contains(groupPosition));
|
||||
|
@ -1061,9 +1080,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
});
|
||||
} else {
|
||||
row.findViewById(R.id.icon).setVisibility(View.VISIBLE);
|
||||
if (addToMapMarkersMode) {
|
||||
ch.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue