Files
ShortX_ToolHub/code/th_12_rebuild.js
linshenjianlu 9ad01b436d fix: 代码审查6项修复
- 689处空catch块补全日志
- eval远程代码增加SHA256校验
- 删除ToolHubLogger重复定义
- getParentFile()增加null保护
- 提取buildButtonEditorPanelView内通用工具函数到文件级
- 修复HandlerThread/ValueAnimator资源泄漏
2026-04-21 07:42:23 +08:00

77 lines
2.3 KiB
JavaScript

// @version 1.0.0
// =======================【新增:改大小后安全重建悬浮球】======================
FloatBallAppWM.prototype.rebuildBallForNewSize = function(keepPanels) {
if (this.state.closing) return false;
if (!this.state.wm) return false;
if (!this.state.addedBall) return false;
if (!this.state.ballRoot) return false;
if (!this.state.ballLp) return false;
if (this.state.dragging) return false;
var oldSize = this.state.ballLp.height;
if (!oldSize || oldSize <= 0) oldSize = this.getDockInfo().ballSize;
var oldX = this.state.ballLp.x;
var oldY = this.state.ballLp.y;
var oldCenterX = oldX + Math.round(oldSize / 2);
var oldCenterY = oldY + Math.round(oldSize / 2);
if (!keepPanels) {
this.hideAllPanels();
}
this.cancelDockTimer();
this.state.docked = false;
this.state.dockSide = null;
this.safeRemoveView(this.state.ballRoot, "ballRoot-rebuild");
this.state.ballRoot = null;
this.state.ballContent = null;
this.state.ballLp = null;
this.state.addedBall = false;
this.createBallViews();
var di = this.getDockInfo();
var newSize = di.ballSize;
var newX = oldCenterX - Math.round(newSize / 2);
var newY = oldCenterY - Math.round(newSize / 2);
var maxX = Math.max(0, this.state.screen.w - newSize);
var maxY = Math.max(0, this.state.screen.h - newSize);
newX = this.clamp(newX, 0, maxX);
newY = this.clamp(newY, 0, maxY);
var lp = new android.view.WindowManager.LayoutParams(
newSize,
newSize,
android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
android.graphics.PixelFormat.TRANSLUCENT
);
lp.gravity = android.view.Gravity.TOP | android.view.Gravity.START;
lp.x = newX;
lp.y = newY;
try {
this.state.wm.addView(this.state.ballRoot, lp);
this.state.ballLp = lp;
this.state.addedBall = true;
} catch (eAdd) {
try { this.toast("重建悬浮球失败: " + String(eAdd)); } catch(eT) { safeLog(null, 'e', "catch " + String(eT)); }
safeLog(this.L, 'e', "rebuildBall add fail err=" + String(eAdd));
return false;
}
this.savePos(this.state.ballLp.x, this.state.ballLp.y);
this.touchActivity();
safeLog(this.L, 'i', "rebuildBall ok size=" + String(newSize) + " x=" + String(newX) + " y=" + String(newY));
return true;
};