Colors refactoring

This commit is contained in:
Nazar-Kutz 2020-04-29 09:56:28 +03:00
parent 764f413196
commit 8b92ec58a3
10 changed files with 42 additions and 21 deletions

View file

@ -41,6 +41,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:textColor="?android:textColorPrimary"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:gravity="center_vertical"
android:maxLines="1" android:maxLines="1"

View file

@ -377,7 +377,8 @@ public class UiUtilities {
TextView tvMessage = (TextView) view.findViewById(com.google.android.material.R.id.snackbar_text); TextView tvMessage = (TextView) view.findViewById(com.google.android.material.R.id.snackbar_text);
TextView tvAction = (TextView) view.findViewById(com.google.android.material.R.id.snackbar_action); TextView tvAction = (TextView) view.findViewById(com.google.android.material.R.id.snackbar_action);
if (messageColor == null) { if (messageColor == null) {
messageColor = nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light; messageColor = nightMode ? R.color.active_buttons_and_links_text_dark
: R.color.active_buttons_and_links_text_light;
} }
tvMessage.setTextColor(ContextCompat.getColor(ctx, messageColor)); tvMessage.setTextColor(ContextCompat.getColor(ctx, messageColor));
if (actionColor == null) { if (actionColor == null) {
@ -388,7 +389,7 @@ public class UiUtilities {
tvMessage.setMaxLines(maxLines); tvMessage.setMaxLines(maxLines);
} }
if (backgroundColor == null) { if (backgroundColor == null) {
backgroundColor = nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light; backgroundColor = nightMode ? R.color.list_background_color_dark : R.color.color_black;
} }
view.setBackgroundColor(ContextCompat.getColor(ctx, backgroundColor)); view.setBackgroundColor(ContextCompat.getColor(ctx, backgroundColor));
} }

View file

@ -1,6 +1,7 @@
package net.osmand.plus.activities.actions; package net.osmand.plus.activities.actions;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Build.VERSION_CODES; import android.os.Build.VERSION_CODES;
@ -22,6 +23,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -110,6 +112,7 @@ public class AppModeDialog {
public static void updateButtonState(final OsmandApplication ctx, final List<ApplicationMode> visible, public static void updateButtonState(final OsmandApplication ctx, final List<ApplicationMode> visible,
final Set<ApplicationMode> selected, final View.OnClickListener onClickListener, final View[] buttons, final Set<ApplicationMode> selected, final View.OnClickListener onClickListener, final View[] buttons,
int i, final boolean singleChoice, final boolean useMapTheme, final boolean nightMode) { int i, final boolean singleChoice, final boolean useMapTheme, final boolean nightMode) {
Context themedCtx = UiUtilities.getThemedContext(ctx, nightMode);
if (buttons[i] != null) { if (buttons[i] != null) {
View tb = buttons[i]; View tb = buttons[i];
final ApplicationMode mode = visible.get(i); final ApplicationMode mode = visible.get(i);
@ -124,7 +127,7 @@ public class AppModeDialog {
} else { } else {
if (useMapTheme) { if (useMapTheme) {
iv.setImageDrawable(ctx.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode))); iv.setImageDrawable(ctx.getUIUtilities().getIcon(mode.getIconRes(), mode.getIconColorInfo().getColor(nightMode)));
iv.setBackgroundResource(AndroidUtils.resolveAttribute(ctx, android.R.attr.selectableItemBackground)); iv.setBackgroundResource(AndroidUtils.resolveAttribute(themedCtx, android.R.attr.selectableItemBackground));
} else { } else {
iv.setImageDrawable(ctx.getUIUtilities().getThemedIcon(mode.getIconRes())); iv.setImageDrawable(ctx.getUIUtilities().getThemedIcon(mode.getIconRes()));
} }

View file

@ -240,10 +240,11 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
private void createSuggestedMapsItems(List<IndexItem> suggestedMaps) { private void createSuggestedMapsItems(List<IndexItem> suggestedMaps) {
final OsmandApplication app = requiredMyApplication(); final OsmandApplication app = requiredMyApplication();
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
items.add(new DividerItem(getContext())); items.add(new DividerItem(themedCtx));
View categoryView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_with_descr_56dp, null); View categoryView = UiUtilities.getInflater(themedCtx, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_56dp, null);
categoryView.findViewById(R.id.icon).setVisibility(View.GONE); categoryView.findViewById(R.id.icon).setVisibility(View.GONE);
BaseBottomSheetItem addedAppProfiles = new BottomSheetItemWithDescription.Builder() BaseBottomSheetItem addedAppProfiles = new BottomSheetItemWithDescription.Builder()
@ -256,8 +257,8 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
final DownloadIndexesThread downloadThread = app.getDownloadThread(); final DownloadIndexesThread downloadThread = app.getDownloadThread();
for (final IndexItem indexItem : suggestedMaps) { for (final IndexItem indexItem : suggestedMaps) {
View view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.list_item_icon_and_download, null); View view = UiUtilities.getInflater(themedCtx, nightMode).inflate(R.layout.list_item_icon_and_download, null);
AndroidUtils.setBackground(view, UiUtilities.getSelectableDrawable(app)); AndroidUtils.setBackground(view, UiUtilities.getSelectableDrawable(themedCtx));
final ImageView secondaryIcon = view.findViewById(R.id.secondary_icon); final ImageView secondaryIcon = view.findViewById(R.id.secondary_icon);
final ProgressBar progressBar = view.findViewById(R.id.ProgressBar); final ProgressBar progressBar = view.findViewById(R.id.ProgressBar);
@ -302,6 +303,7 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
private void updateItems() { private void updateItems() {
Activity activity = getActivity(); Activity activity = getActivity();
Context themedCtx = UiUtilities.getThemedContext(activity, nightMode);
View mainView = getView(); View mainView = getView();
if (activity != null && mainView != null) { if (activity != null && mainView != null) {
LinearLayout itemsContainer = (LinearLayout) mainView.findViewById(useScrollableItemsContainer() LinearLayout itemsContainer = (LinearLayout) mainView.findViewById(useScrollableItemsContainer()
@ -312,7 +314,7 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
items.clear(); items.clear();
createMenuItems(null); createMenuItems(null);
for (BaseBottomSheetItem item : items) { for (BaseBottomSheetItem item : items) {
item.inflate(activity, itemsContainer, nightMode); item.inflate(themedCtx, itemsContainer, nightMode);
} }
setupHeightAndBackground(mainView); setupHeightAndBackground(mainView);
} }

View file

@ -1,6 +1,7 @@
package net.osmand.plus.profiles; package net.osmand.plus.profiles;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
@ -17,6 +18,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -225,10 +227,11 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
private void addButtonItem(int titleId, int iconId, OnClickListener listener) { private void addButtonItem(int titleId, int iconId, OnClickListener listener) {
OsmandApplication app = requiredMyApplication(); OsmandApplication app = requiredMyApplication();
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
int activeColorResId = isNightMode(app) ? R.color.active_color_primary_dark : R.color.active_color_primary_light; int activeColorResId = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
View buttonView = View.inflate(app, R.layout.bottom_sheet_item_preference_btn, null); View buttonView = View.inflate(themedCtx, R.layout.bottom_sheet_item_preference_btn, null);
TextView tvTitle = buttonView.findViewById(R.id.title); TextView tvTitle = buttonView.findViewById(R.id.title);
tvTitle.setText(app.getString(titleId)); tvTitle.setText(app.getString(titleId));

View file

@ -1207,6 +1207,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (SearchUICore.isDebugMode()) { if (SearchUICore.isDebugMode()) {
LOG.info("UI >> Start loading categories"); LOG.info("UI >> Start loading categories");
} }
final boolean nightMode = !app.getSettings().isLightContent();
SearchResultCollection res = searchUICore.shallowSearch(SearchAmenityTypesAPI.class, "", null); SearchResultCollection res = searchUICore.shallowSearch(SearchAmenityTypesAPI.class, "", null);
if (res != null) { if (res != null) {
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
@ -1274,6 +1275,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
}); });
UiUtilities.setupSnackbarVerticalLayout(snackbar); UiUtilities.setupSnackbarVerticalLayout(snackbar);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show(); snackbar.show();
} }
} }

View file

@ -940,6 +940,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
} }
}); });
UiUtilities.setupSnackbarVerticalLayout(snackbar); UiUtilities.setupSnackbarVerticalLayout(snackbar);
UiUtilities.setupSnackbar(snackbar, nightMode);
snackbar.show(); snackbar.show();
} }
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.settings.bottomsheets; package net.osmand.plus.settings.bottomsheets;
import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.os.Build; import android.os.Build;
@ -51,6 +52,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
if (!(preference instanceof BooleanPreference)) { if (!(preference instanceof BooleanPreference)) {
return; return;
} }
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
String title = switchPreference.getTitle().toString(); String title = switchPreference.getTitle().toString();
items.add(new TitleItem(title)); items.add(new TitleItem(title));
@ -62,8 +64,8 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
? getString(R.string.shared_string_enabled) : summaryOn.toString(); ? getString(R.string.shared_string_enabled) : summaryOn.toString();
final String off = summaryOff == null || summaryOff.toString().equals("") final String off = summaryOff == null || summaryOff.toString().equals("")
? getString(R.string.shared_string_disabled) : summaryOff.toString(); ? getString(R.string.shared_string_disabled) : summaryOff.toString();
final int activeColor = AndroidUtils.resolveAttribute(app, R.attr.active_color_basic); final int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
final int disabledColor = AndroidUtils.resolveAttribute(app, android.R.attr.textColorSecondary); final int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
boolean checked = pref.getModeValue(getAppMode()); boolean checked = pref.getModeValue(getAppMode());
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1]; final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
@ -129,10 +131,11 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
protected void updateCustomButtonView(View customView, boolean checked) { protected void updateCustomButtonView(View customView, boolean checked) {
OsmandApplication app = requiredMyApplication(); OsmandApplication app = requiredMyApplication();
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
View buttonView = customView.findViewById(R.id.button_container); View buttonView = customView.findViewById(R.id.button_container);
int colorRes = getAppMode().getIconColorInfo().getColor(nightMode); int colorRes = getAppMode().getIconColorInfo().getColor(nightMode);
int color = checked ? getResolvedColor(colorRes) : AndroidUtils.getColorFromAttr(app, R.attr.divider_color_basic); int color = checked ? getResolvedColor(colorRes) : AndroidUtils.getColorFromAttr(themedCtx, R.attr.divider_color_basic);
int bgColor = UiUtilities.getColorWithAlpha(color, checked ? 0.1f : 0.5f); int bgColor = UiUtilities.getColorWithAlpha(color, checked ? 0.1f : 0.5f);
int selectedColor = UiUtilities.getColorWithAlpha(color, checked ? 0.3f : 0.5f); int selectedColor = UiUtilities.getColorWithAlpha(color, checked ? 0.3f : 0.5f);

View file

@ -1,5 +1,6 @@
package net.osmand.plus.settings.bottomsheets; package net.osmand.plus.settings.bottomsheets;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
@ -59,6 +60,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
settings = app.getSettings(); settings = app.getSettings();
appMode = getAppMode(); appMode = getAppMode();
preference = settings.ROUTE_RECALCULATION_DISTANCE; preference = settings.ROUTE_RECALCULATION_DISTANCE;
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
getPreferenceStateAndValue(); getPreferenceStateAndValue();
final SwitchPreferenceEx switchPref = (SwitchPreferenceEx) getPreference(); final SwitchPreferenceEx switchPref = (SwitchPreferenceEx) getPreference();
@ -81,9 +83,9 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
} }
final int appModeColorId = appMode.getIconColorInfo().getColor(nightMode); final int appModeColorId = appMode.getIconColorInfo().getColor(nightMode);
final int appModeColor = ContextCompat.getColor(app, appModeColorId); final int appModeColor = ContextCompat.getColor(themedCtx, appModeColorId);
final int activeColor = AndroidUtils.resolveAttribute(app, R.attr.active_color_basic); final int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
final int disabledColor = AndroidUtils.resolveAttribute(app, android.R.attr.textColorSecondary); final int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
String title = getString(R.string.recalculate_route_in_deviation); String title = getString(R.string.recalculate_route_in_deviation);
items.add(new TitleItem(title)); items.add(new TitleItem(title));
@ -176,11 +178,12 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
} }
private void updateSliderView() { private void updateSliderView() {
int activeColor = AndroidUtils.resolveAttribute(app, R.attr.active_color_basic); Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
int disabledColor = AndroidUtils.resolveAttribute(app, android.R.attr.textColorSecondary); int activeColor = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
int textColorPrimary = AndroidUtils.resolveAttribute(app, android.R.attr.textColorPrimary); int disabledColor = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorSecondary);
tvSliderTitle.setTextColor(ContextCompat.getColor(app, enabled ? textColorPrimary : disabledColor)); int textColorPrimary = AndroidUtils.resolveAttribute(themedCtx, android.R.attr.textColorPrimary);
tvSliderSummary.setTextColor(ContextCompat.getColor(app, enabled ? activeColor : disabledColor)); tvSliderTitle.setTextColor(ContextCompat.getColor(themedCtx, enabled ? textColorPrimary : disabledColor));
tvSliderSummary.setTextColor(ContextCompat.getColor(themedCtx, enabled ? activeColor : disabledColor));
tvSliderSummary.setText(getFormattedDistance(app, currentValue)); tvSliderSummary.setText(getFormattedDistance(app, currentValue));
slider.setValue(findIndexOfValue(currentValue)); slider.setValue(findIndexOfValue(currentValue));
slider.setEnabled(enabled); slider.setEnabled(enabled);

View file

@ -12,6 +12,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
@ -42,6 +43,7 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
if (ctx == null || listPreference == null || listPreference.getEntries() == null || listPreference.getEntryValues() == null) { if (ctx == null || listPreference == null || listPreference.getEntries() == null || listPreference.getEntryValues() == null) {
return; return;
} }
ctx = UiUtilities.getThemedContext(ctx, nightMode);
Bundle args = getArguments(); Bundle args = getArguments();
if (args != null && args.containsKey(USE_COLLAPSIBLE_DESCRIPTION)) { if (args != null && args.containsKey(USE_COLLAPSIBLE_DESCRIPTION)) {
collapsibleDescription = args.getBoolean(USE_COLLAPSIBLE_DESCRIPTION); collapsibleDescription = args.getBoolean(USE_COLLAPSIBLE_DESCRIPTION);