Android Open Source - ShareSDK-for-Android Share Core






From Project

Back to project page ShareSDK-for-Android.

License

The source code is released under:

MIT License

If you think the Android project ShareSDK-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Offical Website:http://www.mob.com// ww w.  j  a  v  a 2s. c o  m
 * Support QQ: 4006852216
 * Offical Wechat Account:ShareSDK   (We will inform you our updated news at the first time by Wechat, if we release a new version. If you get any problem, you can also contact us with Wechat, we will reply you within 24 hours.)
 *
 * Copyright (c) 2013 mob.com. All rights reserved.
 */

package cn.sharesdk.onekeyshare;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.text.TextUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;

import cn.sharesdk.framework.CustomPlatform;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.framework.utils.R;

/**
 * ShareCore the actual export of OnekeyShare, which reflects
 * the pass in HashMap to a {@link ShareParams} of the target platform,
 * and shares it
 */
public class ShareCore {
  private ShareContentCustomizeCallback customizeCallback;

  /**
   * add a customize share content callback which will be
   * involved before the target platform sharing
   */
  public void setShareContentCustomizeCallback(ShareContentCustomizeCallback callback) {
    customizeCallback = callback;
  }

  /** perform sharing */
  public boolean share(Platform plat, HashMap<String, Object> data) {
    if (plat == null || data == null) {
      return false;
    }

    try {
      String imagePath = (String) data.get("imagePath");
      Bitmap viewToShare = (Bitmap) data.get("viewToShare");
      if (TextUtils.isEmpty(imagePath) && viewToShare != null && !viewToShare.isRecycled()) {
        String path = R.getCachePath(plat.getContext(), "screenshot");
        File ss = new File(path, String.valueOf(System.currentTimeMillis()) + ".jpg");
        FileOutputStream fos = new FileOutputStream(ss);
        viewToShare.compress(CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        data.put("imagePath", ss.getAbsolutePath());
      }
    } catch (Throwable t) {
      t.printStackTrace();
      return false;
    }

    ShareParams sp = new ShareParams(data);
    if (customizeCallback != null) {
      customizeCallback.onShare(plat, sp);
    }

    plat.share(sp);
    return true;
  }

  /** Determine whether the platform shares by its client or not */
  public static boolean isUseClientToShare(String platform) {
    if ("Wechat".equals(platform) || "WechatMoments".equals(platform)
        || "WechatFavorite".equals(platform) || "ShortMessage".equals(platform)
        || "Email".equals(platform) || "GooglePlus".equals(platform)
        || "QQ".equals(platform) || "Pinterest".equals(platform)
        || "Instagram".equals(platform) || "Yixin".equals(platform)
        || "YixinMoments".equals(platform) || "QZone".equals(platform)
        || "Mingdao".equals(platform) || "Line".equals(platform)
        || "KakaoStory".equals(platform) || "KakaoTalk".equals(platform)
        || "Bluetooth".equals(platform) || "WhatsApp".equals(platform)
        || "BaiduTieba".equals(platform)
        ) {
      return true;
    } else if ("Evernote".equals(platform)) {
      Platform plat = ShareSDK.getPlatform(platform);
      if ("true".equals(plat.getDevinfo("ShareByAppClient"))) {
        return true;
      }
    } else if ("SinaWeibo".equals(platform)) {
      Platform plat = ShareSDK.getPlatform(platform);
      if ("true".equals(plat.getDevinfo("ShareByAppClient"))) {
        Intent test = new Intent(Intent.ACTION_SEND);
        test.setPackage("com.sina.weibo");
        test.setType("image/*");
        ResolveInfo ri = plat.getContext().getPackageManager().resolveActivity(test, 0);
        return (ri != null);
      }
    }

    return false;
  }

  /** Determine whether the platform can authorize */
  public static boolean canAuthorize(Context context, String platform) {
    return !("WechatMoments".equals(platform)
        || "WechatFavorite".equals(platform) || "ShortMessage".equals(platform)
        || "Email".equals(platform)
        || "Pinterest".equals(platform) || "Yixin".equals(platform)
        || "YixinMoments".equals(platform) || "Line".equals(platform)
        || "KakaoStory".equals(platform) || "KakaoTalk".equals(platform)
        || "Bluetooth".equals(platform) || "WhatsApp".equals(platform)
        || "BaiduTieba".equals(platform));
  }


  /** Determine whether the platform can get user info */
  public static boolean canGetUserInfo(Context context, String platform) {
    return !("WechatMoments".equals(platform)
        || "WechatFavorite".equals(platform) || "ShortMessage".equals(platform)
        || "Email".equals(platform)
        || "Pinterest".equals(platform) || "Yixin".equals(platform)
        || "YixinMoments".equals(platform) || "Line".equals(platform)
        || "KakaoStory".equals(platform) || "KakaoTalk".equals(platform)
        || "Bluetooth".equals(platform) || "WhatsApp".equals(platform)
        || "Pocket".equals(platform) || "BaiduTieba".equals(platform));
  }

  /** Determine whether direct share */
  public static boolean isDirectShare(Platform platform) {
    return platform instanceof CustomPlatform || isUseClientToShare(platform.getName());
  }
}




Java Source Code List

cn.sharesdk.demo.AuthPage.java
cn.sharesdk.demo.CustomShareFieldsPage.java
cn.sharesdk.demo.CustomerPage.java
cn.sharesdk.demo.DemoPage.java
cn.sharesdk.demo.GetInforPage.java
cn.sharesdk.demo.GetTokenPage.java
cn.sharesdk.demo.JsonPage.java
cn.sharesdk.demo.Laiwang.java
cn.sharesdk.demo.MainActivity.java
cn.sharesdk.demo.MainAdapter.java
cn.sharesdk.demo.MyAdapter.java
cn.sharesdk.demo.MyQZoneWebShareAdapter.java
cn.sharesdk.demo.OneKeyShareCallback.java
cn.sharesdk.demo.ShareContentCustomizeDemo.java
cn.sharesdk.demo.SlidingMenuPage.java
cn.sharesdk.demo.WechatPage.java
cn.sharesdk.demo.YixinPage.java
cn.sharesdk.demo.wxapi.WXEntryActivity.java
cn.sharesdk.demo.yxapi.YXEntryActivity.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.EditPageFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.FollowerListFakeActivity.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShareTheme.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.PlatformListFakeActivity.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ShareCore.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.ThemeShareCallback.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.EditPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.FollowListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformGridView.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.classic.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.EditPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.FollowListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformGridViewAdapter.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.onekeyshare.theme.skyblue.PlatformListPage.java
cn.sharesdk.socialization.sample.MainActivity.java
cn.sharesdk.socialization.sample.MyPlatform.java
cn.sharesdk.socialization.sample.wxapi.WXEntryActivity.java
cn.sharesdk.socialization.sample.yxapi.YXEntryActivity.java