1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.quicksearchbox.ui
18 
19 import android.content.Context
20 import android.util.AttributeSet
21 import android.view.View
22 import android.widget.QuickContactBadge
23 
24 /**
25  * A [QuickContactBadge] that allows setting a click listener. The base class may use
26  * [View.setOnClickListener] internally, so this class adds a separate click listener field.
27  */
28 class ContactBadge : QuickContactBadge {
29   private var mExtraOnClickListener: View.OnClickListener? = null
30 
31   constructor(context: Context?) : super(context)
32 
33   constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
34 
35   constructor(
36     context: Context?,
37     attrs: AttributeSet?,
38     defStyle: Int
39   ) : super(context, attrs, defStyle)
40 
41   @Override
onClicknull42   override fun onClick(v: View?) {
43     super.onClick(v)
44     if (mExtraOnClickListener != null) {
45       mExtraOnClickListener?.onClick(v)
46     }
47   }
48 
setExtraOnClickListenernull49   fun setExtraOnClickListener(extraOnClickListener: View.OnClickListener?) {
50     mExtraOnClickListener = extraOnClickListener
51   }
52 }
53