Skip to content

Commit

Permalink
set the correct color using Material3 for prepareInputDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
oliexdev committed Jul 22, 2023
1 parent 168c832 commit 60bcfd8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.health.openscale.core.evaluation.EvaluationResult;
import com.health.openscale.core.evaluation.EvaluationSheet;
import com.health.openscale.core.utils.Converters;
import com.health.openscale.gui.utils.ColorUtil;

import java.util.Date;
import java.util.Locale;
Expand Down Expand Up @@ -707,10 +708,12 @@ public void onClick(View button) {
final Button inc = view.findViewById(R.id.btn_inc);
inc.setText("\u25b2 +" + formatValue(INC_DEC_DELTA));
inc.setOnClickListener(onClickListener);
inc.setTextColor(ColorUtil.getPrimaryColor(getContext()));
inc.setOnTouchListener(repeatListener);

final Button dec = view.findViewById(R.id.btn_dec);
dec.setText("\u25bc -" + formatValue(INC_DEC_DELTA));
dec.setTextColor(ColorUtil.getPrimaryColor(getContext()));
dec.setOnClickListener(onClickListener);
dec.setOnTouchListener(repeatListener);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import static com.health.openscale.gui.measurement.MeasurementView.MeasurementViewMode.STATISTIC;
import static com.health.openscale.gui.measurement.MeasurementView.MeasurementViewMode.VIEW;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
Expand All @@ -44,11 +44,13 @@
import android.widget.TableRow;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.preference.CheckBoxPreference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.health.openscale.R;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleMeasurement;
Expand Down Expand Up @@ -454,11 +456,12 @@ private MeasurementView getNextView() {

private void prepareInputDialog(final AlertDialog dialog) {
dialog.setTitle(getName());
getIcon().setColorFilter(ColorUtil.getTintColor(getContext()), PorterDuff.Mode.SRC_IN);
dialog.setIcon(getIcon());

final View input = getInputView();

FrameLayout fl = dialog.findViewById(android.R.id.custom);
FrameLayout fl = dialog.findViewById(R.id.custom);
fl.removeAllViews();
fl.addView(input, new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
Expand All @@ -475,10 +478,13 @@ public void onClick(View view) {
};

dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ColorUtil.getPrimaryColor(getContext()));
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(clickListener);
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(ColorUtil.getPrimaryColor(getContext()));

final MeasurementView next = getNextView();
if (next != null) {
dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(ColorUtil.getPrimaryColor(getContext()));
dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -494,7 +500,7 @@ public void onClick(View v) {
}

private void showInputDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getContext());

builder.setTitle(getName());
builder.setIcon(getIcon());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public class ColorUtil {
public static final int COLOR_BLACK = Color.parseColor("#000000");
public static final int[] COLORS = new int[]{COLOR_BLUE, COLOR_VIOLET, COLOR_GREEN, COLOR_ORANGE, COLOR_RED};

public static int getPrimaryColor(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

int nightModeFlags = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;

if (prefs.getString("app_theme", "Light").equals("Dark") || nightModeFlags == Configuration.UI_MODE_NIGHT_YES) {
return context.getResources().getColor(android.R.color.primary_text_dark);
}

return context.getResources().getColor(android.R.color.primary_text_light);
}

public static int getTintColor(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

Expand Down

0 comments on commit 60bcfd8

Please sign in to comment.