Skip to content

Commit 5c4cf9a

Browse files
author
River@devbox
committed
Added: QSL4A sourcecode for generating document automatically
1 parent 4afb611 commit 5c4cf9a

File tree

335 files changed

+4112
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+4112
-0
lines changed

qsl4a-src/android.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#简易 SL4A 服务 : 快速 但 单实例 功能限制
2+
#by 乘着船 2021-2024
3+
4+
import os,socket as s
5+
6+
k=os.environ.get
7+
c=s.create_connection((k('AP_HOST'),k('AP_PORT'))).makefile("rw")
8+
9+
import collections
10+
from json import dumps,loads
11+
i=0
12+
w,s,c=c.write,c.flush,c.readline
13+
14+
def jsla(method,*params):
15+
global i
16+
w(dumps({'id':i,
17+
'method':method,'params':params})+'\n')
18+
s()
19+
i+=1
20+
return c()
21+
22+
jsla('_authenticate',k('AP_HANDSHAKE'))
23+
k=collections.namedtuple('Result','id,result,error')
24+
25+
def rsla(*a):
26+
return loads(jsla(*a))['result']
27+
28+
def esla(*a):
29+
r=loads(jsla(*a))
30+
if r['error']:
31+
raise Exception(r['error'])
32+
else:
33+
return r['result']
34+
35+
def nsla(*a):
36+
return k(**loads(jsla(*a)))
37+
38+
class Android:
39+
def __getattr__(self,method):
40+
def f(*params):
41+
return nsla(method,*params)
42+
setattr(self,method,f)
43+
return f
44+
droid=Android()
45+
46+
__all__=('droid','esla','rsla','jsla','os')

qsl4a-src/androidhelper/Intent.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
'Common Intent Constants , for more Intent Constants, please refer https://developer.android.google.cn/reference/android/content/Intent.html .\n\nYou can use them like droid.startActivityIntent(droid.makeIntent(action=droid.Intent.ACTION_VIEW,uri="http://www.baidu.com",flags=droid.Intent.FLAG_ACTIVITY_NEW_DOCUMENT).result) .'
2+
3+
ACTION_MAIN='android.intent.action.MAIN'
4+
ACTION_VIEW='android.intent.action.VIEW'
5+
ACTION_EDIT='android.intent.action.EDIT'
6+
ACTION_PICK='android.intent.action.PICK'
7+
ACTION_CHOOSER='android.intent.action.CHOOSER'
8+
ACTION_INSERT='android.intent.action.INSERT'
9+
ACTION_DELETE='android.intent.action.DELETE'
10+
ACTION_RUN='android.intent.action.RUN'
11+
ACTION_SEND='android.intent.action.SEND'
12+
ACTION_SYNC='android.intent.action.SYNC'
13+
ACTION_SEARCH='android.intent.action.SEARCH'
14+
15+
FLAG_ACTIVITY_SINGLE_TOP = 536870912
16+
FLAG_ACTIVITY_MULTIPLE_TASK = 134217728
17+
FLAG_ACTIVITY_NEW_DOCUMENT = 524288
18+
FLAG_ACTIVITY_CLEAR_TASK = 32768
19+
FLAG_ACTIVITY_NEW_TASK = 268435456
20+
21+
EXTRA_TEXT='android.intent.extra.TEXT'
22+
EXTRA_STREAM='android.intent.extra.STREAM'
23+
EXTRA_SUBJECT='android.intent.extra.SUBJECT'
24+
EXTRA_EMAIL='android.intent.extra.EMAIL'
25+
EXTRA_HTML_TEXT='android.intent.extra.HTML_TEXT'
26+
27+
def _intentExtras(Extras):
28+
if not isinstance(Extras,dict):
29+
return Extras
30+
for Key in Extras.keys():
31+
Val = Extras[Key]
32+
if isinstance( Val ,( bytes, bytearray )):
33+
Extras[Key]='\x00byte\x00'+_encode(Val).decode()
34+
elif isinstance( Val, str ):
35+
if Val[0:1]=='\x00':
36+
Extras[Key]='\x00str\x00'+Val
37+
elif isinstance( Extras, dict ):
38+
Extras[Key]=_intentExtras(Val)
39+
elif isinstance( Val, Uri ):
40+
Extras[Key]='\x00uri\x00'+Val
41+
return Extras
42+
43+
class _uri(str):
44+
def __new__(cls,arg):
45+
HEAD='\x00uri\x00'
46+
if arg[:5]!=HEAD:
47+
arg=HEAD+arg
48+
return super(_uri,cls).__new__(cls,arg)
49+
def __repr__(self):
50+
return 'Uri("'+self[5:]+'")'
51+
def __str__(self):
52+
return self[5:]
53+
54+
from .__init__ import Android as _encode
55+
_uri.__doc__=_encode.Uri.__doc__
56+
from base64 import b64encode as _encode
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'android.R module, include id,layout,style Constants .'
2+
class R:
3+
@property
4+
def id(self):
5+
from . import id
6+
R.id=id
7+
return id
8+
@property
9+
def layout(self):
10+
from . import layout
11+
R.layout=layout
12+
return layout
13+
@property
14+
def style(self):
15+
from . import style
16+
R.style=style
17+
return style
18+
R.__doc__=__doc__

qsl4a-src/androidhelper/R/id.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'android.R.id Constants, for more id Constants, please refer https://developer.android.google.cn/reference/android/R.id.html .'
2+
text1=16908308
3+
text2=16908309
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'android.R.layout Constants, for more layout Constants, please refer https://developer.android.google.cn/reference/android/R.layout.html .'
2+
simple_list_item_1=17367043
3+
simple_list_item_2=17367044
4+
simple_expandable_list_item_1=17367046
5+
simple_expandable_list_item_2=17367047
6+
simple_spinner_item=17367048
7+
simple_spinner_dropdown_item=17367049

qsl4a-src/androidhelper/R/style.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'android.R.style Constants, for more style Constants, please refer https://developer.android.google.cn/reference/android/R.style.html .'
2+
Default=0
3+
Theme_Black=16973832
4+
Theme_Black_NoTitleBar=16973833
5+
Theme_Black_NoTitleBar_Fullscreen=16973834
6+
Theme_Light=16973836
7+
Theme_Light_NoTitleBar=16973837
8+
Theme_Light_NoTitleBar_Fullscreen=16973838
9+
Theme_Light_Panel=16973914
10+
Theme_Wallpaper=16973918
11+
Theme_Wallpaper_NoTitleBar=16973919
12+
Theme_Wallpaper_NoTitleBar_Fullscreen=16973920
13+
Theme_Holo=16973931
14+
Theme_Holo_Wallpaper=16973949
15+
Theme_DeviceDefault_Panel=16974138
16+
Theme_DeviceDefault_Wallpaper=16974140
17+
Theme_DeviceDefault_Wallpaper_NoTitleBar=16974141
18+
TextAppearance_DeviceDefault_Large_Inverse=16974256
19+
TextAppearance_DeviceDefault_Medium_Inverse=16974258
20+
Theme_DeviceDefault_Settings=16974371

qsl4a-src/androidhelper/README.htm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<html><head><title></title><meta charset="UTF-8"></head><body>
2+
<p><font color=green>SL4A</font> = <font color=blue>Scripting Layer for Android</font> = <font color=red>安卓脚本层</font></p>
3+
<p><font color=blue>Original Author :</font><br>
4+
<font color=red>原始作者 :</font><br>
5+
<font color=green>Damon Kohler &#60;damonkohler@gmail.com&#62; at 2009</font></p>
6+
<p><font color=blue>Original Source Code :</font><br>
7+
<font color=red>原始源代码 :</font></br>
8+
<font color=green>https://github.com/damonkohler/sl4a</font></p>
9+
<p><font color=blue>QPython SL4A OpenSource Licence :</font><br>
10+
<font color=red>QPython SL4A 开源协议 :</font></br>
11+
<font color=blue>SL4A-2026 Update by 乘着船 @ bilibili at 2021-2026 .<br>
12+
<font color=red>SL4A-2026 更新 by 乘着船 @ bilibili at 2021-2026。</font><br>
13+
<font color=blue>The code updated by 乘着船 is a non-commercial license,</font><br>
14+
<font color=red>乘着船 更新的代码部分,为非商业性许可,</font><br>
15+
<font color=blue>if there is a commercial need, which requires 乘着船's consent .</font><br>
16+
<font color=red>如确有商用需求,需经 乘着船 同意,</font><br>
17+
<font color=blue>The rest of the code follows the Apache 2.0 open source license .</font><br>
18+
<font color=red>其余部分才遵循 Apache 2.0 开源协议。</p>
19+
<p><font color=blue>Apache 2.0 OpenSource Licence :</font><br>
20+
<font color=red>Apache 2.0 开源协议 :</font></br>
21+
<font color=green>http://www.apache.org/licenses/LICENSE-2.0</font></p>
22+
<p><font color=blue>New version of SL4A website :</font><br>
23+
<font color=red>新版SL4A网址 :</font><br>
24+
<font color=green>https://gitee.com/buddygr/qpython-sl4a</font></p>
25+
<p><font color=green>乘着船 @ bilibili</br>
26+
https://www.bilibili.com/space/9185070</font></p>
27+
</body></html>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from . import sl4a
2+
3+
class Android(sl4a.Android):
4+
_o=sl4a.os
5+
_l=_o.listdir
6+
_o=_o.path.isdir
7+
_g=__file__[:-11]
8+
9+
def _addMethod(_file):
10+
exec(open(__file__[:-11]+_file+'.py').read())
11+
for _i in tuple(locals()):
12+
if _i[0]=='_':
13+
continue
14+
exec(f"sl4a.Android.{_i}={_i}")
15+
locals().clear()
16+
17+
_f=_g+'fun/'
18+
for _i in _l(_f):
19+
_t=open(_f+_i).read()
20+
exec(_t)
21+
22+
_f=[_g+'doc/']
23+
while len(_f)>0:
24+
_p=_f.pop(-1)
25+
for _i in _l(_p):
26+
_t=_p+_i
27+
if _o(_t):
28+
_f.append(_t+'/')
29+
else:
30+
try:
31+
_t=open(_t).read()
32+
exec(_i[:-4]+".__doc__=_t")
33+
except:pass
34+
35+
_f=_g+'const/'
36+
for _i in _l(_f):
37+
try:
38+
_t=open(_f+_i).read().splitlines()
39+
_i=_i[:-4]
40+
_o=[eval(_i+".__doc__"),'']
41+
if _o[0]==None:
42+
_o[0]=''
43+
for _t in _t:
44+
_p=_i+"."+_t
45+
exec(_p)
46+
_o.append(_p)
47+
_o='\n'.join(_o)
48+
exec(_i+".__doc__=_o")
49+
except:pass
50+
51+
def _addMethod(_self,_file):
52+
if '_'+_file in _self.__dict__:
53+
return
54+
exec(open(__file__[:-11]+_file+'.py').read())
55+
exec(f'_self._{_file}=None')
56+
from types import MethodType as _m
57+
for _i in tuple(locals()):
58+
if _i[0]=='_':
59+
continue
60+
exec(f'_self.{_i}=_m({_i},_self)')
61+
locals().clear()
62+
63+
def _addClass(_self,_file):
64+
if '_'+_file in _self.__dict__:
65+
return
66+
exec(f'_self._{_file}=None')
67+
exec(f'from .{_file} import {_file}\n{_file}(_self)')
68+
del _self,_file
69+
70+
del _f,_i,_t,_l,_g,_o,_p
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
_c="""
2+
StartService ()
3+
Start the Accessibility Service .
4+
Return True if start successful .
5+
Return False if start failed .
6+
7+
ServiceEnabled ()
8+
Check if Accessibility Service is Enabled ,
9+
Return True or False .
10+
11+
Click ( x=0, y=0, t=50 )
12+
Accessibility Click the Screen Point with the Coordinates ( x, y ) ,
13+
Default Coordinates ( 0, 0 ) means the Center of the Screen ,
14+
The Coordinates ( x, y ) can be Integers or Decimals such as 0.5 or -1.5 ,
15+
parameter Integer t is the Press Time for Milliseconds , default is 50 .
16+
17+
Slide ( XnYn=None, t=None )
18+
Accessibility Slide the Screen with Multi Points ,
19+
XnYn is a Coordinate Set consisting of n points ( X1, Y1, X2, Y2, …… Xn, Yn ) ,
20+
Coordinates X=Y=0 means the Center of the Screen ,
21+
The Coordinates X and Y can be Integers or Decimals such as 0.5 or -1.5 ,
22+
parameter Integer t is the Slide Time for Milliseconds , default value None means 50*n ( 50n milliseconds ) .
23+
24+
Action ( actionCode )
25+
Do Accessibility Action with the designated Action Code .
26+
Return True for successful execution and False for failed execution .
27+
Some action codes are not supported by certain models .
28+
BACK = 1
29+
HOME = 2
30+
RECENTS = 3
31+
NOTIFICATIONS = 4
32+
QUICK_SETTINGS = 5
33+
POWER_DIALOG = 6
34+
TOGGLE_SPLIT_SCREEN = 7
35+
LOCK_SCREEN = 8
36+
TAKE_SCREENSHOT = 9
37+
KEYCODE_HEADSETHOOK = 10
38+
ACCESSIBILITY_BUTTON = 11
39+
ACCESSIBILITY_BUTTON_CHOOSER = 12
40+
ACCESSIBILITY_SHORTCUT = 13
41+
ACCESSIBILITY_ALL_APPS = 14
42+
DISMISS_NOTIFICATION_SHADE = 15
43+
DPAD_UP = 16
44+
DPAD_DOWN = 17
45+
DPAD_LEFT = 18
46+
DPAD_RIGHT = 19
47+
DPAD_CENTER = 20
48+
MENU = 21
49+
MEDIA_PLAY_PAUSE = 22
50+
"""
51+
52+
for _c in _c[1:-1].split('\n\n'):
53+
_c='accessibility'+_c
54+
_e=_c.find(' (')
55+
_d=_c[:_e]
56+
_e=_c[_e+2:_c.find(')')]
57+
_b=[]
58+
for _a in _e.split(","):
59+
_b.append(_a.split("=")[0])
60+
_b=",".join(_b)
61+
exec(f'''
62+
def {_d}(self,{_e}):
63+
return self._rpc("{_d}",{_b})
64+
{_d}.__doc__=_c
65+
''')
66+
67+
for _e in _c.split("\n"):
68+
if _e.find('=')>0:
69+
exec(f"{_d}.{_e}")
70+
71+
del _a,_b,_c,_d,_e

qsl4a-src/androidhelper/battery.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
_doc_='''batteryStartMonitoring()
2+
3+
batteryStopMonitoring()
4+
Stops tracking battery state.
5+
6+
batteryCheckPresent()
7+
Returns the most recently received battery presence data.
8+
9+
batteryGetHealth()
10+
Returns the most recently received battery health data:1 - unknown;2 - good;3 - overheat;4 - dead;5 - over voltage;6 - unspecified failure;
11+
12+
batteryGetLevel()
13+
Returns the most recently received battery level (percentage).
14+
15+
batteryGetPlugType()
16+
Returns the most recently received plug type data:
17+
-1 - unknown;
18+
0 - unplugged;
19+
1 - power source is an AC charger;
20+
2 - power source is a USB port
21+
22+
batteryGetStatus()
23+
Returns the most recently received battery status data:1 - unknown;2 - charging;3 - discharging;4 - not charging;5 - full;
24+
25+
batteryGetTechnology()
26+
Returns the most recently received battery technology data.
27+
28+
batteryGetTemperature()
29+
Returns the most recently received battery temperature.
30+
31+
batteryGetVoltage()
32+
Returns the most recently received battery voltage mV .
33+
34+
readBatteryData()
35+
Returns the most recently recorded battery data.
36+
37+
batteryGetCurrent()
38+
Returns the most recently received battery Current mA .
39+
40+
batteryGetCharge()
41+
Returns the most recently received battery Charge Counter μAh .
42+
'''
43+
44+
_g=_doc_.split('\n\n')
45+
46+
for _t in _g:
47+
_i=_t[:_t.find('(')]
48+
exec(f'def {_i}(self):return self._rpc("{_i}")')
49+
if _t.find('\n')==-1:
50+
_t=eval(f'_self.{_i}.__doc__')
51+
exec(f"{_i}.__doc__=_t")
52+
53+
del _g,_i,_t,_doc_

0 commit comments

Comments
 (0)