1 /* 2 * Copyright (C) 2024 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.google.android.setupdesign.items; 18 19 import android.view.View; 20 import android.widget.TextView; 21 import com.google.android.setupdesign.R; 22 23 /** A section header item that represents a default style or bluechip styles. */ 24 public class SectionHeaderItem extends Item implements Dividable { 25 SectionHeaderItem()26 public SectionHeaderItem() {} 27 28 // dereference of possibly-null reference params 29 @SuppressWarnings("nullness:dereference.of.nullable") 30 @Override onBindView(View view)31 public void onBindView(View view) { 32 TextView label = (TextView) view.findViewById(R.id.sud_items_title); 33 label.setText(getTitle()); 34 TextView summaryView = (TextView) view.findViewById(R.id.sud_items_summary); 35 CharSequence summary = getSummary(); 36 if (hasSummary(summary)) { 37 summaryView.setText(summary); 38 summaryView.setVisibility(View.VISIBLE); 39 } else { 40 summaryView.setVisibility(View.GONE); 41 } 42 view.setId(getViewId()); 43 view.findViewById(R.id.sud_items_icon_container).setVisibility(View.GONE); 44 view.setContentDescription(getContentDescription()); 45 view.setClickable(/* clickable= */ false); 46 } 47 hasSummary(CharSequence summary)48 private boolean hasSummary(CharSequence summary) { 49 return summary != null && summary.length() > 0; 50 } 51 52 @Override getDefaultLayoutResource()53 protected int getDefaultLayoutResource() { 54 return R.layout.sud_items_section_header; 55 } 56 57 @Override isDividerAllowedAbove()58 public boolean isDividerAllowedAbove() { 59 // Keep hiding the divide behavior when we set enable as true to prevent talkback speaks 60 // "disabled" for header item. 61 return false; 62 } 63 64 @Override isDividerAllowedBelow()65 public boolean isDividerAllowedBelow() { 66 // Keep hiding the divide behavior when we set enable as true to prevent talkback speaks 67 // "disabled" for header item. 68 return false; 69 } 70 71 @Override isGroupDivider()72 public boolean isGroupDivider() { 73 return true; 74 } 75 } 76