Commit 1ab0b712 1ab0b7121fb4c1abee7d5e168326eb62380b9bf3 by jinwawa

add function about loading...

1 parent fb025a7b
......@@ -56,6 +56,14 @@ cc.Class({
},
},
start(){
// 第二步:场景加载之后,隐藏原生纯色背景View
// 这里延迟1秒是为了更好的体验,实际可以不用
this.scheduleOnce(() => {
this.hideNativeSplash();
}, 1);
},
onLoad: function () {
this._super();
this._scrollview = this.node.getComponent(cc.ScrollView);
......@@ -63,7 +71,7 @@ cc.Class({
this._oSceneContext._iPageIndex = 1;
this._oSceneContext._iCurrentLeftIndex = 0;
this._oInit = {};
this._iSceneStatus=0;
this._iSceneStatus = 0;
// this.checkUpdate(); //热更新检查是否有新版本 //放到初始化焦点框后
......@@ -293,9 +301,9 @@ cc.Class({
);
if (currentNode.getComponent(FocusInfo)) {
let fiBlock = currentNode.getComponent(FocusInfo); //弄tvlink
if(currentNode.name=="promotionItem_9fd6d854-2a72-42d5-a2c0-1ce824cf406c"){ //针对课程表搞出来一个tvlink
if (currentNode.name == "promotionItem_9fd6d854-2a72-42d5-a2c0-1ce824cf406c") { //针对课程表搞出来一个tvlink
fiBlock.setTVLink('{"click":[{"action":"ChangeScene","parameters":{"sceneName":"sceneClass"}}]}');
}else{
} else {
// fiBlock.setTVLink(currentRemote.tvlink);
fiBlock.setTVLink('{"click":[{"action":"ChangeScene","parameters":{"sceneName":"sceneCategory"}}]}');
}
......@@ -343,19 +351,19 @@ cc.Class({
//初始化焦点框
initFocus: function () {
this._aFocusTargets[1]=[];
this._aFocusTargets[1] = [];
let fiHotUpdateClose=cc.find('update/update_panel/close',this.node).addComponent(FocusInfo); //热更新关闭按钮
fiHotUpdateClose.init('',false,null,null,1.0);
this._aFocusTargets[1]['hot_update_close']=cc.find('update/update_panel/close',this.node);
let fiHotUpdateClose = cc.find('update/update_panel/close', this.node).addComponent(FocusInfo); //热更新关闭按钮
fiHotUpdateClose.init('', false, null, null, 1.0);
this._aFocusTargets[1]['hot_update_close'] = cc.find('update/update_panel/close', this.node);
let fiHotUpdateBtn=cc.find('update/update_panel/update_btn',this.node).addComponent(FocusInfo); //热更新按钮
fiHotUpdateBtn.init('',false,null,null,1.0);
this._aFocusTargets[1]['hot_update_btn']=cc.find('update/update_panel/update_btn',this.node);
let fiHotUpdateBtn = cc.find('update/update_panel/update_btn', this.node).addComponent(FocusInfo); //热更新按钮
fiHotUpdateBtn.init('', false, null, null, 1.0);
this._aFocusTargets[1]['hot_update_btn'] = cc.find('update/update_panel/update_btn', this.node);
let fiCloseBtn=cc.find('update/update_panel/close_btn',this.node).addComponent(FocusInfo); //热更新按钮
fiCloseBtn.init('',false,null,null,1.0);
this._aFocusTargets[1]['hot_close_btn']=cc.find('update/update_panel/close_btn',this.node);
let fiCloseBtn = cc.find('update/update_panel/close_btn', this.node).addComponent(FocusInfo); //热更新按钮
fiCloseBtn.init('', false, null, null, 1.0);
this._aFocusTargets[1]['hot_close_btn'] = cc.find('update/update_panel/close_btn', this.node);
var nodeInitFocus = cc.find(this._oSceneContext.focusPath, this.node);
// cc.log("初始化 "+nodeInitFocus.name);
......@@ -553,15 +561,15 @@ cc.Class({
case cc.macro.KEY.space:
case Common.ANDROID_KEY.enter:
if (0 == this._fiCurrentFocus.node.name.indexOf('close') || 0 == this._fiCurrentFocus.node.name.indexOf('close_btn')) {
this._iSceneStatus=0;
this._iSceneStatus = 0;
cc.find("update", this.node).active = false; //关闭更新面板
let fiAfterNode=cc.find(this._oSceneContext.focusPath,this.node).getComponent(FocusInfo); //热更新按钮
let fiAfterNode = cc.find(this._oSceneContext.focusPath, this.node).getComponent(FocusInfo); //热更新按钮
this._cFocus.flyFocus(this._fiCurrentFocus, fiAfterNode, Common.MOVE_DIRECTION_RIGHT, null, null);
}
else if(0 == this._fiCurrentFocus.node.name.indexOf('update_btn')){
else if (0 == this._fiCurrentFocus.node.name.indexOf('update_btn')) {
this.hotUpdate();
}
else{
else {
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
}
break;
......@@ -731,9 +739,9 @@ cc.Class({
this.panel.fileProgress.progress = 0;
// this.panel.byteProgress.progress = 0;
this._iSceneStatus=1; //焦点框跳转层级
this._iSceneStatus = 1; //焦点框跳转层级
cc.find("update", this.node).active = true; //显示出来更新面板
let fiHotUpdateBtn=cc.find('update/update_panel/update_btn',this.node).getComponent(FocusInfo); //热更新按钮
let fiHotUpdateBtn = cc.find('update/update_panel/update_btn', this.node).getComponent(FocusInfo); //热更新按钮
this._cFocus.flyFocus(this._fiCurrentFocus, fiHotUpdateBtn, Common.MOVE_DIRECTION_RIGHT, null, null);
break;
......@@ -776,8 +784,7 @@ cc.Class({
updateCb: function (event) {
var needRestart = false;
var failed = false;
switch (event.getEventCode())
{
switch (event.getEventCode()) {
case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
this.panel.info.string = 'No local manifest file found, hot update skipped.';
failed = true;
......@@ -849,4 +856,15 @@ cc.Class({
}
},
hideNativeSplash: function () {
if (cc.sys.os == cc.sys.OS_ANDROID) {
// 反射调用原生的隐藏方法
jsb.reflection.callStaticMethod(
"org/cocos2dx/javascript/AppActivity",
"hideSplash",
"()V"
);
}
}
});
......
......@@ -54,7 +54,7 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:usesCleartextTraffic="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:theme="@style/ImageSplashStyle"
android:launchMode="singleTask"
android:taskAffinity="" >
<intent-filter>
......
......@@ -138,4 +138,5 @@ dependencies {
implementation project(':libcocos2dx')
implementation files('libs/TopdrawSDK.jar')
implementation 'com.mcxiaoke.volley:library:+'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.7'
}
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loading"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/bg_loading" />
<pl.droidsonroids.gif.GifImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/loading" />
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ImageSplashStyle"
parent="@android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@drawable/bg_loading</item>
</style>
</resources>
\ No newline at end of file
......@@ -44,6 +44,9 @@ import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
......@@ -54,51 +57,34 @@ import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
public class AppActivity extends Cocos2dxActivity {
private static final String TAG="AppActivity";
private static final String TAG = "AppActivity";
private static AppActivity _activity;
private static View view=null;
private static View view = null;
private static View viewLoading = null;
public static final String ROOT_DIR = "/mnt/sdcard/mythroad11";
private UpdateManager mUpdateManager;
private int serverVersion ; //从服务器获取的版本号
private int clientVersion ; //客户端当前的版本号
private String serverVersionName ; //客户端当前的版本名称
private String apkDownloadUrl ; //apk下载地址
private int serverVersion; //从服务器获取的版本号
private int clientVersion; //客户端当前的版本号
private String serverVersionName; //客户端当前的版本名称
private String apkDownloadUrl; //apk下载地址
private static ImageView splashBgImageView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG,"网络链接:"+isNetworkAvalible(AppActivity.this));
if(!isNetworkAvalible(AppActivity.this)){
TextView msg = new TextView(AppActivity.this);
msg.setText(" 当前未连接网络,请设置网络后登陆!");
new AlertDialog.Builder(AppActivity.this)
.setIcon(R.mipmap.ic_launcher)
.setTitle("网络状态提示")
.setView(msg)
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
try {
new Thread().sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
AppActivity.this.finish();
System.exit(0);
android.os.Process.killProcess(android.os.Process.myPid());
}
}).create().show();
}
getClientCode();
checkNetwork(); //检查网络
getClientCode(); //检查升级
getServerCode();
_activity=this;
_activity = this;
TopdrawSDKWrapper.getInstance().init(this);
MyApplication.appActivity = this;
view= LayoutInflater.from(this).inflate(R.layout.activity_main,null);
//添加加载小游戏进度条
view = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
mFrameLayout.addView(view);
// Workaround in https://stackoverflow.com/questions/16283079/re-launch-of-activity-on-home-button-but-only-the-first-time/16447508
......@@ -112,6 +98,7 @@ public class AppActivity extends Cocos2dxActivity {
// DO OTHER INITIALIZATION BELOW
SDKWrapper.getInstance().init(this);
showSplash();
}
@Override
......@@ -201,9 +188,38 @@ public class AppActivity extends Cocos2dxActivity {
super.onStart();
}
public View getProgressBarView(){
public View getProgressBarView() {
return view;
}
//检查网络
private void checkNetwork() {
Log.d(TAG, "网络链接:" + isNetworkAvalible(AppActivity.this));
if (!isNetworkAvalible(AppActivity.this)) {
TextView msg = new TextView(AppActivity.this);
msg.setText(" 当前未连接网络,请设置网络后登陆!");
new AlertDialog.Builder(AppActivity.this)
.setIcon(R.mipmap.ic_launcher)
.setTitle("网络状态提示")
.setView(msg)
.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
try {
new Thread().sleep(2000);
} catch (Exception e) {
e.printStackTrace();
}
AppActivity.this.finish();
System.exit(0);
android.os.Process.killProcess(android.os.Process.myPid());
}
}).create().show();
}
}
private void getClientCode() {
try {
String pkName = this.getPackageName();
......@@ -211,11 +227,12 @@ public class AppActivity extends Cocos2dxActivity {
} catch (Exception e) {
e.printStackTrace();
clientVersion = -1;
}finally {
Log.v("zjn","---clientVersion:"+ clientVersion);
} finally {
Log.v("zjn", "---clientVersion:" + clientVersion);
}
}
private void getServerCode(){
private void getServerCode() {
VolleyUtil.instance(this).add(new JsonObjectRequest(Request.Method.GET, UpdateManager.UPDATE_CHECK_ENDPOINT, "",
new Response.Listener<JSONObject>() {
@Override
......@@ -227,7 +244,7 @@ public class AppActivity extends Cocos2dxActivity {
apkDownloadUrl = results.getJSONObject(0).getString("url");
String md5Str = results.getJSONObject(0).getString("hash_md5");
mUpdateManager = new UpdateManager(AppActivity.this);
mUpdateManager.showNoticeDialog(serverVersion,clientVersion,serverVersionName,apkDownloadUrl,md5Str);
mUpdateManager.showNoticeDialog(serverVersion, clientVersion, serverVersionName, apkDownloadUrl, md5Str);
} catch (Exception e) {
e.printStackTrace();
}
......@@ -239,6 +256,7 @@ public class AppActivity extends Cocos2dxActivity {
}
}));
}
public static boolean isNetworkAvalible(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
......@@ -257,4 +275,36 @@ public class AppActivity extends Cocos2dxActivity {
return false;
}
private static void showSplash() {
//搞启动黑屏问题
// splashBgImageView = new ImageView(_activity);
// splashBgImageView.setImageResource(R.drawable.bg_loading);
// _activity.addContentView(splashBgImageView,new WindowManager.LayoutParams(
// FrameLayout.LayoutParams.MATCH_PARENT,
// FrameLayout.LayoutParams.MATCH_PARENT
// ));
viewLoading = LayoutInflater.from(_activity).inflate(R.layout.activity_loading, null);
_activity.addContentView(viewLoading, new WindowManager.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
));
}
/**
* 这是给 CC JS 调用的隐藏原生开屏背景的方法
*/
public static void hideSplash() {
_activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// if (splashBgImageView != null) {
// splashBgImageView.setVisibility(View.GONE);
// }
if (viewLoading != null) {
viewLoading.setVisibility(View.GONE);
}
}
});
}
}
......
......@@ -277,6 +277,7 @@
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: __local_aars__:D.\LocalTopdrawSchool\build\jsb-link\frameworks\runtime-src\proj.android-studio\app\libs\TopdrawSDK.jar:unspecified@jar" level="project" />
<orderEntry type="library" name="Gradle: pl.droidsonroids.gif:android-gif-drawable:1.2.7@aar" level="project" />
<orderEntry type="library" name="Gradle: __local_aars__:D.\CocosCreator_2.0.10\resources\cocos2d-x\cocos\platform\android\java\libs\com.android.vending.expansion.zipfile.jar:unspecified@jar" level="project" />
<orderEntry type="library" name="Gradle: __local_aars__:D.\CocosCreator_2.0.10\resources\cocos2d-x\cocos\platform\android\java\libs\android-async-http-1.4.9.jar:unspecified@jar" level="project" />
<orderEntry type="library" name="Gradle: com.mcxiaoke.volley:library:1.0.19@jar" level="project" />
......
......@@ -5004,6 +5004,12 @@ type: cc.Asset,
default: null
}
},
start: function() {
var e = this;
this.scheduleOnce(function() {
e.hideNativeSplash();
}, 1);
},
onLoad: function() {
this._super();
this._scrollview = this.node.getComponent(cc.ScrollView);
......@@ -5499,6 +5505,9 @@ jsb.fileUtils.setSearchPaths(n);
cc.audioEngine.stopAll();
cc.game.restart();
}
},
hideNativeSplash: function() {
cc.sys.os == cc.sys.OS_ANDROID && jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "hideSplash", "()V");
}
});
cc._RF.pop();
......
// 在 main.js 的开头添加如下代码
if (jsb) {
var hotUpdateSearchPaths = localStorage.getItem('HotUpdateSearchPaths');
if (hotUpdateSearchPaths) {
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
}
}
// QQPlay window need to be inited first
if (false) {
BK.Script.loadlib('GameRes://libs/qqplay-adapter.js');
......
......@@ -23,7 +23,7 @@
"group-list": [
"default"
],
"last-module-event-record-time": 1568625456259,
"last-module-event-record-time": 1569319114648,
"simulator-orientation": false,
"simulator-resolution": {
"height": 640,
......