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.View;
23
24import androidx.constraintlayout.widget.ConstraintLayout;
25import eu.siacs.conversations.R;
26import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection;
27
28public class DialpadView extends ConstraintLayout implements View.OnClickListener {
29
30    protected java.util.function.Consumer<String> clickConsumer = null;
31
32    public DialpadView(Context context) {
33        super(context);
34        init();
35    }
36
37    public DialpadView(Context context, AttributeSet attrs) {
38        super(context, attrs);
39        init();
40    }
41
42    public DialpadView(Context context, AttributeSet attrs, int defStyleAttr) {
43        super(context, attrs, defStyleAttr);
44        init();
45    }
46
47    public void setClickConsumer(java.util.function.Consumer<String> clickConsumer) {
48        this.clickConsumer = clickConsumer;
49    }
50
51    private void init() {
52        inflate(getContext(), R.layout.dialpad, this);
53        initViews();
54    }
55
56    private void initViews() {
57        findViewById(R.id.dialpad_1_holder).setOnClickListener(this);
58        findViewById(R.id.dialpad_2_holder).setOnClickListener(this);
59        findViewById(R.id.dialpad_3_holder).setOnClickListener(this);
60        findViewById(R.id.dialpad_4_holder).setOnClickListener(this);
61        findViewById(R.id.dialpad_5_holder).setOnClickListener(this);
62        findViewById(R.id.dialpad_6_holder).setOnClickListener(this);
63        findViewById(R.id.dialpad_7_holder).setOnClickListener(this);
64        findViewById(R.id.dialpad_8_holder).setOnClickListener(this);
65        findViewById(R.id.dialpad_9_holder).setOnClickListener(this);
66        findViewById(R.id.dialpad_0_holder).setOnClickListener(this);
67        findViewById(R.id.dialpad_asterisk_holder).setOnClickListener(this);
68        findViewById(R.id.dialpad_pound_holder).setOnClickListener(this);
69    }
70
71    @Override
72    public void onClick(View v) {
73        clickConsumer.accept(v.getTag().toString());
74    }
75
76}