1、使用新的渠道打包方案,将渠道值写入到已经签名的apk上面,具体参考README.md
2、将各种第三方工具使用的appid、key和渠道值改成用gradle.properties的配置方式
This commit is contained in:
@ -13,6 +13,7 @@ import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.tencent.connect.share.QQShare;
|
||||
import com.tencent.mm.sdk.openapi.*;
|
||||
@ -28,19 +29,26 @@ import java.util.List;
|
||||
*/
|
||||
public class MessageShareUtils {
|
||||
private static MessageShareUtils instance;
|
||||
private static IWXAPI api;
|
||||
private static Tencent mTencent;
|
||||
private IWXAPI mIWXAPI;
|
||||
private Tencent mTencent;
|
||||
private Bitmap shareBm; //分享截图
|
||||
private String picName;
|
||||
private boolean isPlugin = false;
|
||||
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_save};
|
||||
private String[] arrLabel = {"微信好友", "朋友圈", "QQ好友", "QQ空间", "保存"};
|
||||
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_save
|
||||
};
|
||||
|
||||
private PopupWindow popupWindow;
|
||||
private String[] mArrLabel = {"微信好友", "朋友圈", "QQ好友", "QQ空间", "保存"};
|
||||
|
||||
private Context context;
|
||||
private PopupWindow mPopupWindow;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
//TODO 干掉activity,将context变成applicationcontext
|
||||
private Activity activity; // 用来关闭分享页面
|
||||
//QQ或者QQ空间分享回调处理
|
||||
public IUiListener QqShareListener = new IUiListener() {
|
||||
@ -48,19 +56,19 @@ public class MessageShareUtils {
|
||||
public void onComplete(Object o) {
|
||||
activity.finish();
|
||||
activity.overridePendingTransition(0, 0);//禁止退出Activity 动画
|
||||
Utils.toast(context, "分享成功");
|
||||
Utils.toast(mContext, "分享成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(UiError uiError) {
|
||||
Utils.toast(context, "分享失败");
|
||||
Utils.toast(mContext, "分享失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
activity.finish();
|
||||
activity.overridePendingTransition(0, 0);//禁止退出Activity 动画
|
||||
Utils.toast(context, "分享已取消");
|
||||
Utils.toast(mContext, "分享已取消");
|
||||
}
|
||||
};
|
||||
// 适配快传成绩单分享
|
||||
@ -74,14 +82,26 @@ public class MessageShareUtils {
|
||||
|
||||
public static MessageShareUtils getInstance(Context context) {
|
||||
if (instance == null) {
|
||||
instance = new MessageShareUtils();
|
||||
mTencent = Tencent.createInstance("1104659243", context); //初始化QQ分享
|
||||
api = WXAPIFactory.createWXAPI(context, "wx3ffd0785fad18396"); //初始化微信分享
|
||||
instance = new MessageShareUtils(context);
|
||||
}
|
||||
instance.context = context;
|
||||
return instance;
|
||||
}
|
||||
|
||||
private MessageShareUtils(Context context) {
|
||||
mTencent = Tencent.createInstance(Config.TENCENT_APPID, context); //初始化QQ分享
|
||||
mIWXAPI = WXAPIFactory.createWXAPI(context, Config.WECHAT_APPID); //初始化微信分享
|
||||
//TODO changed to application context
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public IWXAPI getIWXAPI() {
|
||||
return mIWXAPI;
|
||||
}
|
||||
|
||||
public Tencent getTencent() {
|
||||
return mTencent;
|
||||
}
|
||||
|
||||
//检查是否安装手机QQ
|
||||
public static boolean isQQClientAvailable(Context context) {
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
@ -109,7 +129,7 @@ public class MessageShareUtils {
|
||||
this.shareBm = bitmap;
|
||||
this.picName = picName;
|
||||
this.shareType = shareType;
|
||||
this.activity = (Activity) context;
|
||||
this.activity = (Activity) mContext;
|
||||
|
||||
if (shareType == 2) {
|
||||
contentSize = 75;
|
||||
@ -128,18 +148,18 @@ public class MessageShareUtils {
|
||||
|
||||
}
|
||||
|
||||
RelativeLayout contentView = new RelativeLayout(context);
|
||||
RelativeLayout contentView = new RelativeLayout(mContext);
|
||||
contentView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
contentView.setBackgroundColor(0x8c000000);
|
||||
contentView.setFocusable(true);
|
||||
contentView.setFocusableInTouchMode(true);
|
||||
|
||||
RecyclerView shareRecyclerView = new RecyclerView(context);
|
||||
shareRecyclerView.setPadding(DisplayUtils.dip2px(context, 10), DisplayUtils.dip2px(context, paddTop), DisplayUtils.dip2px(context, 10), 0);
|
||||
RecyclerView shareRecyclerView = new RecyclerView(mContext);
|
||||
shareRecyclerView.setPadding(DisplayUtils.dip2px(mContext, 10), DisplayUtils.dip2px(mContext, paddTop), DisplayUtils.dip2px(mContext, 10), 0);
|
||||
shareRecyclerView.setBackgroundColor(Color.WHITE);
|
||||
|
||||
//RecyclerView禁止滑动
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, gridCount) {
|
||||
GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, gridCount) {
|
||||
@Override
|
||||
public boolean canScrollVertically() {
|
||||
return false;
|
||||
@ -152,26 +172,26 @@ public class MessageShareUtils {
|
||||
if (shareType == 0 || shareType == 2) {
|
||||
LinearLayout llBottom = (LinearLayout) view;
|
||||
ViewGroup.LayoutParams layoutParams = llBottom.getLayoutParams();
|
||||
layoutParams.height = DisplayUtils.dip2px(context, contentSize);
|
||||
layoutParams.height = DisplayUtils.dip2px(mContext, contentSize);
|
||||
shareRecyclerView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
llBottom.addView(shareRecyclerView);
|
||||
return;
|
||||
}
|
||||
|
||||
RelativeLayout.LayoutParams rlParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT
|
||||
, DisplayUtils.dip2px(context, 106));
|
||||
, DisplayUtils.dip2px(mContext, 106));
|
||||
rlParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
||||
contentView.addView(shareRecyclerView, rlParams);
|
||||
|
||||
popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
mPopupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.MATCH_PARENT
|
||||
, LinearLayout.LayoutParams.MATCH_PARENT, true);
|
||||
popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
|
||||
popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
|
||||
mPopupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
|
||||
mPopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
|
||||
|
||||
contentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
popupWindow.dismiss();
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
@ -180,9 +200,9 @@ public class MessageShareUtils {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK
|
||||
&& event.getRepeatCount() == 0 && popupWindow != null
|
||||
&& popupWindow.isShowing()) {
|
||||
popupWindow.dismiss();
|
||||
&& event.getRepeatCount() == 0 && mPopupWindow != null
|
||||
&& mPopupWindow.isShowing()) {
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -191,43 +211,43 @@ public class MessageShareUtils {
|
||||
|
||||
//QQ分享
|
||||
private void qqSahre() {
|
||||
Utils.toast(context, "分享跳转中...");
|
||||
Utils.toast(mContext, "分享跳转中...");
|
||||
Bundle params = new Bundle();
|
||||
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
|
||||
QQShare.SHARE_TO_QQ_TYPE_IMAGE);
|
||||
params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, mContext.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "光环助手");
|
||||
params.putInt(QQShare.SHARE_TO_QQ_EXT_INT,
|
||||
QQShare.SHARE_TO_QQ_FLAG_QZONE_ITEM_HIDE);
|
||||
mTencent.shareToQQ(
|
||||
(Activity) context, params, QqShareListener);
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
(Activity) mContext, params, QqShareListener);
|
||||
if (mPopupWindow == null) return;
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
|
||||
//QQ空间分享
|
||||
private void qZoneSahre() {
|
||||
Utils.toast(context, "分享跳转中...");
|
||||
Utils.toast(mContext, "分享跳转中...");
|
||||
Bundle params = new Bundle();
|
||||
params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE,
|
||||
QQShare.SHARE_TO_QQ_TYPE_IMAGE);
|
||||
params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, mContext.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "光环助手");
|
||||
params.putInt(QQShare.SHARE_TO_QQ_EXT_INT,
|
||||
QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN);
|
||||
mTencent.shareToQQ(
|
||||
(Activity) context, params, QqShareListener);
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
(Activity) mContext, params, QqShareListener);
|
||||
if (mPopupWindow == null) return;
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
|
||||
//微信好友分享
|
||||
private void wechatSahre() {
|
||||
Utils.toast(context, "分享跳转中...");
|
||||
Utils.toast(mContext, "分享跳转中...");
|
||||
|
||||
//官方分享
|
||||
// WXImageObject imgObj = new WXImageObject();
|
||||
// imgObj.setImagePath(context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
// imgObj.setImagePath(mContext.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
// WXMediaMessage msg = new WXMediaMessage();
|
||||
// msg.mediaObject = imgObj;
|
||||
//
|
||||
@ -238,31 +258,31 @@ public class MessageShareUtils {
|
||||
//
|
||||
// Bitmap compressBp = compressBitmap(shareBm);
|
||||
// msg.thumbData = Util.bmpToByteArray(compressBp, true);
|
||||
// api.sendReq(req);
|
||||
// mIWXAPI.sendReq(req);
|
||||
|
||||
//调用手机系统分享
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("image/*");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + context.getExternalCacheDir().getPath() + "/ShareImg/" + picName));
|
||||
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + mContext.getExternalCacheDir().getPath() + "/ShareImg/" + picName));
|
||||
intent.setComponent(new ComponentName("com.tencent.mm", "com.tencent.mm.ui.tools.ShareImgUI"));
|
||||
context.startActivity(intent);
|
||||
mContext.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
Utils.toast(context, "分享失败!请检查是否已安装微信");
|
||||
Utils.toast(mContext, "分享失败!请检查是否已安装微信");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
if (mPopupWindow == null) return;
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
|
||||
//微信朋友圈分享
|
||||
private void wechatMomentsSahre() {
|
||||
Utils.toast(context, "分享跳转中...");
|
||||
Utils.toast(mContext, "分享跳转中...");
|
||||
|
||||
WXImageObject imgObj = new WXImageObject();
|
||||
imgObj.setImagePath(context.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
imgObj.setImagePath(mContext.getExternalCacheDir().getPath() + "/ShareImg/" + picName);
|
||||
WXMediaMessage msg = new WXMediaMessage();
|
||||
msg.mediaObject = imgObj;
|
||||
|
||||
@ -274,10 +294,10 @@ public class MessageShareUtils {
|
||||
|
||||
Bitmap compressBp = compressBitmap(shareBm);
|
||||
msg.thumbData = Util.bmpToByteArray(compressBp, true);
|
||||
api.sendReq(req);
|
||||
mIWXAPI.sendReq(req);
|
||||
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
if (mPopupWindow == null) return;
|
||||
mPopupWindow.dismiss();
|
||||
}
|
||||
|
||||
private String buildTransaction(final String type) {
|
||||
@ -335,9 +355,9 @@ public class MessageShareUtils {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, fos);
|
||||
}
|
||||
if (isToast) {
|
||||
Utils.toast(context, "成功保存到相册");
|
||||
Utils.toast(mContext, "成功保存到相册");
|
||||
//刷新手机图片库
|
||||
refreshImage(_file, context);
|
||||
refreshImage(_file, mContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -355,27 +375,27 @@ public class MessageShareUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public class ShareRecyclerViewAdapter extends RecyclerView.Adapter<ShareRecyclerViewAdapter.ViewHolder> {
|
||||
class ShareRecyclerViewAdapter extends RecyclerView.Adapter<ShareRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
@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, itemSize)));
|
||||
LinearLayout linearLayout = new LinearLayout(mContext);
|
||||
linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DisplayUtils.dip2px(mContext, itemSize)));
|
||||
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, picSize), DisplayUtils.dip2px(context, picSize));
|
||||
logoParams.setMargins(0, DisplayUtils.dip2px(context, 10), 0, 0);
|
||||
ImageView shareLogo = new ImageView(mContext);
|
||||
LinearLayout.LayoutParams logoParams = new LinearLayout.LayoutParams(DisplayUtils.dip2px(mContext, picSize), DisplayUtils.dip2px(mContext, picSize));
|
||||
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(marImg);
|
||||
|
||||
linearLayout.addView(shareLogo);
|
||||
@ -387,7 +407,7 @@ public class MessageShareUtils {
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
holder.shareLogo.setImageResource(arrLogo[position]);
|
||||
holder.shareLabel.setText(arrLabel[position]);
|
||||
holder.shareLabel.setText(mArrLabel[position]);
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@ -414,8 +434,8 @@ public class MessageShareUtils {
|
||||
String savePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/ghzhushou/";
|
||||
writeBitmap(savePath, "gh-" + new Date().getTime() + ".jpg", shareBm, true);
|
||||
|
||||
if (popupWindow == null) return;
|
||||
popupWindow.dismiss();
|
||||
if (mPopupWindow == null) return;
|
||||
mPopupWindow.dismiss();
|
||||
activity.finish();
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user