blob: e3c8bc5c7e9ebbefe0844eec40fdd98a7df85166 [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.graphics.Point;
23import android.os.Bundle;
24import android.os.Parcel;
25import android.os.Parcelable;
26
27/**
Zak Cohenb399c842019-01-18 14:36:55 -080028 * The request object used to request content selections from {@link ContentSuggestionsManager}.
29 *
30 * <p>Selections are requested for a given taskId as specified by
31 * {@link android.app.ActivityManager} and optionally take an interest point that specifies the
32 * point on the screen that should be considered as the most important.
33 *
Winson Chung3fb0f252019-01-08 17:41:55 -080034 * @hide
35 */
36@SystemApi
37public final class SelectionsRequest implements Parcelable {
38 private final int mTaskId;
39 @Nullable
40 private final Point mInterestPoint;
41 @Nullable
42 private final Bundle mExtras;
43
44 private SelectionsRequest(int taskId, @Nullable Point interestPoint, @Nullable Bundle extras) {
45 mTaskId = taskId;
46 mInterestPoint = interestPoint;
47 mExtras = extras;
48 }
49
50 /**
51 * Return the request task id.
52 */
53 public int getTaskId() {
54 return mTaskId;
55 }
56
57 /**
Zak Cohenb399c842019-01-18 14:36:55 -080058 * Return the request point of interest or {@code null} if there is no point of interest for
59 * this request.
Winson Chung3fb0f252019-01-08 17:41:55 -080060 */
Zak Cohenb399c842019-01-18 14:36:55 -080061 public @Nullable Point getInterestPoint() {
Winson Chung3fb0f252019-01-08 17:41:55 -080062 return mInterestPoint;
63 }
64
65 /**
Zak Cohenb399c842019-01-18 14:36:55 -080066 * Return the request extras or {@code null} if there aren't any.
Winson Chung3fb0f252019-01-08 17:41:55 -080067 */
Zak Cohenb399c842019-01-18 14:36:55 -080068 public @Nullable Bundle getExtras() {
Winson Chung3fb0f252019-01-08 17:41:55 -080069 return mExtras;
70 }
71
72 @Override
73 public int describeContents() {
74 return 0;
75 }
76
77 @Override
78 public void writeToParcel(Parcel dest, int flags) {
79 dest.writeInt(mTaskId);
80 dest.writeTypedObject(mInterestPoint, flags);
81 dest.writeBundle(mExtras);
82 }
83
84 public static final Creator<SelectionsRequest> CREATOR =
85 new Creator<SelectionsRequest>() {
86 @Override
87 public SelectionsRequest createFromParcel(Parcel source) {
88 return new SelectionsRequest(
89 source.readInt(), source.readTypedObject(Point.CREATOR), source.readBundle());
90 }
91
92 @Override
93 public SelectionsRequest[] newArray(int size) {
94 return new SelectionsRequest[size];
95 }
96 };
97
98 /**
99 * A builder for selections requests events.
100 * @hide
101 */
102 @SystemApi
103 public static final class Builder {
104
105 private final int mTaskId;
106 private Point mInterestPoint;
107 private Bundle mExtras;
108
Zak Cohenb399c842019-01-18 14:36:55 -0800109 /**
110 * Default constructor.
111 *
112 * @param taskId of the type used by {@link android.app.ActivityManager}
113 */
Winson Chung3fb0f252019-01-08 17:41:55 -0800114 public Builder(int taskId) {
115 mTaskId = taskId;
116 }
117
118 /**
119 * Sets the request extras.
120 */
121 public Builder setExtras(@NonNull Bundle extras) {
122 mExtras = extras;
123 return this;
124 }
125
126 /**
127 * Sets the request interest point.
128 */
129 public Builder setInterestPoint(@NonNull Point interestPoint) {
130 mInterestPoint = interestPoint;
131 return this;
132 }
133
134 /**
135 * Builds a new request instance.
136 */
137 public SelectionsRequest build() {
138 return new SelectionsRequest(mTaskId, mInterestPoint, mExtras);
139 }
140 }
141}