use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method saveAsGpx.
private void saveAsGpx(final SaveType saveType) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
final LayoutInflater inflater = mapActivity.getLayoutInflater();
final View view = inflater.inflate(R.layout.save_gpx_dialog, null);
final EditText nameEt = (EditText) view.findViewById(R.id.gpx_name_et);
final TextView warningTextView = (TextView) view.findViewById(R.id.file_exists_text_view);
final SwitchCompat showOnMapToggle = (SwitchCompat) view.findViewById(R.id.toggle_show_on_map);
showOnMapToggle.setChecked(true);
final String suggestedName = new SimpleDateFormat("yyyy-MM-dd_HH-mm_EEE", Locale.US).format(new Date());
String displayedName = suggestedName;
File fout = new File(dir, suggestedName + GPX_SUFFIX);
int ind = 1;
while (fout.exists()) {
displayedName = suggestedName + "_" + (++ind);
fout = new File(dir, displayedName + GPX_SUFFIX);
}
nameEt.setText(displayedName);
nameEt.setSelection(displayedName.length());
final boolean[] textChanged = new boolean[1];
AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity).setTitle(R.string.enter_gpx_name).setView(view).setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final String name = nameEt.getText().toString();
String fileName = name + GPX_SUFFIX;
if (textChanged[0]) {
File fout = new File(dir, fileName);
int ind = 1;
while (fout.exists()) {
fileName = name + "_" + (++ind) + GPX_SUFFIX;
fout = new File(dir, fileName);
}
}
saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType, false);
}
}).setNegativeButton(R.string.shared_string_cancel, null);
final AlertDialog dialog = builder.create();
dialog.show();
nameEt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (new File(dir, editable.toString() + GPX_SUFFIX).exists()) {
warningTextView.setVisibility(View.VISIBLE);
warningTextView.setText(R.string.file_with_name_already_exists);
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
} else if (editable.toString().trim().isEmpty()) {
warningTextView.setVisibility(View.VISIBLE);
warningTextView.setText(R.string.enter_the_file_name);
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
} else {
warningTextView.setVisibility(View.INVISIBLE);
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
}
textChanged[0] = true;
}
});
}
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class MeasurementToolFragment method showSnapToRoadControls.
private void showSnapToRoadControls() {
final MapActivity mapActivity = getMapActivity();
final ApplicationMode appMode = editingCtx.getSnapToRoadAppMode();
if (mapActivity != null && appMode != null) {
toolBarController.setTopBarSwitchVisible(true);
toolBarController.setTopBarSwitchChecked(true);
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_snap_to_road));
ImageButton snapToRoadBtn = (ImageButton) mapActivity.findViewById(R.id.snap_to_road_image_button);
snapToRoadBtn.setBackgroundResource(nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle);
snapToRoadBtn.setImageDrawable(getActiveIcon(appMode.getMapIconId()));
snapToRoadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showSnapToRoadMenu(false);
}
});
snapToRoadBtn.setVisibility(View.VISIBLE);
mapActivity.refreshMap();
}
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class SelectedPointBottomSheetDialogFragment method getTitle.
@NonNull
private String getTitle() {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return "";
}
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
int pos = editingCtx.getSelectedPointPosition();
String pointName = editingCtx.getPoints().get(pos).name;
if (!TextUtils.isEmpty(pointName)) {
return pointName;
}
NewGpxData newGpxData = editingCtx.getNewGpxData();
if (newGpxData != null && newGpxData.getActionType() == ActionType.ADD_ROUTE_POINTS) {
return getString(R.string.route_point) + " - " + (pos + 1);
}
return getString(R.string.plugin_distance_point) + " - " + (pos + 1);
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class SelectedPointBottomSheetDialogFragment method getDescription.
@NonNull
private String getDescription() {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return "";
}
StringBuilder description = new StringBuilder();
MeasurementEditingContext editingCtx = mapActivity.getMapLayers().getMeasurementToolLayer().getEditingCtx();
int pos = editingCtx.getSelectedPointPosition();
List<WptPt> points = editingCtx.getPoints();
WptPt pt = points.get(pos);
String pointDesc = pt.desc;
if (!TextUtils.isEmpty(pointDesc)) {
description.append(pointDesc);
} else if (pos < 1) {
description.append(getString(R.string.shared_string_control_start));
} else {
float dist = 0;
for (int i = 1; i <= pos; i++) {
WptPt first = points.get(i - 1);
WptPt second = points.get(i);
dist += MapUtils.getDistance(first.lat, first.lon, second.lat, second.lon);
}
description.append(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
}
NewGpxData newGpxData = editingCtx.getNewGpxData();
if (newGpxData != null && newGpxData.getActionType() == ActionType.EDIT_SEGMENT) {
double elevation = pt.ele;
if (!Double.isNaN(elevation)) {
description.append(" ").append((getString(R.string.altitude)).substring(0, 1)).append(": ");
description.append(OsmAndFormatter.getFormattedAlt(elevation, mapActivity.getMyApplication()));
}
float speed = (float) pt.speed;
if (speed != 0) {
description.append(" ").append((getString(R.string.map_widget_speed)).substring(0, 1)).append(": ");
description.append(OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication()));
}
}
return description.toString();
}
use of net.osmand.plus.activities.MapActivity in project Osmand by osmandapp.
the class SendPoiDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
final PoiUploaderType poiUploaderType = PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, PoiUploaderType.SIMPLE.name()));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null);
final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
final EditText messageEditText = (EditText) view.findViewById(R.id.message_field);
final EditText userNameEditText = (EditText) view.findViewById(R.id.user_name_field);
final EditText passwordEditText = (EditText) view.findViewById(R.id.password_field);
final View messageLabel = view.findViewById(R.id.message_label);
final View userNameLabel = view.findViewById(R.id.osm_user_name_label);
final View passwordLabel = view.findViewById(R.id.osm_user_password_label);
final CheckBox closeChangeSetCheckBox = (CheckBox) view.findViewById(R.id.close_change_set_checkbox);
final OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings();
userNameEditText.setText(settings.USER_NAME.get());
passwordEditText.setText(settings.USER_PASSWORD.get());
boolean hasPoiGroup = false;
assert poi != null;
for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) {
hasPoiGroup = true;
break;
}
}
String defaultChangeSet = createDefaultChangeSet();
messageEditText.setText(defaultChangeSet);
final boolean hasPOI = hasPoiGroup;
messageLabel.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
messageEditText.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
closeChangeSetCheckBox.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
closeChangeSetCheckBox.setChecked(hasPOI && !defaultChangeSet.equals(""));
view.findViewById(R.id.osm_note_header).setVisibility(hasPOI ? View.GONE : View.VISIBLE);
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
userNameLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
userNameEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
}
});
final ProgressDialogPoiUploader progressDialogPoiUploader;
if (poiUploaderType == PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
progressDialogPoiUploader = new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity());
} else {
progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
}
builder.setTitle(hasPOI ? R.string.upload_poi : R.string.upload_osm_note).setView(view).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (progressDialogPoiUploader != null) {
settings.USER_NAME.set(userNameEditText.getText().toString());
settings.USER_PASSWORD.set(passwordEditText.getText().toString());
String comment = messageEditText.getText().toString();
if (comment.length() > 0) {
for (OsmPoint osmPoint : poi) {
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
((OpenstreetmapPoint) osmPoint).setComment(comment);
break;
}
}
}
progressDialogPoiUploader.showProgressDialog(poi, closeChangeSetCheckBox.isChecked(), !hasPOI && uploadAnonymously.isChecked());
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
return builder.create();
}
Aggregations