blob: 9bb39e5991352a4ea1f2355802fb959cf2c802e8 [file] [log] [blame]
Winson Chung3fb0f252019-01-08 17:41:55 -08001/*
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
17package android.app.contentsuggestions;
18
19import android.annotation.NonNull;
20import android.annotation.Nullable;
21import android.annotation.SystemApi;
22import android.os.Bundle;
23import android.os.Parcel;
24import android.os.Parcelable;
25
26import java.util.List;
27
28/**
Zak Cohenb399c842019-01-18 14:36:55 -080029 * 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 *
Winson Chung3fb0f252019-01-08 17:41:55 -080034 * @hide
35 */
36@SystemApi
37public final class ClassificationsRequest implements Parcelable {
38 @NonNull
39 private final List<ContentSelection> mSelections;
40 @Nullable
41 private final Bundle mExtras;
42
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 */
Zak Cohenb399c842019-01-18 14:36:55 -080052 public @NonNull List<ContentSelection> getSelections() {
Winson Chung3fb0f252019-01-08 17:41:55 -080053 return mSelections;
54 }
55
56 /**
Zak Cohenb399c842019-01-18 14:36:55 -080057 * Return the request extras or {@code null} if there are none.
Winson Chung3fb0f252019-01-08 17:41:55 -080058 */
Zak Cohenb399c842019-01-18 14:36:55 -080059 public @Nullable Bundle getExtras() {
Winson Chung3fb0f252019-01-08 17:41:55 -080060 return mExtras;
61 }
62
63 @Override
64 public int describeContents() {
65 return 0;
66 }
67
68 @Override
69 public void writeToParcel(Parcel dest, int flags) {
70 dest.writeTypedList(mSelections);
71 dest.writeBundle(mExtras);
72 }
73
74 public static final 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
99 public Builder(@NonNull List<ContentSelection> selections) {
100 mSelections = selections;
101 }
102
103 /**
104 * Sets the request extras.
105 */
106 public Builder setExtras(@NonNull Bundle extras) {
107 mExtras = extras;
108 return this;
109 }
110
111 /**
112 * Builds a new request instance.
113 */
114 public ClassificationsRequest build() {
115 return new ClassificationsRequest(mSelections, mExtras);
116 }
117 }
118}