open source
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,69 @@
|
||||
import proguard.gradle.ProGuardTask
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
buildToolsVersion "28.0.0"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 28
|
||||
versionCode 17
|
||||
versionName "release-2.9.0"
|
||||
}
|
||||
sourceSets.main{
|
||||
jniLibs.srcDir 'libs'
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
testImplementation 'junit:junit:4.12'
|
||||
implementation 'com.android.support:appcompat-v7:25.3.1'
|
||||
}
|
||||
android {
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def SDK_BASENAME = "conch5";
|
||||
def SDK_VERSION = "_1.0";
|
||||
def sdkDestinationPath = "outJar";
|
||||
def zipFile = file('build/intermediates/packaged-classes/release/classes.jar');
|
||||
|
||||
def fromJar=sdkDestinationPath +"/"+ SDK_BASENAME + SDK_VERSION + ".jar";
|
||||
def toJar=sdkDestinationPath +"/"+ SDK_BASENAME + SDK_VERSION + "_min.jar";
|
||||
task deleteBuild(type: Delete) {
|
||||
delete fromJar
|
||||
}
|
||||
|
||||
|
||||
task conchUglify(type: ProGuardTask, dependsOn: "build") {
|
||||
// 未混淆的jar
|
||||
injars fromJar
|
||||
// 混淆后的jar路径
|
||||
outjars toJar
|
||||
// 具体需要keep住的类
|
||||
configuration 'proguard-rules.pro'
|
||||
}
|
||||
|
||||
|
||||
task conchMakeJar(type: Jar) {
|
||||
from zipTree(zipFile)
|
||||
//from fileTree(dir:'build/intermediates/classes/release',includes:['laya/**'])
|
||||
from fileTree(dir: 'src/main',includes: ['assets/**'])
|
||||
baseName = SDK_BASENAME + SDK_VERSION
|
||||
destinationDir = file(sdkDestinationPath)
|
||||
}
|
||||
|
||||
|
||||
conchMakeJar.dependsOn(deleteBuild, build)
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,45 @@
|
||||
-libraryjars 'C:\Users\fulong\AppData\Local\Android\Sdk\platforms\android-22\android.jar'
|
||||
|
||||
-dontusemixedcaseclassnames
|
||||
-keepattributes *Annotation*
|
||||
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||
-keep public class * extends android.preference.Preference
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
|
||||
-keep class layaair.game.PlatformInterface.** {*;}
|
||||
-keep class layaair.game.wrapper.** {*;}
|
||||
-keep class layaair.game.device.DevID {*;}
|
||||
-keep class layaair.game.browser.ConchJNI{*;}
|
||||
-keep class layaair.game.browser.ExportJavaFunction {*;}
|
||||
-keep class layaair.game.utility.ProcessInfo {*;}
|
||||
-keep class layaair.game.utility.LayaAudioMusic {*;}
|
||||
-keep class layaair.game.Notifycation.LayaNotifyManager {*;}
|
||||
-keep class layaair.game.conch.ILayaEventListener {*;}
|
||||
-keep class layaair.game.conch.ILayaGameEgine {*;}
|
||||
-keep class layaair.game.conch.LayaConch5 {*;}
|
||||
-keep class layaair.game.config.config {*;}
|
||||
-keep class layaair.game.browser.LayaVideoPlayer {*;}
|
||||
-dontwarn layaair.game.browser.LayaVideoPlayer
|
||||
|
||||
-keepclasseswithmembernames class *{
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class *{
|
||||
public <init>(android.content.Context,android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembers class *{
|
||||
public <init>(android.content.Context,android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
-keepclassmembers class * extends android.app.Activity{
|
||||
public void *(android.view.View);
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package layaair.game;
|
||||
|
||||
import android.app.Application;
|
||||
import android.test.ApplicationTestCase;
|
||||
|
||||
/**
|
||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
||||
*/
|
||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
||||
public ApplicationTest() {
|
||||
super(Application.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="layaair.game">
|
||||
|
||||
<application android:allowBackup="true"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name":"layaApp",
|
||||
"version":"1.0.1",
|
||||
"devUpdateUrl":"",
|
||||
"updateUrl":"http://engine.layabox.com/layaAppUpdate/layaApp/v2.1/",
|
||||
"updateDelay":0,
|
||||
"mainjs":"scripts/index.js"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,93 @@
|
||||
function async(gen) {
|
||||
"use strict";
|
||||
var log = console.log;
|
||||
var g = gen();
|
||||
let nr = null;
|
||||
function cast(value) {
|
||||
return value instanceof Promise && value.constructor === Promise ? value : new Promise(function () { });
|
||||
}
|
||||
function thennext(v) {
|
||||
nr = g.next(v);
|
||||
var p = nr.value;
|
||||
nr.done ? (0) : cast(p).then(thennext, function (e) { console.log('async reject:' + e); thennext(null); }).catch(function (r) {
|
||||
alert(`${r}
|
||||
${r.stack}`);
|
||||
});
|
||||
}
|
||||
thennext(void 0);
|
||||
}
|
||||
exports.async = async;
|
||||
//延时
|
||||
function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
exports.delay = delay;
|
||||
//下载图片
|
||||
function loadImage(src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var img = new Image();
|
||||
img.src = src;
|
||||
img.onload = () => { resolve(img); };
|
||||
img.onerror = () => {
|
||||
//reject('file load err:' + src);
|
||||
resolve(null);
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.loadImage = loadImage;
|
||||
//下载文本文件
|
||||
function loadText(src) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', src);
|
||||
xhr.onload = () => { resolve(xhr.responseText); };
|
||||
xhr.onerror = (e) => {
|
||||
//if (reject)
|
||||
// reject('download xhr error:' + src + '. e=' + e);
|
||||
resolve(null);
|
||||
};
|
||||
xhr.send();
|
||||
});
|
||||
}
|
||||
exports.loadText = loadText;
|
||||
function downloadSync(url, bin, onprog) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var f = new conch_File(url);
|
||||
var fr = new conch_FileReader();
|
||||
fr.setIgnoreError(true);
|
||||
fr.onload = () => {
|
||||
console.log('download end');
|
||||
resolve(fr.result);
|
||||
};
|
||||
fr.onerror = (e) => { console.log('onerror ' + e);
|
||||
//if (reject)
|
||||
// reject(e);
|
||||
resolve(null);
|
||||
};
|
||||
fr.onprogress = onprog;
|
||||
if (bin)
|
||||
fr.readAsArrayBuffer(f);
|
||||
else
|
||||
fr.readAsText(f);
|
||||
});
|
||||
}
|
||||
exports.downloadSync = downloadSync;
|
||||
//直到func返回true,tm是间隔
|
||||
function check(func, tm) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
function checkFunc() {
|
||||
if (func()) {
|
||||
clearInterval(chker);
|
||||
resolve(1);
|
||||
}
|
||||
}
|
||||
var chker = setInterval(checkFunc, tm);
|
||||
});
|
||||
}
|
||||
function regGlobal(window) {
|
||||
}
|
||||
exports.regGlobal = regGlobal;
|
||||
window['async'] = async;
|
||||
window['delay'] = delay;
|
||||
window['downloadSync'] = downloadSync;
|
||||
window['asynccheck'] = check;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
/*
|
||||
假装自己是nodejs
|
||||
*/
|
||||
|
||||
function _process(){
|
||||
this.pid=0;
|
||||
this.cwd=function(){
|
||||
return 'd:/temp';
|
||||
}
|
||||
this.mainModule = 'index.js';
|
||||
this.argv=['conch.exe','index.js'];
|
||||
this.version='1.3.1';
|
||||
this._require=function(f){console.log('process require('+f+')');return function nop(){};}; //不能真的load
|
||||
this._debugObject={};
|
||||
}
|
||||
|
||||
window.process = new _process();
|
||||
@@ -0,0 +1,356 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
window._conchInfo = { version: '2.1.3.1' };
|
||||
var _inline = !conchConfig.localizable;
|
||||
console.log('====================================================== ');
|
||||
console.log(' LAYA CONCH ');
|
||||
console.log(' runtimeversion:' + conchConfig.getRuntimeVersion());
|
||||
console.log(' jsversion:' + window._conchInfo.version);
|
||||
console.log(' isplug:' + conchConfig.getIsPlug());
|
||||
console.log('======================================================');
|
||||
function log(m) {
|
||||
console.log(m);
|
||||
}
|
||||
if (conchConfig.getOS() == "Conch-ios") {
|
||||
require('promise');
|
||||
}
|
||||
function loadLib(url) {
|
||||
var script = document.createElement("script");
|
||||
if (url.indexOf("laya.physics3D.js") >= 0) {
|
||||
url = url.replace("laya.physics3D.js", "laya.physics3D.runtime.js");
|
||||
}
|
||||
script.src = url;
|
||||
script.onerror = function () {
|
||||
if (window["onLayaInitError"]) {
|
||||
window["onLayaInitError"]("Load script error");
|
||||
}
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
window['loadLib'] = loadLib;
|
||||
const asyncs = require("async");
|
||||
function initFreeType() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var sOS = conchConfig.getOS();
|
||||
var bRet = false;
|
||||
var sTempFontPath = conch.getCachePath() + "/runtimeFont/";
|
||||
if (!fs_exists(sTempFontPath)) {
|
||||
fs_mkdir(sTempFontPath);
|
||||
}
|
||||
sTempFontPath += "layabox.ttf";
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(sTempFontPath);
|
||||
if (bRet == false) {
|
||||
var assetFontData = conch.readFileFromAsset('font/layabox.ttf', 'raw');
|
||||
if (assetFontData) {
|
||||
fs_writeFileSync(sTempFontPath, assetFontData);
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(sTempFontPath);
|
||||
}
|
||||
}
|
||||
if (!bRet) {
|
||||
if (sOS == "Conch-window") {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("C:/Windows/Fonts/simhei.ttf");
|
||||
}
|
||||
else if (sOS == "Conch-android") {
|
||||
var fSystemVersion = navigator.sv;
|
||||
if (fSystemVersion >= 2.0 && fSystemVersion < 5.0) {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("/system/fonts/DFHEIA5A.ttf");
|
||||
if (bRet == false) {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("/system/fonts/DroidSansFallback.ttf");
|
||||
}
|
||||
}
|
||||
else if (fSystemVersion >= 5.0 && fSystemVersion < 6.0) {
|
||||
var vDefaultStrings = [];
|
||||
vDefaultStrings.push("/system/fonts/NotoSansHans-Regular.otf");
|
||||
vDefaultStrings.push("/system/fonts/Roboto-Regular.ttf");
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(vDefaultStrings.join('|'));
|
||||
}
|
||||
else if (fSystemVersion >= 6.0 && fSystemVersion < 7.0) {
|
||||
var vDefaultStrings = [];
|
||||
vDefaultStrings.push("/system/fonts/NotoSansSC-Regular.otf");
|
||||
vDefaultStrings.push("/system/fonts/Roboto-Regular.ttf");
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(vDefaultStrings.join('|'));
|
||||
}
|
||||
else if (fSystemVersion >= 7.0 && fSystemVersion < 8.0) {
|
||||
bRet = false;
|
||||
}
|
||||
}
|
||||
else if (sOS == "Conch-ios") {
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile("");
|
||||
}
|
||||
}
|
||||
if (bRet == false) {
|
||||
log('字体初始化失败,从网络下载字体...');
|
||||
var data = (yield asyncs.downloadSync(location.fullpath + '/font/simhei.ttf', true, null));
|
||||
if (!data) {
|
||||
data = (yield asyncs.downloadSync('http://runtime.layabox.com/font/simhei.ttf', true, null));
|
||||
}
|
||||
if (!data) {
|
||||
alert('下载字体失败。 ');
|
||||
return;
|
||||
}
|
||||
fs_writeFileSync(sTempFontPath, data);
|
||||
bRet = _conchTextCanvas.initFreeTypeDefaultFontFromFile(sTempFontPath);
|
||||
}
|
||||
if (!bRet) {
|
||||
log('字体初始化失败。');
|
||||
}
|
||||
});
|
||||
}
|
||||
function setOrientation(s) {
|
||||
var nameToVal = {
|
||||
landscape: 0, portrait: 1, user: 2, behind: 3, sensor: 4, nosensor: 5, sensor_landscape: 6, sensorLandscape: 6,
|
||||
sensor_portrait: 7, sensorPortrait: 7, reverse_landscape: 8, reverseLandscape: 8, reverse_portrait: 9, reversePortrait: 9, full_sensor: 10, fullSensor: 10,
|
||||
};
|
||||
var nOri = (function (name) {
|
||||
try {
|
||||
var n = nameToVal[name];
|
||||
return n || 0;
|
||||
}
|
||||
catch (e) {
|
||||
return 0;
|
||||
}
|
||||
})(s);
|
||||
conchConfig.setScreenOrientation(nOri);
|
||||
;
|
||||
}
|
||||
Object.defineProperty(window, 'screenOrientation', {
|
||||
get: function () {
|
||||
return window.___screenOri;
|
||||
},
|
||||
set: function (v) {
|
||||
window.___screenOri = v;
|
||||
setOrientation(v);
|
||||
}
|
||||
});
|
||||
function startApp(data) {
|
||||
var jsonobj = null;
|
||||
try {
|
||||
jsonobj = JSON.parse(data);
|
||||
}
|
||||
catch (e) {
|
||||
console.log("Error:start page parse error! \n " + data);
|
||||
return;
|
||||
}
|
||||
jsonobj.scripts.forEach((v) => {
|
||||
var t = document.createElement("script");
|
||||
t["src"] = v;
|
||||
t.onerror = function () {
|
||||
if (window["onLayaInitError"]) {
|
||||
window["onLayaInitError"]("Load script error");
|
||||
}
|
||||
};
|
||||
document.head.appendChild(t);
|
||||
});
|
||||
if (jsonobj.screenOrientation)
|
||||
setOrientation(jsonobj.screenOrientation);
|
||||
else if (jsonobj.screenorientation)
|
||||
setOrientation(jsonobj.screenorientation);
|
||||
else
|
||||
setOrientation("sensor_landscape");
|
||||
document.createElement("script").text = "window.onload&&window.onload()";
|
||||
}
|
||||
function loadApp(url) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var urllen = url.length;
|
||||
if (urllen < 2)
|
||||
return;
|
||||
url = url.trim();
|
||||
if (url.substring(urllen - 1) === '/')
|
||||
url = url + 'runtime.json';
|
||||
url = url.replace(/.html$/i, '.json');
|
||||
if (url.indexOf('http://stand.alone.version') == 0)
|
||||
_inline = false;
|
||||
if (!_inline) {
|
||||
url = 'http://stand.alone.version/index.js';
|
||||
}
|
||||
console.log("loadApp:" + url);
|
||||
if (history.length <= 0) {
|
||||
history._push(url);
|
||||
}
|
||||
if (url.length < 2)
|
||||
return;
|
||||
location.setHref(url);
|
||||
var urlpath = location.fullpath + '/';
|
||||
var cache = window.appcache = new AppCache(urlpath);
|
||||
document.loadCookie();
|
||||
yield initFreeType();
|
||||
try {
|
||||
require("config");
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
var isDccOk = true;
|
||||
function updateDcc() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
cache.setResourceID('appurl', urlpath);
|
||||
var curassets = cache.getResourceID('netassetsid');
|
||||
var assetsidStr = (yield asyncs.downloadSync(urlpath + 'update/assetsid.txt?rand=' + Math.random() * Date.now(), false, null));
|
||||
console.log("assetsid old:" + curassets + " new:" + assetsidStr);
|
||||
if (!assetsidStr) {
|
||||
if (curassets && curassets != "") {
|
||||
if (window["onLayaInitError"]) {
|
||||
isDccOk = false;
|
||||
window["onLayaInitError"]("Update DCC get assetsid error");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (curassets != assetsidStr) {
|
||||
log('need update;');
|
||||
var txtdcc = '';
|
||||
var bindcc = yield asyncs.downloadSync(urlpath + 'update/filetable.bin?' + assetsidStr, true, null);
|
||||
if (!bindcc || !(bindcc instanceof ArrayBuffer)) {
|
||||
txtdcc = (yield asyncs.downloadSync(urlpath + 'update/filetable.txt?' + assetsidStr, false, null));
|
||||
}
|
||||
else {
|
||||
if (bindcc.byteLength % 8 != 0) {
|
||||
log('下载的的filetable.bin的长度不对。是不是错了。');
|
||||
}
|
||||
else {
|
||||
var v = new Uint32Array(bindcc);
|
||||
if (v[0] != 0xffeeddcc || v[1] != 1) {
|
||||
log('dcc.bin file err!');
|
||||
}
|
||||
else {
|
||||
if (v[2] == 0x00ffffff) {
|
||||
var stp = (4 + 8) / 2;
|
||||
var md5int = v.slice(4, 12);
|
||||
var md5char = new Uint8Array(md5int.buffer);
|
||||
var so = String.fromCharCode.apply(null, md5char);
|
||||
console.log('--------------------------------------------');
|
||||
console.log('so=' + so);
|
||||
console.log('netid=' + assetsidStr);
|
||||
if (so == assetsidStr) {
|
||||
for (var ii = stp, isz = v.length / 2; ii < isz; ii++)
|
||||
txtdcc += v[ii * 2].toString(16) + ' ' + v[ii * 2 + 1].toString(16) + '\n';
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('----------------old format');
|
||||
for (var ii = 1, isz = v.length / 2; ii < isz; ii++)
|
||||
txtdcc += v[ii * 2].toString(16) + ' ' + v[ii * 2 + 1].toString(16) + '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (txtdcc && txtdcc.length > 0) {
|
||||
cache.saveFileTable(txtdcc);
|
||||
window.appcache = cache = new AppCache(urlpath);
|
||||
cache.setResourceID('netassetsid', assetsidStr);
|
||||
}
|
||||
else {
|
||||
if (window["onLayaInitError"]) {
|
||||
isDccOk = false;
|
||||
window["onLayaInitError"]("Update DCC get filetable error");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (_inline) {
|
||||
yield updateDcc();
|
||||
if (!isDccOk) {
|
||||
console.log("init dcc fail");
|
||||
return;
|
||||
}
|
||||
}
|
||||
var data = yield asyncs.loadText(url);
|
||||
for (var n = 0; n < 3 && !data; n++) {
|
||||
data = yield asyncs.loadText(url);
|
||||
}
|
||||
if (!data) {
|
||||
if (window["loadingView"]) {
|
||||
window["loadingView"].setFontColor("#FF0000");
|
||||
window["loadingView"].setTips(['网络异常,请检查您的网络或与开发商联系。']);
|
||||
}
|
||||
data = cache.loadCachedURL(url);
|
||||
if (!data || data.length <= 0)
|
||||
if (window["onLayaInitError"]) {
|
||||
window["onLayaInitError"]("Load start url error");
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.log("");
|
||||
var qpos = url.indexOf('?');
|
||||
if (qpos < 0)
|
||||
qpos = url.length;
|
||||
if (url.substr(qpos - 3, 3) === '.js') {
|
||||
window.eval(data + `
|
||||
//@ sourceURL=${url}
|
||||
`);
|
||||
document.createElement("script").text = "window.onload&&window.onload()";
|
||||
}
|
||||
else {
|
||||
startApp(data);
|
||||
}
|
||||
if (window["loadingView"] && window["loadingView"].loadingAutoClose) {
|
||||
window["loadingView"].hideLoadingView();
|
||||
}
|
||||
});
|
||||
}
|
||||
window.document.addEventListener('keydown', function (e) {
|
||||
switch (e.keyCode) {
|
||||
case 116:
|
||||
reloadJS(true);
|
||||
break;
|
||||
case 117:
|
||||
history.back();
|
||||
break;
|
||||
case 118:
|
||||
break;
|
||||
case 119:
|
||||
break;
|
||||
case 120:
|
||||
gc();
|
||||
break;
|
||||
}
|
||||
});
|
||||
window.loadConchUrl = loadApp;
|
||||
window['updateByZip'] = function (url, onEvent, onEnd) {
|
||||
let cachePath = conch.getCachePath();
|
||||
let localfile = cachePath + url.substr(url.lastIndexOf('/'));
|
||||
downloadBigFile(url, localfile, (total, now, speed) => {
|
||||
onEvent('downloading', Math.floor((now / total) * 100), null);
|
||||
return false;
|
||||
}, (curlret, httpret) => {
|
||||
if (curlret != 0 || httpret < 200 || httpret >= 300) {
|
||||
onEvent('downloadError');
|
||||
}
|
||||
else {
|
||||
onEvent('downloadOK');
|
||||
let zip = new ZipFile();
|
||||
if (zip.setSrc(localfile)) {
|
||||
zip.forEach((id, name, dir, sz) => {
|
||||
if (!dir) {
|
||||
let buf = zip.readFile(id);
|
||||
let fid = window.appcache.hashstr('/' + name);
|
||||
if (window.appcache.updateFile(fid, 0, buf, false)) {
|
||||
onEvent('updating', null, name);
|
||||
}
|
||||
else {
|
||||
onEvent("updateError", null, name);
|
||||
}
|
||||
}
|
||||
});
|
||||
zip.close();
|
||||
if (onEnd)
|
||||
onEnd(localfile);
|
||||
}
|
||||
else {
|
||||
console.log("set zip src error!");
|
||||
onEvent('unknownError');
|
||||
}
|
||||
}
|
||||
}, 10, 100000000);
|
||||
};
|
||||
loadApp(conch.presetUrl || "http://nativetest.layabox.com/layaplayer2.0.1/index.js");
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
exports._load=function(jsf){
|
||||
return function(obj){};
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
window = this;
|
||||
window.conch_File=File;
|
||||
window.conch_FileReader = FileReader;
|
||||
|
||||
(function () {
|
||||
function file2path(p) {
|
||||
if (!p) return null;
|
||||
var lastpos = Math.max(p.lastIndexOf('/'),
|
||||
p.lastIndexOf('\\'));
|
||||
var ret = lastpos < 0 ? p : p.substr(0, lastpos);
|
||||
return ret.replace(/\\/g, '/');
|
||||
}
|
||||
var mcache = {};
|
||||
/*起始路径总是这里,如果需要改变的话,就在这里通过require跳转。*/
|
||||
window.requireOrig = function (file) {
|
||||
function evalreq(fc, fid) {/*return function*/
|
||||
if (!fc || fc.length <= 0) return null;
|
||||
/*注意:并不是window.eval所以脚本中不能假设当前是在window上下文*/
|
||||
try {
|
||||
//注意 fc后面要加\n来关掉行注释
|
||||
var func = eval('(function(exports,global,require,__dirname,__filename){' + fc + ';\nreturn exports;})\n//@ sourceURL=' + fid);
|
||||
mcache[fid] = func;
|
||||
return func;
|
||||
}
|
||||
catch (e) {
|
||||
_console.log(1,'require error:' + e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var mod = { dir: this.dir, file: file };
|
||||
if (file.substr(file.length - 3) != '.js')
|
||||
file += '.js';
|
||||
/*优先读取外部的*/
|
||||
var extfile = null;
|
||||
if (file.charAt(1) === ':' || file.charAt(0) === '/') { extfile = file; }
|
||||
else extfile = this.dir ? (this.dir + '/' + file) : null;
|
||||
var extfunc = null;
|
||||
_console.log(3,'require(' + extfile + ')');
|
||||
var reqresult = mcache[extfile] ||
|
||||
(extfunc = evalreq(readFileSync(extfile, 'utf8'), extfile)) ||
|
||||
mcache[file] ||
|
||||
evalreq(readTextAsset('scripts/' + file), file);
|
||||
if (extfunc) {
|
||||
mod.dir = file2path(extfile);/*使用window的或者当前模块的*/
|
||||
mod.file = extfile;
|
||||
}
|
||||
if (!reqresult) {
|
||||
throw ('require failed:' + file);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
var ret = reqresult({}, window, window.requireOrig.bind(mod), mod.dir, mod.file);
|
||||
return ret;
|
||||
}
|
||||
catch (e) {
|
||||
var err = 'eval script error in require:\n ' + file + '\n' + e.stack;
|
||||
_console.log(1,err);
|
||||
throw err;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
var exepath = file2path(getExePath());
|
||||
window.require = window.requireOrig.bind({ dir: exepath ? (exepath + '/scripts') : '/sdcard/layabox/scripts', file: null })
|
||||
})();
|
||||
@@ -0,0 +1,453 @@
|
||||
var UNIFORM_TYPE;
|
||||
(function (UNIFORM_TYPE) {
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1F"] = 0] = "INTERIOR_UNIFORM1F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1FV"] = 1] = "INTERIOR_UNIFORM1FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1I"] = 2] = "INTERIOR_UNIFORM1I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM1IV"] = 3] = "INTERIOR_UNIFORM1IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2F"] = 4] = "INTERIOR_UNIFORM2F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2FV"] = 5] = "INTERIOR_UNIFORM2FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2I"] = 6] = "INTERIOR_UNIFORM2I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM2IV"] = 7] = "INTERIOR_UNIFORM2IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3F"] = 8] = "INTERIOR_UNIFORM3F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3FV"] = 9] = "INTERIOR_UNIFORM3FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3I"] = 10] = "INTERIOR_UNIFORM3I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM3IV"] = 11] = "INTERIOR_UNIFORM3IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4F"] = 12] = "INTERIOR_UNIFORM4F";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4FV"] = 13] = "INTERIOR_UNIFORM4FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4I"] = 14] = "INTERIOR_UNIFORM4I";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORM4IV"] = 15] = "INTERIOR_UNIFORM4IV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMMATRIX2FV"] = 16] = "INTERIOR_UNIFORMMATRIX2FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMMATRIX3FV"] = 17] = "INTERIOR_UNIFORMMATRIX3FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMMATRIX4FV"] = 18] = "INTERIOR_UNIFORMMATRIX4FV";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMSAMPLER_2D"] = 19] = "INTERIOR_UNIFORMSAMPLER_2D";
|
||||
UNIFORM_TYPE[UNIFORM_TYPE["INTERIOR_UNIFORMSAMPLER_CUBE"] = 20] = "INTERIOR_UNIFORMSAMPLER_CUBE";
|
||||
})(UNIFORM_TYPE || (UNIFORM_TYPE = {}));
|
||||
var ARRAY_BUFFER_PARAM_TYPE;
|
||||
(function (ARRAY_BUFFER_PARAM_TYPE) {
|
||||
ARRAY_BUFFER_PARAM_TYPE[ARRAY_BUFFER_PARAM_TYPE["ARRAY_BUFFER_REF_REFERENCE"] = 0] = "ARRAY_BUFFER_REF_REFERENCE";
|
||||
ARRAY_BUFFER_PARAM_TYPE[ARRAY_BUFFER_PARAM_TYPE["ARRAY_BUFFER_REF_COPY"] = 1] = "ARRAY_BUFFER_REF_COPY";
|
||||
})(ARRAY_BUFFER_PARAM_TYPE || (ARRAY_BUFFER_PARAM_TYPE = {}));
|
||||
var UPLOAD_SHADER_UNIFORM_TYPE;
|
||||
(function (UPLOAD_SHADER_UNIFORM_TYPE) {
|
||||
UPLOAD_SHADER_UNIFORM_TYPE[UPLOAD_SHADER_UNIFORM_TYPE["UPLOAD_SHADER_UNIFORM_TYPE_ID"] = 0] = "UPLOAD_SHADER_UNIFORM_TYPE_ID";
|
||||
UPLOAD_SHADER_UNIFORM_TYPE[UPLOAD_SHADER_UNIFORM_TYPE["UPLOAD_SHADER_UNIFORM_TYPE_DATA"] = 1] = "UPLOAD_SHADER_UNIFORM_TYPE_DATA";
|
||||
})(UPLOAD_SHADER_UNIFORM_TYPE || (UPLOAD_SHADER_UNIFORM_TYPE = {}));
|
||||
var ARRAY_BUFFER_TYPE;
|
||||
(function (ARRAY_BUFFER_TYPE) {
|
||||
ARRAY_BUFFER_TYPE[ARRAY_BUFFER_TYPE["ARRAY_BUFFER_TYPE_DATA"] = 0] = "ARRAY_BUFFER_TYPE_DATA";
|
||||
ARRAY_BUFFER_TYPE[ARRAY_BUFFER_TYPE["ARRAY_BUFFER_TYPE_CMD"] = 1] = "ARRAY_BUFFER_TYPE_CMD";
|
||||
})(ARRAY_BUFFER_TYPE || (ARRAY_BUFFER_TYPE = {}));
|
||||
class conchFloatArrayKeyframe {
|
||||
constructor() {
|
||||
this._nativeObj = new _conchFloatArrayKeyframe();
|
||||
}
|
||||
set time(value) {
|
||||
this._nativeObj.setTime(value);
|
||||
}
|
||||
get time() {
|
||||
return this._nativeObj.getTime();
|
||||
}
|
||||
set data(value) {
|
||||
this._data = value;
|
||||
this._nativeObj.setData(value);
|
||||
}
|
||||
get data() {
|
||||
return this._data;
|
||||
}
|
||||
set inTangent(value) {
|
||||
this._inTangent = value;
|
||||
this._nativeObj.setInTangent(this._inTangent);
|
||||
}
|
||||
get inTangent() {
|
||||
return this._inTangent;
|
||||
}
|
||||
set outTangent(value) {
|
||||
this._outTangent = value;
|
||||
this._nativeObj.setOutTangent(this._outTangent);
|
||||
}
|
||||
get outTangent() {
|
||||
return this._outTangent;
|
||||
}
|
||||
set value(v) {
|
||||
this._value = v;
|
||||
this._nativeObj.setValue(this._value);
|
||||
}
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
clone() {
|
||||
let pDestObj = new conchFloatArrayKeyframe();
|
||||
this.cloneTo(pDestObj);
|
||||
return pDestObj;
|
||||
}
|
||||
cloneTo(destObj) {
|
||||
destObj.inTangent = this._inTangent.slice();
|
||||
destObj.outTangent = this._outTangent.slice();
|
||||
destObj.value = this._value.slice();
|
||||
destObj.data = this._data.slice();
|
||||
}
|
||||
}
|
||||
window["conchFloatArrayKeyframe"] = conchFloatArrayKeyframe;
|
||||
class conchKeyframeNode {
|
||||
constructor() {
|
||||
this._keyFrameArray = [];
|
||||
this._type = 0;
|
||||
this._setKeyframeByIndex = function (index, keyframe) {
|
||||
this._keyFrameArray[index] = keyframe;
|
||||
if (keyframe instanceof (conchFloatArrayKeyframe)) {
|
||||
this._nativeObj._setKeyframeByIndex1(index, keyframe._nativeObj);
|
||||
}
|
||||
else {
|
||||
this._nativeObj._setKeyframeByIndex0(index, keyframe);
|
||||
}
|
||||
};
|
||||
this._nativeObj = new _conchKeyframeNode();
|
||||
}
|
||||
set data(value) {
|
||||
this._data = value;
|
||||
this._nativeObj.setFloat32ArrayData(this._data.elements);
|
||||
}
|
||||
get data() {
|
||||
return this._type == 0 ? this._nativeObj.getFloatData() : this._data;
|
||||
}
|
||||
get indexInList() {
|
||||
return this._nativeObj._indexInList;
|
||||
}
|
||||
set indexInList(value) {
|
||||
this._nativeObj._indexInList = value;
|
||||
}
|
||||
get type() {
|
||||
return this._type;
|
||||
}
|
||||
set type(type) {
|
||||
this._type = type;
|
||||
this._nativeObj.type = type;
|
||||
}
|
||||
get fullPath() {
|
||||
return this._nativeObj.fullPath;
|
||||
}
|
||||
set fullPath(path) {
|
||||
this._nativeObj.fullPath = path;
|
||||
}
|
||||
get propertyOwner() {
|
||||
return this._nativeObj.propertyOwner;
|
||||
}
|
||||
set propertyOwner(value) {
|
||||
this._nativeObj.propertyOwner = value;
|
||||
}
|
||||
get ownerPathCount() {
|
||||
return this._nativeObj.ownerPathCount;
|
||||
}
|
||||
set ownerPathCount(value) {
|
||||
this._nativeObj.ownerPathCount = value;
|
||||
}
|
||||
get propertyCount() {
|
||||
return this._nativeObj.propertyCount;
|
||||
}
|
||||
set propertyCount(value) {
|
||||
this._nativeObj.propertyCount = value;
|
||||
}
|
||||
get keyFramesCount() {
|
||||
return this._keyFrameArray.length;
|
||||
}
|
||||
set keyFramesCount(value) {
|
||||
this._keyFrameArray.length = value;
|
||||
this._nativeObj.keyFramesCount = value;
|
||||
}
|
||||
getOwnerPathCount() {
|
||||
return this._nativeObj.getOwnerPathCount();
|
||||
}
|
||||
_setOwnerPathCount(value) {
|
||||
this._nativeObj._setOwnerPathCount(value);
|
||||
}
|
||||
getPropertyCount() {
|
||||
return this._nativeObj.getPropertyCount();
|
||||
}
|
||||
_setPropertyCount(value) {
|
||||
this._nativeObj._setPropertyCount(value);
|
||||
}
|
||||
getKeyFramesCount() {
|
||||
return this._keyFrameArray.length;
|
||||
}
|
||||
_setKeyframeCount(value) {
|
||||
this._keyFrameArray.length = value;
|
||||
this._nativeObj._setKeyframeCount(value);
|
||||
}
|
||||
getOwnerPathByIndex(index) {
|
||||
return this._nativeObj.getOwnerPathByIndex(index);
|
||||
}
|
||||
_setOwnerPathByIndex(index, value) {
|
||||
this._nativeObj._setOwnerPathByIndex(index, value);
|
||||
}
|
||||
getPropertyByIndex(index) {
|
||||
return this._nativeObj.getPropertyByIndex(index);
|
||||
}
|
||||
_setPropertyByIndex(index, value) {
|
||||
this._nativeObj._setPropertyByIndex(index, value);
|
||||
}
|
||||
getKeyframeByIndex(index) {
|
||||
return this._nativeObj.getKeyframeByIndex(index);
|
||||
}
|
||||
_joinOwnerPath(sep) {
|
||||
return this._nativeObj._joinOwnerPath(sep);
|
||||
}
|
||||
_joinProperty(sep) {
|
||||
return this._nativeObj._joinProperty(sep);
|
||||
}
|
||||
}
|
||||
window["conchKeyframeNode"] = conchKeyframeNode;
|
||||
class conchKeyframeNodeList {
|
||||
constructor() {
|
||||
this._nodes = [];
|
||||
this._nativeObj = new _conchKeyframeNodeList();
|
||||
}
|
||||
set count(value) {
|
||||
this._nodes.length = value;
|
||||
this._nativeObj.setCount(value);
|
||||
}
|
||||
get count() {
|
||||
return this._nodes.length;
|
||||
}
|
||||
getNodeByIndex(index) {
|
||||
return this._nodes[index];
|
||||
}
|
||||
setNodeByIndex(index, node) {
|
||||
this._nodes[index] = node;
|
||||
this._nativeObj.setNodeByIndex(index, node._nativeObj);
|
||||
}
|
||||
}
|
||||
window["conchKeyframeNodeList"] = conchKeyframeNodeList;
|
||||
class _GLCommandEncoder {
|
||||
constructor(gl, reserveSize, adjustSize, isSyncToRenderThread) {
|
||||
this._adjustSize = 0;
|
||||
this._byteLen = 0;
|
||||
this._isSyncToRenderThread = false;
|
||||
this._isSyncToRenderThread = isSyncToRenderThread;
|
||||
this._layagl = gl;
|
||||
this._byteLen = reserveSize;
|
||||
this._adjustSize = adjustSize;
|
||||
this._init(isSyncToRenderThread);
|
||||
}
|
||||
_init(isSyncToRenderThread) {
|
||||
this._buffer = new ArrayBuffer(this._byteLen);
|
||||
this._idata = new Int32Array(this._buffer);
|
||||
this._fdata = new Float32Array(this._buffer);
|
||||
this._byteArray = new Uint8Array(this._buffer);
|
||||
this._layagl.createArrayBufferRef(this._buffer, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_CMD, isSyncToRenderThread);
|
||||
this._idata[0] = 1;
|
||||
}
|
||||
getAlignLength(data) {
|
||||
var byteLength = data.byteLength;
|
||||
return (byteLength + 3) & 0xfffffffc;
|
||||
}
|
||||
getPtrID() {
|
||||
return this._buffer["_ptrID"];
|
||||
}
|
||||
clearEncoding() {
|
||||
this._idata[0] = 1;
|
||||
}
|
||||
getCount() {
|
||||
return this._idata[0];
|
||||
}
|
||||
_need(sz) {
|
||||
if ((this._byteLen - (this._idata[0] << 2)) >= sz)
|
||||
return;
|
||||
this._byteLen += (sz > this._adjustSize) ? sz : this._adjustSize;
|
||||
var pre = this._idata;
|
||||
var preConchRef = this._buffer["conchRef"];
|
||||
var prePtrID = this._buffer["_ptrID"];
|
||||
this._buffer = new ArrayBuffer(this._byteLen);
|
||||
this._idata = new Int32Array(this._buffer);
|
||||
this._fdata = new Float32Array(this._buffer);
|
||||
this._byteArray = new Uint8Array(this._buffer);
|
||||
this._buffer["conchRef"] = preConchRef;
|
||||
this._buffer["_ptrID"] = prePtrID;
|
||||
pre && this._idata.set(pre, 0);
|
||||
webglPlus.updateArrayBufferRef(this._buffer["_ptrID"], preConchRef.isSyncToRender(), this._buffer);
|
||||
}
|
||||
addShaderUniform(one) {
|
||||
var funID = 0;
|
||||
var isArray = one.isArray;
|
||||
switch (one.type) {
|
||||
case _GLCommandEncoder.INT:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM1IV : UNIFORM_TYPE.INTERIOR_UNIFORM1I;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM1FV : UNIFORM_TYPE.INTERIOR_UNIFORM1F;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_VEC2:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM2FV : UNIFORM_TYPE.INTERIOR_UNIFORM2F;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_VEC3:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM3FV : UNIFORM_TYPE.INTERIOR_UNIFORM3F;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_VEC4:
|
||||
funID = isArray ? UNIFORM_TYPE.INTERIOR_UNIFORM4FV : UNIFORM_TYPE.INTERIOR_UNIFORM4F;
|
||||
break;
|
||||
case _GLCommandEncoder.SAMPLER_2D:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMSAMPLER_2D;
|
||||
break;
|
||||
case _GLCommandEncoder.SAMPLER_CUBE:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMSAMPLER_CUBE;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_MAT4:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMMATRIX4FV;
|
||||
break;
|
||||
case _GLCommandEncoder.BOOL:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORM1I;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_MAT2:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMMATRIX2FV;
|
||||
break;
|
||||
case _GLCommandEncoder.FLOAT_MAT3:
|
||||
funID = UNIFORM_TYPE.INTERIOR_UNIFORMMATRIX3FV;
|
||||
break;
|
||||
default:
|
||||
throw new Error("compile shader err!");
|
||||
}
|
||||
this._layagl.syncBufferToRenderThread(this._buffer);
|
||||
this.add_iiiiii(3, funID, one.location.id, one.type, one.dataOffset, one.textureID);
|
||||
}
|
||||
add_iiiiii(a, b, c, d, e, f) {
|
||||
this._need(24);
|
||||
var idata = this._idata;
|
||||
var i = idata[0];
|
||||
idata[i++] = a;
|
||||
idata[i++] = b;
|
||||
idata[i++] = c;
|
||||
idata[i++] = d;
|
||||
idata[i++] = e;
|
||||
idata[i++] = f;
|
||||
idata[0] = i;
|
||||
}
|
||||
}
|
||||
_GLCommandEncoder.INT = 0x1404;
|
||||
_GLCommandEncoder.FLOAT = 0x1406;
|
||||
_GLCommandEncoder.FLOAT_VEC2 = 0x8B50;
|
||||
_GLCommandEncoder.FLOAT_VEC3 = 0x8B51;
|
||||
_GLCommandEncoder.FLOAT_VEC4 = 0x8B52;
|
||||
_GLCommandEncoder.INT_VEC2 = 0x8B53;
|
||||
_GLCommandEncoder.INT_VEC3 = 0x8B54;
|
||||
_GLCommandEncoder.INT_VEC4 = 0x8B55;
|
||||
_GLCommandEncoder.BOOL = 0x8B56;
|
||||
_GLCommandEncoder.BOOL_VEC2 = 0x8B57;
|
||||
_GLCommandEncoder.BOOL_VEC3 = 0x8B58;
|
||||
_GLCommandEncoder.BOOL_VEC4 = 0x8B59;
|
||||
_GLCommandEncoder.FLOAT_MAT2 = 0x8B5A;
|
||||
_GLCommandEncoder.FLOAT_MAT3 = 0x8B5B;
|
||||
_GLCommandEncoder.FLOAT_MAT4 = 0x8B5C;
|
||||
_GLCommandEncoder.SAMPLER_2D = 0x8B5E;
|
||||
_GLCommandEncoder.SAMPLER_CUBE = 0x8B60;
|
||||
function extendWebGLPlusToWebGLContext(gl) {
|
||||
gl.prototype.createArrayBufferRef = function (arrayBuffer, type, syncRender) {
|
||||
var bufferConchRef = webglPlus.createArrayBufferRef(arrayBuffer, type, syncRender, ARRAY_BUFFER_PARAM_TYPE.ARRAY_BUFFER_REF_REFERENCE);
|
||||
arrayBuffer["conchRef"] = bufferConchRef;
|
||||
arrayBuffer["_ptrID"] = bufferConchRef.id;
|
||||
return bufferConchRef;
|
||||
};
|
||||
gl.prototype.createArrayBufferRefs = function (arrayBuffer, type, syncRender, refType) {
|
||||
if (!arrayBuffer._refArray) {
|
||||
arrayBuffer._refArray = [];
|
||||
arrayBuffer._refNum = 1;
|
||||
arrayBuffer._refArray.length = 1;
|
||||
arrayBuffer.getRefNum = function () {
|
||||
return this._refNum;
|
||||
};
|
||||
arrayBuffer.clearRefNum = function () {
|
||||
this._refNum = 1;
|
||||
};
|
||||
arrayBuffer.getRefSize = function () {
|
||||
return this._refArray.length;
|
||||
};
|
||||
arrayBuffer.getPtrID = function (index) {
|
||||
index = index ? index : 0;
|
||||
return this._refArray[index].ptrID;
|
||||
};
|
||||
}
|
||||
var bufferConchRef = null;
|
||||
if (refType == ARRAY_BUFFER_PARAM_TYPE.ARRAY_BUFFER_REF_REFERENCE) {
|
||||
var refArray = arrayBuffer._refArray;
|
||||
if (!refArray[0]) {
|
||||
bufferConchRef = webglPlus.createArrayBufferRef(arrayBuffer, type, syncRender, refType);
|
||||
refArray[0] = { "ref": bufferConchRef, "ptrID": bufferConchRef.id };
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (arrayBuffer._refNum < arrayBuffer._refArray.length) {
|
||||
bufferConchRef = arrayBuffer._refArray[arrayBuffer._refNum].ref;
|
||||
var nPtrID = arrayBuffer.getPtrID(arrayBuffer._refNum);
|
||||
webglPlus.syncArrayBufferDataToRuntime(nPtrID, bufferConchRef.isSyncToRender(), arrayBuffer);
|
||||
}
|
||||
else {
|
||||
bufferConchRef = webglPlus.createArrayBufferRef(arrayBuffer, type, syncRender, refType);
|
||||
arrayBuffer._refArray.push({ "ref": bufferConchRef, "ptrID": bufferConchRef.id });
|
||||
}
|
||||
arrayBuffer._refNum++;
|
||||
}
|
||||
return bufferConchRef;
|
||||
};
|
||||
gl.prototype.updateArrayBufferRef = function (bufferID, isSyncToRender, buffer) {
|
||||
return webglPlus.updateArrayBufferRef(bufferID, isSyncToRender, buffer);
|
||||
};
|
||||
gl.prototype.updateAnimationNodeWorldMatix = function (locPosition, locRotation, locScaling, parentIndices, outWorldMatrix) {
|
||||
return webglPlus.updateAnimationNodeWorldMatix(locPosition, locRotation, locScaling, parentIndices, outWorldMatrix);
|
||||
};
|
||||
gl.prototype.computeSubSkinnedData = function (worldMatrixs, worldMatrixIndex, inverseBindPoses, boneIndices, bindPoseInices, resultData) {
|
||||
return webglPlus.computeSubSkinnedData(worldMatrixs, worldMatrixIndex, inverseBindPoses, boneIndices, bindPoseInices, resultData);
|
||||
};
|
||||
gl.prototype.evaluateClipDatasRealTime = function (nodes, playCurTime, realTimeCurrentFrameIndexs, addtive, frontPlay) {
|
||||
webglPlus.evaluateClipDatasRealTime(nodes, playCurTime, realTimeCurrentFrameIndexs, addtive, frontPlay);
|
||||
};
|
||||
gl.prototype.culling = function (boundFrustumBuffer, cullingBuffer, cullingBufferIndices, cullingCount, cullingBufferResult) {
|
||||
return webglPlus.culling(boundFrustumBuffer, cullingBuffer, cullingBufferIndices, cullingCount, cullingBufferResult);
|
||||
};
|
||||
if (!window["conch"]) {
|
||||
gl.prototype.createCommandEncoder = function (reserveSize, adjustSize, isSyncToRenderThread) {
|
||||
reserveSize = reserveSize ? reserveSize : 128;
|
||||
adjustSize = adjustSize ? adjustSize : 64;
|
||||
isSyncToRenderThread = isSyncToRenderThread ? isSyncToRenderThread : false;
|
||||
var cmd = new _GLCommandEncoder(this, reserveSize, adjustSize, isSyncToRenderThread);
|
||||
if (isSyncToRenderThread) {
|
||||
this.syncBufferToRenderThread(cmd);
|
||||
}
|
||||
return cmd;
|
||||
};
|
||||
window["GLCommandEncoder"] = _GLCommandEncoder;
|
||||
gl.prototype.syncBufferToRenderThread = function (value, index = 0) {
|
||||
};
|
||||
}
|
||||
if (!window["conch"]) {
|
||||
gl.prototype.uploadShaderUniforms = function (commandEncoder, data, type) {
|
||||
if (type == UPLOAD_SHADER_UNIFORM_TYPE.UPLOAD_SHADER_UNIFORM_TYPE_ID) {
|
||||
var dataID = data["_ptrID"];
|
||||
this.syncBufferToRenderThread(data);
|
||||
}
|
||||
else {
|
||||
var nAlignLength = this.getAlignLength(data);
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
gl.prototype.uniformMatrix2fvEx = function (location, transpose, value) {
|
||||
if (!value["_ptrID"]) {
|
||||
this.createArrayBufferRef(value, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_DATA, true);
|
||||
}
|
||||
var nID = value["_ptrID"];
|
||||
this.syncBufferToRenderThread(value);
|
||||
};
|
||||
gl.prototype.uniformMatrix3fvEx = function (location, transpose, value) {
|
||||
if (!value["_ptrID"]) {
|
||||
this.createArrayBufferRef(value, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_DATA, true);
|
||||
}
|
||||
var nID = value["_ptrID"];
|
||||
this.syncBufferToRenderThread(value);
|
||||
};
|
||||
gl.prototype.uniformMatrix4fvEx = function (location, transpose, value) {
|
||||
if (!value["_ptrID"]) {
|
||||
this.createArrayBufferRef(value, ARRAY_BUFFER_TYPE.ARRAY_BUFFER_TYPE_DATA, true);
|
||||
}
|
||||
var nID = value["_ptrID"];
|
||||
this.syncBufferToRenderThread(value);
|
||||
};
|
||||
}
|
||||
}
|
||||
window["extendWebGLPlusToWebGLContext"] = extendWebGLPlusToWebGLContext;
|
||||
@@ -0,0 +1,39 @@
|
||||
if( !window.runtime )
|
||||
{
|
||||
window.runtime=
|
||||
{
|
||||
ScriptFrameParent:null,
|
||||
callObjectC:function(js)
|
||||
{
|
||||
if(!this.ScriptFrameParent)
|
||||
{
|
||||
this.ScriptFrameParent= document.createElement("div");
|
||||
this.ScriptFrameParent.cssText="position:absolute;left:0px;top:0;width:1px;height:1px;display:none";
|
||||
document.documentElement.appendChild(this.ScriptFrameParent);
|
||||
}
|
||||
var iframe = document.createElement("IFRAME");
|
||||
iframe.setAttribute("src", "runtime:"+js );
|
||||
this.ScriptFrameParent.appendChild(iframe);
|
||||
this.ScriptFrameParent.removeChild(iframe);
|
||||
iframe = null;
|
||||
},
|
||||
callConchJSFunction:function(name,json,callback)
|
||||
{
|
||||
this.callObjectC( "callConchJSFunction"+"\5" + name+"\5"+json+"\5"+callback );
|
||||
},
|
||||
JSLog:function( message )
|
||||
{
|
||||
this.callObjectC( "JSLog" + "\5" + message );
|
||||
}
|
||||
}
|
||||
}
|
||||
window.postRuntimeMessage=function(d,s){
|
||||
window.runtime.callConchJSFunction('window.postRuntimeMessage',encodeURIComponent( JSON.stringify(d)),'');
|
||||
};
|
||||
window.__getMessemage=function(d,s){
|
||||
d=decodeURIComponent(d);
|
||||
var e=document.createEvent("MessageEvent");
|
||||
e.initMessageEvent("message",false,false,JSON.parse(d),"","",window);
|
||||
e.target=window;
|
||||
window.dispatchEvent(e);
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import layaair.game.utility.Utils;
|
||||
|
||||
public class AlertRunnable implements Runnable {
|
||||
public Context m_context;
|
||||
public String m_sAlertMsg = "";
|
||||
public int m_nAlertCallbackType = 0;
|
||||
public String m_sAlertTitle = "";
|
||||
public void run() {
|
||||
ExportJavaFunction expjava = ExportJavaFunction.GetInstance();
|
||||
if (expjava != null) {
|
||||
expjava.m_pEngine.alertJS(m_sAlertTitle, m_sAlertMsg, m_nAlertCallbackType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+325
@@ -0,0 +1,325 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ConfigurationInfo;
|
||||
import android.graphics.PixelFormat;
|
||||
import layaair.game.browser.GLSurfaceView;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.Choreographer;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import javax.microedition.khronos.egl.EGL10;
|
||||
import javax.microedition.khronos.egl.EGLConfig;
|
||||
import javax.microedition.khronos.egl.EGLContext;
|
||||
import javax.microedition.khronos.egl.EGLDisplay;
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
import layaair.game.conch.LayaConch5;
|
||||
|
||||
|
||||
public class ConchCanvas extends GLSurfaceView// implements Choreographer.FrameCallback
|
||||
{
|
||||
//public static MainCanvas ms_pCanvas = null;
|
||||
private static String TAG = "MainCanvas";
|
||||
protected boolean m_bReleasing = false;
|
||||
public TouchFilter m_TouchFilter = new TouchFilter();
|
||||
private Renderer render;
|
||||
private Choreographer mChoreographer=null;
|
||||
//public boolean mbUseChoreographer=false;
|
||||
public int m_nDisplayWidth=0;
|
||||
public int m_nDisplayHeight=0;
|
||||
public int m_nFixedWidth=0;
|
||||
public int m_nFixedHeight=0;
|
||||
//------------------------------------------------------------------------------
|
||||
private static class ContextFactory implements GLSurfaceView.EGLContextFactory
|
||||
{
|
||||
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
|
||||
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig)
|
||||
{
|
||||
checkEglError("Before eglCreateContext", egl);
|
||||
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
|
||||
EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
|
||||
checkEglError("After eglCreateContext", egl);
|
||||
return context;
|
||||
}
|
||||
public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context)
|
||||
{
|
||||
egl.eglDestroyContext(display, context);
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
private static void checkEglError(String prompt, EGL10 egl)
|
||||
{
|
||||
int error;
|
||||
while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS)
|
||||
{
|
||||
Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public ConchCanvas(Context context)
|
||||
{
|
||||
super(context);
|
||||
init(false, 24, 8);
|
||||
//ms_pCanvas=this;
|
||||
}
|
||||
|
||||
/*@TargetApi(16)
|
||||
public void doFrame(long var1){
|
||||
if(mbUseChoreographer) {
|
||||
if (mChoreographer != null)
|
||||
mChoreographer.postFrameCallback(this);
|
||||
ConchJNI.onVSyncCallback(var1);
|
||||
}
|
||||
}*/
|
||||
|
||||
public void destory()
|
||||
{
|
||||
this.m_TouchFilter=null;
|
||||
}
|
||||
|
||||
|
||||
public void captureScreen()
|
||||
{
|
||||
if(render!=null)
|
||||
{
|
||||
render.captureScreen();
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
private void init(boolean translucent, int depth, int stencil)
|
||||
{
|
||||
int androidver = Build.VERSION.SDK_INT;
|
||||
//if(androidver>=24){
|
||||
//这个用native接口
|
||||
//}else if(androidver>=16) {
|
||||
/*if(androidver>=16) { //改成全部都用java的
|
||||
mChoreographer = Choreographer.getInstance();
|
||||
mChoreographer.postFrameCallback(this);
|
||||
}*/
|
||||
|
||||
if (translucent)
|
||||
{
|
||||
this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
|
||||
}
|
||||
setPreserveEGLContextOnPause(true);
|
||||
//setEGLContextFactory(new ContextFactory());
|
||||
int reportedVersion = getVersionFromActivityManager(getContext());
|
||||
|
||||
if (getMajorVersion(reportedVersion) == 3)
|
||||
{
|
||||
Log.i(TAG, "Android OpenGL ES Major Version 3");
|
||||
setEGLContextClientVersion(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.i(TAG, "Android OpenGL ES Major Version 2");
|
||||
setEGLContextClientVersion(2);
|
||||
}
|
||||
setEGLConfigChooser(new ConfigChooser(8, 8, 8, 8, depth, stencil));
|
||||
render=new Renderer();
|
||||
render.pCanvas = this;
|
||||
setRenderer(render);
|
||||
}
|
||||
private static int getVersionFromActivityManager(Context context) {
|
||||
ActivityManager activityManager =
|
||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo();
|
||||
if (configInfo.reqGlEsVersion != ConfigurationInfo.GL_ES_VERSION_UNDEFINED) {
|
||||
return configInfo.reqGlEsVersion;
|
||||
} else {
|
||||
return 1 << 16; // Lack of property means OpenGL ES version 1
|
||||
}
|
||||
}
|
||||
private static int getMajorVersion(int glEsVersion) {
|
||||
return ((glEsVersion & 0xffff0000) >> 16);
|
||||
}
|
||||
public void setFixedSize(int w, int h){
|
||||
Log.i("fix","setFixedSize "+w+","+h+",scr:"+m_nDisplayWidth+","+m_nDisplayHeight);
|
||||
if(w<=0||h<=0)
|
||||
return;
|
||||
getHolder().setFixedSize(w,h);
|
||||
if(LayaConch5.ms_layaConche.getHorizontalScreen()){
|
||||
if(w<h){
|
||||
Log.e("LayaBox","setFixedSize error! screen orientation = landscape w should bigger than h");
|
||||
}
|
||||
m_TouchFilter.m_fScaleX = ((float)w)/Math.max(m_nDisplayWidth,m_nDisplayHeight);
|
||||
m_TouchFilter.m_fScaleY = ((float)h)/Math.min(m_nDisplayWidth,m_nDisplayHeight);
|
||||
LayaConch5.ms_layaConche.m_pEditBox.m_fPostScaleX = 1.0f/m_TouchFilter.m_fScaleX;
|
||||
LayaConch5.ms_layaConche.m_pEditBox.m_fPostScaleY = 1.0f/m_TouchFilter.m_fScaleY;
|
||||
}else{
|
||||
if(w>h){
|
||||
Log.e("LayaBox","setFixedSize error! screen orientation = portrait w should less than h");
|
||||
}
|
||||
m_TouchFilter.m_fScaleX = ((float)w)/Math.min(m_nDisplayWidth,m_nDisplayHeight);
|
||||
m_TouchFilter.m_fScaleY = ((float)h)/Math.max(m_nDisplayWidth,m_nDisplayHeight);
|
||||
LayaConch5.ms_layaConche.m_pEditBox.m_fPostScaleX = 1.0f/m_TouchFilter.m_fScaleX;
|
||||
LayaConch5.ms_layaConche.m_pEditBox.m_fPostScaleY = 1.0f/m_TouchFilter.m_fScaleY;
|
||||
}
|
||||
m_nFixedWidth=w;
|
||||
m_nFixedHeight=h;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
if(m_bReleasing ) return true;
|
||||
super.onTouchEvent(event);
|
||||
if( event!=null)
|
||||
{
|
||||
m_TouchFilter.onTouchEvent(event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
/*if (mChoreographer != null)
|
||||
mChoreographer.postFrameCallback(this);*/
|
||||
}
|
||||
public void onPause(){
|
||||
super.onPause();
|
||||
/*if(mChoreographer!=null){
|
||||
mChoreographer.removeFrameCallback(this);
|
||||
}*/
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser
|
||||
{
|
||||
//------------------------------------------------------------------------------
|
||||
public ConfigChooser(int r, int g, int b, int a, int depth, int stencil)
|
||||
{
|
||||
mRedSize = r;
|
||||
mGreenSize = g;
|
||||
mBlueSize = b;
|
||||
mAlphaSize = a;
|
||||
mDepthSize = depth;
|
||||
mStencilSize = stencil;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
private static int EGL_OPENGL_ES2_BIT = 4;
|
||||
//------------------------------------------------------------------------------
|
||||
private static int[] s_configAttribs2 =
|
||||
{
|
||||
EGL10.EGL_RED_SIZE, 4,
|
||||
EGL10.EGL_GREEN_SIZE, 4,
|
||||
EGL10.EGL_BLUE_SIZE, 4,
|
||||
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL10.EGL_NONE
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
|
||||
{
|
||||
int[] num_config = new int[1];
|
||||
egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
|
||||
int numConfigs = num_config[0];
|
||||
if (numConfigs <= 0)
|
||||
{
|
||||
throw new IllegalArgumentException("No configs match configSpec");
|
||||
}
|
||||
EGLConfig[] configs = new EGLConfig[numConfigs];
|
||||
egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);
|
||||
return chooseConfig(egl, display, configs);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,EGLConfig[] configs)
|
||||
{
|
||||
for(EGLConfig config : configs)
|
||||
{
|
||||
int d = findConfigAttrib(egl, display, config,EGL10.EGL_DEPTH_SIZE, 0);
|
||||
int s = findConfigAttrib(egl, display, config,EGL10.EGL_STENCIL_SIZE, 0);
|
||||
if (d < mDepthSize || s < mStencilSize)continue;
|
||||
int r = findConfigAttrib(egl, display, config,EGL10.EGL_RED_SIZE, 0);
|
||||
int g = findConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
|
||||
int b = findConfigAttrib(egl, display, config,EGL10.EGL_BLUE_SIZE, 0);
|
||||
int a = findConfigAttrib(egl, display, config,EGL10.EGL_ALPHA_SIZE, 0);
|
||||
if (r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize)return config;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
private int findConfigAttrib(EGL10 egl, EGLDisplay display,EGLConfig config, int attribute, int defaultValue)
|
||||
{
|
||||
if (egl.eglGetConfigAttrib(display, config, attribute, mValue))
|
||||
{
|
||||
return mValue[0];
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
protected int mRedSize;
|
||||
protected int mGreenSize;
|
||||
protected int mBlueSize;
|
||||
protected int mAlphaSize;
|
||||
protected int mDepthSize;
|
||||
protected int mStencilSize;
|
||||
private int[] mValue = new int[1];
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
private static class Renderer implements GLSurfaceView.Renderer
|
||||
{
|
||||
private GL10 m_lastgl=null;
|
||||
private int m_nlastW=0,m_nlastH=0;
|
||||
private boolean m_bTakeScreenshot;
|
||||
public ConchCanvas pCanvas=null;
|
||||
//------------------------------------------------------------------------------
|
||||
public void onDrawFrame(GL10 gl)
|
||||
{
|
||||
//Log.e("", "usedMem:"+ProcessInfo.GetUsedMem());
|
||||
//ProcessInfo.GetTotalMem();
|
||||
ConchJNI.onDrawFrame();
|
||||
if(m_bTakeScreenshot) {
|
||||
LayaConch5.GetInstance().dispatchGL(gl, m_nlastW, m_nlastH);
|
||||
m_bTakeScreenshot=false;
|
||||
}
|
||||
|
||||
}
|
||||
public void captureScreen()
|
||||
{
|
||||
m_bTakeScreenshot=true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public void onSurfaceChanged(GL10 gl, int width, int height)
|
||||
{
|
||||
if (LayaConch5.ms_layaConche != null)
|
||||
{
|
||||
/*if(pCanvas!=null){
|
||||
pCanvas.doFrame(System.nanoTime());
|
||||
}*/
|
||||
|
||||
boolean isHorizontion = LayaConch5.ms_layaConche.getHorizontalScreen();
|
||||
if (isHorizontion&& width<height)
|
||||
{
|
||||
m_nlastW=height;
|
||||
m_nlastH=width;
|
||||
m_lastgl=gl;
|
||||
Log.e("",">>>>>>>>>>>>surfaceChangedhw w="+m_nlastW+",h="+m_nlastH+" gl="+gl);
|
||||
ConchJNI.OnGLReady(m_nlastW, m_nlastH);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e("",">>>>>>>>>>>>>surface not ready");
|
||||
return;
|
||||
}
|
||||
|
||||
if(width==m_nlastW && height==m_nlastH && gl==m_lastgl )return;
|
||||
m_nlastW=width;
|
||||
m_nlastH=height;
|
||||
m_lastgl=gl;
|
||||
Log.e("",">>>>>>>>>>>>surfaceChanged w="+width+",h="+height+" gl="+gl);
|
||||
ConchJNI.OnGLReady(width, height);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public void onSurfaceCreated(GL10 gl, EGLConfig config)
|
||||
{
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package layaair.game.browser;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.Build;
|
||||
|
||||
import layaair.game.conch.LayaConch5;
|
||||
|
||||
public class ConchJNI
|
||||
{
|
||||
public static boolean g_bInitialized=false;
|
||||
//kuo add code for plugin implement
|
||||
//{{begin
|
||||
public static boolean initNativeLibrary(String library,boolean plugin)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(plugin){
|
||||
System.load(library);
|
||||
}
|
||||
else {
|
||||
if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {//android 4.2
|
||||
System.loadLibrary("c++_shared");
|
||||
System.loadLibrary("v8_libbase.cr");
|
||||
System.loadLibrary("v8.cr");
|
||||
System.loadLibrary("v8_libplatform.cr");
|
||||
}
|
||||
System.loadLibrary(library);
|
||||
}
|
||||
ConchJNI.setLocalizable(LayaConch5.GetInstance().localizable);
|
||||
g_bInitialized = true;
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
g_bInitialized=false;
|
||||
}
|
||||
return g_bInitialized;
|
||||
}
|
||||
//}}end
|
||||
//------------------------------------------------------------------------------
|
||||
//启动前的配置
|
||||
public static native void configSetURL(String p_strUrl);
|
||||
|
||||
public static native void configSetIsPlug(boolean p_bIsPlug);
|
||||
|
||||
//
|
||||
public static native void configSetParamExt(String p_strExt);
|
||||
|
||||
//初始化
|
||||
public static native void InitDLib( AssetManager p_am,int nDownloadThreadNum, String p_strAssetRoot, String p_strCachePath, String p_strAPKExpansionMainPath, String p_strAPKExpansionPatchPath,int threadMode,int debugMode,int debugPort);
|
||||
|
||||
//touch
|
||||
public static native void handleTouch( int type,int id,int x,int y );
|
||||
|
||||
public static native void handleKeyEvent(int keyCode, int actionType);
|
||||
|
||||
public static native void handleJoystickEvent(float THUMBL_xOffset,float THUMBL_yOffset,float THUMBR_xOffset,float THUMBR_yOffset,float LT_Offset,float RT_Offset);
|
||||
|
||||
public static native void handleDeviceMotionEvent(float ax, float ay, float az, float agx, float agy, float agz, float ra, float rb, float rg, float interval);
|
||||
|
||||
public static native void handleDeviceOrientationEvent(float ra,float rb,float rg);
|
||||
//初始化下载管理器
|
||||
//@param[in] p_bforceLocal
|
||||
//@param[in] p_pszRoot 保存下载文件的地方,/data/data/laya.game.browser/cache/LayaCache
|
||||
//@param[in] p_am
|
||||
//@param[in] p_strAssetRoot 相对于assets目录的路径,可以是网站的hash,现在是固定值
|
||||
public static native void InitDownLoadManager( int p_bForceLocal,String p_pszRoot, AssetManager p_am, String p_strAssetRoot );
|
||||
|
||||
public static native void SetLocalStoragePath( String p_strLocalStorage );
|
||||
|
||||
//释放gl资源
|
||||
public static native void ReleaseDLib();
|
||||
|
||||
//退出。(进程不一定退出)
|
||||
public static native void OnAppDestroy();
|
||||
|
||||
//通知c应用暂停,一般是进入后台。可能需要做一些恢复设备的准备工作
|
||||
public static native void OnAppPause();
|
||||
|
||||
//渲染部分的初始化,必须在GLES环境准备好之后再做
|
||||
//通知c glcontext已经建立或者已经恢复,需要做一些恢复工作。恢复:shader,texture,FBO...
|
||||
public static native void OnGLReady(int width,int height);
|
||||
|
||||
//通知app又进入前台了。与上面不同的是不保证context有效了
|
||||
public static native void OnAppResume();
|
||||
|
||||
//测试用渲染update
|
||||
public static native void onDrawFrame();
|
||||
|
||||
public static native void onVSyncCallback(long vsynctm);
|
||||
|
||||
public static native void exportObjectToC(String objName, Object expObj );
|
||||
|
||||
public static native void exportStaticMethodToC( String packcls);
|
||||
|
||||
public static native void closeExternalWebView();
|
||||
|
||||
public static native void editBoxOnInput( String p_sEvent );
|
||||
|
||||
public static native void alertCallback();
|
||||
|
||||
public static native void onSensorChanged( float arc );
|
||||
|
||||
public static native void reloadJS();
|
||||
|
||||
public static native void onRunCmd(int cmd, int param1, int param2 );
|
||||
|
||||
//执行一段js代码或者函数
|
||||
//参数是一段js代码。
|
||||
public static native void RunJS( String jsstring );
|
||||
|
||||
//java给runtime发消息。params是一个JSON对象
|
||||
public static native void postMsgToRuntime(String msg, String params);
|
||||
|
||||
public static native void audioMusicPlayEnd();
|
||||
|
||||
public static native void networkChanged( int p_nNetworkType );
|
||||
//market 回调-----------------------------------
|
||||
public static native void onMarketInit( String p_sTokenDir );
|
||||
public static native void loginCallback( String jsonParam);
|
||||
public static native void authorizeCallback( String jsonParam);
|
||||
public static native void refreshTokenCallback( String jsonParam);
|
||||
public static native void rechargeEvent( String jsonParam );
|
||||
public static native void inputChange(int keyCode);
|
||||
|
||||
public static native void onShareAndFeed( String jsonParam);
|
||||
public static native void onGetGameFriends( String jsonParam);
|
||||
public static native void onSendToDesktop( String jsonParam );
|
||||
public static native void onLogout( String jsonParam );
|
||||
public static native void onTopicCircle( String jsonParam );
|
||||
public static native void onInviteCallback(String jsonParam);
|
||||
|
||||
public static native void onSwitchUserCallback(String jsonParam);
|
||||
public static native void onEnterPlatformCallback(String jsonParam);
|
||||
public static native void onEnterBBSCallback(String jsonParam);
|
||||
public static native void onEnterFeedbackCallback(String jsonParam);
|
||||
public static native void onEnterAccountMgrCallback(String jsonParam);
|
||||
public static native void onBuyPropsCallback(String jsonParam);
|
||||
public static native void onSetRechargeInfoCallback(String jsonParam);
|
||||
public static native void onSendMessageToPlatformCallback(String jsonParam);
|
||||
|
||||
public static native void onGetUserInfoCallback(String jsonParam);
|
||||
public static native void onGetAvailableLoginTypeCallback(String jsonParam);
|
||||
public static native void setLocalizable(boolean isLocalPackage);
|
||||
//调用Conch的JS函数
|
||||
public static native void callConchJSFunction( String sFunctionName,String sJsonParam,String sCallbackFunction );
|
||||
|
||||
public static native void captureScreenCallBack(int w, int h, byte[] buff);
|
||||
|
||||
public static native boolean onBackPressed();
|
||||
}
|
||||
+1261
File diff suppressed because it is too large
Load Diff
+93
@@ -0,0 +1,93 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Animation.AnimationListener;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import layaair.game.config.config;
|
||||
|
||||
public class FlashScreen
|
||||
{
|
||||
//logo闪屏相关的
|
||||
private LinearLayout m_pLayoutHead = null;
|
||||
private int m_curFlashIndex = 1;
|
||||
private Activity m_pActivity = null;
|
||||
//------------------------------------------------------------------------------
|
||||
public FlashScreen( Activity p_pActivity )
|
||||
{
|
||||
m_pActivity = p_pActivity;
|
||||
m_pLayoutHead = new LinearLayout( m_pActivity );
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public void start(final ValueCallback<Boolean> callback)
|
||||
{
|
||||
Log.e("0", "==============Java流程 FlashScreen start");
|
||||
String sImageName = "flashscreen"+m_curFlashIndex+".jpg";
|
||||
AssetManager pAssetManager = m_pActivity.getAssets();
|
||||
InputStream pInputStream = null;
|
||||
try
|
||||
{
|
||||
pInputStream=pAssetManager.open( sImageName );//name:图片的名称
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
if( pInputStream == null )
|
||||
{
|
||||
Log.e("0", "==============Java流程 FlashScreen end 调用checkApkUpdate");
|
||||
//LayaWrapper.GetInstance().checkApkUpdate();
|
||||
callback.onReceiveValue(true);
|
||||
return;
|
||||
}
|
||||
m_pLayoutHead.removeAllViews();
|
||||
ImageView pLogoImage = new ImageView( m_pActivity );
|
||||
LinearLayout.LayoutParams param=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
|
||||
m_pLayoutHead.setGravity(Gravity.CENTER);
|
||||
Bitmap pBitMap = BitmapFactory.decodeStream( pInputStream );
|
||||
LinearLayout.LayoutParams pLayoutParams =new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
pLogoImage.setImageBitmap( pBitMap );
|
||||
m_pLayoutHead.setBackgroundColor( config.GetInstance().m_nMarketWaitScreenBKColor );
|
||||
m_pLayoutHead.addView( pLogoImage,pLayoutParams );
|
||||
m_pActivity.setContentView(m_pLayoutHead,param);
|
||||
AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f);
|
||||
alphaAnimation.setDuration(2000);
|
||||
pLogoImage.startAnimation( alphaAnimation );
|
||||
alphaAnimation.setAnimationListener(new AnimationListener()
|
||||
{
|
||||
public void onAnimationStart(Animation animation)
|
||||
{
|
||||
}
|
||||
public void onAnimationRepeat(Animation animation)
|
||||
{
|
||||
}
|
||||
public void onAnimationEnd(Animation animation)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
m_curFlashIndex++;
|
||||
start(callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
}
|
||||
+1935
File diff suppressed because it is too large
Load Diff
+781
@@ -0,0 +1,781 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import layaair.game.conch.LayaConch5;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.text.InputFilter;
|
||||
import android.text.InputType;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnKeyListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AbsoluteLayout;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class LayaEditBox
|
||||
{
|
||||
public EditText m_pEditBox = null;
|
||||
public Context m_pApplication = null;
|
||||
public int m_nPosX = 0;
|
||||
public int m_nPosY = 0;
|
||||
public int m_nWidth = 0;
|
||||
public int m_nHeight = 0;
|
||||
public boolean m_bForbidEdit=false;
|
||||
public AbsoluteLayout.LayoutParams m_pLayoutParams = null;
|
||||
private static final String TAG="LayaBox";
|
||||
public float m_fPostScaleX=1.0f;
|
||||
public float m_fPostScaleY=1.0f;
|
||||
//---------------------------------------------------------------
|
||||
//为了避免线程问题
|
||||
public String m_sValues;
|
||||
private int m_nBackGroudColor = 0;
|
||||
private boolean m_nNumberOnly = false;
|
||||
private boolean m_bPassWord = false;
|
||||
private int m_nTextColor = 0xffffff;
|
||||
private int m_nTexSize = 24;
|
||||
private boolean m_bBold = false;
|
||||
private boolean m_bShow = false;
|
||||
public boolean m_bFocus = false;
|
||||
private int m_nMaxLength = 0;
|
||||
private int m_nLines = 1;
|
||||
private LayaEditBoxWatcher m_pEditBoxWatcher = null;
|
||||
private String m_sRegular = null;
|
||||
private String m_sStyle = null;
|
||||
public Handler m_Handler = new Handler();
|
||||
//---------------------------------------------------------------
|
||||
|
||||
public void destory()
|
||||
{
|
||||
m_pApplication=null;
|
||||
if(m_pEditBoxWatcher!=null)
|
||||
{
|
||||
m_pEditBoxWatcher.destory();
|
||||
m_pEditBoxWatcher=null;
|
||||
}
|
||||
if(m_pEditBox!=null)
|
||||
{
|
||||
m_pEditBox.destroyDrawingCache();
|
||||
m_pEditBox=null;
|
||||
}
|
||||
}
|
||||
@SuppressLint("NewApi")
|
||||
public static void hideSoftKeyBorad()
|
||||
{
|
||||
if(Build.VERSION.SDK_INT>18)
|
||||
{
|
||||
int a=((Activity) LayaConch5.GetInstance().mCtx).getWindow().getDecorView().getSystemUiVisibility();
|
||||
Log.i(TAG, ">>>>>>>>>>>>>>>>>>>a:"+a);
|
||||
if((a&0x1000)==0x1000)
|
||||
{
|
||||
LayaConch5.GetInstance().m_pAbsLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public static void hideSystemKeyBoard( Context mcontext,View v )
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager) (mcontext.getSystemService(Context.INPUT_METHOD_SERVICE));
|
||||
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
|
||||
hideSoftKeyBorad();
|
||||
}
|
||||
public LayaEditBox( Context p_pContext )
|
||||
{
|
||||
m_pApplication = p_pContext;
|
||||
m_pEditBox = null;
|
||||
}
|
||||
public void SetRegular( String p_sRegular )
|
||||
{
|
||||
m_sRegular = p_sRegular;
|
||||
}
|
||||
public String GetRegular()
|
||||
{
|
||||
return m_sRegular;
|
||||
}
|
||||
public boolean IsInputValid( String p_sBuffer )
|
||||
{
|
||||
if( m_sRegular == null||m_sRegular.equals("null")) return true;
|
||||
return Pattern.matches( m_sRegular, p_sBuffer );
|
||||
}
|
||||
public void CreateEditBox()
|
||||
{
|
||||
/*
|
||||
m_pEditBox = new EditText( m_pApplication );
|
||||
m_pEditBox.setBackgroundColor( 0xffffffff );
|
||||
m_pEditBoxWatcher = new LayaEditBoxWatcher( this );
|
||||
m_pEditBox.addTextChangedListener( m_pEditBoxWatcher );
|
||||
setLayoutParams();
|
||||
m_pEditBox.setVisibility( m_pEditBox.VISIBLE );
|
||||
*/
|
||||
|
||||
m_pEditBox = new EditText( m_pApplication );
|
||||
m_pEditBox.setBackgroundColor( 0xffffffff );
|
||||
m_pEditBox.setBackgroundDrawable(null);
|
||||
m_pEditBox.setVisibility( m_pEditBox.INVISIBLE );
|
||||
//为了兼容好多板子,比如三星的板子 editbox最小只能是50,所有小于50的,就不再小了,把所有文字靠左上显示
|
||||
m_pEditBox.setGravity( Gravity.START | Gravity.TOP );
|
||||
m_pEditBox.setSingleLine(true);
|
||||
m_pEditBox.setGravity(Gravity.CENTER_VERTICAL);
|
||||
m_pEditBoxWatcher = new LayaEditBoxWatcher( this );
|
||||
m_pEditBox.addTextChangedListener( m_pEditBoxWatcher );
|
||||
m_pEditBox.setPadding(0, 0, 0, 0);
|
||||
m_pEditBox.setOnEditorActionListener(m_pEditBoxWatcher);
|
||||
//m_pEditBox.setIncludeFontPadding(false);
|
||||
//m_pEditBox.setMaxLines(1);
|
||||
//这个在2.3的系统下没有
|
||||
//m_pEditBox.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
|
||||
/*
|
||||
//不知到为什么这个不起作用,好像只能接收硬件键盘的消息.只能接受控制字符,可见字符的输入都是走输入法的
|
||||
m_pEditBox.setOnKeyListener(new OnKeyListener()
|
||||
{
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event)
|
||||
{
|
||||
if (event.getAction()==KeyEvent.ACTION_DOWN )
|
||||
{
|
||||
//TODO
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
public boolean setLayoutParams()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
if( m_pLayoutParams == null )
|
||||
{
|
||||
m_pEditBox.setWidth( m_nWidth );
|
||||
m_pEditBox.setHeight( m_nHeight );
|
||||
m_pLayoutParams = new AbsoluteLayout.LayoutParams( m_nWidth,m_nHeight,m_nPosX,m_nPosY );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pLayoutParams.width = m_nWidth;
|
||||
m_pLayoutParams.height = m_nHeight;
|
||||
m_pLayoutParams.x = m_nPosX;
|
||||
m_pLayoutParams.y = m_nPosY;
|
||||
m_pEditBox.setWidth( m_nWidth );
|
||||
m_pEditBox.setHeight( m_nHeight );
|
||||
}
|
||||
m_pEditBox.setLayoutParams( m_pLayoutParams );
|
||||
//密码的设置都失效了,再来一遍
|
||||
if (m_bPassWord)
|
||||
{
|
||||
setRealPassWord();
|
||||
int len=m_pEditBox.getText().length();
|
||||
m_pEditBox.setSelection(len);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public String getValue()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
return m_pEditBox.getText().toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public void setValue( String p_sValues )
|
||||
{
|
||||
if(p_sValues==null)p_sValues="";
|
||||
m_sValues = p_sValues;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealValue();
|
||||
int len=m_pEditBox.getText().length();
|
||||
m_pEditBox.setSelection(len);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealValue()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
m_pEditBox.setText( m_sValues );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setBackGroud( int p_nColor )
|
||||
{
|
||||
m_nBackGroudColor = p_nColor;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealBackGroud();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealBackGroud()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
m_pEditBox.setBackgroundColor( m_nBackGroudColor );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setMultiAble(final boolean p_bMultiAble)
|
||||
{
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
m_pEditBox.setSingleLine(!p_bMultiAble);
|
||||
if(p_bMultiAble)
|
||||
{
|
||||
m_pEditBox.setGravity(Gravity.TOP);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pEditBox.setGravity(Gravity.CENTER_VERTICAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void setForbidEdit(final boolean p_bForbidEdit)
|
||||
{
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
m_bForbidEdit = p_bForbidEdit;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void setPos( int p_nX,int p_nY )
|
||||
{
|
||||
m_nPosX = (int)(p_nX*m_fPostScaleX);
|
||||
m_nPosY = (int)(p_nY*m_fPostScaleY);
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setLayoutParams();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void setPosX( int p_nX )
|
||||
{
|
||||
m_nPosX = (int)(p_nX*m_fPostScaleX);
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setLayoutParams();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void setPosY( int p_nY )
|
||||
{
|
||||
m_nPosY = (int)(p_nY*m_fPostScaleY);
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setLayoutParams();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void setSize( int p_nW,int p_nH )
|
||||
{
|
||||
m_nWidth = (int)(p_nW*m_fPostScaleX);
|
||||
m_nHeight = (int)(p_nH*m_fPostScaleY);
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setLayoutParams();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void setWidth( int p_nWidth )
|
||||
{
|
||||
m_nWidth = (int)(p_nWidth*m_fPostScaleX);
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setLayoutParams();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void setHeight( int p_nHeight )
|
||||
{
|
||||
m_nHeight = (int)(p_nHeight*m_fPostScaleY);
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setLayoutParams();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void setNumberOnly( boolean p_bNumberOnly )
|
||||
{
|
||||
m_nNumberOnly = p_bNumberOnly;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealNumberOnly();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealNumberOnly()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
if( m_nNumberOnly )
|
||||
{
|
||||
m_pEditBox.setInputType( InputType.TYPE_CLASS_NUMBER );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pEditBox.setInputType( InputType.TYPE_CLASS_TEXT );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setPassWord( boolean p_bPassWord )
|
||||
{
|
||||
m_bPassWord = p_bPassWord;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealPassWord();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealPassWord()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
if( m_bPassWord )
|
||||
{
|
||||
//下面两种方式,有的机器用第一种是好用的。。有的用第二种是好用的。
|
||||
//但是如果是用第2种方式,明文和密码切换有问题。。明文也变成密码了。。这种方式太影响用户体验了
|
||||
//所以用第一种方式,但是这种方式,有的时候切换密码不太好用,因为在老谢那边也会处理,显示变成了*。。所以不太影响
|
||||
m_pEditBox.setInputType( InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pEditBox.setInputType(m_pEditBox.getInputType() & ~InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setTextColor( int p_nColor )
|
||||
{
|
||||
m_nTextColor = p_nColor;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealTextColor();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealTextColor()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
m_pEditBox.setTextColor( m_nTextColor );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setTextSize( int p_nTextSize )
|
||||
{
|
||||
m_nTexSize = (int)(p_nTextSize*m_fPostScaleX);
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealTextSize();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealTextSize()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
m_pEditBox.setTextSize( TypedValue.COMPLEX_UNIT_PX, m_nTexSize );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setBold( boolean p_bBold )
|
||||
{
|
||||
m_bBold = p_bBold;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealBold();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealBold()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
if( m_bBold )
|
||||
{
|
||||
m_pEditBox.setTypeface( Typeface.DEFAULT_BOLD );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setVisible( boolean p_bVisble )
|
||||
{
|
||||
m_bShow= p_bVisble;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealVisible();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean getVisible( )
|
||||
{
|
||||
return m_bShow ;
|
||||
}
|
||||
public boolean setRealVisible()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
if( m_bShow == true )
|
||||
{
|
||||
m_pEditBox.setVisibility( View.VISIBLE );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pEditBox.setVisibility( View.INVISIBLE );
|
||||
m_pEditBox.clearFocus();
|
||||
hideSystemKeyBoard( m_pApplication,m_pEditBox );
|
||||
ExportJavaFunction mTemp = ExportJavaFunction.GetInstance();
|
||||
if (mTemp!=null && mTemp.m_pEngine!=null) {
|
||||
mTemp.m_pEngine.setGameFocus();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setFocus( boolean p_bFocus )
|
||||
{
|
||||
m_bFocus = p_bFocus;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealFocus();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean getFocus( )
|
||||
{
|
||||
return m_bFocus ;
|
||||
}
|
||||
public boolean setRealFocus()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
m_pEditBox.setFocusable( true );
|
||||
m_pEditBox.setFocusableInTouchMode(true);
|
||||
if(m_bFocus)
|
||||
{
|
||||
boolean isIntercepter = false;
|
||||
ExportJavaFunction mTemp = ExportJavaFunction.GetInstance();
|
||||
if (mTemp!=null && mTemp.m_pEngine!=null) {
|
||||
isIntercepter = mTemp.m_pEngine.getInterceptKey();
|
||||
}
|
||||
if (isIntercepter) {
|
||||
m_pEditBox.setOnKeyListener(new OnKeyListener() {
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if( keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN ){
|
||||
Log.i(TAG,"onKey = "+keyCode);
|
||||
setFocus(false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
m_pEditBox.requestFocus();
|
||||
InputMethodManager imm = (InputMethodManager)m_pApplication.getSystemService( m_pApplication.INPUT_METHOD_SERVICE );
|
||||
imm.showSoftInput(m_pEditBox, 0);
|
||||
m_pEditBox.invalidate();
|
||||
CharSequence text = m_pEditBox.getText();
|
||||
if (text != null)
|
||||
{
|
||||
Spannable spanText = (Spannable)text;
|
||||
Selection.setSelection(spanText, text.length());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pEditBox.clearFocus();
|
||||
hideSystemKeyBoard( m_pApplication,m_pEditBox );
|
||||
ExportJavaFunction mTemp = ExportJavaFunction.GetInstance();
|
||||
if (mTemp!=null && mTemp.m_pEngine!=null) {
|
||||
mTemp.m_pEngine.setGameFocus();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setMaxLength( int p_nMaxLength )
|
||||
{
|
||||
m_nMaxLength = p_nMaxLength;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealMaxLength();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealMaxLength()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
m_pEditBox.setFilters( new InputFilter[]{ new InputFilter.LengthFilter( m_nMaxLength ) } );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setLines( int p_nLines )
|
||||
{
|
||||
m_nLines = p_nLines;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealLines();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public boolean setRealLines()
|
||||
{
|
||||
if( m_pEditBox != null )
|
||||
{
|
||||
m_pEditBox.setMaxLines(m_nLines);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void setStyle( String p_sStyle )
|
||||
{
|
||||
m_sStyle = p_sStyle;
|
||||
setRealStyle();
|
||||
}
|
||||
public void setRealStyle()
|
||||
{
|
||||
if ( m_sStyle.length() <= 0 ) return ;
|
||||
String[] vString = m_sStyle.split( ";" );
|
||||
int nLength = vString.length;
|
||||
if ( nLength <= 0 )
|
||||
{
|
||||
String[] vString1 = m_sStyle.split(":");
|
||||
if ( vString1.length < 2 )
|
||||
{
|
||||
Log.e(TAG,"java setRealStyle error");
|
||||
return;
|
||||
}
|
||||
paserStyle( vString1[0], vString1[1] );
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String aVString : vString) {
|
||||
String[] vString2 = aVString.split(":");
|
||||
if (vString2.length < 2) {
|
||||
Log.e(TAG, "java setRealStyle error2");
|
||||
continue;
|
||||
}
|
||||
paserStyle(vString2[0], vString2[1]);
|
||||
}
|
||||
}
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setLayoutParams();
|
||||
setRealTextSize();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
public void paserStyle( String styleKey, String styleValue )
|
||||
{
|
||||
try
|
||||
{
|
||||
if (styleKey.equals("left"))
|
||||
{
|
||||
if (styleValue.contains("px"))
|
||||
{
|
||||
styleValue = styleValue.substring(0, styleValue.length() - 2);
|
||||
|
||||
}
|
||||
m_nPosX = Integer.parseInt( styleValue );
|
||||
}
|
||||
else if (styleKey.equals("top"))
|
||||
{
|
||||
if (styleValue.contains("px"))
|
||||
{
|
||||
styleValue = styleValue.substring(0, styleValue.length() - 2);
|
||||
}
|
||||
m_nPosY = Integer.parseInt( styleValue );
|
||||
}
|
||||
else if (styleKey.equals("width"))
|
||||
{
|
||||
if (styleValue.contains("px"))
|
||||
{
|
||||
styleValue = styleValue.substring(0, styleValue.length() - 2);
|
||||
}
|
||||
m_nWidth = Integer.parseInt( styleValue );
|
||||
}
|
||||
else if (styleKey.equals("height"))
|
||||
{
|
||||
if (styleValue.contains("px"))
|
||||
{
|
||||
styleValue = styleValue.substring(0, styleValue.length() - 2);
|
||||
}
|
||||
m_nHeight = Integer.parseInt( styleValue );
|
||||
}
|
||||
else if (styleKey.equals("font-size"))
|
||||
{
|
||||
if (styleValue.contains("px"))
|
||||
{
|
||||
styleValue = styleValue.substring(0, styleValue.length() - 2);
|
||||
}
|
||||
m_nTexSize = Integer.parseInt( styleValue );
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.e("",e.toString());
|
||||
}
|
||||
}
|
||||
public void onChanged(String s)
|
||||
{
|
||||
ConchJNI.inputChange(0);
|
||||
//m_pWebView.runScript("window.inputobjs["+m_nID+"].onInnerChanged('"+s+"');");
|
||||
}
|
||||
public void setCursorPosition( final int p_nPos )
|
||||
{
|
||||
m_bShow = true;
|
||||
m_bFocus = true;
|
||||
m_Handler.post
|
||||
(
|
||||
new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
setRealVisible();
|
||||
setRealFocus();
|
||||
int len=m_pEditBox.getText().length();
|
||||
if(p_nPos<0)
|
||||
{
|
||||
m_pEditBox.setSelection(0);
|
||||
}
|
||||
else if(p_nPos> len )
|
||||
{
|
||||
m_pEditBox.setSelection(len);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pEditBox.setSelection(p_nPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package layaair.game.browser;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class LayaEditBoxWatcher implements TextWatcher,TextView.OnEditorActionListener
|
||||
{
|
||||
private CharSequence m_pTemp = null;
|
||||
private int m_nEditStart = 0;
|
||||
private int m_nEditEnd = 0;
|
||||
public LayaEditBox m_pEditBox = null;
|
||||
public String m_sOldBuffer = "";
|
||||
//-------------------------------------------------------------------
|
||||
public LayaEditBoxWatcher( LayaEditBox p_pEditBox )
|
||||
{
|
||||
m_pEditBox = p_pEditBox;
|
||||
}
|
||||
|
||||
public void destory()
|
||||
{
|
||||
m_pEditBox=null;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
public void afterTextChanged( Editable s )
|
||||
{
|
||||
if( m_pEditBox.m_pEditBox == null ) return;
|
||||
m_nEditStart = m_pEditBox.m_pEditBox.getSelectionStart();
|
||||
m_nEditEnd = m_pEditBox.m_pEditBox.getSelectionEnd();
|
||||
int nLength = m_pTemp.length();
|
||||
if ( nLength > 0 )
|
||||
{
|
||||
if( m_pEditBox.m_bForbidEdit )
|
||||
{
|
||||
if( s.toString().equals(m_pEditBox.m_sValues) == false )
|
||||
{
|
||||
m_pEditBox.m_pEditBox.setText(m_pEditBox.m_sValues);
|
||||
}
|
||||
}
|
||||
else if(m_pEditBox.GetRegular()!=null&&m_nEditStart>0)
|
||||
{
|
||||
String sBuffer = "" + m_pTemp.charAt(m_nEditStart-1);
|
||||
//判断是否合法
|
||||
if(!m_pEditBox.IsInputValid(sBuffer))
|
||||
{
|
||||
s.delete(m_nEditStart-1, m_nEditStart);
|
||||
m_pEditBox.m_pEditBox.setText(s);
|
||||
}
|
||||
m_pEditBox.m_pEditBox.setSelection(m_nEditStart);
|
||||
/*
|
||||
m_pEditBox.m_pEditBox.setText(s);
|
||||
m_pEditBox.m_pEditBox.setSelection(m_nEditStart);
|
||||
*/
|
||||
}
|
||||
}
|
||||
if( m_pEditBox.m_bForbidEdit == false) {
|
||||
if (m_sOldBuffer.compareTo(s.toString()) != 0)
|
||||
m_pEditBox.onChanged(s.toString());
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
||||
{
|
||||
m_sOldBuffer = m_pEditBox.m_pEditBox.getText().toString();
|
||||
m_pTemp = s;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
public void onTextChanged( CharSequence s, int start, int before, int count)
|
||||
{
|
||||
}
|
||||
public boolean onEditorAction(TextView paramTextView, int paramInt, KeyEvent paramKeyEvent)
|
||||
{
|
||||
Log.e("input", ">>>>onEditor"+paramInt);
|
||||
LayaEditBox.hideSoftKeyBorad();
|
||||
if(paramInt==KeyEvent.KEYCODE_ENDCALL)
|
||||
{
|
||||
ConchJNI.inputChange(paramInt);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
+488
@@ -0,0 +1,488 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.widget.AbsoluteLayout;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import layaair.game.BuildConfig;
|
||||
import layaair.game.browser.Video.IVideoRenderTarget;
|
||||
import layaair.game.browser.Video.SurfaceViewRenderTarget;
|
||||
import layaair.game.browser.Video.TextureViewRenderTarget;
|
||||
import layaair.game.browser.Video.VideoPlayerState;
|
||||
import layaair.game.conch.LayaConch5;
|
||||
|
||||
import static android.content.Context.AUDIO_SERVICE;
|
||||
import static android.media.MediaPlayer.SEEK_CLOSEST;
|
||||
|
||||
|
||||
public class LayaVideoPlayer implements IVideoRenderTarget.Callback{
|
||||
public final static String TAG = "LayaVideo";
|
||||
|
||||
enum ReadyState {
|
||||
HAVE_NOTHING(0),
|
||||
HAVE_METADATA(1),
|
||||
HAVE_CURRENT_DATA(2),
|
||||
HAVE_FUTURE_DATA(3),
|
||||
HAVE_ENOUGH_DATA(4);
|
||||
|
||||
private int m_value;
|
||||
|
||||
ReadyState(int val)
|
||||
{
|
||||
m_value = val;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
};
|
||||
|
||||
enum MediaPlayerStatus
|
||||
{
|
||||
NotInit,
|
||||
Idle,
|
||||
Initalized,
|
||||
Preparing,
|
||||
Prepared,
|
||||
Started,
|
||||
Stopped,
|
||||
Paused,
|
||||
OnPaused,
|
||||
};
|
||||
|
||||
enum PendingType
|
||||
{
|
||||
Null,
|
||||
Load,
|
||||
Play,
|
||||
Pause,
|
||||
Stop,
|
||||
}
|
||||
|
||||
class PendingData
|
||||
{
|
||||
public PendingType type = PendingType.Null;
|
||||
public String additionData = null;
|
||||
|
||||
public PendingData()
|
||||
{
|
||||
this(PendingType.Null, null);
|
||||
}
|
||||
|
||||
public PendingData(PendingType type)
|
||||
{
|
||||
this(type, null);
|
||||
}
|
||||
|
||||
public PendingData(PendingType type, String additionData)
|
||||
{
|
||||
this.type = type;
|
||||
this.additionData = additionData;
|
||||
}
|
||||
}
|
||||
|
||||
private IVideoRenderTarget m_renderTarget;
|
||||
private MediaPlayer m_mediaPlayer = null;
|
||||
|
||||
private ReadyState m_readyState = ReadyState.HAVE_NOTHING;
|
||||
|
||||
private AbsoluteLayout m_parentLayout;
|
||||
|
||||
private Context m_ctx;
|
||||
|
||||
private MediaPlayerStatus m_curStatus = MediaPlayerStatus.NotInit;
|
||||
|
||||
|
||||
private boolean m_isSurfaceCreated = false;
|
||||
private boolean m_isEmitEnable = true;
|
||||
private ArrayList<PendingData> m_pendingDataAr = new ArrayList<PendingData>();
|
||||
|
||||
private long m_appVideoPtr = 0;
|
||||
|
||||
private static Context ms_ctx = null;
|
||||
private static AbsoluteLayout ms_mediaPlayerLayout = null;
|
||||
|
||||
private String m_url = null;
|
||||
private int m_currentTime = 0;
|
||||
// volume
|
||||
private float m_volume = 1.0f;
|
||||
|
||||
VideoPlayerState m_playerState;
|
||||
|
||||
|
||||
private native void emit(long appVideoPtr, String evtName);
|
||||
private native void transferBitmap(Bitmap bitmap, long dataPtr);
|
||||
|
||||
public static void SetDefaultVideoContext(Context context, AbsoluteLayout parentLayout)
|
||||
{
|
||||
ms_ctx = context;
|
||||
ms_mediaPlayerLayout = parentLayout;
|
||||
}
|
||||
|
||||
public LayaVideoPlayer(long appVideoPtr)
|
||||
{
|
||||
m_ctx= ms_ctx;
|
||||
m_parentLayout = ms_mediaPlayerLayout;
|
||||
m_appVideoPtr = appVideoPtr;
|
||||
Init();
|
||||
LayaConch5.GetInstance().addVideoPlayer( this );
|
||||
}
|
||||
|
||||
public LayaVideoPlayer(Context context, AbsoluteLayout parentLayout)
|
||||
{
|
||||
m_ctx = context;
|
||||
m_parentLayout = parentLayout;
|
||||
Init();
|
||||
LayaConch5.GetInstance().addVideoPlayer( this );
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
m_isEmitEnable = false;
|
||||
if(m_mediaPlayer != null)
|
||||
{
|
||||
m_mediaPlayer.release();
|
||||
m_mediaPlayer = null;
|
||||
}
|
||||
m_renderTarget.dispose();
|
||||
|
||||
LayaConch5.GetInstance().removeVideoPlayer( this );
|
||||
}
|
||||
|
||||
private void Init()
|
||||
{
|
||||
if(m_ctx == null)
|
||||
{
|
||||
m_ctx = ms_ctx;
|
||||
m_parentLayout = ms_mediaPlayerLayout;
|
||||
}
|
||||
|
||||
m_playerState = new VideoPlayerState(m_ctx, this);
|
||||
|
||||
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT)
|
||||
{
|
||||
m_renderTarget = new SurfaceViewRenderTarget(m_ctx, m_parentLayout);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_renderTarget = new TextureViewRenderTarget(m_ctx, m_parentLayout);
|
||||
}
|
||||
m_renderTarget.addCallback(this);
|
||||
}
|
||||
|
||||
public MediaPlayer getMediaPlayer()
|
||||
{
|
||||
return m_mediaPlayer;
|
||||
}
|
||||
|
||||
public void Load(String url)
|
||||
{
|
||||
m_url = url;
|
||||
if(!m_isSurfaceCreated)
|
||||
{
|
||||
m_pendingDataAr.clear();
|
||||
m_pendingDataAr.add(new PendingData(PendingType.Load, m_url));
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "[Debug][Video] Load: Begin Load Video " + url);
|
||||
|
||||
Stop();
|
||||
|
||||
try {
|
||||
Uri videoUri = Uri.parse(m_url);
|
||||
|
||||
m_readyState = ReadyState.HAVE_NOTHING;
|
||||
emit("loadstart");
|
||||
m_mediaPlayer.setDataSource(m_ctx, videoUri);
|
||||
m_curStatus = MediaPlayerStatus.Initalized;
|
||||
|
||||
m_mediaPlayer.prepareAsync();
|
||||
m_curStatus = MediaPlayerStatus.Preparing;
|
||||
m_mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mediaPlayer) {
|
||||
m_curStatus = MediaPlayerStatus.Prepared;
|
||||
m_readyState = ReadyState.HAVE_ENOUGH_DATA;
|
||||
//setCurrentTime(m_currentTime);
|
||||
emit("loadedmetadata");
|
||||
emit("canplay");
|
||||
Log.i(TAG, "[Debug][Video]Load: Video is Prepared.");
|
||||
m_playerState.applyAutoplay();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.e(TAG, "[Debug][Video]Load: Have errors on load video");
|
||||
emit("error");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if(!m_isSurfaceCreated)
|
||||
{
|
||||
m_pendingDataAr.add(new PendingData(PendingType.Play));
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_readyState != ReadyState.HAVE_ENOUGH_DATA || m_curStatus == MediaPlayerStatus.Initalized || m_curStatus == MediaPlayerStatus.Preparing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.i(TAG, "[Debug][Video]Play: Start to Play!");
|
||||
setCurrentTime(m_currentTime);
|
||||
m_mediaPlayer.start();
|
||||
m_curStatus = MediaPlayerStatus.Started;
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause()
|
||||
{
|
||||
if (m_curStatus == MediaPlayerStatus.Started) {
|
||||
m_currentTime = getCurrentTime();
|
||||
m_curStatus = MediaPlayerStatus.OnPaused;
|
||||
m_mediaPlayer.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRestart() {
|
||||
if (!m_isSurfaceCreated && m_curStatus == MediaPlayerStatus.OnPaused) {
|
||||
m_pendingDataAr.clear();
|
||||
m_pendingDataAr.add( new PendingData( PendingType.Load, m_url ) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
Play();
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
|
||||
if(!m_isSurfaceCreated)
|
||||
{
|
||||
m_pendingDataAr.add(new PendingData(PendingType.Pause));
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_curStatus == MediaPlayerStatus.Started)
|
||||
{
|
||||
m_curStatus = MediaPlayerStatus.Paused;
|
||||
m_mediaPlayer.pause();
|
||||
|
||||
Log.i(TAG, "[Debug][Video]Pause: Start to Pause");
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if(!m_isSurfaceCreated)
|
||||
{
|
||||
m_pendingDataAr.add(new PendingData(PendingType.Stop));
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_curStatus == MediaPlayerStatus.Started ||
|
||||
m_curStatus == MediaPlayerStatus.Paused) {
|
||||
m_mediaPlayer.stop();
|
||||
m_curStatus = MediaPlayerStatus.Stopped;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean IsPaused()
|
||||
{
|
||||
if(!m_isSurfaceCreated)
|
||||
{
|
||||
Log.e(TAG, "[Debug][Video]IsPaused: The surface is not created");
|
||||
return true;
|
||||
}
|
||||
|
||||
Log.i(TAG, "[Debug][Video]IsPaused: " + m_mediaPlayer.isPlaying());
|
||||
return !m_mediaPlayer.isPlaying();
|
||||
}
|
||||
|
||||
public boolean IsLoop()
|
||||
{
|
||||
return m_playerState.isLoop;
|
||||
}
|
||||
|
||||
public void SetLoop(boolean value)
|
||||
{
|
||||
m_playerState.isLoop = value;
|
||||
m_playerState.applyLoop();
|
||||
}
|
||||
|
||||
public boolean IsAutoplay()
|
||||
{
|
||||
return m_playerState.isAutoplay;
|
||||
}
|
||||
|
||||
public void SetAutoplay(boolean value)
|
||||
{
|
||||
Log.i(TAG, "[Debug][Video]SetAutoplay: SetAutoPlay");
|
||||
m_playerState.isAutoplay = value;
|
||||
}
|
||||
|
||||
public void setX(int x)
|
||||
{
|
||||
m_renderTarget.setX(x);
|
||||
}
|
||||
|
||||
public void setY(int y)
|
||||
{
|
||||
m_renderTarget.setY(y);
|
||||
}
|
||||
|
||||
public void setWidth(int width)
|
||||
{
|
||||
m_renderTarget.setWidth(width);
|
||||
}
|
||||
|
||||
public void setHeight(int height)
|
||||
{
|
||||
m_renderTarget.setHeight(height);
|
||||
}
|
||||
|
||||
public int getVideoWidth()
|
||||
{
|
||||
// Log.i(TAG, "[Debug][Video]getVideoWidth: " + m_mediaPlayer.getVideoWidth());
|
||||
return m_mediaPlayer.getVideoWidth();
|
||||
}
|
||||
|
||||
public int getVideoHeight()
|
||||
{
|
||||
// Log.i(TAG, "[Debug][Video]getVideoHeight: " + m_mediaPlayer.getVideoHeight());
|
||||
return m_mediaPlayer.getVideoHeight();
|
||||
}
|
||||
|
||||
public int GetReadyState() { return m_readyState.getValue(); }
|
||||
|
||||
public int getDuration()
|
||||
{
|
||||
return m_mediaPlayer.getDuration();
|
||||
}
|
||||
|
||||
public int getCurrentTime()
|
||||
{
|
||||
return m_mediaPlayer.getCurrentPosition();
|
||||
}
|
||||
public void setCurrentTime(int pos)
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
m_mediaPlayer.seekTo( pos, SEEK_CLOSEST );
|
||||
}
|
||||
else {
|
||||
m_mediaPlayer.seekTo( pos );
|
||||
}
|
||||
}
|
||||
|
||||
public double getVolume()
|
||||
{
|
||||
return m_volume;
|
||||
}
|
||||
|
||||
public void setVolume(double percentage)
|
||||
{
|
||||
// Log.i(TAG, "[Debug][Video]setVolume: " + percentage);
|
||||
m_volume = (float) (percentage < 0.0 ? 0.0 : (percentage > 1.0 ? 1.0 : percentage));
|
||||
AudioManager am = (AudioManager) m_ctx.getSystemService(AUDIO_SERVICE);
|
||||
int sysVolume= am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
|
||||
if(m_playerState.isMuted)
|
||||
return;
|
||||
|
||||
int value = (int)(sysVolume * m_volume);
|
||||
Log.i(TAG, "[Debug][Video]setVolume: " + value);
|
||||
m_mediaPlayer.setVolume(value, value);
|
||||
}
|
||||
|
||||
public boolean getMuted()
|
||||
{
|
||||
return m_playerState.isMuted;
|
||||
}
|
||||
|
||||
public void setMuted(boolean value)
|
||||
{
|
||||
if(m_playerState.isMuted == value)
|
||||
return;
|
||||
|
||||
m_playerState.isMuted = value;
|
||||
m_playerState.applyMute();
|
||||
}
|
||||
|
||||
private void emit(String evtName)
|
||||
{
|
||||
if(m_isEmitEnable)
|
||||
emit(m_appVideoPtr, evtName);
|
||||
}
|
||||
|
||||
public boolean isFrameAvailable()
|
||||
{
|
||||
if(IsPaused())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_renderTarget.isFrameAvailable();
|
||||
}
|
||||
|
||||
public void updateBitmap(long dataPtr)
|
||||
{
|
||||
Bitmap bitmap = m_renderTarget.getBitmap();
|
||||
// Log.i(TAG, "[Debug][Video]updateBitmap: (" + bitmap.getWidth() + ", " + bitmap.getHeight() + ")" + "pointer : " + dataPtr);
|
||||
transferBitmap(bitmap, dataPtr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderTargetCreated() {
|
||||
Log.i(TAG, "[Debug][Video]surfaceCreated: call me");
|
||||
m_mediaPlayer = new MediaPlayer();
|
||||
m_mediaPlayer.setSurface(m_renderTarget.getSurface());
|
||||
m_mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||
|
||||
m_curStatus = MediaPlayerStatus.Idle;
|
||||
|
||||
m_mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mediaPlayer) {
|
||||
Log.i(TAG, "[Debug][Video]surfaceCreated: emit ended");
|
||||
m_currentTime = 0;
|
||||
emit("ended");
|
||||
}
|
||||
});
|
||||
|
||||
m_isSurfaceCreated = true;
|
||||
|
||||
m_playerState.applyLoop();
|
||||
m_playerState.applyMute();
|
||||
|
||||
for (PendingData p : m_pendingDataAr) {
|
||||
if (p.type == PendingType.Load)
|
||||
Load(p.additionData);
|
||||
else if (p.type == PendingType.Play)
|
||||
Play();
|
||||
else if (p.type == PendingType.Pause)
|
||||
Pause();
|
||||
else if (p.type == PendingType.Stop)
|
||||
Stop();
|
||||
}
|
||||
|
||||
m_pendingDataAr.clear();
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import android.util.Log;
|
||||
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.JsResult;
|
||||
|
||||
public class LayaWebChromeClient extends WebChromeClient
|
||||
{
|
||||
private LayaWebView m_pLayaWebView=null;
|
||||
public LayaWebChromeClient(LayaWebView webView )
|
||||
{
|
||||
m_pLayaWebView = webView;
|
||||
}
|
||||
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
||||
Log.e( "LayaWebView","onJsAlert message=" + message );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import layaair.game.conch.LayaConch5;
|
||||
import layaair.game.config.config;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.AbsoluteLayout;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
class ReadyData
|
||||
{
|
||||
public int m_nX = 0;
|
||||
public int m_nY = 0;
|
||||
public int m_nWidth = 0;
|
||||
public int m_nHeight = 0;
|
||||
public String m_sUrl = "";
|
||||
public Boolean m_bKeyEventCloseView = true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public class LayaWebView extends AbsoluteLayout implements View.OnKeyListener
|
||||
{
|
||||
public ReadyData m_pReadyData = new ReadyData();
|
||||
private LayaWebViewClient m_pWebViewClient = null;
|
||||
private LayaWebChromeClient m_pWebChromeClient = null;
|
||||
private WebView m_pWebView = null;
|
||||
private boolean m_bIsAdd = false;
|
||||
private int m_nX = 0;
|
||||
private int m_nY = 0;
|
||||
private int m_nWidth = 0;
|
||||
private int m_nHeight = 0;
|
||||
public LayaConch5 m_pEngine=null;
|
||||
//------------------------------------------------------------------------------
|
||||
@Override
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event)
|
||||
{
|
||||
if(m_pReadyData.m_bKeyEventCloseView==false) return false;
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN)
|
||||
{
|
||||
if (!ConchJNI.onBackPressed())
|
||||
{
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK && m_pWebView.canGoBack())
|
||||
{
|
||||
//m_pWebView.goBack();//后退
|
||||
if(config.GetInstance().m_bBackkeyWebviewHide) {
|
||||
hideWebView();
|
||||
}
|
||||
else
|
||||
closeWebView();
|
||||
return true; //已处理
|
||||
}
|
||||
else if (keyCode == KeyEvent.KEYCODE_BACK && !m_pWebView.canGoBack())
|
||||
{
|
||||
if(config.GetInstance().m_bBackkeyWebviewHide) {
|
||||
hideWebView();
|
||||
}
|
||||
else
|
||||
closeWebView();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@SuppressLint("JavascriptInterface")
|
||||
public LayaWebView( Context context, LayaConch5 engine )
|
||||
{
|
||||
super( context );
|
||||
m_pEngine = engine;
|
||||
m_pWebViewClient = new LayaWebViewClient();
|
||||
m_pWebViewClient.m_pLayaWebView=this;
|
||||
m_pWebView = new WebView( context );
|
||||
m_pWebView.setWebViewClient(m_pWebViewClient);
|
||||
m_pWebView.getSettings().setJavaScriptEnabled(true);
|
||||
m_pWebView.getSettings().setDefaultTextEncodingName("GBK");
|
||||
m_pWebView.getSettings().setDomStorageEnabled(true);
|
||||
m_pWebView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
|
||||
String appCachePath = context.getApplicationContext().getCacheDir().getAbsolutePath()+"/webviewCache";
|
||||
m_pWebView.getSettings().setAppCachePath(appCachePath);
|
||||
m_pWebView.getSettings().setAllowFileAccess(true);
|
||||
m_pWebView.getSettings().setAppCacheEnabled(true);
|
||||
m_pWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
|
||||
m_pWebView.setBackgroundColor(0);
|
||||
this.addView(m_pWebView);
|
||||
m_pWebChromeClient = new LayaWebChromeClient( this );
|
||||
m_pWebView.setWebChromeClient( m_pWebChromeClient );
|
||||
m_pWebView.addJavascriptInterface(this, "runtime");
|
||||
m_pWebView.setOnKeyListener(this);
|
||||
}
|
||||
public void destory()
|
||||
{
|
||||
this.removeAllViews();
|
||||
if(m_pWebViewClient!=null)
|
||||
{
|
||||
m_pWebViewClient.m_pLayaWebView=null;
|
||||
m_pWebViewClient=null;
|
||||
}
|
||||
m_pEngine=null;
|
||||
if(m_pWebView!=null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
m_pWebView.removeJavascriptInterface("runtime");
|
||||
}
|
||||
m_pWebView.setWebViewClient(null);
|
||||
m_pWebView.setWebChromeClient(null);
|
||||
m_pWebView.setOnKeyListener(null);
|
||||
m_pWebView = null;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public WebView getWebView()
|
||||
{
|
||||
return m_pWebView;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public boolean showWebView() {
|
||||
return m_pReadyData != null && showWebView(m_pReadyData.m_sUrl, m_pReadyData.m_nX, m_pReadyData.m_nY, m_pReadyData.m_nWidth, m_pReadyData.m_nHeight);
|
||||
}
|
||||
public void setReadyData(int x,int y,int w,int h)
|
||||
{
|
||||
m_pReadyData.m_nX=x;
|
||||
m_pReadyData.m_nY=y;
|
||||
m_pReadyData.m_nWidth=w;
|
||||
m_pReadyData.m_nHeight=h;
|
||||
}
|
||||
public void showWebViewEx(){
|
||||
m_pWebView.requestFocus();
|
||||
setVisibility(VISIBLE);
|
||||
}
|
||||
public void closeWebView()
|
||||
{
|
||||
m_pWebView.clearFocus();
|
||||
m_pWebView.loadDataWithBaseURL(null, "","text/html", "utf-8",null);
|
||||
setVisibility(INVISIBLE);
|
||||
ConchJNI.closeExternalWebView();
|
||||
}
|
||||
public void hideWebView()
|
||||
{
|
||||
String sBuffer = "javascript:window.conchBack&&window.conchBack();";
|
||||
Log.i("LayaWebView",sBuffer);
|
||||
m_pWebView.loadUrl( sBuffer );
|
||||
m_pWebView.clearFocus();
|
||||
setVisibility(INVISIBLE);
|
||||
//ConchJNI.closeExternalWebView();
|
||||
}
|
||||
public void stopWebViewLoading()
|
||||
{
|
||||
m_pWebView.stopLoading();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public boolean showWebView( String p_sUrl,int p_nX,int p_nY,int p_nWidth,int p_nHeight )
|
||||
{
|
||||
if( m_pEngine==null ) return false;
|
||||
m_pWebView.requestFocus();
|
||||
//第一次添加
|
||||
if(!m_bIsAdd)
|
||||
{
|
||||
m_nX = p_nX;
|
||||
m_nY = p_nY;
|
||||
m_nWidth = p_nWidth;
|
||||
m_nHeight = p_nHeight;
|
||||
m_pEngine.getAbsLayout().addView(this);
|
||||
//排版
|
||||
this.composing( m_nX,m_nY,m_nWidth,m_nHeight );
|
||||
this.LoadUrl( p_sUrl );
|
||||
m_bIsAdd = true;
|
||||
return true;
|
||||
}
|
||||
//宽和高度改变
|
||||
else if( m_nWidth != p_nWidth || m_nHeight != p_nHeight || m_nX != p_nX || m_nY != p_nY )
|
||||
{
|
||||
m_nWidth = p_nWidth;
|
||||
m_nHeight = p_nHeight;
|
||||
//排版
|
||||
this.composing( p_nX,p_nY,m_nWidth,m_nHeight );
|
||||
this.LoadUrl( p_sUrl );
|
||||
this.setVisibility( VISIBLE );
|
||||
return true;
|
||||
}
|
||||
//都没有改变
|
||||
else
|
||||
{
|
||||
this.composing( p_nX,p_nY,m_nWidth,m_nHeight ); //不调用这个会导致这种情况出问题:开web,关,开editbox,关,再开web,web无法显示
|
||||
this.LoadUrl( p_sUrl );
|
||||
this.setVisibility( VISIBLE );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
private void composing( int p_nX,int p_nY,int p_nWidth,int p_nHeight )
|
||||
{
|
||||
AbsoluteLayout.LayoutParams pWebViewLP = new AbsoluteLayout.LayoutParams( p_nWidth,p_nHeight, p_nX,p_nY);
|
||||
m_pWebView.setLayoutParams( pWebViewLP );
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
private void LoadUrl( String p_sUrl )
|
||||
{
|
||||
if( m_pWebViewClient != null )
|
||||
{
|
||||
m_pWebViewClient.shouldOverrideUrlLoading( m_pWebView,p_sUrl );
|
||||
}
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void JSLog( String p_sBuf )
|
||||
{
|
||||
Log.i( "LayaWebView",p_sBuf );
|
||||
}
|
||||
@JavascriptInterface
|
||||
public void callWebViewJSFunction( String sFunctionName,String sJsonParam,String sCallbackFuncton )
|
||||
{
|
||||
if( m_pWebView != null )
|
||||
{
|
||||
String sBuffer = "javascript: try{" + sFunctionName+"(\"" + sJsonParam +"\",\"" + sCallbackFuncton + "\"" + ");}catch(e){window.runtime.JSLog('CallJSFunction err ' + e.stack );}";
|
||||
Log.i("LayaWebView",sBuffer);
|
||||
m_pWebView.loadUrl( sBuffer );
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@JavascriptInterface
|
||||
public void callConchJSFunction(String sFunctionName, String sJsonParam, String sCallbackFunction)
|
||||
{
|
||||
Log.i("LayaWebView","CallConchJSFuncton functionName=" + sFunctionName + ",sJsonParam=" + sJsonParam + ",callbackFunction=" + sCallbackFunction );
|
||||
ConchJNI.callConchJSFunction( sFunctionName,sJsonParam,sCallbackFunction );
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import layaair.game.conch.LayaConch5;
|
||||
import layaair.game.config.config;
|
||||
|
||||
public class LayaWebViewClient extends WebViewClient
|
||||
{
|
||||
public LayaWebView m_pLayaWebView = null;
|
||||
//------------------------------------------------------------------------------
|
||||
public LayaWebViewClient()
|
||||
{
|
||||
}
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, String sUrl)
|
||||
{
|
||||
Log.i("LayaWebView", "shouldInterceptRequest url=" + sUrl);
|
||||
|
||||
if(config.GetInstance().m_sConchGameUrl != null )
|
||||
{
|
||||
if (sUrl.indexOf(config.GetInstance().m_sConchGameUrl) > -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_pLayaWebView.callConchJSFunction("document.setReferrer", config.GetInstance().m_sWebviewUrl, "");
|
||||
m_pLayaWebView.callConchJSFunction("window.loadConchUrl", sUrl, "");
|
||||
ExportJavaFunction.hideExternalLink();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
return new WebResourceResponse("html","UTF-8",null);
|
||||
}
|
||||
}
|
||||
catch ( Exception exception )
|
||||
{
|
||||
Log.i( "0","exception" + exception.toString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.shouldInterceptRequest(view, sUrl);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
public boolean shouldOverrideUrlLoading( WebView view, String sUrl )
|
||||
{
|
||||
Log.i("LayaWebView", "shouldOverrideUrlLoading url=" + sUrl);
|
||||
if(config.GetInstance().m_sConchGameUrl != null )
|
||||
{
|
||||
if (sUrl.indexOf(config.GetInstance().m_sConchGameUrl) > -1)
|
||||
{
|
||||
m_pLayaWebView.callConchJSFunction("window.loadConchUrl", sUrl, "");
|
||||
ExportJavaFunction.closeExternalLink();
|
||||
}
|
||||
else
|
||||
{
|
||||
view.loadUrl(sUrl);
|
||||
}
|
||||
}
|
||||
/*if (sUrl.startsWith("weixin://wap/pay?")||sUrl.startsWith("mqqapi://forward/url?")) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(sUrl));
|
||||
m_pLayaWebView.m_pEngine.getGameContext().startActivity(intent);
|
||||
view.stopLoading();
|
||||
}
|
||||
else*/
|
||||
{
|
||||
view.loadUrl(sUrl);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
Log.d("LayaWebView","onPageStarted url="+url);
|
||||
super.onPageStarted(view, url, favicon);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public void onLoadResource(WebView view, String url)
|
||||
{
|
||||
super.onLoadResource(view, url);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
public void onPageFinished(android.webkit.WebView view, java.lang.String url)
|
||||
{
|
||||
Log.i("LayaWebView", "onPageFinished");
|
||||
String sBuffer = "javascript:";
|
||||
AssetManager am= LayaConch5.GetInstance().m_AM;
|
||||
try {
|
||||
InputStream in= am.open("scripts/webviewInit.js");
|
||||
int ch;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(); //实现了一个输出流
|
||||
while((ch=in.read())!=-1) {
|
||||
out.write(ch); //将指定的字节写入此 byte 数组输出流
|
||||
}
|
||||
byte[] buff = out.toByteArray();//以 byte 数组的形式返回此输出流的当前内容
|
||||
out.close(); //关闭流
|
||||
in.close(); //关闭流
|
||||
String content = new String(buff, "UTF-8"); //设置字符串编码
|
||||
sBuffer+=content;
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.i("LayaWebView",sBuffer);
|
||||
m_pLayaWebView.getWebView().loadUrl(sBuffer );
|
||||
super.onPageFinished(view, url);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/*
|
||||
* 只处理MotionEvent中的主事件,相当于一次只接收一个点的状态。根据这些信息可以知道
|
||||
* 当前所有的点的位置和状态。
|
||||
*
|
||||
* 限定最多只有10个触摸点。
|
||||
*
|
||||
* 测试:
|
||||
* 单点
|
||||
* 刚down后的小范围移动不产生输出
|
||||
* 一旦move后,就不再限制范围,只要有移动的输入就会有输出
|
||||
* up后数组为空
|
||||
*
|
||||
* 多点
|
||||
* 同时按下n个点后,数组中有n个有效元素
|
||||
* 抬起一个点后,能正确删除
|
||||
* 都抬起后能clear
|
||||
*/
|
||||
public class TouchFilter
|
||||
{
|
||||
int m_nMovRange=10; //移动检测范围。move后,超过1秒钟没有超出此范围则认为静止了
|
||||
/*
|
||||
* m_vTouches 只是用来更新pointer的状态的,内部并不保存和更新当前的实际位置。
|
||||
* 目前 只有当状态为PTSTATE_MOVING的时候,其位置才代表实际位置
|
||||
*/
|
||||
TouchPoint m_vTouches[] = new TouchPoint[10];
|
||||
public float m_fScaleX=1.0f;
|
||||
public float m_fScaleY=1.0f;
|
||||
public TouchFilter()
|
||||
{
|
||||
for( int i=0; i<10; i++)
|
||||
{
|
||||
m_vTouches[i] = new TouchPoint();
|
||||
m_vTouches[i].m_nID=-1;
|
||||
m_vTouches[i].m_nLastMoveX = 0;
|
||||
m_vTouches[i].m_nLastMoveY = 0;
|
||||
m_vTouches[i].m_nTouchState = TouchPoint.PTSTATE_NOTOUCH;
|
||||
}
|
||||
setMoveRangeMM( 0.8f );
|
||||
}
|
||||
|
||||
//外部设置移动的偏差毫米为单位
|
||||
public void setMoveRangeMM( float p_fMM )
|
||||
{
|
||||
//毫米转英寸
|
||||
float fInch = (float) (p_fMM/10.0f*0.3937008);
|
||||
m_nMovRange = Math.round( fInch );
|
||||
}
|
||||
|
||||
TouchPoint GetTouchPt(int p_nID)
|
||||
{
|
||||
for( int i=0; i<10; i++)
|
||||
{
|
||||
if( m_vTouches[i].m_nID<0)
|
||||
continue;
|
||||
if( m_vTouches[i].m_nID==p_nID)
|
||||
return m_vTouches[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void AddTouchPt(int p_nID, int p_nX, int p_nY )
|
||||
{
|
||||
for( int i=0; i<10; i++)
|
||||
{
|
||||
if( m_vTouches[i].m_nID<0)
|
||||
{
|
||||
m_vTouches[i].m_nID = p_nID;
|
||||
m_vTouches[i].m_nLastMoveX = p_nX;
|
||||
m_vTouches[i].m_nLastMoveY = p_nY;
|
||||
m_vTouches[i].m_nTouchState = TouchPoint.PTSTATE_DOWNSTILL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DelTouchPt(int p_nID)
|
||||
{
|
||||
for( int i=0; i<10; i++)
|
||||
{
|
||||
if( m_vTouches[i].m_nID<0)
|
||||
continue;
|
||||
if( m_vTouches[i].m_nID==p_nID)
|
||||
{
|
||||
m_vTouches[i].m_nID = -1;
|
||||
m_vTouches[i].m_nLastMoveX = 0;
|
||||
m_vTouches[i].m_nLastMoveY = 0;
|
||||
m_vTouches[i].m_nTouchState = TouchPoint.PTSTATE_NOTOUCH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ClearTouchPt()
|
||||
{
|
||||
for( int i=0; i<10; i++)
|
||||
{
|
||||
m_vTouches[i].m_nID = -1;
|
||||
m_vTouches[i].m_nLastMoveX = 0;
|
||||
m_vTouches[i].m_nLastMoveY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//测试用,获得当前有效数据的个数
|
||||
/* int GetPointerNum()
|
||||
{
|
||||
int nSum=0;
|
||||
for( int i=0; i<10; i++)
|
||||
{
|
||||
if( m_vTouches[i].m_nID >=0)
|
||||
nSum++;
|
||||
}
|
||||
return nSum;
|
||||
}*/
|
||||
public Boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
if( event==null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int nPointerCount = event.getPointerCount();
|
||||
if( nPointerCount > 0 )
|
||||
{
|
||||
int nRawAction = event.getAction();
|
||||
int nAction = nRawAction&0xff;
|
||||
int nActionidx = ( nRawAction&MotionEvent.ACTION_POINTER_INDEX_MASK)>>MotionEvent.ACTION_POINTER_INDEX_SHIFT;
|
||||
int id = event.getPointerId( nActionidx );
|
||||
int nx = (int)event.getX( nActionidx );
|
||||
if(nx<0)nx=0;
|
||||
int ny = (int)event.getY( nActionidx );
|
||||
if(ny<0)ny=0;
|
||||
//加上缩放。即如果用了fixedsize,需要把touch缩放一下
|
||||
nx*=m_fScaleX;
|
||||
ny*=m_fScaleY;
|
||||
switch( nAction )
|
||||
{
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
AddTouchPt(id, nx, ny);
|
||||
//Log.i("0",">>>>input java onTouchEvent ACTION_DOWN" );
|
||||
ConchJNI.handleTouch(nAction, (id < 10) ? id : 0, nx, ny);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
ClearTouchPt();
|
||||
ConchJNI.handleTouch(nAction, (id < 10) ? id : 0, nx, ny);
|
||||
break;
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
AddTouchPt(id, nx, ny);
|
||||
ConchJNI.handleTouch(nAction, (id < 10) ? id : 0, nx, ny);
|
||||
break;
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
DelTouchPt(id);
|
||||
ConchJNI.handleTouch(nAction, (id < 10) ? id : 0, nx, ny);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
{
|
||||
for( int i = 0; i < nPointerCount; i++ )
|
||||
{
|
||||
int nID = event.getPointerId( i );
|
||||
int nx1 = (int)event.getX( i );
|
||||
if(nx1<0)nx1=0;
|
||||
int ny1 = (int)event.getY( i );
|
||||
if(ny1<0)ny1=0;
|
||||
//加上缩放。即如果用了fixedsize,需要把touch缩放一下
|
||||
nx1*=m_fScaleX;
|
||||
ny1*=m_fScaleY;
|
||||
boolean bIgnoreCurEvent = false;
|
||||
TouchPoint pCurTouch = GetTouchPt( nID );
|
||||
if( pCurTouch != null )
|
||||
{
|
||||
if(nx1==pCurTouch.m_nLastMoveX && ny1==pCurTouch.m_nLastMoveY ){
|
||||
bIgnoreCurEvent=true;
|
||||
}else{
|
||||
if( pCurTouch.m_nTouchState == TouchPoint.PTSTATE_DOWNSTILL )
|
||||
{
|
||||
if( Math.abs( nx1-pCurTouch.m_nLastMoveX)>m_nMovRange ||
|
||||
Math.abs( ny1-pCurTouch.m_nLastMoveY)>m_nMovRange )
|
||||
{
|
||||
pCurTouch.m_nLastMoveX = nx1;
|
||||
pCurTouch.m_nLastMoveY = ny1;
|
||||
pCurTouch.m_nTouchState = TouchPoint.PTSTATE_MOVING;
|
||||
}
|
||||
else
|
||||
{
|
||||
bIgnoreCurEvent = true;
|
||||
}
|
||||
}
|
||||
else if( pCurTouch.m_nTouchState== TouchPoint.PTSTATE_MOVING )
|
||||
{
|
||||
pCurTouch.m_nLastMoveX = nx1;
|
||||
pCurTouch.m_nLastMoveY = ny1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e("","touch事件错误,根据id没有找到当前touch对象,id="+nID );
|
||||
}
|
||||
if( !bIgnoreCurEvent )
|
||||
{
|
||||
ConchJNI.handleTouch(nAction, (nID < 10) ? nID : 0, nx1, ny1);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package layaair.game.browser;
|
||||
|
||||
/*
|
||||
* 维护当前pointer的状态。
|
||||
*/
|
||||
public class TouchPoint
|
||||
{
|
||||
public static int PTSTATE_NOTOUCH=0;
|
||||
public static int PTSTATE_DOWNSTILL=1;
|
||||
public static int PTSTATE_MOVING = 2;
|
||||
|
||||
public int m_nID=-1;
|
||||
int m_nTouchState=PTSTATE_NOTOUCH;
|
||||
int m_nLastMoveX=0;
|
||||
int m_nLastMoveY=0;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package layaair.game.browser.Video;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
public interface IVideoRenderTarget {
|
||||
void addCallback(IVideoRenderTarget.Callback callback);
|
||||
void setX(int val);
|
||||
void setY(int val);
|
||||
void setWidth(int val);
|
||||
void setHeight(int val);
|
||||
|
||||
void dispose();
|
||||
|
||||
boolean isFrameAvailable();
|
||||
Bitmap getBitmap();
|
||||
|
||||
Surface getSurface();
|
||||
|
||||
interface Callback
|
||||
{
|
||||
void onRenderTargetCreated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
package layaair.game.browser.Video;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsoluteLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static layaair.game.browser.LayaVideoPlayer.TAG;
|
||||
|
||||
public class SurfaceViewRenderTarget implements IVideoRenderTarget, SurfaceHolder.Callback {
|
||||
|
||||
private SurfaceView m_surfaceView = null;
|
||||
private SurfaceHolder m_surfceHolder = null;
|
||||
|
||||
private AbsoluteLayout m_mediaPlayerLayout = null;
|
||||
private AbsoluteLayout m_parentLayout = null;
|
||||
private Context m_ctx;
|
||||
|
||||
private ArrayList<Callback> m_callbacks = new ArrayList<Callback>();
|
||||
|
||||
public SurfaceViewRenderTarget(Context ctx, AbsoluteLayout parentLayout)
|
||||
{
|
||||
m_ctx = ctx;
|
||||
m_parentLayout = parentLayout;
|
||||
|
||||
Create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
((Activity)m_ctx).runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m_mediaPlayerLayout.removeAllViews();
|
||||
m_parentLayout.removeView(m_mediaPlayerLayout);
|
||||
m_mediaPlayerLayout = null;
|
||||
m_parentLayout.requestLayout();
|
||||
Log.i(TAG, "[Debug][Video]SurfaceViewRenderTarget: dispose");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void Create()
|
||||
{
|
||||
final SurfaceViewRenderTarget thisObj = this;
|
||||
|
||||
((Activity)m_ctx).runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m_surfaceView = new SurfaceView(m_ctx);
|
||||
m_surfceHolder = m_surfaceView.getHolder();
|
||||
m_surfceHolder.addCallback(thisObj);
|
||||
|
||||
m_mediaPlayerLayout = new AbsoluteLayout(m_ctx);
|
||||
m_mediaPlayerLayout.addView(m_surfaceView, new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
m_parentLayout.addView(m_mediaPlayerLayout, new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
m_surfaceView.setZOrderMediaOverlay(true);
|
||||
m_surfaceView.setLayoutParams(new AbsoluteLayout.LayoutParams(800, 480, 0, 0));
|
||||
m_parentLayout.requestLayout();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(Callback callback) {
|
||||
m_callbacks.add(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrameAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getBitmap()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Surface getSurface()
|
||||
{
|
||||
return m_surfceHolder.getSurface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setX(int val) {
|
||||
final int newVal = val;
|
||||
((Activity)m_ctx).runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i(TAG, "[Debug][Video]run: setX : " + newVal);
|
||||
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) m_surfaceView.getLayoutParams();
|
||||
layoutParams.x = newVal;
|
||||
m_surfaceView.setLayoutParams(layoutParams);
|
||||
m_parentLayout.requestLayout();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setY(int val) {
|
||||
final int newVal = val;
|
||||
((Activity)m_ctx).runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i(TAG, "[Debug][Video]run: setY : " + newVal);
|
||||
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) m_surfaceView.getLayoutParams();
|
||||
layoutParams.y = newVal;
|
||||
m_surfaceView.setLayoutParams(layoutParams);
|
||||
m_parentLayout.requestLayout();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int val) {
|
||||
final int newVal = val;
|
||||
((Activity)m_ctx).runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i(TAG, "[Debug][Video]setWidth : " + newVal);
|
||||
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) m_surfaceView.getLayoutParams();
|
||||
layoutParams.width = newVal;
|
||||
m_surfaceView.setLayoutParams(layoutParams);
|
||||
m_parentLayout.requestLayout();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(int val) {
|
||||
final int newVal = val;
|
||||
((Activity)m_ctx).runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i(TAG, "[Debug][Video]setHeight : " + newVal);
|
||||
AbsoluteLayout.LayoutParams layoutParams = (AbsoluteLayout.LayoutParams) m_surfaceView.getLayoutParams();
|
||||
layoutParams.height = newVal;
|
||||
m_surfaceView.setLayoutParams(layoutParams);
|
||||
m_parentLayout.requestLayout();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder surfaceHolder) {
|
||||
for(int i = 0; i < m_callbacks.size(); i++)
|
||||
{
|
||||
m_callbacks.get(i).onRenderTargetCreated();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
|
||||
|
||||
}
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
package layaair.game.browser.Video;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Surface;
|
||||
import android.view.TextureView;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AbsoluteLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static layaair.game.browser.LayaVideoPlayer.TAG;
|
||||
|
||||
public class TextureViewRenderTarget implements IVideoRenderTarget, TextureView.SurfaceTextureListener {
|
||||
private ArrayList<Callback> m_callbacks = new ArrayList<Callback>();
|
||||
|
||||
private TextureView m_textureView;
|
||||
private SurfaceTexture m_SurfaceTexture = null;
|
||||
private Surface m_surface;
|
||||
|
||||
private Context m_ctx;
|
||||
private AbsoluteLayout m_parentLayout = null;
|
||||
|
||||
private boolean m_isFrameAvailable;
|
||||
private Bitmap m_bitmap;
|
||||
|
||||
private int m_width;
|
||||
private int m_height;
|
||||
|
||||
public TextureViewRenderTarget(Context context, AbsoluteLayout parentLayout)
|
||||
{
|
||||
m_ctx = context;
|
||||
m_parentLayout = parentLayout;
|
||||
|
||||
m_isFrameAvailable = false;
|
||||
|
||||
WindowManager wm = (WindowManager)m_ctx.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getMetrics(dm);
|
||||
m_width = dm.widthPixels;
|
||||
m_height = dm.heightPixels;
|
||||
|
||||
// Log.i(TAG, "TextureViewRenderTarget: (" + m_width + ", " + m_height + ")");
|
||||
|
||||
m_bitmap = Bitmap.createBitmap(dm.widthPixels, dm.heightPixels, Bitmap.Config.ARGB_8888);
|
||||
|
||||
final TextureViewRenderTarget thisObj = this;
|
||||
|
||||
((Activity)m_ctx).runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m_textureView = new TextureView(m_ctx);
|
||||
m_textureView.setSurfaceTextureListener(thisObj);
|
||||
|
||||
m_parentLayout.addView(m_textureView, new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
m_textureView.setLayoutParams(new AbsoluteLayout.LayoutParams(thisObj.m_width, thisObj.m_height, 0, 0 ));
|
||||
//m_textureView.setZ(Long.MIN_VALUE + 1);
|
||||
|
||||
Matrix m = new Matrix();
|
||||
m.postTranslate(thisObj.m_width, thisObj.m_height);
|
||||
m_textureView.setTransform(m);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCallback(Callback callback)
|
||||
{
|
||||
m_callbacks.add(callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrameAvailable()
|
||||
{
|
||||
return m_isFrameAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setX(int val) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setY(int val) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWidth(int val) {
|
||||
if(m_width != val)
|
||||
{
|
||||
m_bitmap = Bitmap.createBitmap(m_width, m_height, Bitmap.Config.ARGB_8888);
|
||||
m_width = val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeight(int val) {
|
||||
if(m_height != val)
|
||||
{
|
||||
m_bitmap = Bitmap.createBitmap(m_width, m_height, Bitmap.Config.ARGB_8888);
|
||||
m_height = val;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
Log.i(TAG, "[Debug][Video] dispose");
|
||||
((Activity)m_ctx).runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
m_parentLayout.removeView(m_textureView);
|
||||
m_textureView = null;
|
||||
m_bitmap = null;
|
||||
m_surface = null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Surface getSurface() {
|
||||
return m_surface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getBitmap() {
|
||||
m_isFrameAvailable = false;
|
||||
m_textureView.getBitmap(m_bitmap);
|
||||
return m_bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
|
||||
m_SurfaceTexture = surfaceTexture;
|
||||
m_surface = new Surface(surfaceTexture);
|
||||
// m_SurfaceTexture.setOnFrameAvailableListener(this);
|
||||
|
||||
m_isFrameAvailable = true;
|
||||
for(int ii = 0; ii < m_callbacks.size(); ii++)
|
||||
{
|
||||
m_callbacks.get(ii).onRenderTargetCreated();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
|
||||
this.m_isFrameAvailable = true;
|
||||
}
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package layaair.game.browser.Video;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.util.Log;
|
||||
|
||||
import layaair.game.browser.LayaVideoPlayer;
|
||||
|
||||
import static android.content.Context.AUDIO_SERVICE;
|
||||
import static layaair.game.browser.LayaVideoPlayer.TAG;
|
||||
|
||||
public class VideoPlayerState {
|
||||
public boolean isMuted = false;
|
||||
public boolean isAutoplay = false;
|
||||
public boolean isLoop = false;
|
||||
|
||||
private LayaVideoPlayer m_layaVideoPlayer;
|
||||
private Context m_ctx;
|
||||
|
||||
public VideoPlayerState(Context context, LayaVideoPlayer layaVideoPlayer)
|
||||
{
|
||||
m_layaVideoPlayer = layaVideoPlayer;
|
||||
m_ctx = context;
|
||||
}
|
||||
|
||||
public boolean applyMute()
|
||||
{
|
||||
MediaPlayer mediaPlayer = m_layaVideoPlayer.getMediaPlayer();
|
||||
if(mediaPlayer == null)
|
||||
return false;
|
||||
|
||||
double volume = isMuted ? 0 : m_layaVideoPlayer.getVolume();
|
||||
AudioManager am = (AudioManager) m_ctx.getSystemService(AUDIO_SERVICE);
|
||||
int sysVolume= am.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
int value = (int)(sysVolume * volume);
|
||||
mediaPlayer.setVolume(value, value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean applyAutoplay()
|
||||
{
|
||||
if(m_layaVideoPlayer.getMediaPlayer() == null)
|
||||
return false;
|
||||
|
||||
if(isAutoplay) {
|
||||
Log.i(TAG, "[Debug][Video]applyAutoplay: call me");
|
||||
m_layaVideoPlayer.Play();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean applyLoop()
|
||||
{
|
||||
MediaPlayer mediaPlayer = m_layaVideoPlayer.getMediaPlayer();
|
||||
|
||||
if(mediaPlayer == null)
|
||||
return false;
|
||||
|
||||
mediaPlayer.setLooping(isLoop);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package layaair.game.conch;
|
||||
|
||||
public interface ILayaEventListener {
|
||||
void ExitGame();
|
||||
void destory();
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package layaair.game.conch;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.AssetManager;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.widget.AbsoluteLayout;
|
||||
|
||||
public abstract interface ILayaGameEgine {
|
||||
// 设置是否插件方式运行
|
||||
void setIsPlugin(boolean isPlugin);
|
||||
// 设置游戏缓存目录
|
||||
void setAppCacheDir(String _cacheDir);
|
||||
// 设置下载线程的个数
|
||||
void setDownloadThreadNum(int nNum);
|
||||
// 设置扩展包路径
|
||||
void setExpansionZipDir( final String mainPath,final String patchPath );
|
||||
// 设置so路径
|
||||
void setSoPath(String _soPath);
|
||||
// 设置jar文件名
|
||||
void setJarFile(String _jarFile);
|
||||
// 设置jar路径asset
|
||||
void setAssetInfo(AssetManager am);
|
||||
// 设置so文件名
|
||||
void setSoFile(String _soFile);
|
||||
// 引擎销毁
|
||||
void onDestroy();
|
||||
// 获得游戏显示的view
|
||||
AbsoluteLayout getAbsLayout();
|
||||
// 监听游戏事件(退出)
|
||||
void setLayaEventListener(ILayaEventListener _lis);
|
||||
|
||||
// 设置游戏activity的context
|
||||
void setContext(Context ctx);
|
||||
// 设置游戏地址
|
||||
void setGameUrl(String _url);
|
||||
// 游戏初始化
|
||||
void onCreate();
|
||||
// 游戏切到后台
|
||||
void onPause();
|
||||
// 游戏恢复
|
||||
void onResume();
|
||||
// 游戏停止
|
||||
void onStop();
|
||||
// 按键监听
|
||||
void onKeyEvent(String keyEvent,int keyCode);
|
||||
|
||||
void onNewIntent(Intent intent);
|
||||
|
||||
void onRestart();
|
||||
|
||||
void onActivityResult(int requestCode, int resultCode,Intent intent);
|
||||
|
||||
// 设置是否拦截返回按键 默认不拦截
|
||||
void setInterceptKey(boolean _intercept);
|
||||
|
||||
//设置本地包
|
||||
void setLocalizable(boolean b);
|
||||
|
||||
//设置surface的固定大小。这个最终会被缩放到全屏。
|
||||
void setResolution(int w, int h);
|
||||
|
||||
//是否允许引擎监听onLayout事件。测试救急用。平常勿用。
|
||||
void _enableOnLayout(boolean b);
|
||||
|
||||
void setAlertTitle(String title);
|
||||
|
||||
void setStringOnBackPressed(String str);
|
||||
}
|
||||
+1119
File diff suppressed because it is too large
Load Diff
+106
@@ -0,0 +1,106 @@
|
||||
package layaair.game.config;
|
||||
|
||||
import android.util.Log;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
public class config
|
||||
{
|
||||
private static config ms_config = null;
|
||||
public boolean m_bCheckNetwork=false;
|
||||
public String m_sWebviewUrl = null;
|
||||
public String m_sConchGameUrl = null;
|
||||
public boolean m_bBackkeyWebviewHide=false;
|
||||
public int m_nThreadMode = 2;
|
||||
public int m_nDebugMode = 0;
|
||||
public int m_nDebugPort = 5959;
|
||||
private Properties m_pProperties = null;
|
||||
//------------------------------------------------------------------------------
|
||||
//市场相关的
|
||||
public int m_nMarketWaitScreenBKColor=0xffffffff; //市场等待的背景颜色
|
||||
|
||||
public static config GetInstance()
|
||||
{
|
||||
if( ms_config == null )
|
||||
{
|
||||
ms_config = new config();
|
||||
}
|
||||
return ms_config;
|
||||
}
|
||||
|
||||
public static void DelInstance()
|
||||
{
|
||||
ms_config=null;
|
||||
}
|
||||
public config()
|
||||
{
|
||||
|
||||
}
|
||||
private int getColor(String color)
|
||||
{
|
||||
if(color!=null) {
|
||||
boolean hasAlpha = color.length() <= 6;
|
||||
int nColor = (int) (Long.parseLong(color, 16));
|
||||
if (hasAlpha) {
|
||||
nColor |= 0xff000000;
|
||||
}
|
||||
return nColor;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public String getProperty( final String name,final String defaultValue )
|
||||
{
|
||||
if( m_pProperties != null)
|
||||
{
|
||||
return m_pProperties.getProperty(name,defaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e("LayaBox", "getProperty: error m_pProperties==null name=" + name );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public String getProperty( final String name)
|
||||
{
|
||||
if( m_pProperties != null)
|
||||
{
|
||||
return m_pProperties.getProperty(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.e("LayaBox", "getProperty: error m_pProperties==null name=" + name );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean init( InputStream pInputStream )
|
||||
{
|
||||
if(m_pProperties == null) {
|
||||
m_pProperties = new Properties();
|
||||
}
|
||||
try {
|
||||
if(pInputStream==null)
|
||||
return false;
|
||||
m_pProperties.load(pInputStream);
|
||||
m_bCheckNetwork=!"0".equals( m_pProperties.getProperty("CheckNetwork","0"));
|
||||
m_sWebviewUrl=m_pProperties.getProperty("WebviewUrl");
|
||||
m_sConchGameUrl=m_pProperties.getProperty("ConchGameUrl");
|
||||
m_bBackkeyWebviewHide=!"0".equals( m_pProperties.getProperty("BackKeyWebviewHide","0"));
|
||||
int threadMode = Integer.parseInt(m_pProperties.getProperty("ThreadMode","2"));
|
||||
if (threadMode == 1 || threadMode == 2) {
|
||||
m_nThreadMode = threadMode;
|
||||
}
|
||||
|
||||
int debugMode = Integer.parseInt(m_pProperties.getProperty("JSDebugMode","0"));
|
||||
if (debugMode == 0 || debugMode == 1 || debugMode == 2) {
|
||||
m_nDebugMode = debugMode;
|
||||
}
|
||||
m_nDebugPort = Integer.parseInt(m_pProperties.getProperty("JSDebugPort","5919"));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
m_pProperties=null;
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+223
@@ -0,0 +1,223 @@
|
||||
package layaair.game.device;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class DevID
|
||||
{
|
||||
protected Context m_Context;
|
||||
public DevID( Context context)
|
||||
{
|
||||
m_Context = context;
|
||||
}
|
||||
public String GetAnUniqueID()
|
||||
{
|
||||
String devsn = GetDevSerial();
|
||||
if( devsn!=null && devsn.length()>0)
|
||||
return devsn;
|
||||
String wifimac = GetWifiMac();
|
||||
if( wifimac !=null && wifimac.length()>0 )
|
||||
{
|
||||
return wifimac.replace(":", "");
|
||||
}
|
||||
String androidid = GetAndroidID();
|
||||
if( androidid!=null && androidid.length()>0 )
|
||||
return androidid;
|
||||
return GetMyUniqueID();
|
||||
}
|
||||
public String GetIMEI()
|
||||
{
|
||||
String ts = Context.TELEPHONY_SERVICE;
|
||||
TelephonyManager telephonyMgr = (TelephonyManager) m_Context.getSystemService(ts);
|
||||
String temp="UnKnow";
|
||||
if( telephonyMgr!=null )
|
||||
{
|
||||
try
|
||||
{
|
||||
temp=telephonyMgr.getDeviceId();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.e("LayaBox", e.toString());
|
||||
}
|
||||
catch(Throwable ex)
|
||||
{
|
||||
Log.e("LayaBox",ex.toString());
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
public String GetIMSI()
|
||||
{
|
||||
String ts = Context.TELEPHONY_SERVICE;
|
||||
TelephonyManager telephonyMgr = (TelephonyManager) m_Context.getSystemService(ts);
|
||||
if( telephonyMgr !=null )
|
||||
{
|
||||
String temp=null;
|
||||
try
|
||||
{
|
||||
temp=telephonyMgr.getSubscriberId();
|
||||
}
|
||||
catch(SecurityException e)
|
||||
{
|
||||
Log.e("LayaBox",e.toString());
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getIMSI_1() {
|
||||
String imsiParcel = runCommand("service call iphonesubinfo 3");
|
||||
String imsi = getNumberFromParcel(imsiParcel);
|
||||
Log.d("laya", "IMSI_1:" + imsi);
|
||||
return imsi;
|
||||
}
|
||||
|
||||
public static String getIMSI_2() {
|
||||
String imsiParcel = runCommand("service call iphonesubinfo2 3");
|
||||
String imsi = getNumberFromParcel(imsiParcel);
|
||||
Log.d("laya", "IMSI_2:" + imsi);
|
||||
return imsi;
|
||||
}
|
||||
|
||||
|
||||
public static String runCommand(String src) {
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec(src);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
int read;
|
||||
char[] buffer = new char[2048];
|
||||
StringBuilder output = new StringBuilder();
|
||||
while ((read = reader.read(buffer)) > 0) {
|
||||
output.append(buffer, 0, read);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
// Waits for the command to finish.
|
||||
process.waitFor();
|
||||
|
||||
return output.toString();
|
||||
} catch (IOException e) {
|
||||
Log.e("apipas", "IOException:" + e.getMessage());
|
||||
return null;
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
Log.e("apipas", "InterruptedException:" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getNumberFromParcel(String str) {
|
||||
String res = "";
|
||||
if (str != null && str.length() > 0) {
|
||||
String lines[] = str.split("\n");
|
||||
for (String line : lines) {
|
||||
if (line == null || line.length() == 0)
|
||||
continue;
|
||||
String content[] = line.split("'");
|
||||
if (content.length > 1) {
|
||||
res += content[1].replace(".", "");
|
||||
}
|
||||
}
|
||||
} else return "NA";
|
||||
return res;
|
||||
}
|
||||
public String GetWifiMac()
|
||||
{
|
||||
String mac= getMac();
|
||||
return mac;
|
||||
//WifiManager wm = (WifiManager) m_Context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
//return wm.getConnectionInfo().getMacAddress();
|
||||
}
|
||||
|
||||
private static String parseByte(byte b) {
|
||||
String s = "00" + Integer.toHexString(b)+":";
|
||||
return s.substring(s.length() - 3);
|
||||
}
|
||||
/**
|
||||
* 获取当前系统连接网络的网卡的mac地址
|
||||
* @return
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
public static final String getMac() {
|
||||
byte[] mac = null;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try {
|
||||
Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (netInterfaces.hasMoreElements()) {
|
||||
NetworkInterface ni = netInterfaces.nextElement();
|
||||
Enumeration<InetAddress> address = ni.getInetAddresses();
|
||||
|
||||
while (address.hasMoreElements()) {
|
||||
InetAddress ip = address.nextElement();
|
||||
if (ip.isAnyLocalAddress() || !(ip instanceof Inet4Address) || ip.isLoopbackAddress())
|
||||
continue;
|
||||
if (ip.isSiteLocalAddress())
|
||||
mac = ni.getHardwareAddress();
|
||||
else if (!ip.isLinkLocalAddress()) {
|
||||
mac = ni.getHardwareAddress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(mac != null){
|
||||
for(int i=0 ;i<mac.length ;i++){
|
||||
sb.append(parseByte(mac[i]));
|
||||
}
|
||||
return sb.substring(0, sb.length()-1);
|
||||
}else{
|
||||
return null;
|
||||
//return UpdateService.mDefaultMacAddress;
|
||||
}
|
||||
}
|
||||
|
||||
public String GetDevSerial()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public String GetAndroidID()
|
||||
{
|
||||
return Secure.getString(m_Context.getContentResolver(), Secure.ANDROID_ID);
|
||||
}
|
||||
public String GetMyUniqueID()
|
||||
{
|
||||
return "UNKNOWN";
|
||||
}
|
||||
public String GenARandomID()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
public String GetPhoneModelAndSDK()
|
||||
{
|
||||
return Build.MODEL;//"Model:"+Build.MODEL;//+",SDK:"+Build.VERSION.SDK;
|
||||
}
|
||||
public String GetOSVersion(){
|
||||
return android.os.Build.VERSION.RELEASE;
|
||||
}
|
||||
public int[] GetResolutionArray(){
|
||||
DisplayMetrics pDm = new DisplayMetrics();
|
||||
WindowManager wm = (WindowManager)(m_Context.getSystemService(Context.WINDOW_SERVICE));
|
||||
wm.getDefaultDisplay().getMetrics(pDm);
|
||||
return new int[]{pDm.widthPixels,pDm.heightPixels,pDm.densityDpi};
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
package layaair.game.network;
|
||||
|
||||
import layaair.game.browser.ConchJNI;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
public class NetworkReceiver extends BroadcastReceiver
|
||||
{
|
||||
/**
|
||||
* 枚举网络状态
|
||||
* NET_NO:没有网络
|
||||
* NET_2G:2g网络
|
||||
* NET_3G:3g网络
|
||||
* NET_4G:4g网络
|
||||
* NET_WIFI:wifi
|
||||
* NET_UNKNOWN:未知网络
|
||||
*/
|
||||
public final static int NET_NO = 0;
|
||||
public final static int NET_WIFI = 1;
|
||||
public final static int NET_2G = 2;
|
||||
public final static int NET_3G = 3;
|
||||
public final static int NET_4G = 4;
|
||||
public final static int NET_UNKNOWN = 5;
|
||||
|
||||
@Override
|
||||
public void onReceive( Context context, Intent intent )
|
||||
{
|
||||
String sAction = intent.getAction();
|
||||
if ( sAction.equals(ConnectivityManager.CONNECTIVITY_ACTION ) )
|
||||
{
|
||||
Log.i("0",">>>>>>>>>>>>>The network has changed");
|
||||
handleConnected( getConnectedType( context ) );
|
||||
}
|
||||
}
|
||||
public int getConnectedType( Context context )
|
||||
{
|
||||
int nStateCode = NET_NO;
|
||||
ConnectivityManager pConnectManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo pNetwordInfo = pConnectManager.getActiveNetworkInfo();
|
||||
if ( pNetwordInfo != null && pNetwordInfo.isConnected())
|
||||
{
|
||||
switch ( pNetwordInfo.getType() )
|
||||
{
|
||||
case ConnectivityManager.TYPE_WIFI:
|
||||
nStateCode = NET_WIFI;
|
||||
break;
|
||||
case ConnectivityManager.TYPE_MOBILE:
|
||||
switch (pNetwordInfo.getSubtype())
|
||||
{
|
||||
case TelephonyManager.NETWORK_TYPE_GPRS: //联通2g
|
||||
case TelephonyManager.NETWORK_TYPE_CDMA: //电信2g
|
||||
case TelephonyManager.NETWORK_TYPE_EDGE: //移动2g
|
||||
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
||||
case TelephonyManager. NETWORK_TYPE_IDEN:
|
||||
nStateCode = NET_2G;
|
||||
break;
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_A: //电信3g
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
||||
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
||||
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
||||
nStateCode = NET_3G;
|
||||
break;
|
||||
case TelephonyManager.NETWORK_TYPE_LTE:
|
||||
nStateCode = NET_4G;
|
||||
break;
|
||||
default:
|
||||
nStateCode = NET_UNKNOWN;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
nStateCode = NET_UNKNOWN;
|
||||
}
|
||||
}
|
||||
return nStateCode;
|
||||
}
|
||||
public void handleConnected( int nState )
|
||||
{
|
||||
Log.i("0", "connected type=" + nState );
|
||||
ConchJNI.networkChanged(nState);
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package layaair.game.utility;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import layaair.game.browser.ConchJNI;
|
||||
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaPlayer.OnCompletionListener;
|
||||
import android.util.Log;
|
||||
|
||||
public class LayaAudioMusic
|
||||
{
|
||||
private static MediaPlayer mBackgroundMediaPlayer = null;
|
||||
private static float mLeftVolume = 0.5f;
|
||||
private static float mRightVolume = 0.5f;
|
||||
private static boolean mPaused = false;// whether music is paused state.
|
||||
private static boolean mManualPaused = false;// whether music is paused manually before the program is switched to the background.
|
||||
private static String mCurrentPath = null;
|
||||
private static Object s_lock=new Object();
|
||||
public static void uninit(){
|
||||
|
||||
synchronized (s_lock) {
|
||||
if(mBackgroundMediaPlayer!=null){
|
||||
mBackgroundMediaPlayer.stop();
|
||||
mBackgroundMediaPlayer=null;
|
||||
}
|
||||
mCurrentPath=null;
|
||||
mPaused=false;
|
||||
mManualPaused=false;
|
||||
}
|
||||
}
|
||||
static public void playBackgroundMusic( String p_sFilePath,int p_nTimes,int nCurrentTime )
|
||||
{
|
||||
synchronized (s_lock) {
|
||||
if (mCurrentPath == null)
|
||||
{
|
||||
File localStoragePath = new File(p_sFilePath);
|
||||
if( !localStoragePath.exists()){
|
||||
return;
|
||||
}
|
||||
// it is the first time to play background music or end() was called
|
||||
mBackgroundMediaPlayer = new MediaPlayer();
|
||||
mCurrentPath = p_sFilePath;
|
||||
} else {
|
||||
if (!mCurrentPath.equals(p_sFilePath)) {
|
||||
// play new background music
|
||||
|
||||
// release old resource and create a new one
|
||||
if (mBackgroundMediaPlayer != null) {
|
||||
mBackgroundMediaPlayer.release();
|
||||
}
|
||||
mBackgroundMediaPlayer = new MediaPlayer();
|
||||
// record the path
|
||||
mCurrentPath = p_sFilePath;
|
||||
}
|
||||
}
|
||||
if (mBackgroundMediaPlayer != null)
|
||||
{
|
||||
// if the music is playing or paused, stop it
|
||||
if (mBackgroundMediaPlayer.isPlaying()) {
|
||||
mBackgroundMediaPlayer.stop();
|
||||
//Log.i("MediaPlayer", "stop play");
|
||||
}
|
||||
mBackgroundMediaPlayer.reset();
|
||||
try {
|
||||
if (p_sFilePath.startsWith("/")) {
|
||||
final FileInputStream fis = new FileInputStream(p_sFilePath);
|
||||
mBackgroundMediaPlayer.setDataSource(fis.getFD());
|
||||
fis.close();
|
||||
}
|
||||
/*else {
|
||||
//final AssetFileDescriptor assetFileDescritor = this.mContext.getAssets().openFd(pPath);
|
||||
//mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(), assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
|
||||
}*/
|
||||
|
||||
mBackgroundMediaPlayer.setVolume(mLeftVolume, mRightVolume);
|
||||
} catch (final Exception e) {
|
||||
Log.e("Audio",">>>>>>"+e.toString());
|
||||
mBackgroundMediaPlayer = null;
|
||||
return;//hugao
|
||||
}
|
||||
Boolean bLoop = (p_nTimes==-1);
|
||||
mBackgroundMediaPlayer.setLooping( bLoop );
|
||||
try {
|
||||
mBackgroundMediaPlayer.prepare();
|
||||
mBackgroundMediaPlayer.seekTo(nCurrentTime);
|
||||
mBackgroundMediaPlayer.start();
|
||||
mPaused = false;
|
||||
mBackgroundMediaPlayer.setOnCompletionListener(new OnCompletionListener(){
|
||||
public void onCompletion(MediaPlayer arg0)
|
||||
{
|
||||
ConchJNI.audioMusicPlayEnd();
|
||||
}
|
||||
});
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
static public void stopBackgroundMusic()
|
||||
{
|
||||
if (mBackgroundMediaPlayer != null) {
|
||||
mBackgroundMediaPlayer.stop();
|
||||
// should set the state, if not, the following sequence will be error
|
||||
// play -> pause -> stop -> resume
|
||||
mPaused = false;
|
||||
}
|
||||
}
|
||||
static public void pauseBackgroundMusic()
|
||||
{
|
||||
if (mBackgroundMediaPlayer != null && mBackgroundMediaPlayer.isPlaying()) {
|
||||
mBackgroundMediaPlayer.pause();
|
||||
mPaused = true;
|
||||
mManualPaused = true;
|
||||
}
|
||||
}
|
||||
static public void resumeBackgroundMusic()
|
||||
{
|
||||
if (mBackgroundMediaPlayer != null && mPaused) {
|
||||
mBackgroundMediaPlayer.start();
|
||||
mPaused = false;
|
||||
mManualPaused = false;
|
||||
}
|
||||
}
|
||||
static public void setBackgroundMusicVolume( float p_fVolume )
|
||||
{
|
||||
if (p_fVolume < 0.0f) {
|
||||
p_fVolume = 0.0f;
|
||||
}
|
||||
|
||||
if (p_fVolume > 1.0f) {
|
||||
p_fVolume = 1.0f;
|
||||
}
|
||||
|
||||
mLeftVolume = mRightVolume = p_fVolume;
|
||||
if (mBackgroundMediaPlayer != null) {
|
||||
mBackgroundMediaPlayer.setVolume(mLeftVolume, mRightVolume);
|
||||
}
|
||||
}
|
||||
static public void setCurrentTime(float nCurrentTime)
|
||||
{
|
||||
|
||||
if (mBackgroundMediaPlayer != null) {
|
||||
mBackgroundMediaPlayer.seekTo((int)(nCurrentTime * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
static public float getCurrentTime()
|
||||
{
|
||||
|
||||
if (mBackgroundMediaPlayer != null) {
|
||||
return mBackgroundMediaPlayer.getCurrentPosition() * 0.001f;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
static public float getDuration()
|
||||
{
|
||||
|
||||
if (mBackgroundMediaPlayer != null) {
|
||||
return mBackgroundMediaPlayer.getDuration()* 0.001f;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
package layaair.game.utility;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.MemoryInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Debug;
|
||||
import android.util.Log;
|
||||
|
||||
public class ProcessInfo
|
||||
{
|
||||
static long mnLastTotalCpu=0;
|
||||
static long mnLastAppCpu=0;
|
||||
static String TAG = "PROCESSINFO";
|
||||
static ActivityManager sAM = null;
|
||||
static long mWorkCpuTm = 0;
|
||||
static long mLastWorkCpuTm = 0;
|
||||
static public void init( ActivityManager pAM )
|
||||
{
|
||||
sAM = pAM;
|
||||
}
|
||||
static public void uninit(){
|
||||
sAM = null;
|
||||
}
|
||||
|
||||
//16之前的
|
||||
static public long getTotalMemoryOld() {
|
||||
String str1 = "/proc/meminfo";
|
||||
String str2;
|
||||
String[] arrayOfString;
|
||||
long initial_memory = 0;
|
||||
try {
|
||||
FileReader localFileReader = new FileReader(str1);
|
||||
BufferedReader localBufferedReader = new BufferedReader( localFileReader, 8192);
|
||||
str2 = localBufferedReader.readLine();//meminfo
|
||||
arrayOfString = str2.split("\\s+");
|
||||
for (String num : arrayOfString) {
|
||||
Log.i(str2, num + "\t");
|
||||
}
|
||||
//total Memory
|
||||
initial_memory = Integer.valueOf(arrayOfString[1]).intValue();// * 1024;
|
||||
localBufferedReader.close();
|
||||
return initial_memory;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@SuppressLint("NewApi")
|
||||
static public float getTotalMem()
|
||||
{
|
||||
if( Build.VERSION.SDK_INT<16 ){
|
||||
return (float)getTotalMemoryOld();
|
||||
}
|
||||
|
||||
if(sAM == null ) return 0;
|
||||
MemoryInfo meminfo = new MemoryInfo();
|
||||
sAM.getMemoryInfo(meminfo);
|
||||
float total = meminfo.totalMem/1024.0f;
|
||||
Log.i("", "total:"+total);
|
||||
return total;
|
||||
}
|
||||
|
||||
static public float getAvalidMem()
|
||||
{
|
||||
if(sAM == null ) return 0;
|
||||
MemoryInfo meminfo = new MemoryInfo();
|
||||
sAM.getMemoryInfo(meminfo);
|
||||
float availmem = meminfo.availMem/1024.0f;
|
||||
return availmem;
|
||||
}
|
||||
static public float getUsedMem()
|
||||
{
|
||||
if( sAM ==null )return 0;
|
||||
int pid = android.os.Process.myPid();
|
||||
Debug.MemoryInfo[] memInfos = sAM.getProcessMemoryInfo(new int[] {pid});
|
||||
float usedMem = (float)memInfos[0].getTotalPrivateDirty();
|
||||
Log.d(TAG, "占用内存:" + usedMem );
|
||||
return usedMem;
|
||||
}
|
||||
|
||||
static public int GetFPS()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//得到当前进程的cpu占用率
|
||||
public static float getProcessCpuRate1()
|
||||
{
|
||||
long curTotal = getTotalCpuTime();
|
||||
long curApp = getAppCpuTime();
|
||||
long dapp = curApp-mnLastAppCpu;
|
||||
long dtotal = curTotal-mnLastTotalCpu;
|
||||
float cpuRate = (float) (dapp*1.0/dtotal);
|
||||
if(cpuRate>1)
|
||||
Log.e("","app:"+dapp+",total:"+dtotal);
|
||||
mnLastAppCpu = curApp;
|
||||
mnLastTotalCpu = curTotal;
|
||||
return cpuRate;
|
||||
}
|
||||
public static float getProcessCpuRate()
|
||||
{
|
||||
long curTotal = getTotalCpuTime();
|
||||
long dwork = mWorkCpuTm-mLastWorkCpuTm;
|
||||
long dtotal = curTotal-mnLastTotalCpu;
|
||||
float cpuRate = (float) (dwork*1.0/dtotal);
|
||||
mLastWorkCpuTm=mWorkCpuTm;
|
||||
mnLastTotalCpu = curTotal;
|
||||
return cpuRate;
|
||||
}
|
||||
|
||||
/*
|
||||
* 判断是否支持neon
|
||||
*/
|
||||
public static boolean supportNeon(){
|
||||
try
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream("/proc/cpuinfo")), 1000);
|
||||
String li = reader.readLine();
|
||||
while(li!=null){
|
||||
if( li.startsWith("Features")){
|
||||
if( li.contains("neon")){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
li = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static long getTotalCpuTime()
|
||||
{
|
||||
// 获取系统总CPU使用时间
|
||||
String[] cpuInfos = null;
|
||||
try
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream("/proc/stat")), 1000);
|
||||
String load = reader.readLine();
|
||||
reader.close();
|
||||
cpuInfos = load.split(" ");
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
long worktm = Long.parseLong(cpuInfos[2]) //user mode cpu time
|
||||
+ Long.parseLong(cpuInfos[3]) //nice <0 cpu time
|
||||
+ Long.parseLong(cpuInfos[4]) //system:内核时间
|
||||
+ Long.parseLong(cpuInfos[7]) //irq:
|
||||
+ Long.parseLong(cpuInfos[8]);//softirq
|
||||
|
||||
long waittm = Long.parseLong(cpuInfos[6]) //idle:除了iowait外的空闲时间
|
||||
+ Long.parseLong(cpuInfos[5]); //iowait:
|
||||
|
||||
mWorkCpuTm=worktm;
|
||||
/*
|
||||
long totalCpu = Long.parseLong(cpuInfos[2]) //user mode cpu time
|
||||
+ Long.parseLong(cpuInfos[3]) //nice <0 cpu time
|
||||
+ Long.parseLong(cpuInfos[4]) //system:内核时间
|
||||
+ Long.parseLong(cpuInfos[6]) //idle:除了iowait外的空闲时间
|
||||
+ Long.parseLong(cpuInfos[5]) //iowait:
|
||||
+ Long.parseLong(cpuInfos[7]) //irq:
|
||||
+ Long.parseLong(cpuInfos[8]);//softirq
|
||||
*/
|
||||
return worktm+waittm;
|
||||
}
|
||||
|
||||
public static long getAppCpuTime()
|
||||
{
|
||||
// 获取应用占用的CPU时间
|
||||
String[] cpuInfos = null;
|
||||
try
|
||||
{
|
||||
int pid = android.os.Process.myPid();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream("/proc/" + pid + "/stat")), 1000);
|
||||
String load = reader.readLine();
|
||||
reader.close();
|
||||
cpuInfos = load.split(" ");
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
long appCpuTime = Long.parseLong(cpuInfos[13])
|
||||
+ Long.parseLong(cpuInfos[14]) + Long.parseLong(cpuInfos[15])
|
||||
+ Long.parseLong(cpuInfos[16]);
|
||||
return appCpuTime;
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package layaair.game.utility;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.util.Log;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import javax.microedition.khronos.opengles.GL10;
|
||||
|
||||
/**
|
||||
* Created by hugao on 2016/11/5.
|
||||
*/
|
||||
|
||||
public class Utils {
|
||||
public static byte[] screenShot(GL10 gl, int width, int height) {
|
||||
long begin=System.currentTimeMillis();
|
||||
int screenshotSize = width * height*4;
|
||||
ByteBuffer bb = ByteBuffer.allocateDirect(screenshotSize);
|
||||
bb.order(ByteOrder.nativeOrder());
|
||||
gl.glReadPixels(0, 0, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
|
||||
/*int pixelsBuffer[] = new int[screenshotSize];
|
||||
bb.asIntBuffer().get(pixelsBuffer);
|
||||
bb = null;
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
bitmap.setPixels(pixelsBuffer, screenshotSize - width, -width, 0, 0, width, height);
|
||||
byte sBuffer[] = new byte[screenshotSize*4];
|
||||
ByteBuffer sb = ByteBuffer.wrap(sBuffer);
|
||||
bitmap.copyPixelsToBuffer(sb);
|
||||
int size=screenshotSize*4;
|
||||
byte temp;
|
||||
for(int i=0;i<size;i+=4)
|
||||
{
|
||||
temp=sBuffer[i];
|
||||
sBuffer[i]=sBuffer[i+2];
|
||||
sBuffer[i+2]=temp;
|
||||
}
|
||||
long useTime=System.currentTimeMillis()-begin;
|
||||
Log.e("temp",">>>>>>>>>>>>>>>>>>>>>>>useTimenew"+ useTime);
|
||||
return sb.array();*/
|
||||
byte [] a;
|
||||
try {
|
||||
a = bb.array();
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
{
|
||||
a=new byte[screenshotSize];
|
||||
bb.get(a);
|
||||
}
|
||||
|
||||
verticalMirror(a,width,height);
|
||||
long useTime=System.currentTimeMillis()-begin;
|
||||
Log.e("temp",">>>>>>>>>>>>>>>>>>>>>>>useTimenew"+ useTime);
|
||||
return a;
|
||||
}
|
||||
|
||||
public static byte[] verticalMirror(byte[]a,int w,int h) {
|
||||
byte tR,tG,tB,tA;
|
||||
int tempF,tempT;
|
||||
for (int i = 0; i < w; i++)//n列
|
||||
{
|
||||
for (int j = 0; j < h / 2; j++) //每一列转换(n/2)次
|
||||
{
|
||||
//将上下两个对称的元素进行交
|
||||
tempF=(w * j + i)*4;
|
||||
tempT=((h - j - 1) * w + i)*4;
|
||||
tR=a[tempF];
|
||||
tG=a[tempF+1];
|
||||
tB=a[tempF+2];
|
||||
tA=a[tempF+3];
|
||||
a[tempF]=a[tempT];
|
||||
a[tempF+1]=a[tempT+1];
|
||||
a[tempF+2]=a[tempT+2];
|
||||
a[tempF+3]=a[tempT+3];
|
||||
a[tempT]=tR;
|
||||
a[tempT+1]=tG;
|
||||
a[tempT+2]=tB;
|
||||
a[tempT+3]=tA;
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
public static int getResIdByName(Context context, String className, String resName) {
|
||||
String packageName = context.getPackageName();
|
||||
int id = 0;
|
||||
try {
|
||||
Class r = Class.forName(packageName + ".R");
|
||||
Class[] classes = r.getClasses();
|
||||
Class desireClass = null;
|
||||
for (Class cls : classes) {
|
||||
if (cls.getName().split("\\$")[1].equals(className)) {
|
||||
desireClass = cls;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (desireClass != null) {
|
||||
id = desireClass.getField(resName).getInt(desireClass);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package layaair.game.wrapper;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import layaair.game.conch.ILayaEventListener;
|
||||
|
||||
|
||||
public abstract interface ILayaLibWrapper {
|
||||
void initEngine(Activity context);
|
||||
void setLayaEventListener(ILayaEventListener listener);
|
||||
void setLoadingView(View view);
|
||||
void setGameUrl(String url);
|
||||
void startGame();
|
||||
void setInterceptKey(boolean pInterceptKey);
|
||||
void setOptions(HashMap<String, Object> _option);
|
||||
void setLocalizable(boolean b);
|
||||
void checkApkUpdate();
|
||||
void onPause();
|
||||
void onResume();
|
||||
void onDestroy();
|
||||
// 游戏停止
|
||||
void onStop();
|
||||
void onNewIntent(Intent intent);
|
||||
void onRestart();
|
||||
void onActivityResult(int requestCode, int resultCode,Intent intent);
|
||||
void setResolution(int w, int h);
|
||||
void _enableOnLayout(boolean b);
|
||||
void setAlertTitle(String title);
|
||||
void setStringOnBackPressed(String str);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">Conch5</string>
|
||||
</resources>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package layaair.game;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* To work on unit tests, switch the Test Artifact in the Build Variants view.
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user