OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.share; | |
6 | |
7 import android.app.Activity; | |
8 import android.net.Uri; | |
9 import android.support.annotation.NonNull; | |
10 import android.support.annotation.Nullable; | |
11 | |
12 import org.chromium.chrome.browser.share.ShareHelper.TargetChosenCallback; | |
13 | |
14 /** | |
15 * A container object for passing share parameters to {@link ShareHelper}. | |
16 */ | |
17 public class ShareParams { | |
18 /** | |
19 * Whether it should share directly with the activity that was most recently used to share. | |
20 * If false, the share selection will be saved. | |
21 */ | |
22 private final boolean mShareDirectly; | |
23 | |
24 /** Whether to save the chosen activity for future direct sharing. */ | |
25 private final boolean mSaveLastUsed; | |
26 | |
27 /** The activity that is used to access package manager. */ | |
28 private final Activity mActivity; | |
29 | |
30 /** The title of the page to be shared. */ | |
31 private final String mTitle; | |
32 | |
33 /** | |
34 * The text to be shared. If both |text| and |url| are supplied, they are co ncatenated with a | |
35 * space. | |
36 */ | |
37 private final String mText; | |
38 | |
39 /** The URL of the page to be shared. */ | |
40 private final String mUrl; | |
41 | |
42 /** The Uri to the offline MHTML file to be shared. */ | |
43 private final Uri mOfflineUri; | |
44 | |
45 /** The Uri of the screenshot of the page to be shared. */ | |
46 private final Uri mScreenshotUri; | |
47 | |
48 /** | |
49 * Optional callback to be called when user makes a choice. Will not be call ed if receiving a | |
50 * response when the user makes a choice is not supported (on older Android versions). | |
51 */ | |
52 private TargetChosenCallback mCallback; | |
53 | |
54 private ShareParams(boolean shareDirectly, boolean saveLastUsed, Activity ac tivity, | |
55 String title, String text, String url, @Nullable Uri offlineUri, | |
56 @Nullable Uri screenshotUri, @Nullable TargetChosenCallback callback ) { | |
57 mShareDirectly = shareDirectly; | |
58 mSaveLastUsed = saveLastUsed; | |
59 mActivity = activity; | |
60 mTitle = title; | |
61 mText = text; | |
62 mUrl = url; | |
63 mOfflineUri = offlineUri; | |
64 mScreenshotUri = screenshotUri; | |
65 mCallback = callback; | |
66 } | |
67 | |
68 /** | |
69 * @return Whether it should share directly with the activity that was most recently used to | |
70 * share. | |
71 */ | |
72 public boolean isShareDirectly() { | |
Matt Giuca
2017/06/13 00:53:31
This name (and the following, isSaveLastUsed) is a
ltian
2017/06/13 17:40:53
Done.
| |
73 return mShareDirectly; | |
74 } | |
75 | |
76 /** | |
77 * @return Whether to save the chosen activity for future direct sharing. | |
78 */ | |
79 public boolean isSaveLastUsed() { | |
80 return mSaveLastUsed; | |
81 } | |
82 | |
83 /** | |
84 * @return The activity that is used to access package manager. | |
85 */ | |
86 public Activity getActivity() { | |
87 return mActivity; | |
88 } | |
89 | |
90 /** | |
91 * @return The title of the page to be shared. | |
92 */ | |
93 public String getTitle() { | |
94 return mTitle; | |
95 } | |
96 | |
97 /** | |
98 * @return The text to be shared. | |
99 */ | |
100 public String getText() { | |
101 return mText; | |
102 } | |
103 | |
104 /** | |
105 * @return The URL of the page to be shared. | |
106 */ | |
107 public String getUrl() { | |
108 return mUrl; | |
109 } | |
110 | |
111 /** | |
112 * @return The Uri to the offline MHTML file to be shared. | |
113 */ | |
114 @Nullable | |
115 public Uri getOfflineUri() { | |
116 return mOfflineUri; | |
117 } | |
118 | |
119 /** | |
120 * @return The Uri of the screenshot of the page to be shared. | |
121 */ | |
122 @Nullable | |
123 public Uri getScreenshotUri() { | |
124 return mScreenshotUri; | |
125 } | |
126 | |
127 /** | |
128 * @return The callback to be called when user makes a choice. | |
129 */ | |
130 @Nullable | |
131 public TargetChosenCallback getCallback() { | |
132 return mCallback; | |
133 } | |
134 | |
135 /** The builder for {@link ShareParams} objects. */ | |
136 public static class Builder { | |
137 private boolean mShareDirectly; | |
138 private boolean mSaveLastUsed; | |
139 private Activity mActivity; | |
140 private String mTitle; | |
141 private String mText; | |
142 private String mUrl; | |
143 private Uri mOfflineUri; | |
144 private Uri mScreenshotUri; | |
145 private TargetChosenCallback mCallback; | |
146 | |
147 public Builder(@NonNull Activity activity, @NonNull String title, @NonNu ll String url) { | |
148 mActivity = activity; | |
149 mUrl = url; | |
150 mTitle = title; | |
151 } | |
152 | |
153 /** | |
154 * Sets the text to be shared. | |
155 */ | |
156 public Builder setText(@NonNull String text) { | |
157 mText = text; | |
158 return this; | |
159 } | |
160 | |
161 /** | |
162 * Sets whether it should share directly with the activity that was most recently used to | |
163 * share. | |
164 */ | |
165 public Builder setShareDirectly(boolean shareDirectly) { | |
166 mShareDirectly = shareDirectly; | |
167 return this; | |
168 } | |
169 | |
170 /** | |
171 * Sets whether to save the chosen activity for future direct sharing. | |
172 */ | |
173 public Builder setSaveLastUsed(boolean saveLastUsed) { | |
174 mSaveLastUsed = saveLastUsed; | |
175 return this; | |
176 } | |
177 | |
178 /** | |
179 * Sets the URL of the page to be shared. | |
180 */ | |
181 public Builder setUrl(@NonNull String url) { | |
182 mUrl = url; | |
183 return this; | |
184 } | |
185 | |
186 /** | |
187 * Sets the Uri of the offline MHTML file to be shared. | |
188 */ | |
189 public Builder setOfflineUri(@Nullable Uri offlineUri) { | |
190 mOfflineUri = offlineUri; | |
191 return this; | |
192 } | |
193 | |
194 /** | |
195 * Sets the Uri of the screenshot of the page to be shared. | |
196 */ | |
197 public Builder setScreenshotUri(@Nullable Uri screenshotUri) { | |
198 mScreenshotUri = screenshotUri; | |
199 return this; | |
200 } | |
201 | |
202 /** | |
203 * Sets the callback to be called when user makes a choice. | |
204 */ | |
205 public Builder setCallback(@Nullable TargetChosenCallback callback) { | |
206 mCallback = callback; | |
207 return this; | |
208 } | |
209 | |
210 /** @return A fully constructed {@link ShareParams} object. */ | |
211 public ShareParams build() { | |
212 return new ShareParams(mShareDirectly, mSaveLastUsed, mActivity, mTi tle, mText, mUrl, | |
213 mOfflineUri, mScreenshotUri, mCallback); | |
214 } | |
215 } | |
216 } | |
OLD | NEW |