|
AIWROKÈí¼þÖ§³ÖÐü¸¡´°×ÔÓɶ¨Î»ºÍÍÏ×§¹¦ÄÜ
- //ͨ¹ýfloatUI´´½¨Ðü¸¡´°
- //ÊÊÓÃÓÚES5ϵͳ°²×¿ JavaScriptÒýÇæRhino
- //»ùÓÚAIWROKÈí¼þ°²×¿¿ª·¢¿ò¼Ü
- //Ö§³ÖÐü¸¡´°×ÔÓɶ¨Î»ºÍÍÏ×§¹¦ÄÜ
- //🍎½»Á÷QQȺ711841924Ⱥһ£¬Æ»¹ûÄÚ²âȺ£¬528816639
- if (!String.prototype.repeat) {
- String.prototype.repeat = function(count) {
- 'use strict';
- if (this == null) {
- throw new TypeError('can\'t convert ' + this + ' to object');
- }
- var str = String(this);
- count = +count;
- if (count != count) {
- count = 0;
- }
- if (count < 0) {
- throw new RangeError('repeat count must be non-negative');
- }
- if (count == Infinity) {
- throw new RangeError('repeat count must be less than infinity');
- }
- count = Math.floor(count);
- if (str.length == 0 || count == 0) {
- return '';
- }
- // È·±£Öظ´µÄ×Ö·û´®²»»á³¬³ö×Ö·û´®³¤¶ÈÏÞÖÆ
- if (str.length * count >= 1 << 28) {
- throw new RangeError('repeat count must not overflow maximum string size');
- }
- var rpt = '';
- for (var i = 0; i < count; i++) {
- rpt += str;
- }
- return rpt;
- };
- }
- // ES5¼æÈݵÄString.prototype.padStart polyfill
- if (!String.prototype.padStart) {
- String.prototype.padStart = function(targetLength, padString) {
- targetLength = targetLength >> 0; // ת»»ÎªÕûÊý
- padString = String((typeof padString !== 'undefined' ? padString : ' '));
- if (this.length > targetLength) {
- return String(this);
- } else {
- targetLength = targetLength - this.length;
- if (targetLength > padString.length) {
- padString += padString.repeat(targetLength / padString.length); // ½Ø¶Ï»òÖØ¸´Ìî³ä×Ö·û´®
- }
- return padString.slice(0, targetLength) + String(this);
- }
- };
- }
- /*
- °²×¿¿ÉÒÆ¶¯²àÀ¸ÈÕÖ¾ÍÂ˾
- ¹¦ÄÜ£º
- 1. ¿ÉÍÏ×§ÒÆ¶¯µÄ²àÀ¸Ðü¸¡´°
- 2. Ö§³ÖÈÕÖ¾ÐÅϢʵʱÏÔʾ
- 3. Ö§³ÖÕ¹¿ª/ÊÕÆð¹¦ÄÜ
- 4. Ö§³Ö×Ô¶¨ÒåÈÕÖ¾ÑÕÉ«
- */
- // ¶¨Òå²àÀ¸ÈÕÖ¾Ðü¸¡´°¹¹Ô캯Êý
- function ²àÀ¸ÈÕÖ¾() {
- this.screenHeight = 1920; // ĬÈÏÆÁÄ»¸ß¶È
- this.screenWidth = 1080; // ĬÈÏÆÁÄ»¿í¶È
- this.isExpanded = false; // Õ¹¿ª×´Ì¬±êÖ¾
- this.logs = []; // ÈÕÖ¾Êý×é
- this.maxLogs = 50; // ×î´óÈÕÖ¾ÌõÊý
- this.dragging = false; // ÍÏק״̬±êÖ¾
- this.lastX = 0; // Éϴδ¥ÃþX×ø±ê
- this.lastY = 0; // Éϴδ¥ÃþY×ø±ê
- }
- // ´´½¨²àÀ¸ÈÕÖ¾Ðü¸¡´°
- ²àÀ¸ÈÕÖ¾.prototype.create = function() {
- try {
- // ¼ì²éfloatUIÊÇ·ñ¿ÉÓÃ
- if (typeof floatUI === 'undefined') {
- printl("❌ ´íÎó£ºÎ´ÕÒµ½floatUI¿â");
- return false;
- }
-
- // ´´½¨floatUIʵÀý
- var fui = new floatUI();
-
- // »ñȡʵ¼ÊÆÁÄ»³ß´ç
- try {
- if (context && context.getResources && context.getResources().getDisplayMetrics) {
- var metrics = context.getResources().getDisplayMetrics();
- this.screenHeight = metrics.heightPixels || 1920;
- this.screenWidth = metrics.widthPixels || 1080;
- printl("✅ »ñÈ¡ÆÁÄ»³ß´ç: " + this.screenWidth + "x" + this.screenHeight);
- } else {
- printl("⚠️ ÎÞ·¨»ñÈ¡ÆÁÄ»³ß´ç£¬Ê¹ÓÃĬÈÏÖµ");
- this.screenHeight = 1920; // ĬÈÏÆÁÄ»¸ß¶È
- this.screenWidth = 1080; // ĬÈÏÆÁÄ»¿í¶È
- }
- } catch(e) {
- printl("⚠️ »ñÈ¡ÆÁÄ»³ß´çʧ°Ü£¬Ê¹ÓÃĬÈÏÖµ: " + e);
- this.screenHeight = 1920;
- this.screenWidth = 1080;
- }
-
- // ¶¨Òå²à±ßÀ¸¿í¶ÈºÍ¸ß¶È
- var sidebarWidth = 100; // ¸üյIJà±ßÀ¸¿í¶È
- var sidebarMinWidth = 30; // ¸üÕµÄÊÕÆðʱ×îС¿í¶È
- var sidebarHeight = 100; // ¹Ì¶¨Ð¡¸ß¶È£¬²»ÔÙÒÀÀµÆÁÄ»±ÈÀý
-
- // ¼ÓÔØXML²¼¾Ö
- try {
- fui.loadXML(`
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="${sidebarWidth}dp"
- android:layout_height="${sidebarHeight}dp"
- android:background="#CC000000"
- android:orientation="vertical"
- android:id="main_container">
-
- <!-- ¿ÉÍ϶¯µÄ±êÌâÀ¸ -->
- <LinearLayout
- android:id="title_bar"
- android:layout_width="match_parent"
- android:layout_height="35dp"
- android:background="#666666"
- android:orientation="horizontal"
- android:gravity="center_vertical">
-
- <!-- Í϶¯ÇøÓò -->
- <View
- android:layout_width="${sidebarMinWidth}dp"
- android:layout_height="match_parent"
- android:background="#444444"/>
-
- <!-- ±êÌâÎÄ×Ö£¨½öÔÚÕ¹¿ªÊ±¿É¼û£© -->
- <TextView
- android:id="title_text"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:text="ÔËÐÐÈÕÖ¾"
- android:textColor="#FFFFFF"
- android:gravity="center"
- android:textSize="14sp"/>
-
- <!-- ¹Ø±Õ°´Å¥£¨½öÔÚÕ¹¿ªÊ±¿É¼û£© -->
- <Button
- android:id="close_button"
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:text="✕"
- android:textColor="#FFFFFF"
- android:background="#FF4444"
- android:textSize="14sp"
- android:padding="0dp"
- android:gravity="center"/>
- </LinearLayout>
-
- <!-- ÈÕÖ¾ÏÔÊ¾ÇøÓò£¨½öÔÚÕ¹¿ªÊ±¿É¼û£© -->
- <ScrollView
- android:id="log_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#111111">
-
- <TextView
- android:id="log_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textColor="#00FF00"
- android:textSize="11sp"
- android:padding="3dp"
- android:lineSpacingExtra="1dp"/>
- </ScrollView>
-
- <!-- Õ¹¿ª/ÊÕÆð°´Å¥ -->
- <Button
- android:id="toggle_button"
- android:layout_width="match_parent"
- android:layout_height="25dp"
- android:text="¡Ô"
- android:textColor="#FFFFFF"
- android:background="#555555"
- android:textSize="16sp"/>
- </LinearLayout>
- `);
- printl("✅ XML²¼¾Ö¼ÓÔØ³É¹¦");
- } catch (xmlError) {
- printl("❌ XML²¼¾Ö¼ÓÔØÊ§°Ü: " + xmlError);
- return false;
- }
-
- // ±£´æUIʵÀý
- this.ui = fui;
-
- // ±£´æ¿í¶ÈÉèÖù©toggleExpand·½·¨Ê¹ÓÃ
- this.sidebarWidth = sidebarWidth;
- this.sidebarMinWidth = sidebarMinWidth;
-
- // »ñÈ¡UIÔªËØ
- try {
- this.titleBar = fui.findViewById("title_bar");
- this.titleText = fui.findViewById("title_text");
- this.logContainer = fui.findViewById("log_container");
- this.logText = fui.findViewById("log_text");
- this.toggleButton = fui.findViewById("toggle_button");
- this.closeButton = fui.findViewById("close_button"); // »ñÈ¡¹Ø±Õ°´Å¥
- this.mainContainer = fui.findViewById("main_container");
-
- // ¼ì²é¹Ø¼üÔªËØÊÇ·ñ´æÔÚ
- var missingElements = [];
- if (!this.titleBar) missingElements.push("titleBar");
- if (!this.logText) missingElements.push("logText");
- if (!this.toggleButton) missingElements.push("toggleButton");
- if (!this.mainContainer) missingElements.push("mainContainer");
-
- if (missingElements.length > 0) {
- printl("⚠️ ȱʧ¹Ø¼üUIÔªËØ: " + missingElements.join(", "));
- } else {
- printl("✅ ËùÓÐUIÔªËØ»ñÈ¡³É¹¦");
- }
- } catch (findError) {
- printl("❌ »ñÈ¡UIÔªËØÊ§°Ü: " + findError);
- }
-
- // ÉèÖóõʼλÖã¨ÆÁÄ»×ó²à£©
- try {
- this.setPos(0, (this.screenHeight - 100) / 2);
- printl("✅ ³õʼλÖÃÉèÖóɹ¦");
- } catch (posError) {
- printl("❌ ÉèÖóõʼλÖÃʧ°Ü: " + posError);
- }
-
- // ³õʼ»¯Ê¼þ
- try {
- this.initEvents();
- printl("✅ ʼþ³õʼ»¯³É¹¦");
- } catch (eventError) {
- printl("❌ ʼþ³õʼ»¯Ê§°Ü: " + eventError);
- }
-
- // ÏÔʾ³õʼ»¯ÈÕÖ¾
- this.log("✅ ²àÀ¸ÈÕÖ¾ÒÑÆô¶¯", "#00FF00");
-
- return true;
- } catch (e) {
- printl("❌ ´´½¨²àÀ¸ÈÕ־ʧ°Ü: " + e);
- return false;
- }
- };
- // ³õʼ»¯Ê¼þ
- ²àÀ¸ÈÕÖ¾.prototype.initEvents = function() {
- var self = this;
-
- // ÉèÖÃÍÏקʼþ - Ìí¼Ó¸üÍêÉÆµÄ´íÎó´¦Àí
- try {
- if (typeof View !== 'undefined' && typeof MotionEvent !== 'undefined' && this.titleBar && this.titleBar.setOnTouchListener) {
- this.titleBar.setOnTouchListener(new View.OnTouchListener({
- onTouch: function(view, event) {
- try {
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- self.dragging = true;
- self.lastX = event.getRawX();
- self.lastY = event.getRawY();
- break;
- case MotionEvent.ACTION_MOVE:
- if (self.dragging) {
- var dx = event.getRawX() - self.lastX;
- var dy = event.getRawY() - self.lastY;
-
- // »ñÈ¡µ±Ç°Î»ÖÃ
- var currentX = view.getX();
- var currentY = view.getY();
-
- // ¼ÆËãÐÂλÖ㨿¼ÂÇÕû¸öÈÝÆ÷µÄλÖã©
- var newX = currentX + dx;
- var newY = currentY + dy;
-
- // ±ß½ç¼ì²é
- if (newX < 0) newX = 0;
- if (newY < 0) newY = 0;
- if (newX > self.screenWidth - (self.isExpanded ? self.sidebarWidth : self.sidebarMinWidth))
- newX = self.screenWidth - (self.isExpanded ? self.sidebarWidth : self.sidebarMinWidth);
- if (newY > self.screenHeight - 100)
- newY = self.screenHeight - 100;
-
- // ÉèÖÃÐÂλÖÃ
- self.setPos(newX, newY);
-
- // ¸üÐÂÉϴδ¥ÃþλÖÃ
- self.lastX = event.getRawX();
- self.lastY = event.getRawY();
- }
- break;
- case MotionEvent.ACTION_UP:
- self.dragging = false;
- break;
- }
- return true;
- } catch (touchError) {
- // ¾²Ä¬´¦Àí´¥Ãþʼþ´íÎ󣬱ÜÃâ±ÀÀ£
- return false;
- }
- }
- }));
- } else {
- printl("⚠️ ÎÞ·¨ÉèÖÃÍÏקʼþ£¬È±ÉÙ±ØÒª×é¼þ");
- }
- } catch (touchSetupError) {
- printl("❌ ÉèÖÃÍÏקʼþʧ°Ü: " + touchSetupError);
- }
-
- // Õ¹¿ª/ÊÕÆð°´Å¥µã»÷ʼþ
- try {
- if (this.toggleButton && this.toggleButton.setOnClickListener) {
- this.toggleButton.setOnClickListener(function() {
- try {
- self.toggleExpand();
- } catch (toggleError) {
- printl("❌ Ö´ÐÐÕ¹¿ª/ÊÕÆð²Ù×÷ʧ°Ü: " + toggleError);
- }
- });
- }
- } catch (toggleSetupError) {
- printl("❌ ÉèÖÃÕ¹¿ª/ÊÕÆðʼþʧ°Ü: " + toggleSetupError);
- }
-
- // ¹Ø±Õ°´Å¥µã»÷ʼþ
- try {
- if (this.closeButton && this.closeButton.setOnClickListener) {
- this.closeButton.setOnClickListener(function() {
- try {
- self.close();
- } catch (closeError) {
- printl("❌ Ö´ÐйرղÙ×÷ʧ°Ü: " + closeError);
- }
- });
- }
- } catch (closeSetupError) {
- printl("❌ ÉèÖùرÕʼþʧ°Ü: " + closeSetupError);
- }
- };
- // »ñÈ¡µ±Ç°Ê±¼äÓÃÓÚÈÕÖ¾
- ²àÀ¸ÈÕÖ¾.prototype.getCurrentTime = function() {
- var now = new Date();
- var hours = now.getHours().toString().padStart(2, '0');
- var minutes = now.getMinutes().toString().padStart(2, '0');
- var seconds = now.getSeconds().toString().padStart(2, '0');
- return hours + ':' + minutes + ':' + seconds;
- };
- // Çл»Õ¹¿ª/ÊÕÆð״̬
- ²àÀ¸ÈÕÖ¾.prototype.toggleExpand = function() {
- try {
- var self = this;
-
- // ¼Ç¼µ±Ç°×´Ì¬±ä¸ü£¨Ê¹ÓÃprintl±ÜÃâµÝ¹é£©
- printl("[" + self.getCurrentTime() + "] " + (self.isExpanded ? "🔽 ²àÀ¸ÕýÔÚÊÕÆð" : "🔼 ²àÀ¸ÕýÔÚÕ¹¿ª"));
- // ¶¨ÒåÒªÉèÖõÄÄ¿±ê¿í¶È - ÐÞ¸´Âß¼£ºµ±Ç°Õ¹¿ªÊ±Ó¦¸ÃÉèÖÃΪÊÕÆð¿í¶È£¬µ±Ç°ÊÕÆðʱӦ¸ÃÉèÖÃΪչ¿ª¿í¶È
- var targetWidth = this.isExpanded ? this.sidebarMinWidth : this.sidebarWidth;
-
- // Çл»Õ¹¿ª×´Ì¬±êÖ¾
- this.isExpanded = !this.isExpanded;
-
- // È·±£ÔÚÖ÷Ïß³ÌÖÐÖ´ÐÐUI²Ù×÷
- var uiOperation = function() {
- self.performToggleExpand(targetWidth);
- };
-
- // ³¢ÊÔ¶àÖÖUIÏ̵߳÷¶È·½°¸
- var threadScheduled = false;
-
- // ·½°¸1: ʹÓÃcontext.runOnUiThread
- try {
- if (context && context.runOnUiThread) {
- // ʹÓÃES5¼æÈݵķ½Ê½´´½¨Runnable¶ÔÏó
- var runnable = {
- run: function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ UIÏß³ÌÖ´ÐÐʧ°Ü: " + e);
- }
- }
- };
- context.runOnUiThread(runnable);
- threadScheduled = true;
- printl("✅ ʹÓÃcontext.runOnUiThreadµ÷¶ÈUIÏß³Ì");
- }
- } catch (e) {
- printl("❌ ·½°¸1: context.runOnUiThreadʧ°Ü: " + e);
- }
-
- // ·½°¸2: ʹÓÃView.post (Èç¹ûÓÐÈκÎView¶ÔÏó¿ÉÓÃ)
- if (!threadScheduled) {
- try {
- var viewToUse = self.mainContainer || self.titleBar || self.toggleButton;
- if (viewToUse && viewToUse.post) {
- viewToUse.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ View.postÖ´ÐÐʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- printl("✅ ʹÓÃView.postµ÷¶ÈUIÏß³Ì");
- }
- } catch (e) {
- printl("❌ ·½°¸2: View.postʧ°Ü: " + e);
- }
- }
-
- // ·½°¸3: ³¢ÊÔʹÓÃHandler (Èç¹û¿ÉÓÃ)
- if (!threadScheduled) {
- try {
- if (typeof Handler !== 'undefined' && typeof Looper !== 'undefined' && Looper.getMainLooper) {
- var handler = new Handler(Looper.getMainLooper());
- handler.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ HandlerÖ´ÐÐʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- printl("✅ ʹÓÃHandlerµ÷¶ÈUIÏß³Ì");
- }
- } catch (e) {
- printl("❌ ·½°¸3: Handlerʧ°Ü: " + e);
- }
- }
-
- // ·½°¸4: Ö±½ÓÖ´ÐÐ×÷Ϊ×îºó±¸Ñ¡ (¿ÉÄÜ»áʧ°Üµ«Ìṩ½µ¼¶·½°¸)
- if (!threadScheduled) {
- printl("⚠️ ËùÓÐÏ̵߳÷¶È·½°¸Ê§°Ü£¬³¢ÊÔÖ±½ÓÖ´ÐÐUI²Ù×÷");
- try {
- uiOperation();
- } catch (directError) {
- printl("❌ Ö±½ÓÖ´ÐÐUI²Ù×÷ʧ°Ü: " + directError);
- }
- }
- } catch (e) {
- printl("❌ Çл»Õ¹¿ª×´Ì¬Ê§°Ü: " + e);
- }
- };
- // Ö´ÐÐUI²Ù×÷µÄºËÐÄ·½·¨£¨Ó¦ÔÚÖ÷Ïß³ÌÖе÷Óã©
- ²àÀ¸ÈÕÖ¾.prototype.performToggleExpand = function(targetWidth) {
- try {
- var self = this;
-
- // Çл»UIÔªËØ¿É¼ûÐÔ
- if (!this.isExpanded) {
- // ÊÕÆð״̬
- if (this.titleText && typeof this.titleText.setVisibility === 'function') {
- try {
- this.titleText.setVisibility(View.GONE);
- } catch (e) {
- printl("❌ ÉèÖÃtitleText¿É¼ûÐÔʧ°Ü: " + e);
- }
- }
- if (this.logContainer && typeof this.logContainer.setVisibility === 'function') {
- try {
- this.logContainer.setVisibility(View.GONE);
- } catch (e) {
- printl("❌ ÉèÖÃlogContainer¿É¼ûÐÔʧ°Ü: " + e);
- }
- }
- if (this.closeButton && typeof this.closeButton.setVisibility === 'function') {
- try {
- this.closeButton.setVisibility(View.GONE); // ÊÕÆðʱÒþ²Ø¹Ø±Õ°´Å¥
- } catch (e) {
- printl("❌ ÉèÖÃcloseButton¿É¼ûÐÔʧ°Ü: " + e);
- }
- }
- } else {
- // Õ¹¿ª×´Ì¬
- if (this.titleText && typeof this.titleText.setVisibility === 'function') {
- try {
- this.titleText.setVisibility(View.VISIBLE);
- } catch (e) {
- printl("❌ ÉèÖÃtitleText¿É¼ûÐÔʧ°Ü: " + e);
- }
- }
- if (this.logContainer && typeof this.logContainer.setVisibility === 'function') {
- try {
- this.logContainer.setVisibility(View.VISIBLE);
- } catch (e) {
- printl("❌ ÉèÖÃlogContainer¿É¼ûÐÔʧ°Ü: " + e);
- }
- }
- if (this.closeButton && typeof this.closeButton.setVisibility === 'function') {
- try {
- this.closeButton.setVisibility(View.VISIBLE); // Õ¹¿ªÊ±ÏÔʾ¹Ø±Õ°´Å¥
- } catch (e) {
- printl("❌ ÉèÖÃcloseButton¿É¼ûÐÔʧ°Ü: " + e);
- }
- }
- }
-
- // ³¢ÊÔ¶àÖÖ·½·¨À´ÉèÖÿí¶È£¬Ôö¼Ó¸ü¶àµÄ±¸Ñ¡·½°¸
- var widthSetSuccessfully = false;
- var errorMessages = [];
-
- // »ñÈ¡ÆÁÄ»ÃܶÈ
- var getDensity = function() {
- try {
- if (context && context.getResources && context.getResources().getDisplayMetrics) {
- return context.getResources().getDisplayMetrics().density;
- }
- } catch (e) {
- printl("⚠️ »ñÈ¡ÆÁÄ»ÃܶÈʧ°Ü: " + e);
- }
- return 3; // ĬÈÏÃܶÈ
- };
-
- // ·½·¨1: ³¢ÊÔͨ¹ýFloatUI¶ÔÏóµÄ¿ÉÄÜ·½·¨
- try {
- if (this.ui && typeof this.ui.setLayoutWidth === 'function') {
- this.ui.setLayoutWidth(targetWidth);
- widthSetSuccessfully = true;
- printl("·½·¨1: ʹÓÃsetLayoutWidthÉèÖÿí¶È³É¹¦");
- }
- } catch (e) {
- errorMessages.push("·½·¨1: " + (e.message || String(e)));
- }
-
- // ·½·¨2: ³¢ÊÔͨ¹ýLayoutParamsÉèÖÿí¶È
- if (!widthSetSuccessfully) {
- try {
- if (this.mainContainer && typeof this.mainContainer.getLayoutParams === 'function' &&
- typeof this.mainContainer.setLayoutParams === 'function') {
- var params = this.mainContainer.getLayoutParams();
- if (params) {
- // ³¢ÊÔ½«dpת»»ÎªÏñËØ
- var pixelWidth = Math.round(targetWidth * getDensity());
-
- // °²È«µØÉèÖÿí¶È
- try {
- params.width = pixelWidth;
- this.mainContainer.setLayoutParams(params);
- widthSetSuccessfully = true;
- printl("·½·¨2: ʹÓÃLayoutParamsÉèÖÿí¶È³É¹¦");
- } catch (setParamsError) {
- errorMessages.push("·½·¨2: " + (setParamsError.message || String(setParamsError)));
- }
- }
- }
- } catch (e) {
- errorMessages.push("·½·¨2: " + (e.message || String(e)));
- }
- }
-
- // ·½·¨3: ³¢ÊÔÖ±½ÓÉèÖÃÊÓͼ¿í¶È
- if (!widthSetSuccessfully) {
- try {
- if (this.mainContainer && typeof this.mainContainer.setWidth === 'function') {
- // ʹÓÃÒѾ¼ÆËãºÃµÄÏñËØ¿í¶È
- var pixelWidth = Math.round(targetWidth * getDensity());
- this.mainContainer.setWidth(pixelWidth);
- widthSetSuccessfully = true;
- printl("·½·¨3: ʹÓÃsetWidthÉèÖÿí¶È³É¹¦");
- }
- } catch (e) {
- errorMessages.push("·½·¨3: " + (e.message || String(e)));
- }
- }
-
- // ·½·¨4: ³¢ÊÔÐÞ¸ÄXML²¼¾Ö²ÎÊý
- if (!widthSetSuccessfully) {
- try {
- if (this.ui && typeof this.ui.setLayoutParams === 'function') {
- // ³¢ÊÔ»ñÈ¡²¢ÐÞ¸ÄFloatUIµÄ²¼¾Ö²ÎÊý
- var floatParams = (typeof this.ui.getLayoutParams === 'function') ? this.ui.getLayoutParams() : null;
- if (floatParams) {
- floatParams.width = Math.round(targetWidth * getDensity());
- this.ui.setLayoutParams(floatParams);
- widthSetSuccessfully = true;
- printl("·½·¨4: ʹÓÃFloatUI.setLayoutParamsÉèÖÿí¶È³É¹¦");
- }
- }
- } catch (e) {
- errorMessages.push("·½·¨4: " + (e.message || String(e)));
- }
- }
-
- // ·½·¨5: ³¢ÊÔʹÓÃlayout·½·¨Ö±½ÓÉèÖÃλÖúʹóС
- if (!widthSetSuccessfully) {
- try {
- if (this.mainContainer && typeof this.mainContainer.layout === 'function') {
- var left = 0;
- var top = 0;
- try {
- left = this.mainContainer.getLeft();
- top = this.mainContainer.getTop();
- } catch (positionError) {
- // ʹÓÃĬÈÏλÖÃ
- }
- var pixelWidth = Math.round(targetWidth * getDensity());
- var height = 0;
- try {
- height = this.mainContainer.getHeight();
- } catch (heightError) {
- height = 100; // ĬÈϸ߶È
- }
- this.mainContainer.layout(left, top, left + pixelWidth, top + height);
- widthSetSuccessfully = true;
- printl("·½·¨5: ʹÓÃlayout·½·¨ÉèÖÿí¶È³É¹¦");
- }
- } catch (e) {
- errorMessages.push("·½·¨5: " + (e.message || String(e)));
- }
- }
-
- // ³¢ÊÔUIˢз½·¨
- if (widthSetSuccessfully) {
- try {
- if (this.ui && typeof this.ui.updateLayout === 'function') {
- this.ui.updateLayout();
- printl("UI²¼¾ÖÒѸüÐÂ");
- } else if (this.mainContainer && typeof this.mainContainer.requestLayout === 'function') {
- this.mainContainer.requestLayout();
- printl("ÇëÇóÖØÐ²¼¾Ö");
- } else if (this.mainContainer && typeof this.mainContainer.invalidate === 'function') {
- this.mainContainer.invalidate();
- printl("ÊÓͼÒÑË¢ÐÂ");
- }
- } catch (e) {
- printl("ˢв¼¾Öʧ°Ü: " + e);
- }
- }
-
- // ÉèÖð´Å¥Îı¾
- if (this.toggleButton && typeof this.toggleButton.setText === 'function') {
- try {
- this.toggleButton.setText("¡Ô");
- } catch (e) {
- printl("❌ ÉèÖð´Å¥Îı¾Ê§°Ü: " + e);
- }
- }
-
- // ÑÓ³Ù100msºó¼Ç¼״̬¸üУ¬È·±£UIÒѸüÐÂ
- setTimeout(function() {
- try {
- if (widthSetSuccessfully) {
- printl("✅ " + (self.isExpanded ? "²àÀ¸ÒÑÕ¹¿ª" : "²àÀ¸ÒÑÊÕÆð"));
- } else {
- // Ö»¼Ç¼µÚÒ»¸ö´íÎóÐÅÏ¢£¬±ÜÃâÈÕÖ¾¹ý¶à
- var mainError = errorMessages.length > 0 ? errorMessages[0] : "δ֪´íÎó";
- printl(mainError);
- printl("⚠️ ²àÀ¸" + (self.isExpanded ? "Õ¹¿ª" : "ÊÕÆð") + "µ«¿í¶Èµ÷Õûʧ°Ü");
- }
- } catch (e) {
- // ¾²Ä¬´¦ÀíÈÕÖ¾´íÎó
- }
- }, 100);
-
- return widthSetSuccessfully;
- } catch (e) {
- printl("❌ Ö´ÐÐÇл»Õ¹¿ª/ÊÕÆð²Ù×÷ʧ°Ü: " + e);
- return false;
- }
- };
- // Ìí¼ÓÈÕÖ¾
- ²àÀ¸ÈÕÖ¾.prototype.log = function(message, color) {
- try {
- // Éú³Éʱ¼ä´Á
- var now = new Date();
- var timeStr = now.getHours().toString().padStart(2, '0') + ":" +
- now.getMinutes().toString().padStart(2, '0') + ":" +
- now.getSeconds().toString().padStart(2, '0');
-
- // ¸ñʽ»¯ÈÕÖ¾ÌõÄ¿
- var logEntry = "[" + timeStr + "] " + message;
-
- // Ìí¼Óµ½ÈÕÖ¾Êý×é
- this.logs.push({text: logEntry, color: color || "#00FF00"});
-
- // ÏÞÖÆÈÕÖ¾ÊýÁ¿
- if (this.logs.length > this.maxLogs) {
- this.logs.shift(); // ÒÆ³ý×îÔçµÄÈÕÖ¾
- }
-
- // ¸üÐÂÏÔʾ
- this.updateLogDisplay();
-
- // ͬʱ´òÓ¡µ½¿ØÖÆÌ¨
- printl(logEntry);
- } catch (e) {
- printl("❌ Ìí¼ÓÈÕ־ʧ°Ü: " + e);
- }
- };
- // ¸üÐÂÈÕÖ¾ÏÔʾ
- ²àÀ¸ÈÕÖ¾.prototype.updateLogDisplay = function() {
- try {
- var self = this;
- var uiOperation = function() {
- self.performUpdateLogDisplay();
- };
-
- // ³¢ÊÔ¶àÖÖUIÏ̵߳÷¶È·½°¸
- var threadScheduled = false;
-
- // ·½°¸1: ʹÓÃcontext.runOnUiThread
- try {
- if (context && context.runOnUiThread) {
- var runnable = {
- run: function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ UIÏß³ÌÖ´ÐÐÈÕÖ¾¸üÐÂʧ°Ü: " + e);
- }
- }
- };
- context.runOnUiThread(runnable);
- threadScheduled = true;
- }
- } catch (e) {
- printl("❌ ·½°¸1: context.runOnUiThreadµ÷¶ÈÈÕÖ¾¸üÐÂʧ°Ü: " + e);
- }
-
- // ·½°¸2: ʹÓÃView.post
- if (!threadScheduled) {
- try {
- var viewToUse = self.logText || self.logContainer || self.mainContainer;
- if (viewToUse && viewToUse.post) {
- viewToUse.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ View.postÖ´ÐÐÈÕÖ¾¸üÐÂʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- }
- } catch (e) {
- printl("❌ ·½°¸2: View.postµ÷¶ÈÈÕÖ¾¸üÐÂʧ°Ü: " + e);
- }
- }
-
- // ·½°¸3: ³¢ÊÔʹÓÃHandler
- if (!threadScheduled) {
- try {
- if (typeof Handler !== 'undefined' && typeof Looper !== 'undefined' && Looper.getMainLooper) {
- var handler = new Handler(Looper.getMainLooper());
- handler.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ HandlerÖ´ÐÐÈÕÖ¾¸üÐÂʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- }
- } catch (e) {
- printl("❌ ·½°¸3: Handlerµ÷¶ÈÈÕÖ¾¸üÐÂʧ°Ü: " + e);
- }
- }
-
- // ·½°¸4: Ö±½ÓÖ´ÐÐ×÷Ϊ×îºó±¸Ñ¡
- if (!threadScheduled) {
- try {
- uiOperation();
- } catch (directError) {
- printl("❌ Ö±½ÓÖ´ÐÐÈÕÖ¾¸üÐÂʧ°Ü: " + directError);
- }
- }
- } catch (e) {
- printl("❌ ¸üÐÂÈÕÖ¾ÏÔʾʧ°Ü: " + e);
- }
- };
- // Ö´ÐÐÈÕÖ¾ÏÔʾ¸üеĺËÐÄ·½·¨£¨Ó¦ÔÚÖ÷Ïß³ÌÖе÷Óã©
- ²àÀ¸ÈÕÖ¾.prototype.performUpdateLogDisplay = function() {
- try {
- // ¼ì²élogTextÊÇ·ñ´æÔÚ
- if (!this.logText || typeof this.logText.setText !== 'function') {
- printl("⚠️ ÈÕÖ¾ÏÔʾ×é¼þ²»¿ÉÓÃ");
- return;
- }
-
- // ¹¹½¨ÈÕÖ¾Îı¾
- var logText = "";
- var useHtml = false;
-
- // ³¢ÊÔHTML¸ñʽ
- try {
- if (typeof android.text.Html !== 'undefined' && typeof android.text.Html.fromHtml === 'function') {
- var htmlText = "";
- for (var i = 0; i < this.logs.length; i++) {
- var log = this.logs[i];
- var color = log.color || "#00FF00";
- htmlText += "<font color=\"" + color + "\">" + log.text + "</font><br/>";
- }
-
- try {
- var spanned = android.text.Html.fromHtml(htmlText);
- this.logText.setText(spanned);
- useHtml = true;
- printl("✅ ÈÕ־ʹÓÃHTML¸ñʽÏÔʾ");
- } catch (htmlError) {
- printl("⚠️ HTML¸ñʽ»¯Ê§°Ü£¬»ØÍ˵½´¿Îı¾: " + htmlError);
- }
- }
- } catch (e) {
- printl("⚠️ HTMLÖ§³Ö²»¿ÉÓÃ: " + e);
- }
-
- // Èç¹ûHTML¸ñʽʧ°Ü£¬Ê¹Óô¿Îı¾¸ñʽ
- if (!useHtml) {
- for (var i = 0; i < this.logs.length; i++) {
- logText += this.logs[i].text + "\n";
- }
-
- try {
- this.logText.setText(logText);
- printl("✅ ÈÕ־ʹÓô¿Îı¾¸ñʽÏÔʾ");
- } catch (textError) {
- printl("❌ ÉèÖÃÈÕÖ¾Îı¾Ê§°Ü: " + textError);
- }
- }
-
- // ³¢ÊÔ¹ö¶¯µ½µ×²¿
- var self = this;
- try {
- if (this.logContainer && typeof this.logContainer.post === 'function') {
- this.logContainer.post(function() {
- try {
- if (self.logContainer && typeof self.logContainer.fullScroll === 'function') {
- self.logContainer.fullScroll(android.widget.ScrollView.FOCUS_DOWN);
- }
- } catch (scrollError) {
- // ¾²Ä¬´¦Àí¹ö¶¯´íÎó
- }
- });
- } else if (this.logContainer && typeof this.logContainer.fullScroll === 'function') {
- this.logContainer.fullScroll(android.widget.ScrollView.FOCUS_DOWN);
- }
- } catch (e) {
- // ¾²Ä¬´¦Àí¹ö¶¯´íÎó
- }
- } catch (e) {
- printl("❌ Ö´ÐÐÈÕÖ¾ÏÔʾ¸üÐÂʧ°Ü: " + e);
- }
- };
- // ÉèÖÃÐü¸¡´°Î»ÖÃ
- ²àÀ¸ÈÕÖ¾.prototype.setPos = function(x, y) {
- try {
- var self = this;
-
- // ²ÎÊýÑéÖ¤
- if (typeof x !== 'number' || typeof y !== 'number') {
- printl("❌ setPos²ÎÊý´íÎó: xºÍy±ØÐëÊÇÊý×Ö");
- return false;
- }
-
- // ±ß½ç¼ì²é
- var currentWidth = this.isExpanded ? this.sidebarWidth : this.sidebarMinWidth;
- try {
- if (context && context.getResources && context.getResources().getDisplayMetrics) {
- var density = context.getResources().getDisplayMetrics().density;
- currentWidth *= density;
- }
- } catch (e) {
- currentWidth *= 3; // ʹÓÃĬÈÏÃܶȱ¶Êý
- }
-
- if (x < 0) x = 0;
- if (y < 0) y = 0;
- if (x > this.screenWidth - currentWidth) x = this.screenWidth - currentWidth;
- if (y > this.screenHeight - 100) y = this.screenHeight - 100;
-
- // ʹÓÃprintl±ÜÃâµÝ¹éµ÷ÓÃ
- printl("🔄 ÉèÖÃÐü¸¡´°Î»ÖÃ: x=" + x + ", y=" + y);
-
- // ¶¨ÒåUI²Ù×÷º¯Êý
- var uiOperation = function() {
- self.performSetPos(x, y);
- };
-
- // ³¢ÊÔ¶àÖÖUIÏ̵߳÷¶È·½°¸
- var threadScheduled = false;
-
- // ·½°¸1: ʹÓÃcontext.runOnUiThread
- try {
- if (context && context.runOnUiThread) {
- var runnable = {
- run: function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ UIÏß³ÌÖ´ÐÐλÖÃÉèÖÃʧ°Ü: " + e);
- }
- }
- };
- context.runOnUiThread(runnable);
- threadScheduled = true;
- printl("✅ ʹÓÃcontext.runOnUiThreadµ÷¶ÈλÖÃÉèÖÃ");
- }
- } catch (e) {
- printl("❌ ·½°¸1: context.runOnUiThreadµ÷¶ÈλÖÃÉèÖÃʧ°Ü: " + e);
- }
-
- // ·½°¸2: ʹÓÃView.post
- if (!threadScheduled) {
- try {
- var viewToUse = self.mainContainer || self.titleBar || self.toggleButton;
- if (viewToUse && typeof viewToUse.post === 'function') {
- viewToUse.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ View.postÖ´ÐÐλÖÃÉèÖÃʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- printl("✅ ʹÓÃView.postµ÷¶ÈλÖÃÉèÖÃ");
- }
- } catch (e) {
- printl("❌ ·½°¸2: View.postµ÷¶ÈλÖÃÉèÖÃʧ°Ü: " + e);
- }
- }
-
- // ·½°¸3: ³¢ÊÔʹÓÃHandler
- if (!threadScheduled) {
- try {
- if (typeof Handler !== 'undefined' && typeof Looper !== 'undefined' && Looper.getMainLooper) {
- var handler = new Handler(Looper.getMainLooper());
- handler.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ HandlerÖ´ÐÐλÖÃÉèÖÃʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- printl("✅ ʹÓÃHandlerµ÷¶ÈλÖÃÉèÖÃ");
- }
- } catch (e) {
- printl("❌ ·½°¸3: Handlerµ÷¶ÈλÖÃÉèÖÃʧ°Ü: " + e);
- }
- }
-
- // ·½°¸4: Ö±½ÓÖ´ÐÐ×÷Ϊ×îºó±¸Ñ¡
- if (!threadScheduled) {
- printl("⚠️ ËùÓÐÏ̵߳÷¶È·½°¸Ê§°Ü£¬³¢ÊÔÖ±½ÓÖ´ÐÐλÖÃÉèÖÃ");
- try {
- uiOperation();
- } catch (directError) {
- printl("❌ Ö±½ÓÖ´ÐÐλÖÃÉèÖÃʧ°Ü: " + directError);
- }
- }
-
- return true;
- } catch (e) {
- printl("❌ ÉèÖÃλÖÃʧ°Ü: " + e);
- return false;
- }
- };
- // Ö´ÐÐÉèÖÃλÖõĺËÐÄ·½·¨£¨Ó¦ÔÚÖ÷Ïß³ÌÖе÷Óã©
- ²àÀ¸ÈÕÖ¾.prototype.performSetPos = function(x, y) {
- try {
- var posSetSuccess = false;
-
- // ·½°¸1: ³¢ÊÔʹÓÃfloatUIµÄsetPos·½·¨
- try {
- if (this.ui && this.ui.setPos) {
- this.ui.setPos(x, y);
- posSetSuccess = true;
- printl("✅ ·½°¸1: ʹÓÃfloatUI.setPosÉèÖÃλÖóɹ¦");
- }
- } catch (e) {
- printl("❌ ·½°¸1: floatUI.setPosʧ°Ü: " + e);
- }
-
- // ·½°¸2: ³¢ÊÔʹÓÃfloatUIµÄsetPosition·½·¨
- if (!posSetSuccess) {
- try {
- if (this.ui && this.ui.setPosition) {
- this.ui.setPosition(x, y);
- posSetSuccess = true;
- printl("✅ ·½°¸2: ʹÓÃfloatUI.setPositionÉèÖÃλÖóɹ¦");
- }
- } catch (e) {
- printl("❌ ·½°¸2: floatUI.setPositionʧ°Ü: " + e);
- }
- }
-
- // ·½°¸3: ³¢ÊÔʹÓÃsetXºÍsetY·½·¨£¨Èç¹û¿ÉÓã©
- if (!posSetSuccess) {
- try {
- if (this.ui && typeof this.ui.setX === 'function' && typeof this.ui.setY === 'function') {
- this.ui.setX(x);
- this.ui.setY(y);
- posSetSuccess = true;
- printl("✅ ·½°¸3: ʹÓÃui.setX/setYÉèÖÃλÖóɹ¦");
- }
- } catch (e) {
- printl("❌ ·½°¸3: ui.setX/setYʧ°Ü: " + e);
- }
- }
-
- // ·½°¸4: ³¢ÊÔͨ¹ýmainContainerÉèÖÃλÖÃ
- if (!posSetSuccess) {
- try {
- if (this.mainContainer && typeof this.mainContainer.setX === 'function' && typeof this.mainContainer.setY === 'function') {
- this.mainContainer.setX(x);
- this.mainContainer.setY(y);
- posSetSuccess = true;
- printl("✅ ·½°¸4: ʹÓÃmainContainer.setX/setYÉèÖÃλÖóɹ¦");
- }
- } catch (e) {
- printl("❌ ·½°¸4: mainContainer.setX/setYʧ°Ü: " + e);
- }
- }
-
- // ·½°¸5: ³¢ÊÔͨ¹ýÖ±½Ó·ÃÎÊmainContainerÉèÖÃλÖÃ
- if (!posSetSuccess) {
- try {
- if (this.mainContainer && typeof this.mainContainer.layout === 'function' && typeof this.mainContainer.getWidth === 'function' && typeof this.mainContainer.getHeight === 'function') {
- this.mainContainer.layout(x, y, x + this.mainContainer.getWidth(), y + this.mainContainer.getHeight());
- posSetSuccess = true;
- printl("✅ ·½°¸5: ʹÓÃlayout·½·¨ÉèÖÃλÖóɹ¦");
- }
- } catch (e) {
- printl("❌ ·½°¸5: layout·½·¨Ê§°Ü: " + e);
- }
- }
-
- // Ë¢ÐÂUIÈ·±£Î»ÖøüÐÂÉúЧ
- if (posSetSuccess) {
- try {
- // ³¢ÊÔ¶àÖÖˢз½·¨
- if (this.mainContainer) {
- if (typeof this.mainContainer.invalidate === 'function') {
- this.mainContainer.invalidate();
- }
- if (typeof this.mainContainer.requestLayout === 'function') {
- this.mainContainer.requestLayout();
- }
- }
- printl("✅ λÖÃÉèÖÃË¢ÐÂÍê³É");
- } catch (refreshError) {
- printl("⚠️ Ë¢ÐÂλÖÃʱ³ö´í: " + refreshError);
- }
- } else {
- printl("⚠️ λÖÃÉèÖÃÍê³Éµ«¿ÉÄÜδÉúЧ");
- }
-
- return posSetSuccess;
- } catch (e) {
- printl("❌ Ö´ÐÐλÖÃÉèÖÃʧ°Ü: " + e);
- return false;
- }
- };
- // Çå¿ÕÈÕÖ¾
- ²àÀ¸ÈÕÖ¾.prototype.clearLogs = function() {
- try {
- // Çå¿ÕÈÕÖ¾Êý×é
- this.logs = [];
-
- // Çå¿ÕÈÕÖ¾ÏÔʾ
- if (this.logText && this.logText.setText) {
- try {
- this.logText.setText("");
- } catch (setTextError) {
- printl("⚠️ Çå¿ÕÈÕÖ¾ÏÔʾʧ°Ü: " + setTextError);
- }
- }
-
- // ¼Ç¼Çå¿Õ²Ù×÷
- this.log("🗑️ ÈÕÖ¾ÒÑÇå¿Õ", "#FF0000");
- return true;
- } catch (e) {
- printl("❌ Çå¿ÕÈÕ־ʧ°Ü: " + e);
- return false;
- }
- };
- // ¹Ø±ÕÐü¸¡´°
- ²àÀ¸ÈÕÖ¾.prototype.close = function() {
- try {
- var self = this;
-
- // ʹÓÃprintl±ÜÃâµÝ¹éµ÷ÓÃ
- printl("🔄 ÕýÔڹرղàÀ¸ÈÕÖ¾Ðü¸¡´°...");
-
- // ¶¨ÒåUI²Ù×÷º¯Êý
- var uiOperation = function() {
- self.performClose();
- };
-
- // ³¢ÊÔ¶àÖÖUIÏ̵߳÷¶È·½°¸
- var threadScheduled = false;
-
- // ·½°¸1: ʹÓÃcontext.runOnUiThread
- try {
- if (context && context.runOnUiThread) {
- var runnable = {
- run: function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ UIÏß³ÌÖ´ÐйرղÙ×÷ʧ°Ü: " + e);
- }
- }
- };
- context.runOnUiThread(runnable);
- threadScheduled = true;
- printl("✅ ʹÓÃcontext.runOnUiThreadµ÷¶È¹Ø±Õ²Ù×÷");
- }
- } catch (e) {
- printl("❌ ·½°¸1: context.runOnUiThreadµ÷¶È¹Ø±Õ²Ù×÷ʧ°Ü: " + e);
- }
-
- // ·½°¸2: ʹÓÃView.post
- if (!threadScheduled) {
- try {
- var viewToUse = self.mainContainer || self.titleBar || self.toggleButton;
- if (viewToUse && typeof viewToUse.post === 'function') {
- viewToUse.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ View.postÖ´ÐйرղÙ×÷ʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- printl("✅ ʹÓÃView.postµ÷¶È¹Ø±Õ²Ù×÷");
- }
- } catch (e) {
- printl("❌ ·½°¸2: View.postµ÷¶È¹Ø±Õ²Ù×÷ʧ°Ü: " + e);
- }
- }
-
- // ·½°¸3: ³¢ÊÔʹÓÃHandler
- if (!threadScheduled) {
- try {
- if (typeof Handler !== 'undefined' && typeof Looper !== 'undefined' && Looper.getMainLooper) {
- var handler = new Handler(Looper.getMainLooper());
- handler.post(function() {
- try {
- uiOperation();
- } catch (e) {
- printl("❌ HandlerÖ´ÐйرղÙ×÷ʧ°Ü: " + e);
- }
- });
- threadScheduled = true;
- printl("✅ ʹÓÃHandlerµ÷¶È¹Ø±Õ²Ù×÷");
- }
- } catch (e) {
- printl("❌ ·½°¸3: Handlerµ÷¶È¹Ø±Õ²Ù×÷ʧ°Ü: " + e);
- }
- }
-
- // ·½°¸4: Ö±½ÓÖ´ÐÐ×÷Ϊ×îºó±¸Ñ¡
- if (!threadScheduled) {
- printl("⚠️ ËùÓÐÏ̵߳÷¶È·½°¸Ê§°Ü£¬³¢ÊÔÖ±½ÓÖ´ÐйرղÙ×÷");
- try {
- uiOperation();
- } catch (directError) {
- printl("❌ Ö±½ÓÖ´ÐйرղÙ×÷ʧ°Ü: " + directError);
- }
- }
- } catch (e) {
- printl("❌ ¹Ø±Õ²àÀ¸ÈÕÖ¾Ðü¸¡´°Ê§°Ü: " + e);
- }
- };
- // Ö´ÐйرղÙ×÷µÄºËÐÄ·½·¨£¨Ó¦ÔÚÖ÷Ïß³ÌÖе÷Óã©
- ²àÀ¸ÈÕÖ¾.prototype.performClose = function() {
- try {
- printl("🔄 Ö´ÐÐÐü¸¡´°¹Ø±Õ²Ù×÷...");
-
- // ³¢ÊÔ¶àÖֹرշ½°¸
- var closeSuccess = false;
-
- // ·½°¸1: ³¢ÊÔʹÓÃclose·½·¨
- try {
- if (this.ui && typeof this.ui.close === 'function') {
- this.ui.close();
- closeSuccess = true;
- printl("✅ ·½°¸1: ʹÓÃui.close()³É¹¦¹Ø±Õ");
- }
- } catch (e) {
- printl("❌ ·½°¸1: ʹÓÃui.close()¹Ø±Õʧ°Ü: " + e);
- }
-
- // ·½°¸2: ³¢ÊÔʹÓÃdestroy·½·¨
- if (!closeSuccess) {
- try {
- if (this.ui && typeof this.ui.destroy === 'function') {
- this.ui.destroy();
- closeSuccess = true;
- printl("✅ ·½°¸2: ʹÓÃui.destroy()³É¹¦¹Ø±Õ");
- }
- } catch (e) {
- printl("❌ ·½°¸2: ʹÓÃui.destroy()¹Ø±Õʧ°Ü: " + e);
- }
- }
-
- // ·½°¸3: ³¢ÊÔ´Ó¸¸ÈÝÆ÷ÒÆ³ý
- if (!closeSuccess) {
- try {
- if (this.mainContainer && typeof this.mainContainer.getParent === 'function') {
- var parent = this.mainContainer.getParent();
- if (parent && typeof parent.removeView === 'function') {
- parent.removeView(this.mainContainer);
- closeSuccess = true;
- printl("✅ ·½°¸3: ´Ó¸¸ÈÝÆ÷ÒÆ³ý³É¹¦");
- }
- }
- } catch (e) {
- printl("❌ ·½°¸3: ´Ó¸¸ÈÝÆ÷ÒÆ³ýʧ°Ü: " + e);
- }
- }
-
- // ·½°¸4: ³¢ÊÔÒþ²ØÊÓͼ
- if (!closeSuccess) {
- try {
- if (this.mainContainer && typeof this.mainContainer.setVisibility === 'function') {
- this.mainContainer.setVisibility(View.GONE);
- closeSuccess = true;
- printl("✅ ·½°¸4: Òþ²ØÊÓͼ³É¹¦");
- }
- } catch (e) {
- printl("❌ ·½°¸4: Òþ²ØÊÓͼʧ°Ü: " + e);
- }
- }
-
- // ÇåÀí×ÊÔ´
- try {
- // Çå³ýʼþ¼àÌýÆ÷
- if (this.titleBar && typeof this.titleBar.setOnTouchListener === 'function') {
- this.titleBar.setOnTouchListener(null);
- }
- if (this.toggleButton && typeof this.toggleButton.setOnClickListener === 'function') {
- this.toggleButton.setOnClickListener(null);
- }
- if (this.closeButton && typeof this.closeButton.setOnClickListener === 'function') {
- this.closeButton.setOnClickListener(null);
- }
-
- // Çå³ýÒýÓ㬰ïÖúÀ¬»ø»ØÊÕ
- this.ui = null;
- this.mainContainer = null;
- this.titleBar = null;
- this.toggleButton = null;
- this.closeButton = null;
- this.titleText = null;
- this.logContainer = null;
- this.logText = null;
- this.logs = null;
-
- printl("✅ ×ÊÔ´ÇåÀíÍê³É");
- } catch (cleanupError) {
- printl("⚠️ ×ÊÔ´ÇåÀíʱ³ö´í: " + cleanupError);
- }
-
- // ¸üÐÂ״̬
- sidebarLogger = null;
-
- // ¼Ç¼¹Ø±Õ½á¹û
- if (closeSuccess) {
- printl("✅ ²àÀ¸ÈÕÖ¾Ðü¸¡´°Òѳɹ¦¹Ø±Õ");
- } else {
- printl("⚠️ ²àÀ¸ÈÕÖ¾Ðü¸¡´°³¢ÊԹرգ¬µ«¿ÉÄÜδÍêÈ«³É¹¦");
- }
-
- return closeSuccess;
- } catch (e) {
- printl("❌ Ö´ÐйرղÙ×÷ʧ°Ü: " + e);
- return false;
- }
- };
- // ´´½¨²¢Æô¶¯²àÀ¸ÈÕÖ¾Ðü¸¡´°
- var sidebarLogger = null;
- // °æ±¾ÐÅÏ¢
- const SIDEBAR_LOGGER_VERSION = "1.2.0";
- // ³õʼ»¯Ðü¸¡´°
- function initSidebarLogger(options) {
- try {
- // ·ÀÖ¹ÖØ¸´³õʼ»¯
- if (sidebarLogger) {
- printl("⚠️ ²àÀ¸ÈÕÖ¾ÒѾ³õʼ»¯£¬ÎÞÐèÖØ¸´´´½¨");
- return sidebarLogger;
- }
-
- // ºÏ²¢Ä¬ÈÏÑ¡ÏîºÍÓû§Ñ¡Ïî
- options = options || {};
-
- // »·¾³¼ì²é
- if (typeof floatUI === 'undefined') {
- printl("❌ ´íÎó£ºÎ´ÕÒµ½floatUI¿â£¬ÇëÈ·±£ÔÚAIWROK»·¾³ÖÐÔËÐУ¡");
- return null;
- }
-
- // ´òÓ¡Æô¶¯ÐÅÏ¢
- printl("====================================");
- printl("🔄 ²àÀ¸ÈÕÖ¾Ðü¸¡´°³õʼ»¯ÖÐ...");
- printl("📱 °æ±¾: " + SIDEBAR_LOGGER_VERSION);
- printl("====================================");
-
- // ´´½¨Ðü¸¡´°ÊµÀý
- sidebarLogger = new ²àÀ¸ÈÕÖ¾();
-
- // ´´½¨Ðü¸¡´°
- if (sidebarLogger.create()) {
- printl("✅ ²àÀ¸ÈÕÖ¾Ðü¸¡´°ÒÑ´´½¨³É¹¦£¡");
-
- // Ìí¼Ó»¶ÓÈÕÖ¾
- sidebarLogger.log("🎉 »¶ÓʹÓòàÀ¸ÈÕÖ¾¹¤¾ß", "#00FFFF");
- sidebarLogger.log("📱 °æ±¾: " + SIDEBAR_LOGGER_VERSION, "#00FFFF");
- sidebarLogger.log("💡 µã»÷¡Ô°´Å¥Õ¹¿ª/ÊÕÆð²àÀ¸", "#FFFF00");
- sidebarLogger.log("🔄 Í϶¯±êÌâÀ¸¿ÉÒÆ¶¯Ðü¸¡´°", "#FFFF00");
- sidebarLogger.log("🗑️ ÓÒÉϽǹرհ´Å¥¿É¹Ø±ÕÐü¸¡´°", "#FFFF00");
- sidebarLogger.log("💡 ¿ÉʹÓÃsidebarLogger.log()Ìí¼Ó×Ô¶¨ÒåÈÕÖ¾", "#00FF00");
-
- // ×Ô¶¯Õ¹¿ªÐü¸¡´°£¬ÈÃÓû§¿´µ½¹Ø±Õ°´Å¥
- try {
- setTimeout(function() {
- if (sidebarLogger && typeof sidebarLogger.toggleExpand === 'function') {
- sidebarLogger.toggleExpand();
- }
- }, 500);
- } catch (autoExpandError) {
- printl("⚠️ ×Ô¶¯Õ¹¿ªÊ§°Ü: " + autoExpandError);
- }
-
- return sidebarLogger;
- } else {
- printl("❌ ²àÀ¸ÈÕÖ¾Ðü¸¡´°´´½¨Ê§°Ü£¡");
- sidebarLogger = null;
- return null;
- }
- } catch (e) {
- printl("❌ ³õʼ»¯²àÀ¸ÈÕ־ʧ°Ü: " + e);
- sidebarLogger = null;
- return null;
- }
- }
- // °²È«»ñÈ¡²àÀ¸ÈÕ־ʵÀý
- function getSidebarLogger() {
- return sidebarLogger;
- }
- // °²È«µØ¼Ç¼ÈÕÖ¾£¨¼´Ê¹Ðü¸¡´°Î´³õʼ»¯Ò²²»»á±¨´í£©
- function safeLog(message, color) {
- if (sidebarLogger && typeof sidebarLogger.log === 'function') {
- try {
- sidebarLogger.log(message, color);
- return true;
- } catch (e) {
- printl("⚠️ ¼Ç¼ÈÕ־ʧ°Ü: " + e);
- }
- }
- // ½µ¼¶µ½console.log
- printl(message || "");
- return false;
- }
- // Æô¶¯Ðü¸¡´°
- try {
- // ÑÓ³Ù³õʼ»¯£¬È·±£»·¾³×¼±¸¾ÍÐ÷
- setTimeout(function() {
- initSidebarLogger();
- }, 100);
- } catch (startupError) {
- printl("❌ Æô¶¯Ðü¸¡´°Ê§°Ü: " + startupError);
- // ×÷Ϊ×îºóµÄ±¸Ñ¡£¬³¢ÊÔÖ±½Ó³õʼ»¯
- try {
- initSidebarLogger();
- } catch (finalError) {
- printl("❌ Ö±½Ó³õʼ»¯Ò²Ê§°Ü: " + finalError);
- }
- }
¸´ÖÆ´úÂë
|
|