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 /** 24 * A wrapper describing the contents of an education screen. 25 */ 26 final class TransitionScreenWrapper { 27 public final @StringRes int header; 28 public final @StringRes int description; 29 public final @RawRes int drawable; 30 public final @StringRes int subHeaderTitle; 31 public final @StringRes int subHeader; 32 public final @DrawableRes int subHeaderIcon; 33 public final boolean shouldLoop; 34 public final @StringRes int secondarySubHeaderTitle; 35 public final @StringRes int secondarySubHeader; 36 public final @DrawableRes int secondarySubHeaderIcon; 37 TransitionScreenWrapper(@tringRes int header, @RawRes int drawable)38 TransitionScreenWrapper(@StringRes int header, @RawRes int drawable) { 39 this(header, /* description= */ 0, drawable, /* shouldLoop */ true); 40 } 41 TransitionScreenWrapper(@tringRes int header, @StringRes int description, @RawRes int drawable, boolean shouldLoop)42 TransitionScreenWrapper(@StringRes int header, @StringRes int description, 43 @RawRes int drawable, boolean shouldLoop) { 44 this(header, /* description= */ description, drawable, 0, 0, 0, shouldLoop, 0, 0, 0); 45 } 46 TransitionScreenWrapper(int header, int description, int drawable, int subHeaderTitle, int subHeader, int subHeaderIcon, boolean shouldLoop, int secondarySubHeaderTitle, int secondarySubHeader, int secondarySubHeaderIcon)47 private TransitionScreenWrapper(int header, int description, int drawable, int subHeaderTitle, 48 int subHeader, int subHeaderIcon, boolean shouldLoop, 49 int secondarySubHeaderTitle, int secondarySubHeader, int secondarySubHeaderIcon) { 50 this.header = header; 51 this.description = description; 52 this.drawable = drawable; 53 this.subHeaderTitle = subHeaderTitle; 54 this.subHeader = subHeader; 55 this.subHeaderIcon = subHeaderIcon; 56 this.shouldLoop = shouldLoop; 57 this.secondarySubHeaderTitle = secondarySubHeaderTitle; 58 this.secondarySubHeader = secondarySubHeader; 59 this.secondarySubHeaderIcon = secondarySubHeaderIcon; 60 61 validateFields(); 62 } 63 validateFields()64 private void validateFields() { 65 final boolean isItemProvided = 66 subHeader != 0 67 || subHeaderIcon != 0 68 || subHeaderTitle != 0 69 || secondarySubHeader != 0 70 || secondarySubHeaderIcon != 0 71 || secondarySubHeaderTitle != 0; 72 if (isItemProvided && drawable != 0) { 73 throw new IllegalArgumentException( 74 "Cannot show items and animation at the same time."); 75 } 76 if (header == 0) { 77 throw new IllegalArgumentException("Header resource id must be a positive number."); 78 } 79 } 80 81 public static final class Builder { 82 @StringRes int mHeader; 83 @StringRes int mDescription; 84 @RawRes int mDrawable; 85 @StringRes private int mSubHeaderTitle; 86 @StringRes int mSubHeader; 87 @DrawableRes int mSubHeaderIcon; 88 boolean mShouldLoop; 89 @StringRes int mSecondarySubHeaderTitle; 90 @StringRes int mSecondarySubHeader; 91 @DrawableRes int mSecondarySubHeaderIcon; 92 setHeader(int header)93 public Builder setHeader(int header) { 94 mHeader = header; 95 return this; 96 } 97 setDescription(int description)98 public Builder setDescription(int description) { 99 mDescription = description; 100 return this; 101 } 102 setAnimation(int drawable)103 public Builder setAnimation(int drawable) { 104 mDrawable = drawable; 105 return this; 106 } 107 setSubHeaderTitle(int subHeaderTitle)108 public Builder setSubHeaderTitle(int subHeaderTitle) { 109 mSubHeaderTitle = subHeaderTitle; 110 return this; 111 } 112 setSubHeader(int subHeader)113 public Builder setSubHeader(int subHeader) { 114 mSubHeader = subHeader; 115 return this; 116 } 117 setSubHeaderIcon(int subHeaderIcon)118 public Builder setSubHeaderIcon(int subHeaderIcon) { 119 mSubHeaderIcon = subHeaderIcon; 120 return this; 121 } 122 setShouldLoop(boolean shouldLoop)123 public Builder setShouldLoop(boolean shouldLoop) { 124 mShouldLoop = shouldLoop; 125 return this; 126 } 127 setSecondarySubHeaderTitle(int secondarySubHeaderTitle)128 public Builder setSecondarySubHeaderTitle(int secondarySubHeaderTitle) { 129 mSecondarySubHeaderTitle = secondarySubHeaderTitle; 130 return this; 131 } 132 setSecondarySubHeader(int secondarySubHeader)133 public Builder setSecondarySubHeader(int secondarySubHeader) { 134 mSecondarySubHeader = secondarySubHeader; 135 return this; 136 } 137 setSecondarySubHeaderIcon(int secondarySubHeaderIcon)138 public Builder setSecondarySubHeaderIcon(int secondarySubHeaderIcon) { 139 mSecondarySubHeaderIcon = secondarySubHeaderIcon; 140 return this; 141 } 142 build()143 public TransitionScreenWrapper build() { 144 return new TransitionScreenWrapper(mHeader, mDescription, mDrawable, mSubHeaderTitle, 145 mSubHeader, mSubHeaderIcon, mShouldLoop, mSecondarySubHeaderTitle, 146 mSecondarySubHeader, mSecondarySubHeaderIcon); 147 } 148 } 149 } 150