diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-05-19 20:27:09 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-05-19 20:27:09 -0400 |
| commit | 42b31e7bf70f2cdb13cec3312d1cc262cd3ced6b (patch) | |
| tree | 4ebb233e1386cf477a3d6f59c2bed5f2625470cf /hello.hy | |
Initial commit
Diffstat (limited to 'hello.hy')
| -rw-r--r-- | hello.hy | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/hello.hy b/hello.hy new file mode 100644 index 0000000..25e3b2d --- /dev/null +++ b/hello.hy @@ -0,0 +1,47 @@ +;; Hello Example +;; ============= +;; +;; This is a simple "Hello world!" example, written in Hy. +;; +;; We begin by declaring a unique namespace for the package we are creating. +;; This is typically based on the reversed form of a domain name and should be +;; unique to this package. + +(setv __package__ "com.example.hellohy") + +;; We also import the classes that will be needed by the application. Since this +;; is a simple example, we only need three of them. + +(import [android.app [Activity]]) +(import [android.os [Bundle]]) +(import [android.widget [TextView]]) + +;; We define a class based on the standard Activity class. This represents the +;; application, and will be used to present a graphical interface to the user. +;; +;; The initialisation method simply calls the corresponding method in the base +;; class. This must be done even if no other code is included in the method. + +(defclass HelloActivity [Activity] + (defn __init__ [self] + (.__init__ Activity self)) + + ;; The onCreate method is called when the activity is created by Android. The + ;; return type and parameter types expected by the method are declared using + ;; the following decorator. Since the parameter types for the onCreate method + ;; are defined in the Activity base class, this decorator is not strictly + ;; necessary. + (with-decorator (args void [Bundle]) + (defn onCreate [self bundle] + (.onCreate Activity self bundle) + (setv view (TextView self)) + (.setText view "Hello world!") + (.setContentView self view) + (return None)))) + +;; As with the `__init__` method, we must call the corresponding method in the +;; base class. +;; +;; The user interface for the application is simply a TextView widget that +;; displays a string of text. The final call ensures that the widget is used as +;; the main view for the application. |