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:
1 parent
4645015004
commit
8c3bd3c415
9 files changed
+1017
-52
No files matched your search
@@ -743,6 +743,86 @@ class Context(Stub):
|
||||
def toString(self) -> str:
|
||||
return f"Context{{{self._package_name}}}"
|
||||
|
||||
# ─── 文件流 / 权限 (扩展) ─────────────────────────────────
|
||||
|
||||
def openFileInput(self, name):
|
||||
path = os.path.join(self.getFilesDir(), name)
|
||||
return open(path, 'rb')
|
||||
|
||||
def openFileOutput(self, name, mode):
|
||||
path = os.path.join(self.getFilesDir(), name)
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
return open(path, 'wb')
|
||||
|
||||
def getFileStreamPath(self, name):
|
||||
from ..java.io import File
|
||||
return File(self.getFilesDir(), name)
|
||||
|
||||
def grantUriPermission(self, toPackage, uri, modeFlags):
|
||||
pass
|
||||
|
||||
def revokeUriPermission(self, uri, modeFlags):
|
||||
pass
|
||||
|
||||
def checkUriPermission(self, uri, pid, uid, modeFlags):
|
||||
return 0 # PERMISSION_GRANTED
|
||||
|
||||
def checkPermission(self, permission, pid, uid):
|
||||
return 0 # PERMISSION_GRANTED
|
||||
|
||||
def enforceUriPermission(self, uri, pid, uid, modeFlags, message):
|
||||
pass
|
||||
|
||||
# ─── 资源 / 主题 (扩展) ───────────────────────────────────
|
||||
|
||||
def getApplicationInfo(self):
|
||||
from .content_pm import ApplicationInfo
|
||||
return ApplicationInfo()
|
||||
|
||||
def getTheme(self):
|
||||
return getattr(self, '_theme', 0)
|
||||
|
||||
def setTheme(self, resid):
|
||||
self._theme = resid
|
||||
|
||||
def getText(self, resId):
|
||||
return str(resId)
|
||||
|
||||
def getQuantityString(self, resId, quantity, *formatArgs):
|
||||
return str(resId)
|
||||
|
||||
def getStringArray(self, resId):
|
||||
return []
|
||||
|
||||
def getTextArray(self, resId):
|
||||
return []
|
||||
|
||||
def getIntArray(self, resId):
|
||||
return []
|
||||
|
||||
# ─── Context 派生 / 回调 (扩展) ───────────────────────────
|
||||
|
||||
def createConfigurationContext(self, overrideConfiguration):
|
||||
return Context()
|
||||
|
||||
def createDisplayContext(self, display):
|
||||
return Context()
|
||||
|
||||
def registerComponentCallbacks(self, callback):
|
||||
pass
|
||||
|
||||
def unregisterComponentCallbacks(self, callback):
|
||||
pass
|
||||
|
||||
def getExternalStoragePublicDirectory(self, type_):
|
||||
from ..java.io import File
|
||||
from .os import Environment
|
||||
return Environment.getExternalStoragePublicDirectory(type_)
|
||||
|
||||
def getDisplayMetrics(self):
|
||||
from .util import DisplayMetrics
|
||||
return DisplayMetrics()
|
||||
|
||||
|
||||
class ContextWrapper(Context):
|
||||
"""ContextWrapper — Context 的包装器"""
|
||||
|
||||
Reference in new issue
Block a user