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 package com.android.healthconnect.controller.autodelete 17 18 import android.content.Context 19 import android.view.LayoutInflater 20 import android.view.ViewGroup 21 import android.widget.LinearLayout 22 import android.widget.TextView 23 import androidx.fragment.app.FragmentActivity 24 import androidx.preference.Preference 25 import androidx.preference.PreferenceViewHolder 26 import com.android.healthconnect.controller.R 27 import com.android.healthconnect.controller.utils.DeviceInfoUtilsImpl 28 import com.android.healthconnect.controller.utils.convertTextViewIntoLink 29 30 /** Custom preference for the header of the auto-delete screen. */ 31 class HeaderPreference constructor(context: Context, private val activity: FragmentActivity) : 32 Preference(context) { 33 onBindViewHoldernull34 override fun onBindViewHolder(holder: PreferenceViewHolder?) { 35 super.onBindViewHolder(holder) 36 37 val widgetFrame: ViewGroup = holder?.findViewById(android.R.id.widget_frame) as ViewGroup 38 val widgetFrameParent: LinearLayout = widgetFrame.parent as LinearLayout 39 val iconFrame: LinearLayout? = holder.findViewById(android.R.id.icon_frame) as LinearLayout? 40 widgetFrameParent.removeView(iconFrame) 41 42 var headerView: LinearLayout? = 43 holder.findViewById(R.id.auto_delete_header_content) as LinearLayout? 44 if (headerView == null) { 45 val inflater: LayoutInflater = context.getSystemService(LayoutInflater::class.java) 46 headerView = 47 inflater.inflate(R.layout.widget_auto_delete_header, widgetFrameParent, false) 48 as LinearLayout? 49 widgetFrameParent.addView(headerView, 0) 50 } 51 52 val linkView: TextView? = headerView?.findViewById(R.id.link) as TextView? 53 val linkString: String = context.getString(R.string.auto_delete_learn_more) 54 linkView?.let { 55 convertTextViewIntoLink(it, linkString, 0, linkString.length) { 56 DeviceInfoUtilsImpl().openHCGetStartedLink(activity) 57 } 58 } 59 } 60 } 61