Skip to content

Commit dcc81b3

Browse files
committed
Add PyAndroid documentation for CPython
1 parent 161b306 commit dcc81b3

File tree

1 file changed

+239
-0
lines changed

1 file changed

+239
-0
lines changed

Doc/library/pyandroid.rst

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
:mod:`pyandroid` --- Python Android Development Library
2+
=======================================================
3+
4+
.. module:: pyandroid
5+
:synopsis: Python library for Android application development
6+
7+
.. moduleauthor:: Subhobhai <[email protected]>
8+
9+
**Source code:** `PyAndroid GitHub Repository <https://github.com/subhobhai943/pyandroid-dev>`_
10+
11+
--------------
12+
13+
The :mod:`pyandroid` module provides a comprehensive Python library for Android application
14+
development with cross-platform capabilities. It offers a Pythonic interface for building
15+
Android applications using familiar Python patterns and paradigms.
16+
17+
Overview
18+
--------
19+
20+
PyAndroid enables Python developers to create Android applications without needing to learn
21+
Java or Kotlin. The library provides:
22+
23+
* Core Android components (Activities, Intents, Application lifecycle)
24+
* Complete UI framework (Views, Layouts, Widgets)
25+
* Utility classes (Logger, FileManager, NetworkManager)
26+
* Cross-platform compatibility
27+
* Extensible architecture
28+
29+
Installation
30+
------------
31+
32+
The PyAndroid library can be installed via pip::
33+
34+
pip install pyandroid-dev
35+
36+
Basic Usage
37+
-----------
38+
39+
Creating a Simple Android Application
40+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
42+
::
43+
44+
from pyandroid import AndroidApp, Activity
45+
from pyandroid.ui import LinearLayout, Widget
46+
47+
class MainActivity(Activity):
48+
def __init__(self):
49+
super().__init__("MainActivity")
50+
51+
def on_start(self):
52+
layout = LinearLayout("main_layout")
53+
54+
text_view = Widget.create_text_view(
55+
"hello_text",
56+
"Hello from PyAndroid!"
57+
)
58+
59+
button = Widget.create_button(
60+
"click_btn",
61+
"Click Me",
62+
on_click=lambda v: print("Button clicked!")
63+
)
64+
65+
layout.add_view(text_view)
66+
layout.add_view(button)
67+
self.add_view("main_layout", layout)
68+
69+
# Create and run the application
70+
app = AndroidApp("HelloApp", "com.example.hello")
71+
app.register_activity("main", MainActivity)
72+
app.start_activity("main")
73+
app.run()
74+
75+
Core Classes
76+
------------
77+
78+
.. class:: AndroidApp(app_name, package_name)
79+
80+
Main Android Application class that manages the application lifecycle
81+
and global state.
82+
83+
.. method:: register_activity(activity_name, activity_class)
84+
85+
Register an activity with the application.
86+
87+
.. method:: start_activity(activity_name, **kwargs)
88+
89+
Start a specific activity by name.
90+
91+
.. method:: run()
92+
93+
Run the Android application.
94+
95+
.. class:: Activity(name)
96+
97+
Base class representing a single screen in an Android application.
98+
99+
.. method:: on_start()
100+
101+
Called when the activity starts. Override in subclasses.
102+
103+
.. method:: on_resume()
104+
105+
Called when the activity resumes. Override in subclasses.
106+
107+
.. method:: on_pause()
108+
109+
Called when the activity pauses. Override in subclasses.
110+
111+
.. method:: add_view(view_id, view)
112+
113+
Add a view to this activity.
114+
115+
.. method:: get_view(view_id)
116+
117+
Get a view by its ID.
118+
119+
UI Framework
120+
------------
121+
122+
The PyAndroid UI framework provides a complete set of components for building
123+
user interfaces:
124+
125+
.. class:: View(view_id, width=0, height=0)
126+
127+
Base class for all UI views.
128+
129+
.. method:: set_position(x, y)
130+
131+
Set the view's position on screen.
132+
133+
.. method:: set_size(width, height)
134+
135+
Set the view's dimensions.
136+
137+
.. method:: set_on_click_listener(callback)
138+
139+
Set a function to call when the view is clicked.
140+
141+
.. class:: TextView(view_id, text="", **kwargs)
142+
143+
A view for displaying text.
144+
145+
.. method:: set_text(text)
146+
147+
Set the text content.
148+
149+
.. method:: set_text_color(color)
150+
151+
Set the text color using hex color codes.
152+
153+
.. class:: Button(view_id, text="Button", **kwargs)
154+
155+
A button widget that extends TextView.
156+
157+
.. class:: EditText(view_id, hint="", **kwargs)
158+
159+
A text input field.
160+
161+
.. method:: get_text()
162+
163+
Get the current input text.
164+
165+
Layouts
166+
-------
167+
168+
.. class:: LinearLayout(layout_id, orientation="vertical")
169+
170+
A layout that arranges child views in a single direction.
171+
172+
.. method:: add_view(view)
173+
174+
Add a child view to the layout.
175+
176+
.. method:: find_view_by_id(view_id)
177+
178+
Find a child view by its ID.
179+
180+
Utility Classes
181+
---------------
182+
183+
.. class:: Logger(name, level="INFO")
184+
185+
Enhanced logging utility for Android applications.
186+
187+
.. method:: info(message, **kwargs)
188+
189+
Log an informational message.
190+
191+
.. method:: error(message, **kwargs)
192+
193+
Log an error message.
194+
195+
.. class:: FileManager(app_name)
196+
197+
File and storage management utility.
198+
199+
.. method:: write_file(filename, content, subdir="")
200+
201+
Write content to a file.
202+
203+
.. method:: save_json(filename, data, subdir="")
204+
205+
Save data as a JSON file.
206+
207+
.. method:: load_json(filename, subdir="")
208+
209+
Load data from a JSON file.
210+
211+
.. class:: NetworkManager(app_name, timeout=30)
212+
213+
Network and HTTP utility for Android applications.
214+
215+
.. method:: get(url, headers=None)
216+
217+
Make an HTTP GET request.
218+
219+
.. method:: post_json(url, data, headers=None)
220+
221+
Make an HTTP POST request with JSON data.
222+
223+
.. method:: is_connected(test_url="https://www.google.com")
224+
225+
Check if internet connection is available.
226+
227+
Examples
228+
--------
229+
230+
For more comprehensive examples, see the `PyAndroid Examples Directory
231+
<https://github.com/subhobhai943/pyandroid-dev/tree/main/examples>`_.
232+
233+
See Also
234+
--------
235+
236+
* :mod:`tkinter` --- Python's de-facto standard GUI package
237+
* :mod:`logging` --- Logging facility for Python
238+
* :mod:`json` --- JSON encoder and decoder
239+
* :mod:`urllib` --- URL handling modules

0 commit comments

Comments
 (0)