1 /* 2 * Copyright (C) 2023 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.devicelockcontroller.activities; 18 19 import android.content.Context; 20 import android.text.TextUtils; 21 import android.text.method.LinkMovementMethod; 22 import android.util.AttributeSet; 23 import android.widget.TextView; 24 25 import androidx.annotation.NonNull; 26 import androidx.annotation.Nullable; 27 import androidx.preference.Preference; 28 import androidx.preference.PreferenceViewHolder; 29 30 import com.android.devicelockcontroller.activities.util.UrlUtils; 31 32 public class UrlTextPreference extends Preference { 33 34 public static final String TAG = UrlTextPreference.class.getSimpleName(); 35 UrlTextPreference(@onNull Context context, @Nullable AttributeSet attrs)36 public UrlTextPreference(@NonNull Context context, @Nullable AttributeSet attrs) { 37 super(context, attrs); 38 } 39 40 @Override onBindViewHolder(@onNull PreferenceViewHolder holder)41 public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { 42 super.onBindViewHolder(holder); 43 TextView title = holder.itemView.findViewById(android.R.id.title); 44 if (title != null && !TextUtils.isEmpty(getTitle())) { 45 UrlUtils.setUrlText(title, String.valueOf(getTitle())); 46 title.setMovementMethod(LinkMovementMethod.getInstance()); 47 } 48 } 49 } 50