Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 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 | /** |
Zak Cohen | b399c84 | 2019-01-18 14:36:55 -0800 | [diff] [blame] | 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 | * |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 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 | |
| 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 Cohen | b399c84 | 2019-01-18 14:36:55 -0800 | [diff] [blame] | 52 | public @NonNull List<ContentSelection> getSelections() { |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 53 | return mSelections; |
| 54 | } |
| 55 | |
| 56 | /** |
Zak Cohen | c0fe567 | 2019-03-01 14:06:26 -0800 | [diff] [blame] | 57 | * Return the request extras, can be an empty bundle. |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 58 | */ |
Zak Cohen | c0fe567 | 2019-03-01 14:06:26 -0800 | [diff] [blame] | 59 | public @NonNull Bundle getExtras() { |
| 60 | return mExtras == null ? new Bundle() : mExtras; |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 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 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 74 | public static final @android.annotation.NonNull Creator<ClassificationsRequest> CREATOR = |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 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 | */ |
Zak Cohen | d61093e | 2019-03-01 11:18:47 -0800 | [diff] [blame] | 106 | public @NonNull Builder setExtras(@NonNull Bundle extras) { |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 107 | mExtras = extras; |
| 108 | return this; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Builds a new request instance. |
| 113 | */ |
Zak Cohen | d61093e | 2019-03-01 11:18:47 -0800 | [diff] [blame] | 114 | public @NonNull ClassificationsRequest build() { |
Winson Chung | 3fb0f25 | 2019-01-08 17:41:55 -0800 | [diff] [blame] | 115 | return new ClassificationsRequest(mSelections, mExtras); |
| 116 | } |
| 117 | } |
| 118 | } |