Search in sources :

Example 1 with VectorDrawableCompat

use of androidx.vectordrawable.graphics.drawable.VectorDrawableCompat in project apps-android-commons by commons-app.

the class NearbyParentFragment method updateMarker.

/**
 * Sets marker icon according to marker status. Sets title and distance.
 * @param isBookmarked true if place is bookmarked
 * @param place
 * @param curLatLng current location
 */
public void updateMarker(final boolean isBookmarked, final Place place, @Nullable final fr.free.nrw.commons.location.LatLng curLatLng) {
    VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(getContext().getResources(), getIconFor(place, isBookmarked), getContext().getTheme());
    if (curLatLng != null) {
        for (NearbyBaseMarker nearbyMarker : allMarkers) {
            if (nearbyMarker.getMarker().getTitle() != null && nearbyMarker.getMarker().getTitle().equals(place.getName())) {
                final Bitmap icon = UiUtils.getBitmap(vectorDrawable);
                final String distance = formatDistanceBetween(curLatLng, place.location);
                place.setDistance(distance);
                final NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
                nearbyBaseMarker.title(place.name);
                nearbyBaseMarker.position(new com.mapbox.mapboxsdk.geometry.LatLng(place.location.getLatitude(), place.location.getLongitude()));
                nearbyBaseMarker.place(place);
                nearbyBaseMarker.icon(IconFactory.getInstance(getContext()).fromBitmap(icon));
                nearbyMarker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
                filteredMarkers.add(nearbyBaseMarker);
            }
        }
    } else {
        for (Marker marker : mapBox.getMarkers()) {
            if (marker.getTitle() != null && marker.getTitle().equals(place.getName())) {
                final Bitmap icon = UiUtils.getBitmap(vectorDrawable);
                marker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
            }
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Marker(com.mapbox.mapboxsdk.annotations.Marker) NearbyMarker(fr.free.nrw.commons.nearby.NearbyMarker) NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat)

Example 2 with VectorDrawableCompat

use of androidx.vectordrawable.graphics.drawable.VectorDrawableCompat in project apps-android-commons by commons-app.

the class NearbyParentFragment method hideAllMarkers.

/**
 * Removes all markers except current location marker, an icon has been used
 * but it is transparent more than grey(as the name of the icon might suggest)
 * since grey icon may lead the users to believe that it is disabled or prohibited contribution
 */
private void hideAllMarkers() {
    final VectorDrawableCompat vectorDrawable;
    vectorDrawable = VectorDrawableCompat.create(getContext().getResources(), R.drawable.ic_custom_greyed_out_marker, getContext().getTheme());
    final Bitmap icon = UiUtils.getBitmap(vectorDrawable);
    for (final Marker marker : mapBox.getMarkers()) {
        if (!marker.equals(currentLocationMarker)) {
            marker.setIcon(IconFactory.getInstance(getContext()).fromBitmap(icon));
        }
    }
    addCurrentLocationMarker(NearbyController.currentLocation);
}
Also used : Bitmap(android.graphics.Bitmap) Marker(com.mapbox.mapboxsdk.annotations.Marker) NearbyMarker(fr.free.nrw.commons.nearby.NearbyMarker) NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat)

Example 3 with VectorDrawableCompat

use of androidx.vectordrawable.graphics.drawable.VectorDrawableCompat in project SeriesGuide by UweTrottmann.

the class FeatureStatusView method setFeatureEnabled.

public void setFeatureEnabled(boolean available) {
    if (featureSupported) {
        VectorDrawableCompat drawable = VectorDrawableCompat.create(getContext().getResources(), available ? R.drawable.ic_check_circle_green_24dp : R.drawable.ic_cancel_red_24dp, getContext().getTheme());
        imageViewStatus.setImageDrawable(drawable);
        imageViewStatus.setContentDescription(getContext().getString(available ? R.string.feature_supported : R.string.feature_not_supported));
    }
}
Also used : VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat)

Example 4 with VectorDrawableCompat

use of androidx.vectordrawable.graphics.drawable.VectorDrawableCompat in project apps-android-commons by commons-app.

the class NearbyController method loadAttractionsFromLocationToBaseMarkerOptions.

/**
 * Loads attractions from location for map view, we need to return BaseMarkerOption data type.
 *
 * @param curLatLng users current location
 * @param placeList list of nearby places in Place data type
 * @return BaseMarkerOptions list that holds nearby places
 */
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(LatLng curLatLng, List<Place> placeList, Context context, List<Place> bookmarkplacelist) {
    List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
    if (placeList == null) {
        return baseMarkerOptions;
    }
    placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
    VectorDrawableCompat vectorDrawable = null;
    VectorDrawableCompat vectorDrawableGreen = null;
    VectorDrawableCompat vectorDrawableGrey = null;
    VectorDrawableCompat vectorDrawableMonuments = null;
    vectorDrawable = null;
    try {
        vectorDrawable = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_custom_map_marker, context.getTheme());
        vectorDrawableGreen = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_custom_map_marker_green, context.getTheme());
        vectorDrawableGrey = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_custom_map_marker_grey, context.getTheme());
        vectorDrawableMonuments = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_custom_map_marker_monuments, context.getTheme());
    } catch (Resources.NotFoundException e) {
    // ignore when running tests.
    }
    if (vectorDrawable != null) {
        Bitmap icon = UiUtils.getBitmap(vectorDrawable);
        Bitmap iconGreen = UiUtils.getBitmap(vectorDrawableGreen);
        Bitmap iconGrey = UiUtils.getBitmap(vectorDrawableGrey);
        Bitmap iconMonuments = UiUtils.getBitmap(vectorDrawableMonuments);
        for (Place place : placeList) {
            NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
            String distance = formatDistanceBetween(curLatLng, place.location);
            place.setDistance(distance);
            nearbyBaseMarker.title(place.name);
            nearbyBaseMarker.position(new com.mapbox.mapboxsdk.geometry.LatLng(place.location.getLatitude(), place.location.getLongitude()));
            nearbyBaseMarker.place(place);
            if (place.isMonument()) {
                nearbyBaseMarker.icon(IconFactory.getInstance(context).fromBitmap(iconMonuments));
            } else if (!place.pic.trim().isEmpty()) {
                if (iconGreen != null) {
                    nearbyBaseMarker.icon(IconFactory.getInstance(context).fromBitmap(iconGreen));
                }
            } else if (!place.exists) {
                // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed
                if (iconGrey != null) {
                    nearbyBaseMarker.icon(IconFactory.getInstance(context).fromBitmap(iconGrey));
                }
            } else {
                nearbyBaseMarker.icon(IconFactory.getInstance(context).fromBitmap(icon));
            }
            baseMarkerOptions.add(nearbyBaseMarker);
        }
    }
    return baseMarkerOptions;
}
Also used : Bitmap(android.graphics.Bitmap) ArrayList(java.util.ArrayList) Resources(android.content.res.Resources) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat)

Aggregations

VectorDrawableCompat (androidx.vectordrawable.graphics.drawable.VectorDrawableCompat)4 Bitmap (android.graphics.Bitmap)3 Marker (com.mapbox.mapboxsdk.annotations.Marker)2 NearbyBaseMarker (fr.free.nrw.commons.nearby.NearbyBaseMarker)2 NearbyMarker (fr.free.nrw.commons.nearby.NearbyMarker)2 Resources (android.content.res.Resources)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 ArrayList (java.util.ArrayList)1