DialpadView.java

 1/*
 2 * Copyright 2012-2015 the original author or authors.
 3 *
 4 * This program is free software: you can redistribute it and/or modify
 5 * it under the terms of the GNU General Public License as published by
 6 * the Free Software Foundation, either version 3 of the License, or
 7 * (at your option) any later version.
 8 *
 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18package eu.siacs.conversations.ui.widget;
19
20import android.content.Context;
21import android.util.AttributeSet;
22import android.view.LayoutInflater;
23import android.view.View;
24
25import androidx.constraintlayout.widget.ConstraintLayout;
26import androidx.databinding.DataBindingUtil;
27import eu.siacs.conversations.databinding.DialpadBinding;
28import eu.siacs.conversations.R;
29import eu.siacs.conversations.utils.Consumer;
30
31public class DialpadView extends ConstraintLayout implements View.OnClickListener {
32
33    protected Consumer<String> clickConsumer = null;
34
35    public DialpadView(Context context) {
36        super(context);
37        init();
38    }
39
40    public DialpadView(Context context, AttributeSet attrs) {
41        super(context, attrs);
42        init();
43    }
44
45    public DialpadView(Context context, AttributeSet attrs, int defStyleAttr) {
46        super(context, attrs, defStyleAttr);
47        init();
48    }
49
50    public void setClickConsumer(Consumer<String> clickConsumer) {
51        this.clickConsumer = clickConsumer;
52    }
53
54    private void init() {
55        DialpadBinding binding = DataBindingUtil.inflate(
56            LayoutInflater.from(getContext()),
57            R.layout.dialpad,
58            this,
59            true
60        );
61        binding.setDialpadView(this);
62    }
63
64    @Override
65    public void onClick(View v) {
66        clickConsumer.accept(v.getTag().toString());
67    }
68}