diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 8456023fa7..ba61cd1b36 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -4,6 +4,7 @@ package net.osmand; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.PointF; @@ -11,6 +12,7 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.StateListDrawable; import android.os.Build; import android.os.IBinder; +import android.support.annotation.ColorRes; import android.support.annotation.DrawableRes; import android.support.v4.content.ContextCompat; import android.text.TextUtils; @@ -118,6 +120,21 @@ public class AndroidUtils { return null; } + public static ColorStateList createColorStateList(Context ctx, boolean night, + @ColorRes int lightNormal, @ColorRes int lightPressed, + @ColorRes int darkNormal, @ColorRes int darkPressed) { + return new ColorStateList( + new int[][]{ + new int[]{android.R.attr.state_pressed}, + new int[]{} + }, + new int[]{ + ContextCompat.getColor(ctx, night ? darkPressed : lightPressed), + ContextCompat.getColor(ctx, night ? darkNormal : lightNormal) + } + ); + } + public static StateListDrawable createStateListDrawable(Context ctx, boolean night, @DrawableRes int lightNormal, @DrawableRes int lightPressed, @DrawableRes int darkNormal, @DrawableRes int darkPressed) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index fe3ce68846..72099d943e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -716,16 +716,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo private void enableDisableButtons(View buttonView, TextView button, boolean enabled) { if (enabled) { - ColorStateList buttonColorStateList = new ColorStateList( - new int[][]{ - new int[]{android.R.attr.state_pressed}, - new int[]{} - }, - new int[] { - getResources().getColor(nightMode ? R.color.ctx_menu_controller_button_text_color_dark_p : R.color.ctx_menu_controller_button_text_color_light_p), - getResources().getColor(nightMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n) - } - ); + ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(getContext(), nightMode, + R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, + R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light); button.setTextColor(buttonColorStateList); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 7d53141a19..cd43f295ec 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -991,16 +991,9 @@ public class MenuBuilder { int paddingSides = dpToPx(10f); button.setPadding(paddingSides, 0, paddingSides, 0); if (!selected) { - ColorStateList buttonColorStateList = new ColorStateList( - new int[][] { - new int[]{android.R.attr.state_pressed}, - new int[]{} - }, - new int[] { - context.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p), - context.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n) - } - ); + ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(context, !light, + R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, + R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); button.setTextColor(buttonColorStateList); } else { button.setTextColor(ContextCompat.getColor(context, light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark)); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/OpeningHoursInfo.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/OpeningHoursInfo.java index 09db885529..34990e86ac 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/OpeningHoursInfo.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/OpeningHoursInfo.java @@ -75,15 +75,15 @@ public class OpeningHoursInfo { if (isOpened24_7()) { return context.getString(R.string.shared_string_is_open_24_7); } else if (!Algorithms.isEmpty(getNearToOpeningTime())) { - return context.getString(R.string.will_be_opened_at) + " " + getNearToOpeningTime(); + return context.getString(R.string.will_open_at) + " " + getNearToOpeningTime(); } else if (!Algorithms.isEmpty(getOpeningTime())) { - return context.getString(R.string.opened_from) + " " + getOpeningTime(); + return context.getString(R.string.open_from) + " " + getOpeningTime(); } else if (!Algorithms.isEmpty(getNearToClosingTime())) { - return context.getString(R.string.will_be_closed_at) + " " + getNearToClosingTime(); + return context.getString(R.string.will_close_at) + " " + getNearToClosingTime(); } else if (!Algorithms.isEmpty(getClosingTime())) { - return context.getString(R.string.opened_till) + " " + getClosingTime(); + return context.getString(R.string.open_till) + " " + getClosingTime(); } else if (!Algorithms.isEmpty(getOpeningDay())) { - return context.getString(R.string.will_be_opened_on) + " " + getOpeningDay() + "."; + return context.getString(R.string.will_open_on) + " " + getOpeningDay() + "."; } return ""; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java index 6480054f13..0030eedf43 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/WikipediaDialogFragment.java @@ -102,16 +102,9 @@ public class WikipediaDialogFragment extends DialogFragment { TextView titleTextView = (TextView) mainView.findViewById(R.id.title_text_view); titleTextView.setTextColor(toolbarTextColor); - ColorStateList buttonColorStateList = new ColorStateList( - new int[][]{ - new int[]{android.R.attr.state_pressed}, - new int[]{} - }, - new int[] { - getResources().getColor(darkMode ? R.color.ctx_menu_controller_button_text_color_dark_p : R.color.ctx_menu_controller_button_text_color_light_p), - getResources().getColor(darkMode ? R.color.ctx_menu_controller_button_text_color_dark_n : R.color.ctx_menu_controller_button_text_color_light_n) - } - ); + ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(getContext(), darkMode, + R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, + R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); final TextView readFullArticleButton = (TextView) mainView.findViewById(R.id.read_full_article); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) readFullArticleButton.getLayoutParams(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 5d7610e692..ce158b58b1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -219,16 +219,9 @@ public class AmenityMenuBuilder extends MenuBuilder { button.setTextSize(14); int paddingSides = dpToPx(10f); button.setPadding(paddingSides, 0, paddingSides, 0); - ColorStateList buttonColorStateList = new ColorStateList( - new int[][] { - new int[]{android.R.attr.state_pressed}, - new int[]{} - }, - new int[] { - view.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p), - view.getResources().getColor(light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n) - } - ); + ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(view.getContext(), !light, + R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p, + R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p); button.setTextColor(buttonColorStateList); button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); button.setSingleLine(true); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 977fbe466c..bdb13ffa46 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -754,26 +754,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private class KeyboardAdapter extends ArrayAdapter { - private ColorStateList dividerControlColorStateList = new ColorStateList( - new int[][]{ - new int[]{android.R.attr.state_pressed}, - new int[]{} - }, - new int[] { - getResources().getColor(R.color.keyboard_item_divider_control_color_light_pressed), - getResources().getColor(R.color.keyboard_item_divider_control_color_light) - } - ); - private ColorStateList numberColorStateList = new ColorStateList( - new int[][]{ - new int[]{android.R.attr.state_pressed}, - new int[]{} - }, - new int[] { - getResources().getColor(R.color.keyboard_item_text_color_light_pressed), - getResources().getColor(R.color.keyboard_item_text_color_light) - } - ); + private ColorStateList dividerControlColorStateList = AndroidUtils.createColorStateList(getContext(), false, + R.color.keyboard_item_divider_control_color_light, R.color.keyboard_item_divider_control_color_light_pressed, + 0, 0); + private ColorStateList numberColorStateList = AndroidUtils.createColorStateList(getContext(), false, + R.color.keyboard_item_text_color_light, R.color.keyboard_item_text_color_light_pressed, + 0, 0); KeyboardAdapter(@NonNull Context context, @NonNull Object[] objects) { super(context, 0, objects);