1 /*
2  * Copyright (C) 2018 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.contentsuggestions;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.os.Bundle;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.util.List;
27 
28 /**
29  * Request object used when asking {@link ContentSuggestionsManager} to classify content selections.
30  *
31  * <p>The request contains a list of {@link ContentSelection} objects to be classified along with
32  * implementation specific extras.
33  *
34  * @hide
35  */
36 @SystemApi
37 public final class ClassificationsRequest implements Parcelable {
38     @NonNull
39     private final List<ContentSelection> mSelections;
40     @Nullable
41     private final Bundle mExtras;
42 
ClassificationsRequest(@onNull List<ContentSelection> selections, @Nullable Bundle extras)43     private ClassificationsRequest(@NonNull List<ContentSelection> selections,
44             @Nullable Bundle extras) {
45         mSelections = selections;
46         mExtras = extras;
47     }
48 
49     /**
50      * Return request selections.
51      */
getSelections()52     public @NonNull List<ContentSelection> getSelections() {
53         return mSelections;
54     }
55 
56     /**
57      * Return the request extras, can be an empty bundle.
58      */
getExtras()59     public @NonNull Bundle getExtras() {
60         return mExtras == null ? new Bundle() : mExtras;
61     }
62 
63     @Override
describeContents()64     public int describeContents() {
65         return 0;
66     }
67 
68     @Override
writeToParcel(Parcel dest, int flags)69     public void writeToParcel(Parcel dest, int flags) {
70         dest.writeTypedList(mSelections);
71         dest.writeBundle(mExtras);
72     }
73 
74     public static final @android.annotation.NonNull Creator<ClassificationsRequest> CREATOR =
75             new Creator<ClassificationsRequest>() {
76         @Override
77         public ClassificationsRequest createFromParcel(Parcel source) {
78             return new ClassificationsRequest(
79                     source.createTypedArrayList(ContentSelection.CREATOR),
80                     source.readBundle());
81         }
82 
83         @Override
84         public ClassificationsRequest[] newArray(int size) {
85             return new ClassificationsRequest[size];
86         }
87     };
88 
89     /**
90      * A builder for classifications request events.
91      * @hide
92      */
93     @SystemApi
94     public static final class Builder {
95 
96         private final List<ContentSelection> mSelections;
97         private Bundle mExtras;
98 
Builder(@onNull List<ContentSelection> selections)99         public Builder(@NonNull List<ContentSelection> selections) {
100             mSelections = selections;
101         }
102 
103         /**
104          * Sets the request extras.
105          */
setExtras(@onNull Bundle extras)106         public @NonNull Builder setExtras(@NonNull Bundle extras) {
107             mExtras = extras;
108             return this;
109         }
110 
111         /**
112          * Builds a new request instance.
113          */
build()114         public @NonNull ClassificationsRequest build() {
115             return new ClassificationsRequest(mSelections, mExtras);
116         }
117     }
118 }
119