1 /* 2 * Copyright 2020 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.app.appsearch; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.app.appsearch.safeparcel.AbstractSafeParcelable; 22 import android.app.appsearch.safeparcel.SafeParcelable; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import java.util.Collections; 27 import java.util.List; 28 29 /** 30 * This class represents a page of {@link SearchResult}s 31 * 32 * @hide 33 */ 34 @SafeParcelable.Class(creator = "SearchResultPageCreator") 35 public class SearchResultPage extends AbstractSafeParcelable { 36 @NonNull 37 public static final Parcelable.Creator<SearchResultPage> CREATOR = 38 new SearchResultPageCreator(); 39 40 @Field(id = 1, getter = "getNextPageToken") 41 private final long mNextPageToken; 42 43 @Nullable 44 @Field(id = 2, getter = "getResults") 45 private final List<SearchResult> mResults; 46 47 @Constructor SearchResultPage( @aramid = 1) long nextPageToken, @Param(id = 2) @Nullable List<SearchResult> results)48 public SearchResultPage( 49 @Param(id = 1) long nextPageToken, 50 @Param(id = 2) @Nullable List<SearchResult> results) { 51 mNextPageToken = nextPageToken; 52 mResults = results; 53 } 54 55 /** Default constructor for {@link SearchResultPage}. */ SearchResultPage()56 public SearchResultPage() { 57 mNextPageToken = 0; 58 mResults = Collections.emptyList(); 59 } 60 61 /** Returns the Token to get next {@link SearchResultPage}. */ getNextPageToken()62 public long getNextPageToken() { 63 return mNextPageToken; 64 } 65 66 /** Returns all {@link android.app.appsearch.SearchResult}s of this page */ 67 @NonNull getResults()68 public List<SearchResult> getResults() { 69 if (mResults == null) { 70 return Collections.emptyList(); 71 } 72 return mResults; 73 } 74 75 @Override writeToParcel(@onNull Parcel dest, int flags)76 public void writeToParcel(@NonNull Parcel dest, int flags) { 77 SearchResultPageCreator.writeToParcel(this, dest, flags); 78 } 79 } 80