Пример #1
0
  public void show(Context context) {
    ShareSDK.initSDK(context);
    this.context = context;

    // 打开分享菜单的统计
    ShareSDK.logDemoEvent(1, null);

    // 显示方式是由platform和silent两个字段控制的
    // 如果platform设置了,则无须显示九宫格,否则都会显示;
    // 如果silent为true,表示不进入编辑页面,否则会进入。
    // 本类只判断platform,因为九宫格显示以后,事件交给PlatformGridView控制
    // 当platform和silent都为true,则直接进入分享;
    // 当platform设置了,但是silent为false,则判断是否是“使用客户端分享”的平台,
    // 若为“使用客户端分享”的平台,则直接分享,否则进入编辑页面
    if (shareParamsMap.containsKey("platform")) {
      String name = String.valueOf(shareParamsMap.get("platform"));
      Platform platform = ShareSDK.getPlatform(name);

      if (silent || ShareCore.isUseClientToShare(name) || platform instanceof CustomPlatform) {
        HashMap<Platform, HashMap<String, Object>> shareData =
            new HashMap<Platform, HashMap<String, Object>>();
        shareData.put(ShareSDK.getPlatform(name), shareParamsMap);
        share(shareData);
        return;
      }
    }

    PlatformListFakeActivity platformListFakeActivity;
    try {
      if (OnekeyShareTheme.SKYBLUE == theme) {
        platformListFakeActivity =
            (PlatformListFakeActivity)
                Class.forName("cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage")
                    .newInstance();
      } else {
        platformListFakeActivity =
            (PlatformListFakeActivity)
                Class.forName("cn.sharesdk.onekeyshare.theme.classic.PlatformListPage")
                    .newInstance();
      }
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    platformListFakeActivity.setDialogMode(dialogMode);
    platformListFakeActivity.setShareParamsMap(shareParamsMap);
    platformListFakeActivity.setSilent(silent);
    platformListFakeActivity.setCustomerLogos(customers);
    platformListFakeActivity.setBackgroundView(bgView);
    platformListFakeActivity.setHiddenPlatforms(hiddenPlatforms);
    platformListFakeActivity.setOnShareButtonClickListener(onShareButtonClickListener);
    platformListFakeActivity.setThemeShareCallback(
        new ThemeShareCallback() {

          @Override
          public void doShare(HashMap<Platform, HashMap<String, Object>> shareData) {
            share(shareData);
          }
        });
    if (shareParamsMap.containsKey("platform")) {
      String name = String.valueOf(shareParamsMap.get("platform"));
      Platform platform = ShareSDK.getPlatform(name);
      platformListFakeActivity.showEditPage(context, platform);
      return;
    }
    platformListFakeActivity.show(context, null);
  }
  /** 循环执行分享 */
  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);
    }
  }
Пример #3
0
  /** 循环执行分享 */
  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 isGooglePlus = "GooglePlus".equals(name);
      //			if (isGooglePlus && !plat.isValid()) {
      //				Message msg = new Message();
      //				msg.what = MSG_TOAST;
      //				int resId = getStringRes(context, "google_plus_client_inavailable");
      //				msg.obj = context.getString(resId);
      //				UIHandler.sendMessage(msg, this);
      //				continue;
      //			}

      boolean isKakaoTalk = "KakaoTalk".equals(name);
      if (isKakaoTalk && !plat.isClientValid()) {
        Message msg = new Message();
        msg.what = MSG_TOAST;
        int resId = getStringRes(context, "kakaotalk_client_inavailable");
        msg.obj = context.getString(resId);
        UIHandler.sendMessage(msg, this);
        continue;
      }

      boolean isKakaoStory = "KakaoStory".equals(name);
      if (isKakaoStory && !plat.isClientValid()) {
        Message msg = new Message();
        msg.what = MSG_TOAST;
        int resId = getStringRes(context, "kakaostory_client_inavailable");
        msg.obj = context.getString(resId);
        UIHandler.sendMessage(msg, this);
        continue;
      }

      boolean isLine = "Line".equals(name);
      if (isLine && !plat.isClientValid()) {
        Message msg = new Message();
        msg.what = MSG_TOAST;
        int resId = getStringRes(context, "line_client_inavailable");
        msg.obj = context.getString(resId);
        UIHandler.sendMessage(msg, this);
        continue;
      }

      boolean isWhatsApp = "WhatsApp".equals(name);
      if (isWhatsApp && !plat.isClientValid()) {
        Message msg = new Message();
        msg.what = MSG_TOAST;
        int resId = getStringRes(context, "whatsapp_client_inavailable");
        msg.obj = context.getString(resId);
        UIHandler.sendMessage(msg, this);
        continue;
      }

      boolean isPinterest = "Pinterest".equals(name);
      if (isPinterest && !plat.isClientValid()) {
        Message msg = new Message();
        msg.what = MSG_TOAST;
        int resId = getStringRes(context, "pinterest_client_inavailable");
        msg.obj = context.getString(resId);
        UIHandler.sendMessage(msg, this);
        continue;
      }

      if ("Instagram".equals(name) && !plat.isClientValid()) {
        Message msg = new Message();
        msg.what = MSG_TOAST;
        int resId = getStringRes(context, "instagram_client_inavailable");
        msg.obj = context.getString(resId);
        UIHandler.sendMessage(msg, this);
        continue;
      }

      boolean isLaiwang = "Laiwang".equals(name);
      boolean isLaiwangMoments = "LaiwangMoments".equals(name);
      if (isLaiwang || isLaiwangMoments) {
        if (!plat.isClientValid()) {
          Message msg = new Message();
          msg.what = MSG_TOAST;
          int resId = getStringRes(context, "laiwang_client_inavailable");
          msg.obj = context.getString(resId);
          UIHandler.sendMessage(msg, this);
          continue;
        }
      }

      boolean isYixin = "YixinMoments".equals(name) || "Yixin".equals(name);
      if (isYixin && !plat.isClientValid()) {
        Message msg = new Message();
        msg.what = MSG_TOAST;
        int resId = getStringRes(context, "yixin_client_inavailable");
        msg.obj = context.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;
          if (data.containsKey("musicUrl") && !TextUtils.isEmpty(data.get("musicUrl").toString())) {
            shareType = Platform.SHARE_MUSIC;
          }
        }
      } else {
        Bitmap viewToShare = (Bitmap) data.get("viewToShare");
        if (viewToShare != null && !viewToShare.isRecycled()) {
          shareType = Platform.SHARE_IMAGE;
          if (data.containsKey("url") && !TextUtils.isEmpty(data.get("url").toString())) {
            shareType = Platform.SHARE_WEBPAGE;
            if (data.containsKey("musicUrl")
                && !TextUtils.isEmpty(data.get("musicUrl").toString())) {
              shareType = Platform.SHARE_MUSIC;
            }
          }
        } 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") && !TextUtils.isEmpty(data.get("url").toString())) {
              shareType = Platform.SHARE_WEBPAGE;
              if (data.containsKey("musicUrl")
                  && !TextUtils.isEmpty(data.get("musicUrl").toString())) {
                shareType = Platform.SHARE_MUSIC;
              }
            }
          }
        }
      }
      data.put("shareType", shareType);

      if (!started) {
        started = true;
        if (this == callback) {
          int resId = getStringRes(context, "sharing");
          if (resId > 0) {
            showNotification(context.getString(resId));
          }
        }
      }
      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);
  }