Index: chrome/android/java/src/org/chromium/chrome/browser/share/ShareParams.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareParams.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareParams.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..277cf9068417f7e7c1c4675f90cc09ebac16ba5f |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareParams.java |
@@ -0,0 +1,217 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+package org.chromium.chrome.browser.share; |
+ |
+import android.app.Activity; |
+import android.net.Uri; |
+import android.support.annotation.Nullable; |
+ |
+import org.chromium.chrome.browser.share.ShareHelper.TargetChosenCallback; |
+ |
+/** |
+ * A container object for passing share parameters to {@link ShareHelper}. |
+ */ |
+public class ShareParams { |
+ /** |
+ * Whether it should share directly with the activity that was most recently used to share. |
+ */ |
+ private final boolean mShareDirectly; |
+ |
+ /** Whether to save the chosen activity for future direct sharing. */ |
+ private final boolean mSaveLastUsed; |
+ |
+ /** The activity that is used to access package manager. */ |
+ private final Activity mActivity; |
+ |
+ /** The title of the page to be shared. */ |
+ private final String mTitle; |
+ |
+ /** |
+ * The text to be shared. If both |text| and |url| are supplied, they are concatenated with a |
+ * space. |
+ */ |
+ private final String mText; |
+ |
+ /** The URL of the page to be shared. */ |
+ private final String mUrl; |
+ |
+ /** The Uri to the offline MHTML file to be shared. */ |
+ private final Uri mOfflineUri; |
+ |
+ /** The Uri of the screenshot of the page to be shared. */ |
+ private final Uri mScreenshotUri; |
+ |
+ /** |
+ * Optional callback to be called when user makes a choice. Will not be called if receiving a |
+ * response when the user makes a choice is not supported (on older Android versions). |
+ */ |
+ private final TargetChosenCallback mCallback; |
+ |
+ private ShareParams(boolean shareDirectly, boolean saveLastUsed, Activity activity, |
+ String title, String text, String url, @Nullable Uri offlineUri, |
Yusuf
2017/06/02 20:07:47
These Nullables would actually help in the builder
ltian
2017/06/02 23:44:39
Done.
|
+ @Nullable Uri screenshotUri, @Nullable TargetChosenCallback callback) { |
+ mShareDirectly = shareDirectly; |
+ mSaveLastUsed = saveLastUsed; |
+ mActivity = activity; |
+ mTitle = title; |
+ mText = text; |
+ mUrl = url; |
+ mOfflineUri = offlineUri; |
+ mScreenshotUri = screenshotUri; |
+ mCallback = callback; |
+ } |
+ |
+ /** |
+ * @return Whether it should share directly with the activity that was most recently used to |
+ * share. |
+ */ |
+ public boolean isShareDirectly() { |
+ return mShareDirectly; |
+ } |
+ |
+ /** |
+ * @return Whether to save the chosen activity for future direct sharing. |
+ */ |
+ public boolean isSaveLastUsed() { |
+ return mSaveLastUsed; |
+ } |
+ |
+ /** |
+ * @return The activity that is used to access package manager. |
+ */ |
+ public Activity getActivity() { |
+ return mActivity; |
+ } |
+ |
+ /** |
+ * @return The title of the page to be shared. |
+ */ |
+ public String getTitle() { |
+ return mTitle; |
+ } |
+ |
+ /** |
+ * @return The text to be shared. |
+ */ |
+ public String getText() { |
+ return mText; |
+ } |
+ |
+ /** |
+ * @return The URL of the page to be shared. |
+ */ |
+ public String getUrl() { |
+ return mUrl; |
+ } |
+ |
+ /** |
+ * @return The Uri to the offline MHTML file to be shared. |
+ */ |
+ @Nullable |
+ public Uri getOfflineUri() { |
+ return mOfflineUri; |
+ } |
+ |
+ /** |
+ * @return The Uri of the screenshot of the page to be shared. |
+ */ |
+ @Nullable |
+ public Uri getScreenshotUri() { |
+ return mScreenshotUri; |
+ } |
+ |
+ /** |
+ * @return The callback to be called when user makes a choice. |
+ */ |
+ @Nullable |
+ public TargetChosenCallback getCallback() { |
+ return mCallback; |
+ } |
+ |
+ /** The builder for {@link ShareParams} objects. */ |
+ public static class Builder { |
+ private boolean mShareDirectly; |
+ private boolean mSaveLastUsed; |
+ private Activity mActivity; |
+ private String mTitle; |
+ private String mText; |
+ private String mUrl; |
+ private Uri mOfflineUri; |
+ private Uri mScreenshotUri; |
+ private TargetChosenCallback mCallback; |
+ |
+ public Builder(Activity activity, String title, String url) { |
+ mActivity = activity; |
+ mUrl = url; |
+ mTitle = title; |
+ } |
+ |
+ /** |
+ * Sets the text to be shared. |
+ */ |
+ public Builder setText(String text) { |
+ mText = text; |
+ return this; |
+ } |
+ |
+ /** |
+ * Sets whether it should share directly with the activity that was most recently used to |
+ * share. |
+ */ |
+ public Builder setShareDirectly(boolean shareDirectly) { |
+ mShareDirectly = shareDirectly; |
+ assert !(mShareDirectly & mSaveLastUsed); |
+ return this; |
+ } |
+ |
+ /** |
+ * Sets whether to save the chosen activity for future direct sharing. |
+ */ |
+ public Builder setSaveLastUsed(boolean saveLastUsed) { |
+ mSaveLastUsed = saveLastUsed; |
+ return this; |
+ } |
+ |
+ /** |
+ * Sets the URL of the page to be shared. |
+ */ |
+ public Builder setUrl(String url) { |
+ mUrl = url; |
+ return this; |
+ } |
+ |
+ /** |
+ * Sets the Uri of the offline MHTML file to be shared. |
+ */ |
+ public Builder setOfflineUri(Uri offlineUri) { |
+ mOfflineUri = offlineUri; |
+ return this; |
+ } |
+ |
+ /** |
+ * Sets the Uri of the screenshot of the page to be shared. |
+ */ |
+ public Builder setScreenshotUri(Uri screenshotUri) { |
+ mScreenshotUri = screenshotUri; |
+ return this; |
+ } |
+ |
+ /** |
+ * Sets the callback to be called when user makes a choice. |
+ */ |
+ public Builder setCallback(TargetChosenCallback callback) { |
+ mCallback = callback; |
+ return this; |
+ } |
+ |
+ /** @return A fully constructed {@link ShareParams} object. */ |
+ public ShareParams build() { |
+ if (mShareDirectly) { |
Yusuf
2017/06/02 20:07:46
one line!
ltian
2017/06/02 23:44:39
Done.
|
+ assert !mSaveLastUsed; |
+ } |
+ return new ShareParams(mShareDirectly, mSaveLastUsed, mActivity, mTitle, mText, mUrl, |
+ mOfflineUri, mScreenshotUri, mCallback); |
+ } |
+ } |
+} |