|
|
°²×¿½Å±¾ÃëÍÂ˾¿ìËÙÏÔʾºÍ¹Ø±ÕµÄUIÌáʾ´°¿Ú
- /**
- * ============================================
- * ƽ̨: Android (AIWROK)
- * 🍎½»Á÷QQȺ£º711841924£¨Èº£©
- *🍎½»Á÷QQȺ£º528816639 £¨°²×¿ÄÚ²âȺ£©
- * ============================================
- */
- // µ¼Èë°ü
- importClass(Packages.android.os.Handler);
- importClass(Packages.android.os.Looper);
- /**
- * ÃëÍÂ˾ - ¿ìËÙÏÔʾºÍ¹Ø±ÕµÄUIÌáʾ´°¿Ú£¨Ê¹ÓÃfloatUI£¬×îÉϲãÏÔʾ£©
- * @param {string} message - ÌáʾÐÅÏ¢
- * @param {number} duration - ÏÔʾʱ³¤£¨ºÁÃ룩£¬Ä¬ÈÏ3000ms
- */
- function showQuickToast(message, duration) {
- duration = duration || 3000;
-
- try {
- // ´´½¨ floatUI ʵÀý
- var fui = new floatUI();
-
- // ¼ÓÔØ¼òµ¥µÄÎı¾²¼¾Ö£¨ºìÉ«´ó×Ö£¬À¶É«±³¾°£©
- fui.loadXML(
- '<TextView xmlns:android="http://schemas.android.com/apk/res/android" ' +
- 'android:id="toastText" ' +
- 'android:layout_width="wrap_content" ' +
- 'android:layout_height="wrap_content" ' +
- 'android:text="' + message + '" ' +
- 'android:textColor="#FF0000" ' +
- 'android:textSize="20sp" ' +
- 'android:textStyle="bold" ' +
- 'android:background="#EE4A90E2" ' +
- 'android:padding="20dp" ' +
- 'android:gravity="center" />'
- );
-
- // »ñÈ¡ÆÁÄ»³ß´ç
- var screenWidth = screen.getScreenWidth();
- var screenHeight = screen.getScreenHeight();
-
- // ÉèÖÃλÖã¨ÆÁÄ»ÉÏ·½¾ÓÖУ©
- setTimeout(function() {
- fui.setPosition((screenWidth - 300) / 2, screenHeight / 3);
-
- // ÉèÖÃΪ×îÉϲ㴰¿ÚÀàÐÍ
- try {
- var window = fui.getWindow();
- if (window) {
- var params = window.getAttributes();
- // TYPE_APPLICATION_OVERLAY - Android 8.0+
- // TYPE_SYSTEM_ALERT - Android 8.0ÒÔÏÂ
- params.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
- // »òÕßʹÓøü¸ßµÄ²ã¼¶
- // params.type = 2038; // TYPE_APPLICATION_OVERLAY µÄÖµ
- window.setAttributes(params);
- }
- } catch (e) {
- // Èç¹ûÉèÖÃʧ°Ü£¬ºöÂÔ´íÎó
- }
- }, 50);
-
- // ×Ô¶¯¹Ø±Õ
- setTimeout(function() {
- try {
- fui.close();
- } catch (e) {
- // ºöÂԹرմíÎó
- }
- }, duration);
-
- } catch (e) {
- printl("❌ ÃëÍÂ˾ÏÔʾʧ°Ü: " + e.message);
- // ½µ¼¶·½°¸£ºÖ±½Ó´òÓ¡
- printl("[Ìáʾ] " + message);
- }
- }
- /**
- * ÔÚÖ¸¶¨Î»ÖÃÏÔʾÃëÍÂ˾£¨×îÉϲ㸡¶¯´°£©
- * @param {string} message - ÌáʾÐÅÏ¢
- * @param {string} position - λÖãº'top'(ÉÏ), 'bottom'(ÏÂ), 'left'(×ó), 'right'(ÓÒ)
- * @param {number} duration - ÏÔʾʱ³¤£¨ºÁÃ룩
- */
- function showQuickToastAt(message, position, duration) {
- duration = duration || 3000;
-
- try {
- var fui = new floatUI();
-
- fui.loadXML(
- '<TextView xmlns:android="http://schemas.android.com/apk/res/android" ' +
- 'android:id="toastText" ' +
- 'android:layout_width="wrap_content" ' +
- 'android:layout_height="wrap_content" ' +
- 'android:text="' + message + '" ' +
- 'android:textColor="#FF0000" ' +
- 'android:textSize="20sp" ' +
- 'android:textStyle="bold" ' +
- 'android:background="#EE4A90E2" ' +
- 'android:padding="20dp" ' +
- 'android:gravity="center" />'
- );
-
- var screenWidth = screen.getScreenWidth();
- var screenHeight = screen.getScreenHeight();
- var x, y;
-
- // ¸ù¾ÝλÖÃÉèÖÃ×ø±ê
- switch(position) {
- case 'top':
- x = (screenWidth - 300) / 2;
- y = screenHeight / 4;
- break;
- case 'bottom':
- x = (screenWidth - 300) / 2;
- y = screenHeight * 3 / 4;
- break;
- case 'left':
- x = screenWidth / 4;
- y = (screenHeight - 100) / 2;
- break;
- case 'right':
- x = screenWidth * 3 / 4;
- y = (screenHeight - 100) / 2;
- break;
- default:
- x = (screenWidth - 300) / 2;
- y = screenHeight / 3;
- }
-
- setTimeout(function() {
- fui.setPosition(x, y);
-
- // ÉèÖÃΪ×îÉϲ㴰¿ÚÀàÐÍ
- try {
- var window = fui.getWindow();
- if (window) {
- var params = window.getAttributes();
- params.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
- window.setAttributes(params);
- }
- } catch (e) {
- // Èç¹ûÉèÖÃʧ°Ü£¬ºöÂÔ´íÎó
- }
- }, 50);
-
- setTimeout(function() {
- try {
- fui.close();
- } catch (e) {
- // ºöÂԹرմíÎó
- }
- }, duration);
-
- } catch (e) {
- printl("❌ ÃëÍÂ˾ÏÔʾʧ°Ü: " + e.message);
- printl("[Ìáʾ] " + message);
- }
- }
- /**
- * ²âÊÔÃëÍÂ˾¹¦ÄÜ
- */
- function testQuickToast() {
- printl("=== ²âÊÔÃëÍÂ˾¹¦ÄÜ ===");
-
- // ²âÊÔ1£º»ù±¾ÏÔʾ
- showQuickToast("ÕâÊÇÃëÍÂ˾ÏûÏ¢");
- sleep.millisecond(1200);
-
- // ²âÊÔ2£º¶Ìʱ¼äÏÔʾ
- showQuickToast("¶ÌÏûÏ¢", 600);
- sleep.millisecond(1000);
-
- // ²âÊÔ3£ºÁ¬ÐøÏÔʾ
- showQuickToast("µÚÒ»Ìõ");
- sleep.millisecond(300);
- showQuickToast("µÚ¶þÌõ¸²¸ÇµÚÒ»Ìõ");
- sleep.millisecond(1200);
-
- printl("=== ²âÊÔÍê³É ===");
- }
- /**
- * Ö÷º¯Êý - ²âÊÔÃëÍÂ˾¹¦ÄÜ
- */
- function main() {
- printl("=== ÃëÍÂ˾¹¦ÄÜÑÝʾ ===");
-
- var message = "¼¼Êõ½»Á÷QQȺ711841924Ⱥһ£¬Æ»¹ûÄÚ²âȺ£¬528816639";
-
- // ÑÝʾ1£ºÉÏ·½ÏÔʾ£¨3Ã룩
- printl("1. ÉÏ·½ÏÔʾ");
- showQuickToastAt(message, 'top', 3000);
- sleep.millisecond(3500);
-
- // ÑÝʾ2£ºÏ·½ÏÔʾ£¨3Ã룩
- printl("2. Ï·½ÏÔʾ");
- showQuickToastAt(message, 'bottom', 3000);
- sleep.millisecond(3500);
-
- // ÑÝʾ3£º×ó²àÏÔʾ£¨3Ã룩
- printl("3. ×ó²àÏÔʾ");
- showQuickToastAt(message, 'left', 3000);
- sleep.millisecond(3500);
-
- // ÑÝʾ4£ºÓÒ²àÏÔʾ£¨3Ã룩
- printl("4. ÓÒ²àÏÔʾ");
- showQuickToastAt(message, 'right', 3000);
- sleep.millisecond(3500);
-
- printl("=== ÑÝʾÍê³É ===");
- printl("\nʹÓ÷½·¨£º");
- printl(" showQuickToast('ÏûÏ¢'); // ĬÈÏ3Ã룬ÉÏ·½ÏÔʾ");
- printl(" showQuickToastAt('ÏûÏ¢', 'top', 3000); // ÉÏ·½ÏÔʾ");
- printl(" showQuickToastAt('ÏûÏ¢', 'bottom', 3000); // Ï·½ÏÔʾ");
- printl(" showQuickToastAt('ÏûÏ¢', 'left', 3000); // ×ó²àÏÔʾ");
- printl(" showQuickToastAt('ÏûÏ¢', 'right', 3000); // ÓÒ²àÏÔʾ");
- }
- // Ö´ÐÐÖ÷º¯Êý
- main();
¸´ÖÆ´úÂë
|
|