1 /* 2 * Copyright (C) 2019 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.permissioncontroller.role.ui.handheld; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.Gravity; 22 import android.view.View; 23 import android.widget.LinearLayout; 24 25 import androidx.annotation.AttrRes; 26 import androidx.annotation.NonNull; 27 import androidx.annotation.Nullable; 28 import androidx.annotation.StyleRes; 29 import androidx.preference.Preference; 30 import androidx.preference.PreferenceViewHolder; 31 32 import com.android.permissioncontroller.R; 33 import com.android.permissioncontroller.role.utils.UiUtils; 34 35 /** 36 * {@link Preference} acting as the footer of a page. 37 */ 38 // Made public for com.android.permissioncontroller.role.ui.specialappaccess.handheld 39 public class FooterPreference extends Preference { 40 41 private static final int ICON_LAYOUT_PADDING_VERTICAL_DP = 16; 42 FooterPreference(@onNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)43 FooterPreference(@NonNull Context context, @Nullable AttributeSet attrs, 44 @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { 45 super(context, attrs, defStyleAttr, defStyleRes); 46 47 init(); 48 } 49 FooterPreference(@onNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr)50 FooterPreference(@NonNull Context context, @Nullable AttributeSet attrs, 51 @AttrRes int defStyleAttr) { 52 super(context, attrs, defStyleAttr); 53 54 init(); 55 } 56 FooterPreference(@onNull Context context, @Nullable AttributeSet attrs)57 FooterPreference(@NonNull Context context, @Nullable AttributeSet attrs) { 58 super(context, attrs); 59 60 init(); 61 } 62 63 // Made public for com.android.permissioncontroller.role.ui.specialappaccess.handheld FooterPreference(@onNull Context context)64 public FooterPreference(@NonNull Context context) { 65 super(context); 66 67 init(); 68 } 69 init()70 private void init() { 71 setIcon(R.drawable.ic_info_outline); 72 setSelectable(false); 73 } 74 75 @Override onBindViewHolder(@onNull PreferenceViewHolder holder)76 public void onBindViewHolder(@NonNull PreferenceViewHolder holder) { 77 super.onBindViewHolder(holder); 78 79 holder.setDividerAllowedAbove(true); 80 81 View iconFrame = holder.findViewById(R.id.icon_frame); 82 if (iconFrame == null) { 83 iconFrame = holder.findViewById(android.R.id.icon_frame); 84 } 85 LinearLayout.LayoutParams iconFrameLayoutParams = (LinearLayout.LayoutParams) 86 iconFrame.getLayoutParams(); 87 iconFrameLayoutParams.gravity = Gravity.TOP; 88 iconFrame.setLayoutParams(iconFrameLayoutParams); 89 int iconFramePaddingVertical = UiUtils.dpToPxSize(ICON_LAYOUT_PADDING_VERTICAL_DP, 90 iconFrame.getContext()); 91 iconFrame.setPaddingRelative(iconFrame.getPaddingStart(), iconFramePaddingVertical, 92 iconFrame.getPaddingEnd(), iconFramePaddingVertical); 93 } 94 } 95