Unverified Commit 26adc660 authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #265 from ezengsvmx/24HOUR

Add 24 hour detection
parents 00b78754 5d7a8f0b
...@@ -183,6 +183,12 @@ RCT_EXPORT_MODULE() ...@@ -183,6 +183,12 @@ RCT_EXPORT_MODULE()
return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad; return [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
} }
- (bool) is24Hour
{
NSString *format = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:[NSLocale currentLocale]];
return ([format rangeOfString:@"a"].location == NSNotFound);
}
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {
UIDevice *currentDevice = [UIDevice currentDevice]; UIDevice *currentDevice = [UIDevice currentDevice];
...@@ -208,6 +214,7 @@ RCT_EXPORT_MODULE() ...@@ -208,6 +214,7 @@ RCT_EXPORT_MODULE()
@"timezone": self.timezone, @"timezone": self.timezone,
@"isEmulator": @(self.isEmulator), @"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet), @"isTablet": @(self.isTablet),
@"is24Hour": @(self.is24Hour),
}; };
} }
......
...@@ -89,6 +89,10 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -89,6 +89,10 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE; return layout == Configuration.SCREENLAYOUT_SIZE_LARGE || layout == Configuration.SCREENLAYOUT_SIZE_XLARGE;
} }
private Boolean is24Hour() {
return android.text.format.DateFormat.is24HourFormat(this.reactContext.getApplicationContext());
}
@ReactMethod @ReactMethod
public void isPinOrFingerprintSet(Callback callback) { public void isPinOrFingerprintSet(Callback callback) {
KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); //api 16+ KeyguardManager keyguardManager = (KeyguardManager) this.reactContext.getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); //api 16+
...@@ -165,6 +169,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -165,6 +169,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("timezone", TimeZone.getDefault().getID()); constants.put("timezone", TimeZone.getDefault().getID());
constants.put("isEmulator", this.isEmulator()); constants.put("isEmulator", this.isEmulator());
constants.put("isTablet", this.isTablet()); constants.put("isTablet", this.isTablet());
constants.put("is24Hour", this.is24Hour());
if (getCurrentActivity() != null && if (getCurrentActivity() != null &&
(getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED || (getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED ||
getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED || getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED ||
......
...@@ -20,6 +20,7 @@ export function getTimezone(): string; ...@@ -20,6 +20,7 @@ export function getTimezone(): string;
export function getInstanceID(): string; export function getInstanceID(): string;
export function isEmulator(): boolean; export function isEmulator(): boolean;
export function isTablet(): boolean; export function isTablet(): boolean;
export function is24Hour(): boolean;
export function isPinOrFingerprintSet(): (cb: (isPinOrFingerprintSet: boolean) => void) => void; export function isPinOrFingerprintSet(): (cb: (isPinOrFingerprintSet: boolean) => void) => void;
export function getFirstInstallTime(): number; export function getFirstInstallTime(): number;
export function getLastUpdateTime(): number; export function getLastUpdateTime(): number;
......
...@@ -74,6 +74,9 @@ module.exports = { ...@@ -74,6 +74,9 @@ module.exports = {
isTablet: function() { isTablet: function() {
return RNDeviceInfo.isTablet; return RNDeviceInfo.isTablet;
}, },
is24Hour: function() {
return RNDeviceInfo.is24Hour;
},
isPinOrFingerprintSet: function () { isPinOrFingerprintSet: function () {
return RNDeviceInfo.isPinOrFingerprintSet; return RNDeviceInfo.isPinOrFingerprintSet;
}, },
......
...@@ -19,6 +19,7 @@ declare module.exports: { ...@@ -19,6 +19,7 @@ declare module.exports: {
getTimezone: () => string, getTimezone: () => string,
isEmulator: () => boolean, isEmulator: () => boolean,
isTablet: () => boolean, isTablet: () => boolean,
is24Hour: () => boolean,
isPinOrFingerprintSet: () => (cb: (isPinOrFingerprintSet: boolean) => void) => void, isPinOrFingerprintSet: () => (cb: (isPinOrFingerprintSet: boolean) => void) => void,
getAPILevel: () => number, getAPILevel: () => number,
getInstanceID: () => string, getInstanceID: () => string,
......
{ {
"name": "react-native-device-info", "name": "react-native-device-info",
"version": "0.12.1", "version": "0.12.2",
"description": "Get device information using react-native", "description": "Get device information using react-native",
"main": "deviceinfo.js", "main": "deviceinfo.js",
"typings": "./deviceinfo.d.ts", "typings": "./deviceinfo.d.ts",
......
...@@ -37,6 +37,11 @@ namespace RNDeviceInfo ...@@ -37,6 +37,11 @@ namespace RNDeviceInfo
return !rgx.IsMatch(os); return !rgx.IsMatch(os);
} }
private bool is24Hour()
{
return DateTimeFormatInfo.CurrentInfo.ShortTimePattern.Contains("H");
}
public override IReadOnlyDictionary<string, object> Constants public override IReadOnlyDictionary<string, object> Constants
{ {
...@@ -111,6 +116,7 @@ namespace RNDeviceInfo ...@@ -111,6 +116,7 @@ namespace RNDeviceInfo
constants["timezone"] = TimeZoneInfo.Local.Id; constants["timezone"] = TimeZoneInfo.Local.Id;
constants["isEmulator"] = IsEmulator(model); constants["isEmulator"] = IsEmulator(model);
constants["isTablet"] = IsTablet(os); constants["isTablet"] = IsTablet(os);
constants["is24Hour"] = is24Hour();
return constants; return constants;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment