完善uc的代码
This commit is contained in:
parent
f8c016c722
commit
970b4e8ad8
@ -1,11 +1,11 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
compileSdkVersion 26
|
||||
defaultConfig {
|
||||
applicationId "com.hnjc.wjtx.aligames"
|
||||
minSdkVersion 18
|
||||
targetSdkVersion 28
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
versionName "1.0.0"
|
||||
ndk {
|
||||
@ -27,16 +27,17 @@ android {
|
||||
debug.setRoot('build-types/debug')
|
||||
release.setRoot('build-types/release')
|
||||
}
|
||||
buildToolsVersion '28.0.3'
|
||||
buildToolsVersion '26.0.3'
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
useLibrary 'org.apache.http.legacy'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.android.support:appcompat-v7:26.1.0'
|
||||
implementation 'com.android.volley:volley:1.1.1'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.jakewharton:butterknife:8.2.1'
|
||||
|
106
app/proguard-rules.pro
vendored
106
app/proguard-rules.pro
vendored
@ -1,90 +1,34 @@
|
||||
-keepattributes InnerClasses,Signature,Exceptions,Deprecated,*Annotation*
|
||||
-printmapping 'mapping.txt'
|
||||
# this is very dangerous that cause bug
|
||||
-ignorewarnings
|
||||
|
||||
-dontskipnonpubliclibraryclassmembers
|
||||
-dontshrink
|
||||
-dontoptimize
|
||||
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
|
||||
|
||||
-dontwarn android.**
|
||||
-dontwarn com.google.**
|
||||
-keep class android.** {*;}
|
||||
-keep class com.google.** {*;}
|
||||
-keep class com.android.** {*;}
|
||||
-dontwarn org.apache.**
|
||||
-keep class org.apache.** { *; }
|
||||
-keep class sun.misc.Unsafe { *; }
|
||||
-keep class com.google.** {*;}
|
||||
-keepclasseswithmembers class * extends cn.gundam.sdk.shell.even.SDKEventReceiver
|
||||
|
||||
-keep public class android.arch.core.internal.FastSafeIterableMap
|
||||
-keep public class android.arch.core.util.Function
|
||||
-keep public class android.arch.lifecycle.Lifecycle
|
||||
-keep public class android.arch.lifecycle.Observer
|
||||
-keep public class android.arch.lifecycle.ReportFragment
|
||||
-keep public class android.arch.lifecycle.ViewModel
|
||||
-keep public class android.support.v4.app.Fragment
|
||||
-keep public class android.support.annotation.AnimatorRes
|
||||
-keep public class android.support.v4.app.ActivityCompat
|
||||
-keep public class android.support.design.widget.CoordinatorLayout
|
||||
-keep public class android.support.v4.app.AppLaunchChecker
|
||||
-keep public class android.support.v4.app.BackStackState
|
||||
-keep class cn.uc.**{
|
||||
<methods>;
|
||||
<fields>;
|
||||
}
|
||||
-keep class cn.gundam.**{
|
||||
<methods>;
|
||||
<fields>;
|
||||
}
|
||||
-keep class android.**{
|
||||
<methods>;
|
||||
<fields>;
|
||||
}
|
||||
-keep class org.json.**{
|
||||
<methods>;
|
||||
<fields>;
|
||||
}
|
||||
|
||||
#-libraryjars libs/alipaySdk.jar
|
||||
-dontwarn com.alipay.**
|
||||
-keep class com.alipay.** {*;}
|
||||
-keep class com.ut.device.** {*;}
|
||||
-keep class com.ta.utdid2.** {*;}
|
||||
|
||||
#-libraryjars libs/eventbus-3.jar
|
||||
-keep class org.greenrobot.eventbus.** { *; }
|
||||
-keep class de.greenrobot.event.** { *; }
|
||||
-keep class de.greenrobot.dao.** {*;}
|
||||
|
||||
-keepclassmembers class ** {
|
||||
public void onEvent*(**);
|
||||
void onEvent*(**);
|
||||
}
|
||||
|
||||
-keepclassmembers class ** {
|
||||
@org.greenrobot.eventbus.Subscribe <methods>;
|
||||
}
|
||||
-keep enum org.greenrobot.eventbus.ThreadMode { *; }
|
||||
# Only required if you use AsyncExecutor
|
||||
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
|
||||
<init>(java.lang.Throwable);
|
||||
}
|
||||
#-libraryjars libs/wechat.jar
|
||||
-keep class com.tencent.** {*;}
|
||||
|
||||
#-libraryjars libs/glide.jar
|
||||
-keep class com.bumptech.glide.** {*;}
|
||||
|
||||
-dontwarn com.xiaomi.**
|
||||
-keep class com.xiaomi.** {*;}
|
||||
-keep class com.mi.** {*;}
|
||||
-keep class com.wali.** {*;}
|
||||
-keep class cn.com.wali.** {*;}
|
||||
-keep class miui.net.**{*;}
|
||||
-keep class org.xiaomi.** {*;}
|
||||
|
||||
|
||||
|
||||
#保留位于View类中的get和set方法
|
||||
-keepclassmembers public class * extends android.view.View{
|
||||
void set*(***);
|
||||
*** get*();
|
||||
}
|
||||
#保留在Activity中以View为参数的方法不变
|
||||
-keepclassmembers class * extends android.app.Activity{
|
||||
public void *(android.view.View);
|
||||
}
|
||||
#保留实现了Parcelable的类名不变,
|
||||
-keep class * implements android.os.Parcelable{
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
#保留R$*类中静态成员的变量名
|
||||
-keep class **.R$* {*;}
|
||||
|
||||
-dontwarn android.support.**
|
||||
-keep class **.R$styleable{*;}
|
||||
|
||||
-keep class com.hnjc.wjtx.aligames.** { *; }
|
||||
-dontwarn com.hnjc.wjtx.mi.**
|
||||
-dontwarn com.hnjc.wjtx.aligams.**
|
||||
|
||||
|
||||
-keep class org.egret.** { *; }
|
||||
|
@ -11,6 +11,7 @@ import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hnjc.wjtx.aligames.net.DownloadRunnable;
|
||||
import com.hnjc.wjtx.aligames.net.TaskInfo;
|
||||
@ -24,6 +25,16 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import cn.gundam.sdk.shell.even.SDKEventKey;
|
||||
import cn.gundam.sdk.shell.even.SDKEventReceiver;
|
||||
import cn.gundam.sdk.shell.even.Subscribe;
|
||||
import cn.gundam.sdk.shell.exception.AliLackActivityException;
|
||||
import cn.gundam.sdk.shell.open.ParamInfo;
|
||||
import cn.gundam.sdk.shell.open.UCOrientation;
|
||||
import cn.gundam.sdk.shell.param.SDKParamKey;
|
||||
import cn.gundam.sdk.shell.param.SDKParams;
|
||||
import cn.uc.gamesdk.UCGameSdk;
|
||||
|
||||
public class LaunchActivity extends Activity {
|
||||
private final String TAG = "LaunchActivity";
|
||||
private final String ZERO_VERSION = "0";
|
||||
@ -100,7 +111,35 @@ public class LaunchActivity extends Activity {
|
||||
requestPermissions(permissions, 111);
|
||||
}
|
||||
}
|
||||
compareVersions();
|
||||
ucNetworkAndInitUCGameSDK();
|
||||
UCGameSdk.defaultSdk().registerSDKEventReceiver(receiver);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void ucNetworkAndInitUCGameSDK() {
|
||||
//!!!在调用SDK初始化前进行网络检查
|
||||
//当前没有拥有网络
|
||||
ucSdkInit();//执行UCGameSDK初始化
|
||||
}
|
||||
|
||||
private void ucSdkInit() {
|
||||
ParamInfo gameParamInfo = new ParamInfo();
|
||||
|
||||
gameParamInfo.setGameId(UCSdkConfig.gameId);
|
||||
|
||||
gameParamInfo.setOrientation(UCOrientation.PORTRAIT);
|
||||
|
||||
SDKParams sdkParams = new SDKParams();
|
||||
sdkParams.put(SDKParamKey.GAME_PARAMS, gameParamInfo);
|
||||
|
||||
|
||||
|
||||
try {
|
||||
UCGameSdk.defaultSdk().initSdk(this, sdkParams);
|
||||
} catch (AliLackActivityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -301,6 +340,7 @@ public class LaunchActivity extends Activity {
|
||||
handler.removeCallbacksAndMessages(null);
|
||||
handler = null;
|
||||
}
|
||||
UCGameSdk.defaultSdk().unregisterSDKEventReceiver(receiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
@Override
|
||||
@ -309,5 +349,22 @@ public class LaunchActivity extends Activity {
|
||||
// 移除activity的移出场动画
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
ucNetworkAndInitUCGameSDK();
|
||||
}
|
||||
SDKEventReceiver receiver = new SDKEventReceiver() {
|
||||
@Subscribe(event = SDKEventKey.ON_INIT_SUCC)
|
||||
private void onInitSucc() {
|
||||
compareVersions();
|
||||
}
|
||||
|
||||
@Subscribe(event = SDKEventKey.ON_INIT_FAILED)
|
||||
private void onInitFailed(String data) {
|
||||
//初始化失败
|
||||
Toast.makeText(LaunchActivity.this, "init failed", Toast.LENGTH_SHORT).show();
|
||||
Log.i(TAG, "UC SDK init failed");
|
||||
ucNetworkAndInitUCGameSDK();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.hnjc.wjtx.aligames;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@ -24,13 +23,15 @@ import org.egret.egretnativeandroid.EgretNativeAndroid;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.gundam.sdk.shell.even.SDKEventKey;
|
||||
import cn.gundam.sdk.shell.even.SDKEventReceiver;
|
||||
import cn.gundam.sdk.shell.even.Subscribe;
|
||||
import cn.gundam.sdk.shell.exception.AliLackActivityException;
|
||||
import cn.gundam.sdk.shell.exception.AliNotInitException;
|
||||
import cn.gundam.sdk.shell.open.ParamInfo;
|
||||
import cn.gundam.sdk.shell.open.UCOrientation;
|
||||
import cn.gundam.sdk.shell.open.OrderInfo;
|
||||
import cn.gundam.sdk.shell.param.SDKParamKey;
|
||||
import cn.gundam.sdk.shell.param.SDKParams;
|
||||
import cn.uc.gamesdk.UCGameSdk;
|
||||
@ -80,16 +81,12 @@ public class MainActivity extends Activity {
|
||||
nativeAndroid.pause();
|
||||
showLoadingView();
|
||||
vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
ucNetworkAndInitUCGameSDK();
|
||||
UCGameSdk.defaultSdk().registerSDKEventReceiver(receiver);
|
||||
}
|
||||
public void startGame() {
|
||||
nativeAndroid.resume();
|
||||
}
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
ucNetworkAndInitUCGameSDK();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
@ -192,21 +189,18 @@ public class MainActivity extends Activity {
|
||||
nativeAndroid.setExternalInterface("@onError", message -> Log.e(TAG, "Get @onError: " + message));
|
||||
// 支付
|
||||
nativeAndroid.setExternalInterface("pay", message -> {
|
||||
|
||||
Log.i(TAG, "client pay: " + message);
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(message);
|
||||
String cpOrderId = jsonObject.getString("orderId");
|
||||
String productCode = jsonObject.getString("productCode");
|
||||
int count = jsonObject.getInt("count");
|
||||
//TODO: 平台的支付
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("errcode", 0);
|
||||
obj.put("errmsg", "");
|
||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put(SDKParamKey.CALLBACK_INFO, jsonObject.getString("callbackInfo"));
|
||||
paramMap.put(SDKParamKey.NOTIFY_URL, jsonObject.getString("notifyUrl"));
|
||||
paramMap.put(SDKParamKey.AMOUNT, jsonObject.getString("amount"));
|
||||
paramMap.put(SDKParamKey.CP_ORDER_ID, jsonObject.getString("cpOrderId"));
|
||||
paramMap.put(SDKParamKey.ACCOUNT_ID, jsonObject.getString("accountId"));
|
||||
paramMap.put(SDKParamKey.SIGN, jsonObject.getString("sign"));
|
||||
paramMap.put(SDKParamKey.SIGN_TYPE, jsonObject.getString("signType"));
|
||||
ucSdkPay(paramMap);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
} catch ( Exception e ) {
|
||||
@ -230,11 +224,30 @@ public class MainActivity extends Activity {
|
||||
*/
|
||||
nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
|
||||
Log.i(TAG, "Get reportRoleInfo: " + message);
|
||||
try {
|
||||
JSONObject data = new JSONObject(message);
|
||||
SDKParams sdkParams = new SDKParams();
|
||||
sdkParams.put(SDKParamKey.STRING_ROLE_ID, data.getString("userRoleId"));
|
||||
sdkParams.put(SDKParamKey.STRING_ROLE_NAME, data.getString("userRoleName"));
|
||||
sdkParams.put(SDKParamKey.LONG_ROLE_LEVEL, (long) data.getInt("userRoleLevel"));
|
||||
/**
|
||||
*角色创建时间,需要传递当前服务器时间,不可传递设备本地时间,值生成后保持唯一,且角色创建、升级、退出重登三个时机均需传递此参数
|
||||
**/
|
||||
sdkParams.put(SDKParamKey.LONG_ROLE_CTIME, data.getLong("roleCreateTime"));
|
||||
sdkParams.put(SDKParamKey.STRING_ZONE_ID, data.getString("serverId"));
|
||||
sdkParams.put(SDKParamKey.STRING_ZONE_NAME, data.getString("serverName"));
|
||||
UCGameSdk.defaultSdk().submitRoleData(this, sdkParams);
|
||||
// Toast.makeText(MainActivity.this,"submitData = "+sdkParams, Toast.LENGTH_SHORT).show();
|
||||
} catch (AliNotInitException | AliLackActivityException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
UCGameSdk.defaultSdk().unregisterSDKEventReceiver(receiver);
|
||||
receiver = null;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -266,30 +279,7 @@ public class MainActivity extends Activity {
|
||||
launchScreenImageView = null;
|
||||
}
|
||||
|
||||
public void ucNetworkAndInitUCGameSDK() {
|
||||
//!!!在调用SDK初始化前进行网络检查
|
||||
//当前没有拥有网络
|
||||
ucSdkInit();//执行UCGameSDK初始化
|
||||
}
|
||||
|
||||
private void ucSdkInit() {
|
||||
ParamInfo gameParamInfo = new ParamInfo();
|
||||
|
||||
gameParamInfo.setGameId(UCSdkConfig.gameId);
|
||||
|
||||
gameParamInfo.setOrientation(UCOrientation.PORTRAIT);
|
||||
|
||||
SDKParams sdkParams = new SDKParams();
|
||||
sdkParams.put(SDKParamKey.GAME_PARAMS, gameParamInfo);
|
||||
|
||||
|
||||
|
||||
try {
|
||||
UCGameSdk.defaultSdk().initSdk(this, sdkParams);
|
||||
} catch (AliLackActivityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void ucSdkLogin() {
|
||||
try {
|
||||
@ -301,32 +291,28 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private void ucSdkPay() {
|
||||
// Intent intent = new Intent(MainActivity.this, GamePayActivity.class);
|
||||
// MainActivity.this.startActivity(intent);
|
||||
private void ucSdkPay(Map<String, Object> paramMap) {
|
||||
try {
|
||||
|
||||
SDKParams sdkParams = new SDKParams();
|
||||
sdkParams.putAll(paramMap);
|
||||
|
||||
UCGameSdk.defaultSdk().pay(this, sdkParams);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// addOutputResult("charge failed - Exception: " + e.toString() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
SDKEventReceiver receiver = new SDKEventReceiver() {
|
||||
@Subscribe(event = SDKEventKey.ON_INIT_SUCC)
|
||||
private void onInitSucc() {
|
||||
|
||||
startGame();
|
||||
}
|
||||
|
||||
@Subscribe(event = SDKEventKey.ON_INIT_FAILED)
|
||||
private void onInitFailed(String data) {
|
||||
//初始化失败
|
||||
Toast.makeText(MainActivity.this, "init failed", Toast.LENGTH_SHORT).show();
|
||||
Log.i(TAG, "UC SDK init failed");
|
||||
ucNetworkAndInitUCGameSDK();
|
||||
}
|
||||
|
||||
@Subscribe(event = SDKEventKey.ON_LOGIN_SUCC)
|
||||
private void onLoginSucc(String sid) {
|
||||
Log.i(TAG, "UC onLoaginSucc: " + sid);
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("openid", sid);
|
||||
obj.put("token", "");
|
||||
obj.put("token", sid);
|
||||
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
@ -371,6 +357,40 @@ public class MainActivity extends Activity {
|
||||
Toast.makeText(MainActivity.this, desc, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Subscribe(event = SDKEventKey.ON_CREATE_ORDER_SUCC)
|
||||
private void onCreateOrderSucc(OrderInfo orderInfo) {
|
||||
if (orderInfo != null) {
|
||||
String txt = orderInfo.getOrderAmount() + "," + orderInfo.getOrderId() + "," + orderInfo.getPayWay();
|
||||
Log.i(TAG, "下单成功: " + txt + "\n");
|
||||
}
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("errcode", 0);
|
||||
obj.put("errmsg", "");
|
||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.i(TAG, "pay succ");
|
||||
}
|
||||
|
||||
@Subscribe(event = SDKEventKey.ON_PAY_USER_EXIT)
|
||||
private void onPayUserExit(OrderInfo orderInfo) {
|
||||
if (orderInfo != null) {
|
||||
String txt = orderInfo.getOrderAmount() + "," + orderInfo.getOrderId() + "," + orderInfo.getPayWay();
|
||||
// addOutputResult("页面关闭,订单信息: " + txt + "\n");
|
||||
}
|
||||
Log.i(TAG, "pay cancel");
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("errcode", 1);
|
||||
obj.put("errmsg", "user cancel");
|
||||
nativeAndroid.callExternalInterface("payResult", obj.toString());
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ org.gradle.jvmargs=-Xmx1536m
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
|
||||
android.injected.testOnly=false
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
#android.injected.testOnly=false
|
||||
#android.useAndroidX=true
|
||||
#android.enableJetifier=true
|
Loading…
x
Reference in New Issue
Block a user