YYPOST群发软件 发表于 2026-6-10 06:50:29

AIWROK软件智能任务监控悬浮窗

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="&#128202; 任务监控"
                  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="&#128260; 重置统计"
                  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("&#128202; 任务监控已就绪");
      
    } 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("&#128316; 详细信息已收起");
    } else {
      // 展开
      this.detail_layout.setVisibility(View.VISIBLE);
      this.isExpanded = true;
      printl("&#128317; 详细信息已展开");
    }
};

// 启动任务
智能任务监控.prototype.startTask = function() {
    if (this.isRunning) {
      toast.show("⚠️ 任务已在运行中");
      return;
    }
   
    try {
      printl(" 正在启动主脚本...");
      this.addLog("&#128640; 正在加载主脚本...");
      
      // 使用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("&#128260; 开始新任务...");
                  }
                }, 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("&#128260; 统计已重置");
    printl("&#128260; 统计数据已重置");
};

// 更新进度显示
智能任务监控.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("&#128205; 悬浮窗位置设置为: (" + 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",
//点击悬浮窗启动按钮即可开始监控,无需额外配置即可快速上手使用。

页: [1]
查看完整版本: AIWROK软件智能任务监控悬浮窗