团队冲刺二--3
劉晨將新聞的實現(xiàn)做出了大部分:
/** 官網(wǎng)地站:http://www.mob.com
* 技術(shù)支持QQ: 4006852216
* 官方微信:ShareSDK (如果發(fā)布新版本的話,我們將會第一時間通過微信將版本更新內(nèi)容推送給您。如果使用過程中有任何問題,也可以通過微信與我們?nèi)〉寐?lián)系,我們將會在24小時內(nèi)給予回復(fù))
*
* Copyright (c) 2013年 mob.com. All rights reserved.
*/
package cn.sharesdk.onekeyshare;
import static com.mob.tools.utils.BitmapHelper.captureView;
import java.util.ArrayList;
import java.util.HashMap;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import com.mob.tools.utils.R;
/**
* 快捷分享的入口
* <p>
* 通過不同的setter設(shè)置參數(shù),然后調(diào)用{@link #show(Context)}方法啟動快捷分享
*/
public class OnekeyShare {
private HashMap<String, Object> params;
public OnekeyShare() {
params = new HashMap<String, Object>();
params.put("customers", new ArrayList<CustomerLogo>());
params.put("hiddenPlatforms", new HashMap<String, String>());
}
/** address是接收人地址,僅在信息和郵件使用,否則可以不提供 */
public void setAddress(String address) {
params.put("address", address);
}
/**
* title標(biāo)題,在印象筆記、郵箱、信息、微信(包括好友、朋友圈和收藏)、
* 易信(包括好友、朋友圈)、人人網(wǎng)和QQ空間使用,否則可以不提供
*/
public void setTitle(String title) {
params.put("title", title);
}
/** titleUrl是標(biāo)題的網(wǎng)絡(luò)鏈接,僅在人人網(wǎng)和QQ空間使用,否則可以不提供 */
public void setTitleUrl(String titleUrl) {
params.put("titleUrl", titleUrl);
}
/** text是分享文本,所有平臺都需要這個字段 */
public void setText(String text) {
params.put("text", text);
}
/** 獲取text字段的值 */
public String getText() {
return params.containsKey("text") ? String.valueOf(params.get("text")) : null;
}
/** imagePath是本地的圖片路徑,除Linked-In外的所有平臺都支持這個字段 */
public void setImagePath(String imagePath) {
if(!TextUtils.isEmpty(imagePath))
params.put("imagePath", imagePath);
}
/** imageUrl是圖片的網(wǎng)絡(luò)路徑,新浪微博、人人網(wǎng)、QQ空間和Linked-In支持此字段 */
public void setImageUrl(String imageUrl) {
if (!TextUtils.isEmpty(imageUrl))
params.put("imageUrl", imageUrl);
}
/** url在微信(包括好友、朋友圈收藏)和易信(包括好友和朋友圈)中使用,否則可以不提供 */
public void setUrl(String url) {
params.put("url", url);
}
/** filePath是待分享應(yīng)用程序的本地路勁,僅在微信(易信)好友和Dropbox中使用,否則可以不提供 */
public void setFilePath(String filePath) {
params.put("filePath", filePath);
}
/** comment是我對這條分享的評論,僅在人人網(wǎng)和QQ空間使用,否則可以不提供 */
public void setComment(String comment) {
params.put("comment", comment);
}
/** site是分享此內(nèi)容的網(wǎng)站名稱,僅在QQ空間使用,否則可以不提供 */
public void setSite(String site) {
params.put("site", site);
}
/** siteUrl是分享此內(nèi)容的網(wǎng)站地址,僅在QQ空間使用,否則可以不提供 */
public void setSiteUrl(String siteUrl) {
params.put("siteUrl", siteUrl);
}
/** foursquare分享時的地方名 */
public void setVenueName(String venueName) {
params.put("venueName", venueName);
}
/** foursquare分享時的地方描述 */
public void setVenueDescription(String venueDescription) {
params.put("venueDescription", venueDescription);
}
/** 分享地緯度,新浪微博、騰訊微博和foursquare支持此字段 */
public void setLatitude(float latitude) {
params.put("latitude", latitude);
}
/** 分享地經(jīng)度,新浪微博、騰訊微博和foursquare支持此字段 */
public void setLongitude(float longitude) {
params.put("longitude", longitude);
}
/** 是否直接分享 */
public void setSilent(boolean silent) {
params.put("silent", silent);
}
/** 設(shè)置編輯頁的初始化選中平臺 */
public void setPlatform(String platform) {
params.put("platform", platform);
}
/** 設(shè)置KakaoTalk的應(yīng)用下載地址 */
public void setInstallUrl(String installurl) {
params.put("installurl", installurl);
}
/** 設(shè)置KakaoTalk的應(yīng)用打開地址 */
public void setExecuteUrl(String executeurl) {
params.put("executeurl", executeurl);
}
/** 設(shè)置微信分享的音樂的地址 */
public void setMusicUrl(String musicUrl) {
params.put("musicUrl", musicUrl);
}
/** 設(shè)置自定義的外部回調(diào) */
public void setCallback(PlatformActionListener callback) {
params.put("callback", callback);
}
/** 返回操作回調(diào) */
public PlatformActionListener getCallback() {
return R.forceCast(params.get("callback"));
}
/** 設(shè)置用于分享過程中,根據(jù)不同平臺自定義分享內(nèi)容的回調(diào) */
public void setShareContentCustomizeCallback(ShareContentCustomizeCallback callback) {
params.put("customizeCallback", callback);
}
/** 自定義不同平臺分享不同內(nèi)容的回調(diào) */
public ShareContentCustomizeCallback getShareContentCustomizeCallback() {
return R.forceCast(params.get("customizeCallback"));
}
/** 設(shè)置自己圖標(biāo)和點擊事件,可以重復(fù)調(diào)用添加多次 */
public void setCustomerLogo(Bitmap logo, String label, OnClickListener ocl) {
CustomerLogo cl = new CustomerLogo();
cl.logo = logo;
cl.label = label;
cl.listener = ocl;
ArrayList<CustomerLogo> customers = R.forceCast(params.get("customers"));
customers.add(cl);
}
/** 設(shè)置一個總開關(guān),用于在分享前若需要授權(quán),則禁用sso功能 */
public void disableSSOWhenAuthorize() {
params.put("disableSSO", true);
}
/** 設(shè)置視頻網(wǎng)絡(luò)地址 */
public void setVideoUrl(String url) {
params.put("url", url);
params.put("shareType", Platform.SHARE_VIDEO);
}
/** 設(shè)置編輯頁面的顯示模式為Dialog模式 */
@Deprecated
public void setDialogMode() {
params.put("dialogMode", true);
}
/** 添加一個隱藏的platform */
public void addHiddenPlatform(String platform) {
HashMap<String, String> hiddenPlatforms = R.forceCast(params.get("hiddenPlatforms"));
hiddenPlatforms.put(platform, platform);
}
/** 設(shè)置一個將被截圖分享的View , surfaceView是截不了圖片的*/
public void setViewToShare(View viewToShare) {
try {
Bitmap bm = captureView(viewToShare, viewToShare.getWidth(), viewToShare.getHeight());
params.put("viewToShare", bm);
} catch (Throwable e) {
e.printStackTrace();
}
}
/** 騰訊微博分享多張圖片 */
public void setImageArray(String[] imageArray) {
params.put("imageArray", imageArray);
}
/** 設(shè)置在執(zhí)行分享到QQ或QZone的同時,分享相同的內(nèi)容騰訊微博 */
public void setShareToTencentWeiboWhenPerformingQQOrQZoneSharing() {
params.put("isShareTencentWeibo", true);
}
/** 設(shè)置分享界面的樣式,目前只有一種,不需要設(shè)置 */
public void setTheme(OnekeyShareTheme theme) {
params.put("theme", theme.getValue());
}
@SuppressWarnings("unchecked")
public void show(Context context) {
HashMap<String, Object> shareParamsMap = new HashMap<String, Object>();
shareParamsMap.putAll(params);
ShareSDK.initSDK(context.getApplicationContext());
// 打開分享菜單的統(tǒng)計
ShareSDK.logDemoEvent(1, null);
int iTheme = 0;
try {
iTheme = R.parseInt(String.valueOf(shareParamsMap.remove("theme")));
} catch (Throwable t) {}
OnekeyShareTheme theme = OnekeyShareTheme.fromValue(iTheme);
OnekeyShareThemeImpl themeImpl = theme.getImpl();
themeImpl.setShareParamsMap(shareParamsMap);
themeImpl.setDialogMode(shareParamsMap.containsKey("dialogMode") ? ((Boolean) shareParamsMap.remove("dialogMode")) : false);
themeImpl.setSilent(shareParamsMap.containsKey("silent") ? ((Boolean) shareParamsMap.remove("silent")) : false);
themeImpl.setCustomerLogos((ArrayList<CustomerLogo>) shareParamsMap.remove("customers"));
themeImpl.setHiddenPlatforms((HashMap<String, String>) shareParamsMap.remove("hiddenPlatforms"));
themeImpl.setPlatformActionListener((PlatformActionListener) shareParamsMap.remove("callback"));
themeImpl.setShareContentCustomizeCallback((ShareContentCustomizeCallback) shareParamsMap.remove("customizeCallback"));
if (shareParamsMap.containsKey("disableSSO") ? ((Boolean) shareParamsMap.remove("disableSSO")) : false) {
themeImpl.disableSSO();
}
themeImpl.show(context.getApplicationContext());
}
}
轉(zhuǎn)載于:https://www.cnblogs.com/xswl123/p/11015535.html
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
- 上一篇: docker远程访问TLS证书认证she
- 下一篇: 把 textbox 遍历赋值为空