136 lines
4.8 KiB
Java
136 lines
4.8 KiB
Java
package com.gh.gamecenter;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.text.Html;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.facebook.drawee.view.SimpleDraweeView;
|
|
import com.gh.base.BaseActivity;
|
|
import com.gh.common.util.MessageShareUtils;
|
|
import com.gh.common.util.QRCodeUtils;
|
|
import com.gh.gamecenter.manager.SystemBarTintManager;
|
|
import com.tencent.tauth.Tencent;
|
|
|
|
import java.io.File;
|
|
|
|
import butterknife.BindView;
|
|
|
|
/**
|
|
* Created by khy on 2016/11/7.
|
|
* 分享卡片
|
|
*/
|
|
public class ShareCardActivity extends BaseActivity {
|
|
|
|
@BindView(R.id.sharecard_content) TextView mShareContentTv;
|
|
@BindView(R.id.sharecard_game_name) TextView mShareGameNameTv;
|
|
@BindView(R.id.sharecard_game_icon) SimpleDraweeView mShareGameIconDv;
|
|
@BindView(R.id.sharecard_qrcode) ImageView mShareQrCodeDv;
|
|
@BindView(R.id.sharecard_screenshot) LinearLayout mShareScreenshotLl;
|
|
@BindView(R.id.reuse_actionbar) RelativeLayout mActionbar;
|
|
@BindView(R.id.sharecard_bottom) LinearLayout mShareBottomLl;
|
|
|
|
Handler handler = new Handler();
|
|
|
|
String gameName;
|
|
String gameIconUrl;
|
|
String shareContent;
|
|
String picName;
|
|
String newsId;
|
|
|
|
//接收QQ或者QQ空间分享回调
|
|
@Override
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
if (requestCode == com.tencent.connect.common.Constants.REQUEST_QQ_SHARE
|
|
|| requestCode == com.tencent.connect.common.Constants.REQUEST_QZONE_SHARE) {
|
|
Tencent.onActivityResultData(requestCode, resultCode, data, MessageShareUtils.getInstance(this).QqShareListener);
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
Bundle extras = getIntent().getExtras();
|
|
gameName = extras.getString("gameName");
|
|
gameIconUrl = extras.getString("gameIconUrl");
|
|
shareContent = extras.getString("shareContent");
|
|
newsId = extras.getString("newsId");
|
|
|
|
picName = "shareImg.jpg";
|
|
|
|
View contentView = View.inflate(this, R.layout.activity_sharecard, null);
|
|
init(contentView, "分享卡片");
|
|
|
|
//修改沉浸栏以及ActionBar 颜色
|
|
mActionbar.setBackgroundColor(getResources().getColor(R.color.back));
|
|
SystemBarTintManager tintManager = getTintManager();
|
|
if (tintManager != null) {
|
|
tintManager.setStatusBarTintResource(R.color.back);
|
|
}
|
|
|
|
mShareGameNameTv.setText(gameName);
|
|
mShareContentTv.setText(Html.fromHtml(shareContent));
|
|
mShareGameIconDv.setImageURI(gameIconUrl);
|
|
mShareQrCodeDv.setImageResource(R.drawable.test_qrcode);
|
|
|
|
// 延迟操作,等待截图部分绘制完成
|
|
handler.postDelayed(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
mShareScreenshotLl.setDrawingCacheEnabled(true);
|
|
mShareScreenshotLl.buildDrawingCache();
|
|
Bitmap drawingCache = mShareScreenshotLl.getDrawingCache();
|
|
saveBitmap(drawingCache);
|
|
MessageShareUtils.getInstance(ShareCardActivity.this).showShareWindows(mShareBottomLl, drawingCache, picName, false);
|
|
}
|
|
}, 200);
|
|
|
|
if (!TextUtils.isEmpty(newsId)) {
|
|
createQrCode();
|
|
}
|
|
}
|
|
|
|
private void createQrCode() {
|
|
new Thread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
final String filePath = getExternalCacheDir().getPath() + "/ShareImg/ShareQRCode.jpg";
|
|
boolean success = QRCodeUtils.createQRImage("http://www.ghzhushou.com/article/" + newsId+ ".html?source=appshare200"
|
|
, 200, 200, filePath, ShareCardActivity.this);
|
|
if (success) {
|
|
runOnUiThread(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
mShareQrCodeDv.setImageBitmap(BitmapFactory.decodeFile(filePath));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}).start();
|
|
}
|
|
|
|
public void saveBitmap(Bitmap bm) {
|
|
File file = new File(getExternalCacheDir().getPath() + "/ShareImg");
|
|
if (!file.isDirectory()) {
|
|
file.delete();
|
|
file.mkdirs();
|
|
}
|
|
if (!file.exists()) {
|
|
file.mkdirs();
|
|
}
|
|
MessageShareUtils.getInstance(ShareCardActivity.this).writeBitmap(file.getPath(), picName, bm, false);
|
|
|
|
}
|
|
|
|
}
|