-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
127 lines (95 loc) · 2.72 KB
/
main.go
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"fmt"
"log"
"math/rand"
"runtime/debug"
"github.com/seletskiy/go-android-rpc/android"
"github.com/zazab/zhash"
"github.com/seletskiy/go-android-rpc/android/sdk"
// required for linking
_ "github.com/seletskiy/go-android-rpc/android/modules"
)
type AccelerometerHandler struct {
text sdk.TextView
}
func (handler AccelerometerHandler) OnChange(values []float64) {
handler.text.SetText1s(fmt.Sprintf(
"% 3.2f\n% 3.2f\n% 3.2f", values[0], values[1], values[2],
))
}
func (handler AccelerometerHandler) OnAccuracyChange() {}
type ButtonHandler struct {
button sdk.Button
accelerometerId string
}
func (handler ButtonHandler) OnClick() {
texts := []string{
"oh, hellu there!",
"you are my frrrend",
"wow, it is you agan",
"wow, really wow!",
}
handler.button.PerformHapticFeedback(0)
handler.button.SetText1s(texts[rand.Intn(len(texts))])
result, err := handler.button.IsShown()
log.Printf("%#v", result)
log.Printf("%#v", err)
android.OpenWebPage("http://github.com/seletskiy/go-android-rpc/")
android.UnsubscribeToSensorValues(
handler.accelerometerId,
)
//android.ChangeLayout("another_layout")
}
func (handler ButtonHandler) OnTouch() android.PayloadType {
texts := []string{
`/\/\/\/\/\/\/\/\`,
`\/\/\/\/\/\/\/\/`,
}
handler.button.PerformHapticFeedback(0)
handler.button.SetText1s(texts[rand.Intn(len(texts))])
// wow, it will be returned as OnTouch result in Java!
return false
}
func start() {
sensors := zhash.HashFromMap(android.GetSensorsList())
accelDisplay := android.GetViewById("useless_accel").(sdk.TextView)
accelDisplay.SetTextSize(40.0)
layout := zhash.HashFromMap(android.GetLayoutById("main_layout"))
layout_id, err := layout.GetString(
"layout_id",
)
if err != nil {
panic(err)
}
accelerometerId, err := sensors.GetString(
"sensors", "TYPE_ACCELEROMETER",
)
touchButton := android.GetViewById("useless_touch_button").(sdk.Button)
android.OnTouch(touchButton, ButtonHandler{touchButton, accelerometerId})
if err != nil {
panic(err)
}
android.SubscribeToSensorValues(
accelerometerId,
AccelerometerHandler{accelDisplay},
)
newView := android.CreateView("123", "android.widget.Button").(sdk.Button)
newView.SetText1s("I'm generated!")
android.OnClick(newView, ButtonHandler{newView, accelerometerId})
android.AttachView(newView, layout_id)
a := android.GetViewById("123")
log.Printf("main.go:102 %#v", a)
newTextEdit := android.CreateView("124", "android.widget.EditText").(sdk.EditText)
android.AttachView(newTextEdit, layout_id)
newTextEdit.SetText1s("123123")
}
func main() {
defer func() {
err := recover()
log.Printf("PANIC %s", err)
log.Print(string(debug.Stack()))
}()
android.OnStart(start)
android.Enter()
}