Search in sources :

Example 21 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method saveExternalFile.

private String saveExternalFile(Set<String> deleted) {
    Map<String, FavouritePoint> all = new LinkedHashMap<String, FavouritePoint>();
    loadGPXFile(getExternalFile(), all);
    List<FavouritePoint> favoritePoints = new ArrayList<FavouritePoint>(cachedFavoritePoints);
    if (deleted != null) {
        for (String key : deleted) {
            all.remove(key);
        }
    }
    // remove already existing in memory
    for (FavouritePoint p : favoritePoints) {
        all.remove(getKey(p));
    }
    // save favoritePoints from memory in order to update existing
    favoritePoints.addAll(all.values());
    return saveFile(favoritePoints, getExternalFile());
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class TrackPointFragment method selectFavoritesImpl.

private void selectFavoritesImpl() {
    if (getSelectedItemsCount() > 0) {
        AlertDialog.Builder b = new AlertDialog.Builder(getTrackActivity());
        final EditText editText = new EditText(getTrackActivity());
        String name = getSelectedItems().iterator().next().group.getName();
        if (name.indexOf('\n') > 0) {
            name = name.substring(0, name.indexOf('\n'));
        }
        editText.setText(name);
        int leftMargin = AndroidUtils.dpToPx(getContext(), 16f);
        int topMargin = AndroidUtils.dpToPx(getContext(), 8f);
        editText.setPadding(leftMargin, topMargin, leftMargin, topMargin);
        b.setTitle(R.string.save_as_favorites_points);
        b.setView(editText);
        b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (actionMode != null) {
                    actionMode.finish();
                }
                FavouritesDbHelper fdb = app.getFavorites();
                for (GpxDisplayItem i : getSelectedItems()) {
                    if (i.locationStart != null) {
                        FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.name, editText.getText().toString());
                        if (!Algorithms.isEmpty(i.description)) {
                            fp.setDescription(i.description);
                        }
                        fdb.addFavourite(fp, false);
                    }
                }
                fdb.saveCurrentPointsIntoFile();
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        });
        b.setNegativeButton(R.string.shared_string_cancel, null);
        b.show();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) FavouritePoint(net.osmand.data.FavouritePoint) DialogInterface(android.content.DialogInterface) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) FavouritePoint(net.osmand.data.FavouritePoint)

Example 23 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritePointMenuBuilder method getCollapsableFavouritesView.

private CollapsableView getCollapsableFavouritesView(final Context context, boolean collapsed, @NonNull final FavoriteGroup group, FavouritePoint selectedPoint) {
    LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, true);
    List<FavouritePoint> points = group.points;
    for (int i = 0; i < points.size() && i < 10; i++) {
        final FavouritePoint point = points.get(i);
        boolean selected = selectedPoint != null && selectedPoint.equals(point);
        TextViewEx button = buildButtonInCollapsableView(context, selected, false);
        String name = point.getName();
        button.setText(name);
        if (!selected) {
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    LatLon latLon = new LatLon(point.getLatitude(), point.getLongitude());
                    PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName());
                    mapActivity.getContextMenu().show(latLon, pointDescription, point);
                }
            });
        }
        view.addView(button);
    }
    if (points.size() > 10) {
        TextViewEx button = buildButtonInCollapsableView(context, false, true);
        button.setText(context.getString(R.string.shared_string_show_all));
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                OsmAndAppCustomization appCustomization = app.getAppCustomization();
                final Intent intent = new Intent(context, appCustomization.getFavoritesActivity());
                intent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
                intent.putExtra(FavoritesActivity.GROUP_NAME_TO_SHOW, group.name);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                context.startActivity(intent);
            }
        });
        view.addView(button);
    }
    return new CollapsableView(view, this, collapsed);
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) TextViewEx(net.osmand.plus.widgets.TextViewEx) OsmAndAppCustomization(net.osmand.plus.OsmAndAppCustomization) PointDescription(net.osmand.data.PointDescription) LinearLayout(android.widget.LinearLayout)

Example 24 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavoriteDialogs method confirmReplace.

private static void confirmReplace(final Activity activity, final Bundle args, final FavouritesDbHelper helper, final FavouritesAdapter favouritesAdapter, final Dialog[] dlgHolder, int position) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.update_existing);
    final FavouritePoint fp = favouritesAdapter.getItem(position);
    builder.setMessage(activity.getString(R.string.replace_favorite_confirmation, fp.getName()));
    builder.setNegativeButton(R.string.shared_string_no, null);
    builder.setPositiveButton(R.string.shared_string_yes, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (dlgHolder != null && dlgHolder.length > 0 && dlgHolder[0] != null) {
                dlgHolder[0].dismiss();
            }
            FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
            if (helper.editFavourite(fp, point.getLatitude(), point.getLongitude())) {
                if (activity instanceof MapActivity) {
                    ((MapActivity) activity).getContextMenu().show(new LatLon(point.getLatitude(), point.getLongitude()), fp.getPointDescription(), fp);
                }
            }
            if (activity instanceof MapActivity) {
                ((MapActivity) activity).getMapView().refreshMap();
            }
        }
    });
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LatLon(net.osmand.data.LatLon) FavouritePoint(net.osmand.data.FavouritePoint) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) FavouritePoint(net.osmand.data.FavouritePoint) MapActivity(net.osmand.plus.activities.MapActivity)

Example 25 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavoriteDialogs method createAddFavouriteDialog.

public static Dialog createAddFavouriteDialog(final Activity activity, final Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.favourites_context_menu_edit);
    final View v = activity.getLayoutInflater().inflate(R.layout.favorite_edit_dialog, null, false);
    final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
    builder.setView(v);
    final EditText editText = (EditText) v.findViewById(R.id.Name);
    final EditText description = (EditText) v.findViewById(R.id.description);
    final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
    List<FavoriteGroup> gs = helper.getFavoriteGroups();
    final String[] list = new String[gs.size()];
    for (int i = 0; i < list.length; i++) {
        list[i] = gs.get(i).name;
    }
    cat.setAdapter(new ArrayAdapter<String>(activity, R.layout.list_textview, list));
    if (((OsmandApplication) activity.getApplication()).accessibilityEnabled()) {
        final TextView textButton = (TextView) v.findViewById(R.id.TextButton);
        textButton.setClickable(true);
        textButton.setFocusable(true);
        textButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlertDialog.Builder b = new AlertDialog.Builder(activity);
                b.setTitle(R.string.access_category_choice);
                b.setItems(list, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        cat.setText(list[which]);
                    }
                });
                b.setNegativeButton(R.string.shared_string_cancel, null);
                b.show();
            }
        });
    }
    builder.setNegativeButton(R.string.shared_string_cancel, null);
    builder.setNeutralButton(R.string.update_existing, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Don't use showDialog because it is impossible to refresh favorite items list
            Dialog dlg = createReplaceFavouriteDialog(activity, args);
            if (dlg != null) {
                dlg.show();
            }
        // mapActivity.showDialog(DIALOG_REPLACE_FAVORITE);
        }
    });
    builder.setPositiveButton(R.string.shared_string_add, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
            OsmandApplication app = (OsmandApplication) activity.getApplication();
            String categoryStr = cat.getText().toString().trim();
            final FavouritesDbHelper helper = app.getFavorites();
            app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr);
            point.setName(editText.getText().toString().trim());
            point.setDescription(description.getText().toString().trim());
            point.setCategory(categoryStr);
            AlertDialog.Builder bld = FavouritesDbHelper.checkDuplicates(point, helper, activity);
            if (bld != null) {
                bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        addFavorite(activity, point, helper);
                    }
                });
                bld.show();
            } else {
                addFavorite(activity, point, helper);
            }
        }

        protected void addFavorite(final Activity activity, FavouritePoint point, final FavouritesDbHelper helper) {
            boolean added = helper.addFavourite(point);
            if (added) {
                Toast.makeText(activity, MessageFormat.format(activity.getString(R.string.add_favorite_dialog_favourite_added_template), point.getName()), Toast.LENGTH_SHORT).show();
            }
            if (activity instanceof MapActivity) {
                ((MapActivity) activity).getMapView().refreshMap(true);
            }
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) DialogInterface(android.content.DialogInterface) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) Activity(android.app.Activity) MapActivity(net.osmand.plus.activities.MapActivity) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ListView(android.widget.ListView) FavouritePoint(net.osmand.data.FavouritePoint) OnClickListener(android.content.DialogInterface.OnClickListener) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

FavouritePoint (net.osmand.data.FavouritePoint)51 LatLon (net.osmand.data.LatLon)16 PointDescription (net.osmand.data.PointDescription)10 FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)10 View (android.view.View)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.support.v7.app.AlertDialog)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 TextView (android.widget.TextView)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 MapActivity (net.osmand.plus.activities.MapActivity)7 DialogInterface (android.content.DialogInterface)6 ImageView (android.widget.ImageView)6 Amenity (net.osmand.data.Amenity)6 Paint (android.graphics.Paint)5 AdapterView (android.widget.AdapterView)5 ListView (android.widget.ListView)5 FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)5 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)5 Collator (java.text.Collator)4