Loading app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java +14 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,9 @@ import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient; import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficientBigAreas; import com.google.android.material.textfield.TextInputLayout; public class BrandingUtil { Loading Loading @@ -146,6 +149,17 @@ public class BrandingUtil { )); } public static void applyBrandToEditTextInputLayout(@ColorInt int color, @NonNull TextInputLayout til) { final int colorPrimary = ContextCompat.getColor(til.getContext(), R.color.primary); final int colorAccent = ContextCompat.getColor(til.getContext(), R.color.accent); final var colorDanger = ColorStateList.valueOf(ContextCompat.getColor(til.getContext(), R.color.danger)); til.setBoxStrokeColor(contrastRatioIsSufficientBigAreas(color, colorPrimary) ? color : colorAccent); til.setHintTextColor(ColorStateList.valueOf(contrastRatioIsSufficient(color, colorPrimary) ? color : colorAccent)); til.setErrorTextColor(colorDanger); til.setBoxStrokeErrorColor(colorDanger); til.setErrorIconTintList(colorDanger); } public static void tintMenuIcon(@NonNull MenuItem menuItem, @ColorInt int color) { var drawable = menuItem.getIcon(); if (drawable != null) { Loading app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ public class CategoryDialogFragment extends BrandedDialogFragment { @Override public void applyBrand(int mainColor, int textColor) { BrandingUtil.applyBrandToEditText(mainColor, textColor, binding.search); BrandingUtil.applyBrandToEditTextInputLayout(mainColor, binding.inputWrapper); } /** Loading app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java +9 −1 Original line number Diff line number Diff line package it.niedermann.owncloud.notes.edit.title; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToEditTextInputLayout; import android.app.Dialog; import android.content.Context; import android.os.Bundle; Loading @@ -15,9 +17,10 @@ import androidx.fragment.app.DialogFragment; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogEditTitleBinding; public class EditTitleDialogFragment extends DialogFragment { public class EditTitleDialogFragment extends BrandedDialogFragment { private static final String TAG = EditTitleDialogFragment.class.getSimpleName(); static final String PARAM_OLD_TITLE = "old_title"; Loading Loading @@ -83,6 +86,11 @@ public class EditTitleDialogFragment extends DialogFragment { return fragment; } @Override public void applyBrand(int mainColor, int textColor) { applyBrandToEditTextInputLayout(mainColor, binding.inputWrapper); } /** * Interface that must be implemented by the calling Activity. */ Loading app/src/main/java/it/niedermann/owncloud/notes/shared/util/NotesColorUtil.java +11 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,17 @@ public final class NotesColorUtil { return ret; } public static boolean contrastRatioIsSufficientBigAreas(@ColorInt int colorOne, @ColorInt int colorTwo) { final var key = new ColorPair(colorOne, colorTwo); var ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key); if (ret == null) { ret = ColorUtil.INSTANCE.getContrastRatio(colorOne, colorTwo) > 1.47d; CONTRAST_RATIO_SUFFICIENT_CACHE.put(key, ret); return ret; } return ret; } private static class ColorPair extends Pair<Integer, Integer> { private ColorPair(@Nullable Integer first, @Nullable Integer second) { Loading app/src/main/res/color/text_input_layout_color.xml 0 → 100644 +7 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:color="@color/accent"/> <item android:state_hovered="true" android:color="@color/accent"/> <item android:state_focused="true" android:color="@color/accent"/> <item android:color="@color/grey600" /> </selector> Loading
app/src/main/java/it/niedermann/owncloud/notes/branding/BrandingUtil.java +14 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,9 @@ import it.niedermann.owncloud.notes.NotesApplication; import it.niedermann.owncloud.notes.R; import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient; import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficientBigAreas; import com.google.android.material.textfield.TextInputLayout; public class BrandingUtil { Loading Loading @@ -146,6 +149,17 @@ public class BrandingUtil { )); } public static void applyBrandToEditTextInputLayout(@ColorInt int color, @NonNull TextInputLayout til) { final int colorPrimary = ContextCompat.getColor(til.getContext(), R.color.primary); final int colorAccent = ContextCompat.getColor(til.getContext(), R.color.accent); final var colorDanger = ColorStateList.valueOf(ContextCompat.getColor(til.getContext(), R.color.danger)); til.setBoxStrokeColor(contrastRatioIsSufficientBigAreas(color, colorPrimary) ? color : colorAccent); til.setHintTextColor(ColorStateList.valueOf(contrastRatioIsSufficient(color, colorPrimary) ? color : colorAccent)); til.setErrorTextColor(colorDanger); til.setBoxStrokeErrorColor(colorDanger); til.setErrorIconTintList(colorDanger); } public static void tintMenuIcon(@NonNull MenuItem menuItem, @ColorInt int color) { var drawable = menuItem.getIcon(); if (drawable != null) { Loading
app/src/main/java/it/niedermann/owncloud/notes/edit/category/CategoryDialogFragment.java +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ public class CategoryDialogFragment extends BrandedDialogFragment { @Override public void applyBrand(int mainColor, int textColor) { BrandingUtil.applyBrandToEditText(mainColor, textColor, binding.search); BrandingUtil.applyBrandToEditTextInputLayout(mainColor, binding.inputWrapper); } /** Loading
app/src/main/java/it/niedermann/owncloud/notes/edit/title/EditTitleDialogFragment.java +9 −1 Original line number Diff line number Diff line package it.niedermann.owncloud.notes.edit.title; import static it.niedermann.owncloud.notes.branding.BrandingUtil.applyBrandToEditTextInputLayout; import android.app.Dialog; import android.content.Context; import android.os.Bundle; Loading @@ -15,9 +17,10 @@ import androidx.fragment.app.DialogFragment; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.branding.BrandedDialogFragment; import it.niedermann.owncloud.notes.databinding.DialogEditTitleBinding; public class EditTitleDialogFragment extends DialogFragment { public class EditTitleDialogFragment extends BrandedDialogFragment { private static final String TAG = EditTitleDialogFragment.class.getSimpleName(); static final String PARAM_OLD_TITLE = "old_title"; Loading Loading @@ -83,6 +86,11 @@ public class EditTitleDialogFragment extends DialogFragment { return fragment; } @Override public void applyBrand(int mainColor, int textColor) { applyBrandToEditTextInputLayout(mainColor, binding.inputWrapper); } /** * Interface that must be implemented by the calling Activity. */ Loading
app/src/main/java/it/niedermann/owncloud/notes/shared/util/NotesColorUtil.java +11 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,17 @@ public final class NotesColorUtil { return ret; } public static boolean contrastRatioIsSufficientBigAreas(@ColorInt int colorOne, @ColorInt int colorTwo) { final var key = new ColorPair(colorOne, colorTwo); var ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key); if (ret == null) { ret = ColorUtil.INSTANCE.getContrastRatio(colorOne, colorTwo) > 1.47d; CONTRAST_RATIO_SUFFICIENT_CACHE.put(key, ret); return ret; } return ret; } private static class ColorPair extends Pair<Integer, Integer> { private ColorPair(@Nullable Integer first, @Nullable Integer second) { Loading
app/src/main/res/color/text_input_layout_color.xml 0 → 100644 +7 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_enabled="true" android:color="@color/accent"/> <item android:state_hovered="true" android:color="@color/accent"/> <item android:state_focused="true" android:color="@color/accent"/> <item android:color="@color/grey600" /> </selector>