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

LabelChip.java « labelchip « view « 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: d69ff2898c372915593a65c5fca10943243bbb42 (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
47
48
49
50
51
52
53
54
55
56
57
package it.niedermann.nextcloud.deck.ui.view.labelchip;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Px;

import com.google.android.flexbox.FlexboxLayout;
import com.google.android.material.chip.Chip;

import it.niedermann.android.util.ColorUtil;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.model.Label;

@SuppressLint("ViewConstructor")
public class LabelChip extends Chip {

    private final Label label;

    protected final FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
    );

    public LabelChip(@NonNull Context context, @NonNull Label label, @Px int gutter) {
        super(context);
        this.label = label;

        params.setMargins(0, 0, gutter, 0);
        setLayoutParams(params);
        setEnsureMinTouchTargetSize(false);
        setMinHeight(0);
        setChipMinHeight(0);
        setPadding(0, gutter, 0, gutter);
        setChipStartPadding(gutter);
        setTextStartPadding(gutter);
        setTextEndPadding(gutter);
        setChipEndPadding(gutter);
        setClickable(false);

        try {
            int labelColor = label.getColor();
            final var colorStateList = ColorStateList.valueOf(labelColor);
            setChipBackgroundColor(colorStateList);
            setTextColor(ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(labelColor));
        } catch (IllegalArgumentException e) {
            DeckLog.logError(e);
        }
    }

    public Label getLabel() {
        return this.label;
    }
}