1 /*
2  * Copyright (C) 2021 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.settings.bluetooth;
18 
19 import android.content.Context;
20 import android.graphics.drawable.Drawable;
21 import android.view.View;
22 import android.widget.ImageButton;
23 
24 import androidx.preference.Preference;
25 import androidx.preference.PreferenceViewHolder;
26 
27 import com.android.settings.R;
28 
29 /**
30  * A custom preference for companion device apps. Added a button for association removal
31  */
32 public class CompanionAppWidgetPreference extends Preference {
33     private Drawable mWidgetIcon;
34     private View.OnClickListener mWidgetListener;
35     private int mImageButtonPadding;
36 
CompanionAppWidgetPreference(Drawable widgetIcon, View.OnClickListener widgetListener, Context context)37     public CompanionAppWidgetPreference(Drawable widgetIcon, View.OnClickListener widgetListener,
38             Context context) {
39         super(context);
40         mWidgetIcon = widgetIcon;
41         mWidgetListener = widgetListener;
42         mImageButtonPadding = context.getResources().getDimensionPixelSize(
43                 R.dimen.bluetooth_companion_app_widget);
44         setWidgetLayoutResource(R.layout.companion_apps_remove_button_widget);
45     }
46 
47     @Override
onBindViewHolder(PreferenceViewHolder holder)48     public void onBindViewHolder(PreferenceViewHolder holder) {
49         super.onBindViewHolder(holder);
50         ImageButton imageButton = (ImageButton) holder.findViewById(R.id.remove_button);
51         imageButton.setPadding(
52                 mImageButtonPadding, mImageButtonPadding, mImageButtonPadding, mImageButtonPadding);
53         imageButton.setColorFilter(getContext().getColor(android.R.color.darker_gray));
54         imageButton.setImageDrawable(mWidgetIcon);
55         imageButton.setOnClickListener(mWidgetListener);
56     }
57 
58 }
59