|
| 1 | +// Copyright 2019 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.google.android.ads.nativetemplates; |
| 16 | + |
| 17 | +import android.graphics.Typeface; |
| 18 | +import android.graphics.drawable.ColorDrawable; |
| 19 | +import androidx.annotation.Nullable; |
| 20 | +import com.google.errorprone.annotations.CanIgnoreReturnValue; |
| 21 | + |
| 22 | +/** A class containing the optional styling options for the Native Template. */ |
| 23 | +public class NativeTemplateStyle { |
| 24 | + |
| 25 | + // Call to action typeface. |
| 26 | + private Typeface callToActionTextTypeface; |
| 27 | + |
| 28 | + // Size of call to action text. |
| 29 | + private float callToActionTextSize; |
| 30 | + |
| 31 | + // Call to action typeface color in the form 0xAARRGGBB. |
| 32 | + @Nullable private Integer callToActionTypefaceColor; |
| 33 | + |
| 34 | + // Call to action background color. |
| 35 | + private ColorDrawable callToActionBackgroundColor; |
| 36 | + |
| 37 | + // All templates have a primary text area which is populated by the native ad's headline. |
| 38 | + |
| 39 | + // Primary text typeface. |
| 40 | + private Typeface primaryTextTypeface; |
| 41 | + |
| 42 | + // Size of primary text. |
| 43 | + private float primaryTextSize; |
| 44 | + |
| 45 | + // Primary text typeface color in the form 0xAARRGGBB. |
| 46 | + @Nullable private Integer primaryTextTypefaceColor; |
| 47 | + |
| 48 | + // Primary text background color. |
| 49 | + private ColorDrawable primaryTextBackgroundColor; |
| 50 | + |
| 51 | + // The typeface, typeface color, and background color for the second row of text in the template. |
| 52 | + // All templates have a secondary text area which is populated either by the body of the ad or |
| 53 | + // by the rating of the app. |
| 54 | + |
| 55 | + // Secondary text typeface. |
| 56 | + private Typeface secondaryTextTypeface; |
| 57 | + |
| 58 | + // Size of secondary text. |
| 59 | + private float secondaryTextSize; |
| 60 | + |
| 61 | + // Secondary text typeface color in the form 0xAARRGGBB. |
| 62 | + @Nullable private Integer secondaryTextTypefaceColor; |
| 63 | + |
| 64 | + // Secondary text background color. |
| 65 | + private ColorDrawable secondaryTextBackgroundColor; |
| 66 | + |
| 67 | + // The typeface, typeface color, and background color for the third row of text in the template. |
| 68 | + // The third row is used to display store name or the default tertiary text. |
| 69 | + |
| 70 | + // Tertiary text typeface. |
| 71 | + private Typeface tertiaryTextTypeface; |
| 72 | + |
| 73 | + // Size of tertiary text. |
| 74 | + private float tertiaryTextSize; |
| 75 | + |
| 76 | + // Tertiary text typeface color in the form 0xAARRGGBB. |
| 77 | + @Nullable private Integer tertiaryTextTypefaceColor; |
| 78 | + |
| 79 | + // Tertiary text background color. |
| 80 | + private ColorDrawable tertiaryTextBackgroundColor; |
| 81 | + |
| 82 | + // The background color for the bulk of the ad. |
| 83 | + private ColorDrawable mainBackgroundColor; |
| 84 | + |
| 85 | + public Typeface getCallToActionTextTypeface() { |
| 86 | + return callToActionTextTypeface; |
| 87 | + } |
| 88 | + |
| 89 | + public float getCallToActionTextSize() { |
| 90 | + return callToActionTextSize; |
| 91 | + } |
| 92 | + |
| 93 | + @Nullable |
| 94 | + public Integer getCallToActionTypefaceColor() { |
| 95 | + return callToActionTypefaceColor; |
| 96 | + } |
| 97 | + |
| 98 | + public ColorDrawable getCallToActionBackgroundColor() { |
| 99 | + return callToActionBackgroundColor; |
| 100 | + } |
| 101 | + |
| 102 | + public Typeface getPrimaryTextTypeface() { |
| 103 | + return primaryTextTypeface; |
| 104 | + } |
| 105 | + |
| 106 | + public float getPrimaryTextSize() { |
| 107 | + return primaryTextSize; |
| 108 | + } |
| 109 | + |
| 110 | + @Nullable |
| 111 | + public Integer getPrimaryTextTypefaceColor() { |
| 112 | + return primaryTextTypefaceColor; |
| 113 | + } |
| 114 | + |
| 115 | + public ColorDrawable getPrimaryTextBackgroundColor() { |
| 116 | + return primaryTextBackgroundColor; |
| 117 | + } |
| 118 | + |
| 119 | + public Typeface getSecondaryTextTypeface() { |
| 120 | + return secondaryTextTypeface; |
| 121 | + } |
| 122 | + |
| 123 | + public float getSecondaryTextSize() { |
| 124 | + return secondaryTextSize; |
| 125 | + } |
| 126 | + |
| 127 | + @Nullable |
| 128 | + public Integer getSecondaryTextTypefaceColor() { |
| 129 | + return secondaryTextTypefaceColor; |
| 130 | + } |
| 131 | + |
| 132 | + public ColorDrawable getSecondaryTextBackgroundColor() { |
| 133 | + return secondaryTextBackgroundColor; |
| 134 | + } |
| 135 | + |
| 136 | + public Typeface getTertiaryTextTypeface() { |
| 137 | + return tertiaryTextTypeface; |
| 138 | + } |
| 139 | + |
| 140 | + public float getTertiaryTextSize() { |
| 141 | + return tertiaryTextSize; |
| 142 | + } |
| 143 | + |
| 144 | + @Nullable |
| 145 | + public Integer getTertiaryTextTypefaceColor() { |
| 146 | + return tertiaryTextTypefaceColor; |
| 147 | + } |
| 148 | + |
| 149 | + public ColorDrawable getTertiaryTextBackgroundColor() { |
| 150 | + return tertiaryTextBackgroundColor; |
| 151 | + } |
| 152 | + |
| 153 | + public ColorDrawable getMainBackgroundColor() { |
| 154 | + return mainBackgroundColor; |
| 155 | + } |
| 156 | + |
| 157 | + /** A class that provides helper methods to build a style object. */ |
| 158 | + public static class Builder { |
| 159 | + |
| 160 | + private NativeTemplateStyle styles; |
| 161 | + |
| 162 | + public Builder() { |
| 163 | + this.styles = new NativeTemplateStyle(); |
| 164 | + } |
| 165 | + |
| 166 | + @CanIgnoreReturnValue |
| 167 | + public Builder withCallToActionTextTypeface(Typeface callToActionTextTypeface) { |
| 168 | + this.styles.callToActionTextTypeface = callToActionTextTypeface; |
| 169 | + return this; |
| 170 | + } |
| 171 | + |
| 172 | + @CanIgnoreReturnValue |
| 173 | + public Builder withCallToActionTextSize(float callToActionTextSize) { |
| 174 | + this.styles.callToActionTextSize = callToActionTextSize; |
| 175 | + return this; |
| 176 | + } |
| 177 | + |
| 178 | + @CanIgnoreReturnValue |
| 179 | + public Builder withCallToActionTypefaceColor(int callToActionTypefaceColor) { |
| 180 | + this.styles.callToActionTypefaceColor = callToActionTypefaceColor; |
| 181 | + return this; |
| 182 | + } |
| 183 | + |
| 184 | + @CanIgnoreReturnValue |
| 185 | + public Builder withCallToActionBackgroundColor(ColorDrawable callToActionBackgroundColor) { |
| 186 | + this.styles.callToActionBackgroundColor = callToActionBackgroundColor; |
| 187 | + return this; |
| 188 | + } |
| 189 | + |
| 190 | + @CanIgnoreReturnValue |
| 191 | + public Builder withPrimaryTextTypeface(Typeface primaryTextTypeface) { |
| 192 | + this.styles.primaryTextTypeface = primaryTextTypeface; |
| 193 | + return this; |
| 194 | + } |
| 195 | + |
| 196 | + @CanIgnoreReturnValue |
| 197 | + public Builder withPrimaryTextSize(float primaryTextSize) { |
| 198 | + this.styles.primaryTextSize = primaryTextSize; |
| 199 | + return this; |
| 200 | + } |
| 201 | + |
| 202 | + @CanIgnoreReturnValue |
| 203 | + public Builder withPrimaryTextTypefaceColor(int primaryTextTypefaceColor) { |
| 204 | + this.styles.primaryTextTypefaceColor = primaryTextTypefaceColor; |
| 205 | + return this; |
| 206 | + } |
| 207 | + |
| 208 | + @CanIgnoreReturnValue |
| 209 | + public Builder withPrimaryTextBackgroundColor(ColorDrawable primaryTextBackgroundColor) { |
| 210 | + this.styles.primaryTextBackgroundColor = primaryTextBackgroundColor; |
| 211 | + return this; |
| 212 | + } |
| 213 | + |
| 214 | + @CanIgnoreReturnValue |
| 215 | + public Builder withSecondaryTextTypeface(Typeface secondaryTextTypeface) { |
| 216 | + this.styles.secondaryTextTypeface = secondaryTextTypeface; |
| 217 | + return this; |
| 218 | + } |
| 219 | + |
| 220 | + @CanIgnoreReturnValue |
| 221 | + public Builder withSecondaryTextSize(float secondaryTextSize) { |
| 222 | + this.styles.secondaryTextSize = secondaryTextSize; |
| 223 | + return this; |
| 224 | + } |
| 225 | + |
| 226 | + @CanIgnoreReturnValue |
| 227 | + public Builder withSecondaryTextTypefaceColor(int secondaryTextTypefaceColor) { |
| 228 | + this.styles.secondaryTextTypefaceColor = secondaryTextTypefaceColor; |
| 229 | + return this; |
| 230 | + } |
| 231 | + |
| 232 | + @CanIgnoreReturnValue |
| 233 | + public Builder withSecondaryTextBackgroundColor(ColorDrawable secondaryTextBackgroundColor) { |
| 234 | + this.styles.secondaryTextBackgroundColor = secondaryTextBackgroundColor; |
| 235 | + return this; |
| 236 | + } |
| 237 | + |
| 238 | + @CanIgnoreReturnValue |
| 239 | + public Builder withTertiaryTextTypeface(Typeface tertiaryTextTypeface) { |
| 240 | + this.styles.tertiaryTextTypeface = tertiaryTextTypeface; |
| 241 | + return this; |
| 242 | + } |
| 243 | + |
| 244 | + @CanIgnoreReturnValue |
| 245 | + public Builder withTertiaryTextSize(float tertiaryTextSize) { |
| 246 | + this.styles.tertiaryTextSize = tertiaryTextSize; |
| 247 | + return this; |
| 248 | + } |
| 249 | + |
| 250 | + @CanIgnoreReturnValue |
| 251 | + public Builder withTertiaryTextTypefaceColor(int tertiaryTextTypefaceColor) { |
| 252 | + this.styles.tertiaryTextTypefaceColor = tertiaryTextTypefaceColor; |
| 253 | + return this; |
| 254 | + } |
| 255 | + |
| 256 | + @CanIgnoreReturnValue |
| 257 | + public Builder withTertiaryTextBackgroundColor(ColorDrawable tertiaryTextBackgroundColor) { |
| 258 | + this.styles.tertiaryTextBackgroundColor = tertiaryTextBackgroundColor; |
| 259 | + return this; |
| 260 | + } |
| 261 | + |
| 262 | + @CanIgnoreReturnValue |
| 263 | + public Builder withMainBackgroundColor(ColorDrawable mainBackgroundColor) { |
| 264 | + this.styles.mainBackgroundColor = mainBackgroundColor; |
| 265 | + return this; |
| 266 | + } |
| 267 | + |
| 268 | + public NativeTemplateStyle build() { |
| 269 | + return styles; |
| 270 | + } |
| 271 | + } |
| 272 | +} |
0 commit comments