Search in sources :

Example 51 with MapActivity

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;
            }
        });
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RecyclerView(android.support.v7.widget.RecyclerView) Date(java.util.Date) LayoutInflater(android.view.LayoutInflater) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) MapActivity(net.osmand.plus.activities.MapActivity) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 52 with MapActivity

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();
    }
}
Also used : ImageButton(android.widget.ImageButton) ApplicationMode(net.osmand.plus.ApplicationMode) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RecyclerView(android.support.v7.widget.RecyclerView) MapActivity(net.osmand.plus.activities.MapActivity)

Example 53 with MapActivity

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);
}
Also used : MapActivity(net.osmand.plus.activities.MapActivity) NonNull(android.support.annotation.NonNull)

Example 54 with MapActivity

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();
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(android.support.annotation.NonNull)

Example 55 with MapActivity

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) OsmPoint(net.osmand.plus.osmedit.OsmPoint) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) CheckBox(android.widget.CheckBox) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(android.support.annotation.NonNull)

Aggregations

MapActivity (net.osmand.plus.activities.MapActivity)85 View (android.view.View)39 ImageView (android.widget.ImageView)28 TextView (android.widget.TextView)28 RecyclerView (android.support.v7.widget.RecyclerView)15 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)14 AlertDialog (android.support.v7.app.AlertDialog)12 Nullable (android.support.annotation.Nullable)11 DialogInterface (android.content.DialogInterface)10 AdapterView (android.widget.AdapterView)9 LatLon (net.osmand.data.LatLon)9 OsmandApplication (net.osmand.plus.OsmandApplication)9 Bundle (android.os.Bundle)7 Button (android.widget.Button)7 EditText (android.widget.EditText)7 ImageButton (android.widget.ImageButton)7 FavouritePoint (net.osmand.data.FavouritePoint)7 Fragment (android.support.v4.app.Fragment)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 ViewTreeObserver (android.view.ViewTreeObserver)6