• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.os.Bundle;
22 
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Objects;
27 
28 /**
29  * This class represents a page of {@link SearchResult}s
30  *
31  * @hide
32  */
33 public class SearchResultPage {
34     public static final String RESULTS_FIELD = "results";
35     public static final String NEXT_PAGE_TOKEN_FIELD = "nextPageToken";
36     private final long mNextPageToken;
37 
38     @Nullable private List<SearchResult> mResults;
39 
40     @NonNull private final Bundle mBundle;
41 
SearchResultPage(@onNull Bundle bundle)42     public SearchResultPage(@NonNull Bundle bundle) {
43         mBundle = Objects.requireNonNull(bundle);
44         mNextPageToken = mBundle.getLong(NEXT_PAGE_TOKEN_FIELD);
45     }
46 
47     /** Returns the {@link Bundle} of this class. */
48     @NonNull
getBundle()49     public Bundle getBundle() {
50         return mBundle;
51     }
52 
53     /** Returns the Token to get next {@link SearchResultPage}. */
getNextPageToken()54     public long getNextPageToken() {
55         return mNextPageToken;
56     }
57 
58     /** Returns all {@link android.app.appsearch.SearchResult}s of this page */
59     @NonNull
getResults()60     public List<SearchResult> getResults() {
61         if (mResults == null) {
62             ArrayList<Bundle> resultBundles = mBundle.getParcelableArrayList(RESULTS_FIELD);
63             if (resultBundles == null) {
64                 mResults = Collections.emptyList();
65             } else {
66                 mResults = new ArrayList<>(resultBundles.size());
67                 for (int i = 0; i < resultBundles.size(); i++) {
68                     mResults.add(new SearchResult(resultBundles.get(i)));
69                 }
70             }
71         }
72         return mResults;
73     }
74 }
75