Compare commits

...

10 Commits
vivo ... master

Author SHA1 Message Date
zhl
32096e8d74 修正热更无法正常运行的bug 2020-12-23 19:52:33 +08:00
zhl
b2e58d4462 更新文档 2020-11-23 17:27:59 +08:00
zhl
c0e90edc9e 增加一些注释 2020-11-19 19:21:48 +08:00
zhl
e29648f328 增加登陆和支付回调的示例代码 2020-11-19 19:09:03 +08:00
zhl
36e83cdd26 修改退出流程 2020-11-19 17:52:25 +08:00
zhl
77dad4165f 更新gitignore 2020-11-19 16:05:07 +08:00
zhl
74f0323ebe 移除activity的切换动画 2020-11-19 15:11:38 +08:00
zhl
3e27e9cba7 增加角色上报功能 2020-11-19 11:35:26 +08:00
zhl
5ae3e1d729 升级gradle插件的版本 2020-11-19 11:11:26 +08:00
zhl
93c149afb6 增加游戏退出时的二次确认 2020-11-19 11:07:36 +08:00
11 changed files with 84 additions and 13 deletions

2
.gitignore vendored
View File

@ -10,4 +10,4 @@
/app/build/
/sdk/build/
/.idea/
/assets
/assets/game

View File

@ -6,4 +6,9 @@ key/publish_key
key store pass: 7654321Kingsome_
key alias: release
key pass: 7654321Kingsome_
vivo key alias: vivo
oppo key alias: oppo
xiaomi key alias: release
```

View File

@ -35,8 +35,8 @@ android {
}
dependencies {
implementation fileTree(include: '*.jar', dir: 'libs')
implementation(name: 'egret', ext: 'aar')
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.volley:volley:1.1.1'
implementation 'org.greenrobot:eventbus:3.2.0'
}

View File

@ -128,7 +128,7 @@ public class LaunchActivity extends Activity {
*/
private void getLocalVersionInfo() {
String fileName = gameUrl.replace("index.html", "version.json");
String realPath = getFileDirByUrl(fileName);
String realPath = preloadPath + "/" + getFileDirByUrl(fileName) + "version.json" ;
File versionFile = new File(realPath);
if (versionFile.exists()) {
JSONObject data = AssetsUtil.readJsonFromFile(this, realPath);
@ -198,7 +198,7 @@ public class LaunchActivity extends Activity {
});
}
private void preloadGame() {
String dir = preloadPath + getFileDirByUrl(gameUrl);
String dir = preloadPath + "/" + getFileDirByUrl(gameUrl);
File dirFile = new File(dir);
if (!dirFile.exists()) {
dirFile.mkdirs();
@ -257,8 +257,10 @@ public class LaunchActivity extends Activity {
}
private void startMain() {
Intent intent = new Intent(LaunchActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.putExtra("preloadPath", preloadPath);
startActivity(intent);
overridePendingTransition(0, 0);
finish();
}
@Override
@ -270,5 +272,10 @@ public class LaunchActivity extends Activity {
}
super.onDestroy();
}
@Override
public void finish() {
super.finish();
overridePendingTransition(0, 0);
}
}

View File

@ -1,6 +1,7 @@
package com.hnjc.wjtx;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
@ -16,6 +17,7 @@ import android.widget.ImageView;
import android.widget.Toast;
import com.hnjc.wjtx.util.AssetsUtil;
import com.hnjc.wjtx.util.IdUtil;
import com.hnjc.wjtx.util.StorageUtil;
import com.hnjc.wjtx.util.StringUtil;
@ -84,10 +86,24 @@ public class MainActivity extends Activity {
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
nativeAndroid.exitGame();
//声明并初始化弹出对象
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("提示:");
builder.setMessage("是否退出");
//设置确认按钮
builder.setNegativeButton("确定", (dialog, which) -> {
nativeAndroid.exitGame();
finish();//退出程序
});
//设置取消按钮
builder.setPositiveButton("取消",null);
//显示弹框
builder.show();
return true;
} else {
return super.onKeyDown(keyCode, keyEvent);
}
return super.onKeyDown(keyCode, keyEvent);
}
private void setExternalInterfaces() {
@ -148,6 +164,18 @@ public class MainActivity extends Activity {
});
nativeAndroid.setExternalInterface("getUid", message -> {
//TODO: 平台的登陆
JSONObject obj = new JSONObject();
try {
obj.put("openid", IdUtil.getUid(this));
obj.put("token", "");
// 如果其他登陆过程中的错误, 则传入一个大于0的errorcode
obj.put("errorcode", 1);
nativeAndroid.callExternalInterface("sendUidToJS", obj.toString());
} catch (JSONException e) {
e.printStackTrace();
nativeAndroid.callExternalInterface("loginCancel", "");
}
});
nativeAndroid.setExternalInterface("@onState", message -> {
Log.e(TAG, "Get @onState: " + message);
@ -171,12 +199,38 @@ public class MainActivity extends Activity {
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();
}
} catch (JSONException e) {
e.printStackTrace();
} catch ( Exception e ) {
e.printStackTrace();
}
});
/**
* isCreateRole: isNew,
* roleCreateTime: Date.now(),
* serverId: giant.Core.serverVO.id,
* serverName: giant.Core.serverVO.name,
* userRoleId: giant.Core.hero.id,
* userRoleName: giant.Core.hero.name,
* userRoleBalance: giant.Core.hero.coin,
* vipLevel: giant.Core.hero.vipLevel,
* userRoleLevel: giant.Core.hero.level,
* partyId: 0,
* partyName: giant.Core.hero.camp,
* gameRoleGender: giant.Core.hero.gender,
* gameRolePower: giant.Core.hero.power,
*/
nativeAndroid.setExternalInterface("reportRoleInfo", message -> {
Log.i(TAG, "Get reportRoleInfo: " + message);
});
}
@Override

View File

@ -12,6 +12,7 @@ import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -187,12 +188,15 @@ public class AssetsUtil {
*/
public static String readFromFile(Context context, String path) {
try {
InputStreamReader inputReader = new InputStreamReader(context.openFileInput(path));
FileInputStream fileInputStream = new FileInputStream(new File(path));
InputStreamReader inputReader = new InputStreamReader(fileInputStream);
BufferedReader bufReader = new BufferedReader(inputReader);
String line="";
StringBuilder result= new StringBuilder();
while((line = bufReader.readLine()) != null)
result.append(line);
fileInputStream.close();
inputReader.close();
bufReader.close();
return result.toString();

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@color/color_black"/>
<item android:drawable="@color/colorBlack"/>
<item>
<bitmap
android:gravity="center"

View File

@ -3,5 +3,6 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorBlack">#000000</color>
<color name="colorProgressBg">#32000000</color>
</resources>

View File

@ -3,7 +3,7 @@
<string name="load_game">下载游戏资源</string>
<string name="start_game">进入游戏</string>
<string name="preload_path">preload</string>
<string name="game_url">http://local/index.html</string>
<string name="game_url">http://local/index.html?channel=7103</string>
<string name="local_version">1.0.0</string>
<string name="load_back">load_back</string>
<string name="launch_version">获取游戏版本</string>

View File

@ -11,7 +11,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:4.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Mon Nov 16 13:55:33 CST 2020
#Thu Nov 19 11:09:11 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip