1 /* 2 * Copyright (C) 2021 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.managedprovisioning.provisioning; 18 19 import android.annotation.DrawableRes; 20 import android.annotation.RawRes; 21 import android.annotation.StringRes; 22 23 import com.android.managedprovisioning.util.LazyStringResource; 24 import com.android.managedprovisioning.util.LazyStringResource.Empty; 25 26 /** 27 * A wrapper describing the contents of an education screen. 28 */ 29 final class TransitionScreenWrapper { 30 public final LazyStringResource header; 31 public final LazyStringResource description; 32 public final @RawRes int drawable; 33 public final LazyStringResource subHeaderTitle; 34 public final LazyStringResource subHeader; 35 public final @DrawableRes int subHeaderIcon; 36 public final boolean shouldLoop; 37 public final LazyStringResource secondarySubHeaderTitle; 38 public final LazyStringResource secondarySubHeader; 39 public final @DrawableRes int secondarySubHeaderIcon; 40 TransitionScreenWrapper(LazyStringResource header, @RawRes int drawable)41 TransitionScreenWrapper(LazyStringResource header, @RawRes int drawable) { 42 this(header, /* description= */ Empty.INSTANCE, drawable, /* shouldLoop= */ true); 43 } 44 TransitionScreenWrapper(@tringRes int headerId, @RawRes int drawable)45 TransitionScreenWrapper(@StringRes int headerId, @RawRes int drawable) { 46 this(LazyStringResource.of(headerId), drawable); 47 } 48 49 /** 50 * @param description will be ignored if glif expressive style is enabled 51 * since we repurpose the description field for the 52 * progress label. 53 */ TransitionScreenWrapper( LazyStringResource header, LazyStringResource description, @RawRes int drawable, boolean shouldLoop)54 TransitionScreenWrapper( 55 LazyStringResource header, 56 LazyStringResource description, 57 @RawRes int drawable, 58 boolean shouldLoop) { 59 this( 60 header, 61 description, 62 drawable, 63 /* subHeaderTitle= */ Empty.INSTANCE, 64 /* subHeader= */ Empty.INSTANCE, 65 /* subHeaderIcon= */ 0, 66 shouldLoop, 67 /* secondarySubHeaderTitle= */ Empty.INSTANCE, 68 /* secondarySubHeader= */ Empty.INSTANCE, 69 /* secondarySubHeaderIcon= */ 0); 70 } 71 72 /** 73 * @param descriptionId will be ignored if glif expressive style is enabled 74 * since we repurpose the description field for the 75 * progress label. 76 */ TransitionScreenWrapper( @tringRes int headerId, @StringRes int descriptionId, @RawRes int drawable, boolean shouldLoop)77 TransitionScreenWrapper( 78 @StringRes int headerId, 79 @StringRes int descriptionId, 80 @RawRes int drawable, 81 boolean shouldLoop) { 82 this(LazyStringResource.of(headerId), LazyStringResource.of(descriptionId), 83 drawable, shouldLoop); 84 } 85 TransitionScreenWrapper( LazyStringResource header, LazyStringResource description, int drawable, LazyStringResource subHeaderTitle, LazyStringResource subHeader, int subHeaderIcon, boolean shouldLoop, LazyStringResource secondarySubHeaderTitle, LazyStringResource secondarySubHeader, int secondarySubHeaderIcon)86 private TransitionScreenWrapper( 87 LazyStringResource header, 88 LazyStringResource description, 89 int drawable, 90 LazyStringResource subHeaderTitle, 91 LazyStringResource subHeader, 92 int subHeaderIcon, 93 boolean shouldLoop, 94 LazyStringResource secondarySubHeaderTitle, 95 LazyStringResource secondarySubHeader, 96 int secondarySubHeaderIcon) { 97 this.header = header; 98 this.description = description; 99 this.drawable = drawable; 100 this.subHeaderTitle = subHeaderTitle; 101 this.subHeader = subHeader; 102 this.subHeaderIcon = subHeaderIcon; 103 this.shouldLoop = shouldLoop; 104 this.secondarySubHeaderTitle = secondarySubHeaderTitle; 105 this.secondarySubHeader = secondarySubHeader; 106 this.secondarySubHeaderIcon = secondarySubHeaderIcon; 107 108 validateFields(); 109 } 110 validateFields()111 private void validateFields() { 112 final boolean isItemProvided = 113 !(subHeader instanceof Empty) 114 || subHeaderIcon != 0 115 || !(subHeaderTitle instanceof Empty) 116 || !(secondarySubHeader instanceof Empty) 117 || secondarySubHeaderIcon != 0 118 || !(secondarySubHeaderTitle instanceof Empty); 119 if (isItemProvided && drawable != 0) { 120 throw new IllegalArgumentException("Cannot show items and animation at the same time."); 121 } 122 if (header instanceof Empty) { 123 throw new IllegalArgumentException("Header resource id must be a positive number."); 124 } 125 } 126 127 public static final class Builder { 128 private LazyStringResource mHeader = Empty.INSTANCE; 129 private LazyStringResource mDescription = Empty.INSTANCE; 130 @RawRes 131 private int mDrawable; 132 private LazyStringResource mSubHeaderTitle = Empty.INSTANCE; 133 private LazyStringResource mSubHeader = Empty.INSTANCE; 134 @DrawableRes 135 private int mSubHeaderIcon; 136 private boolean mShouldLoop; 137 private LazyStringResource mSecondarySubHeaderTitle = Empty.INSTANCE; 138 private LazyStringResource mSecondarySubHeader = Empty.INSTANCE; 139 @DrawableRes 140 private int mSecondarySubHeaderIcon; 141 setHeader(LazyStringResource header)142 public Builder setHeader(LazyStringResource header) { 143 this.mHeader = header; 144 return this; 145 } 146 setHeader(@tringRes int headerId)147 public Builder setHeader(@StringRes int headerId) { 148 return setHeader(LazyStringResource.of(headerId)); 149 } 150 setDescription(LazyStringResource description)151 public Builder setDescription(LazyStringResource description) { 152 this.mDescription = description; 153 return this; 154 } 155 setDescription(@tringRes int descriptionId)156 public Builder setDescription(@StringRes int descriptionId) { 157 return setDescription(LazyStringResource.of(descriptionId)); 158 } 159 setAnimation(int drawable)160 public Builder setAnimation(int drawable) { 161 this.mDrawable = drawable; 162 return this; 163 } 164 setSubHeaderTitle(LazyStringResource subHeaderTitle)165 public Builder setSubHeaderTitle(LazyStringResource subHeaderTitle) { 166 this.mSubHeaderTitle = subHeaderTitle; 167 return this; 168 } 169 setSubHeaderTitle(@tringRes int subHeaderTitleId)170 public Builder setSubHeaderTitle(@StringRes int subHeaderTitleId) { 171 return setSubHeaderTitle(LazyStringResource.of(subHeaderTitleId)); 172 } 173 setSubHeader(LazyStringResource subHeader)174 public Builder setSubHeader(LazyStringResource subHeader) { 175 this.mSubHeader = subHeader; 176 return this; 177 } 178 setSubHeader(@tringRes int subHeaderId)179 public Builder setSubHeader(@StringRes int subHeaderId) { 180 return setSubHeader(LazyStringResource.of(subHeaderId)); 181 } 182 setSubHeaderIcon(int subHeaderIcon)183 public Builder setSubHeaderIcon(int subHeaderIcon) { 184 this.mSubHeaderIcon = subHeaderIcon; 185 return this; 186 } 187 setShouldLoop(boolean shouldLoop)188 public Builder setShouldLoop(boolean shouldLoop) { 189 this.mShouldLoop = shouldLoop; 190 return this; 191 } 192 setSecondarySubHeaderTitle(LazyStringResource secondarySubHeaderTitle)193 public Builder setSecondarySubHeaderTitle(LazyStringResource secondarySubHeaderTitle) { 194 this.mSecondarySubHeaderTitle = secondarySubHeaderTitle; 195 return this; 196 } 197 setSecondarySubHeaderTitle(@tringRes int secondarySubHeaderTitleId)198 public Builder setSecondarySubHeaderTitle(@StringRes int secondarySubHeaderTitleId) { 199 return setSecondarySubHeaderTitle(LazyStringResource.of(secondarySubHeaderTitleId)); 200 } 201 setSecondarySubHeader(LazyStringResource secondarySubHeader)202 public Builder setSecondarySubHeader(LazyStringResource secondarySubHeader) { 203 this.mSecondarySubHeader = secondarySubHeader; 204 return this; 205 } 206 setSecondarySubHeader(@tringRes int secondarySubHeaderId)207 public Builder setSecondarySubHeader(@StringRes int secondarySubHeaderId) { 208 return setSecondarySubHeader(LazyStringResource.of(secondarySubHeaderId)); 209 } 210 setSecondarySubHeaderIcon(int secondarySubHeaderIcon)211 public Builder setSecondarySubHeaderIcon(int secondarySubHeaderIcon) { 212 this.mSecondarySubHeaderIcon = secondarySubHeaderIcon; 213 return this; 214 } 215 build()216 public TransitionScreenWrapper build() { 217 return new TransitionScreenWrapper( 218 mHeader, 219 mDescription, 220 mDrawable, 221 mSubHeaderTitle, 222 mSubHeader, 223 mSubHeaderIcon, 224 mShouldLoop, 225 mSecondarySubHeaderTitle, 226 mSecondarySubHeader, 227 mSecondarySubHeaderIcon); 228 } 229 } 230 } 231