Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35a378b8 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Material 3: Navbar highlighting, TextInputLayouts in dialogs, Buttons

parent 20bb9481
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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 {

@@ -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) {
+1 −1
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+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;
@@ -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";
@@ -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.
     */
+11 −0
Original line number Diff line number Diff line
@@ -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) {
+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