分享光环(普通分享和热点网页分享)

This commit is contained in:
khy
2017-02-07 17:06:32 +08:00
parent 30bb750d94
commit 575ba33e43
27 changed files with 1790 additions and 72 deletions

View File

@ -12,7 +12,6 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
@ -63,7 +62,7 @@ public class ShareUtils {
private static IWXAPI api;
private static Tencent mTencent;
private Handler handler;
private Boolean ispopupWindow;
private int[] arrLogo = {R.drawable.share_wechat_logo, R.drawable.share_wechatmoments_logo, R.drawable.share_qq_logo
, R.drawable.share_qzone_logo, R.drawable.share_sinaweibo_logo, R.drawable.share_shortmessage_logo
@ -84,21 +83,31 @@ public class ShareUtils {
return instance;
}
public void showShareWindows(View view, String url, String gameName, String icon ,String newsTitle, boolean isPlugin){
/**
*
* @param view ispopupWindow-true是绑定的布局 ispopupWindow-false 则是嵌套的父控件
* @param url 分享链接
* @param gameName 游戏名 与 新闻标题区分
* @param icon 分享图标
* @param newsTitle 新闻标题 与 游戏名区分
* @param isPlugin 判断游戏是否是插件
* @param ispopupWindow 判断是否是 PopupWindow false可直接嵌套进布局分享光环view是父控件
*/
public void showShareWindows(View view, String url, String gameName, String icon ,String newsTitle,
boolean isPlugin, boolean ispopupWindow){
this.shareIcon = icon;
this.shareGameName = gameName;
this.shareUrl = url;
this.shareNewsTitle = newsTitle;
this.isPlugin = isPlugin;
this.ispopupWindow = ispopupWindow;
RelativeLayout contentView = new RelativeLayout(context);
contentView.setBackgroundColor(0x8c000000);
contentView.setFocusable(true);
contentView.setFocusableInTouchMode(true);
RecyclerView shareRecyclerView = new RecyclerView(context);
shareRecyclerView.setPadding(DisplayUtils.dip2px(context, 20), DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, 20), 0);
shareRecyclerView.setBackgroundColor(Color.WHITE);
//RecyclerView禁止滑动
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 4){
@ -116,6 +125,16 @@ public class ShareUtils {
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
contentView.addView(shareRecyclerView,rlParams);
if (!ispopupWindow) {
LinearLayout layout = (LinearLayout) view;
layout.addView(contentView);
arrLabel[7] = "邮件";
arrLogo[7] = R.drawable.share_email_logo;
return;
}
contentView.setBackgroundColor(0x8c000000);
shareRecyclerView.setBackgroundColor(Color.WHITE);
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
, LinearLayout.LayoutParams.MATCH_PARENT, true);
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
@ -198,10 +217,24 @@ public class ShareUtils {
shortMessageSahre();
break;
case 6:
copyLink(shareUrl);
copyLink("推荐光环助手,绿色安全的手游加速助手:" + shareUrl);
break;
case 7:
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
} else {
Intent data=new Intent(Intent.ACTION_SENDTO);
data.setData(Uri.parse("mailto:"));
data.putExtra(Intent.EXTRA_SUBJECT, "快来试试光环助手");
data.putExtra(Intent.EXTRA_TEXT, "我用光环助手一段时间了在里面可以下载各种热门卡牌手游的加速版绿色安全超级省心做日常效率提高3-5倍\n" +
"\n" +
"不用肝的感觉真好,快来试试。\n" +
"\n" +
"光环助手官网地址:\n" +
"\n" +
"http://www.ghzhushou.com?source=appshare333");
context.startActivity(data);
}
break;
}
}
@ -228,22 +261,31 @@ public class ShareUtils {
}
//QQ分享
private void qqSahre(){
private void qqSahre() {
Utils.toast(context,"分享跳转中...");
Bundle params = new Bundle();
if (shareNewsTitle != null){
params.putString(QQShare.SHARE_TO_QQ_TITLE, shareNewsTitle);
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, "来自光环助手(最强卡牌神器)");
}else {
params.putString(QQShare.SHARE_TO_QQ_TITLE, "向你推荐:");
if (isPlugin){
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareGameName + "(光环加速版)");
}else {
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareGameName);
}
}
String title;
String summary;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
summary = "来自光环助手(最强卡牌神器)";
} else {
title = "向你推荐:";
if (isPlugin) {
summary = shareGameName + "(光环加速版)";
} else {
summary = shareGameName;
}
}
} else {
title = "不用肝的感觉真好";
summary = "绿色安全的手游加速助手";
}
params.putString(QQShare.SHARE_TO_QQ_TITLE, title);
params.putString(QQShare.SHARE_TO_QQ_SUMMARY, summary);
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, shareUrl);
params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, shareIcon);
@ -251,57 +293,84 @@ public class ShareUtils {
mTencent.shareToQQ(
(Activity) context, params,QqShareListener);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//微信好友分享
private void wechatSahre(){
private void wechatSahre() {
Utils.toast(context,"分享跳转中...");
WXWebpageObject webpage = new WXWebpageObject();
WXMediaMessage msg = new WXMediaMessage(webpage);
webpage.webpageUrl = shareUrl;
if (shareNewsTitle != null){
msg.title = shareNewsTitle;
msg.description = "来自光环助手(最强卡牌神器)";
}else {
if (isPlugin){
msg.title = "向你推荐";
msg.description = shareGameName + "(光环加速版";
}else {
msg.title = "向你推荐";
msg.description = shareGameName;
String title;
String summary;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
summary = "来自光环助手(最强卡牌神器";
} else {
title = "向你推荐";
if (isPlugin){
summary = shareGameName + "(光环加速版)";
} else {
summary = shareGameName;
}
}
} else {
title = "不用肝的感觉真好";
summary = "绿色安全的手游加速助手";
}
msg.title = title;
msg.description = summary;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
req.message = msg;
req.scene = SendMessageToWX.Req.WXSceneSession;
loadBitMap(shareIcon, msg, req);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//QQ空间分享
private void qZoneSahre(){
private void qZoneSahre() {
Utils.toast(context,"分享跳转中...");
Bundle params = new Bundle();
if (shareNewsTitle != null){
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, shareNewsTitle);
}else {
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, "向你推荐:");
if (isPlugin){
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, shareGameName + "(光环加速版)");
}else {
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, shareGameName);
String title;
String summary = null;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
} else {
title = "向你推荐:";
if (isPlugin) {
summary = shareGameName + "(光环加速版)";
} else {
summary = shareGameName;
}
}
} else {
title = "不用肝的感觉真好";
summary = "绿色安全的手游加速助手";
}
ArrayList<String> imageUrls = new ArrayList<String>();
imageUrls.add(shareIcon);
if (summary != null) {
params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, summary);
}
params.putString(QzoneShare.SHARE_TO_QQ_TITLE, title);
params.putInt(QzoneShare.SHARE_TO_QZONE_KEY_TYPE, QzoneShare.SHARE_TO_QZONE_TYPE_NO_TYPE);
params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, shareUrl);
params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, imageUrls);
@ -309,26 +378,36 @@ public class ShareUtils {
mTencent.shareToQzone(
(Activity) context, params,QqShareListener);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//微信朋友圈分享
private void wechatMomentsSahre(){
private void wechatMomentsSahre() {
Utils.toast(context,"分享跳转中...");
WXWebpageObject webpage = new WXWebpageObject();
WXMediaMessage msg = new WXMediaMessage(webpage);
webpage.webpageUrl = shareUrl;
if (shareNewsTitle != null){
msg.title = shareNewsTitle;
}else {
if (isPlugin){
msg.title = "向你推荐:" + shareGameName + "(光环加速版)";
}else {
msg.title = "向你推荐:" + shareGameName;
String title;
if (ispopupWindow) {
if (shareNewsTitle != null) {
title = shareNewsTitle;
} else {
if (isPlugin){
title = shareGameName + "(光环加速版)";
} else {
title = shareGameName;
}
}
} else {
title = "玩手游不用肝的感觉真好";
}
msg.title = title;
SendMessageToWX.Req req = new SendMessageToWX.Req();
req.transaction = buildTransaction("webpage");
@ -336,12 +415,14 @@ public class ShareUtils {
req.scene = SendMessageToWX.Req.WXSceneTimeline;
loadBitMap(shareIcon, msg, req);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//新浪微博分享
private void sinaWeiboSahre(){
private void sinaWeiboSahre() {
Intent intent = new Intent(context, WeiBoShareActivity.class);
Bundle bundle = new Bundle();
bundle.putString("shareNewsTitle", shareNewsTitle);
@ -349,23 +430,31 @@ public class ShareUtils {
bundle.putString("shareGameName", shareGameName);
bundle.putString("shareUrl", shareUrl);
bundle.putBoolean("isPlugin",isPlugin);
bundle.putBoolean("ispopupWindow", ispopupWindow);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
//短信分享
private void shortMessageSahre(){
private void shortMessageSahre() {
String smsBody;
if (shareNewsTitle != null){
smsBody = shareNewsTitle + shareUrl;
}else {
if (isPlugin){
smsBody = "向你推荐:" + shareGameName + "(光环加速版)" + shareUrl;
if (ispopupWindow) {
if (shareNewsTitle != null){
smsBody = shareNewsTitle + shareUrl;
}else {
smsBody = "向你推荐:" + shareGameName + shareUrl;
if (isPlugin){
smsBody = "向你推荐:" + shareGameName + "(光环加速版)" + shareUrl;
}else {
smsBody = "向你推荐:" + shareGameName + shareUrl;
}
}
} else {
smsBody = "这个App可以下载各种热门卡牌手游的加速版绿色安全超级省心做日常效率提高3-5倍光环助手官网" + shareUrl;
}
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:"));
@ -379,7 +468,9 @@ public class ShareUtils {
e.printStackTrace();
}
popupWindow.dismiss();
if (ispopupWindow) {
popupWindow.dismiss();
}
}
private String buildTransaction(final String type) {
@ -390,9 +481,12 @@ public class ShareUtils {
private void copyLink(String copyContent) {
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setText(copyContent);
popupWindow.dismiss();
Utils.toast(context,"复制成功");
if (ispopupWindow != null && ispopupWindow) {
popupWindow.dismiss();
Utils.toast(context,"复制成功,请到微信/QQ粘贴分享");
} else {
Utils.toast(context,"复制成功");
}
}
private void loadBitMap(final String iconUrl, final WXMediaMessage msg, final SendMessageToWX.Req req){