Fix strings; extract boilerplate code to AndroidUtils
This commit is contained in:
parent
a6932c15b6
commit
e6fa541c02
7 changed files with 40 additions and 65 deletions
|
@ -4,6 +4,7 @@ package net.osmand;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
|
@ -11,6 +12,7 @@ import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.StateListDrawable;
|
import android.graphics.drawable.StateListDrawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.support.annotation.ColorRes;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
@ -118,6 +120,21 @@ public class AndroidUtils {
|
||||||
return null;
|
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,
|
public static StateListDrawable createStateListDrawable(Context ctx, boolean night,
|
||||||
@DrawableRes int lightNormal, @DrawableRes int lightPressed,
|
@DrawableRes int lightNormal, @DrawableRes int lightPressed,
|
||||||
@DrawableRes int darkNormal, @DrawableRes int darkPressed) {
|
@DrawableRes int darkNormal, @DrawableRes int darkPressed) {
|
||||||
|
|
|
@ -716,16 +716,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
||||||
|
|
||||||
private void enableDisableButtons(View buttonView, TextView button, boolean enabled) {
|
private void enableDisableButtons(View buttonView, TextView button, boolean enabled) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
ColorStateList buttonColorStateList = new ColorStateList(
|
ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(getContext(), nightMode,
|
||||||
new int[][]{
|
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||||
new int[]{android.R.attr.state_pressed},
|
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||||
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)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
|
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_bg_dark : R.drawable.context_menu_controller_bg_light);
|
||||||
button.setTextColor(buttonColorStateList);
|
button.setTextColor(buttonColorStateList);
|
||||||
|
|
|
@ -991,16 +991,9 @@ public class MenuBuilder {
|
||||||
int paddingSides = dpToPx(10f);
|
int paddingSides = dpToPx(10f);
|
||||||
button.setPadding(paddingSides, 0, paddingSides, 0);
|
button.setPadding(paddingSides, 0, paddingSides, 0);
|
||||||
if (!selected) {
|
if (!selected) {
|
||||||
ColorStateList buttonColorStateList = new ColorStateList(
|
ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(context, !light,
|
||||||
new int[][] {
|
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||||
new int[]{android.R.attr.state_pressed},
|
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||||
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)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
button.setTextColor(buttonColorStateList);
|
button.setTextColor(buttonColorStateList);
|
||||||
} else {
|
} 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));
|
button.setTextColor(ContextCompat.getColor(context, light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
|
||||||
|
|
|
@ -75,15 +75,15 @@ public class OpeningHoursInfo {
|
||||||
if (isOpened24_7()) {
|
if (isOpened24_7()) {
|
||||||
return context.getString(R.string.shared_string_is_open_24_7);
|
return context.getString(R.string.shared_string_is_open_24_7);
|
||||||
} else if (!Algorithms.isEmpty(getNearToOpeningTime())) {
|
} 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())) {
|
} 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())) {
|
} 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())) {
|
} 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())) {
|
} 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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,16 +102,9 @@ public class WikipediaDialogFragment extends DialogFragment {
|
||||||
TextView titleTextView = (TextView) mainView.findViewById(R.id.title_text_view);
|
TextView titleTextView = (TextView) mainView.findViewById(R.id.title_text_view);
|
||||||
titleTextView.setTextColor(toolbarTextColor);
|
titleTextView.setTextColor(toolbarTextColor);
|
||||||
|
|
||||||
ColorStateList buttonColorStateList = new ColorStateList(
|
ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(getContext(), darkMode,
|
||||||
new int[][]{
|
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||||
new int[]{android.R.attr.state_pressed},
|
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||||
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)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
final TextView readFullArticleButton = (TextView) mainView.findViewById(R.id.read_full_article);
|
final TextView readFullArticleButton = (TextView) mainView.findViewById(R.id.read_full_article);
|
||||||
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) readFullArticleButton.getLayoutParams();
|
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) readFullArticleButton.getLayoutParams();
|
||||||
|
|
|
@ -219,16 +219,9 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
button.setTextSize(14);
|
button.setTextSize(14);
|
||||||
int paddingSides = dpToPx(10f);
|
int paddingSides = dpToPx(10f);
|
||||||
button.setPadding(paddingSides, 0, paddingSides, 0);
|
button.setPadding(paddingSides, 0, paddingSides, 0);
|
||||||
ColorStateList buttonColorStateList = new ColorStateList(
|
ColorStateList buttonColorStateList = AndroidUtils.createColorStateList(view.getContext(), !light,
|
||||||
new int[][] {
|
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||||
new int[]{android.R.attr.state_pressed},
|
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||||
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)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
button.setTextColor(buttonColorStateList);
|
button.setTextColor(buttonColorStateList);
|
||||||
button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
button.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
|
||||||
button.setSingleLine(true);
|
button.setSingleLine(true);
|
||||||
|
|
|
@ -754,26 +754,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
||||||
|
|
||||||
private class KeyboardAdapter extends ArrayAdapter<Object> {
|
private class KeyboardAdapter extends ArrayAdapter<Object> {
|
||||||
|
|
||||||
private ColorStateList dividerControlColorStateList = new ColorStateList(
|
private ColorStateList dividerControlColorStateList = AndroidUtils.createColorStateList(getContext(), false,
|
||||||
new int[][]{
|
R.color.keyboard_item_divider_control_color_light, R.color.keyboard_item_divider_control_color_light_pressed,
|
||||||
new int[]{android.R.attr.state_pressed},
|
0, 0);
|
||||||
new int[]{}
|
private ColorStateList numberColorStateList = AndroidUtils.createColorStateList(getContext(), false,
|
||||||
},
|
R.color.keyboard_item_text_color_light, R.color.keyboard_item_text_color_light_pressed,
|
||||||
new int[] {
|
0, 0);
|
||||||
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)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
KeyboardAdapter(@NonNull Context context, @NonNull Object[] objects) {
|
KeyboardAdapter(@NonNull Context context, @NonNull Object[] objects) {
|
||||||
super(context, 0, objects);
|
super(context, 0, objects);
|
||||||
|
|
Loading…
Reference in a new issue