feat: 大幅增强原生行为 — 修复P0 Bug + 补全核心API

P0 Bug 修复:
- Canvas.drawBitmap 重复定义导致重载丢失 → 合并为*args重载
- String.hashCode() 不可达的第二return → 修复为单return
- File.compareTo() 调用不存在的__cmp__ → 改为显式比较
- HashMap.remove() 逻辑错误 → 区分单参(返回旧值)/双参(返回boolean)

P1 核心行为增强:
- Handler: sendMessage/sendMessageDelayed 现在真正入队异步执行
- Looper: loop() 实现真正的消息循环(按when时间取出到期消息)
- AsyncTask: execute() 在后台线程池执行,完成后主线程回调
- Bundle: 新增12个数组类型put/get方法
- Math.round: 改为Java语义(floor(a+0.5))而非Python银行家舍入
- Thread: currentThread()缓存对象, 新增join/getState/getId/getPriority
- String: 新增strip/repeat/isBlank/lines/subSequence/getChars/chars/formatted/translateEscapes

P2 缺失API补全:
- 新增21个Java标准Exception类 (NullPointerException等)
- View: 新增39个事件处理/监听器/位置尺寸方法
- Activity: 新增33个生命周期/权限/UI方法
- Context: 新增22个文件流/权限/资源/主题方法
- Canvas: 支持 Canvas(Bitmap) 构造函数重载
- __init__.py: __all__ 补全Exception体系和Activity类
This commit is contained in:
shuiyu1123 committed 2026-06-24 15:04:17 +00:00
1 parent 4645015004
commit 8c3bd3c415
9 files changed
+1017 -52

No files matched your search

+167
View File
@@ -777,6 +777,155 @@ class View(Stub):
def inflate(context, resource, root):
return View(context)
# ─── 事件处理 (扩展) ───────────────────────────────────────
def onGenericMotionEvent(self, event) -> bool:
return False
def onHoverEvent(self, event) -> bool:
return False
def onDragEvent(self, event) -> bool:
return False
def onSizeChanged(self, w, h, oldw, oldh):
pass
def onFocusChanged(self, gainFocus, direction, previouslyFocusedRect):
pass
def onScrollChanged(self, l, t, oldl, oldt):
pass
def onVisibilityChanged(self, changedView, visibility):
pass
# ─── 监听器设置 (扩展) ─────────────────────────────────────
def setOnGenericMotionListener(self, listener):
self._on_generic_motion_listener = listener
return self
def setOnHoverListener(self, listener):
self._on_hover_listener = listener
return self
def setOnDragListener(self, listener):
self._on_drag_listener = listener
return self
def setOnFocusChangeListener(self, listener):
self._on_focus_change_listener = listener
return self
def setOnContextClickListener(self, listener):
self._on_context_click_listener = listener
return self
def addOnLayoutChangeListener(self, listener):
if not hasattr(self, '_layout_change_listeners'):
self._layout_change_listeners = []
self._layout_change_listeners.append(listener)
def removeOnLayoutChangeListener(self, listener):
if hasattr(self, '_layout_change_listeners'):
try:
self._layout_change_listeners.remove(listener)
except ValueError:
pass
def setOnApplyWindowInsetsListener(self, listener):
self._on_apply_window_insets_listener = listener
return self
# ─── 位置和尺寸 (扩展) ─────────────────────────────────────
def getLocationOnScreen(self, location):
location[0] = self._left if hasattr(self, '_left') else 0
location[1] = self._top if hasattr(self, '_top') else 0
def getLocationInWindow(self, location):
self.getLocationOnScreen(location)
def offsetLeftAndRight(self, offset):
if hasattr(self, '_left'):
self._left += offset
def offsetTopAndBottom(self, offset):
if hasattr(self, '_top'):
self._top += offset
def getHitRect(self, out_rect):
out_rect.left = self._left if hasattr(self, '_left') else 0
out_rect.top = self._top if hasattr(self, '_top') else 0
out_rect.right = out_rect.left + (self._width if hasattr(self, '_width') else 0)
out_rect.bottom = out_rect.top + (self._height if hasattr(self, '_height') else 0)
def getDrawingRect(self, out_rect):
out_rect.left = 0
out_rect.top = 0
out_rect.right = self._width if hasattr(self, '_width') else 0
out_rect.bottom = self._height if hasattr(self, '_height') else 0
# ─── 其他扩展方法 ──────────────────────────────────────────
def setTooltipText(self, text):
self._tooltip_text = text
def getTooltipText(self):
return getattr(self, '_tooltip_text', None)
def setTranslationZ(self, translationZ):
self._translation_z = translationZ
def getTranslationZ(self):
return getattr(self, '_translation_z', 0.0)
def setZ(self, z):
self._z = z
def getZ(self):
return getattr(self, '_z', 0.0)
def setTransitionName(self, name):
self._transition_name = name
def getTransitionName(self):
return getattr(self, '_transition_name', None)
def setClipToOutline(self, clipToOutline):
self._clip_to_outline = clipToOutline
def getClipToOutline(self):
return getattr(self, '_clip_to_outline', False)
def setFitsSystemWindows(self, fitSystemWindows):
self._fits_system_windows = fitSystemWindows
def getFitsSystemWindows(self):
return getattr(self, '_fits_system_windows', False)
def playSoundEffect(self, soundConstant):
pass
def setSaveEnabled(self, enabled):
self._save_enabled = enabled
def isSaveEnabled(self):
return getattr(self, '_save_enabled', True)
def setSystemUiVisibility(self, visibility):
self._system_ui_visibility = visibility
def getSystemUiVisibility(self):
return getattr(self, '_system_ui_visibility', 0)
def requestApplyInsets(self):
pass
def onApplyWindowInsets(self, insets):
return insets
class MeasureSpec:
"""MeasureSpec — 测量规格包装"""
@@ -2646,6 +2795,24 @@ class SurfaceTexture(Stub):
mtx[i] = 1.0 if i % 5 == 0 else 0.0
# ═══════════════════════════════════════════════════════════════
# MenuInflater
# ═══════════════════════════════════════════════════════════════
class MenuInflater(Stub):
"""MenuInflater — 菜单填充器(桌面环境桩实现)"""
def __init__(self, context=None):
super().__init__()
self._context = context
def inflate(self, menu_res: int, menu: Any):
return menu
def toString(self) -> str:
return f"MenuInflater@{hex(id(self))}"
# ═══════════════════════════════════════════════════════════════
# Window
# ═══════════════════════════════════════════════════════════════