From e30e2e1034e8c93654fa5af17e73fdc4d8afb98a Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Wed, 10 Mar 2021 16:17:39 +0200 Subject: [PATCH 1/3] New plugin added dialog missing plugin icon https://github.com/osmandapp/OsmAnd-Issues/issues/489 --- .../net/osmand/plus/activities/PluginsFragment.java | 6 +++++- .../dialogs/PluginInstalledBottomSheetDialog.java | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java b/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java index b1f16ee4e7..d3429f02a5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.res.TypedArray; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; @@ -225,7 +226,10 @@ public class PluginsFragment extends BaseOsmAndFragment implements PluginStateLi pluginDescription.setText(plugin.getDescription()); int color = AndroidUtils.getColorFromAttr(context, R.attr.list_background_color); - pluginLogo.setImageDrawable(UiUtilities.tintDrawable(plugin.getLogoResource(), color)); + + Drawable pluginIcon = plugin.getLogoResource(); + pluginIcon.clearColorFilter(); + pluginLogo.setImageDrawable(UiUtilities.tintDrawable(pluginIcon, color)); pluginLogo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java index db9422859a..a31c74f680 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java @@ -2,7 +2,9 @@ package net.osmand.plus.dialogs; import android.app.Activity; import android.content.Context; +import android.graphics.PorterDuff; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.SpannableString; import android.view.View; @@ -11,12 +13,11 @@ import android.widget.LinearLayout; import android.widget.ProgressBar; import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; -import net.osmand.plus.profiles.ProfileDataUtils; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -34,6 +35,8 @@ import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.profiles.ProfileDataUtils; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.widgets.style.CustomTypefaceSpan; import org.apache.commons.logging.Log; @@ -87,11 +90,14 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm Typeface typeface = FontCache.getRobotoMedium(getContext()); SpannableString pluginTitleSpan = new SpannableString(plugin.getName()); pluginTitleSpan.setSpan(new CustomTypefaceSpan(typeface), 0, pluginTitleSpan.length(), 0); + Drawable pluginIcon = plugin.getLogoResource(); + pluginIcon.setColorFilter(ContextCompat.getColor( + context, nightMode ? R.color.icon_color_default_light : R.color.icon_color_default_dark), PorterDuff.Mode.MULTIPLY); BaseBottomSheetItem pluginTitle = new SimpleBottomSheetItem.Builder() .setTitle(pluginTitleSpan) .setTitleColorId(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light) - .setIcon(plugin.getLogoResource()) + .setIcon(pluginIcon) .setLayoutId(R.layout.bottom_sheet_item_simple_56dp) .create(); items.add(pluginTitle); From edb4dc19e016d7da3bbfa942037b3bc2cc56be09 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Wed, 10 Mar 2021 17:49:32 +0200 Subject: [PATCH 2/3] Review --- .../src/net/osmand/plus/activities/PluginsFragment.java | 5 +---- .../plus/dialogs/PluginInstalledBottomSheetDialog.java | 8 +++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java b/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java index d3429f02a5..ec863540cf 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java @@ -6,7 +6,6 @@ import android.content.DialogInterface; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.text.method.LinkMovementMethod; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -23,7 +22,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; -import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -228,7 +226,6 @@ public class PluginsFragment extends BaseOsmAndFragment implements PluginStateLi int color = AndroidUtils.getColorFromAttr(context, R.attr.list_background_color); Drawable pluginIcon = plugin.getLogoResource(); - pluginIcon.clearColorFilter(); pluginLogo.setImageDrawable(UiUtilities.tintDrawable(pluginIcon, color)); pluginLogo.setOnClickListener(new View.OnClickListener() { @Override @@ -253,7 +250,7 @@ public class PluginsFragment extends BaseOsmAndFragment implements PluginStateLi if (active) { pluginLogo.setBackgroundResource(nightMode ? R.drawable.bg_plugin_logo_enabled_dark : R.drawable.bg_plugin_logo_enabled_light); } else { - TypedArray attributes = context.getTheme().obtainStyledAttributes(new int[] {R.attr.bg_plugin_logo_disabled}); + TypedArray attributes = context.getTheme().obtainStyledAttributes(new int[]{R.attr.bg_plugin_logo_disabled}); pluginLogo.setBackgroundDrawable(attributes.getDrawable(0)); attributes.recycle(); } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java index a31c74f680..4cd675805b 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/PluginInstalledBottomSheetDialog.java @@ -2,7 +2,6 @@ package net.osmand.plus.dialogs; import android.app.Activity; import android.content.Context; -import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -91,8 +90,11 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm SpannableString pluginTitleSpan = new SpannableString(plugin.getName()); pluginTitleSpan.setSpan(new CustomTypefaceSpan(typeface), 0, pluginTitleSpan.length(), 0); Drawable pluginIcon = plugin.getLogoResource(); - pluginIcon.setColorFilter(ContextCompat.getColor( - context, nightMode ? R.color.icon_color_default_light : R.color.icon_color_default_dark), PorterDuff.Mode.MULTIPLY); + if (pluginIcon.getConstantState() != null) { + pluginIcon = pluginIcon.getConstantState().newDrawable().mutate(); + } + pluginIcon = UiUtilities.tintDrawable(pluginIcon, ContextCompat.getColor( + context, nightMode ? R.color.icon_color_default_light : R.color.icon_color_default_dark)); BaseBottomSheetItem pluginTitle = new SimpleBottomSheetItem.Builder() .setTitle(pluginTitleSpan) From 6de096260801250faf91db81ae3cdaff48f0ffd9 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Wed, 10 Mar 2021 18:09:10 +0200 Subject: [PATCH 3/3] Create copy icon --- OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java b/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java index ec863540cf..04666e9607 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginsFragment.java @@ -224,8 +224,10 @@ public class PluginsFragment extends BaseOsmAndFragment implements PluginStateLi pluginDescription.setText(plugin.getDescription()); int color = AndroidUtils.getColorFromAttr(context, R.attr.list_background_color); - Drawable pluginIcon = plugin.getLogoResource(); + if (pluginIcon.getConstantState() != null) { + pluginIcon = pluginIcon.getConstantState().newDrawable().mutate(); + } pluginLogo.setImageDrawable(UiUtilities.tintDrawable(pluginIcon, color)); pluginLogo.setOnClickListener(new View.OnClickListener() { @Override