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.core.util.Consumer;
26
27import androidx.constraintlayout.widget.ConstraintLayout;
28import androidx.databinding.DataBindingUtil;
29import eu.siacs.conversations.databinding.DialpadBinding;
30import eu.siacs.conversations.R;
31
32public class DialpadView extends ConstraintLayout implements View.OnClickListener {
33
34    protected Consumer<String> clickConsumer = null;
35
36    public DialpadView(Context context) {
37        super(context);
38        init();
39    }
40
41    public DialpadView(Context context, AttributeSet attrs) {
42        super(context, attrs);
43        init();
44    }
45
46    public DialpadView(Context context, AttributeSet attrs, int defStyleAttr) {
47        super(context, attrs, defStyleAttr);
48        init();
49    }
50
51    public void setClickConsumer(Consumer<String> clickConsumer) {
52        this.clickConsumer = clickConsumer;
53    }
54
55    private void init() {
56        DialpadBinding binding = DataBindingUtil.inflate(
57            LayoutInflater.from(getContext()),
58            R.layout.dialpad,
59            this,
60            true
61        );
62        binding.setDialpadView(this);
63    }
64
65    @Override
66    public void onClick(View v) {
67        clickConsumer.accept(v.getTag().toString());
68    }
69}