Skip to content

Commit

Permalink
Merge branch 'pr/5'
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
tjvantoll committed Aug 18, 2015
2 parents a915cc5 + 2b0bdba commit c002c60
Show file tree
Hide file tree
Showing 181 changed files with 2,320 additions and 3,323 deletions.
2 changes: 1 addition & 1 deletion .abproject
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
],
"AndroidHardwareAcceleration": "false",
"iOSStatusBarStyle": "Default",
"FrameworkVersion": "1.2.2",
"FrameworkVersion": "1.2.3",
"Framework": "NativeScript"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var appModule = require("application");
var Common = require("application-settings/application-settings-common");
var utils = require("utils/utils");
var sharedPreferences = utils.ad.getApplicationContext().getSharedPreferences("prefs.db", 0);
var sharedPreferences = appModule.android.context.getSharedPreferences("prefs.db", 0);
exports.hasKey = function (key) {
Common.checkKey(key);
return sharedPreferences.contains(key);
Expand Down
3 changes: 1 addition & 2 deletions app/tns_modules/application/application-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ var fileSystemAccess = require("file-system/file-system-access");
var styleScope = require("ui/styling/style-scope");
var observable = require("data/observable");
var events = new observable.Observable();
global.moduleMerge(events, exports);
require("utils/module-merge").merge(events, exports);
exports.launchEvent = "launch";
exports.suspendEvent = "suspend";
exports.resumeEvent = "resume";
exports.exitEvent = "exit";
exports.lowMemoryEvent = "lowMemory";
exports.uncaughtErrorEvent = "uncaughtError";
exports.orientationChangedEvent = "orientationChanged";
exports.cssFile = "app.css";
exports.resources = {};
exports.onUncaughtError = undefined;
Expand Down
143 changes: 40 additions & 103 deletions app/tns_modules/application/application.android.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
if (typeof __decorate !== "function") __decorate = function (decorators, target, key, desc) {
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
switch (arguments.length) {
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
}
};
var appModule = require("application/application-common");
var dts = require("application");
var frame = require("ui/frame");
var types = require("utils/types");
var observable = require("data/observable");
var enums = require("ui/enums");
global.moduleMerge(appModule, exports);
require("utils/module-merge").merge(appModule, exports);
exports.mainModule;
var initEvents = function () {
var androidApp = exports.android;
var lifecycleCallbacks = new android.app.Application.ActivityLifecycleCallbacks({
onActivityCreated: function (activity, bundle) {
if (!(activity instanceof com.tns.NativeScriptActivity)) {
return;
}
if (!androidApp.startActivity) {
androidApp.startActivity = activity;
androidApp.notify({ eventName: "activityCreated", object: androidApp, activity: activity, bundle: bundle });
Expand All @@ -23,9 +33,6 @@ var initEvents = function () {
androidApp.currentContext = activity;
},
onActivityDestroyed: function (activity) {
if (!(activity instanceof com.tns.NativeScriptActivity)) {
return;
}
if (activity === androidApp.foregroundActivity) {
androidApp.foregroundActivity = undefined;
}
Expand All @@ -46,9 +53,6 @@ var initEvents = function () {
gc();
},
onActivityPaused: function (activity) {
if (!(activity instanceof com.tns.NativeScriptActivity)) {
return;
}
if (activity === androidApp.foregroundActivity) {
if (exports.onSuspend) {
exports.onSuspend();
Expand All @@ -61,9 +65,6 @@ var initEvents = function () {
}
},
onActivityResumed: function (activity) {
if (!(activity instanceof com.tns.NativeScriptActivity)) {
return;
}
if (activity === androidApp.foregroundActivity) {
if (exports.onResume) {
exports.onResume();
Expand All @@ -76,28 +77,19 @@ var initEvents = function () {
}
},
onActivitySaveInstanceState: function (activity, bundle) {
if (!(activity instanceof com.tns.NativeScriptActivity)) {
return;
}
androidApp.notify({ eventName: "saveActivityState", object: androidApp, activity: activity, bundle: bundle });
if (androidApp.onSaveActivityState) {
androidApp.onSaveActivityState(activity, bundle);
}
},
onActivityStarted: function (activity) {
if (!(activity instanceof com.tns.NativeScriptActivity)) {
return;
}
androidApp.foregroundActivity = activity;
androidApp.notify({ eventName: "activityStarted", object: androidApp, activity: activity });
if (androidApp.onActivityStarted) {
androidApp.onActivityStarted(activity);
}
},
onActivityStopped: function (activity) {
if (!(activity instanceof com.tns.NativeScriptActivity)) {
return;
}
androidApp.notify({ eventName: "activityStopped", object: androidApp, activity: activity });
if (androidApp.onActivityStopped) {
androidApp.onActivityStopped(activity);
Expand All @@ -119,16 +111,13 @@ var AndroidApplication = (function (_super) {
__extends(AndroidApplication, _super);
function AndroidApplication() {
_super.apply(this, arguments);
this._registeredReceivers = {};
this._pendingReceiverRegistrations = new Array();
}
AndroidApplication.prototype.getActivity = function (intent) {
if (intent && intent.getAction() === android.content.Intent.ACTION_MAIN) {
if (exports.onLaunch) {
exports.onLaunch(intent);
}
exports.notify({ eventName: dts.launchEvent, object: this, android: intent });
setupOrientationListener(this);
}
var topFrame = frame.topmost();
if (!topFrame) {
Expand All @@ -148,40 +137,7 @@ var AndroidApplication = (function (_super) {
this.context = nativeApp.getApplicationContext();
this._eventsToken = initEvents();
this.nativeApp.registerActivityLifecycleCallbacks(this._eventsToken);
this._registerPendingReceivers();
};
AndroidApplication.prototype._registerPendingReceivers = function () {
if (this._pendingReceiverRegistrations) {
var i = 0;
var length = this._pendingReceiverRegistrations.length;
for (; i < length; i++) {
var registerFunc = this._pendingReceiverRegistrations[i];
registerFunc(this.context);
}
this._pendingReceiverRegistrations = new Array();
}
};
AndroidApplication.prototype.registerBroadcastReceiver = function (intentFilter, onReceiveCallback) {
var that = this;
var registerFunc = function (context) {
var receiver = new BroadcastReceiver(onReceiveCallback);
context.registerReceiver(receiver, new android.content.IntentFilter(intentFilter));
that._registeredReceivers[intentFilter] = receiver;
};
if (this.context) {
registerFunc(this.context);
}
else {
this._pendingReceiverRegistrations.push(registerFunc);
}
};
AndroidApplication.prototype.unregisterBroadcastReceiver = function (intentFilter) {
var receiver = this._registeredReceivers[intentFilter];
if (receiver) {
this.context.unregisterReceiver(receiver);
this._registeredReceivers[intentFilter] = undefined;
delete this._registeredReceivers[intentFilter];
}
this.context = this.nativeApp.getApplicationContext();
};
AndroidApplication.activityCreatedEvent = "activityCreated";
AndroidApplication.activityDestroyedEvent = "activityDestroyed";
Expand All @@ -192,23 +148,33 @@ var AndroidApplication = (function (_super) {
AndroidApplication.saveActivityStateEvent = "saveActivityState";
AndroidApplication.activityResultEvent = "activityResult";
AndroidApplication.activityBackPressedEvent = "activityBackPressed";
__decorate([
Deprecated
], AndroidApplication.prototype, "onActivityCreated");
__decorate([
Deprecated
], AndroidApplication.prototype, "onActivityDestroyed");
__decorate([
Deprecated
], AndroidApplication.prototype, "onActivityStarted");
__decorate([
Deprecated
], AndroidApplication.prototype, "onActivityPaused");
__decorate([
Deprecated
], AndroidApplication.prototype, "onActivityResumed");
__decorate([
Deprecated
], AndroidApplication.prototype, "onActivityStopped");
__decorate([
Deprecated
], AndroidApplication.prototype, "onSaveActivityState");
__decorate([
Deprecated
], AndroidApplication.prototype, "onActivityResult");
return AndroidApplication;
})(observable.Observable);
exports.AndroidApplication = AndroidApplication;
var BroadcastReceiver = (function (_super) {
__extends(BroadcastReceiver, _super);
function BroadcastReceiver(onReceiveCallback) {
_super.call(this);
this._onReceiveCallback = onReceiveCallback;
return global.__native(this);
}
BroadcastReceiver.prototype.onReceive = function (context, intent) {
if (this._onReceiveCallback) {
this._onReceiveCallback(context, intent);
}
};
return BroadcastReceiver;
})(android.content.BroadcastReceiver);
global.__onUncaughtError = function (error) {
if (!types.isFunction(exports.onUncaughtError)) {
return;
Expand All @@ -225,32 +191,3 @@ exports.start = function () {
dts.loadCss();
};
exports.android = new AndroidApplication();
var currentOrientation;
function setupOrientationListener(androidApp) {
androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_CONFIGURATION_CHANGED, onConfigurationChanged);
currentOrientation = androidApp.context.getResources().getConfiguration().orientation;
}
function onConfigurationChanged(context, intent) {
var orientation = context.getResources().getConfiguration().orientation;
if (currentOrientation !== orientation) {
currentOrientation = orientation;
var newValue;
switch (orientation) {
case android.content.res.Configuration.ORIENTATION_LANDSCAPE:
newValue = enums.DeviceOrientation.landscape;
break;
case android.content.res.Configuration.ORIENTATION_PORTRAIT:
newValue = enums.DeviceOrientation.portrait;
break;
default:
newValue = enums.DeviceOrientation.unknown;
break;
}
exports.notify({
eventName: dts.orientationChangedEvent,
android: context,
newValue: newValue,
object: exports.android,
});
}
}
Loading

0 comments on commit c002c60

Please sign in to comment.