Resolved Issue #451: Improve the Network Stack

Resolved Issue #473: Add support for Notification Observers (iOS) and Broadcast Receivers (Android)
This commit is contained in:
Rossen Hristov
2015-07-23 16:16:54 +03:00
parent d83e3a6ccd
commit 548ea66d37
18 changed files with 503 additions and 50 deletions

View File

@@ -26,7 +26,26 @@ var dir = context.getFilesDir();
// ### Tracking the current Activity
// ``` JavaScript
if (androidApp.foregroundActivity === androidApp.startActivity) {
console.log("We are currently in the main (start) activity of the application");
////console.log("We are currently in the main (start) activity of the application");
}
// ```
// </snippet>
// <snippet module="application" title="application">
// ### Registering a Broadcast Receiver (Android)
// ``` JavaScript
//// Register the broadcast receiver
if (app.android) {
app.android.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED,
function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) {
var level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1);
var scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1);
var percent = (level / scale) * 100.0;
////console.log("Battery: " + percent + "%");
});
}
//// When no longer needed, unregister the broadcast receiver
if (app.android) {
app.android.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED);
}
// ```
// </snippet>

View File

@@ -1 +1,27 @@

/* tslint:disable:no-unused-variable */
import app = require("application");
import TKUnit = require("./TKUnit");
import commonTests = require("./application-tests-common");
// merge the exports of the application_common file with the exports of this file
declare var exports;
require("utils/module-merge").merge(commonTests, exports);
// <snippet module="application" title="application">
// ### Adding a Notification Observer (iOS)
// ``` JavaScript
//// Add the notification observer
if (app.ios) {
app.ios.addNotificationObserver(UIDeviceBatteryLevelDidChangeNotification,
function onReceiveCallback(notification: NSNotification) {
var percent = UIDevice.currentDevice().batteryLevel * 100;
var message = "Battery: " + percent + "%";
////console.log(message);
});
}
//// When no longer needed, remove the notification observer
if (app.ios) {
app.ios.removeNotificationObserver(UIDeviceBatteryLevelDidChangeNotification);
}
// ```
// </snippet>

View File

@@ -24,4 +24,27 @@ export var test_DummyTestForSnippetOnly0 = function () {
}
// ```
// </snippet>
}
export var test_DummyTestForSnippetOnly1 = function () {
// <snippet module="connectivity" title="connectivity">
// ### Monitoring connection type.
// ``` JavaScript
connectivity.starMonitoring(function onConnectionTypeChanged(newConnectionType: number) {
switch (newConnectionType) {
case connectivity.connectionType.none:
////console.log("Connection type changed to none.");
break;
case connectivity.connectionType.wifi:
////console.log("Connection type changed to WiFi.");
break;
case connectivity.connectionType.mobile:
////console.log("Connection type changed to mobile.");
break;
}
});
////...
connectivity.stopMonitoring();
// ```
// </snippet>
}