1 /** 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * ``` 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * ``` 10 * 11 * Unless required by applicable law or agreed to in writing, software distributed under the License 12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 13 * or implied. See the License for the specific language governing permissions and limitations under 14 * the License. 15 */ 16 package com.android.healthconnect.controller.permissions.connectedapps 17 18 import android.content.Context 19 import android.util.AttributeSet 20 import android.widget.ImageView 21 import android.widget.TextView 22 import androidx.core.view.isVisible 23 import androidx.preference.Preference 24 import androidx.preference.PreferenceViewHolder 25 import com.android.healthconnect.controller.R 26 27 class PermissionHeaderPreference 28 @JvmOverloads 29 constructor( 30 context: Context, 31 attrs: AttributeSet? = null, 32 defStyleAttr: Int = 0, 33 defStyleRes: Int = 0, 34 ) : Preference(context, attrs, defStyleAttr, defStyleRes) { 35 36 private lateinit var iconView: ImageView 37 private lateinit var titleView: TextView 38 private lateinit var subtitleView: TextView 39 40 init { 41 layoutResource = R.layout.widget_permission_header 42 isSelectable = false 43 } 44 onBindViewHoldernull45 override fun onBindViewHolder(holder: PreferenceViewHolder) { 46 super.onBindViewHolder(holder) 47 iconView = holder.findViewById(R.id.permission_header_icon) as ImageView 48 iconView.setImageDrawable(getIcon()) 49 titleView = holder.findViewById(R.id.permission_header_title) as TextView 50 titleView.setText(getTitle()) 51 subtitleView = holder.findViewById(R.id.permission_header_summary) as TextView 52 subtitleView.isVisible = (summary != null) 53 if (summary != null) { 54 subtitleView.setText(summary) 55 } 56 } 57 } 58