-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview1.lua
245 lines (213 loc) · 7.92 KB
/
view1.lua
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
local json = require( "json" )
local native = require( "native" )
local widget = require( "widget" )
local composer = require( "composer" )
local OneSignal = require( "plugin.OneSignal" )
local scene = composer.newScene()
function GetYSpacingFromButton( button, padding )
return button.y + button.height + padding
end
function scene:create( event )
local sceneGroup = self.view
-- Called when the scene's view does not exist.
--
-- INSERT code here to initialize the scene
-- e.g. add display objects to 'sceneGroup', add touch listeners, etc.
-- create a white background to fill screen
local background = display.newRect( display.contentCenterX, display.contentCenterY, display.contentWidth, 1000 )
background:setFillColor( 1 ) -- white
local textOptions = {
text = "",
width = 280,
fontSize = 14,
align = "left" -- Alignment parameter
}
local textBox = display.newText( textOptions )
textBox.anchorX = 0
textBox.anchorY = 0
textBox.x = 24;
textBox:setFillColor( 0, 0, 0 )
-- Send tags event handler
local buttonHandlerSendTags = function( event )
-- Send a single tag in key, value fashion
OneSignal.SendTag( "CoronaTag1", "value1" )
-- Send several tags at once using a table
local tagsTable = {["CoronaTag2"] = "value2", ["CoronaTag3"] = "value3"}
OneSignal.SendTags( tagsTable )
textBox.text = "Sent tags\nCoronaTag1, value1\n['CoronaTag2'] = 'value2', ['CoronaTag3'] = 'value3'"
OneSignal.RegisterForNotifications();
end
local getTagsCallback = function ( tags )
local tagsString = json.encode(tags);
textBox.text = tagsString
print("TAGS: " .. tagsString)
end
local buttonHandlerGetTags = function( event )
-- Send a single tag in key, value fashion
OneSignal.GetTags( getTagsCallback )
end
-- START: OneSignal Logo
-- Create a vector rectangle
local oneSignalLogo = display.newRect( 0, 0, 140, 140 )
-- Set the fill (paint) to use the bitmap image
local oneSignalLogoPaint = {
type = "image",
filename = "onesignal.png"
}
-- Fill the circle
oneSignalLogo.fill = oneSignalLogoPaint
oneSignalLogo.x = display.contentCenterX; oneSignalLogo.y = 80;
-- END: OneSignal Logo
-- START: Send tags button
local sendTagsButton = widget.newButton(
{
label = "Send Tags",
emboss = true,
shape = "roundedRect",
width = 280,
height = 40,
cornerRadius = 4,
fillColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeWidth = 0,
labelColor = { default={ 1, 1, 1, 1 }, over={ 1, 1, 1, 1 } }
}
)
sendTagsButton:addEventListener( "tap", buttonHandlerSendTags )
sendTagsButton.x = display.contentCenterX; sendTagsButton.y = oneSignalLogo.y + 88;
-- END: Send tags button
-- START: Get tags button
local getTagsButton = widget.newButton(
{
label = "Get Tags",
emboss = true,
shape = "roundedRect",
width = 280,
height = 40,
cornerRadius = 4,
fillColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeWidth = 0,
labelColor = { default={ 1, 1, 1, 1 }, over={ 1, 1, 1, 1 } }
}
)
getTagsButton:addEventListener( "tap", buttonHandlerGetTags )
getTagsButton.x = display.contentCenterX; getTagsButton.y = GetYSpacingFromButton(sendTagsButton, 12);
-- END: Get tags button
-- START: Add trigger key text field
local addTriggerKeyTextField = native.newTextField( 24, 0, 130, 30 )
addTriggerKeyTextField.anchorX = 0
addTriggerKeyTextField.text = "key"
addTriggerKeyTextField.size = 16
addTriggerKeyTextField.y = GetYSpacingFromButton(getTagsButton, 12);
addTriggerKeyTextField:resizeHeightToFitFont()
-- END: Add trigger key text field
-- START: Add trigger value text field
local addTriggerValueTextField = native.newTextField( 0, 0, 130, 30 )
addTriggerValueTextField.anchorX = 0
addTriggerValueTextField.text = "value"
addTriggerValueTextField.size = 16
addTriggerValueTextField.x = addTriggerKeyTextField.width + 38
addTriggerValueTextField.y = GetYSpacingFromButton(getTagsButton, 12);
addTriggerValueTextField:resizeHeightToFitFont()
-- END: Add trigger value text field
local buttonHandlerAddTrigger = function( event )
-- Add a trigger in key, value fashion
OneSignal.AddTrigger( addTriggerKeyTextField.text, addTriggerValueTextField.text )
local addTriggerString = "Adding Trigger Key: " .. addTriggerKeyTextField.text .. " Value: " .. addTriggerValueTextField.text
textBox.text = addTriggerString
print(addTriggerString)
end
-- START: Add trigger button
local addTriggerButton = widget.newButton(
{
label = "Add Trigger",
emboss = true,
shape = "roundedRect",
width = 280,
height = 40,
cornerRadius = 4,
fillColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeWidth = 0,
labelColor = { default={ 1, 1, 1, 1 }, over={ 1, 1, 1, 1 } }
}
)
addTriggerButton:addEventListener( "tap", buttonHandlerAddTrigger )
addTriggerButton.x = display.contentCenterX; addTriggerButton.y = GetYSpacingFromButton(addTriggerKeyTextField, 12);
-- END: Add trigger button
-- START: Add trigger key text field
local removeTriggerKeyTextField = native.newTextField( 0, 0, 272, 30 )
removeTriggerKeyTextField.text = "key"
removeTriggerKeyTextField.size = 16
removeTriggerKeyTextField.x = display.contentCenterX
removeTriggerKeyTextField.y = GetYSpacingFromButton(addTriggerButton, 12)
removeTriggerKeyTextField:resizeHeightToFitFont()
-- END: Add trigger key text field
local buttonHandlerRemoveTrigger = function( event )
-- Remove a single trigger with key
OneSignal.RemoveTriggerForKey( removeTriggerKeyTextField.text )
local removeTriggerString = "Removing Trigger Key: " .. removeTriggerKeyTextField.text
textBox.text = removeTriggerString
print(removeTriggerString)
end
-- START: Remove trigger button
local removeTriggerButton = widget.newButton(
{
label = "Remove Trigger",
emboss = true,
shape = "roundedRect",
width = 280,
height = 40,
cornerRadius = 4,
fillColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeColor = { default={ 0.9, 0.3, 0.3, 1 }, over={ 0.8, 0.3, 0.3, 1 } },
strokeWidth = 0,
labelColor = { default={ 1, 1, 1, 1 }, over={ 1, 1, 1, 1 } }
}
)
removeTriggerButton:addEventListener( "tap", buttonHandlerRemoveTrigger )
removeTriggerButton.x = display.contentCenterX; removeTriggerButton.y = GetYSpacingFromButton(removeTriggerKeyTextField, 12);
-- END: Remove trigger button
-- Set texBox below lowest view element
textBox.y = GetYSpacingFromButton(removeTriggerButton, 0);
-- all objects must be added to group (e.g. self.view)
sceneGroup:insert( background )
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is still off screen and is about to move on screen
elseif phase == "did" then
-- Called when the scene is now on screen
--
-- INSERT code here to make the scene come alive
-- e.g. start timers, begin animation, play audio, etc.
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
-- Called when the scene is on screen and is about to move off screen
--
-- INSERT code here to pause the scene
-- e.g. stop timers, stop animation, unload sounds, etc.)
elseif phase == "did" then
-- Called when the scene is now off screen
end
end
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's "view" (sceneGroup)
--
-- INSERT code here to cleanup the scene
-- e.g. remove display objects, remove touch listeners, save state, etc.
end
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
return scene