完善uc的代码

This commit is contained in:
zhl 2020-11-27 20:16:01 +08:00
parent f8c016c722
commit 970b4e8ad8
5 changed files with 173 additions and 151 deletions

View File

@ -1,11 +1,11 @@
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 28 compileSdkVersion 26
defaultConfig { defaultConfig {
applicationId "com.hnjc.wjtx.aligames" applicationId "com.hnjc.wjtx.aligames"
minSdkVersion 18 minSdkVersion 19
targetSdkVersion 28 targetSdkVersion 26
versionCode 1 versionCode 1
versionName "1.0.0" versionName "1.0.0"
ndk { ndk {
@ -27,16 +27,17 @@ android {
debug.setRoot('build-types/debug') debug.setRoot('build-types/debug')
release.setRoot('build-types/release') release.setRoot('build-types/release')
} }
buildToolsVersion '28.0.3' buildToolsVersion '26.0.3'
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
useLibrary 'org.apache.http.legacy'
} }
dependencies { dependencies {
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs') 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 'com.android.volley:volley:1.1.1'
implementation 'org.greenrobot:eventbus:3.2.0' implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.jakewharton:butterknife:8.2.1' implementation 'com.jakewharton:butterknife:8.2.1'

106
app/proguard-rules.pro vendored
View File

@ -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.** -keepclasseswithmembers class * extends cn.gundam.sdk.shell.even.SDKEventReceiver
-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.** {*;}
-keep public class android.arch.core.internal.FastSafeIterableMap -keep class cn.uc.**{
-keep public class android.arch.core.util.Function <methods>;
-keep public class android.arch.lifecycle.Lifecycle <fields>;
-keep public class android.arch.lifecycle.Observer }
-keep public class android.arch.lifecycle.ReportFragment -keep class cn.gundam.**{
-keep public class android.arch.lifecycle.ViewModel <methods>;
-keep public class android.support.v4.app.Fragment <fields>;
-keep public class android.support.annotation.AnimatorRes }
-keep public class android.support.v4.app.ActivityCompat -keep class android.**{
-keep public class android.support.design.widget.CoordinatorLayout <methods>;
-keep public class android.support.v4.app.AppLaunchChecker <fields>;
-keep public class android.support.v4.app.BackStackState }
-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.** { *; } -keep class com.hnjc.wjtx.aligames.** { *; }
-dontwarn com.hnjc.wjtx.mi.** -dontwarn com.hnjc.wjtx.aligams.**
-keep class org.egret.** { *; } -keep class org.egret.** { *; }

View File

@ -11,6 +11,7 @@ import android.os.Message;
import android.util.Log; import android.util.Log;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import com.hnjc.wjtx.aligames.net.DownloadRunnable; import com.hnjc.wjtx.aligames.net.DownloadRunnable;
import com.hnjc.wjtx.aligames.net.TaskInfo; import com.hnjc.wjtx.aligames.net.TaskInfo;
@ -24,6 +25,16 @@ import org.json.JSONObject;
import java.io.File; 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 { public class LaunchActivity extends Activity {
private final String TAG = "LaunchActivity"; private final String TAG = "LaunchActivity";
private final String ZERO_VERSION = "0"; private final String ZERO_VERSION = "0";
@ -100,7 +111,35 @@ public class LaunchActivity extends Activity {
requestPermissions(permissions, 111); 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.removeCallbacksAndMessages(null);
handler = null; handler = null;
} }
UCGameSdk.defaultSdk().unregisterSDKEventReceiver(receiver);
super.onDestroy(); super.onDestroy();
} }
@Override @Override
@ -309,5 +349,22 @@ public class LaunchActivity extends Activity {
// 移除activity的移出场动画 // 移除activity的移出场动画
overridePendingTransition(0, 0); 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();
}
};
} }

View File

@ -2,7 +2,6 @@ package com.hnjc.wjtx.aligames;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -24,13 +23,15 @@ import org.egret.egretnativeandroid.EgretNativeAndroid;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; 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.SDKEventKey;
import cn.gundam.sdk.shell.even.SDKEventReceiver; import cn.gundam.sdk.shell.even.SDKEventReceiver;
import cn.gundam.sdk.shell.even.Subscribe; import cn.gundam.sdk.shell.even.Subscribe;
import cn.gundam.sdk.shell.exception.AliLackActivityException; import cn.gundam.sdk.shell.exception.AliLackActivityException;
import cn.gundam.sdk.shell.exception.AliNotInitException; import cn.gundam.sdk.shell.exception.AliNotInitException;
import cn.gundam.sdk.shell.open.ParamInfo; import cn.gundam.sdk.shell.open.OrderInfo;
import cn.gundam.sdk.shell.open.UCOrientation;
import cn.gundam.sdk.shell.param.SDKParamKey; import cn.gundam.sdk.shell.param.SDKParamKey;
import cn.gundam.sdk.shell.param.SDKParams; import cn.gundam.sdk.shell.param.SDKParams;
import cn.uc.gamesdk.UCGameSdk; import cn.uc.gamesdk.UCGameSdk;
@ -80,16 +81,12 @@ public class MainActivity extends Activity {
nativeAndroid.pause(); nativeAndroid.pause();
showLoadingView(); showLoadingView();
vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
ucNetworkAndInitUCGameSDK();
UCGameSdk.defaultSdk().registerSDKEventReceiver(receiver); UCGameSdk.defaultSdk().registerSDKEventReceiver(receiver);
} }
public void startGame() { public void startGame() {
nativeAndroid.resume(); nativeAndroid.resume();
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ucNetworkAndInitUCGameSDK();
}
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
@ -192,21 +189,18 @@ public class MainActivity extends Activity {
nativeAndroid.setExternalInterface("@onError", message -> Log.e(TAG, "Get @onError: " + message)); nativeAndroid.setExternalInterface("@onError", message -> Log.e(TAG, "Get @onError: " + message));
// 支付 // 支付
nativeAndroid.setExternalInterface("pay", message -> { nativeAndroid.setExternalInterface("pay", message -> {
Log.i(TAG, "client pay: " + message);
try { try {
JSONObject jsonObject = new JSONObject(message); JSONObject jsonObject = new JSONObject(message);
String cpOrderId = jsonObject.getString("orderId"); Map<String, Object> paramMap = new HashMap<>();
String productCode = jsonObject.getString("productCode"); paramMap.put(SDKParamKey.CALLBACK_INFO, jsonObject.getString("callbackInfo"));
int count = jsonObject.getInt("count"); paramMap.put(SDKParamKey.NOTIFY_URL, jsonObject.getString("notifyUrl"));
//TODO: 平台的支付 paramMap.put(SDKParamKey.AMOUNT, jsonObject.getString("amount"));
JSONObject obj = new JSONObject(); paramMap.put(SDKParamKey.CP_ORDER_ID, jsonObject.getString("cpOrderId"));
try { paramMap.put(SDKParamKey.ACCOUNT_ID, jsonObject.getString("accountId"));
obj.put("errcode", 0); paramMap.put(SDKParamKey.SIGN, jsonObject.getString("sign"));
obj.put("errmsg", ""); paramMap.put(SDKParamKey.SIGN_TYPE, jsonObject.getString("signType"));
nativeAndroid.callExternalInterface("payResult", obj.toString()); ucSdkPay(paramMap);
} catch (JSONException e) {
e.printStackTrace();
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} catch ( Exception e ) { } catch ( Exception e ) {
@ -230,11 +224,30 @@ public class MainActivity extends Activity {
*/ */
nativeAndroid.setExternalInterface("reportRoleInfo", message -> { nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
Log.i(TAG, "Get 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 @Override
protected void onDestroy() { protected void onDestroy() {
UCGameSdk.defaultSdk().unregisterSDKEventReceiver(receiver);
receiver = null;
super.onDestroy(); super.onDestroy();
} }
@ -266,30 +279,7 @@ public class MainActivity extends Activity {
launchScreenImageView = null; 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() { private void ucSdkLogin() {
try { try {
@ -301,32 +291,28 @@ public class MainActivity extends Activity {
} }
} }
private void ucSdkPay() { private void ucSdkPay(Map<String, Object> paramMap) {
// Intent intent = new Intent(MainActivity.this, GamePayActivity.class); try {
// MainActivity.this.startActivity(intent);
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() { 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) @Subscribe(event = SDKEventKey.ON_LOGIN_SUCC)
private void onLoginSucc(String sid) { private void onLoginSucc(String sid) {
Log.i(TAG, "UC onLoaginSucc: " + sid);
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
try { try {
obj.put("openid", sid); obj.put("openid", sid);
obj.put("token", ""); obj.put("token", sid);
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString()); nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
@ -371,6 +357,40 @@ public class MainActivity extends Activity {
Toast.makeText(MainActivity.this, desc, Toast.LENGTH_SHORT).show(); 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();
}
}
}; };
} }

View File

@ -16,6 +16,6 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true # org.gradle.parallel=true
android.injected.testOnly=false #android.injected.testOnly=false
android.useAndroidX=true #android.useAndroidX=true
android.enableJetifier=true #android.enableJetifier=true