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.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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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 "";
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -754,26 +754,12 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
|
||||
private class KeyboardAdapter extends ArrayAdapter<Object> {
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue