1 /* 2 * Copyright (C) 2018 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.car.settings.common; 18 19 import android.content.Context; 20 import android.content.res.TypedArray; 21 import android.util.AttributeSet; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceGroup; 25 26 import com.android.car.ui.R; 27 import com.android.car.ui.preference.CarUiEditTextPreference; 28 import com.android.car.ui.preference.CarUiPreference; 29 30 /** 31 * {@link PreferenceGroup} which does not display a title, icon, or summary. This allows for 32 * logical grouping of preferences without indications in the UI. 33 */ 34 public class LogicalPreferenceGroup extends PreferenceGroup { 35 36 private final boolean mShouldShowChevron; 37 LogicalPreferenceGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)38 public LogicalPreferenceGroup(Context context, AttributeSet attrs, int defStyleAttr, 39 int defStyleRes) { 40 super(context, attrs, defStyleAttr, defStyleRes); 41 setLayoutResource(R.layout.logical_preference_group); 42 TypedArray a = context.obtainStyledAttributes( 43 attrs, 44 R.styleable.PreferenceGroup, 45 defStyleAttr, 46 defStyleRes); 47 48 mShouldShowChevron = a.getBoolean(R.styleable.PreferenceGroup_showChevron, true); 49 a.recycle(); 50 } 51 LogicalPreferenceGroup(Context context, AttributeSet attrs, int defStyleAttr)52 public LogicalPreferenceGroup(Context context, AttributeSet attrs, int defStyleAttr) { 53 this(context, attrs, defStyleAttr, 0); 54 } 55 LogicalPreferenceGroup(Context context, AttributeSet attrs)56 public LogicalPreferenceGroup(Context context, AttributeSet attrs) { 57 this(context, attrs, 0); 58 } 59 LogicalPreferenceGroup(Context context)60 public LogicalPreferenceGroup(Context context) { 61 this(context, null); 62 } 63 64 @Override addPreference(Preference preference)65 public boolean addPreference(Preference preference) { 66 if (!mShouldShowChevron && (preference instanceof CarUiPreference 67 || preference instanceof CarUiEditTextPreference)) { 68 ((CarUiPreference) preference).setShowChevron(false); 69 } 70 return super.addPreference(preference); 71 } 72 } 73