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 TransitionScreenWrapper( LazyStringResource header, LazyStringResource description, @RawRes int drawable, boolean shouldLoop)49 TransitionScreenWrapper( 50 LazyStringResource header, 51 LazyStringResource description, 52 @RawRes int drawable, 53 boolean shouldLoop) { 54 this( 55 header, 56 description, 57 drawable, 58 /* subHeaderTitle= */ Empty.INSTANCE, 59 /* subHeader= */ Empty.INSTANCE, 60 /* subHeaderIcon= */ 0, 61 shouldLoop, 62 /* secondarySubHeaderTitle= */ Empty.INSTANCE, 63 /* secondarySubHeader= */ Empty.INSTANCE, 64 /* secondarySubHeaderIcon= */ 0); 65 } 66 TransitionScreenWrapper( @tringRes int headerId, @StringRes int descriptionId, @RawRes int drawable, boolean shouldLoop)67 TransitionScreenWrapper( 68 @StringRes int headerId, 69 @StringRes int descriptionId, 70 @RawRes int drawable, 71 boolean shouldLoop) { 72 this(LazyStringResource.of(headerId), LazyStringResource.of(descriptionId), 73 drawable, shouldLoop); 74 } 75 TransitionScreenWrapper( LazyStringResource header, LazyStringResource description, int drawable, LazyStringResource subHeaderTitle, LazyStringResource subHeader, int subHeaderIcon, boolean shouldLoop, LazyStringResource secondarySubHeaderTitle, LazyStringResource secondarySubHeader, int secondarySubHeaderIcon)76 private TransitionScreenWrapper( 77 LazyStringResource header, 78 LazyStringResource description, 79 int drawable, 80 LazyStringResource subHeaderTitle, 81 LazyStringResource subHeader, 82 int subHeaderIcon, 83 boolean shouldLoop, 84 LazyStringResource secondarySubHeaderTitle, 85 LazyStringResource secondarySubHeader, 86 int secondarySubHeaderIcon) { 87 this.header = header; 88 this.description = description; 89 this.drawable = drawable; 90 this.subHeaderTitle = subHeaderTitle; 91 this.subHeader = subHeader; 92 this.subHeaderIcon = subHeaderIcon; 93 this.shouldLoop = shouldLoop; 94 this.secondarySubHeaderTitle = secondarySubHeaderTitle; 95 this.secondarySubHeader = secondarySubHeader; 96 this.secondarySubHeaderIcon = secondarySubHeaderIcon; 97 98 validateFields(); 99 } 100 validateFields()101 private void validateFields() { 102 final boolean isItemProvided = 103 !(subHeader instanceof Empty) 104 || subHeaderIcon != 0 105 || !(subHeaderTitle instanceof Empty) 106 || !(secondarySubHeader instanceof Empty) 107 || secondarySubHeaderIcon != 0 108 || !(secondarySubHeaderTitle instanceof Empty); 109 if (isItemProvided && drawable != 0) { 110 throw new IllegalArgumentException("Cannot show items and animation at the same time."); 111 } 112 if (header instanceof Empty) { 113 throw new IllegalArgumentException("Header resource id must be a positive number."); 114 } 115 } 116 117 public static final class Builder { 118 private LazyStringResource mHeader = Empty.INSTANCE; 119 private LazyStringResource mDescription = Empty.INSTANCE; 120 @RawRes 121 private int mDrawable; 122 private LazyStringResource mSubHeaderTitle = Empty.INSTANCE; 123 private LazyStringResource mSubHeader = Empty.INSTANCE; 124 @DrawableRes 125 private int mSubHeaderIcon; 126 private boolean mShouldLoop; 127 private LazyStringResource mSecondarySubHeaderTitle = Empty.INSTANCE; 128 private LazyStringResource mSecondarySubHeader = Empty.INSTANCE; 129 @DrawableRes 130 private int mSecondarySubHeaderIcon; 131 setHeader(LazyStringResource header)132 public Builder setHeader(LazyStringResource header) { 133 this.mHeader = header; 134 return this; 135 } 136 setHeader(@tringRes int headerId)137 public Builder setHeader(@StringRes int headerId) { 138 return setHeader(LazyStringResource.of(headerId)); 139 } 140 setDescription(LazyStringResource description)141 public Builder setDescription(LazyStringResource description) { 142 this.mDescription = description; 143 return this; 144 } 145 setDescription(@tringRes int descriptionId)146 public Builder setDescription(@StringRes int descriptionId) { 147 return setDescription(LazyStringResource.of(descriptionId)); 148 } 149 setAnimation(int drawable)150 public Builder setAnimation(int drawable) { 151 this.mDrawable = drawable; 152 return this; 153 } 154 setSubHeaderTitle(LazyStringResource subHeaderTitle)155 public Builder setSubHeaderTitle(LazyStringResource subHeaderTitle) { 156 this.mSubHeaderTitle = subHeaderTitle; 157 return this; 158 } 159 setSubHeaderTitle(@tringRes int subHeaderTitleId)160 public Builder setSubHeaderTitle(@StringRes int subHeaderTitleId) { 161 return setSubHeaderTitle(LazyStringResource.of(subHeaderTitleId)); 162 } 163 setSubHeader(LazyStringResource subHeader)164 public Builder setSubHeader(LazyStringResource subHeader) { 165 this.mSubHeader = subHeader; 166 return this; 167 } 168 setSubHeader(@tringRes int subHeaderId)169 public Builder setSubHeader(@StringRes int subHeaderId) { 170 return setSubHeader(LazyStringResource.of(subHeaderId)); 171 } 172 setSubHeaderIcon(int subHeaderIcon)173 public Builder setSubHeaderIcon(int subHeaderIcon) { 174 this.mSubHeaderIcon = subHeaderIcon; 175 return this; 176 } 177 setShouldLoop(boolean shouldLoop)178 public Builder setShouldLoop(boolean shouldLoop) { 179 this.mShouldLoop = shouldLoop; 180 return this; 181 } 182 setSecondarySubHeaderTitle(LazyStringResource secondarySubHeaderTitle)183 public Builder setSecondarySubHeaderTitle(LazyStringResource secondarySubHeaderTitle) { 184 this.mSecondarySubHeaderTitle = secondarySubHeaderTitle; 185 return this; 186 } 187 setSecondarySubHeaderTitle(@tringRes int secondarySubHeaderTitleId)188 public Builder setSecondarySubHeaderTitle(@StringRes int secondarySubHeaderTitleId) { 189 return setSecondarySubHeaderTitle(LazyStringResource.of(secondarySubHeaderTitleId)); 190 } 191 setSecondarySubHeader(LazyStringResource secondarySubHeader)192 public Builder setSecondarySubHeader(LazyStringResource secondarySubHeader) { 193 this.mSecondarySubHeader = secondarySubHeader; 194 return this; 195 } 196 setSecondarySubHeader(@tringRes int secondarySubHeaderId)197 public Builder setSecondarySubHeader(@StringRes int secondarySubHeaderId) { 198 return setSecondarySubHeader(LazyStringResource.of(secondarySubHeaderId)); 199 } 200 setSecondarySubHeaderIcon(int secondarySubHeaderIcon)201 public Builder setSecondarySubHeaderIcon(int secondarySubHeaderIcon) { 202 this.mSecondarySubHeaderIcon = secondarySubHeaderIcon; 203 return this; 204 } 205 build()206 public TransitionScreenWrapper build() { 207 return new TransitionScreenWrapper( 208 mHeader, 209 mDescription, 210 mDrawable, 211 mSubHeaderTitle, 212 mSubHeader, 213 mSubHeaderIcon, 214 mShouldLoop, 215 mSecondarySubHeaderTitle, 216 mSecondarySubHeader, 217 mSecondarySubHeaderIcon); 218 } 219 } 220 } 221