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

BrandedSnackbar.java « branding « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 937373932c0671c6c0893d7518eef6bcb67a646a (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
package it.niedermann.nextcloud.deck.ui.branding;

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.nextcloud.deck.util.ColorUtil;

import static it.niedermann.nextcloud.deck.ui.branding.BrandingUtil.isBrandingEnabled;
import static it.niedermann.nextcloud.deck.ui.branding.BrandingUtil.readBrandMainColor;

public class BrandedSnackbar {

    @NonNull
    public static Snackbar make(
            @NonNull View view, @NonNull CharSequence text, @BaseTransientBottomBar.Duration int duration) {
        final Snackbar snackbar = Snackbar.make(view, text, duration);
        if (isBrandingEnabled(view.getContext())) {
            @ColorInt final int color = readBrandMainColor(view.getContext());
            snackbar.setActionTextColor(ColorUtil.isColorDark(color) ? Color.WHITE : color);
        }
        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);
    }

}