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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions EmbeddingTestBeds/Embedding.XF/OpenUri.xaml.cs
Expand Up @@ -21,7 +21,9 @@ public OpenUri()

void OpenUriButtonOnClicked(object sender, EventArgs eventArgs)
{
#pragma warning disable CS0618 // Type or member is obsolete
Device.OpenUri(new Uri("http://www.bing.com"));
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Expand Up @@ -34,7 +34,9 @@ protected override void Init()
new Button {
Text = "Without Params (Works)",
AutomationId = "btnOpenUri1",
#pragma warning disable CS0618 // Type or member is obsolete
Command = new Command (() => Device.OpenUri (new Uri ("http://www.bing.com")))
#pragma warning restore CS0618 // Type or member is obsolete
}
}
};
Expand Down Expand Up @@ -76,7 +78,9 @@ protected override void Init()
new Button {
Text = "With encoded Params (Breaks)",
AutomationId = "btnOpenUri2",
#pragma warning disable CS0618 // Type or member is obsolete
Command = new Command (() => Device.OpenUri (new Uri ("http://www.bing.com/search?q=xamarin%20bombs%20on%20this")))
#pragma warning restore CS0618 // Type or member is obsolete
}
}
};
Expand Down Expand Up @@ -119,7 +123,9 @@ protected override void Init()
new Button {
Text = "With decoded Params (Breaks)",
AutomationId = "btnOpenUri3",
#pragma warning disable CS0618 // Type or member is obsolete
Command = new Command (() => Device.OpenUri (new Uri ("http://www.bing.com/search?q=xamarin bombs on this")))
#pragma warning restore CS0618 // Type or member is obsolete
}
}
};
Expand Down
Expand Up @@ -23,8 +23,10 @@ protected override void Init()
Content = new StackLayout
{
Children = {
#pragma warning disable CS0618 // Type or member is obsolete
new Button { Text = "Call 123 4567", AutomationId = "tel", Command = new Command(() => Device.OpenUri(new System.Uri("tel:123 4567"))) },
new Button { Text = "Mail support@xamarin.com", AutomationId = "mailto", Command = new Command(() => Device.OpenUri(new System.Uri("mailto:support@xamarin.com"))) }
#pragma warning restore CS0618 // Type or member is obsolete
}
};
}
Expand Down
Expand Up @@ -165,7 +165,9 @@ static void WebView_OnNavigating (object sender, WebNavigatingEventArgs e)
//if external link is clicked
Debug.WriteLine ("WebView_OnNavigating, DIfferent Uri, so open in Native Browser");
e.Cancel = true;
Device.OpenUri (new Uri (e.Url));
#pragma warning disable CS0618 // Type or member is obsolete
Device.OpenUri (new Uri (e.Url));
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Expand Down
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("OpenUri is obsolete as of version 4.3.0. Use Launcher.OpenUri (or CanOpen, or TryOpen) from Xamarin.Essentials")]
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 };
}
}
}