• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.settings.homepage.contextualcards.conditional;
18 
19 import androidx.annotation.VisibleForTesting;
20 
21 import com.android.settings.homepage.contextualcards.ContextualCard;
22 
23 /**
24  * Data class representing a conditional {@link ContextualCard}.
25  *
26  * Use this class to store additional attributes on top of {@link ContextualCard} for
27  * {@link ConditionalCardController}.
28  */
29 public class ConditionalContextualCard extends ContextualCard {
30 
31     @VisibleForTesting
32     static final double UNSUPPORTED_RANKING_SCORE = -100.0;
33 
34     private final long mConditionId;
35     private final int mMetricsConstant;
36     private final CharSequence mActionText;
37 
ConditionalContextualCard(Builder builder)38     private ConditionalContextualCard(Builder builder) {
39         super(builder);
40 
41         mConditionId = builder.mConditionId;
42         mMetricsConstant = builder.mMetricsConstant;
43         mActionText = builder.mActionText;
44     }
45 
46     @Override
getCardType()47     public int getCardType() {
48         return CardType.CONDITIONAL;
49     }
50 
getConditionId()51     public long getConditionId() {
52         return mConditionId;
53     }
54 
getMetricsConstant()55     public int getMetricsConstant() {
56         return mMetricsConstant;
57     }
58 
getActionText()59     public CharSequence getActionText() {
60         return mActionText;
61     }
62 
63     public static class Builder extends ContextualCard.Builder {
64 
65         private long mConditionId;
66         private int mMetricsConstant;
67         private CharSequence mActionText;
68 
setConditionId(long id)69         public Builder setConditionId(long id) {
70             mConditionId = id;
71             return this;
72         }
73 
setMetricsConstant(int metricsConstant)74         public Builder setMetricsConstant(int metricsConstant) {
75             mMetricsConstant = metricsConstant;
76             return this;
77         }
78 
setActionText(CharSequence actionText)79         public Builder setActionText(CharSequence actionText) {
80             mActionText = actionText;
81             return this;
82         }
83 
84         @Override
setCardType(int cardType)85         public Builder setCardType(int cardType) {
86             throw new IllegalArgumentException(
87                     "Cannot change card type for " + getClass().getName());
88         }
89 
build()90         public ConditionalContextualCard build() {
91             setRankingScore(UNSUPPORTED_RANKING_SCORE);
92             return new ConditionalContextualCard(this);
93         }
94     }
95 }