Merge pull request #5887 from Ritzlgrmft/master

added cordova-plugin-app-version and cordova-plugin-ibeacon, modified log4javascript
This commit is contained in:
Masahiro Wakame
2015-09-20 16:54:49 +09:00
6 changed files with 230 additions and 27 deletions
@@ -0,0 +1,19 @@
/// <reference path="../cordova/cordova.d.ts" />
/// <reference path="./cordova-plugin-app-version.d.ts" />
cordova.getAppVersion.getAppName()
.then(appName=> {
console.log(appName)
});
cordova.getAppVersion.getPackageName()
.then(packageName=> {
console.log(packageName);
});
cordova.getAppVersion.getVersionCode()
.then(versionCode=> {
console.log(versionCode);
});
cordova.getAppVersion.getVersionNumber()
.then(versionNumber=> {
console.log(versionNumber);
});
@@ -0,0 +1,15 @@
// Type definitions for cordova-plugin-app-version v0.1.7
// Project: https://github.com/whiteoctober/cordova-plugin-app-version
// Definitions by: Markus Wagner <https://github.com/Ritzlgrmft/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../q/Q.d.ts" />
interface Cordova {
getAppVersion: {
getAppName: () => Q.IPromise<string>;
getPackageName: () => Q.IPromise<string>;
getVersionCode: () => Q.IPromise<string>;
getVersionNumber: () => Q.IPromise<string>;
};
}
@@ -0,0 +1,62 @@
/// <reference path="../cordova/cordova.d.ts" />
/// <reference path="./cordova-plugin-ibeacon.d.ts" />
function registerDelegates() {
cordova.plugins.locationManager.enableDebugLogs();
cordova.plugins.locationManager.delegate.didRangeBeaconsInRegion = (pluginResult) => didRangeBeaconsInRegion(pluginResult);
cordova.plugins.locationManager.delegate.didEnterRegion = (pluginResult) => didEnterRegion(pluginResult);
cordova.plugins.locationManager.delegate.didExitRegion = (pluginResult) => didExitRegion(pluginResult);
cordova.plugins.locationManager.delegate.didDetermineStateForRegion = (pluginResult) => didDetermineStateForRegion(pluginResult);
cordova.plugins.locationManager.delegate.didChangeAuthorizationStatus = (authorizationStatus) => didChangeAuthorizationStatus(authorizationStatus);
cordova.plugins.locationManager.delegate.didStartMonitoringForRegion = (pluginResult) => didStartMonitoringForRegion(pluginResult);
cordova.plugins.locationManager.delegate.monitoringDidFailForRegionWithError = (pluginResult) => monitoringDidFailForRegionWithError(pluginResult);
cordova.plugins.locationManager.onDomDelegateReady();
}
function didRangeBeaconsInRegion(pluginResult: BeaconPlugin.PluginResult): void {
for (var beacon of pluginResult.beacons) {
console.log(beacon.uuid, beacon.major, beacon.minor, beacon.accuracy, beacon.proximity, beacon.rssi, beacon.tx);
}
}
function didEnterRegion(pluginResult: BeaconPlugin.PluginResult): void {
var region: BeaconPlugin.Region = new cordova.plugins.locationManager.BeaconRegion("identifier", "uuid", 1, 2);;
cordova.plugins.locationManager.startRangingBeaconsInRegion(this.createBeaconRegionFromPluginResult(pluginResult))
.then(() => {
console.log("startRangingBeaconsInRegion succeeded");
})
.catch((reason: any) => {
console.error("startRangingBeaconsInRegion failed: " + reason);
});
}
function didExitRegion(pluginResult: BeaconPlugin.PluginResult): void {
var region: BeaconPlugin.Region;
cordova.plugins.locationManager.stopRangingBeaconsInRegion(region)
.then(() => {
console.log("stopRangingBeaconsInRegion succeeded");
})
.catch((reason: any) => {
console.error("stopRangingBeaconsInRegion failed: " + reason);
});
}
function didDetermineStateForRegion(pluginResult: BeaconPlugin.PluginResult): void {
if (pluginResult.state === "CLRegionStateInside") {
console.log(pluginResult.region.identifier);
}
}
function didChangeAuthorizationStatus(authorizationStatus: string): void {
console.log(authorizationStatus);
}
function didStartMonitoringForRegion(pluginResult: BeaconPlugin.PluginResult): void {
console.log(pluginResult.region.identifier);
}
function monitoringDidFailForRegionWithError(pluginResult: BeaconPlugin.PluginResult): void {
console.log(pluginResult.region.identifier);
}
+95
View File
@@ -0,0 +1,95 @@
// Type definitions for cordova-plugin-ibeacon v3.3.0
// Project: https://github.com/petermetz/cordova-plugin-ibeacon
// Definitions by: Markus Wagner <https://github.com/Ritzlgrmft/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../q/Q.d.ts" />
interface CordovaPlugins {
locationManager: BeaconPlugin.LocationManager;
}
declare module BeaconPlugin {
/**
* Beacon Plugin.
*/
export interface LocationManager {
delegate: Delegate;
BeaconRegion: BeaconRegion;
onDomDelegateReady(): void;
startMonitoringForRegion(region: Region): Q.Promise<void>;
stopMonitoringForRegion(region: Region): Q.Promise<void>;
requestStateForRegion(region: Region): Q.Promise<void>;
startRangingBeaconsInRegion(region: Region): Q.Promise<void>;
stopRangingBeaconsInRegion(region: Region): Q.Promise<void>;
getAuthorizationStatus(): Q.Promise<PluginResult>;
requestWhenInUseAuthorization(): Q.Promise<void>;
requestAlwaysAuthorization(): Q.Promise<void>;
getMonitoredRegions(): Q.Promise<Region[]>;
getRangedRegions(): Q.Promise<Region[]>;
isRangingAvailable(): Q.Promise<boolean>;
isMonitoringAvailableForClass(region: Region): Q.Promise<boolean>;
startAdvertising(region: Region, measuredPower: boolean): Q.Promise<void>;
stopAdvertising(): Q.Promise<void>;
isAdvertisingAvailable(): Q.Promise<boolean>;
isAdvertising(): Q.Promise<boolean>;
disableDebugLogs(): Q.Promise<void>;
enableDebugNotifications(): Q.Promise<void>;
disableDebugNotifications(): Q.Promise<void>;
enableDebugLogs(): Q.Promise<void>;
isBluetoothEnabled(): Q.Promise<boolean>;
enableBluetooth(): Q.Promise<void>;
disableBluetooth(): Q.Promise<void>;
appendToDeviceLog(message: string): Q.Promise<string>;
}
export interface PluginResult {
eventType: string;
region: Region;
beacons: Beacon[];
authorizationStatus: string;
state: string;
}
export interface Delegate {
didDetermineStateForRegion(pluginResult: PluginResult): void;
didStartMonitoringForRegion(pluginResult: PluginResult): void;
didExitRegion(pluginResult: PluginResult): void;
didEnterRegion(pluginResult: PluginResult): void;
didRangeBeaconsInRegion(pluginResult: PluginResult): void;
peripheralManagerDidStartAdvertising(pluginResult: PluginResult): void;
peripheralManagerDidUpdateState(pluginResult: PluginResult): void;
didChangeAuthorizationStatus(authorizationStatus: string): void;
monitoringDidFailForRegionWithError(pluginResult: PluginResult): void;
}
export interface Region {
identifier: string;
new (identifier: string): Region;
}
export interface BeaconRegion extends Region {
uuid: string;
major: string;
minor: string;
notifyEntryStateOnDisplay: boolean;
new (identifier: string, uuid: string, major?: number, minor?: number, notifyEntryStateOnDisplay?: boolean): BeaconRegion;
}
export interface CircularRegion extends Region {
latitude: number;
longitude: number;
radius: number;
new (identifier: string, latitude: number, longitude: number, radius: number): CircularRegion;
}
export interface Beacon {
uuid: string;
major: string;
minor: string;
proximity: string;
tx: number;
rssi: number;
accuracy: number;
}
}
+5 -1
View File
@@ -1,4 +1,4 @@
/// <reference path="log4javascript.d.ts" />
/// <reference path="./log4javascript.d.ts" />
function aSimpleLoggingMessageString() {
var log = log4javascript.getDefaultLogger();
@@ -47,4 +47,8 @@ function changingTheFormatOfLogMessages() {
var popUpAppender = new log4javascript.PopUpAppender();
var layout = new log4javascript.PatternLayout("[%-5p] %m");
popUpAppender.setLayout(layout);
}
function configureLogLog() {
log4javascript.logLog.setQuietMode(true);
}
+34 -26
View File
@@ -1051,38 +1051,46 @@ declare module log4javascript {
// #region log4javascript error handling
/**
* Sets whether LogLog is in quiet mode or not. In quiet mode, no messages sent to LogLog have any visible effect. By default,
* quiet mode is switched off.
* @param quietMode Whether to turn quiet mode on or off.
* log4javascript has a single rudimentary logger-like object of its own to handle messages generated by log4javascript itself.
* This logger is called logLog and is accessed via log4javascript.logLog.
*/
export function setQuietMode(quietMode: boolean): void;
export namespace logLog {
/**
* Sets how many errors LogLog will display alerts for. By default, only the first error encountered generates an alert to the
* user. If you turn all errors on by supplying true to this method then all errors will generate alerts.
* @param showAllErrors Whether to show all errors or just the first.
*/
export function setAlertAllErrors(alertAllErrors: boolean): void;
/**
* Sets whether logLog is in quiet mode or not. In quiet mode, no messages sent to logLog have any visible effect. By default,
* quiet mode is switched off.
* @param quietMode Whether to turn quiet mode on or off.
*/
export function setQuietMode(quietMode: boolean): void;
/**
* Logs a debugging message to an in-memory list.
*/
export function debug(message: string, exception?: Error): void;
/**
* Sets how many errors logLog will display alerts for. By default, only the first error encountered generates an alert to the
* user. If you turn all errors on by supplying true to this method then all errors will generate alerts.
* @param showAllErrors Whether to show all errors or just the first.
*/
export function setAlertAllErrors(alertAllErrors: boolean): void;
/**
* Displays an alert of all debugging messages.
*/
export function displayDebug(): void;
/**
* Logs a debugging message to an in-memory list.
*/
export function debug(message: string, exception?: Error): void;
/**
* Currently has no effect.
*/
export function warn(message: string, exception?: Error): void;
/**
* Displays an alert of all debugging messages.
*/
export function displayDebug(): void;
/**
* Generates an alert to the user if and only if the error is the first one encountered and setAlertAllErrors(true) has not been called.
*/
export function error(message: string, exception?: Error): void;
/**
* Currently has no effect.
*/
export function warn(message: string, exception?: Error): void;
/**
* Generates an alert to the user if and only if the error is the first one encountered and setAlertAllErrors(true) has not been called.
*/
export function error(message: string, exception?: Error): void;
}
// #endregion
}