Last active
January 7, 2017 06:11
-
-
Save juanpaexpedite/9b7d16dd52ad90f52587ee9521ed1886 to your computer and use it in GitHub Desktop.
Updated Device Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Devices | |
{ | |
Phone, | |
Tablet, | |
Desktop, | |
Xbox, | |
IoT, | |
Continuum, | |
SurfaceHub | |
} | |
public class DeviceManager | |
{ | |
#region Get Mobile Mode | |
private static Devices GetMobileMode() | |
{ | |
if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1)) | |
{ | |
var keyboard = new Windows.Devices.Input.KeyboardCapabilities(); | |
if (keyboard.KeyboardPresent > 0) | |
{ | |
return Devices.Continuum; | |
} | |
else | |
{ | |
return Devices.Phone; | |
} | |
} | |
else | |
{ | |
return Devices.Tablet; | |
} | |
} | |
#endregion | |
#region Get Desktop Mode | |
private static Devices GetDesktopMode() | |
{ | |
var settings = UIViewSettings.GetForCurrentView(); | |
return settings.UserInteractionMode == UserInteractionMode.Mouse | |
? Devices.Desktop : Devices.Tablet; | |
} | |
#endregion | |
#region Interop | |
public static Devices GetCurrentDevice() | |
{ | |
switch (AnalyticsInfo.VersionInfo.DeviceFamily) | |
{ | |
case "Windows.Mobile": | |
return GetMobileMode(); | |
case "Windows.Desktop": | |
return GetDesktopMode(); | |
case "Windows.Universal": | |
return Devices.IoT; | |
case "Windows.Team": | |
return Devices.SurfaceHub; | |
case "Windows.Xbox": | |
return Devices.Xbox; | |
default: | |
return Devices.Desktop; | |
} | |
} | |
public static bool CurrentIs(params Devices[] devices) | |
{ | |
if (devices == null) | |
return false; | |
var currentdevice = GetCurrentDevice(); | |
return devices.Contains(currentdevice); | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment