Files
ShortX_ToolHub/code/th_12_rebuild.js
root c7e9b92322 refactor: split th_2_core.js into 12 modules, rename all files to 2-digit numbering
- Split th_2_core.js (4715 lines, 177KB) into:
  th_02_core.js, th_03_icon.js, th_04_theme.js, th_05_persistence.js,
  th_06_icon_parser.js, th_07_shortcut.js, th_08_content.js,
  th_09_animation.js, th_10_shell.js, th_11_action.js,
  th_12_rebuild.js, th_13_panel_ui.js
- Rename existing: th_1_base→th_01_base, th_3_panels→th_14_panels,
  th_4_extra→th_15_extra, th_5_entry→th_16_entry
- Update ToolHub.js MODULE_MANIFEST, modules array, and critical module check
2026-04-20 11:53:13 +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(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;
};