Skip to content

Commit be18881

Browse files
committed
Remove Rubicon from Android
1 parent 24d451f commit be18881

File tree

3 files changed

+39
-37
lines changed

3 files changed

+39
-37
lines changed

apps/android_pythonnative_3/app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ android {
2222
python {
2323
pip {
2424
install "matplotlib"
25-
install "rubicon-java"
2625
}
2726
}
2827
}

apps/android_pythonnative_3/app/src/main/java/com/pythonnative/pythonnative/MainActivity.kt

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,45 @@ class MainActivity : AppCompatActivity() {
2727
if (!Python.isStarted()) {
2828
Python.start(AndroidPlatform(this))
2929
}
30-
3130
val py = Python.getInstance()
31+
val createButtonModule = py.getModule("create_button")
32+
val pyButton = createButtonModule.callAttr("create_button", this).toJava(Button::class.java)
33+
val layoutMain = findViewById<ConstraintLayout>(R.id.layout_main)
34+
layoutMain.addView(pyButton)
3235

33-
// Generate UI from Python
34-
val uiLayoutModule = py.getModule("ui_layout")
35-
val layoutJson = uiLayoutModule.callAttr("generate_layout").toString()
36-
val layout = JSONObject(layoutJson)
37-
val widgets = layout.getJSONArray("widgets")
38-
39-
for (i in 0 until widgets.length()) {
40-
val widget = widgets.getJSONObject(i)
41-
when (widget.getString("type")) {
42-
"Button" -> {
43-
val button = Button(this)
44-
button.text = widget.getJSONObject("properties").getString("text")
45-
button.setTextColor(Color.parseColor(widget.getJSONObject("properties").getString("textColor")))
46-
button.setBackgroundColor(Color.parseColor(widget.getJSONObject("properties").getString("backgroundColor")))
36+
// TODO: Run python module and get button
4737

48-
if (widget.has("eventHandlers") && widget.getJSONObject("eventHandlers").has("onClick")) {
49-
val onClickFunctionName = widget.getJSONObject("eventHandlers").getString("onClick")
50-
val onClickFunction = py.getModule("ui_layout").get(onClickFunctionName)
51-
52-
button.setOnClickListener {
53-
onClickFunction?.call()
54-
}
55-
}
56-
57-
// Add button to your layout here
58-
val layoutMain = findViewById<ConstraintLayout>(R.id.layout_main)
59-
layoutMain.addView(button)
60-
}
61-
// Handle other widget types...
62-
}
63-
}
38+
// Generate UI from Python
39+
// val uiLayoutModule = py.getModule("ui_layout")
40+
// val layoutJson = uiLayoutModule.callAttr("generate_layout").toString()
41+
// val layout = JSONObject(layoutJson)
42+
// val widgets = layout.getJSONArray("widgets")
43+
//
44+
// for (i in 0 until widgets.length()) {
45+
// val widget = widgets.getJSONObject(i)
46+
// when (widget.getString("type")) {
47+
// "Button" -> {
48+
// val button = Button(this)
49+
// button.text = widget.getJSONObject("properties").getString("text")
50+
// button.setTextColor(Color.parseColor(widget.getJSONObject("properties").getString("textColor")))
51+
// button.setBackgroundColor(Color.parseColor(widget.getJSONObject("properties").getString("backgroundColor")))
52+
//
53+
// if (widget.has("eventHandlers") && widget.getJSONObject("eventHandlers").has("onClick")) {
54+
// val onClickFunctionName = widget.getJSONObject("eventHandlers").getString("onClick")
55+
// val onClickFunction = py.getModule("ui_layout").get(onClickFunctionName)
56+
//
57+
// button.setOnClickListener {
58+
// onClickFunction?.call()
59+
// }
60+
// }
61+
//
62+
// // Add button to your layout here
63+
// val layoutMain = findViewById<ConstraintLayout>(R.id.layout_main)
64+
// layoutMain.addView(button)
65+
// }
66+
// // Handle other widget types...
67+
// }
68+
// }
6469

6570
// Existing code for displaying plot
6671
// val imageView = findViewById<ImageView>(R.id.image_home)
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from rubicon.java import JavaClass
2-
3-
Button = JavaClass("android/widget/Button")
1+
from java import cast, chaquopy, dynamic_proxy, jarray, jclass
42

53

64
def create_button(context):
5+
Button = jclass("android.widget.Button")
76
button = Button(context)
8-
button.setId(hash(button))
97
button.setText("Button created in Python")
10-
return button.getId()
8+
return button

0 commit comments

Comments
 (0)