1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org>
;;;
;;; This program is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU General Public License as
;;; published by the Free Software Foundation; either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
;; 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.
;; 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.
|