blob: 8f7219b113640321269458c5e491b1cab78530ba (
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
|
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 androidx.core.content.ContextCompat;
import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
import it.niedermann.nextcloud.deck.R;
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);
} else {
snackbar.setActionTextColor(ContextCompat.getColor(view.getContext(), R.color.defaultBrand));
}
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);
}
}
|