public class AuthorizeSDK {
    static Sdk<IAuthorize> sdk = new Sdk<>();

    public static void setDefaultCallback(OnCallback callback) {
        sdk.setDefaultCallback(callback);
    }

    public static <T extends IAuthorize> void register(String name, String appId, Class<T> clazz) {
        sdk.register(name, appId, clazz);
    }

    public static <T extends IAuthorize> void register(IFactory<T> factory) {
        sdk.register(factory);
    }

    public static void authorize(final Activity activity, String platform, OnSucceed<String> listener) {
        authorize(activity, platform, new DefaultCallback(sdk.getDefaultCallback(), listener));
    }

    public static void authorize(Activity activity, String platform, OnCallback<String> callback) {
        if (!sdk.isSupport(platform)) {
            callback.onFailed(activity, ResultCode.RESULT_FAILED, "不支持的平台[" + platform + "]");
            return;
        }
        IAuthorize api = sdk.get(activity, platform);
        if (api == null) {
            return;
        }
        api.authorize(callback);
    }


    public static void onHandleResult(Activity activity, int requestCode, int resultCode, Intent data) {
        sdk.onHandleResult(activity, requestCode, resultCode, data);
    }
} public class PaymentSDK {
    static Sdk<IPayable> sdk = new Sdk<>();

    public static void setDefaultCallback(OnCallback callback) {
        sdk.setDefaultCallback(callback);
    }

    public static <T extends IPayable> void register(String name, Class<T> clazz) {
        sdk.register(name, "", clazz);
    }

    public static <T extends IPayable>  void register(IFactory<T> factory) {
        sdk.register(factory);
    }

    public static void pay(Activity activity, String platform, String data, OnSucceed<String> listener) {
        pay(activity, platform, data, new DefaultCallback(sdk.getDefaultCallback(), listener));
    }

    public static void pay(Activity activity, String platform, String data, OnCallback<String> callback) {
        if (!sdk.isSupport(platform)) {
            callback.onFailed(activity, ResultCode.RESULT_FAILED, "不支持的平台[" + platform + "]");
            return;
        }
        IPayable api = sdk.get(activity, platform);
        if (api == null) {
            return;
        }
        api.pay(data, callback);
    }

    public static void onHandleResult(Activity activity, int requestCode, int resultCode, Intent data) {
        sdk.onHandleResult(activity, requestCode, resultCode, data);
    }
} public class PlatformConfig {

    public static void useWeibo(@NonNull String appId, @NonNull String redirectUrl) {
        Platform platform = new Platform(AuthorizeVia.Weibo, appId).extra("redirectUrl", redirectUrl);
        AuthorizeSDK.register(new DefaultFactory(platform, WBAuth.class));
        ShareSDK.register(new DefaultFactory(platform, WBShare.class));
    }

    public static void useQQ(@NonNull String appId) {
        AuthorizeSDK.register(AuthorizeVia.QQ, appId, QQAuth.class);

        ShareSDK.register(ShareTo.QQ, appId, TXShare.class);
        ShareSDK.register(ShareTo.QZone, appId, TXShare.class);
        ShareSDK.register(ShareTo.ToQQ, "", SendShare.class);
    }

    public static void useWeixin(@NonNull String appId) {
        AuthorizeSDK.register(AuthorizeVia.Weixin, appId, WXAuth.class);

        ShareSDK.register(ShareTo.WXSession, appId, WXShare.class);
        ShareSDK.register(ShareTo.WXTimeline, appId, WXShare.class);
        ShareSDK.register(ShareTo.WXFavorite, appId, WXShare.class);
        ShareSDK.register(ShareTo.ToWXSession, "", SendShare.class);
        ShareSDK.register(ShareTo.ToWXTimeline, "", SendShare.class);
    }
    public static void usePayments() {
        PaymentSDK.register(PaymentVia.Wxpay, WXPayment.class);
        PaymentSDK.register(PaymentVia.Alipay, Alipay.class);
    }
} public class ShareSDK {
    static Sdk<IShareable> sdk = new Sdk<>();

    public static void setDefaultCallback(OnCallback callback) {
        sdk.setDefaultCallback(callback);
    }

    public static <T extends IShareable> void register(String name, String appId, Class<T> clazz) {
        sdk.register(name, appId, clazz);
    }

    public static <T extends IShareable>  void register(IFactory<T> factory) {
        sdk.register(factory);
    }


    private ShareData mData = new ShareData();

    private Activity mActivity;

    private ShareSDK(Activity activity, String text, IMediaObject media) {
        mActivity = activity;
        mData.text = text;
        mData.media = media;
    }

    // 文本
    public static ShareSDK make(Activity activity, String text) {
        return new ShareSDK(activity, text, null);
    }

    // 图片
    public static ShareSDK make(Activity activity, ImageResource image) {
        return new ShareSDK(activity, null, new MoImage(image));
    }

    // 图片、音乐、视频、文件
    public static ShareSDK make(Activity activity, IMediaObject media) {
        return new ShareSDK(activity, null, media);
    }

    public static ShareSDK make(Activity activity, String text, IMediaObject media) {
        return new ShareSDK(activity, text, media);
    }

    public ShareSDK withUrl(String value) {
        mData.url = value;
        return this;
    }

    public ShareSDK withTitle(String value) {
        mData.title = value;
        return this;
    }

    public ShareSDK withDescription(String value) {
        mData.description = value;
        return this;
    }

    public ShareSDK withThumb(ImageResource thumb) {
        mData.thumb = thumb;
        return this;
    }

    public void share(String platform) {
        share(platform, new DefaultCallback(sdk.getDefaultCallback(), null));
    }

    public void share(String platform, OnSucceed<String> listener) {
        share(platform, new DefaultCallback(sdk.getDefaultCallback(), listener));
    }
    public void share(String platform, OnCallback<String> callback) {
        if (!sdk.isSupport(platform)) {
            callback.onFailed(mActivity, ResultCode.RESULT_FAILED, "不支持的平台[" + platform + "]");
            return;
        }
        IShareable api = sdk.get(mActivity, platform);
        if (api == null) {
            return;
        }
        api.share(mData, callback);
    }

    public static void onHandleResult(Activity activity, int requestCode, int resultCode, Intent data) {
        sdk.onHandleResult(activity, requestCode, resultCode, data);
    }
} public class PaymentVia {
  public static final String Alipay = "alipay";
  public static final String Wxpay = "wxpay";
} public interface OnCallback<T> {
    void onStarted(Activity activity);
    void onCompleted(Activity activity);
    void onSucceed(Activity activity, T result);
    void onFailed(Activity activity, int code, String message);
} public interface OnSucceed<T> {
    void onSucceed(T result);
} public class FileResource implements ImageResource {
    public final File file;

    public FileResource(File file) {
        this.file = file;
    }

    @Override
    public String toUri() {
        return file.toString();
    }

    @Override
    public Bitmap toBitmap() {
        return ImageTool.toBitmap(file);
    }

    @Override
    public byte[] toBytes() {
        return ImageTool.toBytes(ImageTool.toBitmap(file), Bitmap.CompressFormat.JPEG);
    }

} public class ResIdResource implements ImageResource {
    Context mContext;
    int mResId;
    boolean mIsRaw;

    public ResIdResource(Context context, int resId, boolean isRaw) {
        mContext = context;
        mResId = resId;
        mIsRaw = isRaw;
    }

    @Override
    public String toUri() {
        return null;
    }

    @Override
    public Bitmap toBitmap() {
        return ImageTool.toBitmap(mContext, mResId, mIsRaw);
    }

    @Override
    public byte[] toBytes() {
        return ImageTool.toBytes(mContext, mResId, mIsRaw, Bitmap.CompressFormat.JPEG);
    }
} public class UrlResource implements ImageResource {
    public final String url;

    public UrlResource(String url) {
        this.url = url;
    }

    @Override
    public String toUri() {
        return url;
    }

    @Override
    public Bitmap toBitmap() {
        return ImageTool.toBitmap(ImageTool.loadNetImage(url));
    }

    @Override
    public byte[] toBytes() {
        return ImageTool.loadNetImage(url);
    }
} public class MoImage implements IMediaObject {

    public ImageResource resource;

    public MoImage(@NonNull ImageResource resource) {
        this.resource = resource;
    }

    public MoImage(String url) {
        resource = new UrlResource(url);
    }

    public MoImage(File file) {
        resource = new FileResource(file);
    }

    public MoImage(byte[] bytes) {
        resource = new BytesResource(bytes);
    }

    public MoImage(Bitmap bitmap) {
        resource = new BitmapResource(bitmap);
    }


    @Override
    public int type() {
        return TYPE_IMAGE;
    }

    public String toUri() {
        return resource.toUri();
    }

    public byte[] toBytes() {
        return resource.toBytes();
    }
} public class MoMusic implements IMediaObject {

    public String mediaUrl;
    public String mediaDataUrl;
    public String lowBandUrl;
    public String lowBandDataUrl;
    public int duration;

    public MoMusic(String url) {
        this.mediaUrl = url;
    }

    public MoMusic(String url, String dataUrl) {
        this.mediaUrl = url;
        this.mediaDataUrl = dataUrl;
    }
    public MoMusic withDuration(int value) {
        this.duration = value;
        return this;
    }
    public MoMusic withLowBand(String url) {
        this.lowBandUrl = url;
        return this;
    }
    public MoMusic withLowBand(String url, String dataUrl) {
        this.lowBandUrl = url;
        this.lowBandDataUrl = dataUrl;
        return this;
    }

    @Override
    public int type() {
        return TYPE_MUSIC;
    }

} public class MoVideo implements IMediaObject {


    public String mediaUrl;
    public String mediaDataUrl;
    public String lowBandUrl;
    public String lowBandDataUrl;
    public int duration;

    public MoVideo(String url) {
        this.mediaUrl = url;
    }

    public MoVideo(String url, String dataUrl) {
        this.mediaUrl = url;
        this.mediaDataUrl = dataUrl;
    }
    public MoVideo withDuration(int value) {
        this.duration = value;
        return this;
    }
    public MoVideo withLowBand(String url) {
        this.lowBandUrl = url;
        return this;
    }
    public MoVideo withLowBand(String url, String dataUrl) {
        this.lowBandUrl = url;
        this.lowBandDataUrl = dataUrl;
        return this;
    }
    @Override
    public int type() {
        return TYPE_VIDEO;
    }
} public class MoWeb implements IMediaObject {

    public String url;

    public MoWeb(@NonNull String url) {
        this.url = url;
    }

    @Override
    public int type() {
        return TYPE_WEB;
    }
}
import android.app.Activity;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import ezy.demo.sdk3rd.databinding.ActivityMainBinding;
import ezy.sdk3rd.social.AuthorizeSDK;
import ezy.sdk3rd.social.PaymentSDK;
import ezy.sdk3rd.social.PlatformConfig;
import ezy.sdk3rd.social.ShareSDK;
import ezy.sdk3rd.social.payment.PaymentVia;
import ezy.sdk3rd.social.sdk.OnCallback;
import ezy.sdk3rd.social.sdk.OnSucceed;
import ezy.sdk3rd.social.share.image.resource.FileResource;
import ezy.sdk3rd.social.share.image.resource.ResIdResource;
import ezy.sdk3rd.social.share.image.resource.UrlResource;
import ezy.sdk3rd.social.share.media.MoImage;
import ezy.sdk3rd.social.share.media.MoMusic;
import ezy.sdk3rd.social.share.media.MoVideo;
import ezy.sdk3rd.social.share.media.MoWeb;
package ezy.demo.sdk3rd;




public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

        PlatformConfig.useQQ(BuildConfig.APPID_QQ);
        PlatformConfig.useWeixin(BuildConfig.APPID_WEIXIN);
        PlatformConfig.useWeibo(BuildConfig.APPID_WEIBO, "http://www.sina.com/");
        PlatformConfig.usePayments();

        ShareSDK.setDefaultCallback(new DefaultCallback("share"));
        PaymentSDK.setDefaultCallback(new DefaultCallback("payment"));
        AuthorizeSDK.setDefaultCallback(new DefaultCallback("auth"));


        binding.setOnShare(this);
        binding.setOnAuth(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String platform = binding.spAuth.getSelectedItem().toString().toLowerCase();
                AuthorizeSDK.authorize(MainActivity.this, platform, new OnSucceed<String>() {
                    @Override
                    public void onSucceed(String result) {
                        Toast.makeText(MainActivity.this, "登陆成功 - " + result, Toast.LENGTH_SHORT).show();

                    }
                });
            }

        });
        binding.setOnPay(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String platform = "";
                String data = "";
                switch (v.getId()) {
                case R.id.btn_wxpay:
                    platform = PaymentVia.Wxpay;
                    data = binding.txtWxpaydata.getText().toString();
                    break;
                case R.id.btn_alipay:
                default:
                    platform = PaymentVia.Alipay;
                    data = binding.txtAlipaydata.getText().toString();
                    break;
                }
                PaymentSDK.pay(MainActivity.this, platform, data, new OnSucceed<String>() {
                    @Override
                    public void onSucceed(String result) {
                        Toast.makeText(MainActivity.this, "支付成功 - " + result, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });

    }

    @Override
    public void onClick(View v) {


        FileResource thumb = new FileResource(new File("/storage/emulated/0/thumb.jpg"));