Skip to content

Commit a8a8c77

Browse files
author
hshristov
committed
Change Application and NativeActivity classes to accommodate android runtime changes.
1 parent 534e800 commit a8a8c77

2 files changed

Lines changed: 40 additions & 46 deletions

File tree

application/application.android.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ var initEvents = function () {
9898
}
9999

100100
app.init({
101-
getActivity: function (intent: android.content.Intent) {
101+
getActivity: function (activity: android.app.Activity) {
102+
var intent = activity.getIntent()
102103
return exports.android.getActivity(intent);
103104
},
104105

ui/frame/frame.android.ts

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var TAG = "_fragmentTag";
1515
var OWNER = "_owner";
1616
var HIDDEN = "_hidden";
1717
var INTENT_EXTRA = "com.tns.activity";
18+
var ANDROID_FRAME = "android_frame";
1819

1920
var navDepth = 0;
2021

@@ -368,36 +369,28 @@ export class Frame extends frameCommon.Frame {
368369
}
369370
}
370371

371-
declare module com {
372-
module tns {
373-
class NativeScriptActivity extends android.app.Activity {
374-
protected onCreate(savedInstanceState: android.os.Bundle);
375-
protected onStart();
376-
protected onStop();
377-
protected onDestroy();
378-
protected onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent)
379-
}
380-
}
381-
}
372+
var NativeActivity = {
382373

383-
class NativeActivity extends com.tns.NativeScriptActivity {
384-
private androidFrame: AndroidFrame;
385-
private get frame(): Frame {
374+
get frame(): Frame {
386375
if (this.androidFrame) {
387376
return this.androidFrame.owner;
388377
}
389378
return null;
390-
}
379+
},
391380

392-
onCreate(savedInstanceState: android.os.Bundle) {
381+
get androidFrame(): AndroidFrame {
382+
return this[ANDROID_FRAME];
383+
},
384+
385+
onCreate: function(savedInstanceState: android.os.Bundle) {
393386
trace.write("NativeScriptActivity.onCreate(); savedInstanceState: " + savedInstanceState, trace.categories.NativeLifecycle);
394387

395388
// Find the frame for this activity.
396389
var frameId = this.getIntent().getExtras().getInt(INTENT_EXTRA);
397390
for (var i = 0; i < framesCache.length; i++) {
398391
var aliveFrame = framesCache[i].get();
399392
if (aliveFrame && aliveFrame.frameId === frameId) {
400-
this.androidFrame = aliveFrame;
393+
this[ANDROID_FRAME] = aliveFrame;
401394
break;
402395
}
403396
}
@@ -408,7 +401,7 @@ class NativeActivity extends com.tns.NativeScriptActivity {
408401

409402
// If there is savedInstanceState this call will recreate all fragments that were previously in the navigation.
410403
// We take care of associating them with a Page from our backstack in the onAttachFragment callback.
411-
super.onCreate(savedInstanceState);
404+
this.super.onCreate(savedInstanceState);
412405

413406
this.androidFrame.setActivity(this);
414407

@@ -423,42 +416,42 @@ class NativeActivity extends com.tns.NativeScriptActivity {
423416
// If there is no instance state - we call navigateCore from here since Activity is created AFTER the navigate call and navigateCore will fail.
424417
var isRestart = !!savedInstanceState;
425418
this.frame._onActivityCreated(isRestart);
426-
}
419+
},
427420

428-
onActivityResult(requestCode: number, resultCode: number, data: android.content.Intent) {
429-
super.onActivityResult(requestCode, resultCode, data);
421+
onActivityResult: function(requestCode: number, resultCode: number, data: android.content.Intent) {
422+
this.super.onActivityResult(requestCode, resultCode, data);
430423
trace.write("NativeScriptActivity.onActivityResult();", trace.categories.NativeLifecycle);
431424

432425
var result = application.android.onActivityResult;
433426
if (result) {
434427
result(requestCode, resultCode, data);
435428
}
436-
}
429+
},
437430

438-
onAttachFragment(fragment: android.app.Fragment) {
431+
onAttachFragment: function(fragment: android.app.Fragment) {
439432
trace.write("NativeScriptActivity.onAttachFragment() : " + fragment.getTag(), trace.categories.NativeLifecycle);
440-
super.onAttachFragment(fragment);
433+
this.super.onAttachFragment(fragment);
441434

442435
if (!(<PageFragmentBody>fragment).entry) {
443436
// There is no entry set to the fragment, so this must be destroyed fragment that was recreated by Android.
444437
// We should find its corresponding page in our backstack and set it manually.
445438
findPageForFragment(fragment, this.frame);
446439
}
447-
}
440+
},
448441

449-
onStart() {
450-
super.onStart();
442+
onStart: function() {
443+
this.super.onStart();
451444
trace.write("NativeScriptActivity.onStart();", trace.categories.NativeLifecycle);
452445
this.frame.onLoaded();
453-
}
446+
},
454447

455-
onStop() {
456-
super.onStop();
448+
onStop: function() {
449+
this.super.onStop();
457450
trace.write("NativeScriptActivity.onStop();", trace.categories.NativeLifecycle);
458451
this.frame.onUnloaded();
459-
}
452+
},
460453

461-
onDestroy() {
454+
onDestroy: function() {
462455
// TODO: Implement uninitialized(detached) routine
463456
var frame = this.frame;
464457
frame._onDetached(true);
@@ -470,11 +463,11 @@ class NativeActivity extends com.tns.NativeScriptActivity {
470463

471464
this.androidFrame.reset();
472465

473-
super.onDestroy();
466+
this.super.onDestroy();
474467
trace.write("NativeScriptActivity.onDestroy();", trace.categories.NativeLifecycle);
475-
}
468+
},
476469

477-
onOptionsItemSelected(menuItem: android.view.IMenuItem) {
470+
onOptionsItemSelected: function(menuItem: android.view.IMenuItem) {
478471
if (!this.androidFrame.hasListeners(frameCommon.Frame.androidOptionSelectedEvent)) {
479472
return false;
480473
}
@@ -488,27 +481,27 @@ class NativeActivity extends com.tns.NativeScriptActivity {
488481

489482
this.androidFrame.notify(data);
490483
return data.handled;
491-
}
484+
},
492485

493-
onBackPressed() {
486+
onBackPressed: function() {
494487
trace.write("NativeScriptActivity.onBackPressed;", trace.categories.NativeLifecycle);
495488
if (!frameCommon.goBack()) {
496-
super.onBackPressed();
489+
this.super.onBackPressed();
497490
}
498-
}
491+
},
499492

500-
onLowMemory() {
493+
onLowMemory: function() {
501494
gc();
502495
java.lang.System.gc();
503-
super.onLowMemory();
504-
}
496+
this.super.onLowMemory();
497+
},
505498

506-
onTrimMemory(level) {
499+
onTrimMemory: function(level: number) {
507500
gc();
508501
java.lang.System.gc();
509-
super.onTrimMemory(level);
502+
this.super.onTrimMemory(level);
510503
}
511-
}
504+
};
512505

513506
var framesCounter = 0;
514507
var framesCache: Array<WeakRef<AndroidFrame>> = new Array<WeakRef<AndroidFrame>>();

0 commit comments

Comments
 (0)