Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/share/ShareParams.java

Issue 2917703004: [Android] Wrap all share parameters into the ShareParams class (Closed)
Patch Set: Update based on Yusuf's comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 package org.chromium.chrome.browser.share;
Ted C 2017/06/07 18:03:06 add a space above this
ltian 2017/06/07 18:15:19 Done.
5
6 import android.app.Activity;
7 import android.net.Uri;
8 import android.support.annotation.NonNull;
9 import android.support.annotation.Nullable;
10
11 import org.chromium.chrome.browser.share.ShareHelper.TargetChosenCallback;
12
13 /**
14 * A container object for passing share parameters to {@link ShareHelper}.
15 */
16 public class ShareParams {
17 /**
18 * Whether it should share directly with the activity that was most recently used to share.
19 * If false, the share selection will be saved.
20 */
21 private final boolean mShareDirectly;
22
23 /** The activity that is used to access package manager. */
24 private final Activity mActivity;
25
26 /** The title of the page to be shared. */
27 private final String mTitle;
28
29 /**
30 * The text to be shared. If both |text| and |url| are supplied, they are co ncatenated with a
31 * space.
32 */
33 private final String mText;
34
35 /** The URL of the page to be shared. */
36 private final String mUrl;
37
38 /** The Uri to the offline MHTML file to be shared. */
39 private final Uri mOfflineUri;
40
41 /** The Uri of the screenshot of the page to be shared. */
42 private final Uri mScreenshotUri;
43
44 /**
45 * Optional callback to be called when user makes a choice. Will not be call ed if receiving a
46 * response when the user makes a choice is not supported (on older Android versions).
47 */
48 private final TargetChosenCallback mCallback;
49
50 private ShareParams(boolean shareDirectly, Activity activity, String title, String text,
51 String url, @Nullable Uri offlineUri, @Nullable Uri screenshotUri,
52 @Nullable TargetChosenCallback callback) {
53 mShareDirectly = shareDirectly;
54 mActivity = activity;
55 mTitle = title;
56 mText = text;
57 mUrl = url;
58 mOfflineUri = offlineUri;
59 mScreenshotUri = screenshotUri;
60 mCallback = callback;
61 }
62
63 /**
64 * @return Whether it should share directly with the activity that was most recently used to
65 * share.
66 */
67 public boolean isShareDirectly() {
68 return mShareDirectly;
69 }
70
71 /**
72 * @return The activity that is used to access package manager.
73 */
74 public Activity getActivity() {
75 return mActivity;
76 }
77
78 /**
79 * @return The title of the page to be shared.
80 */
81 public String getTitle() {
82 return mTitle;
83 }
84
85 /**
86 * @return The text to be shared.
87 */
88 public String getText() {
89 return mText;
90 }
91
92 /**
93 * @return The URL of the page to be shared.
94 */
95 public String getUrl() {
96 return mUrl;
97 }
98
99 /**
100 * @return The Uri to the offline MHTML file to be shared.
101 */
102 @Nullable
103 public Uri getOfflineUri() {
104 return mOfflineUri;
105 }
106
107 /**
108 * @return The Uri of the screenshot of the page to be shared.
109 */
110 @Nullable
111 public Uri getScreenshotUri() {
112 return mScreenshotUri;
113 }
114
115 /**
116 * @return The callback to be called when user makes a choice.
117 */
118 @Nullable
119 public TargetChosenCallback getCallback() {
120 return mCallback;
121 }
122
123 /** The builder for {@link ShareParams} objects. */
124 public static class Builder {
125 private boolean mShareDirectly;
126 private Activity mActivity;
127 private String mTitle;
128 private String mText;
129 private String mUrl;
130 private Uri mOfflineUri;
131 private Uri mScreenshotUri;
132 private TargetChosenCallback mCallback;
133
134 public Builder(@NonNull Activity activity, @NonNull String title, @NonNu ll String url) {
135 mActivity = activity;
136 mUrl = url;
137 mTitle = title;
138 }
139
140 /**
141 * Sets the text to be shared.
142 */
143 public Builder setText(@NonNull String text) {
144 mText = text;
145 return this;
146 }
147
148 /**
149 * Sets whether it should share directly with the activity that was most recently used to
150 * share.
151 */
152 public Builder setShareDirectly(boolean shareDirectly) {
153 mShareDirectly = shareDirectly;
154 return this;
155 }
156
157 /**
158 * Sets the URL of the page to be shared.
159 */
160 public Builder setUrl(@NonNull String url) {
161 mUrl = url;
162 return this;
163 }
164
165 /**
166 * Sets the Uri of the offline MHTML file to be shared.
167 */
168 public Builder setOfflineUri(@Nullable Uri offlineUri) {
169 mOfflineUri = offlineUri;
170 return this;
171 }
172
173 /**
174 * Sets the Uri of the screenshot of the page to be shared.
175 */
176 public Builder setScreenshotUri(@Nullable Uri screenshotUri) {
177 mScreenshotUri = screenshotUri;
178 return this;
179 }
180
181 /**
182 * Sets the callback to be called when user makes a choice.
183 */
184 public Builder setCallback(@Nullable TargetChosenCallback callback) {
185 mCallback = callback;
186 return this;
187 }
188
189 /** @return A fully constructed {@link ShareParams} object. */
190 public ShareParams build() {
191 return new ShareParams(mShareDirectly, mActivity, mTitle, mText, mUr l, mOfflineUri,
192 mScreenshotUri, mCallback);
193 }
194 }
195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698