From 67614b80163923a4e66eb39c2e46dee4565e29ac Mon Sep 17 00:00:00 2001 From: hyb1996 <946994919@qq.com> Date: Mon, 5 Nov 2018 11:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20captureScreen()=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E9=80=A0=E6=88=90=E6=AD=BB=E5=BE=AA=E7=8E=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 5 +- .../main/assets/sample/复杂界面/音乐浏览器.js | 78 +++++++++++-------- .../autojs/core/http/MutableOkHttp.java | 5 -- .../core/image/capture/ScreenCapturer.java | 5 +- common/release/output.json | 2 +- project-versions.json | 4 +- 6 files changed, 55 insertions(+), 44 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d861c3fe..2aadea9b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,6 +14,7 @@ + @@ -116,8 +117,8 @@ - - + + diff --git a/app/src/main/assets/sample/复杂界面/音乐浏览器.js b/app/src/main/assets/sample/复杂界面/音乐浏览器.js index f3d6f949..0664fbdc 100644 --- a/app/src/main/assets/sample/复杂界面/音乐浏览器.js +++ b/app/src/main/assets/sample/复杂界面/音乐浏览器.js @@ -1,20 +1,39 @@ "ui"; -//音乐文件的后缀名 -var musicExts = [".mp3", ".wma", ".rm", ".wav", ".mid", ".ape", ".flac"]; -//扫描路径 -var path = files.getSdcardPath(); -//保存音乐文件列表的数组 -var musicFiles = []; +var IconView = (function() { + //继承ui.Widget + util.extend(IconView, ui.Widget); + + function IconView() { + //调用父类构造函数 + ui.Widget.call(this); + //自定义属性color,定义按钮颜色 + this.defineAttr("icon", (view, name, defaultGetter) => { + return this._icon; + }, (view, name, value, defaultSetter) => { + this._icon = value; + view.setImageResource(value); + }); + } + IconView.prototype.render = function() { + return ( + + ); + } + ui.registerWidget("icon", IconView); + return IconView; +})(); + +var apps = []; ui.layout( - + - - + + @@ -22,38 +41,31 @@ ui.layout( ); -ui.files.setDataSource(musicFiles); +ui.apps.setDataSource(musicFiles); -ui.files.on("item_click", function(item, pos){ - media.playMusic(item.path, 1); +ui.apps.on("item_click", function(item, pos){ + toast(item); }); //启动线程来扫描音乐文件 threads.start(function () { - listMuiscFiles(path, musicFiles); + listApps(apps); ui.run(()=> { ui.progressbar.setVisility(8); }); }); -function listMuiscFiles(dir, list) { - //遍历该文件夹的文件 - files.listDir(dir).forEach(fileName => { - var path = files.join(dir, fileName); - //如果是子文件夹则继续扫描子文件夹的文件 - if (files.isDir(path)) { - listMuiscFiles(path, list); - return; - } - for (var i = 0; i < musicExts.length; i++) { - //如果文件名的后缀是音乐格式 - if (fileName.endsWith(musicExts[i])) { - //则把它添加到列表中 - list.push({ - name: fileName, - path: path - }); - } - } - }); +function listApps(apps) { + var pm = context.getPackageManager(); + let list = pm.getInstalledPackages(0); + for(let i = 0; i < list.size(); i++){ + let p = list.get(i); + apps.push({ + appName: p.applicationInfo.loadLabel(pm).toString(), + packageName: p.packageName, + versionName: p.versionName, + versionCode: p.versionCode, + icon: p.applicationInfo.loadIcon(pm) + }); + } } \ No newline at end of file diff --git a/autojs/src/main/java/com/stardust/autojs/core/http/MutableOkHttp.java b/autojs/src/main/java/com/stardust/autojs/core/http/MutableOkHttp.java index b9245367..f80c5ed5 100644 --- a/autojs/src/main/java/com/stardust/autojs/core/http/MutableOkHttp.java +++ b/autojs/src/main/java/com/stardust/autojs/core/http/MutableOkHttp.java @@ -1,10 +1,5 @@ package com.stardust.autojs.core.http; -import android.widget.AdapterView; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Proxy; import java.util.Collections; import java.util.concurrent.TimeUnit; diff --git a/autojs/src/main/java/com/stardust/autojs/core/image/capture/ScreenCapturer.java b/autojs/src/main/java/com/stardust/autojs/core/image/capture/ScreenCapturer.java index a0f5e064..2b04cbae 100644 --- a/autojs/src/main/java/com/stardust/autojs/core/image/capture/ScreenCapturer.java +++ b/autojs/src/main/java/com/stardust/autojs/core/image/capture/ScreenCapturer.java @@ -21,6 +21,7 @@ import android.view.OrientationEventListener; import com.stardust.autojs.runtime.exception.ScriptException; import com.stardust.autojs.runtime.exception.ScriptInterruptedException; +import com.stardust.lang.ThreadCompat; import com.stardust.util.ScreenMetrics; import java.util.concurrent.atomic.AtomicReference; @@ -152,7 +153,8 @@ public class ScreenCapturer { mException = null; throw new ScriptException(e); } - while (true) { + Thread thread = ThreadCompat.currentThread(); + while (!thread.isInterrupted()) { Image cachedImage = mCachedImage.getAndSet(null); if (cachedImage != null) { if (mUnderUsingImage != null) { @@ -162,6 +164,7 @@ public class ScreenCapturer { return cachedImage; } } + throw new ScriptInterruptedException(); } public int getScreenDensity() { diff --git a/common/release/output.json b/common/release/output.json index 0bed4d9b..2ec12d7a 100644 --- a/common/release/output.json +++ b/common/release/output.json @@ -1 +1 @@ -[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":436,"versionName":"4.0.4 Alpha7","enabled":true,"outputFile":"commonRelease-4.0.4 Alpha7.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.4 Alpha7.apk","properties":{}}] \ No newline at end of file +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":437,"versionName":"4.0.4 Alpha8","enabled":true,"outputFile":"commonRelease-4.0.4 Alpha8.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.4 Alpha8.apk","properties":{}}] \ No newline at end of file diff --git a/project-versions.json b/project-versions.json index 54411dcc..80e0fb64 100644 --- a/project-versions.json +++ b/project-versions.json @@ -1,6 +1,6 @@ { - "appVersionCode": 436, - "appVersionName": "4.0.4 Alpha7", + "appVersionCode": 437, + "appVersionName": "4.0.4 Alpha8", "target": 28, "mini": 17, "compile": 28,