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