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.SystemApi;
21 import android.os.Bundle;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 
25 /**
26  * Represents a suggested selection within a set of on screen content. The result of a
27  * {@link SelectionsRequest} to {@link ContentSuggestionsManager}.
28  *
29  * @hide
30  */
31 @SystemApi
32 public final class ContentSelection implements Parcelable {
33     @NonNull
34     private final String mSelectionId;
35     @NonNull
36     private final Bundle mExtras;
37 
38     /**
39      * Default constructor.
40      *
41      * @param selectionId implementation specific id for the selection.
42      * @param extras containing the data that represents the selection.
43      */
ContentSelection(@onNull String selectionId, @NonNull Bundle extras)44     public ContentSelection(@NonNull String selectionId, @NonNull Bundle extras) {
45         mSelectionId = selectionId;
46         mExtras = extras;
47     }
48 
49     /**
50      * Return the selection id.
51      */
getId()52     public @NonNull String getId() {
53         return mSelectionId;
54     }
55 
56     /**
57      * Return the selection extras.
58      */
getExtras()59     public @NonNull Bundle getExtras() {
60         return 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.writeString(mSelectionId);
71         dest.writeBundle(mExtras);
72     }
73 
74     public static final @android.annotation.NonNull Creator<ContentSelection> CREATOR =
75             new Creator<ContentSelection>() {
76         @Override
77         public ContentSelection createFromParcel(Parcel source) {
78             return new ContentSelection(
79                     source.readString(),
80                     source.readBundle());
81         }
82 
83         @Override
84         public ContentSelection[] newArray(int size) {
85             return new ContentSelection[size];
86         }
87     };
88 }
89