1 /* 2 * Copyright (C) 2015 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.content.Context; 20 import android.util.AttributeSet; 21 import android.view.View; 22 import android.widget.FrameLayout; 23 import android.widget.TextView; 24 import com.google.android.setupcompat.PartnerCustomizationLayout; 25 import com.google.android.setupdesign.GlifLayout; 26 import com.google.android.setupdesign.R; 27 import com.google.android.setupdesign.util.DescriptionStyler; 28 29 /** 30 * Definition of an item in an {@link ItemHierarchy}. An item is usually defined in XML and inflated 31 * using {@link ItemInflater}. 32 * 33 * @deprecated Use {@link com.google.android.setupdesign.template.DescriptionMixin} instead. 34 */ 35 @Deprecated 36 public class DescriptionItem extends Item { 37 38 private boolean partnerDescriptionHeavyStyle = false; 39 private boolean partnerDescriptionLightStyle = false; 40 DescriptionItem()41 public DescriptionItem() { 42 super(); 43 } 44 DescriptionItem(Context context, AttributeSet attrs)45 public DescriptionItem(Context context, AttributeSet attrs) { 46 super(context, attrs); 47 } 48 49 /** 50 * Returns true if the description of partner's layout should apply heavy style, this depends on 51 * if the layout fulfill conditions in {@code applyPartnerHeavyThemeResource} of {@link 52 * com.google.android.setupdesign.GlifLayout} 53 */ shouldApplyPartnerDescriptionHeavyStyle()54 public boolean shouldApplyPartnerDescriptionHeavyStyle() { 55 return partnerDescriptionHeavyStyle; 56 } 57 58 /** 59 * Returns true if the description of partner's layout should apply light style, this depends on 60 * if the layout fulfill conditions in {@code shouldApplyPartnerResource} of {@link 61 * com.google.android.setupcompat.PartnerCustomizationLayout} 62 */ shouldApplyPartnerDescriptionLightStyle()63 public boolean shouldApplyPartnerDescriptionLightStyle() { 64 return partnerDescriptionLightStyle; 65 } 66 67 /** 68 * Applies partner description style on the title of the item, i.e. the TextView with {@code 69 * R.id.sud_items_title}. 70 * 71 * @param layout A layout indicates if the description of partner's layout should apply heavy or 72 * light style 73 */ setPartnerDescriptionStyle(FrameLayout layout)74 public void setPartnerDescriptionStyle(FrameLayout layout) { 75 if (layout instanceof GlifLayout) { 76 this.partnerDescriptionHeavyStyle = 77 ((GlifLayout) layout).shouldApplyPartnerHeavyThemeResource(); 78 } 79 if (layout instanceof PartnerCustomizationLayout) { 80 this.partnerDescriptionLightStyle = 81 ((PartnerCustomizationLayout) layout).shouldApplyPartnerResource(); 82 } 83 notifyItemChanged(); 84 } 85 86 @Override onBindView(View view)87 public void onBindView(View view) { 88 super.onBindView(view); 89 TextView label = (TextView) view.findViewById(R.id.sud_items_title); 90 if (shouldApplyPartnerDescriptionHeavyStyle()) { 91 DescriptionStyler.applyPartnerCustomizationHeavyStyle(label); 92 } else if (shouldApplyPartnerDescriptionLightStyle()) { 93 DescriptionStyler.applyPartnerCustomizationLightStyle(label); 94 } 95 } 96 } 97