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_height="match_parent"
android:layout_weight="1"
android:textColor="?android:textColorPrimary"
android:ellipsize="end"
android:gravity="center_vertical"
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 tvAction = (TextView) view.findViewById(com.google.android.material.R.id.snackbar_action);
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));
if (actionColor == null) {
@ -388,7 +389,7 @@ public class UiUtilities {
tvMessage.setMaxLines(maxLines);
}
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 file

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

View file

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

View file

@ -1,6 +1,7 @@
package net.osmand.plus.profiles;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
@ -17,6 +18,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
@ -225,10 +227,11 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
private void addButtonItem(int titleId, int iconId, OnClickListener listener) {
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);
tvTitle.setText(app.getString(titleId));

View file

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

View file

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

View file

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

View file

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

View file

@ -12,6 +12,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButton;
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) {
return;
}
ctx = UiUtilities.getThemedContext(ctx, nightMode);
Bundle args = getArguments();
if (args != null && args.containsKey(USE_COLLAPSIBLE_DESCRIPTION)) {
collapsibleDescription = args.getBoolean(USE_COLLAPSIBLE_DESCRIPTION);