142 lines
4.9 KiB
Java
142 lines
4.9 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.*;
|
|
import butterknife.BindView;
|
|
import com.facebook.drawee.view.SimpleDraweeView;
|
|
import com.gh.base.BaseActivity;
|
|
import com.gh.common.util.*;
|
|
import com.readystatesoftware.systembartint.SystemBarTintManager;
|
|
import com.tencent.tauth.Tencent;
|
|
|
|
import java.io.File;
|
|
|
|
/**
|
|
* 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;
|
|
String gameName;
|
|
String gameIconUrl;
|
|
String shareContent;
|
|
String picName;
|
|
String newsId;
|
|
private Handler handler = new Handler();
|
|
|
|
//接收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, getString(R.string.title_share_card));
|
|
|
|
//修改沉浸栏以及ActionBar 颜色
|
|
mActionbar.setBackgroundColor(getResources().getColor(android.R.color.black));
|
|
SystemBarTintManager tintManager = getTintManager();
|
|
if (tintManager != null) {
|
|
tintManager.setStatusBarTintResource(android.R.color.black);
|
|
}
|
|
|
|
mShareGameNameTv.setText(gameName);
|
|
mShareContentTv.setText(Html.fromHtml(shareContent));
|
|
// mShareGameIconDv.setImageURI(gameIconUrl);
|
|
ImageUtils.display(mShareGameIconDv, 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, 0);
|
|
}
|
|
}, 200);
|
|
|
|
if (!TextUtils.isEmpty(newsId)) {
|
|
createQrCode();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
super.onDestroy();
|
|
handler.removeCallbacksAndMessages(null);
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|