Beispiel #1
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);
    }
  }
Beispiel #2
0
 public boolean handleMessage(Message msg) {
   switch (msg.what) {
     case MSG_TOAST:
       {
         String text = String.valueOf(msg.obj);
         Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
       }
       break;
     case MSG_ACTION_CCALLBACK:
       {
         switch (msg.arg1) {
           case 1:
             {
               // 成功
               int resId = getStringRes(context, "share_completed");
               if (resId > 0) {
                 showNotification(context.getString(resId));
               }
             }
             break;
           case 2:
             {
               // 失败
               String expName = msg.obj.getClass().getSimpleName();
               if ("WechatClientNotExistException".equals(expName)
                   || "WechatTimelineNotSupportedException".equals(expName)
                   || "WechatFavoriteNotSupportedException".equals(expName)) {
                 int resId = getStringRes(context, "wechat_client_inavailable");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               } else if ("GooglePlusClientNotExistException".equals(expName)) {
                 int resId = getStringRes(context, "google_plus_client_inavailable");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               } else if ("QQClientNotExistException".equals(expName)) {
                 int resId = getStringRes(context, "qq_client_inavailable");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               } else if ("YixinClientNotExistException".equals(expName)
                   || "YixinTimelineNotSupportedException".equals(expName)) {
                 int resId = getStringRes(context, "yixin_client_inavailable");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               } else if ("KakaoTalkClientNotExistException".equals(expName)) {
                 int resId = getStringRes(context, "kakaotalk_client_inavailable");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               } else if ("KakaoStoryClientNotExistException".equals(expName)) {
                 int resId = getStringRes(context, "kakaostory_client_inavailable");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               } else if ("WhatsAppClientNotExistException".equals(expName)) {
                 int resId = getStringRes(context, "whatsapp_client_inavailable");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               } else {
                 int resId = getStringRes(context, "share_failed");
                 if (resId > 0) {
                   showNotification(context.getString(resId));
                 }
               }
             }
             break;
           case 3:
             {
               // 取消
               int resId = getStringRes(context, "share_canceled");
               if (resId > 0) {
                 showNotification(context.getString(resId));
               }
             }
             break;
         }
       }
       break;
     case MSG_CANCEL_NOTIFY:
       {
         NotificationManager nm = (NotificationManager) msg.obj;
         if (nm != null) {
           nm.cancel(msg.arg1);
         }
       }
       break;
   }
   return false;
 }
  /** 循环执行分享 */
  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);
    }
  }