Files
assistant-android/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java
2018-08-07 11:47:51 +08:00

158 lines
6.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.gh.gamecenter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.facebook.common.references.CloseableReference;
import com.facebook.datasource.DataSource;
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
import com.facebook.imagepipeline.image.CloseableImage;
import com.gh.common.util.ImageUtils;
import com.gh.common.util.ShareUtils;
import com.lightgame.utils.Utils;
import com.sina.weibo.sdk.api.ImageObject;
import com.sina.weibo.sdk.api.TextObject;
import com.sina.weibo.sdk.api.WebpageObject;
import com.sina.weibo.sdk.api.WeiboMultiMessage;
import com.sina.weibo.sdk.share.WbShareCallback;
import com.sina.weibo.sdk.share.WbShareHandler;
import com.sina.weibo.sdk.utils.Utility;
/**
* Created by khy on 2016/11/23.
* <p>
* 微博分享
*/
public class WeiBoShareActivity extends Activity implements WbShareCallback {
private static final String KET_SHAREICON = "shareIcon";
private static final String KET_SHAREURL = "shareUrl";
private static final String KET_TITLE = "KET_TITLE";
private static final String KET_TYPE = "KET_TYPE";
private static final String KET_SUMMARY = "KET_SUMMARY";
private String shareUrl;
private String mTitle;
private String mSummary;
private String mShareType;
private WbShareHandler mWeiboShareAPI;
@NonNull
public static Intent getWeiboshareIntent(Context context, String shareUrl, String shareIcon,
String shareTitle, String shareSummary, String shareType) {
Intent intent = new Intent(context, WeiBoShareActivity.class);
Bundle bundle = new Bundle();
bundle.putString(KET_TITLE, shareTitle);
bundle.putString(KET_SHAREICON, shareIcon);
bundle.putString(KET_SUMMARY, shareSummary);
bundle.putString(KET_SHAREURL, shareUrl);
bundle.putString(KET_TYPE, shareType);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
mTitle = extras.getString(KET_TITLE);
String shareIcon = extras.getString(KET_SHAREICON);
mSummary = extras.getString(KET_SUMMARY);
shareUrl = extras.getString(KET_SHAREURL);
mShareType = extras.getString(KET_TYPE);
Utils.toast(this, R.string.share_skip);
mWeiboShareAPI = new WbShareHandler(this);
mWeiboShareAPI.registerApp();
weiboLoadBitMap(shareIcon);
}
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
mWeiboShareAPI.doResultIntent(intent, this); //当前应用唤起微博分享后,返回当前应用
}
private void weiboLoadBitMap(String iconUrl) {
ImageUtils.display(this, iconUrl, new BaseBitmapDataSubscriber() {
@Override
protected void onNewResultImpl(Bitmap bitmap) {
Utils.log("分享获取bitmap成功准备分享");
Bitmap compressBp = ShareUtils.compressBitmap(bitmap);
Bitmap bgBitmap;
if (ShareUtils.ShareType.askInvite.name().equals(mShareType) || ShareUtils.ShareType.askNormal.name().equals(mShareType)) {
bgBitmap = compressBp;
} else {
bgBitmap = ShareUtils.getInstance(WeiBoShareActivity.this).addBackGround(compressBp);
}
TextObject textObject = new TextObject();
if (ShareUtils.ShareType.tools.name().equals(mShareType)) {
textObject.text = mTitle + "@光环助手";
} else if (ShareUtils.ShareType.shareGh.name().equals(mShareType)) {
textObject.text = "这个App可以下载各种热门卡牌手游的加速版绿色安全超级省心做日常效率提高3-5倍不用肝的感觉真好 @光环助手";
} else if (ShareUtils.ShareType.plugin.name().equals(mShareType)) {
textObject.text = mTitle + mSummary + "(光环加速版)" + " @光环助手 ";
} else if (ShareUtils.ShareType.game.name().equals(mShareType)) {
textObject.text = mTitle + mSummary + " @光环助手 ";
} else {
textObject.text = mTitle + " @光环助手 ";
}
ImageObject imageObject = new ImageObject();
imageObject.setImageObject(bgBitmap);//设置缩略图。 注意:最终压缩过的缩略图大小不得超过 32kb。
WebpageObject webObject = new WebpageObject();
webObject.identify = Utility.generateGUID();
webObject.title = "";
webObject.description = getString(R.string.app_name);
webObject.defaultText = getString(R.string.app_name);
webObject.actionUrl = shareUrl;
webObject.setThumbImage(bgBitmap);
WeiboMultiMessage weiboMessage = new WeiboMultiMessage();//初始化微博的分享消息
weiboMessage.textObject = textObject;
weiboMessage.imageObject = imageObject;
weiboMessage.mediaObject = webObject;
mWeiboShareAPI.shareMessage(weiboMessage, false);
}
@Override
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
Utils.log("分享获取bitmap失败");
}
});
}
@Override
public void onWbShareSuccess() {
Utils.toast(this, R.string.share_success_hint);
finish();
}
@Override
public void onWbShareCancel() {
Utils.toast(this, R.string.share_cancel_hint);
finish();
}
@Override
public void onWbShareFail() {
Utils.toast(this, R.string.share_fail_hint);
finish();
}
}