From 861db6ba94764ac308854ea64a65ba7a36e3982e Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Fri, 8 May 2020 11:07:42 +0300 Subject: [PATCH] Refactor colors --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 8 +++++--- .../plus/activities/MapActivityActions.java | 7 ++++--- .../plus/audionotes/adapters/NotesAdapter.java | 13 ++++++++----- .../net/osmand/plus/osmedit/OsmEditsAdapter.java | 16 ++++++++++------ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 30da1c855e..db32602343 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -525,15 +525,17 @@ public class UiUtilities { int activeDisableColor = getColorWithAlpha(activeColor, 0.25f); ColorStateList activeCsl = new ColorStateList(states, new int[] {activeColor, activeDisableColor}); - int inactiveColor = AndroidUtils.getColorFromAttr(ctx, R.attr.default_icon_color); + int inactiveColor = ContextCompat.getColor(ctx, + nightMode ? R.color.icon_color_default_dark : R.color.icon_color_secondary_light); ColorStateList inactiveCsl = new ColorStateList(states, new int[] {inactiveColor, inactiveColor}); slider.setTrackColorActive(activeCsl); slider.setTrackColorInactive(inactiveCsl); slider.setHaloColor(activeCsl); slider.setThumbColor(activeCsl); - int ticksColor = showTicks ? ContextCompat.getColor(ctx, - nightMode ? R.color.color_black : R.color.color_white) : + int colorBlack = ContextCompat.getColor(ctx, R.color.color_black); + int ticksColor = showTicks ? + (nightMode ? colorBlack : getColorWithAlpha(colorBlack, 0.5f)) : Color.TRANSPARENT; slider.setTickColor(new ColorStateList(states, new int[] {ticksColor, ticksColor})); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 7f950606dd..9da47a4bce 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -706,9 +706,10 @@ public class MapActivityActions implements DialogProvider { public ContextMenuAdapter createMainOptionsMenu() { final OsmandMapTileView mapView = mapActivity.getMapView(); final OsmandApplication app = mapActivity.getMyApplication(); - ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - + ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app); + optionsMenuHelper.setNightMode(nightMode); + if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) { return createSwitchProfileOptionsMenu(app, optionsMenuHelper, nightMode); } @@ -764,7 +765,7 @@ public class MapActivityActions implements DialogProvider { } }) .createItem()); - + return optionsMenuHelper; } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java b/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java index 278fdbd737..7fe810ee63 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java @@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.audionotes.NotesFragment; @@ -66,6 +67,8 @@ public class NotesAdapter extends ArrayAdapter { @NonNull @Override public View getView(final int position, View row, @NonNull ViewGroup parent) { + boolean nightMode = !app.getSettings().isLightContent(); + Context themedCtx = UiUtilities.getThemedContext(getContext(), nightMode); if (portrait) { final int type = getItemViewType(position); boolean header = type == TYPE_DATE_HEADER @@ -74,7 +77,7 @@ public class NotesAdapter extends ArrayAdapter { || type == TYPE_VIDEO_HEADER; if (row == null) { - LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); if (header) { row = inflater.inflate(R.layout.list_item_header, parent, false); HeaderViewHolder hHolder = new HeaderViewHolder(row); @@ -97,16 +100,16 @@ public class NotesAdapter extends ArrayAdapter { return row; } else { - LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); boolean lastCard = getCardsCount() == position + 1; int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding); int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10; - FrameLayout fl = new FrameLayout(getContext()); - LinearLayout ll = new LinearLayout(getContext()); + FrameLayout fl = new FrameLayout(themedCtx); + LinearLayout ll = new LinearLayout(themedCtx); fl.addView(ll); ll.setOrientation(LinearLayout.VERTICAL); - ll.setBackgroundResource(app.getSettings().isLightContent() ? R.drawable.bg_card_light : R.drawable.bg_card_dark); + ll.setBackgroundResource(nightMode ? R.drawable.bg_card_dark : R.drawable.bg_card_light); ((FrameLayout.LayoutParams) ll.getLayoutParams()).setMargins(sideMargin, margin, sideMargin, lastCard ? margin : 0); if (position == 0 && hasShareLocationItem()) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java index 9668654adc..9855203b0c 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java @@ -1,5 +1,6 @@ package net.osmand.plus.osmedit; +import android.content.Context; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.text.SpannableString; @@ -22,6 +23,7 @@ import androidx.core.content.ContextCompat; import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.render.RenderingIcons; import java.util.List; @@ -71,14 +73,16 @@ public class OsmEditsAdapter extends ArrayAdapter { @NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { + boolean nightMode = !app.getSettings().isLightContent(); + Context themedCtx = UiUtilities.getThemedContext(getContext(), nightMode); if (portrait) { if (convertView == null) { if (position == 0) { - convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_header, parent, false); + convertView = LayoutInflater.from(themedCtx).inflate(R.layout.list_item_header, parent, false); HeaderViewHolder holder = new HeaderViewHolder(convertView); convertView.setTag(holder); } else { - convertView = LayoutInflater.from(getContext()).inflate(R.layout.note_list_item, parent, false); + convertView = LayoutInflater.from(themedCtx).inflate(R.layout.note_list_item, parent, false); OsmEditViewHolder holder = new OsmEditViewHolder(convertView); convertView.setTag(holder); } @@ -98,21 +102,21 @@ public class OsmEditsAdapter extends ArrayAdapter { int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding); int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10; - FrameLayout fl = new FrameLayout(getContext()); - LinearLayout ll = new LinearLayout(getContext()); + FrameLayout fl = new FrameLayout(themedCtx); + LinearLayout ll = new LinearLayout(themedCtx); ll.setOrientation(LinearLayout.VERTICAL); ll.setBackgroundResource(app.getSettings().isLightContent() ? R.drawable.bg_card_light : R.drawable.bg_card_dark); fl.addView(ll); ((FrameLayout.LayoutParams) ll.getLayoutParams()).setMargins(sideMargin, margin, sideMargin, margin); - HeaderViewHolder headerViewHolder = new HeaderViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.list_item_header, parent, false)); + HeaderViewHolder headerViewHolder = new HeaderViewHolder(LayoutInflater.from(themedCtx).inflate(R.layout.list_item_header, parent, false)); bindHeaderViewHolder(headerViewHolder); ll.addView(headerViewHolder.mainView); for (int i = 0; i < items.size(); i++) { Object item = getItem(i); if (item instanceof OsmPoint) { - OsmEditViewHolder viewHolder = new OsmEditViewHolder(LayoutInflater.from(getContext()).inflate(R.layout.note_list_item, parent, false)); + OsmEditViewHolder viewHolder = new OsmEditViewHolder(LayoutInflater.from(themedCtx).inflate(R.layout.note_list_item, parent, false)); bindOsmEditViewHolder(viewHolder, (OsmPoint) item, i); ll.addView(viewHolder.mainView); }