Search in sources :

Example 6 with FavoriteGroup

use of net.osmand.plus.FavouritesDbHelper.FavoriteGroup in project Osmand by osmandapp.

the class FavoritesTreeFragment method selectMapMarkersImpl.

private void selectMapMarkersImpl() {
    if (getSelectedFavoritesCount() > 0) {
        MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
        List<LatLon> points = new ArrayList<>();
        List<PointDescription> names = new ArrayList<>();
        for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
            FavoriteGroup favGr = helper.getGroup(entry.getKey());
            MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(favGr);
            if (entry.getValue().size() == favGr.points.size()) {
                markersHelper.addOrEnableGroup(markersGr);
            } else {
                for (FavouritePoint fp : entry.getValue()) {
                    points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
                    names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
                }
                markersHelper.addMapMarkers(points, names, markersGr);
                points.clear();
                names.clear();
            }
        }
        MapActivity.launchMapActivityMoveToTop(getActivity());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) ArrayList(java.util.ArrayList) LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) PointDescription(net.osmand.data.PointDescription) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with FavoriteGroup

use of net.osmand.plus.FavouritesDbHelper.FavoriteGroup in project Osmand by osmandapp.

the class FavoritesTreeFragment method shareFavorites.

public void shareFavorites(final FavoriteGroup group) {
    final AsyncTask<Void, Void, Void> exportTask = new AsyncTask<Void, Void, Void>() {

        File src = null;

        File dst = null;

        @Override
        protected Void doInBackground(Void... params) {
            if (group != null) {
                helper.saveFile(group.points, dst);
            }
            return null;
        }

        @Override
        protected void onPreExecute() {
            showProgressBar();
            File dir = new File(getActivity().getCacheDir(), "share");
            if (!dir.exists()) {
                dir.mkdir();
            }
            if (group == null) {
                src = helper.getExternalFile();
            }
            dst = new File(dir, src != null ? src.getName() : FavouritesDbHelper.FILE_TO_SAVE);
        }

        @Override
        protected void onPostExecute(Void res) {
            hideProgressBar();
            if (getActivity() == null) {
                // user quit application
                return;
            }
            try {
                if (src != null && dst != null) {
                    Algorithms.fileCopy(src, dst);
                }
                final Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                List<FavoriteGroup> groups;
                if (group != null) {
                    groups = new ArrayList<>();
                    groups.add(group);
                } else {
                    groups = getMyApplication().getFavorites().getFavoriteGroups();
                }
                sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint(groups).toString()));
                sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
                sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getActivity(), getActivity().getPackageName() + ".fileprovider", dst));
                sendIntent.setType("text/plain");
                startActivity(sendIntent);
            } catch (IOException e) {
                Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        }
    };
    exportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) AsyncTask(android.os.AsyncTask) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File)

Example 8 with FavoriteGroup

use of net.osmand.plus.FavouritesDbHelper.FavoriteGroup in project Osmand by osmandapp.

the class FavoritesTreeFragment method onChildClick.

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
    if (selectionMode) {
        CheckBox ch = (CheckBox) v.findViewById(R.id.toggle_item);
        FavouritePoint model = favouritesAdapter.getChild(groupPosition, childPosition);
        FavoriteGroup group = favouritesAdapter.getGroup(groupPosition);
        ch.setChecked(!ch.isChecked());
        if (ch.isChecked()) {
            Set<FavouritePoint> set = favoritesSelected.get(group.name);
            if (set != null) {
                set.add(model);
            } else {
                set = new LinkedHashSet<>();
                set.add(model);
                favoritesSelected.put(group.name, set);
            }
        } else {
            Set<FavouritePoint> set = favoritesSelected.get(group.name);
            if (set != null) {
                set.remove(model);
            }
        }
        updateSelectionMode(actionMode);
    } else {
        final FavouritePoint point = favouritesAdapter.getChild(groupPosition, childPosition);
        showOnMap(point);
    }
    return true;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) CheckBox(android.widget.CheckBox) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup)

Example 9 with FavoriteGroup

use of net.osmand.plus.FavouritesDbHelper.FavoriteGroup in project Osmand by osmandapp.

the class FavoritesTreeFragment method generateHtmlPrint.

private StringBuilder generateHtmlPrint(List<FavoriteGroup> groups) {
    StringBuilder html = new StringBuilder();
    html.append("<h1>My Favorites</h1>");
    for (FavoriteGroup group : groups) {
        html.append("<h3>" + group.name + "</h3>");
        for (FavouritePoint fp : group.points) {
            String url = "geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "?m=" + fp.getName();
            html.append("<p>" + fp.getName() + " - " + "<a href=\"" + url + "\">geo:" + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "</a><br>");
            if (!Algorithms.isEmpty(fp.getDescription())) {
                html.append(": " + fp.getDescription());
            }
            html.append("</p>");
        }
    }
    return html;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup)

Example 10 with FavoriteGroup

use of net.osmand.plus.FavouritesDbHelper.FavoriteGroup in project Osmand by osmandapp.

the class QuickSearchListItem method getIcon.

public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
    if (searchResult == null || searchResult.objectType == null) {
        return null;
    }
    int iconId = -1;
    switch(searchResult.objectType) {
        case CITY:
            return getIcon(app, R.drawable.ic_action_building_number);
        case VILLAGE:
            return getIcon(app, R.drawable.ic_action_home_dark);
        case POSTCODE:
        case STREET:
            return getIcon(app, R.drawable.ic_action_street_name);
        case HOUSE:
            return getIcon(app, R.drawable.ic_action_building);
        case STREET_INTERSECTION:
            return getIcon(app, R.drawable.ic_action_intersection);
        case POI_TYPE:
            if (searchResult.object instanceof AbstractPoiType) {
                String iconName = getPoiTypeIconName((AbstractPoiType) searchResult.object);
                if (!Algorithms.isEmpty(iconName)) {
                    iconId = RenderingIcons.getBigIconResourceId(iconName);
                }
            } else if (searchResult.object instanceof CustomSearchPoiFilter) {
                Object res = ((CustomSearchPoiFilter) searchResult.object).getIconResource();
                if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
                    iconId = RenderingIcons.getBigIconResourceId(res.toString());
                } else {
                    iconId = R.drawable.mx_user_defined;
                }
            }
            if (iconId > 0) {
                return getIcon(app, iconId);
            } else {
                return getIcon(app, R.drawable.ic_action_search_dark);
            }
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            String id = getAmenityIconName(app, amenity);
            Drawable icon = null;
            if (id != null) {
                iconId = RenderingIcons.getBigIconResourceId(id);
                if (iconId > 0) {
                    icon = getIcon(app, iconId);
                }
            }
            if (icon == null) {
                return getIcon(app, R.drawable.ic_action_search_dark);
            } else {
                return icon;
            }
        case LOCATION:
            return getIcon(app, R.drawable.ic_action_world_globe);
        case FAVORITE:
            FavouritePoint fav = (FavouritePoint) searchResult.object;
            return FavoriteImageDrawable.getOrCreate(app, fav.getColor(), false);
        case FAVORITE_GROUP:
            FavoriteGroup group = (FavoriteGroup) searchResult.object;
            int color = group.color == 0 || group.color == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : group.color;
            return app.getIconsCache().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000);
        case REGION:
            return getIcon(app, R.drawable.ic_world_globe_dark);
        case RECENT_OBJ:
            HistoryEntry entry = (HistoryEntry) searchResult.object;
            if (entry.getName() != null && !Algorithms.isEmpty(entry.getName().getIconName())) {
                String iconName = entry.getName().getIconName();
                if (RenderingIcons.containsBigIcon(iconName)) {
                    iconId = RenderingIcons.getBigIconResourceId(iconName);
                } else {
                    iconId = app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
                }
            }
            if (iconId <= 0) {
                iconId = SearchHistoryFragment.getItemIcon(entry.getName());
            }
            try {
                return getIcon(app, iconId);
            } catch (Exception e) {
                return getIcon(app, SearchHistoryFragment.getItemIcon(entry.getName()));
            }
        case WPT:
            WptPt wpt = (WptPt) searchResult.object;
            return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) WptPt(net.osmand.plus.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) FavoriteGroup(net.osmand.plus.FavouritesDbHelper.FavoriteGroup) Drawable(android.graphics.drawable.Drawable) FavoriteImageDrawable(net.osmand.plus.base.FavoriteImageDrawable) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) FavouritePoint(net.osmand.data.FavouritePoint)

Aggregations

FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)10 FavouritePoint (net.osmand.data.FavouritePoint)6 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 AsyncTask (android.os.AsyncTask)1 AlertDialog (android.support.v7.app.AlertDialog)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 CheckBox (android.widget.CheckBox)1 EditText (android.widget.EditText)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1