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.content; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.graphics.pdf.flags.Flags; 22 import android.graphics.pdf.utils.Preconditions; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 /** 27 * <p> 28 * Represents the content associated with an image type in a page of a PDF document. 29 */ 30 @FlaggedApi(Flags.FLAG_ENABLE_PDF_VIEWER) 31 public final class PdfPageImageContent implements Parcelable { 32 @NonNull 33 public static final Creator<PdfPageImageContent> CREATOR = new Creator<PdfPageImageContent>() { 34 @Override 35 public PdfPageImageContent createFromParcel(Parcel in) { 36 return new PdfPageImageContent(in); 37 } 38 39 @Override 40 public PdfPageImageContent[] newArray(int size) { 41 return new PdfPageImageContent[size]; 42 } 43 }; 44 private final String mAltText; 45 46 /** 47 * Creates a new instance of {@link PdfPageImageContent} using the alternate text of the image 48 * on the page. 49 * 50 * @param altText Alternate text for the image. 51 * @throws NullPointerException If the alternate text is null. 52 */ PdfPageImageContent(@onNull String altText)53 public PdfPageImageContent(@NonNull String altText) { 54 Preconditions.checkNotNull(altText, "Alternate text cannot be null"); 55 this.mAltText = altText; 56 } 57 PdfPageImageContent(Parcel in)58 private PdfPageImageContent(Parcel in) { 59 mAltText = in.readString(); 60 } 61 62 /** 63 * Gets the alternate text associated with the image represented by this instance. If there 64 * is no such text associated with the image, the method will return an empty string. 65 * 66 * @return the alternate text of the image. 67 */ 68 @NonNull getAltText()69 public String getAltText() { 70 return mAltText; 71 } 72 73 @Override describeContents()74 public int describeContents() { 75 return 0; 76 } 77 78 @Override writeToParcel(@ndroidx.annotation.NonNull Parcel dest, int flags)79 public void writeToParcel(@androidx.annotation.NonNull Parcel dest, int flags) { 80 dest.writeString(mAltText); 81 } 82 } 83