52 lines
1.1 KiB
Haxe
52 lines
1.1 KiB
Haxe
package ru.m;
|
|
|
|
enum abstract Platform(String) from String to String {
|
|
var ANDROID = "android";
|
|
var LINUX = "linux";
|
|
var WINDOWS = "windows";
|
|
var FLASH = "flash";
|
|
var HTML5 = "html5";
|
|
var UNKNOWN = "unknown";
|
|
}
|
|
|
|
class Device {
|
|
|
|
public static var platform(get, null):Platform;
|
|
|
|
private static function get_platform():Platform {
|
|
#if android
|
|
return ANDROID;
|
|
#elseif linux
|
|
return LINUX;
|
|
#elseif windows
|
|
return WINDOWS;
|
|
#elseif flash
|
|
return FLASH;
|
|
#elseif html5
|
|
return HTML5;
|
|
#else
|
|
return UNKNOWN;
|
|
#end
|
|
}
|
|
|
|
private static var MOBILES(default, never):Array<String> = [
|
|
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
|
|
];
|
|
|
|
public static function isMobile():Bool {
|
|
#if android
|
|
return true;
|
|
#elseif js
|
|
var userAgent = js.Browser.navigator.userAgent;
|
|
for (mobile in MOBILES) {
|
|
if (userAgent.indexOf(mobile) > -1) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
#else
|
|
return false;
|
|
#end
|
|
}
|
|
}
|