blob: 2051a55e1c2f6e8a2e438352cd31e44abc782b6d [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 Cohenc0fe5672019-03-01 14:06:26 -080057 * Return the request extras, can be an empty bundle.
Winson Chung3fb0f252019-01-08 17:41:55 -080058 */
Zak Cohenc0fe5672019-03-01 14:06:26 -080059 public @NonNull Bundle getExtras() {
60 return mExtras == null ? new Bundle() : mExtras;
Winson Chung3fb0f252019-01-08 17:41:55 -080061 }
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
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070074 public static final @android.annotation.NonNull Creator<ClassificationsRequest> CREATOR =
Winson Chung3fb0f252019-01-08 17:41:55 -080075 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 */
Zak Cohend61093e2019-03-01 11:18:47 -0800106 public @NonNull Builder setExtras(@NonNull Bundle extras) {
Winson Chung3fb0f252019-01-08 17:41:55 -0800107 mExtras = extras;
108 return this;
109 }
110
111 /**
112 * Builds a new request instance.
113 */
Zak Cohend61093e2019-03-01 11:18:47 -0800114 public @NonNull ClassificationsRequest build() {
Winson Chung3fb0f252019-01-08 17:41:55 -0800115 return new ClassificationsRequest(mSelections, mExtras);
116 }
117 }
118}