diff --git a/README.md b/README.md index fdf0d49c52..76cc8ab993 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,23 @@ -# 光环助手 +# 光环助手Android客户端 + +### 多渠道打包配置 +* 使用[ApkChannelPackage](https://github.com/ltlovezh/ApkChannelPackage)的方案 + +* 正式打包命令:请使用./gradlew channelRelease打包渠道包 + +### 混淆配置 +* 配置文件:Android默认配置+proguard-rules.txt等 +* 参考libraries下每个项目独立的配置文件``proguard-project.txt`` + +### apk大小优化 +* 限制resConfig资源集 +* 开启ShrinkResources +* 开启混淆,使用minifyEnabled(仅在release开启) +* pngquant对png压缩、png/jpg->webp(未尝试) + +### 第三方appkey等配置 +* 修改``gradle.properties``文件将各种key填入其中,实现统一管理 +* 通过gradle文件内的resValue/buildConfigField/manifestPlaceHolder方式实现编译期间修改,具体情况请参考``./build.gradle``和``./app/build.gradle``配置 ### Ver 2.5 -* xxx \ No newline at end of file +* 此处写本次更新所做的业务和代码修改 diff --git a/app/build.gradle b/app/build.gradle index d8354f542b..fc765caa4e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,9 +2,12 @@ apply plugin: 'com.android.application' apply plugin: 'com.neenbedankt.android-apt' -//apply tinker插件 +//tinker插件 //apply plugin: 'com.tencent.tinker.patch' +// apkChannelPackage +apply plugin: 'channel' + android { compileOptions { @@ -42,12 +45,31 @@ android { multiDexEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt', 'proguard-fresco.txt' + + /** + * All third-party appid/appkey + */ + buildConfigField "String", "WECHAT_APPID", "\"${WECHAT_APPID}\"" + buildConfigField "String", "TENCENT_APPID", "\"${TENCENT_APPID}\"" + buildConfigField "String", "WEIBO_APPKEY", "\"${WEIBO_APPKEY}\"" + buildConfigField "String", "MIPUSH_APPID", "\"${MIPUSH_APPID}\"" + buildConfigField "String", "MIPUSH_APPKEY", "\"${MIPUSH_APPKEY}\"" + buildConfigField "String", "MTA_APPKEY", "\"${MTA_APPKEY}\"" + buildConfigField "String", "TD_APPID", "\"${TD_APPID}\"" + buildConfigField "String", "UMENG_APPKEY", "\"${UMENG_APPKEY}\"" + buildConfigField "String", "UMENG_MESSAGE_SECRET", "\"${UMENG_MESSAGE_SECRET}\"" + } + // gradle 2.2以上默认同时启用v1和v2(优先用于Android N) signingConfigs { debug { + v1SigningEnabled true + v2SigningEnabled true } release { + v1SigningEnabled true + v2SigningEnabled true } } @@ -68,44 +90,62 @@ android { } /** - * 多渠道打包 + * 多渠道打包,所有渠道值均通过java code设置 */ - productFlavors { - GH_100 {} - GH_101 {} - GH_102 {} - GH_103 {} - GH_104 {} - GH_106 {} - GH_107 {} - GH_108 {} - GH_109 {} - GH_110 {} - GH_111 {} - GH_113 {} - GH_114 {} - GH_115 {} - GH_116 {} - GH_117 {} - GH_118 {} - GH_119 {} - GH_120 {} - GH_121 {} - GH_123 {} - GH_127 {} - GH_200 {} - GH_201 {} - GH_202 {} - GH_203 {} - GH_204 {} - GH_205 {} - GH_222 {} - GH_307 {} - GH_TEST {} - } - productFlavors.all { flavor -> - flavor.manifestPlaceholders = [CHANNEL_VALUE: name]//命令 gradlew assembleRelease - } +// productFlavors { +// GH_100 {} +// GH_101 {} +// GH_102 {} +// GH_103 {} +// GH_104 {} +// GH_106 {} +// GH_107 {} +// GH_108 {} +// GH_109 {} +// GH_110 {} +// GH_111 {} +// GH_113 {} +// GH_114 {} +// GH_115 {} +// GH_116 {} +// GH_117 {} +// GH_118 {} +// GH_119 {} +// GH_120 {} +// GH_121 {} +// GH_123 {} +// GH_127 {} +// GH_200 {} +// GH_201 {} +// GH_202 {} +// GH_203 {} +// GH_204 {} +// GH_205 {} +// GH_222 {} +// GH_307 {} +// GH_TEST {} +// } +// productFlavors.all { flavor -> +// flavor.manifestPlaceholders = [CHANNEL_VALUE: name]//命令 gradlew assembleRelease +// } + +} + +// apkChannelPackage +channel { + //多渠道包的输出目录,默认为new File(project.buildDir,"channel") + baseOutputDir = new File(project.buildDir, "channel") + //多渠道包的命名规则,默认为:${appName}-${versionName}-${versionCode}-${flavorName}-${buildType} + apkNameFormat = '${appName}-${versionName}-${versionCode}-${flavorName}-${buildType}' +} + +rebuildChannel { +// baseDebugApk = 已有Debug APK +// baseReleaseApk = 已有Release APK +// //默认为new File(project.buildDir, "rebuildChannel/debug") +// debugOutputDir = Debug渠道包输出目录 +// //默认为new File(project.buildDir, "rebuildChannel/release") +// releaseOutputDir = Release渠道包输出目录 } dependencies { @@ -128,6 +168,8 @@ dependencies { compile libs.okHttp compile libs.okHttpLogInterceptor + compile libs.apkChannelPackage + // debugCompile libs.stetho // debugCompile libs.stethoWithOkHttp diff --git a/app/src/main/java/com/gh/base/AppController.java b/app/src/main/java/com/gh/base/AppController.java index 5f16ed250a..814fe1d288 100644 --- a/app/src/main/java/com/gh/base/AppController.java +++ b/app/src/main/java/com/gh/base/AppController.java @@ -7,10 +7,13 @@ import android.content.Context; import android.os.Process; import android.support.multidex.MultiDex; import android.support.v4.util.ArrayMap; +import android.text.TextUtils; import android.util.Log; import com.facebook.drawee.backends.pipeline.Fresco; +import com.gh.common.constant.Config; import com.gh.common.util.*; import com.gh.gamecenter.BuildConfig; +import com.leon.channel.helper.ChannelReaderUtil; import com.umeng.message.*; import com.xiaomi.channel.commonutils.logger.LoggerInterface; import com.xiaomi.mipush.sdk.*; @@ -22,10 +25,6 @@ import java.util.concurrent.Executors; public class AppController extends Application { public static final String TAG = AppController.class.getSimpleName(); - // TODO xiaomi push appid 2882303761517352993 - public static final String APP_ID = "2882303761517564447"; - // TODO xiaomi push appkey 5451735292993 - public static final String APP_KEY = "5761756481447"; public static final String KEY_FILE_INFO = "FileInfo"; //快传文件发送单线程 public static Executor FILE_SENDER_EXECUTOR = Executors.newSingleThreadExecutor(); @@ -34,6 +33,12 @@ public class AppController extends Application { private static AppController mInstance; private static ArrayMap objectMap = new ArrayMap<>(); + private String mChannel; + + public String getChannel() { + return mChannel; + } + public static void put(String key, Object object) { if (objectMap == null) { objectMap = new ArrayMap<>(); @@ -80,13 +85,9 @@ public class AppController extends Application { @Override public void onCreate() { super.onCreate(); - //初始化Fresco - Fresco.initialize(this); - DataUtils.init(this); MultiDex.install(this); - - HttpsUtils.initHttpsUrlConnection(this); + mInstance = this; //TODO 强烈不建议开发阶段开启这个Handler,必须处理错误 if (!BuildConfig.DEBUG) { @@ -94,7 +95,21 @@ public class AppController extends Application { Thread.setDefaultUncaughtExceptionHandler(appUncaughtHandler); } - mInstance = this; +// mChannel = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"); + mChannel = ChannelReaderUtil.getChannel(this); + if (TextUtils.isEmpty(mChannel)) { + //默认用Android Studio run时并没有写入channel magic number到apk包里面,所以需要fallback + mChannel = "GH_TEST"; + } + + Log.e("CHANNEL_ID", mChannel); + + //初始化Fresco + Fresco.initialize(this); + + DataUtils.init(this, BuildConfig.DEBUG, mChannel); + + HttpsUtils.initHttpsUrlConnection(this); // if (BuildConfig.DEBUG) { // Stetho.initializeWithDefaults(this); @@ -106,7 +121,7 @@ public class AppController extends Application { * 的{@link MiPushCommandMessage} 对象参数中获取注册信息 */ if (shouldInit()) { - MiPushClient.registerPush(this, APP_ID, APP_KEY); + MiPushClient.registerPush(this, Config.MIPUSH_APPID, Config.MIPUSH_APPKEY); } if (BuildConfig.DEBUG) { @@ -132,7 +147,7 @@ public class AppController extends Application { //友盟推送 final PushAgent pushAgent = PushAgent.getInstance(this); - + pushAgent.setAppkeyAndSecret(Config.UMENG_APPKEY, Config.UMENG_MESSAGE_SECRET); //注册推送服务,每次调用register方法都会回调该接口 pushAgent.register(new IUmengRegisterCallback() { diff --git a/app/src/main/java/com/gh/base/GHPushMessageReceiver.java b/app/src/main/java/com/gh/base/GHPushMessageReceiver.java index 39224c2323..f2b90b7a08 100644 --- a/app/src/main/java/com/gh/base/GHPushMessageReceiver.java +++ b/app/src/main/java/com/gh/base/GHPushMessageReceiver.java @@ -11,7 +11,6 @@ import android.os.Bundle; import android.support.v4.app.NotificationCompat; import android.support.v4.util.ArrayMap; import android.text.TextUtils; -import android.util.Log; import android.widget.RemoteViews; import com.gh.common.util.*; import com.gh.gamecenter.BuildConfig; @@ -48,20 +47,26 @@ import static com.gh.common.util.EntranceUtils.*; * //TODO 请勿更改此类路径,若需更改时请注意更改./libraries/MiPush/proguard-library.txt混淆对应配置 */ public class GHPushMessageReceiver extends PushMessageReceiver { + private String mAlias; @Override public void onReceivePassThroughMessage(Context context, MiPushMessage message) { + if (BuildConfig.DEBUG) { + AppDebugConfig.logMethodWithParams(this, message); + } // 1判断notifyid是否为4 try { + //TODO what is magic number 4? if (message.getNotifyId() == 4) { JSONObject jsonObject = new JSONObject(message.getContent()); Utils.log(jsonObject.toString()); String channel = jsonObject.getString("channel"); Utils.log("channel = " + channel); + // 1判断渠道号是否一致或是否为ALL - String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID"); - if ("ALL".equals(channel) || channel.equalsIgnoreCase(TD_CHANNEL_ID)) { + String packageChannel = AppController.getInstance().getChannel(); + if ("ALL".equals(channel) || channel.equalsIgnoreCase(packageChannel)) { String type = jsonObject.getString(KEY_TYPE); Utils.log("type = " + type); if ("NEWS".equals(type)) { @@ -93,8 +98,7 @@ public class GHPushMessageReceiver extends PushMessageReceiver { // 判断gh_version是否相同 if (gh_version.equals(apk.getString("gh_version"))) { // 判断version是否相同 - String version = PackageUtils.getVersionByPackage( - context, packageName); + String version = PackageUtils.getVersionByPackage(context, packageName); if (apk.getString("version").equals(version)) { // 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包 continue; @@ -115,8 +119,6 @@ public class GHPushMessageReceiver extends PushMessageReceiver { } catch (JSONException e) { e.printStackTrace(); } - - Log.v(AppController.TAG, "onReceivePassThroughMessage is called. " + message.toString()); } private void showNotification(Context context, JSONObject jsonObject, int id) throws JSONException { @@ -124,11 +126,9 @@ public class GHPushMessageReceiver extends PushMessageReceiver { intent.setAction("com.gh.gamecenter.NOTIFICATION"); intent.putExtra("notifyId", id); intent.putExtra("notifyData", jsonObject.toString()); - PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, - intent, PendingIntent.FLAG_ONE_SHOT); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_ONE_SHOT); - NotificationManager nManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); + NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.logo) @@ -139,28 +139,20 @@ public class GHPushMessageReceiver extends PushMessageReceiver { RemoteViews remoteViews = null; - if (Build.MANUFACTURER.equals("Meizu") - && (Build.MODEL.startsWith("m") - || Build.MODEL.startsWith("MX"))) { - remoteViews = new RemoteViews(context.getPackageName(), - R.layout.notification_meizu); - SimpleDateFormat format = new SimpleDateFormat("HH:mm", - Locale.getDefault()); + if (Build.MANUFACTURER.equals("Meizu") && + (Build.MODEL.startsWith("m") || Build.MODEL.startsWith("MX"))) { + remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_meizu); + SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); remoteViews.setTextViewText(R.id.time, format.format(new Date())); - } else if (Build.MANUFACTURER.equals("Xiaomi") - && (Build.MODEL.startsWith("MI") - || Build.MODEL.startsWith("HM") - || Build.MODEL.startsWith("Redmi"))) { + } else if (Build.MANUFACTURER.equals("Xiaomi") && + (Build.MODEL.startsWith("MI") || Build.MODEL.startsWith("HM") || Build.MODEL.startsWith("Redmi"))) { // 小米系统 - remoteViews = new RemoteViews(context.getPackageName(), - R.layout.notification_xiaomi); - SimpleDateFormat format = new SimpleDateFormat("ah:mm", - Locale.getDefault()); + remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_xiaomi); + SimpleDateFormat format = new SimpleDateFormat("ah:mm", Locale.getDefault()); remoteViews.setTextViewText(R.id.time, format.format(new Date())); } else if (Build.MANUFACTURER.equals("HUAWEI")) { // 华为系统 - remoteViews = new RemoteViews(context.getPackageName(), - R.layout.notification_huawei); + remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_huawei); } String url = jsonObject.getString("icon"); diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index aae6efefb6..bb7606d368 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -3,6 +3,7 @@ package com.gh.common.constant; import android.content.Context; import android.content.SharedPreferences; +import com.gh.gamecenter.BuildConfig; public class Config { @@ -14,6 +15,18 @@ public class Config { public static final String MESSAGE_HOST = "http://message.ghzhushou.com/v1d0/"; public static final String PREFERENCE = "ghzhushou"; + // Third-Party confs + public static final String WECHAT_APPID = BuildConfig.WECHAT_APPID; + public static final String TENCENT_APPID = BuildConfig.TENCENT_APPID; + public static final String WEIBO_APPKEY = BuildConfig.WEIBO_APPKEY; + public static final String MIPUSH_APPID = BuildConfig.MIPUSH_APPID; + public static final String MIPUSH_APPKEY = BuildConfig.MIPUSH_APPKEY; + public static final String MTA_APPKEY = BuildConfig.MTA_APPKEY; + public static final String TD_APPID = BuildConfig.TD_APPID;// TalkingData + public static final String UMENG_APPKEY = BuildConfig.UMENG_APPKEY; + public static final String UMENG_MESSAGE_SECRET = BuildConfig.UMENG_MESSAGE_SECRET; + + public static boolean isShow(Context context) { SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE); return sp.getBoolean("isShow", true); diff --git a/app/src/main/java/com/gh/common/util/DataLogUtils.java b/app/src/main/java/com/gh/common/util/DataLogUtils.java index 02d8683450..9a2d8c02c8 100644 --- a/app/src/main/java/com/gh/common/util/DataLogUtils.java +++ b/app/src/main/java/com/gh/common/util/DataLogUtils.java @@ -1,6 +1,7 @@ package com.gh.common.util; import android.content.Context; +import com.gh.base.AppController; import com.gh.download.DownloadEntity; import com.gh.gamecenter.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; @@ -22,7 +23,7 @@ public class DataLogUtils { public static void uploadLog(Context context, String topic, Map map) { String version = PackageUtils.getVersionName(context); String user = Installation.getUUID(context); - String channel = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID"); + String channel = AppController.getInstance().getChannel(); map.put("version", version); map.put("user", user); map.put("device_id", TokenUtils.getDeviceId(context)); diff --git a/app/src/main/java/com/gh/common/util/DataUtils.java b/app/src/main/java/com/gh/common/util/DataUtils.java index a528832b0b..378cb92337 100644 --- a/app/src/main/java/com/gh/common/util/DataUtils.java +++ b/app/src/main/java/com/gh/common/util/DataUtils.java @@ -1,8 +1,8 @@ package com.gh.common.util; import android.app.Activity; -import android.app.Application; import android.content.Context; +import com.gh.common.constant.Config; import com.tencent.stat.*; import com.tendcloud.tenddata.TCAgent; @@ -14,28 +14,40 @@ import java.util.*; */ public class DataUtils { - public static void init(Application application) { + /** + * 初始化各种统计工具,仅在release build(非debug)模式启用统计 + * + * @param context + * @param debug 是否debug模式 + * @param channel + */ + public static void init(Context context, final boolean debug, String channel) { + //TalkingData - //dubug true release false - TCAgent.LOG_ON = true; - TCAgent.init(application); - TCAgent.setReportUncaughtExceptions(true); + if (!debug) { + TCAgent.setReportUncaughtExceptions(true); + TCAgent.init(context, Config.TD_APPID, channel); + } else { + TCAgent.LOG_ON = true; + } //MTA - // 打开debug开关,可查看mta上报日志或错误 - // dubug true release false - StatConfig.setDebugEnable(true); - // 收集未处理的异常 - StatConfig.setAutoExceptionCaught(true); - // 设置数据上报策略 - StatConfig.setStatSendStrategy(StatReportStrategy.PERIOD); - StatConfig.setSendPeriodMinutes(5); - // 开启收集服务 - String TA_APPKEY = (String) PackageUtils.getMetaData(application, application.getPackageName(), "TA_APPKEY"); - try { - StatService.startStatService(application, TA_APPKEY, com.tencent.stat.common.StatConstants.VERSION); - } catch (MtaSDkException e) { - e.printStackTrace(); + if (!debug) { + // 收集未处理的异常 + StatConfig.setAutoExceptionCaught(true); + // 设置数据上报策略 + StatConfig.setStatSendStrategy(StatReportStrategy.PERIOD); + StatConfig.setSendPeriodMinutes(5); + try { + // 开启收集服务 + StatService.startStatService(context, Config.MTA_APPKEY, com.tencent.stat.common.StatConstants.VERSION); + } catch (MtaSDkException e) { + e.printStackTrace(); + } + } else { + // 打开debug开关,可查看mta上报日志或错误 + // dubug true release false + StatConfig.setDebugEnable(true); } } diff --git a/app/src/main/java/com/gh/common/util/MessageShareUtils.java b/app/src/main/java/com/gh/common/util/MessageShareUtils.java index 9840f9ee23..90ab36a25c 100644 --- a/app/src/main/java/com/gh/common/util/MessageShareUtils.java +++ b/app/src/main/java/com/gh/common/util/MessageShareUtils.java @@ -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 { + class ShareRecyclerViewAdapter extends RecyclerView.Adapter { @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; diff --git a/app/src/main/java/com/gh/common/util/ShareUtils.java b/app/src/main/java/com/gh/common/util/ShareUtils.java index 0a4503f088..f975703770 100644 --- a/app/src/main/java/com/gh/common/util/ShareUtils.java +++ b/app/src/main/java/com/gh/common/util/ShareUtils.java @@ -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: diff --git a/app/src/main/java/com/gh/gamecenter/MainActivity.java b/app/src/main/java/com/gh/gamecenter/MainActivity.java index 6eee6f2803..6132e0fe8a 100644 --- a/app/src/main/java/com/gh/gamecenter/MainActivity.java +++ b/app/src/main/java/com/gh/gamecenter/MainActivity.java @@ -12,13 +12,11 @@ import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.util.ArrayMap; import android.text.*; -import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.*; -import com.gh.base.BaseActivity; -import com.gh.base.SearchBarHint; +import com.gh.base.*; import com.gh.common.constant.Config; import com.gh.common.util.*; import com.gh.download.*; @@ -383,8 +381,6 @@ public class MainActivity extends BaseActivity implements OnClickListener { // 执行跳转事件 handler.postDelayed(skipRun, 500); - Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID")); - if (sp.getBoolean("changeDefaultIcon", false) && sp.getInt("default_user_icon", 0) != 0) { postDefaultIcon(true, sp.getInt("default_user_icon", 0), 1); } @@ -569,9 +565,9 @@ public class MainActivity extends BaseActivity implements OnClickListener { final String versionCode = PackageUtils.getVersionCode(MainActivity.this); final String versionName = PackageUtils.getVersionName(MainActivity.this); - final String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(MainActivity.this, getPackageName(), "TD_CHANNEL_ID"); + final String packageChannel = AppController.getInstance().getChannel(); if ((TextUtils.isEmpty(version_code) || TextUtils.isEmpty(version_name) || TextUtils.isEmpty(channel)) - || (!version_code.equals(versionCode) || !version_name.equals(versionName) || !channel.equals(TD_CHANNEL_ID))) { + || (!version_code.equals(versionCode) || !version_name.equals(versionName) || !channel.equals(packageChannel))) { TokenUtils.getToken(MainActivity.this, true) .flatMap(new Func1>() { @Override @@ -579,7 +575,7 @@ public class MainActivity extends BaseActivity implements OnClickListener { Map params = new ArrayMap<>(); params.put("version_code", versionCode); params.put("version_name", versionName); - params.put("channel", TD_CHANNEL_ID); + params.put("channel", packageChannel); RequestBody body = RequestBody.create(MediaType.parse("application/json"), new JSONObject(params).toString()); return RetrofitManager.getUser().postGhzs(token, body); @@ -592,7 +588,7 @@ public class MainActivity extends BaseActivity implements OnClickListener { SharedPreferences.Editor editor = sp.edit(); editor.putString("version_code", versionCode); editor.putString("version_name", versionName); - editor.putString("channel", TD_CHANNEL_ID); + editor.putString("channel", packageChannel); editor.apply(); } }); diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java index 25f36f85ea..3a50db5f45 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java @@ -12,6 +12,7 @@ import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.*; import android.widget.*; +import com.gh.base.AppController; import com.gh.base.BaseActivity; import com.gh.common.constant.Config; import com.gh.common.util.*; @@ -265,8 +266,8 @@ public class SplashScreenActivity extends BaseActivity { // 获取下载按钮显示状态 private void getDownloadStatus() { - String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"); - RetrofitManager.getApi().getDownloadStatus(PackageUtils.getVersionName(getApplicationContext()), TD_CHANNEL_ID) + String channel = AppController.getInstance().getChannel(); + RetrofitManager.getApi().getDownloadStatus(PackageUtils.getVersionName(getApplicationContext()), channel) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new JSONObjectResponse() { diff --git a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java index 8bdc61c489..5f42403fc6 100644 --- a/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SuggestionActivity.java @@ -16,6 +16,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.*; import butterknife.BindView; import butterknife.OnClick; +import com.gh.base.AppController; import com.gh.base.BaseActivity; import com.gh.common.constant.Config; import com.gh.common.util.*; @@ -424,7 +425,7 @@ public class SuggestionActivity extends BaseActivity implements SuggestTypeAdapt params.put("message", mSuggestContentEt.getText().toString().trim()); params.put("from", email); params.put("ghversion", PackageUtils.getVersionName(this)); - params.put("channel", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID")); + params.put("channel", AppController.getInstance().getChannel()); params.put("type", android.os.Build.MODEL); params.put("sdk", String.valueOf(android.os.Build.VERSION.SDK_INT)); params.put("version", android.os.Build.VERSION.RELEASE); diff --git a/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java b/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java index 4247f53df4..9a57840331 100644 --- a/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java +++ b/app/src/main/java/com/gh/gamecenter/WeiBoShareActivity.java @@ -9,6 +9,7 @@ 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.common.constant.Config; import com.gh.common.util.*; import com.sina.weibo.sdk.api.*; import com.sina.weibo.sdk.api.share.*; @@ -47,7 +48,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon Utils.toast(this, "分享跳转中..."); - mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(this, "1723629218"); + mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(this, Config.WEIBO_APPKEY); mWeiboShareAPI.registerApp(); weiboLoadBitMap(shareIcon); @@ -118,7 +119,7 @@ public class WeiBoShareActivity extends Activity implements IWeiboHandler.Respon request.transaction = String.valueOf(System.currentTimeMillis()); request.multiMessage = weiboMessage; - AuthInfo authInfo = new AuthInfo(WeiBoShareActivity.this, "1723629218", "https://api.weibo.com/oauth2/default.html", ""); + AuthInfo authInfo = new AuthInfo(WeiBoShareActivity.this, Config.WEIBO_APPKEY, "https://api.weibo.com/oauth2/default.html", ""); Oauth2AccessToken accessToken = AccessTokenKeeper.readAccessToken(WeiBoShareActivity.this); String token = ""; if (accessToken != null) { diff --git a/app/src/main/java/com/gh/gamecenter/manager/DataCollectionManager.java b/app/src/main/java/com/gh/gamecenter/manager/DataCollectionManager.java index 0f98def170..a83ecafe37 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/DataCollectionManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/DataCollectionManager.java @@ -1,6 +1,7 @@ package com.gh.gamecenter.manager; import android.content.Context; +import com.gh.base.AppController; import com.gh.common.constant.Config; import com.gh.common.util.*; import com.gh.gamecenter.db.DataCollectionDao; @@ -124,8 +125,7 @@ public class DataCollectionManager { private void realTimeUpload(final String type, Map map) { String version = PackageUtils.getVersionName(mContext); String user = Installation.getUUID(mContext); - String channel = (String) PackageUtils.getMetaData(mContext, - mContext.getPackageName(), "TD_CHANNEL_ID"); + String channel = AppController.getInstance().getChannel(); map.put("version", version); map.put("user", user); map.put("device_id", TokenUtils.getDeviceId(mContext)); @@ -199,8 +199,7 @@ public class DataCollectionManager { String version = PackageUtils.getVersionName(mContext); String user = Installation.getUUID(mContext); - String channel = (String) PackageUtils.getMetaData(mContext, - mContext.getPackageName(), "TD_CHANNEL_ID"); + String channel = AppController.getInstance().getChannel(); HashMap map = new HashMap<>(); DataCollectionInfo dataCollectionEntity; diff --git a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java index ac841ad0ce..19cde925c0 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java @@ -8,6 +8,7 @@ import android.text.Html; import android.view.View; import android.view.Window; import android.widget.*; +import com.gh.base.AppController; import com.gh.common.constant.Config; import com.gh.common.util.*; import com.gh.download.*; @@ -96,8 +97,8 @@ public class UpdateManager { if (!isCheck) { loadingDialog = DialogUtils.showWaitDialog(context, "检查更新中..."); } - String TD_CHANNEL_ID = (String) PackageUtils.getMetaData(context, context.getPackageName(), "TD_CHANNEL_ID"); - RetrofitManager.getApi().getUpdate(PackageUtils.getVersionName(context), TD_CHANNEL_ID) + String channel = AppController.getInstance().getChannel(); + RetrofitManager.getApi().getUpdate(PackageUtils.getVersionName(context), channel) .map(new Func1() { @Override public String call(AppEntity appEntity) { diff --git a/app/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java b/app/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java index c497ab6651..570f805f97 100644 --- a/app/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java +++ b/app/src/main/java/com/gh/gamecenter/wxapi/WXEntryActivity.java @@ -3,6 +3,7 @@ package com.gh.gamecenter.wxapi; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import com.gh.common.constant.Config; import com.gh.common.util.Utils; import com.tencent.mm.sdk.openapi.*; @@ -20,7 +21,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mWxApi = WXAPIFactory.createWXAPI(this, "wx3ffd0785fad18396", false); + mWxApi = WXAPIFactory.createWXAPI(this, Config.WECHAT_APPID, false); mWxApi.handleIntent(getIntent(), this); } diff --git a/build.gradle b/build.gradle index 7c32d1523b..1bfb361c8a 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,9 @@ buildscript { // classpath 'com.android.tools.build:gradle-experimental:0.6.0-alpha5' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // for tinker - classpath ('com.tencent.tinker:tinker-patch-gradle-plugin:1.7.9') + classpath 'com.tencent.tinker:tinker-patch-gradle-plugin:1.7.9' + // for apkChannelPackage https://github.com/ltlovezh/ApkChannelPackage + classpath 'com.leon.channel:plugin:1.0.4' } } @@ -34,11 +36,7 @@ subprojects { // for those defined in AndroidManifest.xml manifestPlaceholders = [ manifestApplicationId : "${applicationId}", - onesignal_app_id : "${ONESIGNAL_APP_ID}", - onesignal_google_project_number: "${ONESIGNAL_GOOGLE_PROJECT_NUMBER}", - facebook_app_id : "${FACEBOOK_APPID}", -// TA_APPKEY : "${MTA_APPKEY}", -// TA_INSTALL_CHANNEL : "${MTA_INSTALL_CHANNEL}" + tencentAppId : "${TENCENT_APPID}", ] } lintOptions.abortOnError false diff --git a/channel.txt b/channel.txt new file mode 100644 index 0000000000..9151d3f608 --- /dev/null +++ b/channel.txt @@ -0,0 +1,31 @@ +GH_TEST +GH_100 +GH_101 +GH_102 +GH_103 +GH_104 +GH_106 +GH_107 +GH_108 +GH_109 +GH_110 +GH_111 +GH_113 +GH_114 +GH_115 +GH_116 +GH_117 +GH_118 +GH_119 +GH_120 +GH_121 +GH_123 +GH_127 +GH_200 +GH_201 +GH_202 +GH_203 +GH_204 +GH_205 +GH_222 +GH_307 \ No newline at end of file diff --git a/dependencies.gradle b/dependencies.gradle index 9d337c063d..1507a414ee 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -57,6 +57,7 @@ ext { google_play_services = "8.4.0" tinker = "1.7.9" + apkChannelPackage = "1.0.4" //Test jUnit = '4.12' @@ -116,6 +117,7 @@ ext { google_location : "com.google.android.gms:play-services-location:${google_play_services}", tinker_anno : "com.tencent.tinker:tinker-android-anno:${tinker}", tinker_lib : "com.tencent.tinker:tinker-android-lib:${tinker}", + apkChannelPackage : "com.leon.channel:helper:${apkChannelPackage}", ] diff --git a/gradle.properties b/gradle.properties index 7936c18b76..96fea26527 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,15 +18,16 @@ org.gradle.parallel=true android.useDeprecatedNdk=true org.gradle.jvmargs=-Xmx2048m -XX\:MaxPermSize\=512m -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8 -API_APP_KEY=chhota_bheem_sea_race -API_APP_SECRET=WbnVL35GS6Bf9lp2 -ONESIGNAL_APP_ID=3093142e-cabe-4ec3-b82c-fbe9566ec35e -ONESIGNAL_GOOGLE_PROJECT_NUMBER=315153852022 -VUNGLE_KEY=56fc8a724a075fd70600004e -FACEBOOK_APPID=448897998640792 -FLURRY_KEY=W48K2YFTKWJZWV7ZNDQF -MTA_APPKEY=ACVFN2GM555T -# TODO xiaomi push appid 2882303761517352993 -MIPUSH_APP_ID = 2882303761517564447 -# TODO xiaomi push appkey 5451735292993 -MIPUSH_APP_KEY = 5761756481447 \ No newline at end of file + +MIPUSH_APPID=2882303761517564447 +MIPUSH_APPKEY=5761756481447 +WECHAT_APPID=wx3ffd0785fad18396 +TENCENT_APPID=1104659243 +WEIBO_APPKEY=1723629218 +MTA_APPKEY=APV567FTBS7J +TD_APPID=81DB144D555386A38A70B833537EC256 +UMENG_APPKEY=58e5b0b9c62dca35a00005e6 +UMENG_MESSAGE_SECRET=ca08596492f8a7fde2ab48dceab8c1f3 + +# for apkChannelPackage +channel_file=channel.txt diff --git a/libraries/MTA/src/main/AndroidManifest.xml b/libraries/MTA/src/main/AndroidManifest.xml index fd906263ce..04f73cc392 100644 --- a/libraries/MTA/src/main/AndroidManifest.xml +++ b/libraries/MTA/src/main/AndroidManifest.xml @@ -12,13 +12,12 @@ - - - + + + + + + - + - + - - - - + + + + - + - + - - - - + + + + + + + - - - - - + + + + + - + diff --git a/libraries/UmengPush/src/main/AndroidManifest.xml b/libraries/UmengPush/src/main/AndroidManifest.xml index 46a57fa428..d90c199599 100644 --- a/libraries/UmengPush/src/main/AndroidManifest.xml +++ b/libraries/UmengPush/src/main/AndroidManifest.xml @@ -24,18 +24,17 @@ - - - - - - + + + + + + + + + + - diff --git a/scripts/install_all.sh b/scripts/install_all.sh index fb4e091064..b36c5f5218 100644 --- a/scripts/install_all.sh +++ b/scripts/install_all.sh @@ -1,13 +1,24 @@ #!/bin/bash #CsHeng @2015.08.01 -#CWD=$(dirname $(readlink -f $0)) CWD=$(cd "$(dirname "$0")"; pwd) -VERSION=1.03 -DST="${CWD}/../channels/${VERSION}" -for entry in `find ${DST} -name '*apk'` +INPUT="${CWD}/../app/build/channel" +while getopts "s:0:" arg do - echo ready to install ${entry} + case ${arg} in + s) + INPUT=${OPTARG} + ;; + ?) + echo "unknown argument" + exit 1; + ;; + esac +done + +for entry in `find ${INPUT} -name '*apk'` +do + echo preparing to install ${entry} adb install -r ${entry} done