Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BrandedSnackbar.java « branding « notes « owncloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c0ebf11e71fb4a5b47c192153aa1ce2fcfac251 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package it.niedermann.owncloud.notes.branding;

import static it.niedermann.owncloud.notes.NotesApplication.isDarkThemeActive;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.getAttribute;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.readBrandMainColor;
import static it.niedermann.owncloud.notes.shared.util.NotesColorUtil.contrastRatioIsSufficient;

import android.graphics.Color;
import android.view.View;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;

import it.niedermann.owncloud.notes.R;

public class BrandedSnackbar {

    @NonNull
    public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @BaseTransientBottomBar.Duration int duration) {
        final var snackbar = Snackbar.make(view, text, duration);

        @ColorInt final int backgroundColor = getAttribute(view.getContext(), R.attr.colorSurfaceInverse);
        @ColorInt final int color = readBrandMainColor(view.getContext());

        if (contrastRatioIsSufficient(backgroundColor, color)) {
            snackbar.setActionTextColor(color);
        } else {
            if (isDarkThemeActive(view.getContext())) {
                snackbar.setActionTextColor(Color.BLACK);
            } else {
                snackbar.setActionTextColor(Color.WHITE);
            }
        }

        return snackbar;
    }

    @NonNull
    public static Snackbar make(@NonNull View view, @StringRes int resId, @BaseTransientBottomBar.Duration int duration) {
        return make(view, view.getResources().getText(resId), duration);
    }
}