This repository has been archived by the owner on May 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
MainDynamicLinks.as
355 lines (279 loc) · 10.2 KB
/
MainDynamicLinks.as
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package
{
import com.doitflash.consts.Direction;
import com.doitflash.consts.Orientation;
import com.doitflash.mobileProject.commonCpuSrc.DeviceInfo;
import com.doitflash.starling.utils.list.List;
import com.doitflash.text.modules.MySprite;
import flash.desktop.NativeApplication;
import flash.desktop.SystemIdleMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.InvokeEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import flash.ui.Keyboard;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import com.luaye.console.C;
import com.myflashlab.air.extensions.dependency.OverrideAir;
import com.myflashlab.air.extensions.firebase.core.*;
import com.myflashlab.air.extensions.firebase.dynamicLinks.*;
/**
* ...
* @author Hadi Tavakoli - 1/4/2017 4:04 PM
*/
public class MainDynamicLinks extends Sprite
{
private var _deepLink:String;
private var _deepLinkShort:String;
private const BTN_WIDTH:Number = 150;
private const BTN_HEIGHT:Number = 60;
private const BTN_SPACE:Number = 2;
private var _txt:TextField;
private var _body:Sprite;
private var _list:List;
private var _numRows:int = 1;
public function MainDynamicLinks():void
{
Multitouch.inputMode = MultitouchInputMode.GESTURE;
NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate);
NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate);
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys);
stage.addEventListener(Event.RESIZE, onResize);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
C.startOnStage(this, "`");
C.commandLine = false;
C.commandLineAllowed = false;
C.x = 20;
C.width = 250;
C.height = 150;
C.strongRef = true;
C.visible = true;
C.scaleX = C.scaleY = DeviceInfo.dpiScaleMultiplier;
_txt = new TextField();
_txt.autoSize = TextFieldAutoSize.LEFT;
_txt.antiAliasType = AntiAliasType.ADVANCED;
_txt.multiline = true;
_txt.wordWrap = true;
_txt.embedFonts = false;
_txt.htmlText = "<font face='Arimo' color='#333333' size='20'><b>Firebase Dynamic Links V"+DynamicLinks.VERSION+"</font>";
_txt.scaleX = _txt.scaleY = DeviceInfo.dpiScaleMultiplier;
this.addChild(_txt);
_body = new Sprite();
this.addChild(_body);
_list = new List();
_list.holder = _body;
_list.itemsHolder = new Sprite();
_list.orientation = Orientation.VERTICAL;
_list.hDirection = Direction.LEFT_TO_RIGHT;
_list.vDirection = Direction.TOP_TO_BOTTOM;
_list.space = BTN_SPACE;
init();
onResize();
}
private function onInvoke(e:InvokeEvent):void
{
//C.log(e.arguments);
}
private function handleActivate(e:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}
private function handleDeactivate(e:Event):void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}
private function handleKeys(e:KeyboardEvent):void
{
if(e.keyCode == Keyboard.BACK)
{
e.preventDefault();
NativeApplication.nativeApplication.exit();
}
}
private function onResize(e:*=null):void
{
if (_txt)
{
_txt.y = 150 * (1 / DeviceInfo.dpiScaleMultiplier);
_txt.width = stage.stageWidth * (1 / DeviceInfo.dpiScaleMultiplier);
C.x = 0;
C.y = _txt.y + _txt.height + 0;
C.width = stage.stageWidth * (1 / DeviceInfo.dpiScaleMultiplier);
C.height = 300 * (1 / DeviceInfo.dpiScaleMultiplier);
}
if (_list)
{
_numRows = Math.floor(stage.stageWidth / (BTN_WIDTH * DeviceInfo.dpiScaleMultiplier + BTN_SPACE));
_list.row = _numRows;
_list.itemArrange();
}
if (_body)
{
_body.y = stage.stageHeight - _body.height;
}
}
private function init():void
{
// Remove OverrideAir debugger in production builds
OverrideAir.enableDebugger(function ($ane:String, $class:String, $msg:String):void
{
trace($ane+" ("+$class+") "+$msg);
});
// pass "true" for the init method so the ANE can prepare itself for accepting dynamic links.
var isConfigFound:Boolean = Firebase.init(true);
if (isConfigFound)
{
// to be able to build "short" dynamicLinks, you need to set the Web API Key manually
// copy this information from Firebase console: https://console.firebase.google.com/project/_/settings/general/
Firebase.getConfig().webApiKey = "AIzaSyBvWdo5STJ4pPl3FG6MHlEsiguedNzdxhQ";
var config:FirebaseConfig = Firebase.getConfig();
C.log("webApiKey = " + config.webApiKey);
C.log("default_web_client_id = " + config.default_web_client_id);
C.log("firebase_database_url = " + config.firebase_database_url);
C.log("gcm_defaultSenderId = " + config.gcm_defaultSenderId);
C.log("google_api_key = " + config.google_api_key);
C.log("google_app_id = " + config.google_app_id);
C.log("google_crash_reporting_api_key = " + config.google_crash_reporting_api_key);
C.log("google_storage_bucket = " + config.google_storage_bucket);
C.log("project_id = " + config.project_id);
initDynamicLinks();
}
else
{
C.log("Config file is not found!");
}
}
private function initDynamicLinks():void
{
// DynamicLinks class must be initialized right after Firebase.init(true); and as soon as possible.
DynamicLinks.init();
// You should immediately listen for possible DynamicLinksEvents.INVOKE event
DynamicLinks.listener.addEventListener(DynamicLinksEvents.INVOKE, onDynamicLinksInvoke);
var btn1:MySprite = createBtn("build a deeplink");
btn1.addEventListener(MouseEvent.CLICK, buildDeepLink);
_list.add(btn1);
function buildDeepLink(e:MouseEvent):void
{
var androidParams:AndroidParams = new AndroidParams();
androidParams.apn = "air." + NativeApplication.nativeApplication.applicationID;
androidParams.amv = 3;
var iosParams:IosParams = new IosParams();
iosParams.ibi = NativeApplication.nativeApplication.applicationID;
iosParams.isi = "2293507574";
var socialMediaParams:SocialMediaParams = new SocialMediaParams();
socialMediaParams.st = "my Social Media title";
socialMediaParams.sd = "my Social Media description";
// add optional Analytics params: http://myflashlab.github.io/asdoc/com/myflashlab/air/extensions/firebase/dynamicLinks/AnalyticsParams.html
var analyticsParams:AnalyticsParams = new AnalyticsParams();
// add optional otherPlatform params: http://myflashlab.github.io/asdoc/com/myflashlab/air/extensions/firebase/dynamicLinks/OtherPlatformParams.html
var otherPlatformParams:OtherPlatformParams = new OtherPlatformParams();
// add optional navigation params: http://myflashlab.github.io/asdoc/com/myflashlab/air/extensions/firebase/dynamicLinks/NavigationParams.html
var navigationParams:NavigationParams = new NavigationParams();
// first create your URL Prefix from your Firebase Console: https://console.firebase.google.com/project/_/durablelinks/links/
_deepLink = DynamicLinks.build(
"myflashlabs.page.link",
"https://www.myflashlabs.com/deeplinks",
androidParams,
iosParams,
socialMediaParams,
analyticsParams,
otherPlatformParams,
navigationParams,
"MY_INVITATION_ID");
trace(_deepLink);
C.log(_deepLink);
}
var btn2:MySprite = createBtn("make it short!");
btn2.addEventListener(MouseEvent.CLICK, makeItShort);
_list.add(btn2);
function makeItShort(e:MouseEvent):void
{
if(!_deepLink)
{
C.log("First create a deeplink!");
trace("First create a deeplink!");
return;
}
DynamicLinks.toMakeShort(_deepLink, function ($link:String, $raw:String):void
{
trace("$raw = " + $raw);
if($link)
{
_deepLinkShort = $link;
C.log("$link = " + _deepLinkShort);
trace("$link = " + _deepLinkShort);
}
});
}
var btn3:MySprite = createBtn("share deeplink");
btn3.addEventListener(MouseEvent.CLICK, shareDeeplink);
_list.add(btn3);
function shareDeeplink(e:MouseEvent):void
{
if(!_deepLinkShort)
{
C.log("First create a _deepLinkShort!");
return;
}
DynamicLinks.share("Title", _deepLinkShort);
}
onResize();
}
private function onDynamicLinksInvoke(e:DynamicLinksEvents):void
{
C.log("e.link = " + e.link);
C.log("e.invitationId = " + e.invitationId);
trace("e.link = " + e.link);
trace("e.invitationId = " + e.invitationId);
}
private function createBtn($str:String):MySprite
{
var sp:MySprite = new MySprite();
sp.addEventListener(MouseEvent.MOUSE_OVER, onOver);
sp.addEventListener(MouseEvent.MOUSE_OUT, onOut);
sp.addEventListener(MouseEvent.CLICK, onOut);
sp.bgAlpha = 1;
sp.bgColor = 0xDFE4FF;
sp.drawBg();
sp.width = BTN_WIDTH * DeviceInfo.dpiScaleMultiplier;
sp.height = BTN_HEIGHT * DeviceInfo.dpiScaleMultiplier;
function onOver(e:MouseEvent):void
{
sp.bgAlpha = 1;
sp.bgColor = 0xFFDB48;
sp.drawBg();
}
function onOut(e:MouseEvent):void
{
sp.bgAlpha = 1;
sp.bgColor = 0xDFE4FF;
sp.drawBg();
}
var format:TextFormat = new TextFormat("Arimo", 16, 0x666666, null, null, null, null, null, TextFormatAlign.CENTER);
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.antiAliasType = AntiAliasType.ADVANCED;
txt.mouseEnabled = false;
txt.multiline = true;
txt.wordWrap = true;
txt.scaleX = txt.scaleY = DeviceInfo.dpiScaleMultiplier;
txt.width = sp.width * (1 / DeviceInfo.dpiScaleMultiplier);
txt.defaultTextFormat = format;
txt.text = $str;
txt.y = sp.height - txt.height >> 1;
sp.addChild(txt);
return sp;
}
}
}