/** 循环执行分享 */ public void share(HashMap<Platform, HashMap<String, Object>> shareData) { boolean started = false; for (Entry<Platform, HashMap<String, Object>> ent : shareData.entrySet()) { Platform plat = ent.getKey(); plat.SSOSetting(disableSSO); String name = plat.getName(); boolean isWechat = "WechatMoments".equals(name) || "Wechat".equals(name) || "WechatFavorite".equals(name); if (isWechat && !plat.isValid()) { Message msg = new Message(); msg.what = MSG_TOAST; int resId = getStringRes(getContext(), "wechat_client_inavailable"); msg.obj = activity.getString(resId); UIHandler.sendMessage(msg, this); continue; } boolean isGooglePlus = "GooglePlus".equals(name); if (isGooglePlus && !plat.isValid()) { Message msg = new Message(); msg.what = MSG_TOAST; int resId = getStringRes(getContext(), "google_plus_client_inavailable"); msg.obj = activity.getString(resId); UIHandler.sendMessage(msg, this); continue; } boolean isPinterest = "Pinterest".equals(name); if (isPinterest && !plat.isValid()) { Message msg = new Message(); msg.what = MSG_TOAST; int resId = getStringRes(getContext(), "pinterest_client_inavailable"); msg.obj = activity.getString(resId); UIHandler.sendMessage(msg, this); continue; } if ("Instagram".equals(name)) { Intent test = new Intent(Intent.ACTION_SEND); test.setPackage("com.instagram.android"); test.setType("image/*"); ResolveInfo ri = activity.getPackageManager().resolveActivity(test, 0); if (ri == null) { Message msg = new Message(); msg.what = MSG_TOAST; int resId = getStringRes(getContext(), "instagram_client_inavailable"); msg.obj = activity.getString(resId); UIHandler.sendMessage(msg, this); continue; } } boolean isYixin = "YixinMoments".equals(name) || "Yixin".equals(name); if (isYixin && !plat.isValid()) { Message msg = new Message(); msg.what = MSG_TOAST; int resId = getStringRes(getContext(), "yixin_client_inavailable"); msg.obj = activity.getString(resId); UIHandler.sendMessage(msg, this); continue; } HashMap<String, Object> data = ent.getValue(); int shareType = Platform.SHARE_TEXT; String imagePath = String.valueOf(data.get("imagePath")); if (imagePath != null && (new File(imagePath)).exists()) { shareType = Platform.SHARE_IMAGE; if (imagePath.endsWith(".gif")) { shareType = Platform.SHARE_EMOJI; } else if (data.containsKey("url") && !TextUtils.isEmpty(data.get("url").toString())) { shareType = Platform.SHARE_WEBPAGE; } } else { Bitmap viewToShare = (Bitmap) data.get("viewToShare"); if (viewToShare != null && !viewToShare.isRecycled()) { shareType = Platform.SHARE_IMAGE; if (data.containsKey("url")) { Object url = data.get("url"); if (url != null && !TextUtils.isEmpty(url.toString())) { shareType = Platform.SHARE_WEBPAGE; } } } else { Object imageUrl = data.get("imageUrl"); if (imageUrl != null && !TextUtils.isEmpty(String.valueOf(imageUrl))) { shareType = Platform.SHARE_IMAGE; if (String.valueOf(imageUrl).endsWith(".gif")) { shareType = Platform.SHARE_EMOJI; } else if (data.containsKey("url")) { Object url = data.get("url"); if (url != null && !TextUtils.isEmpty(url.toString())) { shareType = Platform.SHARE_WEBPAGE; } } } } } data.put("shareType", shareType); if (!started) { started = true; if (equals(callback)) { int resId = getStringRes(getContext(), "sharing"); if (resId > 0) { showNotification(2000, getContext().getString(resId)); } } finish(); } plat.setPlatformActionListener(callback); ShareCore shareCore = new ShareCore(); shareCore.setShareContentCustomizeCallback(customizeCallback); shareCore.share(plat, data); } }
public void onCreate() { // 显示方式是由platform和silent两个字段控制的 // 如果platform设置了,则无须显示九宫格,否则都会显示; // 如果silent为true,表示不进入编辑页面,否则会进入。 // 本类只判断platform,因为九宫格显示以后,事件交给PlatformGridView控制 // 当platform和silent都为true,则直接进入分享; // 当platform设置了,但是silent为false,则判断是否是“使用客户端分享”的平台, // 若为“使用客户端分享”的平台,则直接分享,否则进入编辑页面 HashMap<String, Object> copy = new HashMap<String, Object>(); copy.putAll(reqMap); if (copy.containsKey("platform")) { String name = String.valueOf(copy.get("platform")); if (silent) { HashMap<Platform, HashMap<String, Object>> shareData = new HashMap<Platform, HashMap<String, Object>>(); shareData.put(ShareSDK.getPlatform(name), copy); share(shareData); } else if (ShareCore.isUseClientToShare(name)) { HashMap<Platform, HashMap<String, Object>> shareData = new HashMap<Platform, HashMap<String, Object>>(); shareData.put(ShareSDK.getPlatform(name), copy); share(shareData); } else { Platform pp = ShareSDK.getPlatform(name); if (pp instanceof CustomPlatform) { HashMap<Platform, HashMap<String, Object>> shareData = new HashMap<Platform, HashMap<String, Object>>(); shareData.put(ShareSDK.getPlatform(name), copy); share(shareData); } else { EditPage page = new EditPage(); page.setBackGround(bgView); bgView = null; page.setShareData(copy); if (dialogMode) { page.setDialogMode(); } page.showForResult( activity, null, new FakeActivity() { public void onResult(HashMap<String, Object> data) { if (data != null && data.containsKey("editRes")) { @SuppressWarnings("unchecked") HashMap<Platform, HashMap<String, Object>> editRes = (HashMap<Platform, HashMap<String, Object>>) data.get("editRes"); share(editRes); } } }); } } finish(); return; } finishing = false; canceled = false; initPageView(); initAnim(); activity.setContentView(flPage); // 设置宫格列表数据 grid.setData(copy, silent); grid.setHiddenPlatforms(hiddenPlatforms); grid.setCustomerLogos(customers); grid.setParent(this); btnCancel.setOnClickListener(this); // 显示列表 flPage.clearAnimation(); flPage.startAnimation(animShow); // 打开分享菜单的统计 ShareSDK.logDemoEvent(1, null); }