完整案例原生UI功能演示

351

主题

193

回帖

2252

积分

管理员

积分
2252
完整案例原生UI功能演示

2.png


3.png


4.png


5.png


  1. /**
  2. * AIWROK 原生UI功能演示
  3. * 交流QQ群: 711841924 (群一) / 528816639 (苹果内测群)
  4. * 整合:文本框 + 按钮 + 配置保存 + 日志显示 + 多选框 + Toast消息 + 日志悬浮窗 + 多按钮操作 + 计时器 + 进度条 + 开关 + 列表 + 对话框 + 日期时间 + 下拉选择 + 评分条 + 拖动条
  5. */

  6. var ac = new activity();
  7. ac.loadSXML(`
  8. <ScrollView
  9.     android:layout_width="match_parent"
  10.     android:layout_height="match_parent">

  11.     <LinearLayout
  12.         android:layout_width="match_parent"
  13.         android:layout_height="wrap_content"
  14.         android:orientation="vertical"
  15.         android:padding="16dp"
  16.         android:background="#f5f5f5">

  17.     <TextView
  18.         android:layout_width="match_parent"
  19.         android:layout_height="wrap_content"
  20.         android:text="AIWROK UI演示"
  21.         android:textSize="24sp"
  22.         android:textStyle="bold"
  23.         android:textColor="#333333"
  24.         android:gravity="center"
  25.         android:layout_marginBottom="10dp"/>

  26.     <!-- QQ群信息 -->
  27.     <LinearLayout
  28.         android:layout_width="match_parent"
  29.         android:layout_height="wrap_content"
  30.         android:orientation="vertical"
  31.         android:background="#FFF3E0"
  32.         android:padding="10dp"
  33.         android:layout_marginBottom="15dp">

  34.         <TextView
  35.             android:layout_width="match_parent"
  36.             android:layout_height="wrap_content"
  37.             android:text="🍎 交流QQ群:711841924(群)"
  38.             android:textSize="14sp"
  39.             android:textColor="#E65100"
  40.             android:gravity="center"
  41.             android:layout_marginBottom="5dp"/>

  42.         <TextView
  43.             android:layout_width="match_parent"
  44.             android:layout_height="wrap_content"
  45.             android:text="🍎 交流QQ群:528816639(安卓内测群)"
  46.             android:textSize="14sp"
  47.             android:textColor="#E65100"
  48.             android:gravity="center"/>
  49.     </LinearLayout>

  50.     <EditText
  51.         android:id="@+id/etUser"
  52.         android:layout_width="match_parent"
  53.         android:layout_height="wrap_content"
  54.         android:hint="输入用户名"
  55.         android:layout_marginBottom="10dp"/>

  56.     <Button
  57.         android:id="@+id/btnSave"
  58.         android:layout_width="match_parent"
  59.         android:layout_height="wrap_content"
  60.         android:text="保存"
  61.         android:background="#4CAF50"
  62.         android:textColor="#ffffff"
  63.         android:layout_marginBottom="10dp"/>

  64.     <Button
  65.         android:id="@+id/btnLoad"
  66.         android:layout_width="match_parent"
  67.         android:layout_height="wrap_content"
  68.         android:text="读取"
  69.         android:background="#2196F3"
  70.         android:textColor="#ffffff"
  71.         android:layout_marginBottom="20dp"/>

  72.     <TextView
  73.         android:layout_width="match_parent"
  74.         android:layout_height="wrap_content"
  75.         android:text="多选功能:"
  76.         android:textSize="16sp"
  77.         android:textColor="#333333"
  78.         android:layout_marginBottom="10dp"/>

  79.     <LinearLayout
  80.         android:id="@+id/checkBoxLayout"
  81.         android:layout_width="match_parent"
  82.         android:layout_height="wrap_content"
  83.         android:orientation="vertical"
  84.         android:layout_marginBottom="10dp">

  85.         <CheckBox
  86.             android:id="@+id/checkBox1"
  87.             android:layout_width="wrap_content"
  88.             android:layout_height="wrap_content"
  89.             android:text="选项1" />

  90.         <CheckBox
  91.             android:id="@+id/checkBox2"
  92.             android:layout_width="wrap_content"
  93.             android:layout_height="wrap_content"
  94.             android:text="选项2" />

  95.         <CheckBox
  96.             android:id="@+id/checkBox3"
  97.             android:layout_width="wrap_content"
  98.             android:layout_height="wrap_content"
  99.             android:text="选项3" />
  100.     </LinearLayout>

  101.     <Button
  102.         android:id="@+id/btnToast"
  103.         android:layout_width="match_parent"
  104.         android:layout_height="wrap_content"
  105.         android:text="显示Toast消息"
  106.         android:background="#9C27B0"
  107.         android:textColor="#ffffff"
  108.         android:layout_marginBottom="10dp"/>

  109.     <Button
  110.         android:id="@+id/btnCheck"
  111.         android:layout_width="match_parent"
  112.         android:layout_height="wrap_content"
  113.         android:text="获取选中项"
  114.         android:background="#FF9800"
  115.         android:textColor="#ffffff"
  116.         android:layout_marginBottom="10dp"/>

  117.     <Button
  118.         android:id="@+id/btnClear"
  119.         android:layout_width="match_parent"
  120.         android:layout_height="wrap_content"
  121.         android:text="清空日志"
  122.         android:background="#795548"
  123.         android:textColor="#ffffff"
  124.         android:layout_marginBottom="10dp"/>

  125.     <Button
  126.         android:id="@+id/btnInfo"
  127.         android:layout_width="match_parent"
  128.         android:layout_height="wrap_content"
  129.         android:text="显示系统信息"
  130.         android:background="#009688"
  131.         android:textColor="#ffffff"
  132.         android:layout_marginBottom="10dp"/>

  133.     <TextView
  134.         android:layout_width="match_parent"
  135.         android:layout_height="wrap_content"
  136.         android:text="计时器功能:"
  137.         android:textSize="16sp"
  138.         android:textColor="#333333"
  139.         android:layout_marginTop="10dp"
  140.         android:layout_marginBottom="10dp"/>

  141.     <TextView
  142.         android:id="@+id/tvTimer"
  143.         android:layout_width="match_parent"
  144.         android:layout_height="wrap_content"
  145.         android:text="00:00:00"
  146.         android:textSize="32sp"
  147.         android:textStyle="bold"
  148.         android:textColor="#E91E63"
  149.         android:gravity="center"
  150.         android:padding="10dp"
  151.         android:background="#ffffff"
  152.         android:layout_marginBottom="10dp"/>

  153.     <LinearLayout
  154.         android:layout_width="match_parent"
  155.         android:layout_height="wrap_content"
  156.         android:orientation="horizontal"
  157.         android:layout_marginBottom="10dp">

  158.         <Button
  159.             android:id="@+id/btnStartTimer"
  160.             android:layout_width="0dp"
  161.             android:layout_height="wrap_content"
  162.             android:layout_weight="1"
  163.             android:text="开始"
  164.             android:background="#4CAF50"
  165.             android:textColor="#ffffff"
  166.             android:layout_marginRight="5dp"/>

  167.         <Button
  168.             android:id="@+id/btnStopTimer"
  169.             android:layout_width="0dp"
  170.             android:layout_height="wrap_content"
  171.             android:layout_weight="1"
  172.             android:text="停止"
  173.             android:background="#F44336"
  174.             android:textColor="#ffffff"
  175.             android:layout_marginLeft="5dp"/>
  176.     </LinearLayout>

  177.     <Button
  178.         android:id="@+id/btnResetTimer"
  179.         android:layout_width="match_parent"
  180.         android:layout_height="wrap_content"
  181.         android:text="重置计时器"
  182.         android:background="#607D8B"
  183.         android:textColor="#ffffff"
  184.         android:layout_marginBottom="10dp"/>

  185.     <TextView
  186.         android:layout_width="match_parent"
  187.         android:layout_height="wrap_content"
  188.         android:text="随机数生成:"
  189.         android:textSize="16sp"
  190.         android:textColor="#333333"
  191.         android:layout_marginTop="10dp"
  192.         android:layout_marginBottom="10dp"/>

  193.     <LinearLayout
  194.         android:layout_width="match_parent"
  195.         android:layout_height="wrap_content"
  196.         android:orientation="horizontal"
  197.         android:layout_marginBottom="10dp">

  198.         <EditText
  199.             android:id="@+id/etMin"
  200.             android:layout_width="0dp"
  201.             android:layout_height="wrap_content"
  202.             android:layout_weight="1"
  203.             android:hint="最小值"
  204.             android:inputType="number"
  205.             android:layout_marginRight="5dp"/>

  206.         <EditText
  207.             android:id="@+id/etMax"
  208.             android:layout_width="0dp"
  209.             android:layout_height="wrap_content"
  210.             android:layout_weight="1"
  211.             android:hint="最大值"
  212.             android:inputType="number"
  213.             android:layout_marginLeft="5dp"/>
  214.     </LinearLayout>

  215.     <Button
  216.         android:id="@+id/btnRandom"
  217.         android:layout_width="match_parent"
  218.         android:layout_height="wrap_content"
  219.         android:text="生成随机数"
  220.         android:background="#FF5722"
  221.         android:textColor="#ffffff"
  222.         android:layout_marginBottom="10dp"/>

  223.     <TextView
  224.         android:id="@+id/tvRandom"
  225.         android:layout_width="match_parent"
  226.         android:layout_height="wrap_content"
  227.         android:text="随机数将显示在这里"
  228.         android:textSize="24sp"
  229.         android:textStyle="bold"
  230.         android:textColor="#FF5722"
  231.         android:gravity="center"
  232.         android:padding="10dp"
  233.         android:background="#ffffff"
  234.         android:layout_marginBottom="10dp"/>

  235.     <TextView
  236.         android:layout_width="match_parent"
  237.         android:layout_height="wrap_content"
  238.         android:text="进度条演示:"
  239.         android:textSize="16sp"
  240.         android:textColor="#333333"
  241.         android:layout_marginTop="10dp"
  242.         android:layout_marginBottom="10dp"/>

  243.     <ProgressBar
  244.         android:id="@+id/progressBar"
  245.         style="?android:attr/progressBarStyleHorizontal"
  246.         android:layout_width="match_parent"
  247.         android:layout_height="wrap_content"
  248.         android:max="100"
  249.         android:progress="0"
  250.         android:layout_marginBottom="10dp"/>

  251.     <LinearLayout
  252.         android:layout_width="match_parent"
  253.         android:layout_height="wrap_content"
  254.         android:orientation="horizontal"
  255.         android:layout_marginBottom="10dp">

  256.         <Button
  257.             android:id="@+id/btnProgressStart"
  258.             android:layout_width="0dp"
  259.             android:layout_height="wrap_content"
  260.             android:layout_weight="1"
  261.             android:text="开始"
  262.             android:background="#4CAF50"
  263.             android:textColor="#ffffff"
  264.             android:layout_marginRight="5dp"/>

  265.         <Button
  266.             android:id="@+id/btnProgressPause"
  267.             android:layout_width="0dp"
  268.             android:layout_height="wrap_content"
  269.             android:layout_weight="1"
  270.             android:text="暂停"
  271.             android:background="#FF9800"
  272.             android:textColor="#ffffff"
  273.             android:layout_marginLeft="5dp"/>
  274.     </LinearLayout>

  275.     <TextView
  276.         android:id="@+id/tvProgress"
  277.         android:layout_width="match_parent"
  278.         android:layout_height="wrap_content"
  279.         android:text="进度: 0%"
  280.         android:textSize="16sp"
  281.         android:textColor="#666666"
  282.         android:gravity="center"
  283.         android:layout_marginBottom="10dp"/>

  284.     <TextView
  285.         android:layout_width="match_parent"
  286.         android:layout_height="wrap_content"
  287.         android:text="开关控制:"
  288.         android:textSize="16sp"
  289.         android:textColor="#333333"
  290.         android:layout_marginTop="10dp"
  291.         android:layout_marginBottom="10dp"/>

  292.     <Switch
  293.         android:id="@+id/switch1"
  294.         android:layout_width="match_parent"
  295.         android:layout_height="wrap_content"
  296.         android:text="功能开关"
  297.         android:textSize="16sp"
  298.         android:layout_marginBottom="10dp"/>

  299.     <Switch
  300.         android:id="@+id/switch2"
  301.         android:layout_width="match_parent"
  302.         android:layout_height="wrap_content"
  303.         android:text="通知开关"
  304.         android:textSize="16sp"
  305.         android:layout_marginBottom="10dp"/>

  306.     <Button
  307.         android:id="@+id/btnSwitchStatus"
  308.         android:layout_width="match_parent"
  309.         android:layout_height="wrap_content"
  310.         android:text="查看开关状态"
  311.         android:background="#3F51B5"
  312.         android:textColor="#ffffff"
  313.         android:layout_marginBottom="10dp"/>

  314.     <TextView
  315.         android:layout_width="match_parent"
  316.         android:layout_height="wrap_content"
  317.         android:text="列表视图:"
  318.         android:textSize="16sp"
  319.         android:textColor="#333333"
  320.         android:layout_marginTop="10dp"
  321.         android:layout_marginBottom="10dp"/>

  322.     <LinearLayout
  323.         android:layout_width="match_parent"
  324.         android:layout_height="wrap_content"
  325.         android:orientation="horizontal"
  326.         android:layout_marginBottom="10dp">

  327.         <EditText
  328.             android:id="@+id/etListItem"
  329.             android:layout_width="0dp"
  330.             android:layout_height="wrap_content"
  331.             android:layout_weight="1"
  332.             android:hint="输入列表项"
  333.             android:layout_marginRight="5dp"/>

  334.         <Button
  335.             android:id="@+id/btnAddItem"
  336.             android:layout_width="wrap_content"
  337.             android:layout_height="wrap_content"
  338.             android:text="添加"
  339.             android:background="#4CAF50"
  340.             android:textColor="#ffffff"
  341.             android:layout_marginRight="5dp"/>
  342.         
  343.         <Button
  344.             android:id="@+id/btnReadList"
  345.             android:layout_width="wrap_content"
  346.             android:layout_height="wrap_content"
  347.             android:text="读取列表"
  348.             android:background="#2196F3"
  349.             android:textColor="#ffffff"/>
  350.     </LinearLayout>

  351.     <TextView
  352.         android:id="@+id/listView"
  353.         android:layout_width="match_parent"
  354.         android:layout_height="150dp"
  355.         android:text="示例项1\n示例项2\n示例项3"
  356.         android:textSize="16sp"
  357.         android:textColor="#333333"
  358.         android:background="#ffffff"
  359.         android:padding="10dp"
  360.         android:gravity="left|top"
  361.         android:scrollbars="vertical"
  362.         android:layout_marginBottom="10dp"/>

  363.     <TextView
  364.         android:layout_width="match_parent"
  365.         android:layout_height="wrap_content"
  366.         android:text="对话框演示:"
  367.         android:textSize="16sp"
  368.         android:textColor="#333333"
  369.         android:layout_marginTop="10dp"
  370.         android:layout_marginBottom="10dp"/>

  371.     <LinearLayout
  372.         android:layout_width="match_parent"
  373.         android:layout_height="wrap_content"
  374.         android:orientation="horizontal"
  375.         android:layout_marginBottom="10dp">

  376.         <Button
  377.             android:id="@+id/btnDialog1"
  378.             android:layout_width="0dp"
  379.             android:layout_height="wrap_content"
  380.             android:layout_weight="1"
  381.             android:text="确认框"
  382.             android:background="#2196F3"
  383.             android:textColor="#ffffff"
  384.             android:layout_marginRight="5dp"/>

  385.         <Button
  386.             android:id="@+id/btnDialog2"
  387.             android:layout_width="0dp"
  388.             android:layout_height="wrap_content"
  389.             android:layout_weight="1"
  390.             android:text="输入框"
  391.             android:background="#9C27B0"
  392.             android:textColor="#ffffff"
  393.             android:layout_marginLeft="5dp"/>
  394.     </LinearLayout>

  395.     <TextView
  396.         android:layout_width="match_parent"
  397.         android:layout_height="wrap_content"
  398.         android:text="日期时间:"
  399.         android:textSize="16sp"
  400.         android:textColor="#333333"
  401.         android:layout_marginTop="10dp"
  402.         android:layout_marginBottom="10dp"/>

  403.     <TextView
  404.         android:id="@+id/tvDateTime"
  405.         android:layout_width="match_parent"
  406.         android:layout_height="wrap_content"
  407.         android:text="点击按钮选择日期时间"
  408.         android:textSize="18sp"
  409.         android:textColor="#666666"
  410.         android:gravity="center"
  411.         android:padding="10dp"
  412.         android:background="#ffffff"
  413.         android:layout_marginBottom="10dp"/>

  414.     <LinearLayout
  415.         android:layout_width="match_parent"
  416.         android:layout_height="wrap_content"
  417.         android:orientation="horizontal"
  418.         android:layout_marginBottom="10dp">

  419.         <Button
  420.             android:id="@+id/btnDatePicker"
  421.             android:layout_width="0dp"
  422.             android:layout_height="wrap_content"
  423.             android:layout_weight="1"
  424.             android:text="选择日期"
  425.             android:background="#00BCD4"
  426.             android:textColor="#ffffff"
  427.             android:layout_marginRight="5dp"/>

  428.         <Button
  429.             android:id="@+id/btnTimePicker"
  430.             android:layout_width="0dp"
  431.             android:layout_height="wrap_content"
  432.             android:layout_weight="1"
  433.             android:text="选择时间"
  434.             android:background="#009688"
  435.             android:textColor="#ffffff"
  436.             android:layout_marginLeft="5dp"/>
  437.     </LinearLayout>

  438.     <TextView
  439.         android:layout_width="match_parent"
  440.         android:layout_height="wrap_content"
  441.         android:text="下拉选择:"
  442.         android:textSize="16sp"
  443.         android:textColor="#333333"
  444.         android:layout_marginTop="10dp"
  445.         android:layout_marginBottom="10dp"/>

  446.     <Button
  447.         android:id="@+id/spinner"
  448.         android:layout_width="match_parent"
  449.         android:layout_height="wrap_content"
  450.         android:text=" 请选择..."
  451.         android:background="#ffffff"
  452.         android:textColor="#666666"
  453.         android:textSize="16sp"
  454.         android:gravity="left|center_vertical"
  455.         android:padding="10dp"
  456.         android:layout_marginBottom="10dp"/>

  457.     <TextView
  458.         android:id="@+id/tvSpinner"
  459.         android:layout_width="match_parent"
  460.         android:layout_height="wrap_content"
  461.         android:text="请选择..."
  462.         android:textSize="16sp"
  463.         android:textColor="#666666"
  464.         android:gravity="center"
  465.         android:layout_marginBottom="10dp"/>

  466.     <TextView
  467.         android:layout_width="match_parent"
  468.         android:layout_height="wrap_content"
  469.         android:text="评分条:"
  470.         android:textSize="16sp"
  471.         android:textColor="#333333"
  472.         android:layout_marginTop="10dp"
  473.         android:layout_marginBottom="10dp"/>

  474.     <RatingBar
  475.         android:id="@+id/ratingBar"
  476.         android:layout_width="wrap_content"
  477.         android:layout_height="wrap_content"
  478.         android:numStars="5"
  479.         android:stepSize="0.5"
  480.         android:rating="0"
  481.         android:layout_gravity="center"
  482.         android:layout_marginBottom="10dp"/>

  483.     <TextView
  484.         android:id="@+id/tvRating"
  485.         android:layout_width="match_parent"
  486.         android:layout_height="wrap_content"
  487.         android:text="评分: 0"
  488.         android:textSize="18sp"
  489.         android:textColor="#FF9800"
  490.         android:gravity="center"
  491.         android:layout_marginBottom="10dp"/>

  492.     <Button
  493.         android:id="@+id/btnReadRating"
  494.         android:layout_width="match_parent"
  495.         android:layout_height="wrap_content"
  496.         android:text="读取评分"
  497.         android:background="#FF9800"
  498.         android:textColor="#ffffff"
  499.         android:layout_marginBottom="10dp"/>

  500.     <TextView
  501.         android:layout_width="match_parent"
  502.         android:layout_height="wrap_content"
  503.         android:text="拖动条:"
  504.         android:textSize="16sp"
  505.         android:textColor="#333333"
  506.         android:layout_marginTop="10dp"
  507.         android:layout_marginBottom="10dp"/>

  508.     <SeekBar
  509.         android:id="@+id/seekBar"
  510.         android:layout_width="match_parent"
  511.         android:layout_height="wrap_content"
  512.         android:max="100"
  513.         android:progress="50"
  514.         android:layout_marginBottom="10dp"/>

  515.     <TextView
  516.         android:id="@+id/tvSeekBar"
  517.         android:layout_width="match_parent"
  518.         android:layout_height="wrap_content"
  519.         android:text="值: 50"
  520.         android:textSize="18sp"
  521.         android:textColor="#E91E63"
  522.         android:gravity="center"
  523.         android:layout_marginBottom="10dp"/>

  524.     <Button
  525.         android:id="@+id/btnReadSeekBar"
  526.         android:layout_width="match_parent"
  527.         android:layout_height="wrap_content"
  528.         android:text="读取拖动条值"
  529.         android:background="#E91E63"
  530.         android:textColor="#ffffff"
  531.         android:layout_marginBottom="10dp"/>

  532.     <TextView
  533.         android:layout_width="match_parent"
  534.         android:layout_height="wrap_content"
  535.         android:text="运行控制:"
  536.         android:textSize="18sp"
  537.         android:textStyle="bold"
  538.         android:textColor="#333333"
  539.         android:layout_marginTop="20dp"
  540.         android:layout_marginBottom="10dp"/>

  541.     <Button
  542.         android:id="@+id/btnRunMain"
  543.         android:layout_width="match_parent"
  544.         android:layout_height="wrap_content"
  545.         android:text="▶ 开始运行主脚本"
  546.         android:background="#F44336"
  547.         android:textColor="#ffffff"
  548.         android:textSize="18sp"
  549.         android:padding="15dp"
  550.         android:layout_marginBottom="10dp"/>

  551.     <TextView
  552.         android:id="@+id/tvRunStatus"
  553.         android:layout_width="match_parent"
  554.         android:layout_height="wrap_content"
  555.         android:text="状态: 未运行"
  556.         android:textSize="14sp"
  557.         android:textColor="#666666"
  558.         android:gravity="center"
  559.         android:padding="10dp"
  560.         android:background="#ffffff"
  561.         android:layout_marginBottom="20dp"/>

  562.     <TextView
  563.         android:id="@+id/tvLog"
  564.         android:layout_width="match_parent"
  565.         android:layout_height="wrap_content"
  566.         android:text="日志将显示在这里"
  567.         android:textSize="14sp"
  568.         android:textColor="#666666"
  569.         android:padding="10dp"
  570.         android:background="#ffffff"/>

  571. </LinearLayout>

  572. </ScrollView>
  573. `);

  574. // 日志悬浮窗
  575. var 日志悬浮窗 = new floatUI();
  576. 日志悬浮窗.loadXML(
  577.     '<LinearLayout orientation="vertical" w="15" h="350" gravity="center">' +
  578.     '  <TextView id="rz" textColor="#ff3ee4" background="#000000" layout_width="wrap_content" layout_height="wrap_content" />' +
  579.     '</LinearLayout>'
  580. );
  581. var g_日志 = 日志悬浮窗.findViewById('rz');
  582. if (g_日志) {
  583.     setTimeout(function() {
  584.         日志悬浮窗.setPosition(0, (screen.getScreenHeight() * 0.4));
  585.         g_日志.setText("日志已启动");
  586.     }, 100);
  587. }

  588. var etUser = ac.findViewById("etUser");
  589. var btnSave = ac.findViewById("btnSave");
  590. var btnLoad = ac.findViewById("btnLoad");
  591. var btnToast = ac.findViewById("btnToast");
  592. var btnCheck = ac.findViewById("btnCheck");
  593. var btnClear = ac.findViewById("btnClear");
  594. var btnInfo = ac.findViewById("btnInfo");
  595. var btnStartTimer = ac.findViewById("btnStartTimer");
  596. var btnStopTimer = ac.findViewById("btnStopTimer");
  597. var btnResetTimer = ac.findViewById("btnResetTimer");
  598. var btnRandom = ac.findViewById("btnRandom");
  599. var tvTimer = ac.findViewById("tvTimer");
  600. var tvRandom = ac.findViewById("tvRandom");
  601. var etMin = ac.findViewById("etMin");
  602. var etMax = ac.findViewById("etMax");
  603. var progressBar = ac.findViewById("progressBar");
  604. var btnProgressStart = ac.findViewById("btnProgressStart");
  605. var btnProgressPause = ac.findViewById("btnProgressPause");
  606. var tvProgress = ac.findViewById("tvProgress");
  607. var switch1 = ac.findViewById("switch1");
  608. var switch2 = ac.findViewById("switch2");
  609. var btnSwitchStatus = ac.findViewById("btnSwitchStatus");
  610. var etListItem = ac.findViewById("etListItem");
  611. var btnAddItem = ac.findViewById("btnAddItem");
  612. var listView = ac.findViewById("listView");
  613. var btnDialog1 = ac.findViewById("btnDialog1");
  614. var btnDialog2 = ac.findViewById("btnDialog2");
  615. var tvDateTime = ac.findViewById("tvDateTime");
  616. var btnDatePicker = ac.findViewById("btnDatePicker");
  617. var btnTimePicker = ac.findViewById("btnTimePicker");
  618. var spinner = ac.findViewById("spinner");
  619. var tvSpinner = ac.findViewById("tvSpinner");
  620. var ratingBar = ac.findViewById("ratingBar");
  621. var tvRating = ac.findViewById("tvRating");
  622. var btnReadRating = ac.findViewById("btnReadRating"); // 读取评分按钮
  623. var seekBar = ac.findViewById("seekBar");
  624. var tvSeekBar = ac.findViewById("tvSeekBar");
  625. var btnReadSeekBar = ac.findViewById("btnReadSeekBar"); // 读取拖动条按钮
  626. var btnRunMain = ac.findViewById("btnRunMain");
  627. var tvRunStatus = ac.findViewById("tvRunStatus");
  628. var checkBoxContainer = ac.findViewById("checkBoxLayout");
  629. var tvLog = ac.findViewById("tvLog");

  630. // 加载已保存的用户名
  631. var savedName = config.getConfig('/sdcard/aiwrok_config.ini', 'username', '');
  632. if (savedName) {
  633.     etUser.setText(savedName);
  634.     tvLog.setText("已加载: " + savedName);
  635. }

  636. // 保存按钮
  637. btnSave.setOnClickListener(function() {
  638.     var name = etUser.getText().toString();
  639.     if (name) {
  640.         config.setConfig('/sdcard/aiwrok_config.ini', 'username', name);
  641.         tvLog.setText("✅ 已保存: " + name);
  642.         console.log("保存成功: " + name);
  643.     } else {
  644.         tvLog.setText("⚠️ 请输入用户名");
  645.     }
  646. });

  647. // 读取按钮
  648. btnLoad.setOnClickListener(function() {
  649.     var name = config.getConfig('/sdcard/aiwrok_config.ini', 'username', '无数据');
  650.     tvLog.setText("📖 读取到: " + name);
  651.     console.log("读取到: " + name);
  652. });

  653. // Toast消息按钮
  654. btnToast.setOnClickListener(function() {
  655.     var name = etUser.getText().toString();
  656.     if (name) {
  657.         tvLog.setText("🔔 Toast: 你好," + name);
  658.         console.log("Toast: 你好," + name);
  659.         if (g_日志) g_日志.setText("Toast: " + name);
  660.     } else {
  661.         tvLog.setText("⚠️ 请先输入用户名");
  662.     }
  663. });

  664. // 获取选中项按钮
  665. btnCheck.setOnClickListener(function() {
  666.     var count = checkBoxContainer.getChildCount();
  667.     var selectedItems = [];

  668.     for (var i = 0; i < count; i++) {
  669.         var checkBox = checkBoxContainer.getChildAt(i);
  670.         if (checkBox.isChecked()) {
  671.             selectedItems.push(checkBox.getText().toString());
  672.         }
  673.     }
  674.    
  675.     if (selectedItems.length > 0) {
  676.         tvLog.setText("✅ 选中: " + selectedItems.join(', '));
  677.         console.log("选中: " + selectedItems.join(', '));
  678.         if (g_日志) g_日志.setText("选中: " + selectedItems.length + "项");
  679.     } else {
  680.         tvLog.setText("⚠️ 未选中任何项");
  681.     }
  682. });

  683. // 清空日志按钮
  684. btnClear.setOnClickListener(function() {
  685.     tvLog.setText("日志已清空");
  686.     console.log("日志已清空");
  687.     if (g_日志) g_日志.setText("日志已清空");
  688. });

  689. // 显示系统信息按钮
  690. btnInfo.setOnClickListener(function() {
  691.     var info = "屏幕: " + screen.getScreenWidth() + "x" + screen.getScreenHeight();
  692.     tvLog.setText("ℹ️ " + info);
  693.     console.log(info);
  694.     if (g_日志) g_日志.setText("系统信息");
  695. });

  696. // 计时器功能
  697. var timerInterval = null;
  698. var timerSeconds = 0;

  699. function formatTime(seconds) {
  700.     var hours = Math.floor(seconds / 3600);
  701.     var minutes = Math.floor((seconds % 3600) / 60);
  702.     var secs = seconds % 60;
  703.     return (hours < 10 ? "0" + hours : hours) + ":" +
  704.            (minutes < 10 ? "0" + minutes : minutes) + ":" +
  705.            (secs < 10 ? "0" + secs : secs);
  706. }

  707. btnStartTimer.setOnClickListener(function() {
  708.     if (timerInterval) return;
  709.     timerInterval = setInterval(function() {
  710.         timerSeconds++;
  711.         // 在UI线程更新
  712.         ac.runOnUiThread(function() {
  713.             tvTimer.setText(formatTime(timerSeconds));
  714.         });
  715.     }, 1000);
  716.     tvLog.setText("️ 计时器已启动");
  717.     console.log("计时器启动");
  718.     if (g_日志) g_日志.setText("计时中...");
  719. });

  720. btnStopTimer.setOnClickListener(function() {
  721.     if (timerInterval) {
  722.         clearInterval(timerInterval);
  723.         timerInterval = null;
  724.     }
  725.     tvLog.setText("⏸️ 计时器已停止");
  726.     console.log("计时器停止");
  727.     if (g_日志) g_日志.setText("已停止");
  728. });

  729. btnResetTimer.setOnClickListener(function() {
  730.     if (timerInterval) {
  731.         clearInterval(timerInterval);
  732.         timerInterval = null;
  733.     }
  734.     timerSeconds = 0;
  735.     tvTimer.setText("00:00:00");
  736.     tvLog.setText("🔄 计时器已重置");
  737.     console.log("计时器重置");
  738.     if (g_日志) g_日志.setText("已重置");
  739. });

  740. // 随机数生成功能
  741. btnRandom.setOnClickListener(function() {
  742.     var min = parseInt(etMin.getText().toString()) || 1;
  743.     var max = parseInt(etMax.getText().toString()) || 100;
  744.     if (min > max) {
  745.         var temp = min;
  746.         min = max;
  747.         max = temp;
  748.     }
  749.     var randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
  750.     tvRandom.setText("🎲 " + randomNum);
  751.     tvLog.setText("🎲 随机数: " + randomNum + " (" + min + "-" + max + ")");
  752.     console.log("随机数: " + randomNum);
  753.     if (g_日志) g_日志.setText("随机数: " + randomNum);
  754. });

  755. // 进度条功能
  756. var progressInterval = null;
  757. var currentProgress = 0;

  758. btnProgressStart.setOnClickListener(function() {
  759.     if (progressInterval) return;
  760.     progressInterval = setInterval(function() {
  761.         currentProgress += 1;
  762.         if (currentProgress > 100) {
  763.             currentProgress = 0;
  764.         }
  765.         // 在UI线程更新
  766.         ac.runOnUiThread(function() {
  767.             progressBar.setProgress(currentProgress);
  768.             tvProgress.setText("进度: " + currentProgress + "%");
  769.         });
  770.     }, 100);
  771.     tvLog.setText(" 进度条运行中...");
  772.     console.log("进度条启动");
  773.     if (g_日志) g_日志.setText("进度: " + currentProgress + "%");
  774. });

  775. btnProgressPause.setOnClickListener(function() {
  776.     if (progressInterval) {
  777.         clearInterval(progressInterval);
  778.         progressInterval = null;
  779.     }
  780.     tvLog.setText("⏸️ 进度条已暂停: " + currentProgress + "%");
  781.     console.log("进度条暂停");
  782.     if (g_日志) g_日志.setText("暂停");
  783. });

  784. // 开关控制功能
  785. switch1.setOnCheckedChangeListener(function(buttonView, isChecked) {
  786.     tvLog.setText("🔘 功能开关: " + (isChecked ? "开启" : "关闭"));
  787.     console.log("功能开关: " + (isChecked ? "开启" : "关闭"));
  788.     if (g_日志) g_日志.setText("功能: " + (isChecked ? "开" : "关"));
  789. });

  790. switch2.setOnCheckedChangeListener(function(buttonView, isChecked) {
  791.     tvLog.setText("🔔 通知开关: " + (isChecked ? "开启" : "关闭"));
  792.     console.log("通知开关: " + (isChecked ? "开启" : "关闭"));
  793.     if (g_日志) g_日志.setText("通知: " + (isChecked ? "开" : "关"));
  794. });

  795. btnSwitchStatus.setOnClickListener(function() {
  796.     var status = "功能: " + (switch1.isChecked() ? "开" : "关") + " | 通知: " + (switch2.isChecked() ? "开" : "关");
  797.     tvLog.setText("📊 " + status);
  798.     console.log(status);
  799.     if (g_日志) g_日志.setText(status);
  800. });

  801. // 列表视图功能(使用单个TextView显示列表)
  802. var listData = ["示例项1", "示例项2", "示例项3"];
  803. var listTextView = listView; // 现在是TextView
  804. var btnReadList = ac.findViewById("btnReadList"); // 读取列表按钮

  805. function refreshList() {
  806.     try {
  807.         // 在UI线程执行
  808.         ac.runOnUiThread(function() {
  809.             // 拼接所有列表项
  810.             var text = "";
  811.             for (var i = 0; i < listData.length; i++) {
  812.                 text += "  " + (i + 1) + ". " + listData[i] + "\n";
  813.             }
  814.             listTextView.setText(text);
  815.             console.log("列表刷新成功,共" + listData.length + "项");
  816.         });
  817.     } catch (e) {
  818.         console.log("列表刷新失败: " + e);
  819.     }
  820. }

  821. // 延迟初始化,确保在UI线程
  822. setTimeout(function() {
  823.     refreshList();
  824. }, 100);

  825. // 添加列表项按钮
  826. btnAddItem.setOnClickListener(function() {
  827.     var item = etListItem.getText().toString();
  828.     if (item) {
  829.         listData.push(item);
  830.         // 在UI线程刷新列表
  831.         refreshList();
  832.         etListItem.setText("");
  833.         tvLog.setText(" 已添加: " + item);
  834.         console.log("添加列表项: " + item);
  835.         if (g_日志) g_日志.setText("列表: " + listData.length + "项");
  836.     }
  837. });

  838. // 读取列表按钮 - 读取并显示列表内容
  839. btnReadList.setOnClickListener(function() {
  840.     try {
  841.         // 读取列表数据
  842.         if (listData.length === 0) {
  843.             tvLog.setText(" 列表为空");
  844.             console.log("列表为空");
  845.             if (g_日志) g_日志.setText("列表: 空");
  846.             return;
  847.         }
  848.         
  849.         // 构建读取结果
  850.         var result = "📋 读取列表 (" + listData.length + "项):\n";
  851.         for (var i = 0; i < listData.length; i++) {
  852.             result += (i + 1) + ". " + listData[i] + "\n";
  853.         }
  854.         
  855.         // 显示读取结果
  856.         tvLog.setText(result);
  857.         console.log("读取列表成功,共" + listData.length + "项");
  858.         if (g_日志) g_日志.setText("读取: " + listData.length + "项");
  859.         
  860.         // 也可以获取单个项(示例:获取第一项)
  861.         if (listData.length > 0) {
  862.             var firstItem = listData[0];
  863.             console.log("第一项: " + firstItem);
  864.         }
  865.     } catch (e) {
  866.         tvLog.setText(" 读取列表失败: " + e);
  867.         console.log("读取列表失败: " + e);
  868.     }
  869. });

  870. // 对话框功能(使用纯文本提示,完全不使用AlertDialog)
  871. btnDialog1.setOnClickListener(function() {
  872.     // 确认框:用界面文本框显示确认消息
  873.     tvLog.setText("✅ 确认框演示\n操作已确认!\n在AIWROK中,使用文本框代替对话框更安全");
  874.     console.log("用户点击确认框");
  875.     if (g_日志) g_日志.setText("确认框");
  876.     // 同时使用Toast提示(如果有的话)
  877.     try {
  878.         toast("操作已确认!");
  879.     } catch (e) {
  880.         // Toast可能也不可用,忽略
  881.     }
  882. });

  883. btnDialog2.setOnClickListener(function() {
  884.     // 输入框:使用界面已有的输入框
  885.     tvLog.setText("📝 输入框演示\n请在顶部“用户名”输入框中输入内容\n然后点击“保存配置”按钮");
  886.     console.log("用户点击输入框");
  887.     if (g_日志) g_日志.setText("输入框");
  888.     // 焦点移到输入框
  889.     try {
  890.         etUser.requestFocus();
  891.     } catch (e) {
  892.         // 忽略焦点设置错误
  893.     }
  894. });

  895. // 日期时间选择器功能(使用界面文本框替代对话框)
  896. btnDatePicker.setOnClickListener(function() {
  897.     // 直接显示当前日期
  898.     var now = new java.util.Date();
  899.     var dateStr = new java.text.SimpleDateFormat("yyyy-MM-dd").format(now);
  900.     tvDateTime.setText("📅 日期: " + dateStr);
  901.     tvLog.setText(" 当前日期: " + dateStr);
  902.     console.log("显示日期: " + dateStr);
  903.     if (g_日志) g_日志.setText("日期: " + dateStr);
  904. });

  905. btnTimePicker.setOnClickListener(function() {
  906.     // 直接显示当前时间
  907.     var now = new java.util.Date();
  908.     var hours = now.getHours();
  909.     var minutes = now.getMinutes();
  910.     var timeStr = hours + ":" + (minutes < 10 ? "0" + minutes : minutes);
  911.     tvDateTime.setText("⏰ 时间: " + timeStr);
  912.     tvLog.setText("⏰ 当前时间: " + timeStr);
  913.     console.log("显示时间: " + timeStr);
  914.     if (g_日志) g_日志.setText("时间: " + timeStr);
  915. });

  916. // 下拉选择功能(使用列表对话框显示所有选项)
  917. var spinnerData = ["选项A", "选项B", "选项C", "选项D", "选项E"];
  918. var selectedSpinnerIndex = 0;

  919. spinner.setOnClickListener(function() {
  920.     try {
  921.         // 构建选项列表字符串
  922.         var optionsText = "";
  923.         for (var i = 0; i < spinnerData.length; i++) {
  924.             optionsText += (i + 1) + ". " + spinnerData[i] + "\n";
  925.         }
  926.         
  927.         // 在日志区域显示所有选项
  928.         tvLog.setText("📋 选项列表:\n" + optionsText);
  929.         console.log("显示选项列表");
  930.         
  931.         // 提示当前选中项
  932.         tvSpinner.setText(" 已选择: " + spinnerData[selectedSpinnerIndex] + " (点击切换)");
  933.         
  934.         // 循环切换到下一个选项
  935.         selectedSpinnerIndex = (selectedSpinnerIndex + 1) % spinnerData.length;
  936.         var selected = spinnerData[selectedSpinnerIndex];
  937.         spinner.setText(" " + selected);
  938.         
  939.         // 更新日志
  940.         tvLog.setText("✅ 已选择: " + selected);
  941.         console.log("下拉选择: " + selected);
  942.         if (g_日志) g_日志.setText("选择: " + selected);
  943.     } catch (e) {
  944.         tvLog.setText(" 选择失败: " + e);
  945.         console.log("下拉选择失败: " + e);
  946.     }
  947. });

  948. // 评分条功能
  949. ratingBar.setOnRatingBarChangeListener(function(ratingBar, rating, fromUser) {
  950.     tvRating.setText("⭐ 评分: " + rating);
  951.     tvLog.setText("⭐ 评分: " + rating + "星");
  952.     console.log("评分: " + rating);
  953.     if (g_日志) g_日志.setText("评分: " + rating);
  954. });

  955. // 读取评分按钮 - 主动读取当前评分值
  956. btnReadRating.setOnClickListener(function() {
  957.     try {
  958.         // 使用getRating()方法读取当前评分
  959.         var currentRating = ratingBar.getRating();
  960.         var result = "⭐ 读取评分: " + currentRating + "星\n";
  961.         result += "总星数: 5星\n";
  962.         result += "步长: 0.5星\n";
  963.         result += "百分比: " + (currentRating / 5 * 100).toFixed(1) + "%";
  964.         
  965.         tvLog.setText(result);
  966.         console.log("读取评分: " + currentRating);
  967.         if (g_日志) g_日志.setText("评分: " + currentRating);
  968.     } catch (e) {
  969.         tvLog.setText(" 读取评分失败: " + e);
  970.         console.log("读取评分失败: " + e);
  971.     }
  972. });

  973. // 拖动条功能
  974. seekBar.setOnSeekBarChangeListener({
  975.     onProgressChanged: function(seekBar, progress, fromUser) {
  976.         tvSeekBar.setText(" 值: " + progress);
  977.         if (g_日志) g_日志.setText("拖动: " + progress);
  978.     },
  979.     onStartTrackingTouch: function(seekBar) {},
  980.     onStopTrackingTouch: function(seekBar) {
  981.         var value = seekBar.getProgress();
  982.         tvLog.setText("📊 拖动条拖: " + value);
  983.         console.log("拖动条拖: " + value);
  984.     }
  985. });

  986. // 读取拖动条按钮 - 主动读取当前拖动条值
  987. btnReadSeekBar.setOnClickListener(function() {
  988.     try {
  989.         // 使用getProgress()方法读取当前值
  990.         var currentValue = seekBar.getProgress();
  991.         var maxValue = seekBar.getMax();
  992.         var result = "📊 读取拖动条值: " + currentValue + "\n";
  993.         result += "最大值: " + maxValue + "\n";
  994.         result += "百分比: " + (currentValue / maxValue * 100).toFixed(1) + "%";
  995.         
  996.         tvLog.setText(result);
  997.         console.log("读取拖动条值: " + currentValue);
  998.         if (g_日志) g_日志.setText("拖动: " + currentValue);
  999.     } catch (e) {
  1000.         tvLog.setText(" 读取拖动条失败: " + e);
  1001.         console.log("读取拖动条失败: " + e);
  1002.     }
  1003. });

  1004. // 运行主脚本按钮(简化版,直接执行)
  1005. var isRunning = false;

  1006. btnRunMain.setOnClickListener(function() {
  1007.     if (isRunning) {
  1008.         tvLog.setText(" 脚本正在运行中,请稍候...");
  1009.         return;
  1010.     }
  1011.    
  1012.     // 更新UI状态
  1013.     isRunning = true;
  1014.     tvRunStatus.setText("状态: 运行中...");
  1015.     tvRunStatus.setTextColor(android.graphics.Color.parseColor("#4CAF50"));
  1016.     btnRunMain.setText("⏳ 运行中...");
  1017.     tvLog.setText("▶ 开始运行主脚本...");
  1018.     console.log("开始运行主脚本");
  1019.     if (g_日志) g_日志.setText("运行主脚本");
  1020.    
  1021.     try {
  1022.         // 直接导入并运行主脚本
  1023.         Import("主脚本.js");
  1024.         
  1025.         // 运行完成后更新状态
  1026.         tvRunStatus.setText("状态: 运行完成");
  1027.         tvRunStatus.setTextColor(android.graphics.Color.parseColor("#2196F3"));
  1028.         btnRunMain.setText("▶ 重新运行");
  1029.         isRunning = false;
  1030.         
  1031.         tvLog.setText("✅ 主脚本运行完成");
  1032.         console.log("主脚本运行完成");
  1033.         if (g_日志) g_日志.setText("完成");
  1034.     } catch (e) {
  1035.         tvRunStatus.setText("状态: 运行失败");
  1036.         tvRunStatus.setTextColor(android.graphics.Color.parseColor("#F44336"));
  1037.         btnRunMain.setText("▶ 重新运行");
  1038.         isRunning = false;
  1039.         
  1040.         tvLog.setText(" 运行失败: " + e);
  1041.         console.log("运行失败: " + e);
  1042.         if (g_日志) g_日志.setText("失败");
  1043.     }
  1044. });

  1045. console.log("✅ UI演示系统已启动");
复制代码


举报 回复