From a80a073e176ac279130ca3c4c9ae192dbebc3312 Mon Sep 17 00:00:00 2001 From: Darin Dimitrov Date: Wed, 22 Apr 2015 11:20:10 +0300 Subject: [PATCH 1/2] Added user agent string and selected language to the platform module --- platform/platform.android.ts | 21 +++++++++++++++++++++ platform/platform.d.ts | 11 +++++++++++ platform/platform.ios.ts | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/platform/platform.android.ts b/platform/platform.android.ts index bb800a486..e5c5c0eb2 100644 --- a/platform/platform.android.ts +++ b/platform/platform.android.ts @@ -18,6 +18,8 @@ export class device implements definition.device { private static _sdkVersion: string; private static _deviceType: string; private static _uuid: string; + private static _userAgent: string; + private static _language: string; static get os(): string { return platformNames.android; @@ -81,6 +83,25 @@ export class device implements definition.device { return device._uuid; } + + static get userAgent(): string { + if (!device._userAgent) { + var context = application.android.context; + device._userAgent = new android.webkit.WebView(context).getSettings().getUserAgentString(); + } + + return device._userAgent; + } + + static get language(): string { + if (!device._language) { + var context = application.android.context; + var locale = context.getResources().getConfiguration().locale; + device._language = locale.getDefault().toString(); + } + + return device._language; + } } var mainScreenInfo: definition.ScreenMetrics; diff --git a/platform/platform.d.ts b/platform/platform.d.ts index c71b87e32..539c841be 100644 --- a/platform/platform.d.ts +++ b/platform/platform.d.ts @@ -56,6 +56,17 @@ declare module "platform" { * Gets the uuid */ static uuid: string; + + /** + * Gets the user agent string as it would be reported by the + * device built-in web browser control + */ + static userAgent: string; + + /** + * Gets the preferred language. For example "en" or "en_US" + */ + static language: string; } /** diff --git a/platform/platform.ios.ts b/platform/platform.ios.ts index b1d6dac6f..957d2d81e 100644 --- a/platform/platform.ios.ts +++ b/platform/platform.ios.ts @@ -14,6 +14,8 @@ export class device implements definition.device { private static _osVersion: string; private static _sdkVersion: string; private static _deviceType: string; + private static _userAgent: string; + private static _language: string; static get manufacturer(): string { return "Apple"; @@ -74,6 +76,23 @@ export class device implements definition.device { return app_uuid; } + + static get userAgent(): string { + if (!device._userAgent) { + device._userAgent = new UIWebView().stringByEvaluatingJavaScriptFromString('navigator.userAgent'); + } + + return device._userAgent; + } + + static get language(): string { + if (!device._language) { + var languages = NSLocale.preferredLanguages(); + device._language = languages[0]; + } + + return device._language; + } } var mainScreenInfo: definition.ScreenMetrics = null; From 050ab3e4c7ece39206d5b60e926f2e0ea68e0bd3 Mon Sep 17 00:00:00 2001 From: Darin Dimitrov Date: Wed, 22 Apr 2015 18:31:38 +0300 Subject: [PATCH 2/2] Removing the userAgent setting from the platform module --- platform/platform.android.ts | 10 ---------- platform/platform.d.ts | 6 ------ platform/platform.ios.ts | 9 --------- 3 files changed, 25 deletions(-) diff --git a/platform/platform.android.ts b/platform/platform.android.ts index e5c5c0eb2..15e09bf0a 100644 --- a/platform/platform.android.ts +++ b/platform/platform.android.ts @@ -18,7 +18,6 @@ export class device implements definition.device { private static _sdkVersion: string; private static _deviceType: string; private static _uuid: string; - private static _userAgent: string; private static _language: string; static get os(): string { @@ -84,15 +83,6 @@ export class device implements definition.device { return device._uuid; } - static get userAgent(): string { - if (!device._userAgent) { - var context = application.android.context; - device._userAgent = new android.webkit.WebView(context).getSettings().getUserAgentString(); - } - - return device._userAgent; - } - static get language(): string { if (!device._language) { var context = application.android.context; diff --git a/platform/platform.d.ts b/platform/platform.d.ts index 539c841be..2b48a6e1b 100644 --- a/platform/platform.d.ts +++ b/platform/platform.d.ts @@ -57,12 +57,6 @@ declare module "platform" { */ static uuid: string; - /** - * Gets the user agent string as it would be reported by the - * device built-in web browser control - */ - static userAgent: string; - /** * Gets the preferred language. For example "en" or "en_US" */ diff --git a/platform/platform.ios.ts b/platform/platform.ios.ts index 957d2d81e..44e1ff22e 100644 --- a/platform/platform.ios.ts +++ b/platform/platform.ios.ts @@ -14,7 +14,6 @@ export class device implements definition.device { private static _osVersion: string; private static _sdkVersion: string; private static _deviceType: string; - private static _userAgent: string; private static _language: string; static get manufacturer(): string { @@ -77,14 +76,6 @@ export class device implements definition.device { return app_uuid; } - static get userAgent(): string { - if (!device._userAgent) { - device._userAgent = new UIWebView().stringByEvaluatingJavaScriptFromString('navigator.userAgent'); - } - - return device._userAgent; - } - static get language(): string { if (!device._language) { var languages = NSLocale.preferredLanguages();