Skip to content

Commit

Permalink
Fix "Car bearing icon don't use profile color #18843"
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-kutz committed Jan 16, 2024
1 parent 287de4b commit 0f1c55e
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 27 deletions.
Binary file removed OsmAnd/res/drawable-hdpi/map_navigation_car_center.png
Binary file not shown.
Binary file removed OsmAnd/res/drawable-mdpi/map_navigation_car_center.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 7 additions & 5 deletions OsmAnd/res/drawable/map_navigation_car.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
android:src="@drawable/map_navigation_car_bottom"
android:gravity="bottom|center" />
</item>
<item android:id="@+id/center">
<bitmap
android:src="@drawable/map_navigation_car_center"
android:gravity="bottom|center" />
</item>

<item
android:id="@+id/center"
android:drawable="@drawable/map_navigation_car_center"
android:gravity="bottom|center" />

<item android:id="@+id/top">
<bitmap
android:src="@drawable/map_navigation_car_top"
android:gravity="bottom|center" />
</item>

</layer-list>
4 changes: 4 additions & 0 deletions OsmAnd/res/drawable/map_navigation_car_center.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="52dp" android:height="52dp" android:viewportWidth="52" android:viewportHeight="52">
<path android:pathData="M32,17L30.0478,17.2789C26.7069,17.7562 23.3092,17.6619 20,17L18.6011,16.7202C16.2202,16.244 13.7726,16.2046 11.3775,16.6038L9.6857,16.8857C9.2311,16.9615 8.7904,17.1048 8.3783,17.3109C7.4836,17.7582 6.7582,18.4836 6.3109,19.3783L6.0506,19.8988C6.0169,19.9662 5.988,20.0359 5.9642,20.1074L5.9013,20.2961C5.3043,22.087 5,23.9624 5,25.8502L5,26.1498C5,28.0376 5.3043,29.913 5.9013,31.704L5.9642,31.8927C5.988,31.9641 6.0169,32.0338 6.0506,32.1012L6.3109,32.6217C6.7582,33.5164 7.4836,34.2418 8.3783,34.6891C8.7904,34.8952 9.2311,35.0385 9.6857,35.1143L11.3775,35.3963C13.7726,35.7954 16.2202,35.756 18.6011,35.2798L20,35C23.3092,34.3382 26.7069,34.2439 30.0478,34.7211L32,35L32.362,35.0905C34.7506,35.6876 37.2494,35.6876 39.638,35.0905L40,35C41.8536,34.6911 43.3972,33.4078 44.0394,31.6417L44.5364,30.275C44.8431,29.4315 45,28.5409 45,27.6434V24.3566C45,23.4591 44.8431,22.5685 44.5364,21.7251L44.0394,20.3583C43.3972,18.5922 41.8536,17.3089 40,17L39.638,16.9095C37.2494,16.3124 34.7506,16.3124 32.362,16.9095L32,17Z" android:fillColor="#732EEB"/>
</vector>
1 change: 1 addition & 0 deletions OsmAnd/src/net/osmand/plus/profiles/NavigationIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.osmand.plus.R;

public enum NavigationIcon {

DEFAULT(R.drawable.map_navigation_default),
NAUTICAL(R.drawable.map_navigation_nautical),
CAR(R.drawable.map_navigation_car);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.graphics.Matrix;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
Expand Down Expand Up @@ -545,24 +546,27 @@ private void updateLocationIconSelector(LocationIcon locationIcon) {
}

private View createNavigationIconView(NavigationIcon navigationIcon, ViewGroup rootView) {
FrameLayout navigationIconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_select_icon_button, rootView, false);
LayerDrawable navigationIconDrawable = (LayerDrawable) AppCompatResources.getDrawable(app, navigationIcon.getIconId());
if (navigationIconDrawable != null) {
DrawableCompat.setTint(DrawableCompat.wrap(navigationIconDrawable.getDrawable(1)),
changedProfile.getActualColor());
LayoutInflater inflater = UiUtilities.getInflater(getContext(), isNightMode());
FrameLayout navigationIconView = (FrameLayout) inflater.inflate(R.layout.preference_select_icon_button, rootView, false);
LayerDrawable navigationDrawable = (LayerDrawable) AppCompatResources.getDrawable(app, navigationIcon.getIconId());
if (navigationDrawable != null) {
Drawable topDrawable = DrawableCompat.wrap(navigationDrawable.getDrawable(1));
DrawableCompat.setTint(topDrawable, changedProfile.getActualColor());
}
ImageView imageView = navigationIconView.findViewById(R.id.icon);
imageView.setImageDrawable(navigationIconDrawable);
imageView.setImageDrawable(navigationDrawable);
Matrix matrix = new Matrix();
imageView.setScaleType(ImageView.ScaleType.MATRIX);
matrix.postRotate((float) -90, imageView.getDrawable().getIntrinsicWidth() / 2,
imageView.getDrawable().getIntrinsicHeight() / 2);
float width = imageView.getDrawable().getIntrinsicWidth() / 2f;
float height = imageView.getDrawable().getIntrinsicHeight() / 2f;
matrix.postRotate((float) -90, width, height);
imageView.setImageMatrix(matrix);

ImageView coloredRect = navigationIconView.findViewById(R.id.backgroundRect);
AndroidUtils.setBackground(coloredRect,
UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, R.drawable.bg_select_icon_button),
ColorUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f)));
Drawable coloredDrawable = UiUtilities.tintDrawable(
AppCompatResources.getDrawable(app, R.drawable.bg_select_icon_button),
ColorUtilities.getColor(app, R.color.icon_color_default_light, 0.1f));
AndroidUtils.setBackground(coloredRect, coloredDrawable);
coloredRect.setOnClickListener(v -> {
if (navigationIcon != changedProfile.navigationIcon) {
setVerticalScrollBarEnabled(false);
Expand Down
13 changes: 8 additions & 5 deletions OsmAnd/src/net/osmand/plus/utils/ColorUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,18 @@ public static int getAppModeColor(@NonNull OsmandApplication app, boolean nightM
@ColorInt
public static int getAppModeColor(@NonNull ApplicationMode appMode, boolean nightMode, float alpha) {
int color = appMode.getProfileColor(nightMode);
if (alpha < 1.0f) {
color = ColorUtilities.getColorWithAlpha(color, alpha);
}
return color;
return alpha < 1.0f ? getColorWithAlpha(color, alpha) : color;
}

@ColorInt
public static int getColor(@NonNull Context ctx, @ColorRes int colorId) {
return ContextCompat.getColor(ctx, colorId);
return getColor(ctx, colorId, 1.0f);
}

@ColorInt
public static int getColor(@NonNull Context ctx, @ColorRes int colorId, float alpha) {
int color = ContextCompat.getColor(ctx, colorId);
return alpha < 1.0f ? getColorWithAlpha(color, alpha) : color;
}

@ColorInt
Expand Down
4 changes: 1 addition & 3 deletions OsmAnd/src/net/osmand/plus/utils/UiUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
Expand Down Expand Up @@ -205,13 +204,12 @@ public static Drawable tintDrawable(Drawable drawable, @ColorInt int color) {
coloredDrawable = coloredDrawable.getConstantState().newDrawable();
}
coloredDrawable.mutate();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && coloredDrawable instanceof RippleDrawable) {
if (coloredDrawable instanceof RippleDrawable) {
((RippleDrawable) coloredDrawable).setColor(ColorStateList.valueOf(color));
} else {
DrawableCompat.setTint(coloredDrawable, color);
}
}

return coloredDrawable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@

import java.util.List;

public class PointLocationLayer extends OsmandMapLayer implements OsmAndLocationListener,
OsmAndCompassListener, IContextMenuProvider {
public class PointLocationLayer extends OsmandMapLayer
implements OsmAndLocationListener, OsmAndCompassListener, IContextMenuProvider {

protected static final float BEARING_SPEED_THRESHOLD = 0.1f;
protected static final int MIN_ZOOM = 3;
Expand Down

0 comments on commit 0f1c55e

Please sign in to comment.