add coordinate input to my places-tracks

This commit is contained in:
Chumva 2018-06-18 15:29:32 +03:00
parent f96525089d
commit 8c63958053
3 changed files with 21 additions and 12 deletions

View file

@ -6,7 +6,6 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -38,7 +37,6 @@ import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
@ -60,7 +58,6 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener; import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener;
@ -1225,9 +1222,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
if (!compassUpdateAllowed) { if (!compassUpdateAllowed) {
return; return;
} }
final MapActivity mapActivity = (MapActivity) getActivity(); final OsmandApplication app = getMyApplication();
if (mapActivity != null && adapter != null) { if (app != null && adapter != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();

View file

@ -21,9 +21,9 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
@ -47,6 +47,7 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
boolean isCoordInput = false; boolean isCoordInput = false;
int number = 0; int number = 0;
Bundle args = getArguments(); Bundle args = getArguments();
@ -55,9 +56,8 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
if (number != 0) if (number != 0)
isCoordInput = true; isCoordInput = true;
} }
MapActivity mapActivity = (MapActivity) getActivity();
portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
final boolean nightMode = !getMyApplication().getSettings().isLightContent(); final boolean nightMode = !app.getSettings().isLightContent();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container); final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container);
@ -81,16 +81,16 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
if (textBox instanceof TextInputLayout) { if (textBox instanceof TextInputLayout) {
((TextInputLayout) textBox).setHintTextAppearance(R.style.TextAppearance_App_DarkTextInputLayout); ((TextInputLayout) textBox).setHintTextAppearance(R.style.TextAppearance_App_DarkTextInputLayout);
} else if (textBox instanceof OsmandTextFieldBoxes) { } else if (textBox instanceof OsmandTextFieldBoxes) {
((OsmandTextFieldBoxes) textBox).setPrimaryColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark)); ((OsmandTextFieldBoxes) textBox).setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
} }
} }
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers");
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
Date date = new Date(); Date date = new Date();
final String suggestedName = mapActivity.getString(R.string.markers) + "_" + DateFormat.format("yyyy-MM-dd", date).toString(); final String suggestedName = app.getString(R.string.markers) + "_" + DateFormat.format("yyyy-MM-dd", date).toString();
String displayedName = suggestedName; String displayedName = suggestedName;
File fout = new File(dir, suggestedName + GPX_SUFFIX); File fout = new File(dir, suggestedName + GPX_SUFFIX);
int ind = 1; int ind = 1;

View file

@ -77,6 +77,7 @@ import net.osmand.plus.download.ui.LocalIndexesFragment;
import net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback; import net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -474,6 +475,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}); });
} else if (itemId == R.string.gpx_add_track) { } else if (itemId == R.string.gpx_add_track) {
addTrack(); addTrack();
}else if (itemId == R.string.coordinate_input) {
openCoordinatesInput();
} }
return true; return true;
} }
@ -481,6 +484,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.gpx_add_track, getActivity()) optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.gpx_add_track, getActivity())
.setIcon(R.drawable.ic_action_plus) .setIcon(R.drawable.ic_action_plus)
.setListener(listener).createItem()); .setListener(listener).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.coordinate_input, getActivity())
.setIcon(R.drawable.ic_action_coordinates_longitude)
.setListener(listener).createItem());
optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity()) optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity())
.setIcon(R.drawable.ic_show_on_map) .setIcon(R.drawable.ic_show_on_map)
.setListener(listener).createItem()); .setListener(listener).createItem());
@ -538,6 +544,12 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
((FavoritesActivity) getActivity()).addTrack(); ((FavoritesActivity) getActivity()).addTrack();
} }
private void openCoordinatesInput() {
CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment();
fragment.setRetainInstance(true);
fragment.show(getChildFragmentManager(), CoordinateInputDialogFragment.TAG);
}
public void showProgressBar() { public void showProgressBar() {
((FavoritesActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true); ((FavoritesActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true);
} }