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;
29
30public class DialpadView extends ConstraintLayout implements View.OnClickListener {
31
32    protected Consumer<String> clickConsumer = null;
33
34    public DialpadView(Context context) {
35        super(context);
36        init();
37    }
38
39    public DialpadView(Context context, AttributeSet attrs) {
40        super(context, attrs);
41        init();
42    }
43
44    public DialpadView(Context context, AttributeSet attrs, int defStyleAttr) {
45        super(context, attrs, defStyleAttr);
46        init();
47    }
48
49    public void setClickConsumer(Consumer<String> clickConsumer) {
50        this.clickConsumer = clickConsumer;
51    }
52
53    private void init() {
54        DialpadBinding binding = DataBindingUtil.inflate(
55            LayoutInflater.from(getContext()),
56            R.layout.dialpad,
57            this,
58            true
59        );
60        binding.setDialpadView(this);
61    }
62
63    @Override
64    public void onClick(View v) {
65        clickConsumer.accept(v.getTag().toString());
66    }
67
68	// Based on java.util.function.Consumer to avoid Android 24 dependency
69	public interface Consumer<T> {
70		void accept(T t);
71	}
72}