Merge pull request #8917 from osmandapp/ColorsRefactoring

Refactor colors
This commit is contained in:
vshcherb 2020-05-08 16:01:42 +02:00 committed by GitHub
commit fc130d4001
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 17 deletions

View file

@ -525,15 +525,17 @@ public class UiUtilities {
int activeDisableColor = getColorWithAlpha(activeColor, 0.25f); int activeDisableColor = getColorWithAlpha(activeColor, 0.25f);
ColorStateList activeCsl = new ColorStateList(states, ColorStateList activeCsl = new ColorStateList(states,
new int[] {activeColor, activeDisableColor}); 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, ColorStateList inactiveCsl = new ColorStateList(states,
new int[] {inactiveColor, inactiveColor}); new int[] {inactiveColor, inactiveColor});
slider.setTrackColorActive(activeCsl); slider.setTrackColorActive(activeCsl);
slider.setTrackColorInactive(inactiveCsl); slider.setTrackColorInactive(inactiveCsl);
slider.setHaloColor(activeCsl); slider.setHaloColor(activeCsl);
slider.setThumbColor(activeCsl); slider.setThumbColor(activeCsl);
int ticksColor = showTicks ? ContextCompat.getColor(ctx, int colorBlack = ContextCompat.getColor(ctx, R.color.color_black);
nightMode ? R.color.color_black : R.color.color_white) : int ticksColor = showTicks ?
(nightMode ? colorBlack : getColorWithAlpha(colorBlack, 0.5f)) :
Color.TRANSPARENT; Color.TRANSPARENT;
slider.setTickColor(new ColorStateList(states, new int[] {ticksColor, ticksColor})); slider.setTickColor(new ColorStateList(states, new int[] {ticksColor, ticksColor}));

View file

@ -706,8 +706,9 @@ public class MapActivityActions implements DialogProvider {
public ContextMenuAdapter createMainOptionsMenu() { public ContextMenuAdapter createMainOptionsMenu() {
final OsmandMapTileView mapView = mapActivity.getMapView(); final OsmandMapTileView mapView = mapActivity.getMapView();
final OsmandApplication app = mapActivity.getMyApplication(); final OsmandApplication app = mapActivity.getMyApplication();
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app);
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
ContextMenuAdapter optionsMenuHelper = new ContextMenuAdapter(app);
optionsMenuHelper.setNightMode(nightMode);
if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) { if (drawerMode == DRAWER_MODE_SWITCH_PROFILE) {
return createSwitchProfileOptionsMenu(app, optionsMenuHelper, nightMode); return createSwitchProfileOptionsMenu(app, optionsMenuHelper, nightMode);

View file

@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.audionotes.NotesFragment; import net.osmand.plus.audionotes.NotesFragment;
@ -66,6 +67,8 @@ public class NotesAdapter extends ArrayAdapter<Object> {
@NonNull @NonNull
@Override @Override
public View getView(final int position, View row, @NonNull ViewGroup parent) { public View getView(final int position, View row, @NonNull ViewGroup parent) {
boolean nightMode = !app.getSettings().isLightContent();
Context themedCtx = UiUtilities.getThemedContext(getContext(), nightMode);
if (portrait) { if (portrait) {
final int type = getItemViewType(position); final int type = getItemViewType(position);
boolean header = type == TYPE_DATE_HEADER boolean header = type == TYPE_DATE_HEADER
@ -74,7 +77,7 @@ public class NotesAdapter extends ArrayAdapter<Object> {
|| type == TYPE_VIDEO_HEADER; || type == TYPE_VIDEO_HEADER;
if (row == null) { if (row == null) {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
if (header) { if (header) {
row = inflater.inflate(R.layout.list_item_header, parent, false); row = inflater.inflate(R.layout.list_item_header, parent, false);
HeaderViewHolder hHolder = new HeaderViewHolder(row); HeaderViewHolder hHolder = new HeaderViewHolder(row);
@ -97,16 +100,16 @@ public class NotesAdapter extends ArrayAdapter<Object> {
return row; return row;
} else { } else {
LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
boolean lastCard = getCardsCount() == position + 1; boolean lastCard = getCardsCount() == position + 1;
int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding); int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10; int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10;
FrameLayout fl = new FrameLayout(getContext()); FrameLayout fl = new FrameLayout(themedCtx);
LinearLayout ll = new LinearLayout(getContext()); LinearLayout ll = new LinearLayout(themedCtx);
fl.addView(ll); fl.addView(ll);
ll.setOrientation(LinearLayout.VERTICAL); 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); ((FrameLayout.LayoutParams) ll.getLayoutParams()).setMargins(sideMargin, margin, sideMargin, lastCard ? margin : 0);
if (position == 0 && hasShareLocationItem()) { if (position == 0 && hasShareLocationItem()) {

View file

@ -1,5 +1,6 @@
package net.osmand.plus.osmedit; package net.osmand.plus.osmedit;
import android.content.Context;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.SpannableString; import android.text.SpannableString;
@ -22,6 +23,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import java.util.List; import java.util.List;
@ -71,14 +73,16 @@ public class OsmEditsAdapter extends ArrayAdapter<Object> {
@NonNull @NonNull
@Override @Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) { public View getView(int position, View convertView, @NonNull ViewGroup parent) {
boolean nightMode = !app.getSettings().isLightContent();
Context themedCtx = UiUtilities.getThemedContext(getContext(), nightMode);
if (portrait) { if (portrait) {
if (convertView == null) { if (convertView == null) {
if (position == 0) { 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); HeaderViewHolder holder = new HeaderViewHolder(convertView);
convertView.setTag(holder); convertView.setTag(holder);
} else { } 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); OsmEditViewHolder holder = new OsmEditViewHolder(convertView);
convertView.setTag(holder); convertView.setTag(holder);
} }
@ -98,21 +102,21 @@ public class OsmEditsAdapter extends ArrayAdapter<Object> {
int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding); int margin = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10; int sideMargin = app.getResources().getDisplayMetrics().widthPixels / 10;
FrameLayout fl = new FrameLayout(getContext()); FrameLayout fl = new FrameLayout(themedCtx);
LinearLayout ll = new LinearLayout(getContext()); LinearLayout ll = new LinearLayout(themedCtx);
ll.setOrientation(LinearLayout.VERTICAL); ll.setOrientation(LinearLayout.VERTICAL);
ll.setBackgroundResource(app.getSettings().isLightContent() ? R.drawable.bg_card_light : R.drawable.bg_card_dark); ll.setBackgroundResource(app.getSettings().isLightContent() ? R.drawable.bg_card_light : R.drawable.bg_card_dark);
fl.addView(ll); fl.addView(ll);
((FrameLayout.LayoutParams) ll.getLayoutParams()).setMargins(sideMargin, margin, sideMargin, margin); ((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); bindHeaderViewHolder(headerViewHolder);
ll.addView(headerViewHolder.mainView); ll.addView(headerViewHolder.mainView);
for (int i = 0; i < items.size(); i++) { for (int i = 0; i < items.size(); i++) {
Object item = getItem(i); Object item = getItem(i);
if (item instanceof OsmPoint) { 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); bindOsmEditViewHolder(viewHolder, (OsmPoint) item, i);
ll.addView(viewHolder.mainView); ll.addView(viewHolder.mainView);
} }