|
| 1 | +#qpy:quiet |
| 2 | +#-*-coding:utf8;-*- |
| 3 | +""" |
| 4 | +This is a sample project which use SL4A UI Framework, |
| 5 | +There is another Sample project: https://github.com/qpython-android/qpy-calcount |
| 6 | +""" |
| 7 | +import qpy |
| 8 | +import androidhelper |
| 9 | +import urllib.request as ur |
| 10 | +from qsl4ahelper.fullscreenwrapper2 import * |
| 11 | + |
| 12 | +droid = androidhelper.Android() |
| 13 | + |
| 14 | +class MainScreen(Layout): |
| 15 | + def __init__(self): |
| 16 | + super(MainScreen,self).__init__(str("""<?xml version="1.0" encoding="utf-8"?> |
| 17 | +<LinearLayout |
| 18 | + android:layout_width="fill_parent" |
| 19 | + android:layout_height="fill_parent" |
| 20 | + android:background="#ff0E4200" |
| 21 | + android:orientation="vertical" |
| 22 | + xmlns:android="http://schemas.android.com/apk/res/android"> |
| 23 | + <ImageView |
| 24 | + android:id="@+id/logo" |
| 25 | + android:layout_width="fill_parent" |
| 26 | + android:layout_height="0px" |
| 27 | + android:layout_weight="10" |
| 28 | + /> |
| 29 | + <LinearLayout |
| 30 | + android:layout_width="fill_parent" |
| 31 | + android:layout_height="0px" |
| 32 | + android:orientation="horizontal" |
| 33 | + android:layout_weight="20"> |
| 34 | + |
| 35 | + <TextView |
| 36 | + android:layout_width="fill_parent" |
| 37 | + android:layout_height="fill_parent" |
| 38 | + android:textSize="8dp" |
| 39 | + android:text="Hello, QPython" |
| 40 | + android:textColor="#ffffffff" |
| 41 | + android:layout_weight="1" |
| 42 | + android:gravity="center" |
| 43 | + /> |
| 44 | + </LinearLayout> |
| 45 | + |
| 46 | + <ListView |
| 47 | + android:id="@+id/data_list" |
| 48 | + android:layout_width="fill_parent" |
| 49 | + android:layout_height="0px" |
| 50 | + android:layout_weight="55"/> |
| 51 | + |
| 52 | + <LinearLayout |
| 53 | + android:layout_width="fill_parent" |
| 54 | + android:layout_height="0px" |
| 55 | + android:orientation="horizontal" |
| 56 | + android:layout_weight="8"> |
| 57 | + <Button |
| 58 | + android:layout_width="fill_parent" |
| 59 | + android:layout_height="fill_parent" |
| 60 | + android:text="Load" |
| 61 | + android:id="@+id/but_load" |
| 62 | + android:textSize="8dp" |
| 63 | + android:background="#ffEFC802" |
| 64 | + android:textColor="#ffffffff" |
| 65 | + android:layout_weight="1" |
| 66 | + android:gravity="center"/> |
| 67 | + <Button |
| 68 | + android:layout_width="fill_parent" |
| 69 | + android:layout_height="fill_parent" |
| 70 | + android:text="Exit" |
| 71 | + android:id="@+id/but_exit" |
| 72 | + android:textSize="8dp" |
| 73 | + android:background="#ff06AF00" |
| 74 | + android:textColor="#ffffffff" |
| 75 | + android:layout_weight="1" |
| 76 | + android:gravity="center"/> |
| 77 | + </LinearLayout> |
| 78 | +</LinearLayout> |
| 79 | +"""),"SL4AApp") |
| 80 | + |
| 81 | + def on_show(self): |
| 82 | + self.views.but_exit.add_event(click_EventHandler(self.views.but_exit, self.exit)) |
| 83 | + self.views.but_load.add_event(click_EventHandler(self.views.but_load, self.load)) |
| 84 | + |
| 85 | + pass |
| 86 | + |
| 87 | + def on_close(self): |
| 88 | + pass |
| 89 | + |
| 90 | + def load(self, view, dummy): |
| 91 | + droid = FullScreenWrapper2App.get_android_instance() |
| 92 | + droid.makeToast("Load") |
| 93 | + |
| 94 | + saved_logo = qpy.tmp+"/qpy.logo" |
| 95 | + ur.urlretrieve("https://www.qpython.org/static/img_logo.png", saved_logo) |
| 96 | + self.views.logo.src = "file://"+saved_logo |
| 97 | + |
| 98 | + def exit(self, view, dummy): |
| 99 | + droid = FullScreenWrapper2App.get_android_instance() |
| 100 | + droid.makeToast("Exit") |
| 101 | + FullScreenWrapper2App.close_layout() |
| 102 | + |
| 103 | +if __name__ == '__main__': |
| 104 | + FullScreenWrapper2App.initialize(droid) |
| 105 | + FullScreenWrapper2App.show_layout(MainScreen()) |
| 106 | + FullScreenWrapper2App.eventloop() |
0 commit comments