Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[C] Obsolete Device.OpenUri #6844

Merged
merged 3 commits into from Jul 24, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
235 changes: 118 additions & 117 deletions Xamarin.Forms.Core/Device.cs
Expand Up @@ -9,49 +9,49 @@

namespace Xamarin.Forms
{
public static class Device
{
public const string iOS = "iOS";
public const string Android = "Android";
public const string UWP = "UWP";
public const string macOS = "macOS";
public const string GTK = "GTK";
public const string Tizen = "Tizen";
public static class Device
{
public const string iOS = "iOS";
public const string Android = "Android";
public const string UWP = "UWP";
public const string macOS = "macOS";
public const string GTK = "GTK";
public const string Tizen = "Tizen";
public const string WPF = "WPF";

[EditorBrowsable(EditorBrowsableState.Never)]
public static DeviceInfo info;
[EditorBrowsable(EditorBrowsableState.Never)]
public static DeviceInfo info;

static IPlatformServices s_platformServices;
static IPlatformServices s_platformServices;

[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetIdiom(TargetIdiom value) => Idiom = value;
public static TargetIdiom Idiom { get; internal set; }
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetIdiom(TargetIdiom value) => Idiom = value;
public static TargetIdiom Idiom { get; internal set; }

//TODO: Why are there two of these? This is never used...?
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetTargetIdiom(TargetIdiom value) => Idiom = value;

[Obsolete("TargetPlatform is obsolete as of version 2.3.4. Please use RuntimePlatform instead.")]
[Obsolete("TargetPlatform is obsolete as of version 2.3.4. Please use RuntimePlatform instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
#pragma warning disable 0618
public static TargetPlatform OS
{
get
{
TargetPlatform platform;
if (Enum.TryParse(RuntimePlatform, out platform))
return platform;

// In the old TargetPlatform, there was no distinction between WinRT/UWP
if (RuntimePlatform == UWP)
{
return TargetPlatform.Windows;
}

return TargetPlatform.Other;
}
}
{
get
{
TargetPlatform platform;
if (Enum.TryParse(RuntimePlatform, out platform))
return platform;

// In the old TargetPlatform, there was no distinction between WinRT/UWP
if (RuntimePlatform == UWP)
{
return TargetPlatform.Windows;
}

return TargetPlatform.Other;
}
}
#pragma warning restore 0618

public static string RuntimePlatform => PlatformServices.RuntimePlatform;
Expand Down Expand Up @@ -169,113 +169,114 @@ public static double GetNamedSize(NamedSize size, Element targetElement)
return GetNamedSize(size, targetElement.GetType());
}

public static double GetNamedSize(NamedSize size, Type targetElementType)
{
return GetNamedSize(size, targetElementType, false);
}
public static double GetNamedSize(NamedSize size, Type targetElementType)
{
return GetNamedSize(size, targetElementType, false);
}

[Obsolete("OnPlatform is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.")]
[Obsolete("OnPlatform is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void OnPlatform(Action iOS = null, Action Android = null, Action WinPhone = null, Action Default = null)
{
switch (OS)
{
case TargetPlatform.iOS:
if (iOS != null)
iOS();
else if (Default != null)
Default();
break;
case TargetPlatform.Android:
if (Android != null)
Android();
else if (Default != null)
Default();
break;
case TargetPlatform.Windows:
case TargetPlatform.WinPhone:
if (WinPhone != null)
WinPhone();
else if (Default != null)
Default();
break;
case TargetPlatform.Other:
if (Default != null)
Default();
break;
}
}

[Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.")]
{
switch (OS)
{
case TargetPlatform.iOS:
if (iOS != null)
iOS();
else if (Default != null)
Default();
break;
case TargetPlatform.Android:
if (Android != null)
Android();
else if (Default != null)
Default();
break;
case TargetPlatform.Windows:
case TargetPlatform.WinPhone:
if (WinPhone != null)
WinPhone();
else if (Default != null)
Default();
break;
case TargetPlatform.Other:
if (Default != null)
Default();
break;
}
}

[Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use 'switch (Device.RuntimePlatform)' instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T OnPlatform<T>(T iOS, T Android, T WinPhone)
{
switch (OS)
{
case TargetPlatform.iOS:
return iOS;
case TargetPlatform.Android:
return Android;
case TargetPlatform.Windows:
case TargetPlatform.WinPhone:
return WinPhone;
}
{
switch (OS)
{
case TargetPlatform.iOS:
return iOS;
case TargetPlatform.Android:
return Android;
case TargetPlatform.Windows:
case TargetPlatform.WinPhone:
return WinPhone;
}

return iOS;
}
return iOS;
}

public static void OpenUri(Uri uri)
{
PlatformServices.OpenUriAction(uri);
}
[Obsolete("Use Launcher.OpenUri (or CanOpen, or TryOpen) from Xamarin.Essentials")]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're looking for it, here's the only meaningful change ^^^

StephaneDelcroix marked this conversation as resolved.
Show resolved Hide resolved
public static void OpenUri(Uri uri)
{
PlatformServices.OpenUriAction(uri);
}

public static void StartTimer(TimeSpan interval, Func<bool> callback)
{
PlatformServices.StartTimer(interval, callback);
}
public static void StartTimer(TimeSpan interval, Func<bool> callback)
{
PlatformServices.StartTimer(interval, callback);
}

[EditorBrowsable(EditorBrowsableState.Never)]
public static Assembly[] GetAssemblies()
{
return PlatformServices.GetAssemblies();
}
[EditorBrowsable(EditorBrowsableState.Never)]
public static Assembly[] GetAssemblies()
{
return PlatformServices.GetAssemblies();
}

[EditorBrowsable(EditorBrowsableState.Never)]
public static double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
{
return PlatformServices.GetNamedSize(size, targetElementType, useOldSizes);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public static double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
{
return PlatformServices.GetNamedSize(size, targetElementType, useOldSizes);
}

internal static Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
return PlatformServices.GetStreamAsync(uri, cancellationToken);
}
internal static Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
return PlatformServices.GetStreamAsync(uri, cancellationToken);
}

public static class Styles
{
public static readonly string TitleStyleKey = "TitleStyle";
public static class Styles
{
public static readonly string TitleStyleKey = "TitleStyle";

public static readonly string SubtitleStyleKey = "SubtitleStyle";
public static readonly string SubtitleStyleKey = "SubtitleStyle";

public static readonly string BodyStyleKey = "BodyStyle";
public static readonly string BodyStyleKey = "BodyStyle";

public static readonly string ListItemTextStyleKey = "ListItemTextStyle";
public static readonly string ListItemTextStyleKey = "ListItemTextStyle";

public static readonly string ListItemDetailTextStyleKey = "ListItemDetailTextStyle";
public static readonly string ListItemDetailTextStyleKey = "ListItemDetailTextStyle";

public static readonly string CaptionStyleKey = "CaptionStyle";
public static readonly string CaptionStyleKey = "CaptionStyle";

public static readonly Style TitleStyle = new Style(typeof(Label)) { BaseResourceKey = TitleStyleKey };
public static readonly Style TitleStyle = new Style(typeof(Label)) { BaseResourceKey = TitleStyleKey };

public static readonly Style SubtitleStyle = new Style(typeof(Label)) { BaseResourceKey = SubtitleStyleKey };
public static readonly Style SubtitleStyle = new Style(typeof(Label)) { BaseResourceKey = SubtitleStyleKey };

public static readonly Style BodyStyle = new Style(typeof(Label)) { BaseResourceKey = BodyStyleKey };
public static readonly Style BodyStyle = new Style(typeof(Label)) { BaseResourceKey = BodyStyleKey };

public static readonly Style ListItemTextStyle = new Style(typeof(Label)) { BaseResourceKey = ListItemTextStyleKey };
public static readonly Style ListItemTextStyle = new Style(typeof(Label)) { BaseResourceKey = ListItemTextStyleKey };

public static readonly Style ListItemDetailTextStyle = new Style(typeof(Label)) { BaseResourceKey = ListItemDetailTextStyleKey };
public static readonly Style ListItemDetailTextStyle = new Style(typeof(Label)) { BaseResourceKey = ListItemDetailTextStyleKey };

public static readonly Style CaptionStyle = new Style(typeof(Label)) { BaseResourceKey = CaptionStyleKey };
}
}
public static readonly Style CaptionStyle = new Style(typeof(Label)) { BaseResourceKey = CaptionStyleKey };
}
}
}