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
/
MainCrashlytics.as
267 lines (226 loc) · 7.43 KB
/
MainCrashlytics.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
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 com.luaye.console.C;
import com.myflashlab.air.extensions.dependency.OverrideAir;
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.myflashlab.air.extensions.firebase.core.*;
import com.myflashlab.air.extensions.firebase.crash.*;
/**
* ...
* @author Hadi Tavakoli - 5/20/2018 12:18 PM
*/
public class MainCrashlytics extends Sprite
{
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 MainCrashlytics():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 Crashlytics V" + Crashlytics.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
{
NativeApplication.nativeApplication.removeEventListener(InvokeEvent.INVOKE, onInvoke);
}
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
{
toTrace($ane+" ("+$class+") "+$msg);
});
var isConfigFound:Boolean = Firebase.init();
if(isConfigFound)
{
var config:FirebaseConfig = Firebase.getConfig();
toTrace("default_web_client_id = " + config.default_web_client_id);
toTrace("firebase_database_url = " + config.firebase_database_url);
toTrace("gcm_defaultSenderId = " + config.gcm_defaultSenderId);
toTrace("google_api_key = " + config.google_api_key);
toTrace("google_app_id = " + config.google_app_id);
toTrace("google_crash_reporting_api_key = " + config.google_crash_reporting_api_key);
toTrace("google_storage_bucket = " + config.google_storage_bucket);
toTrace("project_id = " + config.project_id);
startWithCrashlytics();
} else
{
toTrace("Config file is not found!");
}
}
private function startWithCrashlytics():void
{
// Initialize Crashlytics anytime after a successful Firebase initialization.
Crashlytics.init();
/*
Use Crashlytics.userIdentifier to bind crash reports to users.
Why you shouldn't use 'username' and 'userEmail'? read below
https://myflashlab.github.io/asdoc/com/myflashlab/air/extensions/firebase/crash/Crashlytics.html#userIdentifier
*/
// Crashlytics.userIdentifier = "1234567890";
// Crashlytics.username = "myflashlabs";
// Crashlytics.userEmail = "email@site.com";
var btn1:MySprite = createBtn("Force a crash");
btn1.addEventListener(MouseEvent.CLICK, crashTheApp);
_list.add(btn1);
function crashTheApp(e:MouseEvent):void
{
toTrace("calling: Crashlytics.crash();");
Crashlytics.crash();
}
var btn2:MySprite = createBtn("log something");
btn2.addEventListener(MouseEvent.CLICK, logSomething);
_list.add(btn2);
function logSomething(e:MouseEvent):void
{
toTrace("calling: Crashlytics.log");
Crashlytics.log("key1", 1); //int
Crashlytics.log("key2", 1.2); // Number
Crashlytics.log("key3", true); // Boolean
Crashlytics.log("key4", false);// Boolean
Crashlytics.log("key5", "String");
}
}
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;
}
private function toTrace(...rest):void
{
C.log(rest);
trace(rest);
}
}
}