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

Commit

Permalink
Merge branch 'main' into TextToSpeechCancelHang
Browse files Browse the repository at this point in the history
  • Loading branch information
jfversluis authored Jan 18, 2022
2 parents 987109f + 20d627e commit 8b83bf9
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 125 deletions.
20 changes: 1 addition & 19 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,4 @@ labels: feature-request
assignees: ''

---

## Summary
Please provide a brief summary of your proposal. Two to three sentences is best here.

## API Changes

Include a list of all API changes, additions, subtractions as would be required by your proposal. These APIs should be considered placeholders, so the naming is not as important as getting the concepts correct. If possible you should include some "example" code of usage of your new API. You should also provide details of the level of availability for the feature on each of the supported platforms.

e.g.

In order to facilitate the new Shiny Button api, a bool is added to the Button class. This is done as a bool because it is simpler to data bind and other reasons...

var button = new Button ();
button.MakeShiny = true; // new API

The MakeShiny API works even if the button is already visible.

## Intended Use Case
Provide a detailed example of where your proposal would be used and for what purpose.
We are no longer accepting new feature request for Xamarin.Essentials. Please make your new feature requests in the .NET MAUI repo which contains .NET MAUI Essentials.
6 changes: 2 additions & 4 deletions DeviceTests/DeviceTests.Android/DeviceTests.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<RootNamespace>DeviceTests.Droid</RootNamespace>
<AssemblyName>XamarinEssentialsDeviceTestsAndroid</AssemblyName>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<AndroidApplication>True</AndroidApplication>
<AndroidUseIntermediateDesignerFile>true</AndroidUseIntermediateDesignerFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
Expand All @@ -19,6 +18,7 @@
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -29,7 +29,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
<AotAssemblies>false</AotAssemblies>
<EnableLLVM>false</EnableLLVM>
Expand All @@ -47,7 +46,6 @@
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
<JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
</PropertyGroup>
Expand All @@ -63,7 +61,7 @@
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
<PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.20602.1" />
<PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.21620.1" />
<PackageReference Include="Xamarin.AndroidX.MediaRouter" Version="1.2.0.1" />
<PackageReference Include="Xamarin.AndroidX.Palette" Version="1.0.0.6" />
</ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions DeviceTests/DeviceTests.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,36 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<queries>
<!-- Email -->
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
<!-- Browser -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<!-- Browser -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<!-- Sms -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="smsto" />
</intent>
<!-- PhoneDialer -->
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<!-- MediaPicker -->
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/MainTheme"></application>
</manifest>
2 changes: 1 addition & 1 deletion DeviceTests/DeviceTests.iOS/DeviceTests.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2083" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.devices" Version="2.5.25" />
<PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.20602.1" />
<PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="1.0.0-prerelease.21620.1" />
<PackageReference Include="System.Numerics.Vectors" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions DeviceTests/DeviceTests.iOS/Main.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using UIKit;
using System;
using UIKit;

namespace DeviceTests.iOS
{
public class Application
{
static void Main(string[] args)
{
if (args?.Length > 0) // usually means this is from xharness
UIApplication.Main(args, null, nameof(TestApplicationDelegate));
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("ci-run")))
UIApplication.Main(args, null, typeof(TestApplicationDelegate));
else
UIApplication.Main(args, null, nameof(AppDelegate));
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
5 changes: 3 additions & 2 deletions DeviceTests/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ Task("test-ios-emu")
CleanDirectories(IOS_TEST_RESULTS_PATH.FullPath);
// Run the tests
var resultCode = StartProcess("xharness", "ios test " +
var resultCode = StartProcess("xharness", "apple test " +
$"--app=\"{IOS_IPA_PATH}\" " +
$"--targets=\"ios-simulator-64\" " +
$"--output-directory=\"{IOS_TEST_RESULTS_PATH}\" " +
$"--verbosity=\"Debug\" ");
$"--verbosity=\"Debug\" " +
$"--set-env=ci-run=true ");
// Rename test result files
var resultFiles = GetFiles($"{IOS_TEST_RESULTS_PATH}/*.xml");
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ Here are some frequently asked questions about Xamarin.Essentials, but be sure t

Please see the [License](LICENSE).

## Stats
<img src="https://repobeats.axiom.co/api/embed/f917a77cbbdeee19b87fa1f2f932895d1df18b31.svg" />
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AspNet.Security.OAuth.Apple" Version="5.0.14" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="5.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="5.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="5.0.10" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="AspNet.Security.OAuth.Apple" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Samples/Samples.iOS/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Application
{
static void Main(string[] args)
{
UIApplication.Main(args, null, nameof(AppDelegate));
UIApplication.Main(args, null, typeof(AppDelegate));
}
}
}
74 changes: 71 additions & 3 deletions Xamarin.Essentials/Connectivity/Connectivity.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,46 @@ namespace Xamarin.Essentials
public partial class Connectivity
{
static ConnectivityBroadcastReceiver conectivityReceiver;
static Intent connectivityIntent = new Intent(Platform.EssentialsConnectivityChanged);
static EssentialsNetworkCallback networkCallback;

static void StartListeners()
{
Permissions.EnsureDeclared<Permissions.NetworkState>();

conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);
var filter = new IntentFilter();

if (Platform.HasApiLevelN)
{
RegisterNetworkCallback();
filter.AddAction(Platform.EssentialsConnectivityChanged);
}
else
{
#pragma warning disable CS0618 // Type or member is obsolete
Platform.AppContext.RegisterReceiver(conectivityReceiver, new IntentFilter(ConnectivityManager.ConnectivityAction));
filter.AddAction(ConnectivityManager.ConnectivityAction);
#pragma warning restore CS0618 // Type or member is obsolete
}

conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);

Platform.AppContext.RegisterReceiver(conectivityReceiver, filter);
}

static void StopListeners()
{
if (conectivityReceiver == null)
return;

try
{
UnregisterNetworkCallback();
}
catch
{
Debug.WriteLine("Connectivity receiver already unregistered. Disposing of it.");
}

try
{
Platform.AppContext.UnregisterReceiver(conectivityReceiver);
Expand All @@ -39,6 +63,50 @@ static void StopListeners()
conectivityReceiver = null;
}

static void RegisterNetworkCallback()
{
if (!Platform.HasApiLevelN)
return;

var manager = Platform.ConnectivityManager;
if (manager == null)
return;

var request = new NetworkRequest.Builder().Build();
networkCallback = new EssentialsNetworkCallback();
manager.RegisterNetworkCallback(request, networkCallback);
}

static void UnregisterNetworkCallback()
{
if (!Platform.HasApiLevelN)
return;

var manager = Platform.ConnectivityManager;
if (manager == null || networkCallback == null)
return;

manager.UnregisterNetworkCallback(networkCallback);

networkCallback?.Dispose();
networkCallback = null;
}

class EssentialsNetworkCallback : ConnectivityManager.NetworkCallback
{
public override void OnAvailable(Network network) => Platform.AppContext.SendBroadcast(connectivityIntent);

public override void OnLost(Network network) => Platform.AppContext.SendBroadcast(connectivityIntent);

public override void OnCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) => Platform.AppContext.SendBroadcast(connectivityIntent);

public override void OnUnavailable() => Platform.AppContext.SendBroadcast(connectivityIntent);

public override void OnLinkPropertiesChanged(Network network, LinkProperties linkProperties) => Platform.AppContext.SendBroadcast(connectivityIntent);

public override void OnLosing(Network network, int maxMsToLive) => Platform.AppContext.SendBroadcast(connectivityIntent);
}

static NetworkAccess IsBetterAccess(NetworkAccess currentAccess, NetworkAccess newAccess) =>
newAccess > currentAccess ? newAccess : currentAccess;

Expand Down Expand Up @@ -245,7 +313,7 @@ public ConnectivityBroadcastReceiver(Action onChanged) =>
public override async void OnReceive(Context context, Intent intent)
{
#pragma warning disable CS0618 // Type or member is obsolete
if (intent.Action != ConnectivityManager.ConnectivityAction)
if (intent.Action != ConnectivityManager.ConnectivityAction && intent.Action != Platform.EssentialsConnectivityChanged)
#pragma warning restore CS0618 // Type or member is obsolete
return;

Expand Down
8 changes: 8 additions & 0 deletions Xamarin.Essentials/Contacts/Contacts.ios.macos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ static Task<Contact> PlatformPickContactAsync()
})
};

if (picker.PresentationController != null)
{
picker.PresentationController.Delegate = new Platform.UIPresentationControllerDelegate
{
DismissHandler = () => source?.TrySetResult(null)
};
}

uiView.PresentViewController(picker, true, null);

return source.Task;
Expand Down
7 changes: 6 additions & 1 deletion Xamarin.Essentials/DeviceDisplay/DeviceDisplay.android.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Android.Content;
using Android.Content.Res;
using Android.Provider;
Expand Down Expand Up @@ -114,6 +115,10 @@ class Listener : OrientationEventListener
internal Listener(Context context, Action handler)
: base(context) => onChanged = handler;

public override void OnOrientationChanged(int orientation) => onChanged();
public override async void OnOrientationChanged(int orientation)
{
await Task.Delay(500);
onChanged();
}
}
}
13 changes: 11 additions & 2 deletions Xamarin.Essentials/Email/Email.ios.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Threading.Tasks;
using Foundation;
using MessageUI;
Expand Down Expand Up @@ -50,13 +51,21 @@ static Task ComposeWithMailCompose(EmailMessage message)
}
}

// show the controller
var tcs = new TaskCompletionSource<bool>();
controller.Finished += (sender, e) =>
{
controller.DismissViewController(true, null);
tcs.TrySetResult(e.Result == MFMailComposeResult.Sent);
};

if (controller.PresentationController != null)
{
controller.PresentationController.Delegate = new Platform.UIPresentationControllerDelegate
{
DismissHandler = () => tcs.TrySetResult(false)
};
}

parentController.PresentViewController(controller, true, null);

return tcs.Task;
Expand Down
12 changes: 2 additions & 10 deletions Xamarin.Essentials/FilePicker/FilePicker.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ static async Task<IEnumerable<FileResult>> PlatformPickAsync(PickOptions options

if (documentPicker.PresentationController != null)
{
documentPicker.PresentationController.Delegate = new PickerPresentationControllerDelegate
documentPicker.PresentationController.Delegate = new Platform.UIPresentationControllerDelegate
{
PickHandler = urls => GetFileResults(urls, tcs)
DismissHandler = () => GetFileResults(null, tcs)
};
}

Expand Down Expand Up @@ -74,14 +74,6 @@ public override void DidPickDocument(UIDocumentPickerViewController controller,
public override void DidPickDocument(UIDocumentPickerViewController controller, NSUrl url)
=> PickHandler?.Invoke(new NSUrl[] { url });
}

class PickerPresentationControllerDelegate : UIAdaptivePresentationControllerDelegate
{
public Action<NSUrl[]> PickHandler { get; set; }

public override void DidDismiss(UIPresentationController presentationController) =>
PickHandler?.Invoke(null);
}
}

public partial class FilePickerFileType
Expand Down
Loading

0 comments on commit 8b83bf9

Please sign in to comment.