1 /* 2 * Copyright (C) 2024 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 android.graphics.pdf; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.graphics.pdf.flags.Flags; 23 24 /** 25 * Represents a set of parameters to load the PDF document. 26 */ 27 @FlaggedApi(Flags.FLAG_ENABLE_PDF_VIEWER) 28 public final class LoadParams { 29 @Nullable 30 private final String mPassword; 31 LoadParams(String password)32 private LoadParams(String password) { 33 mPassword = password; 34 } 35 36 /** 37 * Gets the password for the loaded document. Returns {@code null} if not set. 38 * 39 * @return the password for the document. 40 */ 41 @Nullable getPassword()42 public String getPassword() { 43 return mPassword; 44 } 45 46 /** 47 * Builder for constructing {@link LoadParams}. 48 */ 49 public static final class Builder { 50 @Nullable 51 private String mPassword; 52 53 /** Constructor for builder to create {@link LoadParams}. */ Builder()54 public Builder() { 55 } 56 57 /** 58 * Sets the optional password for a protected PDF document. A {@code null} value will be 59 * treated as no password supplied or document is unprotected. 60 * 61 * @param password Password for the protected PDF document. 62 */ 63 @NonNull setPassword(@ullable String password)64 public Builder setPassword(@Nullable String password) { 65 mPassword = password; 66 return this; 67 } 68 69 /** 70 * Builds the {@link LoadParams} after the optional values has been set. 71 * 72 * @return new instance of {@link LoadParams} 73 */ 74 @NonNull build()75 public LoadParams build() { 76 return new LoadParams(mPassword); 77 } 78 } 79 } 80