Fix select category dark theme

This commit is contained in:
Dima-1 2020-04-14 17:07:32 +03:00
parent 0f869b81be
commit 1942a9a09d
3 changed files with 22 additions and 20 deletions

View file

@ -1,6 +1,5 @@
package net.osmand.plus.helpers;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
@ -171,8 +170,8 @@ public class ColorDialogs {
colorSpinner.setSelection(selection);
}
public static void setupColorSpinnerEx(final Activity ctx, int selectedColor, final Spinner colorSpinner,
final TIntArrayList colors, OnItemSelectedListener listener) {
public static void setupColorSpinnerEx(final Context ctx, int selectedColor, final Spinner colorSpinner,
final TIntArrayList colors, OnItemSelectedListener listener) {
colors.add(pallette);
List<String> colorNames = new ArrayList<String>();
int selection = -1;
@ -237,9 +236,8 @@ public class ColorDialogs {
return "#" + c; //$NON-NLS-1$
}
private static Drawable getIcon(final Activity activity, int resId, int color) {
OsmandApplication app = (OsmandApplication)activity.getApplication();
Drawable d = app.getResources().getDrawable(resId).mutate();
private static Drawable getIcon(final Context ctx, int resId, int color) {
Drawable d = ctx.getResources().getDrawable(resId).mutate();
d.clearColorFilter();
d.setColorFilter(color, PorterDuff.Mode.SRC_IN);
return d;
@ -256,7 +254,7 @@ public class ColorDialogs {
return colorName;
}
private static int dpToPx(final Activity activity, float dp) {
private static int dpToPx(final Context activity, float dp) {
Resources r = activity.getResources();
return (int) TypedValue.applyDimension(
COMPLEX_UNIT_DIP,

View file

@ -20,6 +20,7 @@ import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.util.Algorithms;
@ -69,10 +70,10 @@ public class EditCategoryDialogFragment extends DialogFragment {
} else if (getArguments() != null) {
restoreState(getArguments());
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
builder.setTitle(R.string.favorite_category_add_new_title);
final View v = activity.getLayoutInflater().inflate(R.layout.favorite_category_edit_dialog, null, false);
final View v = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_edit_dialog, null, false);
nameEdit = (EditText)v.findViewById(R.id.edit_name);
nameEdit.setText(name);
@ -81,7 +82,7 @@ public class EditCategoryDialogFragment extends DialogFragment {
colorSpinner = (Spinner)v.findViewById(R.id.edit_color);
final TIntArrayList colors = new TIntArrayList();
final int intColor = color;
ColorDialogs.setupColorSpinnerEx(activity, intColor, colorSpinner, colors, new AdapterView.OnItemSelectedListener() {
ColorDialogs.setupColorSpinnerEx(v.getContext(), intColor, colorSpinner, colors, new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
color = colors.get(position);

View file

@ -70,26 +70,29 @@ public class SelectCategoryDialogFragment extends DialogFragment {
}
final FragmentActivity activity = requireActivity();
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final OsmandApplication app = (OsmandApplication) activity.getApplication();
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode));
builder.setTitle(R.string.favorite_category_select);
final View v = activity.getLayoutInflater().inflate(R.layout.favorite_categories_dialog, null, false);
final View v = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_categories_dialog, null, false);
LinearLayout ll = (LinearLayout) v.findViewById(R.id.list_container);
final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites();
final FavouritesDbHelper helper = app.getFavorites();
if (gpxFile != null) {
if (gpxCategories != null) {
for (Map.Entry<String, Integer> e : gpxCategories.entrySet()) {
String categoryName = e.getKey();
addCategory(activity, ll, categoryName, e.getValue());
ll.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue()));
}
}
} else {
List<FavouritesDbHelper.FavoriteGroup> gs = helper.getFavoriteGroups();
for (final FavouritesDbHelper.FavoriteGroup category : gs) {
addCategory(activity, ll, category.getDisplayName(getContext()), category.getColor());
ll.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()),
category.getColor()));
}
}
View itemView = activity.getLayoutInflater().inflate(R.layout.favorite_category_dialog_item, null);
View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_dialog_item, null);
Button button = (Button)itemView.findViewById(R.id.button);
button.setCompoundDrawablesWithIntrinsicBounds(getIcon(activity, R.drawable.map_zoom_in), null, null, null);
button.setCompoundDrawablePadding(AndroidUtils.dpToPx(activity,15f));
@ -113,8 +116,8 @@ public class SelectCategoryDialogFragment extends DialogFragment {
return builder.create();
}
private void addCategory(@NonNull final Activity activity, @NonNull LinearLayout ll, final String categoryName, final int categoryColor) {
View itemView = activity.getLayoutInflater().inflate(R.layout.favorite_category_dialog_item, null);
private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor) {
View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.favorite_category_dialog_item, null);
Button button = (Button)itemView.findViewById(R.id.button);
if (categoryColor != 0) {
button.setCompoundDrawablesWithIntrinsicBounds(
@ -143,7 +146,7 @@ public class SelectCategoryDialogFragment extends DialogFragment {
dismiss();
}
});
ll.addView(itemView);
return itemView;
}
public static SelectCategoryDialogFragment createInstance(String editorTag) {