Merge pull request #5706 from osmandapp/Fix_5539

Fix_5539
This commit is contained in:
Alexander Sytnyk 2018-07-20 10:58:40 +03:00 committed by GitHub
commit 00edc64b24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View file

@ -170,6 +170,7 @@
<color name="color_transparent">#0000</color>
<color name="color_black_transparent">#90000000</color>
<color name="widgettext_night">#ffC8C8C8</color>
<!-- widgettext_shadow_night is the same as widget background color for non-transparent night skin (from box_night_free_simple.9.png) -->
<color name="widgettext_shadow_night">#dc262626</color>

View file

@ -5,6 +5,7 @@ import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.views.DirectionDrawable;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.hardware.Sensor;
@ -97,6 +98,12 @@ public class UiUtilities {
return light ? R.color.icon_color : R.color.color_white;
}
@ColorInt
public static int getContrastColor(Context context, @ColorInt int color, boolean transparent) {
// Counting the perceptive luminance - human eye favors green color...
double luminance = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
return luminance < 0.5 ? transparent ? ContextCompat.getColor(context, R.color.color_black_transparent) : Color.BLACK : Color.WHITE;
}
public UpdateLocationViewCache getUpdateLocationViewCache(){
UpdateLocationViewCache uvc = new UpdateLocationViewCache();

View file

@ -11,6 +11,7 @@ import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.transport.TransportStopRoute;
import java.util.List;
@ -43,7 +44,9 @@ public class TransportStopRouteAdapter extends ArrayAdapter<TransportStopRoute>
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text);
transportStopRouteTextView.setText(getAdjustedRouteRef(transportStopRoute.route.getRef()));
GradientDrawable gradientDrawableBg = (GradientDrawable) transportStopRouteTextView.getBackground();
gradientDrawableBg.setColor(transportStopRoute.getColor(app, nightMode));
int bgColor = transportStopRoute.getColor(app, nightMode);
gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(app, bgColor, true));
}
convertView.setOnClickListener(new View.OnClickListener() {