add coordinate input to TrackPointFragment

This commit is contained in:
Chumva 2018-06-19 19:20:38 +03:00
parent 107a830d6e
commit 273e5675c1
3 changed files with 42 additions and 3 deletions

View file

@ -54,6 +54,7 @@ import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
@ -80,14 +81,18 @@ import java.util.Locale;
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN; import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
import static android.content.Context.CLIPBOARD_SERVICE; import static android.content.Context.CLIPBOARD_SERVICE;
import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT; import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT;
import static net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.COORDINATE_INPUT_MODE_KEY;
public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener {
public static final String TAG = "CoordinateInputDialogFragment"; public static final String TAG = "CoordinateInputDialogFragment";
public static final String ADDED_MARKERS_NUMBER_KEY = "added_markers_number_key"; public static final String ADDED_MARKERS_NUMBER_KEY = "added_markers_number_key";
public static final String WAYPOINTS_MODE_KEY = "waypoints_mode_key";
private final List<MapMarker> mapMarkers = new ArrayList<>(); private final List<MapMarker> mapMarkers = new ArrayList<>();
private List<GPXUtilities.WptPt> waypoints;
private MapMarker selectedMarker; private MapMarker selectedMarker;
private GPXUtilities.GPXFile gpxFile;
private OnMapMarkersSavedListener listener; private OnMapMarkersSavedListener listener;
private View mainView; private View mainView;
@ -100,6 +105,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
private boolean hasUnsavedChanges; private boolean hasUnsavedChanges;
private boolean isSoftKeyboardShown; private boolean isSoftKeyboardShown;
private boolean isWptMode;
private boolean north = true; private boolean north = true;
private boolean east = true; private boolean east = true;
@ -118,6 +124,17 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
lightTheme = getMyApplication().getSettings().isLightContent(); lightTheme = getMyApplication().getSettings().isLightContent();
setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
Bundle args = getArguments();
if (args != null) {
isWptMode = args.getBoolean(WAYPOINTS_MODE_KEY);
if (isWptMode && gpxFile != null) {
waypoints = gpxFile.getPoints();
}
}
}
public void setGpxFile(GPXUtilities.GPXFile gpxFile) {
this.gpxFile = gpxFile;
} }
private void quit() { private void quit() {
@ -134,6 +151,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size()); args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size());
args.putBoolean(COORDINATE_INPUT_MODE_KEY, true);
fragment.setArguments(args); fragment.setArguments(args);
fragment.setListener(createSaveAsTrackFragmentListener()); fragment.setListener(createSaveAsTrackFragmentListener());
fragment.show(getChildFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG); fragment.show(getChildFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);

View file

@ -36,6 +36,7 @@ import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.ADDED_MAR
public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment { public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment {
public final static String TAG = "SaveAsTrackBottomSheetDialogFragment"; public final static String TAG = "SaveAsTrackBottomSheetDialogFragment";
public static final String COORDINATE_INPUT_MODE_KEY = "coordinate_input_mode_key";
private boolean portrait; private boolean portrait;
private MarkerSaveAsTrackFragmentListener listener; private MarkerSaveAsTrackFragmentListener listener;
@ -52,9 +53,10 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
int number = 0; int number = 0;
Bundle args = getArguments(); Bundle args = getArguments();
if (args != null) { if (args != null) {
isCoordInput = args.getBoolean(COORDINATE_INPUT_MODE_KEY);
if (isCoordInput) {
number = args.getInt(ADDED_MARKERS_NUMBER_KEY); number = args.getInt(ADDED_MARKERS_NUMBER_KEY);
if (number != 0) }
isCoordInput = true;
} }
portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
final boolean nightMode = !app.getSettings().isLightContent(); final boolean nightMode = !app.getSettings().isLightContent();

View file

@ -65,6 +65,7 @@ import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -83,6 +84,8 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.WAYPOINTS_MODE_KEY;
public class TrackPointFragment extends OsmandExpandableListFragment implements TrackBitmapDrawerListener { public class TrackPointFragment extends OsmandExpandableListFragment implements TrackBitmapDrawerListener {
public static final int SEARCH_ID = -1; public static final int SEARCH_ID = -1;
@ -90,6 +93,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
public static final int DELETE_ACTION_ID = 3; public static final int DELETE_ACTION_ID = 3;
public static final int SHARE_ID = 4; public static final int SHARE_ID = 4;
public static final int SELECT_MAP_MARKERS_ID = 5; public static final int SELECT_MAP_MARKERS_ID = 5;
public static final int COORDINATE_INPUT_ID = 6;
//public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6; //public static final int SELECT_MAP_MARKERS_ACTION_MODE_ID = 6;
public static final int SELECT_FAVORITES_ID = 7; public static final int SELECT_FAVORITES_ID = 7;
public static final int SELECT_FAVORITES_ACTION_MODE_ID = 8; public static final int SELECT_FAVORITES_ACTION_MODE_ID = 8;
@ -274,6 +278,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
} else if (item.getItemId() == DELETE_ID) { } else if (item.getItemId() == DELETE_ID) {
enterDeleteMode(); enterDeleteMode();
return true; return true;
} else if (item.getItemId() == COORDINATE_INPUT_ID) {
openCoordinatesInput();
return true;
} else { } else {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -301,6 +308,16 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
} }
} }
private void openCoordinatesInput() {
Bundle args = new Bundle();
args.putBoolean(WAYPOINTS_MODE_KEY, true);
CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
fragment.setRetainInstance(true);
fragment.setArguments(args);
fragment.setGpxFile(getGpx());
fragment.show(getChildFragmentManager(), CoordinateInputDialogFragment.TAG);
}
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear(); menu.clear();
@ -367,6 +384,8 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
R.drawable.ic_action_fav_dark, MenuItem.SHOW_AS_ACTION_NEVER); R.drawable.ic_action_fav_dark, MenuItem.SHOW_AS_ACTION_NEVER);
createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark,
R.drawable.ic_action_delete_dark, MenuItem.SHOW_AS_ACTION_NEVER); R.drawable.ic_action_delete_dark, MenuItem.SHOW_AS_ACTION_NEVER);
createMenuItem(menu, COORDINATE_INPUT_ID, R.string.coordinate_input, R.drawable.ic_action_coordinates_longitude,
R.drawable.ic_action_coordinates_longitude, MenuItem.SHOW_AS_ACTION_NEVER);
} }
this.optionsMenu = menu; this.optionsMenu = menu;
} }