1、使用新的渠道打包方案,将渠道值写入到已经签名的apk上面,具体参考README.md

2、将各种第三方工具使用的appid、key和渠道值改成用gradle.properties的配置方式
This commit is contained in:
CsHeng
2017-05-12 15:46:46 +08:00
parent b280e1bf89
commit 5eb5f6807e
25 changed files with 462 additions and 297 deletions

View File

@ -16,8 +16,8 @@ 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.gamecenter.R;
import com.gh.gamecenter.WeiBoShareActivity;
import com.gh.common.constant.Config;
import com.gh.gamecenter.*;
import com.tencent.connect.share.QQShare;
import com.tencent.connect.share.QzoneShare;
import com.tencent.mm.sdk.openapi.*;
@ -33,8 +33,8 @@ import java.util.List;
*/
public class ShareUtils {
private static ShareUtils instance;
private static IWXAPI api;
private static Tencent mTencent;
private IWXAPI mIWXAPI;
private Tencent mTencent;
private String shareUrl;
private String shareGameName;
private String shareIcon;
@ -42,42 +42,53 @@ public class ShareUtils {
private boolean isPlugin = false;
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
, R.drawable.share_copyfont_logo, R.drawable.share_cancel_logo};
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,
R.drawable.share_copyfont_logo,
R.drawable.share_cancel_logo
};
private String[] arrLabel = {"微信好友", "朋友圈", "QQ好友", "QQ空间", "新浪微博", "短信", "复制链接", "取消"};
private PopupWindow popupWindow;
private Context context;
private Context mContext;
//QQ或者QQ空间分享回调处理
public IUiListener QqShareListener = new IUiListener() {
@Override
public void onComplete(Object o) {
Utils.toast(context, "分享成功");
Utils.toast(mContext, "分享成功");
}
@Override
public void onError(UiError uiError) {
Utils.toast(context, "分享失败");
Utils.toast(mContext, "分享失败");
}
@Override
public void onCancel() {
Utils.toast(context, "分享已取消");
Utils.toast(mContext, "分享已取消");
}
};
public static ShareUtils getInstance(Activity context) {
if (instance == null) {
instance = new ShareUtils();
mTencent = Tencent.createInstance("1104659243", context); //初始化QQ分享
api = WXAPIFactory.createWXAPI(context, "wx3ffd0785fad18396"); //初始化微信分享
instance = new ShareUtils(context);
}
instance.context = context;
return instance;
}
private ShareUtils(Context context){
mTencent = Tencent.createInstance(Config.TENCENT_APPID, context); //初始化QQ分享
mIWXAPI = WXAPIFactory.createWXAPI(context, Config.WECHAT_APPID); //初始化微信分享
mContext = context;
}
//检查是否安装手机QQ
public static boolean isQQClientAvailable(Context context) {
final PackageManager packageManager = context.getPackageManager();
@ -111,15 +122,15 @@ public class ShareUtils {
this.isPlugin = isPlugin;
this.ispopupWindow = ispopupWindow;
RelativeLayout contentView = new RelativeLayout(context);
RelativeLayout contentView = new RelativeLayout(mContext);
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);
RecyclerView shareRecyclerView = new RecyclerView(mContext);
shareRecyclerView.setPadding(DisplayUtils.dip2px(mContext, 20), DisplayUtils.dip2px(mContext, 10), DisplayUtils.dip2px(mContext, 20), 0);
//RecyclerView禁止滑动
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 4) {
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 4) {
@Override
public boolean canScrollVertically() {
return false;
@ -130,7 +141,7 @@ public class ShareUtils {
shareRecyclerView.setAdapter(new ShareRecyclerViewAdapter());
RelativeLayout.LayoutParams rlParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
, DisplayUtils.dip2px(context, 200));
, DisplayUtils.dip2px(mContext, 200));
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
contentView.addView(shareRecyclerView, rlParams);
@ -179,7 +190,7 @@ public class ShareUtils {
//QQ分享
private void qqSahre() {
Utils.toast(context, "分享跳转中...");
Utils.toast(mContext, "分享跳转中...");
Bundle params = new Bundle();
String title;
@ -209,7 +220,7 @@ public class ShareUtils {
params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "光环助手");
mTencent.shareToQQ(
(Activity) context, params, QqShareListener);
(Activity) mContext, params, QqShareListener);
if (ispopupWindow) {
popupWindow.dismiss();
@ -218,7 +229,7 @@ public class ShareUtils {
//微信好友分享
private void wechatSahre() {
Utils.toast(context, "分享跳转中...");
Utils.toast(mContext, "分享跳转中...");
WXWebpageObject webpage = new WXWebpageObject();
WXMediaMessage msg = new WXMediaMessage(webpage);
webpage.webpageUrl = shareUrl;
@ -259,7 +270,7 @@ public class ShareUtils {
//QQ空间分享
private void qZoneSahre() {
Utils.toast(context, "分享跳转中...");
Utils.toast(mContext, "分享跳转中...");
Bundle params = new Bundle();
String title;
@ -294,7 +305,7 @@ public class ShareUtils {
params.putString(QzoneShare.SHARE_TO_QQ_APP_NAME, "光环助手");
mTencent.shareToQzone(
(Activity) context, params, QqShareListener);
(Activity) mContext, params, QqShareListener);
if (ispopupWindow) {
popupWindow.dismiss();
}
@ -302,7 +313,7 @@ public class ShareUtils {
//微信朋友圈分享
private void wechatMomentsSahre() {
Utils.toast(context, "分享跳转中...");
Utils.toast(mContext, "分享跳转中...");
WXWebpageObject webpage = new WXWebpageObject();
WXMediaMessage msg = new WXMediaMessage(webpage);
@ -339,7 +350,7 @@ public class ShareUtils {
//新浪微博分享
private void sinaWeiboSahre() {
Intent intent = new Intent(context, WeiBoShareActivity.class);
Intent intent = new Intent(mContext, WeiBoShareActivity.class);
Bundle bundle = new Bundle();
bundle.putString("shareNewsTitle", shareNewsTitle);
bundle.putString("shareIcon", shareIcon);
@ -349,7 +360,7 @@ public class ShareUtils {
bundle.putBoolean("ispopupWindow", ispopupWindow);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
mContext.startActivity(intent);
if (ispopupWindow) {
popupWindow.dismiss();
@ -379,9 +390,9 @@ public class ShareUtils {
try {
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(sendIntent);
mContext.startActivity(sendIntent);
} catch (Exception e) {
Utils.toast(context, "系统异常,分享失败");
Utils.toast(mContext, "系统异常,分享失败");
e.printStackTrace();
}
@ -396,24 +407,24 @@ public class ShareUtils {
//复制文字链接
private void copyLink(String copyContent) {
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipboardManager cmb = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
cmb.setText(copyContent);
if (ispopupWindow != null && ispopupWindow) {
Utils.toast(context, "复制成功");
Utils.toast(mContext, "复制成功");
popupWindow.dismiss();
} else {
Utils.toast(context, "复制成功,请到微信/QQ粘贴分享");
Utils.toast(mContext, "复制成功,请到微信/QQ粘贴分享");
}
}
private void loadBitMap(final String iconUrl, final WXMediaMessage msg, final SendMessageToWX.Req req) {
ImageUtils.getInstance().display(context, iconUrl, new BaseBitmapDataSubscriber() {
ImageUtils.getInstance().display(mContext, iconUrl, new BaseBitmapDataSubscriber() {
@Override
protected void onNewResultImpl(Bitmap bitmap) {
Bitmap compressBp = compressBitmap(bitmap);
Bitmap resultBp = addBackGround(compressBp);
msg.thumbData = Util.bmpToByteArray(resultBp, true);
api.sendReq(req);
mIWXAPI.sendReq(req);
}
@Override
@ -474,23 +485,23 @@ public class ShareUtils {
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(context, 90)));
LinearLayout linearLayout = new LinearLayout(mContext);
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(mContext, 90)));
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
linearLayout.setBackgroundResource(R.drawable.cardview_item_style);
ImageView shareLogo = new ImageView(context);
LinearLayout.LayoutParams logoParams = new LinearLayout.LayoutParams(DisplayUtils.dip2px(context, 45), DisplayUtils.dip2px(context, 45));
logoParams.setMargins(0, DisplayUtils.dip2px(context, 10), 0, 0);
ImageView shareLogo = new ImageView(mContext);
LinearLayout.LayoutParams logoParams = new LinearLayout.LayoutParams(DisplayUtils.dip2px(mContext, 45), DisplayUtils.dip2px(mContext, 45));
logoParams.setMargins(0, DisplayUtils.dip2px(mContext, 10), 0, 0);
shareLogo.setLayoutParams(logoParams);
TextView shareLabel = new TextView(context);
TextView shareLabel = new TextView(mContext);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(0, DisplayUtils.dip2px(context, 10), 0, 0);
layoutParams.setMargins(0, DisplayUtils.dip2px(mContext, 10), 0, 0);
shareLabel.setLayoutParams(layoutParams);
shareLabel.setGravity(Gravity.CENTER);
shareLabel.setTextColor(ContextCompat.getColor(context, R.color.text_3a3a3a));
shareLabel.setTextColor(ContextCompat.getColor(mContext, R.color.text_3a3a3a));
shareLabel.setTextSize(13);
linearLayout.addView(shareLogo);
@ -539,7 +550,7 @@ public class ShareUtils {
"光环助手官网地址:\n" +
"\n" +
"http://www.ghzhushou.com/link?source=appshare333");
context.startActivity(data);
mContext.startActivity(data);
}
break;
case 7: