|
|
AIWROKÈí¼þÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°
- // ÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°
- // ½»Á÷£º711841924 / 528816639
- // »ùÓÚAIWROKÈí¼þ°²×¿¿ª·¢¿ò¼Ü
- // ÌṩÈÎÎñ¼à¿Ø¡¢½ø¶ÈÏÔʾ¡¢¿ìËÙ¿ØÖƵȹ¦ÄÜ
- function ÖÇÄÜÈÎÎñ¼à¿Ø() {
- this.screenHeight = 1920; // ĬÈÏÖµ
- this.screenWidth = 1080; // ĬÈÏÖµ
- this.isExpanded = false; // Õ¹¿ª×´Ì¬
- this.taskStatus = "´ý»ú"; // ÈÎÎñ״̬
- this.progress = 0; // ½ø¶È°Ù·Ö±È
- this.taskCount = 0; // Íê³ÉÈÎÎñÊý
- this.isRunning = false; // ÊÇ·ñÔËÐÐÖÐ
- this.mainThread = null; // Ö÷½Å±¾Ïß³ÌÒýÓÃ
- this.isPaused = false; // ÊÇ·ñÔÝÍ£
- }
- // ´´½¨Ðü¸¡´°ÊµÀý
- var ¼à¿Ø´°¿Ú = new ÖÇÄÜÈÎÎñ¼à¿Ø();
- // ´´½¨Ðü¸¡´°·½·¨
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.create = function() {
- try {
- printl("===== ¿ªÊ¼´´½¨ÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´° =====");
-
- // ´´½¨ floatUI ʵÀý
- var fui = new floatUI();
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- try {
- var metrics = context.getResources().getDisplayMetrics();
- this.screenHeight = metrics.heightPixels;
- this.screenWidth = metrics.widthPixels;
- printl("✅ »ñÈ¡ÆÁÄ»³ß´ç: " + this.screenWidth + "x" + this.screenHeight);
- } catch(e) {
- printl("⚠️ »ñÈ¡ÆÁÄ»³ß´çʧ°Ü£¬Ê¹ÓÃĬÈÏÖµ: " + e);
- }
-
- // ¼ÓÔØÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°XML²¼¾Ö
- fui.loadXML(`
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="220dp"
- android:layout_height="wrap_content"
- android:background="#DD1E1E1E"
- android:orientation="vertical"
- android:padding="8dp"
- android:elevation="10dp">
-
- <!-- ±êÌâÀ¸ -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:gravity="center_vertical">
-
- <TextView
- android:id="title_text"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="📊 ÈÎÎñ¼à¿Ø"
- android:textSize="14sp"
- android:textStyle="bold"
- android:textColor="#FFFFFF"/>
-
- <ImageButton
- android:id="btn_expand"
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:src="@android:drawable/arrow_down_float"
- android:background="#00000000"
- android:scaleType="fitCenter"/>
- </LinearLayout>
-
- <!-- ºËÐÄÐÅÏ¢ÇøÓò£¨Ê¼ÖÕÏÔʾ£© -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_marginTop="5dp">
-
- <!-- ״̬ÏÔʾ -->
- <TextView
- android:id="status_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="״̬: ´ý»ú"
- android:textSize="12sp"
- android:textColor="#00FF00"
- android:layout_marginBottom="3dp"/>
-
- <!-- ½ø¶ÈÌõ -->
- <ProgressBar
- android:id="progress_bar"
- style="?android:attr/progressBarStyleHorizontal"
- android:layout_width="match_parent"
- android:layout_height="8dp"
- android:max="100"
- android:progress="0"
- android:progressDrawable="@android:drawable/progress_horizontal"
- android:layout_marginBottom="3dp"/>
-
- <!-- ½ø¶È°Ù·Ö±È -->
- <TextView
- android:id="progress_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="½ø¶È: 0%"
- android:textSize="11sp"
- android:textColor="#AAAAAA"
- android:gravity="right"/>
- </LinearLayout>
-
- <!-- ÏêϸÐÅÏ¢ÇøÓò£¨¿ÉÕ¹¿ª£© -->
- <LinearLayout
- android:id="detail_layout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:visibility="gone"
- android:layout_marginTop="8dp">
-
- <!-- ·Ö¸ôÏß -->
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#444444"
- android:layout_marginBottom="5dp"/>
-
- <!-- ͳ¼ÆÐÅÏ¢ -->
- <TextView
- android:id="stats_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="ÒÑÍê³É: 0 ¸öÈÎÎñ"
- android:textSize="11sp"
- android:textColor="#CCCCCC"
- android:layout_marginBottom="5dp"/>
-
- <!-- ÈÕÖ¾Êä³öÇø -->
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="60dp"
- android:background="#1A1A1A"
- android:padding="5dp"
- android:layout_marginBottom="5dp">
-
- <TextView
- android:id="log_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="µÈ´ýÈÎÎñÆô¶¯..."
- android:textSize="10sp"
- android:textColor="#888888"
- android:lineSpacingExtra="2dp"/>
- </ScrollView>
-
- <!-- ¿ØÖư´Å¥×é -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:gravity="center">
-
- <Button
- android:id="btn_start"
- android:layout_width="0dp"
- android:layout_height="32dp"
- android:layout_weight="1"
- android:text="▶ Æô¶¯"
- android:textSize="11sp"
- android:background="#28A745"
- android:textColor="#FFFFFF"
- android:layout_marginRight="2dp"/>
-
- <Button
- android:id="btn_pause"
- android:layout_width="0dp"
- android:layout_height="32dp"
- android:layout_weight="1"
- android:text="⏸ ÔÝÍ£"
- android:textSize="11sp"
- android:background="#FFC107"
- android:textColor="#000000"
- android:layout_marginLeft="2dp"
- android:layout_marginRight="2dp"/>
-
- <Button
- android:id="btn_stop"
- android:layout_width="0dp"
- android:layout_height="32dp"
- android:layout_weight="1"
- android:text="⏹ Í£Ö¹"
- android:textSize="11sp"
- android:background="#DC3545"
- android:textColor="#FFFFFF"
- android:layout_marginLeft="2dp"/>
- </LinearLayout>
-
- <!-- ÖØÖð´Å¥ -->
- <Button
- android:id="btn_reset"
- android:layout_width="match_parent"
- android:layout_height="35dp"
- android:text="🔄 ÖØÖÃͳ¼Æ"
- android:textSize="12sp"
- android:background="#6C757D"
- android:textColor="#FFFFFF"
- android:layout_marginTop="5dp"
- android:layout_marginBottom="2dp"/>
- </LinearLayout>
- </LinearLayout>
- `);
-
- // ±£´æfloatUIʵÀý
- this.ui = fui;
-
- // ÉèÖóõʼλÖã¨ÆÁÄ»ÓÒ²à¾ÓÖУ©
- var posX = this.screenWidth - 240;
- var posY = (this.screenHeight - 350) / 2;
- this.setPos(posX, posY);
-
- // »ñÈ¡UIÔªËØ
- this.title_text = fui.findViewById("title_text");
- this.btn_expand = fui.findViewById("btn_expand");
- this.status_text = fui.findViewById("status_text");
- this.progress_bar = fui.findViewById("progress_bar");
- this.progress_text = fui.findViewById("progress_text");
- this.detail_layout = fui.findViewById("detail_layout");
- this.stats_text = fui.findViewById("stats_text");
- this.log_text = fui.findViewById("log_text");
- this.btn_start = fui.findViewById("btn_start");
- this.btn_pause = fui.findViewById("btn_pause");
- this.btn_stop = fui.findViewById("btn_stop");
- this.btn_reset = fui.findViewById("btn_reset");
-
- // ³õʼ»¯°´Å¥Ê¼þ
- this.initButtons();
-
- printl("✅ ÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°´´½¨³É¹¦");
- toast.show("📊 ÈÎÎñ¼à¿ØÒѾÍÐ÷");
-
- } catch (err) {
- printl("❌ Ðü¸¡´°´´½¨Ê§°Ü: " + err);
- }
- };
- // ³õʼ»¯°´Å¥Ê¼þ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.initButtons = function() {
- var self = this;
-
- // Õ¹¿ª/ÊÕÆð°´Å¥µã»÷ʼþ
- this.btn_expand.setOnClickListener(function() {
- self.toggleDetail();
- });
-
- // Æô¶¯°´Å¥µã»÷ʼþ
- this.btn_start.setOnClickListener(function() {
- self.startTask();
- });
-
- // ÔÝÍ£°´Å¥µã»÷ʼþ
- this.btn_pause.setOnClickListener(function() {
- self.pauseTask();
- });
-
- // Í£Ö¹°´Å¥µã»÷ʼþ
- this.btn_stop.setOnClickListener(function() {
- self.stopTask();
- });
-
- // ÖØÖð´Å¥µã»÷ʼþ
- this.btn_reset.setOnClickListener(function() {
- self.resetStats();
- });
- };
- // Õ¹¿ª/ÊÕÆðÏêϸÐÅÏ¢
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.toggleDetail = function() {
- if (this.isExpanded) {
- // ÊÕÆð
- this.detail_layout.setVisibility(View.GONE);
- this.isExpanded = false;
- printl("🔼 ÏêϸÐÅÏ¢ÒÑÊÕÆð");
- } else {
- // Õ¹¿ª
- this.detail_layout.setVisibility(View.VISIBLE);
- this.isExpanded = true;
- printl("🔽 ÏêϸÐÅÏ¢ÒÑÕ¹¿ª");
- }
- };
- // Æô¶¯ÈÎÎñ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.startTask = function() {
- if (this.isRunning) {
- toast.show("⚠️ ÈÎÎñÒÑÔÚÔËÐÐÖÐ");
- return;
- }
-
- try {
- printl(" ÕýÔÚÆô¶¯Ö÷½Å±¾...");
- this.addLog("🚀 ÕýÔÚ¼ÓÔØÖ÷½Å±¾...");
-
- // ʹÓÃAIWROKµÄthread APIÆô¶¯Ö÷½Å±¾
- var self = this;
- var threadObj = new thread();
- this.mainThread = threadObj;
- this.isRunning = true;
- this.isPaused = false;
-
- // ÔÚÏß³ÌÖÐÖ´ÐÐÖ÷½Å±¾´úÂë
- threadObj.runJsCode(function() {
- try {
- printl("✅ Ö÷½Å±¾Ïß³ÌÒÑÆô¶¯");
- // ʹÓÃImport¼ÓÔØÖ÷½Å±¾
- Import("Ö÷½Å±¾.js");
- } catch(e) {
- printl(" Ö÷½Å±¾Ö´ÐÐʧ°Ü: " + e);
- }
- }, "Ö÷½Å±¾Ïß³Ì");
-
- this.taskStatus = "ÔËÐÐÖÐ";
- this.updateStatus("#00FF00", "״̬: ÔËÐÐÖÐ");
- this.addLog("✅ Ö÷½Å±¾ÒÑÆô¶¯");
- toast.show("▶ Ö÷½Å±¾Æô¶¯³É¹¦");
-
- // Ä£Äâ½ø¶È¸üÐÂ
- this.taskTimer = setInterval(function() {
- if (!self.isRunning) {
- clearInterval(self.taskTimer);
- return;
- }
-
- // Èç¹ûÔÝÍ££¬²»¸üнø¶È
- if (self.isPaused) {
- return;
- }
-
- self.progress += 2;
- if (self.progress >= 100) {
- self.progress = 100;
- self.taskCount++;
- self.addLog("✅ ÈÎÎñÍê³É #" + self.taskCount);
- self.updateStats();
-
- // ÖØÖýø¶È£¬Ä£ÄâÏÂÒ»¸öÈÎÎñ
- setTimeout(function() {
- if (self.isRunning && !self.isPaused) {
- self.progress = 0;
- self.addLog("🔄 ¿ªÊ¼ÐÂÈÎÎñ...");
- }
- }, 1000);
- }
-
- self.updateProgress();
- }, 2000);
-
- } catch(e) {
- printl("❌ Æô¶¯Ê§°Ü: " + e);
- this.addLog("❌ Æô¶¯Ê§°Ü: " + e);
- toast.show(" Ö÷½Å±¾Æô¶¯Ê§°Ü");
- }
- };
- // ÔÝÍ£ÈÎÎñ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.pauseTask = function() {
- if (!this.isRunning) {
- toast.show("⚠️ ÈÎÎñδÔÚÔËÐÐ");
- return;
- }
-
- try {
- // ÔÝÍ£±êÖ¾
- this.isPaused = true;
-
- // ÖжÏÖ÷½Å±¾Ïß³Ì
- if (this.mainThread) {
- this.mainThread.stop();
- printl("⏸ Ö÷½Å±¾Ïß³ÌÒÑÔÝÍ£");
- }
-
- this.taskStatus = "ÒÑÔÝÍ£";
- this.updateStatus("#FFC107", "״̬: ÒÑÔÝÍ£");
- this.addLog("⏸ Ö÷½Å±¾ÒÑÔÝÍ£");
- toast.show("⏸ Ö÷½Å±¾ÔÝÍ£");
-
- if (this.taskTimer) {
- clearInterval(this.taskTimer);
- }
- } catch(e) {
- printl("❌ ÔÝͣʧ°Ü: " + e);
- this.addLog("❌ ÔÝͣʧ°Ü: " + e);
- toast.show("❌ ÔÝͣʧ°Ü");
- }
- };
- // Í£Ö¹ÈÎÎñ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.stopTask = function() {
- try {
- // Í£Ö¹Ö÷½Å±¾Ïß³Ì
- if (this.mainThread) {
- this.mainThread.stop();
- this.mainThread = null;
- printl("⏹ Ö÷½Å±¾Ïß³ÌÒÑÍ£Ö¹");
- }
-
- this.isRunning = false;
- this.isPaused = false;
- this.taskStatus = "ÒÑÍ£Ö¹";
- this.updateStatus("#DC3545", "״̬: ÒÑÍ£Ö¹");
- this.addLog("⏹ Ö÷½Å±¾ÒÑÍ£Ö¹");
- toast.show("⏹ Ö÷½Å±¾Í£Ö¹");
-
- if (this.taskTimer) {
- clearInterval(this.taskTimer);
- }
- } catch(e) {
- printl("❌ ֹͣʧ°Ü: " + e);
- this.addLog("❌ ֹͣʧ°Ü: " + e);
- toast.show("❌ ֹͣʧ°Ü");
- }
- };
- // ÖØÖÃͳ¼Æ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.resetStats = function() {
- // ÏÈÍ£Ö¹µ±Ç°ÈÎÎñ
- if (this.isRunning) {
- this.stopTask();
- }
-
- this.progress = 0;
- this.taskCount = 0;
- this.taskStatus = "´ý»ú";
- this.isRunning = false;
- this.isPaused = false;
- this.mainThread = null;
-
- this.updateProgress();
- this.updateStatus("#00FF00", "״̬: ´ý»ú");
- this.updateStats();
- this.log_text.setText("µÈ´ýÈÎÎñÆô¶¯...");
-
- toast.show("🔄 ͳ¼ÆÒÑÖØÖÃ");
- printl("🔄 ͳ¼ÆÊý¾ÝÒÑÖØÖÃ");
- };
- // ¸üнø¶ÈÏÔʾ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.updateProgress = function() {
- this.progress_bar.setProgress(this.progress);
- this.progress_text.setText("½ø¶È: " + this.progress + "%");
- };
- // ¸üÐÂ״̬ÏÔʾ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.updateStatus = function(color, text) {
- this.status_text.setTextColor(android.graphics.Color.parseColor(color));
- this.status_text.setText(text);
- };
- // ¸üÐÂͳ¼ÆÐÅÏ¢
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.updateStats = function() {
- this.stats_text.setText("ÒÑÍê³É: " + this.taskCount + " ¸öÈÎÎñ");
- };
- // Ìí¼ÓÈÕÖ¾
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.addLog = function(message) {
- var currentTime = new Date().toLocaleTimeString();
- var currentLog = this.log_text.getText().toString();
- var newLog = "[" + currentTime + "] " + message + "\n" + currentLog;
-
- // ÏÞÖÆÈÕÖ¾ÐÐÊý£¬×î¶à±£Áô10ÐÐ
- var lines = newLog.split("\n");
- if (lines.length > 10) {
- lines = lines.slice(0, 10);
- newLog = lines.join("\n");
- }
-
- this.log_text.setText(newLog);
- };
- // ÉèÖÃÐü¸¡´°Î»ÖÃ
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.setPos = function(x, y) {
- this.ui.setPosition(x, y);
- printl("📍 Ðü¸¡´°Î»ÖÃÉèÖÃΪ: (" + x + ", " + y + ")");
- };
- // ¹Ø±ÕÐü¸¡´°
- ÖÇÄÜÈÎÎñ¼à¿Ø.prototype.close = function() {
- // ÏÈÍ£Ö¹Ö÷½Å±¾Ïß³Ì
- if (this.mainThread) {
- this.mainThread.stop();
- this.mainThread = null;
- }
-
- // Çå³ý¶¨Ê±Æ÷
- if (this.taskTimer) {
- clearInterval(this.taskTimer);
- }
-
- this.ui.close();
- printl("✅ ÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°ÒѹرÕ");
- };
- // Æô¶¯Ðü¸¡´°
- try {
- ¼à¿Ø´°¿Ú.create();
- printl("===== ÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°Æô¶¯³É¹¦ =====");
- } catch (err) {
- printl("❌ ÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°Æô¶¯Ê§°Ü: " + err);
- }
- //±¾½Å±¾ÊÇרΪ ES5 ϵͳ°²×¿ JavaScript ÒýÇæ Rhino ¿ª·¢¡¢
- //»ùÓÚ AIWROK ¿ò¼ÜµÄÖÇÄÜÈÎÎñ¼à¿ØÐü¸¡´°¹¤¾ß£¬ÔËÐкó»áÔÚÆÁÄ»ÓÒ²à¾ÓÖÐÉú³É¿ÉÕ¹¿ªÊÕÆðµÄÐü¸¡´°£¬
- //ºËÐÄÌṩ×Ô¶¯»¯ÈÎÎñÈ«Á÷³Ì¹Ü¿ØÄÜÁ¦£¬ÄÜʵʱÏÔʾÈÎÎñÔËÐÐ״̬¡¢½ø¶ÈÌõºÍÍê³ÉÈÎÎñÊý£¬
- //¼¯³ÉÆô¶¯¡¢ÔÝÍ£¡¢Í£Ö¹¡¢ÖØÖÃͳ¼ÆËÄ´óºËÐÄ¿ØÖư´Å¥£¬ÄÚÖôøÊ±¼ä´ÁµÄÈÕ־ϵͳ×Ô¶¯±£Áô×îР10 ÌõÔËÐмǼ£¬
- //Ö§³Ö×Ô¶¯ÊÊÅ䲻ͬÉ豸ÆÁÄ»³ß´ç£¬ËùÓвÙ×÷¾ùÓÐ Toast ÌáʾºÍ¿ØÖÆÌ¨ÈÕÖ¾·´À¡£¬
- //Ö»Ð轫ÐèÖ´ÐеÄ×Ô¶¯»¯´úÂë±£´æÎªÍ¬Ä¿Â¼Ï嵀 "Ö÷½Å±¾.js"£¬
- //µã»÷Ðü¸¡´°Æô¶¯°´Å¥¼´¿É¿ªÊ¼¼à¿Ø£¬ÎÞÐè¶îÍâÅäÖü´¿É¿ìËÙÉÏÊÖʹÓá£
¸´ÖÆ´úÂë
|
|