From 134804f3dbea6c67619f0945784c4af438edc9ba Mon Sep 17 00:00:00 2001 From: StageGuard <1355416608@qq.com> Date: Sun, 19 Jul 2020 11:54:03 +0800 Subject: [PATCH] Initial commit --- LICENSE | 55 +- gitVersion | 1 + source/SkyAutoplayer.js | 1848 +++++++++++++++++++++++++++++++++++++++ update_log.txt | 4 + 4 files changed, 1854 insertions(+), 54 deletions(-) create mode 100644 gitVersion create mode 100644 source/SkyAutoplayer.js create mode 100644 update_log.txt diff --git a/LICENSE b/LICENSE index f288702..ed990f8 100644 --- a/LICENSE +++ b/LICENSE @@ -618,57 +618,4 @@ an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/gitVersion b/gitVersion new file mode 100644 index 0000000..ccc3bc4 --- /dev/null +++ b/gitVersion @@ -0,0 +1 @@ +f5a1b \ No newline at end of file diff --git a/source/SkyAutoplayer.js b/source/SkyAutoplayer.js new file mode 100644 index 0000000..a2b263a --- /dev/null +++ b/source/SkyAutoplayer.js @@ -0,0 +1,1848 @@ +"ui"; +"use strict"; + +/* + Sky Auto Player (Auto.js script) + Copyright © 2020 StageGuard + Contact : + (QQ: 1355416608) + (Email: beamiscool@qq.com) + (BaiduTieba@拐角处_等你) + (Weibo@StageGuard) + (CoolApk@StageGuard) + (Twiter@stageguardcn) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see +*/ + +const user_agreements = + "请仔细阅读以下使用须知!\n\n" + + "未充分测试,若遇到BUG,请酷安私信@StageGuard或在github中的StageGuard/SkyAutoPlayerScript新建Issue来反馈BUG!\n\n" + + "1. SkyAutoPlayer(以下简称\"本脚本\")是完全免费且开源的软件/脚本(https://github.com/StageGuard/SkyAutoPlayerScript),禁止使用本脚本作为盈利用途!\n若你是从其他渠道购买获得的本脚本,那么就说明你被骗了!\n\n" + + "2. 本脚本仅可用作娱乐用途,请不要在正规场合使用本脚本(请自行体会\"正规场合\"是什么意思),若因使用本脚本所出现了一些不友好的问题,与脚本作者StageGuard(以下简称\"作者\")无关。\n\n" + + "3. 脚本只能给你一时满足感而不能使你进步,请适当使用,只有真正的技术才是王道,才能使你感到快乐。\n\n" + + "4. 本脚本的发行遵守GPLv3协议,若你不了解协议内容,请访问 https://www.gnu.org/licenses 查看" +; + +//Script global scope +const scope = this; +//activity context +const ctx = activity; + +//global gui +var gui = null; +//SimpleListAdapter(gitee@projectXero) +var RhinoListAdapter; +//sheets manager +var sheetmgr = null; +//sheets player +var sheetplayer = null; +//load config & resources +var config = null; +//display density +scope.dp = context.getResources().getDisplayMetrics().density; +//show error; +const error = function(text) { + console.show(); + console.error("SkyAutoPlayer发生了一个错误,请酷安私信@StageGuard或在github中的StageGuard/SkyAutoPlayerScript新建Issue来反馈这个BUG!\n详细信息:" + text); +}; + +//Asynchronous load script +threads.start(function() { + +sheetmgr = { + rootDir: android.os.Environment.getExternalStorageDirectory() + "/Android/data/com.Maple.SkyStudio/files/Sheet/", + encoding: "utf-16le", + + cachedSheetList: [], + + getSheetList: function(forceRefresh, listener) { + if(this.cachedSheetList.length == 0 || forceRefresh) { + this.__internal_fetchLocalSheets(listener); + } + return this.cachedSheetList; + }, + + __internal_fetchLocalSheets: function(listener) { + var sheets = files.listDir(this.rootDir, function(name){return name.endsWith(".txt");}); + this.cachedSheetList.length = 0; + for(var i in sheets) { + if(listener != null) listener(i); + var readable = files.open(files.join(this.rootDir, sheets[i]), "r", this.encoding); + var parsed = eval(readable.read())[0]; + readable.close(); + parsed.songNotes = (function(raw){ + var r = []; + var t_time = 0; + var t_sets = []; + for(var i in raw) { + var key = Number(raw[i].key.replace(/^(\d)Key(\d{1,})$/, "$2")); + if(raw[i].time != t_time) { + r.push({time: t_time, keys: t_sets}); + t_sets = []; + t_time = raw[i].time; + } + if(t_sets.indexOf(key) == -1) t_sets.push(key); + } + return r; + }(parsed.songNotes)); + this.cachedSheetList.push(parsed); + } + }, +}; + +sheetplayer = { + + notes: [], + bpm: [], + noteCount: 0, + name: "", + pitch: 0, + + currentNote: 0, + playing: false, + nextInterval: 0, + + + thread: null, + + play: function(listener) { + if(this.playing == true) return; + this.playing = true; + this.thread = threads.start(function(){ + do { + sheetplayer.nextInterval = sheetplayer.notes[(sheetplayer.currentNote + 1 == sheetplayer.noteCount) ? sheetplayer.currentNote : (sheetplayer.currentNote + 1)].time - sheetplayer.notes[sheetplayer.currentNote].time; + sheetplayer.notes[sheetplayer.currentNote].keys.map(function(e, i) {threads.start(function(){ + click(config.values.key_coordinates[e][0], config.values.key_coordinates[e][1]); + })}); + if(listener != null) listener(); + java.lang.Thread.sleep(sheetplayer.nextInterval); + sheetplayer.currentNote ++; + } while( + sheetplayer.playing && sheetplayer.currentNote < sheetplayer.noteCount + ); + }); + + }, + + stop: function() { + this.playing = false; + this.currentNote = 0; + this.thread = null; + }, + pause: function() { + this.playing = false; + }, + + setProgress: function(p) { + if(this.playing) this.currentNote = p; + }, + + setSheet: function(j) { + if(this.thread != null) this.stop(); + this.thread = null; + this.name = j.name; + this.notes = j.songNotes; + this.pitch = j.pitchLevel; + this.bpm = j.bpm; + this.noteCount = j.songNotes.length; + + }, + + +} + +config = { + + _global_storage: null, + + values: { + key_coordinates: [], + skipRunScriptTip: false, + skipOpenWindowTip: false, + skipOnlineUploadSkip: false, + currentVersion: 1, + gitVersion: "", + }, + + bitmaps: {}, + + init: function() { + this._global_storage = storages.create("StageGuard:SkyAutoPlayer:Config"); + this.values.key_coordinates = this._global_storage.get("key_coordinates", this.values.key_coordinates); + this.values.skipRunScriptTip = this._global_storage.get("skip_run_script_tip", this.values.skipRunScriptTip); + this.values.skipOpenWindowTip = this._global_storage.get("skip_open_window_tip", this.values.skipOpenWindowTip); + this.values.skipOnlineUploadSkip = this._global_storage.get("skip_online_upload_skip", this.values.skipOnlineUploadSkip); + }, + + save: function(key, value) { + this._global_storage.put(key, value == null ? this.values[key] : this.values[key] = value); + }, + + checkVersion: function() { + this.values.gitVersion = http.get("https://gitee.com/stageguard/SkyAutoPlayerScript/raw/master/gitVersion").body.string(); + var periodVersion = this._global_storage.get("version", this.values.currentVersion); + var currentVersion = this.values.currentVersion; + if(periodVersion < currentVersion) { + try { + var updateInfo = http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@" + this.values.gitVersion + "/update_log.txt"); + gui.dialogs.showConfirmDialog({ + title: "SkyAutoPlayer已更新", + text: "当前版本: " + currentVersion + " ← " + periodVersion + "\n\n更新日志: \n" + updateInfo.body.string(), + canExit: false, + buttons: ["确认"] + }); + } catch(e) { + error("获取版本信息失败!详细信息:" + e); + } + } + this.save("version", currentVersion); + }, + + fetchResources: function(listener) { + var remoteHost = "https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript@" + this.values.gitVersion + "/"; + var resourceList = ["local.png", "online.png", "play.png", "pause.png", "refresh.png", "settings.png"]; + var localRootDir = android.os.Environment.getExternalStorageDirectory() + "/Documents/SkyAutoPlayer/"; + var downloadQueue = []; + var tryCount = 1; + try { + files.createWithDirs(localRootDir); + listener("加载资源中..."); + resourceList.map(function(element, i) { + var absolutePath = files.join(localRootDir, element); + if(files.exists(absolutePath)) { + try { + listener("加载资源中: " + element); + config.bitmaps[files.getNameWithoutExtension(absolutePath)] = android.graphics.Bitmap.createBitmap(android.graphics.BitmapFactory.decodeFile(absolutePath)); + } catch(e) { + listener("加载失败: " + element); + downloadQueue.push(element); + } + } else { + listener("无本地资源,进入下载队列: " + element); + downloadQueue.push(element); + } + }); + if(downloadQueue.length == 0) { + listener("资源加载完成"); + java.lang.Thread.sleep(1000); //为了方便看清 + return; + } + + while (downloadQueue.length != 0 && tryCount <= 5) { + listener("第" + tryCount + "次尝试下载资源,共需下载" + downloadQueue.length + "项资源"); + java.lang.Thread.sleep(1500); //为了方便看清 + var tmpQueue = []; + for(var i in downloadQueue) tmpQueue.push(downloadQueue[i]); + var iterator = 0; + tmpQueue.map(function(element, i) { + try { + listener("下载资源中: " + element); + var absolutePath = files.join(localRootDir, element); + var resp = http.get(remoteHost + element); + files.create(absolutePath); + files.writeBytes(absolutePath, resp.body.bytes()); + config.bitmaps[files.getNameWithoutExtension(absolutePath)] = android.graphics.Bitmap.createBitmap(android.graphics.BitmapFactory.decodeFile(absolutePath)); + downloadQueue.splice(iterator, 1); + } catch(e) { + iterator++; + listener("资源" + element + "下载/加载失败: " + e); + java.lang.Thread.sleep(1000); //为了方便看清 + } + }); + tryCount ++; + } + //处理结果 + if(tryCount > 5) { + listener(new Error("以下资源下载失败:" + downloadQueue)) + } else { + listener("资源下载完成"); + java.lang.Thread.sleep(1000); //为了方便看清 + } + } catch(error) { + listener(new Error("资源下载时发生了问题" + error)); + } + + }, + +} + + +RhinoListAdapter = (function() { + var r = function(arr, vmaker, params, preload) { + var src = arr.slice(), + views = new Array(arr.length), + dso = [], + controller; + if (preload) { + src.forEach(function(e, i, a) { + views[i] = vmaker(e, i, a, params); + }); + } + controller = new RhinoListAdapter.Controller(src, views, dso, vmaker, params, preload); + return new android.widget.ListAdapter({ + getCount: function() { + return src.length; + }, + getItem: function(pos) { + if (pos == -1) return controller; + return src[pos]; + }, + getItemId: function(pos) { + return pos; + }, + getItemViewType: function(pos) { + return 0; + }, + getView: function(pos, convert, parent) { + try { + return views[pos] ? views[pos] : (views[pos] = vmaker(src[pos], parseInt(pos), src, params)); + } catch (e) { + var a = new android.widget.TextView(ctx); + a.setText(e + "\n" + e.stack); + return a; + } + }, + getViewTypeCount: function() { + return 1; + }, + hasStableIds: function() { + return true; + }, + isEmpty: function() { + return src.length === 0; + }, + areAllItemsEnabled: function() { + return true; + }, + isEnabled: function(pos) { + return pos >= 0 && pos < src.length; + }, + registerDataSetObserver: function(p) { + if (dso.indexOf(p) >= 0) return; + dso.push(p); + }, + unregisterDataSetObserver: function(p) { + var i = dso.indexOf(p); + if (p >= 0) dso.splice(i, 1); + } + }); + } + r.Controller = function(src, views, dso, vmaker, params, preload) { + this.src = src; + this.views = views; + this.dso = dso; + this.vmaker = vmaker; + this.params = params; + this.preload = preload; + } + r.Controller.prototype = { + notifyChange: function() { + this.dso.forEach(function(e) { + if (e) e.onChanged(); + }); + }, + notifyInvalidate: function() { + this.dso.forEach(function(e) { + if (e) e.onInvalidated(); + }); + }, + add: function(e, isInv) { + this.src.push(e); + if (this.preload) this.views.push(this.vmaker(e, this.src.length - 1, this.src, this.params)); + if (isInv) this.notifyChange(); + }, + concat: function(arr) { + arr.forEach(function(e) { + this.src.push(e) + if (this.preload) this.views.push(this.vmaker(e, this.src.length - 1, this.src, this.params)); + }, this); + this.notifyChange(); + }, + filter: function(f, thisArg) { + var i; + for (i = 0; i < this.src.length; i++) { + if (!f.call(thisArg, this.src[i], i, this.src)) { + this.src.splice(i, 1); + this.views.splice(i, 1); + i--; + } + } + this.notifyChange(); + }, + forEach: function(f, thisArg) { + var i; + for (i in this.src) { + if (f.call(thisArg, this.src[i], i, this.src)) { + this.views[i] = this.vmaker(this.src[i], i, this.src, this.params); + } + } + this.notifyChange(); + }, + get: function(i) { + if (typeof(i) == "number") { + return this.src[i]; + } else { + return this.src; + } + }, + insert: function(e, i, respawn) { + this.src.splice(i, 0, e); + if (respawn) { + this.respawnAll(); + } else { + this.views.splice(i, 0, this.preload ? this.vmaker(e, i, this.src, this.params) : null); + } + this.notifyChange(); + }, + getCount: function() { + return this.src.length; + }, + remove: function(e, respawn) { + var i; + for (i = this.src.length; i >= 0; i--) { + if (this.src[i] != e) continue; + this.src.splice(i, 1); + this.views.splice(i, 1); + } + if (respawn) this.respawnAll(); + this.notifyChange(); + }, + removeByIndex: function(i, respawn) { + this.src.splice(i, 1); + this.views.splice(i, 1); + if (respawn) this.respawnAll(); + this.notifyChange(); + }, + removeAll: function(respawn) { + this.src.length = 0; + this.views.length = 0; + if (respawn) this.respawnAll(); + }, + replace: function(e, i) { + this.src[i] = e; + this.views[i] = this.preload ? this.vmaker(e, i, this.src, this.params) : null; + this.notifyChange(); + }, + respawn: function(i) { + this.views[i] = this.vmaker(this.src[i], i, this.src, this.params); + this.notifyChange(); + }, + respawnAll: function(i) { + this.src.forEach(function(e, i, a) { + this.views[i] = this.vmaker(e, i, a, this.params); + }, this); + this.notifyChange(); + }, + slice: function(start, end) { + return Array.prototype.slice.apply(this.src, arguments); + }, + splice: function(index, len) { + var i, z = []; + for (i in arguments) z.push(arguments[i]); + var r = Array.prototype.splice.apply(this.src, z); + for (i = 2; i < z.length; i++) { + z[i] = this.preload ? this.vmaker(z[i], i - 2 + index, this.src, this.params) : null; + } + Array.prototype.splice.apply(this.views, z); + this.notifyChange(); + }, + getArray: function() { + return this.src.slice(); + }, + setArray: function(a) { + this.views.length = this.src.length = 0; + for (var i in a) this.src.push(a[i]); + this.views.length = this.src.length; + if (this.preload) { + this.respawnAll(); + } else { + this.notifyChange(); + } + }, + } + r.getController = function(adapter) { + var r = adapter.getItem(-1); + r.self = adapter; + return r; + } + return r; +}()); + +gui = { + + //run in ui thread + run: function(obj) { + ctx.runOnUiThread(new java.lang.Runnable({run:obj})); + }, + + winMgr: ctx.getSystemService(android.content.Context.WINDOW_SERVICE), + + config: { + colors: { + background: android.graphics.Color.parseColor("#212121"), + primary: android.graphics.Color.parseColor("#009688"), + text: android.graphics.Color.WHITE, + dark_text: android.graphics.Color.BLACK, + sec_text: android.graphics.Color.parseColor("#7B7B7B"), + }, + }, + + utils: { + value_animation: function self(type, start, end, duration, interpolator, onUpdate) { + self.anim = android.animation.ValueAnimator["of" + type](start, end); + self.anim.setDuration(duration); + self.anim.setInterpolator(interpolator); + self.anim.addUpdateListener(new android.animation.ValueAnimator.AnimatorUpdateListener({ + onAnimationUpdate: onUpdate + })); + self.anim.start(); + }, + ripple_drawable: function(width, height, customshape) { + var rs = null; + switch(customshape) { + case "oval": rs = new android.graphics.drawable.shapes.OvalShape(); break; + case "rect": rs = new android.graphics.drawable.shapes.RectShape(); break; + case "roundrect": rs = new android.graphics.drawable.shapes.RoundRectShape( + [arguments[3], arguments[3], arguments[3], arguments[3], arguments[3], arguments[3], arguments[3], arguments[3]], + new android.graphics.RectF(0, 0, width, height), + null + ); break; + default: rs = new android.graphics.drawable.shapes.OvalShape(); break; + } + rs.draw(new android.graphics.Canvas(), new android.graphics.Paint()); + var mask = new android.graphics.drawable.ShapeDrawable(rs); + var gradientDrawable = new android.graphics.drawable.GradientDrawable(); + gradientDrawable.setColor(android.graphics.Color.TRANSPARENT); + if (customshape == "roundrect") gradientDrawable.setCornerRadius(arguments[3]); + gradientDrawable.setStroke(dp * 10, android.graphics.Color.TRANSPARENT); + return new android.graphics.drawable.RippleDrawable(android.content.res.ColorStateList.valueOf(android.graphics.Color.argb(1, 0, 0, 0)), gradientDrawable, mask); + }, + }, + + dialogs: { + showDialog: function(layout, width, height, onDismiss, canExit) { + var frame, trans, params; + frame = new android.widget.FrameLayout(ctx); + frame.setBackgroundColor(android.graphics.Color.argb(0x80, 0, 0, 0)); + frame.setOnTouchListener(new android.view.View.OnTouchListener({ + onTouch: function touch(v, e) { + try { + if (e.getAction() == e.ACTION_DOWN && canExit) { + frame.setEnabled(false); + frame.setClickable(false); + gui.utils.value_animation("Float", 1.0, 0, 75, new android.view.animation.LinearInterpolator(), function(anim) { + frame.setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 0) { + if(onDismiss != null) onDismiss(frame); + gui.winMgr.removeView(frame); + } + }); + } + return false; + } catch (e) { + error(e); + return false; + } + } + })); + layout.setLayoutParams(new android.widget.FrameLayout.LayoutParams(width, height, android.view.Gravity.CENTER)); + layout.getLayoutParams().setMargins(20 * dp, 20 * dp, 20 * dp, 20 * dp); + frame.addView(layout); + gui.utils.value_animation("Float", 0, 1, 75, new android.view.animation.LinearInterpolator(), function(anim) { + frame.setAlpha(anim.getAnimatedValue()); + }); + layout.setElevation(16 * dp); + params = new android.view.WindowManager.LayoutParams(); + params.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + if(!canExit) params.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + params.format = android.graphics.PixelFormat.TRANSLUCENT; + params.width = -1; + params.height = -1; + gui.winMgr.addView(frame, params); + return frame; + }, + showProgressDialog: function self(f, isNoText, canExit) { + self.init = function(o) { + gui.run(function() { + try { + var layout = o.layout = new android.widget.LinearLayout(ctx); + layout.setOrientation(android.widget.LinearLayout.VERTICAL); + layout.setPadding(dp * 10, isNoText ? dp * 5 : dp * 10, dp * 10, isNoText ? dp * 5 : 0); + layout.setBackgroundColor(gui.config.colors.background); + if (!isNoText) { + var text = o.text = new android.widget.TextView(ctx); + text.setLayoutParams(new android.widget.FrameLayout.LayoutParams(-2, -2)); + text.setTextColor(gui.config.colors.text); + text.setPadding(dp * 10, dp * 10, dp * 10, dp * 10); + layout.addView(text); + } + var progress = o.progress = android.widget.ProgressBar(ctx, null, android.R.attr.progressBarStyleHorizontal); + layout.addView(progress); + o.popup = gui.dialogs.showDialog(layout, -2, -2, null, canExit); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }) + }, self.controller = { + setText: function(s) { + if (isNoText) return; + var o = this; + gui.run(function() { + try { + o.text.setText(s); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }); + }, + setIndeterminate: function(b) { + var o = this; + gui.run(function() { + try { + o.progress.setIndeterminate(b); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }); + }, + setMax: function(max) { + var o = this; + gui.run(function() { + try { + o.progress.setMax(max); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }); + }, + setProgress: function(prog) { + var o = this; + gui.run(function() { + try { + if (!o.progress.isIndeterminate()) { + o.progress.setProgress(prog, true); + } + } catch (e) { + error(e + " → " + e.lineNumber); + } + }); + }, + close: function() { + var o = this; + gui.run(function() { + try { + gui.utils.value_animation("Float", 1, 0, 75, new android.view.animation.LinearInterpolator(), function(anim) { + o.popup.setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 1) gui.winMgr.removeView(o.popup); + }); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }); + }, + async: function(f) { + var o = this; + var t = threads.start(function() { + try { + f(o); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }); + } + }; + var o = Object.create(self.controller); + self.init(o); + if (f) o.async(f); + return o; + }, + showConfirmDialog: function(s) { + gui.run(function() { + try { + var scr, layout, title, text, skip, onClick, dialog; + scr = new android.widget.ScrollView(ctx); + scr.setBackgroundColor(gui.config.colors.background); + layout = new android.widget.LinearLayout(ctx); + layout.setLayoutParams(new android.widget.FrameLayout.LayoutParams(-2, -2)); + layout.setOrientation(android.widget.LinearLayout.VERTICAL); + layout.setPadding(15 * dp, 15 * dp, 15 * dp, 5 * dp); + if (s.title) { + title = new android.widget.TextView(ctx); + title.setText(s.title); + title.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2)); + title.setPadding(0, 0, 0, 10 * dp); + title.setTextColor(gui.config.colors.text); + title.setTextSize(16); + layout.addView(title); + } + if (s.text) { + text = new android.widget.TextView(ctx); + text.setText(s.text); + text.setPadding(0, 0, 0, 10 * dp); + text.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2)); + text.setTextColor(gui.config.colors.sec_text); + text.setTextSize(14); + layout.addView(text); + } + if (s.skip) { + skip = new android.widget.CheckBox(ctx); + //skip.setChecked(Boolean(s.canSkip)); + skip.setLayoutParams(android.widget.LinearLayout.LayoutParams(-2, -2, 0)); + skip.getLayoutParams().setMargins(0, 0, 0, 10 * dp) + skip.setText("不再提示"); + skip.setTextColor(gui.config.colors.sec_text) + layout.addView(skip); + } + onClick = function(i) { + if (s.skip) s.skip(skip.isChecked()); + if (s.callback && s.callback(i)) return; + } + var closed = false; + s.buttons.map(function(e, i) { + var b = android.widget.TextView(ctx); + b.setId(i); + b.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, -2)); + b.setText(String(e)); + b.setGravity(android.view.Gravity.CENTER); + b.setPadding(10 * dp, 10 * dp, 10 * dp, 10 * dp); + b.setTextColor(gui.config.colors.text); + b.setTextSize(14); + b.measure(0, 0); + b.setBackgroundDrawable(gui.utils.ripple_drawable(b.getMeasuredWidth(), b.getMeasuredHeight(), "rect")); + b.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function f(v) { + try {if(closed != true) { + onClick(v.getId()); + closed = true; + gui.winMgr.removeView(dialog); + return true; + }} catch (e) { + error(e + " → " + e.lineNumber); + } + } + })); + layout.addView(b); + return b; + }); + scr.addView(layout); + dialog = gui.dialogs.showDialog(scr, -2, -2, null, (s.canExit != true ? false : true)); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }) + }, + showOperateDialog: function self(s, callback, canExit) { + gui.run(function() { + try { + var frame, list, dialog; + if (!self.adapter) { + self.adapter = function(e) { + e.view = new android.widget.LinearLayout(ctx); + e.view.setOrientation(android.widget.LinearLayout.VERTICAL); + e.view.setPadding(15 * dp, 15 * dp, 15 * dp, 15 * dp); + e.view.setLayoutParams(new android.widget.AbsListView.LayoutParams(-1, -2)); + e._title = new android.widget.TextView(ctx); + e._title.setText(e.text); + e._title.setGravity(android.view.Gravity.CENTER | android.view.Gravity.LEFT); + e._title.setFocusable(false); + e._title.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, -2)); + e._title.setTextSize(16); + e._title.setTextColor(gui.config.colors.text); + e.view.addView(e._title); + if (e.description) { + e._description = new android.widget.TextView(ctx); + e._description.setText(e.description); + e._description.setPadding(0, 3 * dp, 0, 0); + e._description.setLayoutParams(android.widget.LinearLayout.LayoutParams(-1, -2)); + e._description.setTextSize(14); + e._description.setTextColor(gui.config.colors.sec_text); + e.view.addView(e._description); + } + return e.view; + } + } + frame = new android.widget.FrameLayout(ctx); + frame.setPadding(5 * dp, 5 * dp, 5 * dp, 5 * dp); + frame.setBackgroundColor(gui.config.colors.background); + list = new android.widget.ListView(ctx); + list.setLayoutParams(new android.widget.FrameLayout.LayoutParams(-1, -2)); + list.setDividerHeight(0); + list.setAdapter(new RhinoListAdapter(s, self.adapter)); + list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener({ + onItemClick: function(parent, view, pos, id) { + try { + var e = s[pos]; + if (callback && !callback(pos)) gui.utils.value_animation("Float", 1, 0, 75, new android.view.animation.LinearInterpolator(), function(anim) { + dialog.setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 1) gui.winMgr.removeView(dialog); + }); + return true; + } catch (e) { + error(e + " → " + e.lineNumber); + } + } + })); + frame.addView(list); + dialog = gui.dialogs.showDialog(frame, -1, -2, null, (canExit != true ? (typeof(canExit) != "boolean" ? true : false) : true)); + } catch (e) { + error(e + " → " + e.lineNumber); + } + }) + }, + }, + + + main: { + + //window + window_width: 325, + window_height: 275, + status_bar_height: 32, + navigation_bar_height : 50, + navigation_bar_updown_margin: 2.5, + + //_global_main_popup: null, + _global_base: null, + _global_content_container: null, + _global_content: null, + _global_title: null, + _global_navigation_bar: null, + _global_close: null, + + isShowing: false, + current_navigation_selection: NaN, + func_showing: false, + + cx: dp * 10, + cy: dp * 10, + + views: [], + + addPage: function(j) { + for(var i in gui.main.views) { + if(gui.main.views[i].index == j.index) { + throw new Error("Index " + j.index + " is already exists, title is " + gui.main.views[i].title); + return; + } else if (j.index > 3){ + throw new Error("Page num should be lower than 4."); + return; + } + } + if(j instanceof Object) gui.main.views.push(j); + }, + removePage: function(index) { + for(var i in gui.main.views) { + if(gui.main.views[i].index == index) { + gui.main.views.splice(i, 1); + } + } + }, + + show: function(index) { + var valid = false; + for(var i in gui.main.views) { + if(gui.main.views[i].index == index) { + gui.main.__internal_show(gui.main.views[i]); + valid = true; + } + } + if(valid == false) { + throw new Error("Index " + index + " referenced a invalid view."); + return; + } + }, + + getPageInfo: function(index) { + for(var i in gui.main.views) { + if(gui.main.views[i].index == index) { + return gui.main.views[i]; + } + } + }, + + //internal methods + __internal_show: function s(content) { gui.run(function(){ + s.index = content.index; + s.initial = false; + if(!gui.main.isShowing) { //create a new window and show content view + gui.main._global_base = new android.widget.LinearLayout(ctx); + gui.main._global_base.setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + gui.main._global_base.setOrientation(android.widget.LinearLayout.VERTICAL); + gui.main._global_base.setLayoutParams(new android.widget.LinearLayout.LayoutParams(dp * gui.main.window_width, dp * gui.main.window_height)); + gui.main._global_base.setBackgroundColor(gui.config.colors.background); + + s.statusBar = new android.widget.RelativeLayout(ctx); + s.statusBar.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-1, dp * gui.main.status_bar_height)); + s.statusBar.setBackgroundColor(gui.config.colors.primary); + s.statusBar.setElevation(10 * dp); + + gui.main._global_title = new android.widget.TextView(ctx); + gui.main._global_title.setGravity(android.view.Gravity.LEFT | android.view.Gravity.CENTER); + gui.main._global_title.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-2, -1)); + gui.main._global_title.setPadding(dp * 5, dp * 5, dp * 5, dp * 5); + gui.main._global_title.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT); + if(content.title != null) gui.main._global_title.setText(content.title); + gui.main._global_title.setTextSize(15); + gui.main._global_title.setShadowLayer(dp * 5, 0, 0, android.graphics.Color.BLACK); + gui.main._global_title.setTextColor(gui.config.colors.text); + gui.main._global_title.setOnTouchListener(new android.view.View.OnTouchListener({ + onTouch: function onTouchFunction(view, event) { + switch (event.getAction()) { + case event.ACTION_MOVE: + onTouchFunction.lp = gui.main._global_base.getLayoutParams(); + onTouchFunction.lp.x = gui.main.cx = s.x = event.getRawX() + onTouchFunction.offsetX; + onTouchFunction.lp.y = gui.main.cy = s.y = event.getRawY() + onTouchFunction.offsetY; + gui.winMgr.updateViewLayout(gui.main._global_base, onTouchFunction.lp); + break; + case event.ACTION_DOWN: + onTouchFunction.offsetX = s.x - event.getRawX(); + onTouchFunction.offsetY = s.y - event.getRawY(); + break; + default: + return false; + } + return true; + }, + })); + s.statusBar.addView(gui.main._global_title); + + gui.main._global_close = new android.widget.TextView(ctx); + gui.main._global_close.setId(23); + gui.main._global_close.setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + gui.main._global_close.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(dp * gui.main.status_bar_height, dp * gui.main.status_bar_height)); + gui.main._global_close.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT); + gui.main._global_close.measure(0, 0); + gui.main._global_close.setBackgroundDrawable(gui.utils.ripple_drawable(gui.main._global_close.getMeasuredWidth(), gui.main._global_close.getMeasuredHeight(), "rect")); + gui.main._global_close.setText("×"); + gui.main._global_close.setTextSize(22); + gui.main._global_close.setTextColor(gui.config.colors.text); + gui.main._global_close.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() { + gui.main.__internal_dismiss(); + gui.suspension.show(); + } + })); + s.func = new android.widget.ImageView(ctx); + s.func.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(dp * gui.main.status_bar_height, dp * gui.main.status_bar_height)); + s.func.setPadding(dp * 1, dp * 1, dp * 1, dp * 1); + s.func.getLayoutParams().addRule(android.widget.RelativeLayout.LEFT_OF, 23); + s.func.measure(0, 0); + s.func.setBackgroundDrawable(gui.utils.ripple_drawable(s.func.getMeasuredWidth(), s.func.getMeasuredHeight(), "rect")); + s.func.setPadding(dp * 5, dp * 5, dp * 5, dp * 5); + s.statusBar.addView(s.func); + s.statusBar.addView(gui.main._global_close); + + gui.main._global_base.addView(s.statusBar); + + gui.main._global_content_container = new android.widget.RelativeLayout(ctx); + gui.main._global_content_container.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, dp * (gui.main.window_height - gui.main.status_bar_height - gui.main.navigation_bar_height))); + gui.main._global_content_container.setBackgroundColor(gui.config.colors.background); + + s._content_height = dp * (gui.main.window_height - gui.main.status_bar_height - gui.main.navigation_bar_height); + gui.main._global_content_container.measure(0, 0); + s._content_width = gui.main._global_content_container.getMeasuredWidth(); + + s["contentViewLayout" + s.index] = new android.widget.LinearLayout(ctx); + s["contentViewLayout" + s.index].setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, s._content_height)); + s["contentViewLayout" + s.index].setId(s.index); + + if(content.view != null) { + s.initial = true; + var v = content.view(s); + v.setId(15); + s["contentViewLayout" + s.index].addView(v); + } + gui.main._global_content_container.addView(s["contentViewLayout" + s.index]); + + gui.main._global_base.addView(gui.main._global_content_container); + + gui.main._global_navigation_bar = new android.widget.LinearLayout(ctx); + gui.main._global_navigation_bar.setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + gui.main._global_navigation_bar.setOrientation(android.widget.LinearLayout.HORIZONTAL); + gui.main._global_navigation_bar.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, dp * (gui.main.navigation_bar_height + gui.main.navigation_bar_updown_margin * 2))); + gui.main._global_navigation_bar.setBackgroundColor(gui.config.colors.background); + + gui.main.__internal_genNavigationList(s); + + gui.main._global_base.addView(gui.main._global_navigation_bar); + + //ui.setContentView(gui.main._global_base); + /*gui.main._global_main_popup = new android.widget.PopupWindow(ctx); + gui.main._global_main_popup.setWindowLayoutType(android.os.Build.VERSION.SDK_INT >= 26 ? android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : android.view.WindowManager.LayoutParams.TYPE_PHONE); + gui.main._global_main_popup.setFocusable(false); + gui.main._global_main_popup.setOutsideTouchable(false); + gui.main._global_main_popup.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(0)); + gui.main._global_main_popup.setContentView(gui.main._global_base); + gui.main._global_main_popup.setWidth(gui.main.window_width * dp); + gui.main._global_main_popup.setHeight((gui.main.window_height + gui.main.navigation_bar_updown_margin * 2) * dp); + gui.main._global_main_popup.showAtLocation(ctx.getWindow().getDecorView(), 0, s.x = gui.main.cx, s.y = gui.main.cy);*/ + + s._winParams = new android.view.WindowManager.LayoutParams(); + s._winParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + s._winParams.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + s._winParams.format = android.graphics.PixelFormat.TRANSLUCENT; + s._winParams.width = gui.main.window_width * dp; + s._winParams.height = (gui.main.window_height + gui.main.navigation_bar_updown_margin * 2) * dp; + s._winParams.x = s.x = gui.main.cx; + s._winParams.y = s.y = gui.main.cy; + gui.winMgr.addView(gui.main._global_base, s._winParams); + + gui.main.isShowing = true; + + gui.utils.value_animation("Float", 0, 1.0, 200, new android.view.animation.LinearInterpolator(), function(anim) { + gui.main._global_base.setAlpha(anim.getAnimatedValue()); + }); + gui.utils.value_animation("Float", 0, 1.0, 400 , new android.view.animation.LinearInterpolator(), function(anim) { + gui.main._global_content_container.setAlpha(anim.getAnimatedValue()); + gui.main._global_title.setAlpha(anim.getAnimatedValue()); + }); + + if(s._anim != null) s._anim(); + if(gui.main.views[s.index].update != null) gui.main.views[s.index].update(s); + } else { //window is showing, change content view + if(gui.main.current_navigation_selection == s.index) return; + if(content.title != null) gui.main._global_title.setText(content.title); + + if(!/^android/.test(String(gui.main._global_content_container.findViewById(s.index)))) { + s["contentViewLayout" + s.index] = new android.widget.LinearLayout(ctx); + s["contentViewLayout" + s.index].setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-1, dp * (gui.main.window_height - gui.main.status_bar_height - gui.main.navigation_bar_height))); + s["contentViewLayout" + s.index].setId(s.index); + if(content.view != null) { + s.initial = true; + var v = content.view(s); + v.setId(15); + s["contentViewLayout" + s.index].addView(v); + gui.main._global_content_container.addView(s["contentViewLayout" + s.index]); + } + } + var cid = gui.main.current_navigation_selection; + var tid = s.index; + gui.utils.value_animation("Float", 0, 1.0, 200, new android.view.animation.DecelerateInterpolator(), function(anim) { + gui.main._global_content_container.findViewById(cid).findViewById(15).setAlpha(1.0 - anim.getAnimatedValue()); + gui.main._global_content_container.findViewById(tid).findViewById(15).setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 1.0) { + gui.main._global_content_container.findViewById(cid).findViewById(15).setEnabled(false); + gui.main._global_content_container.findViewById(cid).findViewById(15).setClickable(false); + gui.main._global_content_container.findViewById(cid).setEnabled(false); + gui.main._global_content_container.findViewById(cid).setClickable(false); //飞了 + gui.main._global_content_container.findViewById(cid).setZ(0); + gui.main._global_content_container.findViewById(tid).findViewById(15).setEnabled(true); + gui.main._global_content_container.findViewById(tid).findViewById(15).setClickable(true); + gui.main._global_content_container.findViewById(tid).setEnabled(true); + gui.main._global_content_container.findViewById(tid).setClickable(true); + gui.main._global_content_container.findViewById(tid).setZ(1); //回来 + } + }); + gui.utils.value_animation("Float", 0, 1.0, 200, new android.view.animation.LinearInterpolator(), function(anim) { + gui.main._global_title.setAlpha(anim.getAnimatedValue()); + }); + + + gui.main.__internal_changeNavigationStatus(s.index); + if(gui.main.views[tid].update != null) gui.main.views[tid].update(s); + } + if(gui.main.views[s.index].func == null) { + if(gui.main.func_showing) { + gui.main.func_showing = false; + gui.utils.value_animation("Float", 0, 1, 300 , new android.view.animation.DecelerateInterpolator(), function(anim) { + s.func.setTranslationX(anim.getAnimatedValue() * s.func.getMeasuredWidth()); + s.func.setAlpha(1 - anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 1.0) { + s.func.setClickable(false); + s.func.setEnabled(false); + s.func.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() {} + })); + s.func.setImageBitmap(android.graphics.Bitmap.createBitmap(1, 1, android.graphics.Bitmap.Config.ARGB_8888)); + } + }); + } + } else { + if(gui.main.func_showing) { + s.func.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() {gui.main.views[s.index].func(s)} + })); + s.func.setImageBitmap(gui.main.views[s.index].func_icon); + gui.utils.value_animation("Float", 0, 1, 200 , new android.view.animation.DecelerateInterpolator(), function(anim) { + s.func.setAlpha(anim.getAnimatedValue()); + }); + } else { + gui.main.func_showing = true; + s.func.setClickable(true); + s.func.setEnabled(true); + s.func.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() {gui.main.views[s.index].func(s)} + })); + s.func.setImageBitmap(gui.main.views[s.index].func_icon); + gui.utils.value_animation("Float", 1, 0, 300 , new android.view.animation.DecelerateInterpolator(), function(anim) { + s.func.setTranslationX(anim.getAnimatedValue() * s.func.getMeasuredWidth()); + s.func.setAlpha(1 - anim.getAnimatedValue()); + }); + } + } + gui.main.current_navigation_selection = s.index; + })}, + __internal_genNavigationList: function(s) { gui.run(function(){ + if(gui.main._global_navigation_bar == null) return; + s.__2x_navigation_padding = (gui.main.window_width - gui.main.views.length * gui.main.navigation_bar_height) / (gui.main.views.length); + for(var i in gui.main.views) { + s["navigationBtn" + i] = new android.widget.LinearLayout(ctx); + s["navigationBtn" + i].setId(i); + s["navigationBtn" + i].setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + s["navigationBtn" + i].setOrientation(android.widget.LinearLayout.VERTICAL); + s["navigationBtn" + i].setLayoutParams(new android.widget.LinearLayout.LayoutParams(dp * gui.main.navigation_bar_height, dp * gui.main.navigation_bar_height)); + s["navigationBtn" + i].setBackgroundDrawable(gui.utils.ripple_drawable(0, 0, "roundrect", dp * 2)); + switch (i) { + case 0: s["navigationBtn" + i].getLayoutParams().setMargins(s.__2x_navigation_padding, dp * gui.main.navigation_bar_updown_margin, s.__2x_navigation_padding / 2, dp * gui.main.navigation_bar_updown_margin); break; + case (gui.main.views.length - 1): s["navigationBtn" + i].getLayoutParams().setMargins(s.__2x_navigation_padding / 2, dp * gui.main.navigation_bar_updown_margin, s.__2x_navigation_padding, dp * gui.main.navigation_bar_updown_margin); break; + default: s["navigationBtn" + i].getLayoutParams().setMargins(s.__2x_navigation_padding / 2, dp * gui.main.navigation_bar_updown_margin, s.__2x_navigation_padding / 2, dp * gui.main.navigation_bar_updown_margin); break; + } + s["navigationBtn" + i].setOnClickListener(new android.view.View.OnClickListener({ + onClick: function(view) { + gui.main.__internal_show(gui.main.views[Number(view.getId())]); + gui.main.current_navigation_selection = Number(view.getId()); + } + })); + + s["navigationBtnText" + i] = new android.widget.TextView(ctx); + s["navigationBtnText" + i].setId(12); + s["navigationBtnText" + i].setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + s["navigationBtnText" + i].setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, -2)); + s["navigationBtnText" + i].setText(gui.main.views[i].navigation_title); + s["navigationBtnText" + i].setTextSize(12); + s["navigationBtnText" + i].setShadowLayer(dp, 0, 0, android.graphics.Color.BLACK); + s["navigationBtnText" + i].setTextColor(s.index == gui.main.views[i].index ? gui.config.colors.text : gui.config.colors.sec_text); + + s["navigationBtnImg" + i] = new android.widget.ImageView(ctx); + s["navigationBtnImg" + i].setId(14); + s["navigationBtnImg" + i].setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP); + if(gui.main.views[i].navigation_icon != null) s["navigationBtnImg" + i].setImageBitmap(gui.main.views[i].navigation_icon); + s.__navigationBtnImgHeight = (function() { + s["navigationBtnText" + i].measure(0, 0); + return dp * gui.main.navigation_bar_height - s["navigationBtnText" + i].getMeasuredHeight(); + }()); + s["navigationBtnImg" + i].setLayoutParams(new android.widget.LinearLayout.LayoutParams(s.__navigationBtnImgHeight, s.__navigationBtnImgHeight)); + + s["navigationBtn" + i].addView(s["navigationBtnImg" + i]); + s["navigationBtn" + i].addView(s["navigationBtnText" + i]); + gui.main._global_navigation_bar.addView(s["navigationBtn" + i]); + } + })}, + __internal_changeNavigationStatus: function(index) { gui.run(function(){ + if(gui.main._global_navigation_bar == null) return; + if(!/^android/.test(String(gui.main._global_navigation_bar.findViewById(index)))) return; + if(gui.main.current_navigation_selection == index) return; + var argbE = new android.animation.ArgbEvaluator(); + var colorAnim = android.animation.ObjectAnimator.ofInt(gui.main._global_navigation_bar.findViewById(index).findViewById(12), "textColor", gui.config.colors.sec_text, gui.config.colors.text); + colorAnim.setDuration(300); + colorAnim.setEvaluator(new android.animation.ArgbEvaluator()); + colorAnim.start(); + colorAnim = android.animation.ObjectAnimator.ofInt(gui.main._global_navigation_bar.findViewById(gui.main.current_navigation_selection).findViewById(12), "textColor", gui.config.colors.text, gui.config.colors.sec_text); + colorAnim.setDuration(300); + colorAnim.setEvaluator(new android.animation.ArgbEvaluator()); + colorAnim.start(); + gui.main.current_navigation_selection = index; + + })}, + __internal_rmNavigationList: function() { gui.run(function(){ + if(gui.main._global_navigation_bar == null) return; + for(var i = 0; i < gui.main.views.length; i++) { + gui.main._global_navigation_bar.removeView(gui.main._global_navigation_bar.findViewById(i)); + } + })}, + __internal_dismiss: function() { gui.run(function(){ + if (gui.main.isShowing) { + gui.main._global_close.setEnabled(false); + gui.main._global_close.setClickable(false); + gui.utils.value_animation("Float", 1.0, 0, 200, new android.view.animation.LinearInterpolator(), function(anim) { + gui.main._global_base.setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 0) { + gui.winMgr.removeView(gui.main._global_base); + gui.main.isShowing = false; + } + }); + } + })}, + }, + + suspension: { + + _global_base: null, + + isShowing: false, + + cx: dp * 10, + cy: dp * 10, + + width: dp * 10, + height: dp * 10, + + previousx: 0, + previousy: 0, + + show: function s() { gui.run(function(){ + if(!gui.suspension.isShowing) { + gui.suspension._global_base = new android.view.View(ctx); + gui.suspension._global_base.setLayoutParams(new android.widget.LinearLayout.LayoutParams(dp * gui.suspension.width, dp * gui.suspension.height)); + gui.suspension._global_base.setBackgroundColor(gui.config.colors.background); + gui.suspension._global_base.setOnTouchListener(new android.view.View.OnTouchListener({ + onTouch: function onTouchFunction(view, event) { + switch (event.getAction()) { + case event.ACTION_MOVE: + onTouchFunction.lp = gui.suspension._global_base.getLayoutParams(); + onTouchFunction.lp.x = gui.suspension.cx = s.x = event.getRawX() + onTouchFunction.offsetX; + onTouchFunction.lp.y = gui.suspension.cy = s.y = event.getRawY() + onTouchFunction.offsetY; + gui.winMgr.updateViewLayout(gui.suspension._global_base, onTouchFunction.lp); + break; + case event.ACTION_DOWN: + onTouchFunction.offsetX = s.x - event.getRawX(); + onTouchFunction.offsetY = s.y - event.getRawY(); + break; + case event.ACTION_UP: + + if(Math.abs(gui.suspension.previousx - event.getRawX()) <= gui.suspension.width * dp / 2 && Math.abs(gui.suspension.previousy - event.getRawY()) <= gui.suspension.height * dp / 2) { + gui.suspension.dismiss(); + gui.main.show(0); + return false; + } + gui.suspension.previousx = event.getRawX(); + gui.suspension.previousy = event.getRawY(); + default: + return false; + } + return true; + }, + })); + s._winParams = new android.view.WindowManager.LayoutParams(); + s._winParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + s._winParams.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + s._winParams.format = android.graphics.PixelFormat.TRANSLUCENT; + s._winParams.width = gui.suspension.width * dp; + s._winParams.height = gui.suspension.width * dp; + s._winParams.x = s.x = gui.suspension.cx; + s._winParams.y = s.y = gui.suspension.cy; + gui.winMgr.addView(gui.suspension._global_base, s._winParams); + + gui.suspension.isShowing = true; + } + })}, + dismiss: function() { gui.run(function(){ + if (gui.suspension.isShowing) { + gui.utils.value_animation("Float", 1.0, 0, 200, new android.view.animation.LinearInterpolator(), function(anim) { + gui.suspension._global_base.setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 0) { + gui.winMgr.removeView(gui.suspension._global_base); + gui.suspension.isShowing = false; + } + }); + } + })}, + }, + + key_coordinate_navigation: { + + _global_base: null, + _global_text: null, + + isShowing: false, + isShowingText: false, + + cx: dp * 10, + cy: dp * 10, + + total: 15, + + current_index: 0, + + handler: new android.os.Handler(), + + __internal_showTargetDots: function s() { gui.run(function(){ + if(!gui.key_coordinate_navigation.isShowing) { + gui.key_coordinate_navigation._global_base = new android.widget.TextView(ctx); + gui.key_coordinate_navigation._global_base.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2)); + gui.key_coordinate_navigation._global_base.setTextColor(android.graphics.Color.GREEN); + gui.key_coordinate_navigation._global_base.setText("⛒"); + gui.key_coordinate_navigation._global_base.setTextSize(25); + gui.key_coordinate_navigation._global_base.setOnTouchListener(new android.view.View.OnTouchListener({ + onTouch: function onTouchFunction(view, event) { + switch (event.getAction()) { + case event.ACTION_MOVE: + onTouchFunction.lp = gui.key_coordinate_navigation._global_base.getLayoutParams(); + onTouchFunction.lp.x = gui.key_coordinate_navigation.cx = s.x = event.getRawX() + onTouchFunction.offsetX; + onTouchFunction.lp.y = gui.key_coordinate_navigation.cy = s.y = event.getRawY() + onTouchFunction.offsetY; + gui.winMgr.updateViewLayout(gui.key_coordinate_navigation._global_base, onTouchFunction.lp); + break; + case event.ACTION_DOWN: + onTouchFunction.offsetX = s.x - event.getRawX(); + onTouchFunction.offsetY = s.y - event.getRawY(); + break; + case event.ACTION_UP: + gui.key_coordinate_navigation._global_text.setText("键" + (gui.key_coordinate_navigation.current_index + 1) + "坐标已设置: [" + event.getRawX() + ", " + event.getRawY() + "]"); + config.values.key_coordinates.push([event.getRawX(), event.getRawY()]) + gui.utils.value_animation("Float", 1, 0, 200 , new android.view.animation.DecelerateInterpolator(), function(anim) { + gui.key_coordinate_navigation._global_base.setAlpha(anim.getAnimatedValue()); + gui.key_coordinate_navigation._global_text.setAlpha(1 - anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 0) { + gui.key_coordinate_navigation.__internal_dismissTargetDot(); + gui.key_coordinate_navigation.isShowing = false; + } + }); + threads.start(function() { + java.lang.Thread.currentThread().sleep(1000); + gui.run(function() { + if(++gui.key_coordinate_navigation.current_index < 15) { + gui.key_coordinate_navigation.__internal_showTargetDots(gui.key_coordinate_navigation.current_index); + } else { + config.save("key_coordinates"); + toast("坐标设置已保存至存储!\n"); + gui.key_coordinate_navigation.__internal_dismissText(); + gui.main.show(2); + } + }); + }); + default: + return false; + } + return true; + }, + })); + s._winParams = new android.view.WindowManager.LayoutParams(); + s._winParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + s._winParams.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + s._winParams.format = android.graphics.PixelFormat.TRANSLUCENT; + gui.key_coordinate_navigation._global_base.measure(0, 0); + s._winParams.width = gui.key_coordinate_navigation._global_base.getMeasuredWidth(); + s._winParams.height = gui.key_coordinate_navigation._global_base.getMeasuredHeight(); + s._winParams.x = s.x = gui.key_coordinate_navigation.cx; + s._winParams.y = s.y = gui.key_coordinate_navigation.cy; + gui.winMgr.addView(gui.key_coordinate_navigation._global_base, s._winParams); + gui.utils.value_animation("Float", 0, 1, 200 , new android.view.animation.DecelerateInterpolator(), function(anim) { + gui.key_coordinate_navigation._global_base.setAlpha(anim.getAnimatedValue()); + gui.key_coordinate_navigation._global_text.setAlpha(anim.getAnimatedValue()); + }); + gui.key_coordinate_navigation._global_text.setText("移动\"⛒\"至目标位置来设置第" + (gui.key_coordinate_navigation.current_index + 1) + "个键坐标"); + gui.key_coordinate_navigation.isShowing = true; + } + })}, + __internal_dismissTargetDot: function() { gui.run(function(){ + if (gui.key_coordinate_navigation.isShowing) { + gui.winMgr.removeView(gui.key_coordinate_navigation._global_base); + gui.key_coordinate_navigation.isShowing = false; + } + })}, + + __internal_showTips: function s() { gui.run(function(){ + if(!gui.key_coordinate_navigation.isShowingText) { + gui.key_coordinate_navigation._global_text = new android.widget.TextView(ctx); + gui.key_coordinate_navigation._global_text.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2)); + gui.key_coordinate_navigation._global_text.setTextColor(gui.config.colors.text); + gui.key_coordinate_navigation._global_text.setBackgroundColor(gui.config.colors.background); + gui.key_coordinate_navigation._global_text.setTextSize(16); + gui.key_coordinate_navigation._global_text.setPadding(dp * 5, dp * 5, dp * 5, dp * 5); + gui.key_coordinate_navigation._global_text.getLayoutParams().setMargins(dp * 5, dp * 5, dp * 5, dp * 5); + + s._winParams = new android.view.WindowManager.LayoutParams(); + s._winParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + s._winParams.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + s._winParams.format = android.graphics.PixelFormat.TRANSLUCENT; + gui.key_coordinate_navigation._global_text.measure(0, 0); + s._winParams.width = context.getResources().getDisplayMetrics().widthPixels - dp * 10; + s._winParams.height = gui.key_coordinate_navigation._global_text.getMeasuredHeight(); + + gui.winMgr.addView(gui.key_coordinate_navigation._global_text, s._winParams); + + s.lp = gui.key_coordinate_navigation._global_text.getLayoutParams(); + s.lp.y = context.getResources().getDisplayMetrics().heightPixels / 2 - gui.key_coordinate_navigation._global_text.getMeasuredHeight() - dp * 5; + gui.winMgr.updateViewLayout(gui.key_coordinate_navigation._global_text, s.lp); + gui.key_coordinate_navigation.isShowingText = true; + } + })}, + __internal_dismissText: function() { gui.run(function(){ + if (gui.key_coordinate_navigation.isShowingText) { + gui.utils.value_animation("Float", 1, 0, 200 , new android.view.animation.DecelerateInterpolator(), function(anim) { + gui.key_coordinate_navigation._global_text.setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 0) { + gui.winMgr.removeView(gui.key_coordinate_navigation._global_text); + gui.key_coordinate_navigation.isShowingText = false; + } + }); + } + })}, + + show: function() { + config.values.key_coordinates.length = 0; + gui.key_coordinate_navigation.current_index = 0; + this.__internal_showTips(); + this.__internal_showTargetDots(); + }, + + }, + + player_panel: { + + _global_base: null, + _global_text: null, + _global_seek: null, + + isShowing: false, + + cx: dp * 10, + cy: dp * 10, + + __internal_showPanel: function s() { gui.run(function(){ + if(!gui.player_panel.isShowing) { + gui.player_panel._global_base = new android.widget.RelativeLayout(ctx); + gui.player_panel._global_base.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2)); + gui.player_panel._global_base.setPadding(dp * 5, dp * 5, dp * 5, dp * 5); + gui.player_panel._global_base.getLayoutParams().setMargins(dp * 5, dp * 5, dp * 5, dp * 5); + gui.player_panel._global_base.setBackgroundColor(gui.config.colors.background); + + gui.player_panel._global_text = new android.widget.TextView(ctx); + gui.player_panel._global_text.setId(12); + gui.player_panel._global_text.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-2, -2)); + gui.player_panel._global_text.setTextColor(gui.config.colors.text); + gui.player_panel._global_text.setTextSize(14); + //gui.player_panel._global_text.setPadding(dp * 5, dp * 5, dp * 5, dp * 5); + gui.player_panel._global_text.getLayoutParams().setMargins(0, 0, 0, dp * 2); + gui.player_panel._global_base.addView(gui.player_panel._global_text); + + s.close = new android.widget.TextView(ctx); + s.close.setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + gui.player_panel._global_text.measure(0, 0); + s.close.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(gui.player_panel._global_text.getMeasuredHeight(), gui.player_panel._global_text.getMeasuredHeight())); + s.close.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT); + s.close.measure(0, 0); + s.close.setBackgroundDrawable(gui.utils.ripple_drawable(s.close.getMeasuredWidth(), s.close.getMeasuredHeight(), "rect")); + s.close.setText("×"); + s.close.setTextSize(15); + s.close.setTextColor(gui.config.colors.text); + s.close.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() { + sheetplayer.stop(); + gui.player_panel.__internal_dismiss(); + gui.main.show(0); + } + })); + gui.player_panel._global_base.addView(s.close); + + + gui.player_panel._global_seek = new android.widget.SeekBar(ctx); + gui.player_panel._global_seek.setId(13); + gui.player_panel._global_seek.setMax(sheetplayer.noteCount); + gui.player_panel._global_seek.setMin(0); + gui.player_panel._global_seek.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-1, -2)); + gui.player_panel._global_seek.getLayoutParams().addRule(android.widget.RelativeLayout.BELOW, 12); + gui.player_panel._global_seek.getLayoutParams().setMargins(0, dp * 2, 0, dp * 2); + gui.player_panel._global_seek.setOnSeekBarChangeListener(new android.widget.SeekBar.OnSeekBarChangeListener({ + onProgressChanged: function(sb, p) { + }, + onStopTrackingTouch: function(sb) { + sheetplayer.setProgress(sb.getProgress()); + }, + })); + gui.player_panel._global_base.addView(gui.player_panel._global_seek); + + + s.control_panel = new android.widget.LinearLayout(ctx); + s.control_panel.setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + s.control_panel.setOrientation(android.widget.LinearLayout.HORIZONTAL); + s.control_panel.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-2, -2)); + s.control_panel.getLayoutParams().addRule(android.widget.RelativeLayout.BELOW, 13); + + gui.player_panel._global_status = new android.widget.TextView(ctx); + gui.player_panel._global_status.setLayoutParams(new android.widget.LinearLayout.LayoutParams(dp * 88, dp * 22)); + s.control_panel.setGravity(android.view.Gravity.LEFT | android.view.Gravity.CENTER); + gui.player_panel._global_status.setTextColor(gui.config.colors.sec_text); + gui.player_panel._global_status.setTextSize(12); + //gui.player_panel._global_status.setPadding(dp * 5, dp * 5, dp * 5, dp * 5); + s.control_panel.addView(gui.player_panel._global_status); + + s.play = new android.widget.ImageView(ctx); + s.play.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP); + s.play.setLayoutParams(new android.widget.LinearLayout.LayoutParams(dp * 22, dp * 22)); + s.play.getLayoutParams().setMargins(dp * 8, dp * 8, dp * 8, dp * 8); + s.play.setImageBitmap(config.bitmaps.play); + s.play.measure(0, 0); + s.play.setBackgroundDrawable(gui.utils.ripple_drawable(s.close.getMeasuredWidth(), s.close.getMeasuredHeight(), "rect")); + s.play.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() { + sheetplayer.play(gui.player_panel.refreshStatus); + } + })); + s.control_panel.addView(s.play); + + s.pause = new android.widget.ImageView(ctx); + s.pause.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP); + s.pause.setLayoutParams(new android.widget.LinearLayout.LayoutParams(dp * 22, dp * 22)); + s.pause.getLayoutParams().setMargins(dp * 8, dp * 8, dp * 8, dp * 8); + s.pause.setImageBitmap(config.bitmaps.pause); + s.pause.measure(0, 0); + s.pause.setBackgroundDrawable(gui.utils.ripple_drawable(s.close.getMeasuredWidth(), s.close.getMeasuredHeight(), "rect")); + s.pause.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() { + sheetplayer.pause(); + } + })); + s.control_panel.addView(s.pause); + + gui.player_panel._global_cnote = new android.widget.TextView(ctx); + gui.player_panel._global_cnote.setLayoutParams(new android.widget.LinearLayout.LayoutParams(dp * 88, dp * 22)); + s.control_panel.setGravity(android.view.Gravity.RIGHT | android.view.Gravity.CENTER); + gui.player_panel._global_cnote.setTextColor(gui.config.colors.sec_text); + gui.player_panel._global_cnote.setTextSize(12); + //gui.player_panel._global_cnote.setPadding(dp * 5, dp * 5, dp * 5, dp * 5); + s.control_panel.addView(gui.player_panel._global_cnote); + + gui.player_panel._global_base.addView(s.control_panel); + + s._winParams = new android.view.WindowManager.LayoutParams(); + s._winParams.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + s._winParams.flags = android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + s._winParams.format = android.graphics.PixelFormat.TRANSLUCENT; + gui.player_panel._global_base.measure(0, 0); + s._winParams.width = gui.player_panel._global_base.getMeasuredWidth(); + s._winParams.height = gui.player_panel._global_base.getMeasuredHeight(); + + gui.winMgr.addView(gui.player_panel._global_base, s._winParams); + + s.lp = gui.player_panel._global_base.getLayoutParams(); + s.lp.x = 0; + s.lp.y = context.getResources().getDisplayMetrics().heightPixels / 2 - gui.player_panel._global_base.getMeasuredHeight() - dp * 2; + gui.winMgr.updateViewLayout(gui.player_panel._global_base, s.lp); + gui.player_panel.isShowing = true; + + gui.player_panel._global_text.setText(sheetplayer.name); + gui.player_panel.refreshStatus(); + } + })}, + refreshStatus: function() { gui.run(function(){ + gui.player_panel._global_status.setText(String(sheetplayer.playing ? (sheetplayer.currentNote + "/" + sheetplayer.noteCount) : (sheetplayer.thread == null ? "Idle" : "Paused"))); + gui.player_panel._global_cnote.setText(String(sheetplayer.playing ? (sheetplayer.notes[sheetplayer.currentNote < sheetplayer.noteCount ? sheetplayer.currentNote : sheetplayer.noteCount - 1].keys) : "-")); + gui.player_panel._global_seek.setProgress(sheetplayer.currentNote); + + })}, + __internal_dismiss: function() { gui.run(function(){ + if (gui.player_panel.isShowing) { + gui.utils.value_animation("Float", 1, 0, 200 , new android.view.animation.DecelerateInterpolator(), function(anim) { + gui.player_panel._global_base.setAlpha(anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 0) { + gui.winMgr.removeView(gui.player_panel._global_base); + gui.player_panel.isShowing = false; + } + }); + } + })}, + + show: function() { + this.__internal_showTips(); + this.__internal_showTargetDots(); + }, + + }, + +}; + + +gui.run(function(){ + ui.setContentView((function(){ + var btn = new android.widget.Button(ctx); + btn.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-2, -2)); + btn.setText("EXIT!!!"); + btn.setOnClickListener(new android.view.View.OnClickListener({ + onClick: function() { + java.lang.System.exit(0); + } + })); + return btn; + }())); +}); + +gui.dialogs.showProgressDialog(function(o) { + o.setIndeterminate(true); + o.setText("加载配置中..."); + config.init(); + config.checkVersion(); + o.setText("加载资源中..."); + config.fetchResources(function(msg) { + if(msg instanceof Error) { + o.close(); + error(msg); + exit(); + } else { + o.setText(msg); + } + }); + gui.main.addPage({ + index: 0, + title: "本地乐谱", + navigation_title: "本地乐谱", + navigation_icon: config.bitmaps.local, + func: function(s) { + this.getSheetList(s, true); + }, + func_icon: android.graphics.Bitmap.createBitmap(config.bitmaps.refresh), + view: function(s) { + s.ns0_rl = new android.widget.RelativeLayout(ctx); + s.ns0_rl.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, s._content_height)); + + s.ns0_listView = new android.widget.ListView(ctx); + s.ns0_listView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, s._content_height)); + s.ns0_listView.setAdapter(s.ns0_listAdapter = new RhinoListAdapter([], function self(element) { + self.relative = new android.widget.RelativeLayout(ctx); + self.relative.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, -2)); + + self.title = new android.widget.TextView(ctx); + self.title.setId(10); + self.title.setGravity(android.view.Gravity.LEFT | android.view.Gravity.CENTER); + self.title.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-2, -2)); + self.title.getLayoutParams().setMargins(dp * 15, dp * 15, dp * 15, dp * 1); + self.title.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT); + self.title.setTextSize(16); + self.title.setTextColor(gui.config.colors.text); + self.title.setText(element.name); + self.relative.addView(self.title); + + self.author = new android.widget.TextView(ctx); + self.author.setId(11); + self.author.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-2, -2)); + self.author.getLayoutParams().setMargins(dp * 15, dp * 1, dp * 15, dp * 15); + self.author.getLayoutParams().addRule(android.widget.RelativeLayout.BELOW, 10); + self.author.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT); + self.author.setTextSize(14); + self.author.setTextColor(gui.config.colors.sec_text); + self.author.setText("键数: " + element.songNotes.length + " - BPM: " + element.bpm); + self.relative.addView(self.author); + + self.play = new android.widget.ImageView(ctx); + self.play.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP); + self.play.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(dp * 22, dp * 22)); + self.play.getLayoutParams().setMargins(dp * 15, dp * 15, dp * 15, dp * 15); + self.play.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_RIGHT); + self.play.getLayoutParams().addRule(android.widget.RelativeLayout.CENTER_VERTICAL); + self.play.setImageBitmap(config.bitmaps.play ); + self.relative.addView(self.play); + + return self.relative; + })); + s.ns0_listAdapterController = RhinoListAdapter.getController(s.ns0_listAdapter); + + s.ns0_listView.setAdapter(s.ns0_listAdapterController.self); + s.ns0_listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener({ + onItemClick: function(parent, view, pos, id) { + if(config.values.key_coordinates.length == 15) { + sheetplayer.setSheet(s.ns0_listAdapterController.get(pos)); + gui.main.__internal_dismiss(); + gui.player_panel.__internal_showPanel(); + } else { + toast("未设置键位坐标或坐标数据错误,请前往设置页设置键位坐标"); + } + } + })); + s.ns0_rl.addView(s.ns0_listView); + + s.ns0_progress = new android.widget.ProgressBar(ctx, null, android.R.attr.progressBarStyleHorizontal); + s.ns0_progress.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-1, dp * 15)); + s.ns0_progress.setTranslationY(dp * 5); + s.ns0_progress.setPadding(0, 0, 0, 0); + s.ns0_progress.getLayoutParams().setMargins(0, 0, 0, 0); + s.ns0_progress.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM); + s.ns0_progress.setProgressDrawable(new android.graphics.drawable.ColorDrawable(gui.config.colors.primary)); + s.ns0_progress.setIndeterminate(true); + s.ns0_progress.setAlpha(0); + + s.ns0_rl.addView(s.ns0_progress); + return s.ns0_rl; + }, + update: function(s) { + if(s.initial) this.getSheetList(s, false); + + }, + getSheetList: function(s, isForce) { + gui.run(function() { + s.ns0_progress.setIndeterminate(true); + s.ns0_listAdapterController.removeAll(); + gui.utils.value_animation("Float", 0, 1.0, 200, new android.view.animation.LinearInterpolator(), function(anim) { + gui.main._global_title.setAlpha(anim.getAnimatedValue()); + }); + gui.utils.value_animation("Float", 1.0, 0, 100, new android.view.animation.DecelerateInterpolator(), function(anim) { + s.ns0_listView.setAlpha(anim.getAnimatedValue()); + s.ns0_progress.setAlpha(1 - anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 0) { + s.ns0_listAdapterController.notifyChange(); + s.ns0_listView.setAlpha(1); + threads.start(function() { + sheetmgr.getSheetList(isForce, function(i) { + gui.run(function(){ + gui.main._global_title.setText("加载中: 共" + i + "首乐谱"); + s.ns0_listAdapterController.notifyChange(); + }); + }).map(function(e, i) { + s.ns0_listAdapterController.add(e); + }); + gui.run(function() { + s.ns0_listAdapterController.notifyChange(); + gui.main._global_title.setText(gui.main.getPageInfo(s.index).title); + gui.utils.value_animation("Float", 0, 1.0, 200, new android.view.animation.DecelerateInterpolator(), function(anim) { + gui.main._global_title.setAlpha(anim.getAnimatedValue()); + s.ns0_listView.setAlpha(anim.getAnimatedValue()); + s.ns0_progress.setAlpha(1 - anim.getAnimatedValue()); + if(anim.getAnimatedValue() == 1.0) s.ns0_progress.setIndeterminate(false); + }); + }); + }); + } + }); + }); + } + }); + gui.main.addPage({ + index: 1, + title: "共享乐谱", + navigation_title: "共享乐谱", + navigation_icon: config.bitmaps.online, + view: function(s) { + s.ns + var text = new android.widget.TextView(ctx); + text.setText("Still working on it...\nNot avaliable now :)"); + text.setTextSize(18); + text.setGravity(android.view.Gravity.CENTER | android.view.Gravity.CENTER); + text.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, s._content_height)); + text.setTextColor(gui.config.colors.sec_text); + return text; + }, + }); + gui.main.addPage({ + index: 2, + title: "设置", + navigation_title: "设置", + navigation_icon: config.bitmaps.settings, + view: function(s) { + s.ns1_listView = new android.widget.ListView(ctx); + s.ns1_listView.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, s._content_height)); + s.ns1_listView.setAdapter(s.ns1_listAdapter = new RhinoListAdapter([{ + type: "tag", + name: "基本设置", + }, { + type: "default", + name: "设置键位坐标", + onClick: function(v) { + gui.main.__internal_dismiss(); + gui.key_coordinate_navigation.show(); + } + }, { + type: "default", + name: "查看使用须知", + onClick: function(v) { + gui.dialogs.showConfirmDialog({ + title: "使用须知", + text: user_agreements, + canExit: true, + buttons: ["确认"], + }) + }, + }, { + type: "default", + name: "查看LICENSE", + onClick: function(v) { + threads.start(function() { + var license = http.get("https://cdn.jsdelivr.net/gh/StageGuard/SkyAutoPlayerScript/LICENSE").body.string(); + gui.dialogs.showConfirmDialog({ + title: "GNU GENERAL PUBLIC LICENSE", + text: license, + canExit: true, + buttons: ["确认"], + }); + }); + }, + }, { + type: "tag", + name: "Version: " + config.values.currentVersion + "(git@" + config.values.gitVersion + ")", + }], function self(element) { + self.relative = new android.widget.RelativeLayout(ctx); + self.relative.setLayoutParams(new android.widget.LinearLayout.LayoutParams(-1, -2)); + + switch(element.type) { + case "tag": + self.title = new android.widget.TextView(ctx); + self.title.setGravity(android.view.Gravity.LEFT | android.view.Gravity.CENTER); + self.title.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-2, -2)); + self.title.getLayoutParams().setMargins(dp * 5, dp * 5, dp * 5, dp * 5); + self.title.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT); + self.title.setTextSize(12); + self.title.setTextColor(gui.config.colors.sec_text); + self.title.setText(element.name); + self.relative.addView(self.title); + break; + case "default": + self.title = new android.widget.TextView(ctx); + self.title.setId(10); + self.title.setGravity(android.view.Gravity.LEFT | android.view.Gravity.CENTER); + self.title.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(-2, -2)); + self.title.getLayoutParams().setMargins(dp * 10, dp * 10, dp * 10, dp * 10); + self.title.getLayoutParams().addRule(android.widget.RelativeLayout.ALIGN_PARENT_LEFT); + self.title.setTextSize(14); + self.title.setTextColor(gui.config.colors.text); + self.title.setText(element.name); + self.relative.addView(self.title); + break; + } + return self.relative; + + })); + s.ns1_listAdapterController = RhinoListAdapter.getController(s.ns1_listAdapter); + s.ns1_listView.setDividerHeight(0); + s.ns1_listView.setAdapter(s.ns1_listAdapterController.self); + s.ns1_listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener({ + onItemClick: function(parent, view, pos, id) { + var item = s.ns1_listAdapterController.get(pos); + switch(item.type) { + case "default": + item.onClick(view); + } + } + })); + return s.ns1_listView; + }, + }); + gui.suspension.show(); + o.close(); + if(!config.values.skipRunScriptTip) { + gui.dialogs.showConfirmDialog({ + title: "使用须知", + text: user_agreements, + canExit: false, + buttons: ["确认"], + skip: function(checked) { + config.save("skip_run_script_tip", checked); + }, + callback: function(id) {}, + }); + } +}, false, false); + + +/*gui.dialogs.showOperateDialog([{ + text: "Accessbility", + description: "Use android accessbility permission with function \"click(x, y)\"", +}, { + text: "Root Automator", + description: "Use root permission with function \"RootAutomator.tap(x, y)\"", +}], function(id) { + toast("Clicked " + id); +}, false);*/ + + + +}); \ No newline at end of file diff --git a/update_log.txt b/update_log.txt new file mode 100644 index 0000000..ea72971 --- /dev/null +++ b/update_log.txt @@ -0,0 +1,4 @@ +版本: 2 +更新时间: 2020.07.19 10:51 +更新内容: + * 更新测试 \ No newline at end of file