From 053f7401b8a875c574691abaa1c413443d741312 Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Thu, 22 Feb 2024 08:10:26 +0100 Subject: [PATCH] Styled category label in infowindow --- .../fragments/GeofavoriteMapFragment.java | 2 +- .../views/GeofavMarkerInfoWindow.java | 12 +++++++++ .../res/drawable/rounded_label_background.xml | 6 +++++ app/src/main/res/layout/infowindow_geofav.xml | 27 +++++++++++++++---- 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/rounded_label_background.xml diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java index e9e08a0..94faeb0 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/fragments/GeofavoriteMapFragment.java @@ -159,7 +159,7 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main // Set icon and color Drawable icon = DrawableCompat.wrap(AppCompatResources.getDrawable(requireContext(), R.drawable.ic_list_pin)); - DrawableCompat.setTint(icon, geofavorite.categoryColor()); + DrawableCompat.setTint(icon, geofavorite.categoryColor() == 0 ? requireContext().getColor(R.color.defaultBrand) : geofavorite.categoryColor()); // Set infowindow (popup opened on marker click) and its listeners GeofavMarkerInfoWindow iw = new GeofavMarkerInfoWindow(map, geofavorite); diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/views/GeofavMarkerInfoWindow.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/views/GeofavMarkerInfoWindow.java index d73b5ec..5d2cc5d 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/views/GeofavMarkerInfoWindow.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/views/GeofavMarkerInfoWindow.java @@ -1,7 +1,12 @@ package it.danieleverducci.nextcloudmaps.views; +import android.content.Context; +import android.graphics.drawable.Drawable; import android.view.View; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.core.graphics.drawable.DrawableCompat; + import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.infowindow.InfoWindow; import org.osmdroid.views.overlay.infowindow.MarkerInfoWindow; @@ -14,7 +19,14 @@ public class GeofavMarkerInfoWindow extends MarkerInfoWindow implements View.OnC public GeofavMarkerInfoWindow(MapView mapView, Geofavorite geofavorite) { super(R.layout.infowindow_geofav, mapView); + Context context = getView().getContext(); + // Set category color + View category = getView().findViewById(R.id.bubble_subdescription); + Drawable backgroundDrawable = category.getBackground(); + DrawableCompat.setTint(backgroundDrawable, geofavorite.categoryColor() == 0 ? context.getColor(R.color.defaultBrand) : geofavorite.categoryColor()); + + // Set listeners getView().findViewById(R.id.action_icon_share).setOnClickListener(this); getView().findViewById(R.id.action_icon_nav).setOnClickListener(this); getView().findViewById(R.id.action_icon_delete).setOnClickListener(this); diff --git a/app/src/main/res/drawable/rounded_label_background.xml b/app/src/main/res/drawable/rounded_label_background.xml new file mode 100644 index 0000000..922e392 --- /dev/null +++ b/app/src/main/res/drawable/rounded_label_background.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/app/src/main/res/layout/infowindow_geofav.xml b/app/src/main/res/layout/infowindow_geofav.xml index 721b89c..de0302c 100644 --- a/app/src/main/res/layout/infowindow_geofav.xml +++ b/app/src/main/res/layout/infowindow_geofav.xml @@ -13,6 +13,7 @@ android:padding="7dp" android:orientation="vertical"> + + + + android:layout_width="wrap_content" + android:layout_height="30dp" + android:layout_marginStart="10dp" + android:layout_marginEnd="10dp" + android:layout_marginBottom="10dp" + android:gravity="center_vertical" + android:lines="1" + android:ellipsize="end" + android:text="Lorem ipsum" + app:drawableLeftCompat="@drawable/ic_category_asc" + android:drawablePadding="8sp" + android:drawableTint="@color/white" + android:textColor="@color/white" + android:textStyle="bold" + android:background="@drawable/rounded_label_background"/>