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
/
MainPerformance.as
293 lines (243 loc) · 8.05 KB
/
MainPerformance.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
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.HTTPStatusEvent;
import flash.events.IOErrorEvent;
import flash.events.InvokeEvent;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
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.firebase.core.*;
import com.myflashlab.air.extensions.firebase.performance.*;
import com.myflashlab.air.extensions.dependency.OverrideAir;
import flash.utils.setTimeout;
/**
* ...
* @author Hadi Tavakoli - 22/6/2019 12:38 PM
*/
public class MainPerformance 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 MainPerformance():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 Performance V" + Perf.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
{
}
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);
});
var isConfigFound:Boolean = Firebase.init();
if(isConfigFound)
{
var config:FirebaseConfig = Firebase.getConfig();
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);
initFirebasePerformance();
} else
{
C.log("Config file is not found!");
}
}
private function initFirebasePerformance():void
{
Perf.init();
var btn1:MySprite = createBtn("is collectionEnabled?");
btn1.addEventListener(MouseEvent.CLICK, isCollectionEnabled);
_list.add(btn1);
function isCollectionEnabled(e:MouseEvent):void
{
trace("is collectionEnabled: " + Perf.collectionEnabled);
}
var btn2:MySprite = createBtn("toggle collectionEnabled");
btn2.addEventListener(MouseEvent.CLICK, toggleCollectionEnabled);
_list.add(btn2);
function toggleCollectionEnabled(e:MouseEvent):void
{
Perf.collectionEnabled = !Perf.collectionEnabled;
}
var btn3:MySprite = createBtn("Monitor Network");
btn3.addEventListener(MouseEvent.CLICK, monitorNetwork);
_list.add(btn3);
function monitorNetwork(e:MouseEvent):void
{
var httpMetric:HttpMetric = Perf.newHttpMetric("https://www.google.com", URLRequestMethod.GET);
httpMetric.start();
var request:URLRequest = new URLRequest();
request.url = "https://www.google.com";
request.method = URLRequestMethod.GET;
var loader:URLLoader = new URLLoader();
loader.addEventListener(IOErrorEvent.IO_ERROR, function (event:IOErrorEvent):void {
trace(event.toString());
});
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, function (event:HTTPStatusEvent):void {
trace("httpStatusHandler: " + event);
httpMetric.setHttpResponseCode(event.status);
httpMetric.stop();
});
loader.load(request);
}
var btn4:MySprite = createBtn("custom trace");
btn4.addEventListener(MouseEvent.CLICK, customTrace);
_list.add(btn4);
function customTrace(e:MouseEvent):void
{
var perfTrace:PerfTrace = Perf.newTrace("customTraceName");
perfTrace.start();
setTimeout(function ():void {
trace("app process completed");
perfTrace.stop();
}, 3000);
}
}
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;
}
}
}