From d5cac27b86fac3e4170c59a0ee68c93478e5d137 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 18 Mar 2022 05:22:14 +0200 Subject: [PATCH 01/45] Conform the Essentials API to the rest of MAUI --- .../Accelerometer/Accelerometer.android.cs | 3 +- .../Accelerometer.ios.watchos.cs | 3 +- .../Accelerometer.netstandard.tvos.macos.cs | 2 +- .../src/Accelerometer/Accelerometer.shared.cs | 7 ++- .../src/Accelerometer/Accelerometer.tizen.cs | 2 +- .../src/Accelerometer/Accelerometer.uwp.cs | 2 +- .../AccelerometerQueue.shared.cs | 2 +- .../src/AppActions/AppActions.android.cs | 3 +- .../src/AppActions/AppActions.ios.cs | 2 +- ...ns.netstandard.tvos.watchos.macos.tizen.cs | 2 +- .../src/AppActions/AppActions.shared.cs | 7 +-- .../src/AppActions/AppActions.uwp.cs | 4 +- src/Essentials/src/AppInfo/AppInfo.android.cs | 3 +- .../AppInfo/AppInfo.ios.tvos.watchos.macos.cs | 3 +- .../src/AppInfo/AppInfo.netstandard.cs | 2 +- src/Essentials/src/AppInfo/AppInfo.shared.cs | 4 +- src/Essentials/src/AppInfo/AppInfo.tizen.cs | 2 +- src/Essentials/src/AppInfo/AppInfo.uwp.cs | 2 +- src/Essentials/src/AppInfo/AppTheme.shared.cs | 2 +- .../src/AppInfo/LayoutDirection.shared.cs | 2 +- .../src/Barometer/Barometer.android.cs | 3 +- .../src/Barometer/Barometer.ios.watchos.cs | 3 +- .../Barometer.netstandard.tvos.macos.cs | 2 +- .../src/Barometer/Barometer.shared.cs | 7 ++- .../src/Barometer/Barometer.tizen.cs | 2 +- src/Essentials/src/Barometer/Barometer.uwp.cs | 2 +- src/Essentials/src/Battery/Battery.android.cs | 4 +- .../src/Battery/Battery.ios.watchos.cs | 3 +- src/Essentials/src/Battery/Battery.macos.cs | 2 +- .../src/Battery/Battery.netstandard.tvos.cs | 2 +- src/Essentials/src/Battery/Battery.shared.cs | 5 +- src/Essentials/src/Battery/Battery.tizen.cs | 2 +- src/Essentials/src/Battery/Battery.uwp.cs | 3 +- src/Essentials/src/Browser/Browser.android.cs | 3 +- src/Essentials/src/Browser/Browser.ios.cs | 3 +- src/Essentials/src/Browser/Browser.macos.cs | 2 +- .../Browser.netstandard.tvos.watchos.cs | 2 +- src/Essentials/src/Browser/Browser.shared.cs | 6 +- src/Essentials/src/Browser/Browser.tizen.cs | 2 +- src/Essentials/src/Browser/Browser.uwp.cs | 2 +- .../src/Browser/BrowserLaunchMode.shared.cs | 2 +- .../Browser/BrowserLaunchOptions.shared.cs | 2 +- .../src/Browser/BrowserTitleMode.shared.cs | 2 +- .../src/Clipboard/Clipboard.android.cs | 3 +- src/Essentials/src/Clipboard/Clipboard.ios.cs | 2 +- .../src/Clipboard/Clipboard.macos.cs | 2 +- ...lipboard.netstandard.tvos.watchos.tizen.cs | 2 +- .../src/Clipboard/Clipboard.shared.cs | 6 +- src/Essentials/src/Clipboard/Clipboard.uwp.cs | 2 +- src/Essentials/src/Compass/Compass.android.cs | 3 +- src/Essentials/src/Compass/Compass.ios.cs | 2 +- .../Compass.netstandard.tvos.watchos.macos.cs | 2 +- src/Essentials/src/Compass/Compass.shared.cs | 9 +-- src/Essentials/src/Compass/Compass.tizen.cs | 2 +- src/Essentials/src/Compass/Compass.uwp.cs | 2 +- .../src/Compass/LowPassFilter.shared.cs | 2 +- .../src/Connectivity/Connectivity.android.cs | 4 +- .../Connectivity.ios.tvos.macos.cs | 2 +- ...onnectivity.ios.tvos.macos.reachability.cs | 2 +- .../Connectivity.netstandard.watchos.cs | 2 +- .../src/Connectivity/Connectivity.shared.cs | 5 +- .../Connectivity/Connectivity.shared.enums.cs | 2 +- .../src/Connectivity/Connectivity.tizen.cs | 2 +- .../src/Connectivity/Connectivity.uwp.cs | 2 +- .../src/Contacts/Contacts.android.cs | 3 +- .../src/Contacts/Contacts.ios.macos.cs | 3 +- .../Contacts.netstandard.tvos.watchos.cs | 2 +- .../src/Contacts/Contacts.shared.cs | 5 +- src/Essentials/src/Contacts/Contacts.tizen.cs | 2 +- src/Essentials/src/Contacts/Contacts.uwp.cs | 2 +- .../DeviceDisplay/DeviceDisplay.android.cs | 3 +- .../src/DeviceDisplay/DeviceDisplay.ios.cs | 2 +- .../src/DeviceDisplay/DeviceDisplay.macos.cs | 2 +- .../DeviceDisplay.netstandard.tvos.watchos.cs | 2 +- .../src/DeviceDisplay/DeviceDisplay.shared.cs | 4 +- .../src/DeviceDisplay/DeviceDisplay.tizen.cs | 2 +- .../src/DeviceDisplay/DeviceDisplay.uwp.cs | 4 +- .../src/DeviceInfo/DeviceInfo.android.cs | 2 +- .../DeviceInfo/DeviceInfo.ios.tvos.watchos.cs | 2 +- .../src/DeviceInfo/DeviceInfo.macos.cs | 2 +- .../src/DeviceInfo/DeviceInfo.netstandard.cs | 2 +- .../src/DeviceInfo/DeviceInfo.shared.cs | 4 +- .../src/DeviceInfo/DeviceInfo.tizen.cs | 2 +- .../src/DeviceInfo/DeviceInfo.uwp.cs | 2 +- src/Essentials/src/Email/Email.android.cs | 4 +- src/Essentials/src/Email/Email.ios.cs | 3 +- src/Essentials/src/Email/Email.macos.cs | 2 +- .../Email/Email.netstandard.tvos.watchos.cs | 9 ++- src/Essentials/src/Email/Email.shared.cs | 5 +- src/Essentials/src/Email/Email.tizen.cs | 2 +- src/Essentials/src/Email/Email.uwp.cs | 2 +- .../src/FilePicker/FilePicker.android.cs | 4 +- .../src/FilePicker/FilePicker.ios.cs | 4 +- .../src/FilePicker/FilePicker.macos.cs | 2 +- .../FilePicker.netstandard.watchos.tvos.cs | 2 +- .../src/FilePicker/FilePicker.shared.cs | 3 +- .../src/FilePicker/FilePicker.tizen.cs | 2 +- .../src/FilePicker/FilePicker.uwp.cs | 4 +- .../src/FileSystem/FileSystem.android.cs | 6 +- .../src/FileSystem/FileSystem.ios.cs | 4 +- .../FileSystem.ios.tvos.watchos.macos.cs | 4 +- .../src/FileSystem/FileSystem.netstandard.cs | 4 +- .../src/FileSystem/FileSystem.shared.cs | 8 +-- .../src/FileSystem/FileSystem.tizen.cs | 4 +- .../src/FileSystem/FileSystem.uwp.cs | 7 ++- .../src/Flashlight/Flashlight.android.cs | 5 +- .../src/Flashlight/Flashlight.ios.cs | 2 +- ...ashlight.netstandard.tvos.watchos.macos.cs | 2 +- .../src/Flashlight/Flashlight.shared.cs | 4 +- .../src/Flashlight/Flashlight.tizen.cs | 2 +- .../src/Flashlight/Flashlight.uwp.cs | 2 +- .../src/Geocoding/Geocoding.android.cs | 3 +- .../Geocoding.ios.tvos.watchos.macos.cs | 2 +- .../src/Geocoding/Geocoding.netstandard.cs | 2 +- .../src/Geocoding/Geocoding.shared.cs | 4 +- .../src/Geocoding/Geocoding.tizen.cs | 2 +- src/Essentials/src/Geocoding/Geocoding.uwp.cs | 3 +- .../src/Geolocation/Geolocation.android.cs | 5 +- .../src/Geolocation/Geolocation.ios.macos.cs | 3 +- .../Geolocation.netstandard.tvos.watchos.cs | 2 +- .../src/Geolocation/Geolocation.shared.cs | 8 +-- .../src/Geolocation/Geolocation.tizen.cs | 2 +- .../src/Geolocation/Geolocation.uwp.cs | 3 +- .../GeolocationRequest.ios.macos.cs | 2 +- .../Geolocation/GeolocationRequest.shared.cs | 2 +- .../src/Geolocation/GeolocationRequest.uwp.cs | 2 +- .../src/Gyroscope/Gyroscope.android.cs | 3 +- .../src/Gyroscope/Gyroscope.ios.watchos.cs | 3 +- .../Gyroscope.netstandard.tvos.macos.cs | 2 +- .../src/Gyroscope/Gyroscope.shared.cs | 9 +-- .../src/Gyroscope/Gyroscope.tizen.cs | 2 +- src/Essentials/src/Gyroscope/Gyroscope.uwp.cs | 2 +- .../HapticFeedback/HapticFeedback.android.cs | 4 +- .../src/HapticFeedback/HapticFeedback.ios.cs | 2 +- .../HapticFeedback/HapticFeedback.macos.cs | 2 +- ...HapticFeedback.netstandard.tvos.watchos.cs | 2 +- .../HapticFeedback/HapticFeedback.shared.cs | 6 +- .../HapticFeedback/HapticFeedback.tizen.cs | 2 +- .../src/HapticFeedback/HapticFeedback.uwp.cs | 2 +- .../HapticFeedbackType.shared.cs | 2 +- .../src/Launcher/Launcher.android.cs | 3 +- .../src/Launcher/Launcher.ios.tvos.cs | 4 +- src/Essentials/src/Launcher/Launcher.macos.cs | 2 +- .../Launcher/Launcher.netstandard.watchos.cs | 2 +- .../src/Launcher/Launcher.shared.cs | 5 +- src/Essentials/src/Launcher/Launcher.tizen.cs | 2 +- src/Essentials/src/Launcher/Launcher.uwp.cs | 2 +- .../src/Magnetometer/Magnetometer.android.cs | 3 +- .../Magnetometer/Magnetometer.ios.watchos.cs | 3 +- .../Magnetometer.netstandard.tvos.macos.cs | 2 +- .../src/Magnetometer/Magnetometer.shared.cs | 9 +-- .../src/Magnetometer/Magnetometer.tizen.cs | 2 +- .../src/Magnetometer/Magnetometer.uwp.cs | 2 +- .../src/MainThread/MainThread.android.cs | 2 +- .../MainThread.ios.tvos.watchos.macos.cs | 2 +- .../src/MainThread/MainThread.netstandard.cs | 2 +- .../src/MainThread/MainThread.shared.cs | 2 +- .../src/MainThread/MainThread.tizen.cs | 2 +- .../src/MainThread/MainThread.uwp.cs | 3 +- .../MainThread/MainThreadExtensions.uwp.cs | 2 +- src/Essentials/src/Map/Map.android.cs | 4 +- .../src/Map/Map.ios.watchos.macos.cs | 3 +- .../src/Map/Map.netstandard.tvos.cs | 3 +- src/Essentials/src/Map/Map.shared.cs | 5 +- src/Essentials/src/Map/Map.tizen.cs | 3 +- src/Essentials/src/Map/Map.uwp.cs | 3 +- .../src/Map/MapLaunchOptions.shared.cs | 2 +- .../src/Map/NavigationMode.shared.cs | 2 +- .../src/MediaPicker/MediaPicker.android.cs | 5 +- .../src/MediaPicker/MediaPicker.ios.cs | 6 +- .../src/MediaPicker/MediaPicker.macos.cs | 2 +- .../MediaPicker.netstandard.watchos.tvos.cs | 3 +- .../src/MediaPicker/MediaPicker.shared.cs | 7 ++- .../src/MediaPicker/MediaPicker.tizen.cs | 2 +- .../src/MediaPicker/MediaPicker.uwp.cs | 4 +- .../OrientationSensor.android.cs | 3 +- .../OrientationSensor.ios.watchos.cs | 3 +- ...rientationSensor.netstandard.tvos.macos.cs | 2 +- .../OrientationSensor.shared.cs | 10 ++-- .../OrientationSensor.tizen.cs | 2 +- .../OrientationSensor.uwp.cs | 2 +- .../src/Permissions/Permissions.android.cs | 3 +- .../src/Permissions/Permissions.ios.cs | 2 +- .../Permissions/Permissions.ios.tvos.macos.cs | 3 +- .../Permissions.ios.tvos.watchos.cs | 3 +- .../Permissions/Permissions.ios.watchos.cs | 2 +- .../src/Permissions/Permissions.macos.cs | 2 +- .../Permissions/Permissions.netstandard.cs | 2 +- .../src/Permissions/Permissions.shared.cs | 2 +- .../Permissions/Permissions.shared.enums.cs | 2 +- .../src/Permissions/Permissions.tizen.cs | 2 +- .../src/Permissions/Permissions.uwp.cs | 3 +- .../src/PhoneDialer/PhoneDialer.android.cs | 3 +- .../src/PhoneDialer/PhoneDialer.ios.cs | 2 +- .../src/PhoneDialer/PhoneDialer.macos.cs | 2 +- .../PhoneDialer.netstandard.tvos.watchos.cs | 2 +- .../src/PhoneDialer/PhoneDialer.shared.cs | 8 +-- .../src/PhoneDialer/PhoneDialer.tizen.cs | 2 +- .../src/PhoneDialer/PhoneDialer.uwp.cs | 2 +- .../src/Platform/Platform.android.cs | 6 +- .../src/Platform/Platform.ios.tvos.watchos.cs | 5 +- src/Essentials/src/Platform/Platform.uwp.cs | 1 + .../src/Preferences/Preferences.android.cs | 2 +- .../Preferences.ios.tvos.watchos.macos.cs | 2 +- .../Preferences/Preferences.netstandard.cs | 2 +- .../src/Preferences/Preferences.shared.cs | 5 +- .../src/Preferences/Preferences.tizen.cs | 2 +- .../src/Preferences/Preferences.uwp.cs | 2 +- .../src/Screenshot/Screenshot.android.cs | 5 +- .../src/Screenshot/Screenshot.ios.cs | 4 +- ...eenshot.netstandard.tizen.watchos.macos.cs | 2 +- .../src/Screenshot/Screenshot.shared.cs | 4 +- .../src/Screenshot/Screenshot.tvos.cs | 5 +- .../src/Screenshot/Screenshot.uwp.cs | 4 +- .../SecureStorage/SecureStorage.android.cs | 2 +- .../SecureStorage.ios.tvos.watchos.macos.cs | 2 +- .../SecureStorage.netstandard.cs | 2 +- .../src/SecureStorage/SecureStorage.shared.cs | 6 +- .../src/SecureStorage/SecureStorage.tizen.cs | 2 +- .../src/SecureStorage/SecureStorage.uwp.cs | 2 +- .../SemanticScreenReader.android.cs | 2 +- .../SemanticScreenReader.ios.cs | 2 +- ...er.netstandard.tvos.watchos.macos.tizen.cs | 2 +- .../SemanticScreenReader.shared.cs | 4 +- .../SemanticScreenReader.uwp.cs | 3 +- src/Essentials/src/Share/Share.android.cs | 4 +- src/Essentials/src/Share/Share.ios.cs | 3 +- src/Essentials/src/Share/Share.macos.cs | 2 +- .../Share/Share.netstandard.tvos.watchos.cs | 2 +- src/Essentials/src/Share/Share.shared.cs | 5 +- src/Essentials/src/Share/Share.tizen.cs | 2 +- src/Essentials/src/Share/Share.uwp.cs | 3 +- src/Essentials/src/Sms/Sms.android.cs | 5 +- src/Essentials/src/Sms/Sms.ios.cs | 3 +- src/Essentials/src/Sms/Sms.macos.cs | 2 +- .../src/Sms/Sms.netstandard.tvos.watchos.cs | 2 +- src/Essentials/src/Sms/Sms.shared.cs | 4 +- src/Essentials/src/Sms/Sms.tizen.cs | 2 +- src/Essentials/src/Sms/Sms.uwp.cs | 2 +- .../src/TextToSpeech/TextToSpeech.android.cs | 3 +- .../TextToSpeech.ios.tvos.watchos.cs | 2 +- .../src/TextToSpeech/TextToSpeech.macos.cs | 2 +- .../TextToSpeech/TextToSpeech.netstandard.cs | 2 +- .../src/TextToSpeech/TextToSpeech.shared.cs | 6 +- .../src/TextToSpeech/TextToSpeech.tizen.cs | 2 +- .../src/TextToSpeech/TextToSpeech.uwp.cs | 2 +- .../TextToSpeechExtensions.shared.cs | 2 +- src/Essentials/src/Types/Contact.shared.cs | 2 +- .../src/Types/DeviceIdiom.shared.cs | 2 +- .../src/Types/DevicePlatform.shared.cs | 2 +- .../src/Types/DisplayInfo.shared.cs | 2 +- .../src/Types/DisplayOrientation.shared.cs | 2 +- .../src/Types/DisplayRotation.shared.cs | 2 +- .../src/Types/ExperimentalFeatures.shared.cs | 60 ------------------- .../src/Types/FileProvider.android.cs | 3 +- src/Essentials/src/Types/Location.shared.cs | 4 +- .../src/Types/LocationExtensions.android.cs | 4 +- ...cationExtensions.ios.tvos.watchos.macos.cs | 2 +- .../src/Types/LocationExtensions.shared.cs | 3 +- .../src/Types/LocationExtensions.uwp.cs | 2 +- src/Essentials/src/Types/Placemark.shared.cs | 2 +- .../src/Types/PlacemarkExtensions.android.cs | 2 +- ...cemarkExtensions.ios.tvos.watchos.macos.cs | 2 +- .../src/Types/PlacemarkExtensions.shared.cs | 3 +- .../src/Types/PlacemarkExtensions.uwp.cs | 2 +- .../src/Types/SensorSpeed.android.cs | 2 +- .../src/Types/SensorSpeed.ios.tvos.watchos.cs | 2 +- .../src/Types/SensorSpeed.shared.cs | 2 +- src/Essentials/src/Types/SensorSpeed.tizen.cs | 2 +- src/Essentials/src/Types/SensorSpeed.uwp.cs | 2 +- .../src/Types/Shared/Exceptions.shared.cs | 25 ++++---- .../Types/Shared/PreserveAttribute.shared.cs | 2 +- .../src/Types/Shared/Utils.shared.cs | 2 +- .../src/Types/Shared/WebUtils.shared.cs | 2 +- .../VersionTracking/VersionTracking.shared.cs | 5 +- .../src/Vibration/Vibration.android.cs | 4 +- src/Essentials/src/Vibration/Vibration.ios.cs | 2 +- ...ibration.netstandard.tvos.watchos.macos.cs | 2 +- .../src/Vibration/Vibration.shared.cs | 6 +- .../src/Vibration/Vibration.tizen.cs | 2 +- src/Essentials/src/Vibration/Vibration.uwp.cs | 2 +- .../AppleSignInAuthenticator.ios.cs | 3 +- ...rd.android.tvos.watchos.uwp.tizen.macos.cs | 2 +- .../AppleSignInAuthenticator.shared.cs | 6 +- .../WebAuthenticator.android.cs | 3 +- .../WebAuthenticator.ios.tvos.cs | 6 +- .../WebAuthenticator.macos.cs | 2 +- ...Authenticator.netstandard.watchos.tizen.cs | 2 +- .../WebAuthenticator.shared.cs | 10 ++-- .../WebAuthenticator/WebAuthenticator.uwp.cs | 3 +- ...ebAuthenticatorCallbackActivity.android.cs | 2 +- ...thenticatorIntermediateActivity.android.cs | 2 +- .../WebAuthenticatorResult.shared.cs | 2 +- 293 files changed, 507 insertions(+), 449 deletions(-) delete mode 100644 src/Essentials/src/Types/ExperimentalFeatures.shared.cs diff --git a/src/Essentials/src/Accelerometer/Accelerometer.android.cs b/src/Essentials/src/Accelerometer/Accelerometer.android.cs index 036e82391d9b..69f275efc16a 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.android.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.android.cs @@ -1,7 +1,8 @@ using Android.Hardware; using Android.Runtime; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class AccelerometerImplementation { diff --git a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs index db934b2067ac..011cdab2b991 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs @@ -1,7 +1,8 @@ using CoreMotion; using Foundation; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class AccelerometerImplementation { diff --git a/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs b/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs index f4955c7d6c5b..0b97d55e98c7 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { /// public partial class AccelerometerImplementation diff --git a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs index 215c35550757..35017efdd2d6 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs @@ -2,9 +2,10 @@ using System; using System.ComponentModel; using System.Numerics; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices.Sensors.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface IAccelerometer { @@ -123,7 +124,7 @@ public override string ToString() => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class AccelerometerImplementation : IAccelerometer { diff --git a/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs b/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs index 577abb8b2392..655ff08b847c 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs @@ -1,7 +1,7 @@ using Tizen.Sensor; using TizenAccelerometer = Tizen.Sensor.Accelerometer; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class AccelerometerImplementation { diff --git a/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs b/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs index dc1e0a8efff9..dd83b864f502 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs @@ -1,7 +1,7 @@ using Windows.Devices.Sensors; using WindowsAccelerometer = Windows.Devices.Sensors.Accelerometer; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class AccelerometerImplementation { diff --git a/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs b/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs index 3b8728a4f82f..c2ffae04c0c1 100644 --- a/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs +++ b/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { // Detect if 3/4ths of the accelerometer events in the last half second are accelerating // this means we are free falling or shaking diff --git a/src/Essentials/src/AppActions/AppActions.android.cs b/src/Essentials/src/AppActions/AppActions.android.cs index 483bfd152c7a..0971bc76daaf 100755 --- a/src/Essentials/src/AppActions/AppActions.android.cs +++ b/src/Essentials/src/AppActions/AppActions.android.cs @@ -5,8 +5,9 @@ using Android.Content.PM; using Android.Graphics.Drawables; using Android.Runtime; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class AppActionsImplementation : IAppActions { diff --git a/src/Essentials/src/AppActions/AppActions.ios.cs b/src/Essentials/src/AppActions/AppActions.ios.cs index 6017c2fbceae..7930faff9cea 100755 --- a/src/Essentials/src/AppActions/AppActions.ios.cs +++ b/src/Essentials/src/AppActions/AppActions.ios.cs @@ -5,7 +5,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class AppActionsImplementation : IAppActions { diff --git a/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs b/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs index b7489293239c..31cf550ad0df 100755 --- a/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs +++ b/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { /// public partial class AppActionsImplementation : IAppActions diff --git a/src/Essentials/src/AppActions/AppActions.shared.cs b/src/Essentials/src/AppActions/AppActions.shared.cs index 23ab16f82516..8b6ea38d8117 100755 --- a/src/Essentials/src/AppActions/AppActions.shared.cs +++ b/src/Essentials/src/AppActions/AppActions.shared.cs @@ -2,10 +2,9 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public interface IAppActions { @@ -13,7 +12,7 @@ public interface IAppActions string Type { get; } - Task> GetAsync (); + Task> GetAsync (); Task SetAsync (IEnumerable actions); Task SetAsync (params AppAction[] actions); diff --git a/src/Essentials/src/AppActions/AppActions.uwp.cs b/src/Essentials/src/AppActions/AppActions.uwp.cs index 54c472c7dbfb..e8fb8c292207 100755 --- a/src/Essentials/src/AppActions/AppActions.uwp.cs +++ b/src/Essentials/src/AppActions/AppActions.uwp.cs @@ -11,7 +11,7 @@ using Microsoft.UI.Xaml; #endif -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class AppActions { @@ -48,7 +48,7 @@ internal static async Task OnLaunched(LaunchActivatedEventArgs e) } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class AppActionsImplementation : IAppActions { diff --git a/src/Essentials/src/AppInfo/AppInfo.android.cs b/src/Essentials/src/AppInfo/AppInfo.android.cs index 02b071195fc9..0cdf2fcbb40e 100644 --- a/src/Essentials/src/AppInfo/AppInfo.android.cs +++ b/src/Essentials/src/AppInfo/AppInfo.android.cs @@ -5,8 +5,9 @@ using Android.Content.Res; using Android.Provider; using AndroidX.Core.Content.PM; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class AppInfoImplementation : IAppInfo { diff --git a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs index 90e332127b42..85a21716c463 100644 --- a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Foundation; +using Microsoft.Maui.Essentials; #if __IOS__ || __TVOS__ using ObjCRuntime; using UIKit; @@ -9,7 +10,7 @@ using AppKit; #endif -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class AppInfoImplementation : IAppInfo { diff --git a/src/Essentials/src/AppInfo/AppInfo.netstandard.cs b/src/Essentials/src/AppInfo/AppInfo.netstandard.cs index 57d9c6e6aa02..8d36ebb5f816 100644 --- a/src/Essentials/src/AppInfo/AppInfo.netstandard.cs +++ b/src/Essentials/src/AppInfo/AppInfo.netstandard.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { /// public class AppInfoImplementation : IAppInfo diff --git a/src/Essentials/src/AppInfo/AppInfo.shared.cs b/src/Essentials/src/AppInfo/AppInfo.shared.cs index 977b77374890..9a83e4352158 100644 --- a/src/Essentials/src/AppInfo/AppInfo.shared.cs +++ b/src/Essentials/src/AppInfo/AppInfo.shared.cs @@ -1,9 +1,9 @@ #nullable enable using System; using System.ComponentModel; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public interface IAppInfo { diff --git a/src/Essentials/src/AppInfo/AppInfo.tizen.cs b/src/Essentials/src/AppInfo/AppInfo.tizen.cs index a398afe5ddac..a31091baadbb 100644 --- a/src/Essentials/src/AppInfo/AppInfo.tizen.cs +++ b/src/Essentials/src/AppInfo/AppInfo.tizen.cs @@ -1,7 +1,7 @@ using System.Globalization; using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class AppInfoImplementation { diff --git a/src/Essentials/src/AppInfo/AppInfo.uwp.cs b/src/Essentials/src/AppInfo/AppInfo.uwp.cs index e9de164083dd..65b672b2d85d 100644 --- a/src/Essentials/src/AppInfo/AppInfo.uwp.cs +++ b/src/Essentials/src/AppInfo/AppInfo.uwp.cs @@ -7,7 +7,7 @@ using Windows.UI.Xaml; #endif -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class AppInfoImplementation : IAppInfo { diff --git a/src/Essentials/src/AppInfo/AppTheme.shared.cs b/src/Essentials/src/AppInfo/AppTheme.shared.cs index d29040a613dc..521a53d2ef01 100644 --- a/src/Essentials/src/AppInfo/AppTheme.shared.cs +++ b/src/Essentials/src/AppInfo/AppTheme.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public enum AppTheme diff --git a/src/Essentials/src/AppInfo/LayoutDirection.shared.cs b/src/Essentials/src/AppInfo/LayoutDirection.shared.cs index 69e37fcce758..65a08c53a33a 100644 --- a/src/Essentials/src/AppInfo/LayoutDirection.shared.cs +++ b/src/Essentials/src/AppInfo/LayoutDirection.shared.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public enum LayoutDirection { diff --git a/src/Essentials/src/Barometer/Barometer.android.cs b/src/Essentials/src/Barometer/Barometer.android.cs index 377d7ec9fed9..cf3b2b379635 100644 --- a/src/Essentials/src/Barometer/Barometer.android.cs +++ b/src/Essentials/src/Barometer/Barometer.android.cs @@ -1,8 +1,9 @@ using System; using Android.Hardware; using Android.Runtime; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class BarometerImplementation : IBarometer { diff --git a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs index 09fc39c8652d..15a32c611347 100644 --- a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs +++ b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs @@ -1,8 +1,9 @@ using System; using CoreMotion; using Foundation; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class BarometerImplementation : IBarometer { diff --git a/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs b/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs index c07fec2247b2..6774194fa4e0 100644 --- a/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class BarometerImplementation : IBarometer { diff --git a/src/Essentials/src/Barometer/Barometer.shared.cs b/src/Essentials/src/Barometer/Barometer.shared.cs index c501484f1af0..60acee498924 100644 --- a/src/Essentials/src/Barometer/Barometer.shared.cs +++ b/src/Essentials/src/Barometer/Barometer.shared.cs @@ -1,8 +1,9 @@ using System; using System.ComponentModel; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices.Sensors.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface IBarometer { @@ -101,7 +102,7 @@ public override int GetHashCode() => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class BarometerImplementation : IBarometer { diff --git a/src/Essentials/src/Barometer/Barometer.tizen.cs b/src/Essentials/src/Barometer/Barometer.tizen.cs index ee32d3a9afeb..83e071a334c5 100644 --- a/src/Essentials/src/Barometer/Barometer.tizen.cs +++ b/src/Essentials/src/Barometer/Barometer.tizen.cs @@ -2,7 +2,7 @@ using Tizen.Sensor; using TizenBarometerSensor = Tizen.Sensor.PressureSensor; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public class BarometerImplementation : IBarometer { diff --git a/src/Essentials/src/Barometer/Barometer.uwp.cs b/src/Essentials/src/Barometer/Barometer.uwp.cs index f63463eb0fd7..08b5d38992cb 100644 --- a/src/Essentials/src/Barometer/Barometer.uwp.cs +++ b/src/Essentials/src/Barometer/Barometer.uwp.cs @@ -2,7 +2,7 @@ using Windows.Devices.Sensors; using WinBarometer = Windows.Devices.Sensors.Barometer; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class BarometerImplementation : IBarometer { diff --git a/src/Essentials/src/Battery/Battery.android.cs b/src/Essentials/src/Battery/Battery.android.cs index 3c2d8b50238a..7a1f02a69cb6 100755 --- a/src/Essentials/src/Battery/Battery.android.cs +++ b/src/Essentials/src/Battery/Battery.android.cs @@ -1,8 +1,10 @@ using System; using Android.Content; using Android.OS; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class BatteryImplementation : IBattery { diff --git a/src/Essentials/src/Battery/Battery.ios.watchos.cs b/src/Essentials/src/Battery/Battery.ios.watchos.cs index c94858a191fd..50bffd2e364e 100755 --- a/src/Essentials/src/Battery/Battery.ios.watchos.cs +++ b/src/Essentials/src/Battery/Battery.ios.watchos.cs @@ -1,4 +1,5 @@ using Foundation; +using Microsoft.Maui.ApplicationModel; #if __IOS__ using ObjCRuntime; using UIKit; @@ -7,7 +8,7 @@ using UIDeviceBatteryState = WatchKit.WKInterfaceDeviceBatteryState; #endif -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class BatteryImplementation : IBattery { diff --git a/src/Essentials/src/Battery/Battery.macos.cs b/src/Essentials/src/Battery/Battery.macos.cs index 2b55f29539ab..4dc8fcbc9914 100755 --- a/src/Essentials/src/Battery/Battery.macos.cs +++ b/src/Essentials/src/Battery/Battery.macos.cs @@ -1,7 +1,7 @@ using System; using CoreFoundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class BatteryImplementation : IBattery { diff --git a/src/Essentials/src/Battery/Battery.netstandard.tvos.cs b/src/Essentials/src/Battery/Battery.netstandard.tvos.cs index c9754c901756..6820dea276b1 100755 --- a/src/Essentials/src/Battery/Battery.netstandard.tvos.cs +++ b/src/Essentials/src/Battery/Battery.netstandard.tvos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { /// public partial class BatteryImplementation : IBattery diff --git a/src/Essentials/src/Battery/Battery.shared.cs b/src/Essentials/src/Battery/Battery.shared.cs index 5d8904dd6699..1fbbc2c46dfc 100755 --- a/src/Essentials/src/Battery/Battery.shared.cs +++ b/src/Essentials/src/Battery/Battery.shared.cs @@ -1,9 +1,8 @@ using System; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { public interface IBattery { diff --git a/src/Essentials/src/Battery/Battery.tizen.cs b/src/Essentials/src/Battery/Battery.tizen.cs index 71f821170f3f..4e3cff415c28 100755 --- a/src/Essentials/src/Battery/Battery.tizen.cs +++ b/src/Essentials/src/Battery/Battery.tizen.cs @@ -1,7 +1,7 @@ using System; using TizenBattery = Tizen.System.Battery; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class BatteryImplementation : IBattery { diff --git a/src/Essentials/src/Battery/Battery.uwp.cs b/src/Essentials/src/Battery/Battery.uwp.cs index 16c409e5cb8d..f9d4840361c0 100755 --- a/src/Essentials/src/Battery/Battery.uwp.cs +++ b/src/Essentials/src/Battery/Battery.uwp.cs @@ -1,6 +1,7 @@ +using Microsoft.Maui.ApplicationModel; using Windows.System.Power; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class BatteryImplementation : IBattery { diff --git a/src/Essentials/src/Browser/Browser.android.cs b/src/Essentials/src/Browser/Browser.android.cs index ddbe61dcb972..53b56a0021a0 100755 --- a/src/Essentials/src/Browser/Browser.android.cs +++ b/src/Essentials/src/Browser/Browser.android.cs @@ -2,9 +2,10 @@ using System.Threading.Tasks; using Android.Content; using AndroidX.Browser.CustomTabs; +using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class BrowserImplementation : IBrowser { diff --git a/src/Essentials/src/Browser/Browser.ios.cs b/src/Essentials/src/Browser/Browser.ios.cs index bed55612449a..92271fb709a1 100755 --- a/src/Essentials/src/Browser/Browser.ios.cs +++ b/src/Essentials/src/Browser/Browser.ios.cs @@ -1,12 +1,13 @@ using System; using System.Threading.Tasks; using Foundation; +using Microsoft.Maui.Essentials; using Microsoft.Maui.Graphics.Platform; using ObjCRuntime; using SafariServices; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class BrowserImplementation : IBrowser { diff --git a/src/Essentials/src/Browser/Browser.macos.cs b/src/Essentials/src/Browser/Browser.macos.cs index bb292d43fd5f..0fccc43e30b9 100755 --- a/src/Essentials/src/Browser/Browser.macos.cs +++ b/src/Essentials/src/Browser/Browser.macos.cs @@ -3,7 +3,7 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class BrowserImplementation : IBrowser { diff --git a/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs b/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs index b0cde8ebaffa..d022c8cd9473 100755 --- a/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { /// public partial class BrowserImplementation : IBrowser diff --git a/src/Essentials/src/Browser/Browser.shared.cs b/src/Essentials/src/Browser/Browser.shared.cs index 9f2299e20cfe..e14bab27e762 100755 --- a/src/Essentials/src/Browser/Browser.shared.cs +++ b/src/Essentials/src/Browser/Browser.shared.cs @@ -1,11 +1,11 @@ using System; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.ApplicationModel.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public interface IBrowser { diff --git a/src/Essentials/src/Browser/Browser.tizen.cs b/src/Essentials/src/Browser/Browser.tizen.cs index 9601b6b73a22..ac0b21d2a748 100755 --- a/src/Essentials/src/Browser/Browser.tizen.cs +++ b/src/Essentials/src/Browser/Browser.tizen.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class BrowserImplementation : IBrowser { diff --git a/src/Essentials/src/Browser/Browser.uwp.cs b/src/Essentials/src/Browser/Browser.uwp.cs index 0d00ecc6e832..2bbb7d65e719 100755 --- a/src/Essentials/src/Browser/Browser.uwp.cs +++ b/src/Essentials/src/Browser/Browser.uwp.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class BrowserImplementation : IBrowser { diff --git a/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs b/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs index c234f854d87a..28dfe788bc49 100755 --- a/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs +++ b/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public enum BrowserLaunchMode diff --git a/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs b/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs index 3d0cda6edf9e..6c72348e84b3 100755 --- a/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs +++ b/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Maui.Graphics; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public class BrowserLaunchOptions diff --git a/src/Essentials/src/Browser/BrowserTitleMode.shared.cs b/src/Essentials/src/Browser/BrowserTitleMode.shared.cs index 80dc11fa5b07..51512bd51268 100755 --- a/src/Essentials/src/Browser/BrowserTitleMode.shared.cs +++ b/src/Essentials/src/Browser/BrowserTitleMode.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public enum BrowserTitleMode diff --git a/src/Essentials/src/Clipboard/Clipboard.android.cs b/src/Essentials/src/Clipboard/Clipboard.android.cs index a6f84031de9f..b25acd1160be 100644 --- a/src/Essentials/src/Clipboard/Clipboard.android.cs +++ b/src/Essentials/src/Clipboard/Clipboard.android.cs @@ -1,9 +1,10 @@ using System; using System.Threading.Tasks; using Android.Content; +using Microsoft.Maui.Essentials; using static Android.Content.ClipboardManager; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public partial class ClipboardImplementation : IClipboard { diff --git a/src/Essentials/src/Clipboard/Clipboard.ios.cs b/src/Essentials/src/Clipboard/Clipboard.ios.cs index 335886faf139..f1c59f3c1bc9 100644 --- a/src/Essentials/src/Clipboard/Clipboard.ios.cs +++ b/src/Essentials/src/Clipboard/Clipboard.ios.cs @@ -4,7 +4,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public partial class ClipboardImplementation : IClipboard { diff --git a/src/Essentials/src/Clipboard/Clipboard.macos.cs b/src/Essentials/src/Clipboard/Clipboard.macos.cs index ac4e0f99e35f..79a5a4217e01 100644 --- a/src/Essentials/src/Clipboard/Clipboard.macos.cs +++ b/src/Essentials/src/Clipboard/Clipboard.macos.cs @@ -3,7 +3,7 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public partial class ClipboardImplementation : IClipboard { diff --git a/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs b/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs index e68829c385f7..65914bcc2699 100644 --- a/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs +++ b/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { /// public partial class ClipboardImplementation : IClipboard diff --git a/src/Essentials/src/Clipboard/Clipboard.shared.cs b/src/Essentials/src/Clipboard/Clipboard.shared.cs index 1cbd2f8d6505..34c3d3200782 100644 --- a/src/Essentials/src/Clipboard/Clipboard.shared.cs +++ b/src/Essentials/src/Clipboard/Clipboard.shared.cs @@ -1,10 +1,10 @@ using System; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.DataTransfer; +using Microsoft.Maui.ApplicationModel.DataTransfer.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.DataTransfer { public interface IClipboard { diff --git a/src/Essentials/src/Clipboard/Clipboard.uwp.cs b/src/Essentials/src/Clipboard/Clipboard.uwp.cs index 4862d03b5079..24e52b6b2cc4 100644 --- a/src/Essentials/src/Clipboard/Clipboard.uwp.cs +++ b/src/Essentials/src/Clipboard/Clipboard.uwp.cs @@ -4,7 +4,7 @@ using WindowsClipboard = Windows.ApplicationModel.DataTransfer.Clipboard; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public partial class ClipboardImplementation : IClipboard { diff --git a/src/Essentials/src/Compass/Compass.android.cs b/src/Essentials/src/Compass/Compass.android.cs index d815218f1add..f389f70300e4 100644 --- a/src/Essentials/src/Compass/Compass.android.cs +++ b/src/Essentials/src/Compass/Compass.android.cs @@ -1,8 +1,9 @@ using System; using Android.Hardware; using Android.Runtime; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class CompassImplementation : ICompass { diff --git a/src/Essentials/src/Compass/Compass.ios.cs b/src/Essentials/src/Compass/Compass.ios.cs index d40bc6d283cc..50ae74c15076 100644 --- a/src/Essentials/src/Compass/Compass.ios.cs +++ b/src/Essentials/src/Compass/Compass.ios.cs @@ -1,6 +1,6 @@ using CoreLocation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class CompassImplementation : ICompass, IPlatformCompass { diff --git a/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs b/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs index 0c45da9173f9..ca3c645619c2 100644 --- a/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs +++ b/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class CompassImplementation : ICompass { diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index e55f4c39b830..56edbac155d6 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -1,9 +1,10 @@ using System; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices.Sensors; +using Microsoft.Maui.Devices.Sensors.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface ICompass { @@ -133,7 +134,7 @@ public override string ToString() => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class CompassImplementation : ICompass { diff --git a/src/Essentials/src/Compass/Compass.tizen.cs b/src/Essentials/src/Compass/Compass.tizen.cs index faa1b8833bab..82deb70a001e 100644 --- a/src/Essentials/src/Compass/Compass.tizen.cs +++ b/src/Essentials/src/Compass/Compass.tizen.cs @@ -1,7 +1,7 @@ using Tizen.Sensor; using TizenCompass = Tizen.Sensor.OrientationSensor; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class CompassImplementation : ICompass { diff --git a/src/Essentials/src/Compass/Compass.uwp.cs b/src/Essentials/src/Compass/Compass.uwp.cs index d176a32843ac..564b9bd27347 100644 --- a/src/Essentials/src/Compass/Compass.uwp.cs +++ b/src/Essentials/src/Compass/Compass.uwp.cs @@ -2,7 +2,7 @@ using WindowsCompass = Windows.Devices.Sensors.Compass; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class CompassImplementation : ICompass { diff --git a/src/Essentials/src/Compass/LowPassFilter.shared.cs b/src/Essentials/src/Compass/LowPassFilter.shared.cs index 78866232ee76..b0d56e518f86 100644 --- a/src/Essentials/src/Compass/LowPassFilter.shared.cs +++ b/src/Essentials/src/Compass/LowPassFilter.shared.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { class LowPassFilter { diff --git a/src/Essentials/src/Connectivity/Connectivity.android.cs b/src/Essentials/src/Connectivity/Connectivity.android.cs index b824ccef1a3e..d07d98e629ec 100644 --- a/src/Essentials/src/Connectivity/Connectivity.android.cs +++ b/src/Essentials/src/Connectivity/Connectivity.android.cs @@ -4,9 +4,11 @@ using Android.Content; using Android.Net; using Android.OS; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; using Debug = System.Diagnostics.Debug; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Networking.Implementations { public partial class ConnectivityImplementation : IConnectivity { diff --git a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs index 6a371615c002..4689d7e0d6ac 100644 --- a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs +++ b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Networking.Implementations { public partial class ConnectivityImplementation : IConnectivity { diff --git a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs index 452923505ae6..484dff8a16a9 100644 --- a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs +++ b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs @@ -8,7 +8,7 @@ using CoreFoundation; using SystemConfiguration; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Networking.Implementations { enum NetworkStatus { diff --git a/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs b/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs index fe8a64fcf55a..617a32b828b5 100644 --- a/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs +++ b/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Networking.Implementations { /// public partial class ConnectivityImplementation : IConnectivity diff --git a/src/Essentials/src/Connectivity/Connectivity.shared.cs b/src/Essentials/src/Connectivity/Connectivity.shared.cs index 0dfbbf2e1d15..87da8ff1251b 100644 --- a/src/Essentials/src/Connectivity/Connectivity.shared.cs +++ b/src/Essentials/src/Connectivity/Connectivity.shared.cs @@ -3,9 +3,10 @@ using System.Linq; using System.ComponentModel; using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Networking.Implementations; +using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Networking { public interface IConnectivity { diff --git a/src/Essentials/src/Connectivity/Connectivity.shared.enums.cs b/src/Essentials/src/Connectivity/Connectivity.shared.enums.cs index aaa64ce29eba..65662128e6f6 100644 --- a/src/Essentials/src/Connectivity/Connectivity.shared.enums.cs +++ b/src/Essentials/src/Connectivity/Connectivity.shared.enums.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Networking { /// public enum ConnectionProfile diff --git a/src/Essentials/src/Connectivity/Connectivity.tizen.cs b/src/Essentials/src/Connectivity/Connectivity.tizen.cs index 86e603435f87..1756cee9049e 100644 --- a/src/Essentials/src/Connectivity/Connectivity.tizen.cs +++ b/src/Essentials/src/Connectivity/Connectivity.tizen.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using Tizen.Network.Connection; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Networking.Implementations { public partial class ConnectivityImplementation : IConnectivity { diff --git a/src/Essentials/src/Connectivity/Connectivity.uwp.cs b/src/Essentials/src/Connectivity/Connectivity.uwp.cs index 7aac31ea7550..747ee69b7e2b 100644 --- a/src/Essentials/src/Connectivity/Connectivity.uwp.cs +++ b/src/Essentials/src/Connectivity/Connectivity.uwp.cs @@ -3,7 +3,7 @@ using System.Linq; using Windows.Networking.Connectivity; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Networking.Implementations { public partial class ConnectivityImplementation : IConnectivity { diff --git a/src/Essentials/src/Contacts/Contacts.android.cs b/src/Essentials/src/Contacts/Contacts.android.cs index 3f0693a3cc34..cfc951b63c79 100644 --- a/src/Essentials/src/Contacts/Contacts.android.cs +++ b/src/Essentials/src/Contacts/Contacts.android.cs @@ -5,10 +5,11 @@ using Android.Content; using Android.Database; using Android.Provider; +using Microsoft.Maui.Essentials; using CommonDataKinds = Android.Provider.ContactsContract.CommonDataKinds; using StructuredName = Android.Provider.ContactsContract.CommonDataKinds.StructuredName; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public class ContactsImplementation : IContacts { diff --git a/src/Essentials/src/Contacts/Contacts.ios.macos.cs b/src/Essentials/src/Contacts/Contacts.ios.macos.cs index c70719a67ab9..bf17e8c0a235 100644 --- a/src/Essentials/src/Contacts/Contacts.ios.macos.cs +++ b/src/Essentials/src/Contacts/Contacts.ios.macos.cs @@ -6,9 +6,10 @@ using Contacts; #if __IOS__ using ContactsUI; +using Microsoft.Maui.Essentials; #endif -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public class ContactsImplementation : IContacts { diff --git a/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs b/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs index 159f87a9c56d..0a66b1244c28 100644 --- a/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { /// public class ContactsImplementation : IContacts diff --git a/src/Essentials/src/Contacts/Contacts.shared.cs b/src/Essentials/src/Contacts/Contacts.shared.cs index 5313b7d79601..33976c55fade 100644 --- a/src/Essentials/src/Contacts/Contacts.shared.cs +++ b/src/Essentials/src/Contacts/Contacts.shared.cs @@ -3,9 +3,10 @@ using System.ComponentModel; using System.Threading; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.Communication.Implementations; +using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { public interface IContacts { diff --git a/src/Essentials/src/Contacts/Contacts.tizen.cs b/src/Essentials/src/Contacts/Contacts.tizen.cs index 9322bdb81260..32e1722bb70c 100644 --- a/src/Essentials/src/Contacts/Contacts.tizen.cs +++ b/src/Essentials/src/Contacts/Contacts.tizen.cs @@ -9,7 +9,7 @@ using TizenName = Tizen.Pims.Contacts.ContactsViews.Name; using TizenNumber = Tizen.Pims.Contacts.ContactsViews.Number; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { public static partial class Contacts { diff --git a/src/Essentials/src/Contacts/Contacts.uwp.cs b/src/Essentials/src/Contacts/Contacts.uwp.cs index 422134d90a61..4fa8a3cd3014 100644 --- a/src/Essentials/src/Contacts/Contacts.uwp.cs +++ b/src/Essentials/src/Contacts/Contacts.uwp.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Windows.ApplicationModel.Contacts; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public class ContactsImplementation:IContacts { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs index d46076f7fb5e..515feba118ce 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs @@ -8,8 +8,9 @@ using Android.Runtime; using Android.Util; using Android.Views; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceDisplayImplementation : IDeviceDisplay { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs index 64acccf992af..62f1f73613ab 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs @@ -4,7 +4,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceDisplayImplementation : IDeviceDisplay { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs index 8890d5cd853d..8a34c404aaaf 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs @@ -4,7 +4,7 @@ using CoreVideo; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceDisplayImplementation : IDeviceDisplay { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs index 6127fd4c28d5..fa251c8d754c 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs @@ -1,7 +1,7 @@ #nullable enable using System; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceDisplayImplementation : IDeviceDisplay { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs index de102ed09908..e74ba8b0491d 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs @@ -1,9 +1,9 @@ #nullable enable using System; using System.ComponentModel; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public static partial class DeviceDisplay diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs index a256588e5029..5a145780a2b9 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceDisplayImplementation : IDeviceDisplay { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs index 09e1c2974177..53becf169591 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs @@ -1,12 +1,14 @@ #nullable enable using System; using System.Runtime.InteropServices; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; using Microsoft.UI.Windowing; using Windows.Graphics.Display; using Windows.Graphics.Display.Core; using Windows.System.Display; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceDisplayImplementation : IDeviceDisplay { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs index c4a1812b9dce..5b416ecd1eef 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs @@ -4,7 +4,7 @@ using Android.OS; using Android.Provider; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceInfoImplementation : IDeviceInfo { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs index b23fd61487f2..5dd7a2a78e71 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs @@ -9,7 +9,7 @@ using ObjCRuntime; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceInfoImplementation : IDeviceInfo { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs index 2863db3c5671..b3e19f8bd90f 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs @@ -3,7 +3,7 @@ using Foundation; using ObjCRuntime; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceInfoImplementation : IDeviceInfo { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs index d328acd000d1..05863fcc36f3 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceInfoImplementation : IDeviceInfo { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs index c54ebe79a607..6205b07982f6 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs @@ -1,9 +1,9 @@ #nullable enable using System; using System.ComponentModel; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public static class DeviceInfo diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs index 61a4b8435773..c6c4925e38a0 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs @@ -1,6 +1,6 @@ using Plat = Microsoft.Maui.Essentials.Platform; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceInfoImplementation : IDeviceInfo { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs index a8b359511b2d..097f814b810b 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs @@ -4,7 +4,7 @@ using Windows.System.Profile; using Windows.UI.ViewManagement; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class DeviceInfoImplementation : IDeviceInfo { diff --git a/src/Essentials/src/Email/Email.android.cs b/src/Essentials/src/Email/Email.android.cs index 3744db2fd230..657b2524a14a 100644 --- a/src/Essentials/src/Email/Email.android.cs +++ b/src/Essentials/src/Email/Email.android.cs @@ -6,9 +6,11 @@ using Android.OS; using Android.Text; using Android.Webkit; +using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; using Uri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class EmailImplementation : IEmail { diff --git a/src/Essentials/src/Email/Email.ios.cs b/src/Essentials/src/Email/Email.ios.cs index b05f13d20d4c..0cc45904d99c 100644 --- a/src/Essentials/src/Email/Email.ios.cs +++ b/src/Essentials/src/Email/Email.ios.cs @@ -7,8 +7,9 @@ #endif using ObjCRuntime; using UIKit; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class EmailImplementation : IEmail { diff --git a/src/Essentials/src/Email/Email.macos.cs b/src/Essentials/src/Email/Email.macos.cs index 64cdabd110e0..ea28d8398a54 100644 --- a/src/Essentials/src/Email/Email.macos.cs +++ b/src/Essentials/src/Email/Email.macos.cs @@ -2,7 +2,7 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class EmailImplementation : IEmail { diff --git a/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs b/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs index f765a6da060a..bd51595af2a8 100644 --- a/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { /// public partial class EmailImplementation : IEmail @@ -11,15 +11,18 @@ public partial class EmailImplementation : IEmail public Task ComposeAsync(EmailMessage message) => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task ComposeAsync(string subject, string body, params string[] to) + public Task ComposeAsync(string subject, string body, params string[] to) => throw ExceptionUtils.NotSupportedOrImplementedException; public Task ComposeAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; } +} +namespace Microsoft.Maui.ApplicationModel.Communication +{ #if NETSTANDARD || NET6_0 - /// +/// public partial class EmailAttachment { string PlatformGetContentType(string extension) => diff --git a/src/Essentials/src/Email/Email.shared.cs b/src/Essentials/src/Email/Email.shared.cs index 85de0bd5971b..43d7cb7e4cee 100644 --- a/src/Essentials/src/Email/Email.shared.cs +++ b/src/Essentials/src/Email/Email.shared.cs @@ -4,9 +4,10 @@ using System.Threading.Tasks; using System.ComponentModel; using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.Communication.Implementations; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { public interface IEmail { diff --git a/src/Essentials/src/Email/Email.tizen.cs b/src/Essentials/src/Email/Email.tizen.cs index e2b451c72114..277ffc8754ca 100644 --- a/src/Essentials/src/Email/Email.tizen.cs +++ b/src/Essentials/src/Email/Email.tizen.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class EmailImplementation : IEmail { diff --git a/src/Essentials/src/Email/Email.uwp.cs b/src/Essentials/src/Email/Email.uwp.cs index 95fd82f6a993..1a405a5fa8bd 100644 --- a/src/Essentials/src/Email/Email.uwp.cs +++ b/src/Essentials/src/Email/Email.uwp.cs @@ -10,7 +10,7 @@ using PlatformEmailAttachment = Windows.ApplicationModel.Email.EmailAttachment; using PlatformEmailMessage = Windows.ApplicationModel.Email.EmailMessage; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class EmailImplementation : IEmail { diff --git a/src/Essentials/src/FilePicker/FilePicker.android.cs b/src/Essentials/src/FilePicker/FilePicker.android.cs index 386c32185bf3..17ee54ef28a2 100644 --- a/src/Essentials/src/FilePicker/FilePicker.android.cs +++ b/src/Essentials/src/FilePicker/FilePicker.android.cs @@ -4,8 +4,10 @@ using System.Linq; using System.Threading.Tasks; using Android.Content; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public static partial class FilePicker { diff --git a/src/Essentials/src/FilePicker/FilePicker.ios.cs b/src/Essentials/src/FilePicker/FilePicker.ios.cs index 631b32070643..bdb3988b4180 100644 --- a/src/Essentials/src/FilePicker/FilePicker.ios.cs +++ b/src/Essentials/src/FilePicker/FilePicker.ios.cs @@ -7,8 +7,10 @@ using MobileCoreServices; using ObjCRuntime; using UIKit; +using Microsoft.Maui.Essentials; +using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public static partial class FilePicker { diff --git a/src/Essentials/src/FilePicker/FilePicker.macos.cs b/src/Essentials/src/FilePicker/FilePicker.macos.cs index e4fded76386b..847535d4d408 100644 --- a/src/Essentials/src/FilePicker/FilePicker.macos.cs +++ b/src/Essentials/src/FilePicker/FilePicker.macos.cs @@ -4,7 +4,7 @@ using AppKit; using MobileCoreServices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public static partial class FilePicker { diff --git a/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs b/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs index 5388649041e3..e1027b74c844 100644 --- a/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs +++ b/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs @@ -2,7 +2,7 @@ using System.IO; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { /// public static partial class FilePicker diff --git a/src/Essentials/src/FilePicker/FilePicker.shared.cs b/src/Essentials/src/FilePicker/FilePicker.shared.cs index d5914da90b45..1f3dc56ab0f0 100644 --- a/src/Essentials/src/FilePicker/FilePicker.shared.cs +++ b/src/Essentials/src/FilePicker/FilePicker.shared.cs @@ -3,8 +3,9 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { /// public static partial class FilePicker diff --git a/src/Essentials/src/FilePicker/FilePicker.tizen.cs b/src/Essentials/src/FilePicker/FilePicker.tizen.cs index a25b2d9cae7b..a5e06a2b27bc 100644 --- a/src/Essentials/src/FilePicker/FilePicker.tizen.cs +++ b/src/Essentials/src/FilePicker/FilePicker.tizen.cs @@ -7,7 +7,7 @@ using Tizen; using Tizen.Applications; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public static partial class FilePicker { diff --git a/src/Essentials/src/FilePicker/FilePicker.uwp.cs b/src/Essentials/src/FilePicker/FilePicker.uwp.cs index cf0db521f516..ffcc82932486 100644 --- a/src/Essentials/src/FilePicker/FilePicker.uwp.cs +++ b/src/Essentials/src/FilePicker/FilePicker.uwp.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Essentials; using Windows.Storage; using Windows.Storage.AccessCache; using Windows.Storage.Pickers; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public static partial class FilePicker { diff --git a/src/Essentials/src/FileSystem/FileSystem.android.cs b/src/Essentials/src/FileSystem/FileSystem.android.cs index 475cf3384caf..eb7ef1320842 100644 --- a/src/Essentials/src/FileSystem/FileSystem.android.cs +++ b/src/Essentials/src/FileSystem/FileSystem.android.cs @@ -4,9 +4,11 @@ using System.Threading.Tasks; using Android.Provider; using Android.Webkit; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem { @@ -386,7 +388,7 @@ static string QueryContentResolverColumn(AndroidUri contentUri, string columnNam } } -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public partial class FileBase { diff --git a/src/Essentials/src/FileSystem/FileSystem.ios.cs b/src/Essentials/src/FileSystem/FileSystem.ios.cs index 8f79df3e77de..2d9834ed056d 100644 --- a/src/Essentials/src/FileSystem/FileSystem.ios.cs +++ b/src/Essentials/src/FileSystem/FileSystem.ios.cs @@ -8,7 +8,7 @@ using Photos; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem { @@ -49,7 +49,7 @@ public async Task EnsurePhysicalFileResultsAsync(params NSUrl[] ur } } -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { class BookmarkDataFileResult : FileResult { diff --git a/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs b/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs index d5a74a8003ea..5a48057a38e7 100644 --- a/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs @@ -4,7 +4,7 @@ using Foundation; using MobileCoreServices; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class FileSystemImplementation : IFileSystem { @@ -56,7 +56,7 @@ static string GetDirectory(NSSearchPathDirectory directory) } } -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public partial class FileBase { diff --git a/src/Essentials/src/FileSystem/FileSystem.netstandard.cs b/src/Essentials/src/FileSystem/FileSystem.netstandard.cs index 3000e736e9e4..f5812e6b5479 100644 --- a/src/Essentials/src/FileSystem/FileSystem.netstandard.cs +++ b/src/Essentials/src/FileSystem/FileSystem.netstandard.cs @@ -1,7 +1,7 @@ using System.IO; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class FileSystemImplementation : IFileSystem /// @@ -20,7 +20,7 @@ Task PlatformAppPackageFileExistsAsync(string filename) } } -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { /// public partial class FileBase diff --git a/src/Essentials/src/FileSystem/FileSystem.shared.cs b/src/Essentials/src/FileSystem/FileSystem.shared.cs index d231a9ba9334..baee42f62432 100644 --- a/src/Essentials/src/FileSystem/FileSystem.shared.cs +++ b/src/Essentials/src/FileSystem/FileSystem.shared.cs @@ -2,10 +2,10 @@ using System.IO; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Storage; +using Microsoft.Maui.Storage.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public interface IFileSystem { @@ -305,7 +305,7 @@ public FileResult(FileBase file) } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class FileSystemImplementation { diff --git a/src/Essentials/src/FileSystem/FileSystem.tizen.cs b/src/Essentials/src/FileSystem/FileSystem.tizen.cs index ee0a83a810b5..eedad97643ef 100644 --- a/src/Essentials/src/FileSystem/FileSystem.tizen.cs +++ b/src/Essentials/src/FileSystem/FileSystem.tizen.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class FileSystemImplementation : IFileSystem { @@ -40,7 +40,7 @@ static string NormalizePath(string filename) => } } -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public partial class FileBase { diff --git a/src/Essentials/src/FileSystem/FileSystem.uwp.cs b/src/Essentials/src/FileSystem/FileSystem.uwp.cs index 20ef53c304b0..890fd2f937ce 100644 --- a/src/Essentials/src/FileSystem/FileSystem.uwp.cs +++ b/src/Essentials/src/FileSystem/FileSystem.uwp.cs @@ -1,10 +1,11 @@ using System; using System.IO; using System.Threading.Tasks; -using Windows.ApplicationModel; +using Microsoft.Maui.ApplicationModel; using Windows.Storage; +using Package = Windows.ApplicationModel.Package; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class FileSystemImplementation : IFileSystem { @@ -65,7 +66,7 @@ internal static string NormalizePath(string path) } } -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public partial class FileBase { diff --git a/src/Essentials/src/Flashlight/Flashlight.android.cs b/src/Essentials/src/Flashlight/Flashlight.android.cs index aa75236fcf8f..20232d1702b4 100644 --- a/src/Essentials/src/Flashlight/Flashlight.android.cs +++ b/src/Essentials/src/Flashlight/Flashlight.android.cs @@ -4,10 +4,11 @@ using Android.Graphics; using Android.Hardware.Camera2; using Android.OS; - +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; using Camera = Android.Hardware.Camera; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class FlashlightImplementation : IFlashlight { diff --git a/src/Essentials/src/Flashlight/Flashlight.ios.cs b/src/Essentials/src/Flashlight/Flashlight.ios.cs index fdd76e2b4599..80017bc4471f 100644 --- a/src/Essentials/src/Flashlight/Flashlight.ios.cs +++ b/src/Essentials/src/Flashlight/Flashlight.ios.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using AVFoundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class FlashlightImplementation : IFlashlight { diff --git a/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs b/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs index 1782be2c21f2..62f6b1964843 100644 --- a/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs +++ b/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { /// public class FlashlightImplementation : IFlashlight diff --git a/src/Essentials/src/Flashlight/Flashlight.shared.cs b/src/Essentials/src/Flashlight/Flashlight.shared.cs index 8cc4ed63e9a7..4847ece4c512 100644 --- a/src/Essentials/src/Flashlight/Flashlight.shared.cs +++ b/src/Essentials/src/Flashlight/Flashlight.shared.cs @@ -1,9 +1,9 @@ #nullable enable using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { public interface IFlashlight { diff --git a/src/Essentials/src/Flashlight/Flashlight.tizen.cs b/src/Essentials/src/Flashlight/Flashlight.tizen.cs index a9dd1e336165..c07a57eca641 100644 --- a/src/Essentials/src/Flashlight/Flashlight.tizen.cs +++ b/src/Essentials/src/Flashlight/Flashlight.tizen.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Tizen.System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { public static partial class Flashlight { diff --git a/src/Essentials/src/Flashlight/Flashlight.uwp.cs b/src/Essentials/src/Flashlight/Flashlight.uwp.cs index 74e42f9ff044..bfc3040044d3 100644 --- a/src/Essentials/src/Flashlight/Flashlight.uwp.cs +++ b/src/Essentials/src/Flashlight/Flashlight.uwp.cs @@ -5,7 +5,7 @@ using Windows.Devices.Enumeration; using Windows.Devices.Lights; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public class FlashlightImplementation:IFlashlight { diff --git a/src/Essentials/src/Geocoding/Geocoding.android.cs b/src/Essentials/src/Geocoding/Geocoding.android.cs index eaeba47d1309..4d05acf12da8 100644 --- a/src/Essentials/src/Geocoding/Geocoding.android.cs +++ b/src/Essentials/src/Geocoding/Geocoding.android.cs @@ -3,8 +3,9 @@ using System.Threading.Tasks; using Android.App; using Android.Locations; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public class GeocodingImplementation : IGeocoding { diff --git a/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs b/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs index 3156b370f6ca..1cfdbea7c45c 100644 --- a/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using CoreLocation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public class GeocodingImplementation : IGeocoding { diff --git a/src/Essentials/src/Geocoding/Geocoding.netstandard.cs b/src/Essentials/src/Geocoding/Geocoding.netstandard.cs index f7a7c623aede..3384bc7a8034 100644 --- a/src/Essentials/src/Geocoding/Geocoding.netstandard.cs +++ b/src/Essentials/src/Geocoding/Geocoding.netstandard.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { /// public class GeocodingImplementation : IGeocoding diff --git a/src/Essentials/src/Geocoding/Geocoding.shared.cs b/src/Essentials/src/Geocoding/Geocoding.shared.cs index 74c1ddf42f51..c7ef7d2ee36a 100644 --- a/src/Essentials/src/Geocoding/Geocoding.shared.cs +++ b/src/Essentials/src/Geocoding/Geocoding.shared.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Sensors.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface IGeocoding { diff --git a/src/Essentials/src/Geocoding/Geocoding.tizen.cs b/src/Essentials/src/Geocoding/Geocoding.tizen.cs index e5d402f32b4e..ced919897279 100644 --- a/src/Essentials/src/Geocoding/Geocoding.tizen.cs +++ b/src/Essentials/src/Geocoding/Geocoding.tizen.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public static partial class Geocoding { diff --git a/src/Essentials/src/Geocoding/Geocoding.uwp.cs b/src/Essentials/src/Geocoding/Geocoding.uwp.cs index e2ec87eccc7c..0fac8a3d14a3 100644 --- a/src/Essentials/src/Geocoding/Geocoding.uwp.cs +++ b/src/Essentials/src/Geocoding/Geocoding.uwp.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.Maui.Essentials; using Windows.Devices.Geolocation; using Windows.Services.Maps; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public class GeocodingImplementation: IGeocoding { diff --git a/src/Essentials/src/Geolocation/Geolocation.android.cs b/src/Essentials/src/Geolocation/Geolocation.android.cs index 29d163327d6c..860badc3c35b 100644 --- a/src/Essentials/src/Geolocation/Geolocation.android.cs +++ b/src/Essentials/src/Geolocation/Geolocation.android.cs @@ -6,11 +6,12 @@ using Android.Locations; using Android.OS; using Android.Runtime; - +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; using AndroidLocation = Android.Locations.Location; using LocationPower = Android.Locations.Power; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GeolocationImplementation : IGeolocation { diff --git a/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs b/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs index 469545c657fe..8d51b9144afd 100644 --- a/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs +++ b/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs @@ -4,8 +4,9 @@ using System.Threading.Tasks; using CoreLocation; using Foundation; +using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GeolocationImplementation : IGeolocation { diff --git a/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs b/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs index f085726182f4..5f28dff636ed 100644 --- a/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { /// public partial class GeolocationImplementation : IGeolocation diff --git a/src/Essentials/src/Geolocation/Geolocation.shared.cs b/src/Essentials/src/Geolocation/Geolocation.shared.cs index be4a8ddf6427..b151b1dc2075 100644 --- a/src/Essentials/src/Geolocation/Geolocation.shared.cs +++ b/src/Essentials/src/Geolocation/Geolocation.shared.cs @@ -3,11 +3,11 @@ using System.Threading; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Sensors; +using Microsoft.Maui.Devices.Sensors.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface IGeolocation { @@ -55,7 +55,7 @@ public static void SetCurrent(IGeolocation? implementation) => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GeolocationImplementation : IGeolocation { diff --git a/src/Essentials/src/Geolocation/Geolocation.tizen.cs b/src/Essentials/src/Geolocation/Geolocation.tizen.cs index e31ca4ea7415..ef6f1fdc9faf 100644 --- a/src/Essentials/src/Geolocation/Geolocation.tizen.cs +++ b/src/Essentials/src/Geolocation/Geolocation.tizen.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Tizen.Location; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GeolocationImplementation : IGeolocation { diff --git a/src/Essentials/src/Geolocation/Geolocation.uwp.cs b/src/Essentials/src/Geolocation/Geolocation.uwp.cs index 3519c495a083..b8f0adfd8ef0 100644 --- a/src/Essentials/src/Geolocation/Geolocation.uwp.cs +++ b/src/Essentials/src/Geolocation/Geolocation.uwp.cs @@ -1,9 +1,10 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; using Windows.Devices.Geolocation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GeolocationImplementation : IGeolocation { diff --git a/src/Essentials/src/Geolocation/GeolocationRequest.ios.macos.cs b/src/Essentials/src/Geolocation/GeolocationRequest.ios.macos.cs index 554e4226036d..a6a96532e782 100644 --- a/src/Essentials/src/Geolocation/GeolocationRequest.ios.macos.cs +++ b/src/Essentials/src/Geolocation/GeolocationRequest.ios.macos.cs @@ -3,7 +3,7 @@ using System.Text; using CoreLocation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public partial class GeolocationRequest { diff --git a/src/Essentials/src/Geolocation/GeolocationRequest.shared.cs b/src/Essentials/src/Geolocation/GeolocationRequest.shared.cs index 263a3c2a8cd2..c474700ad9b2 100644 --- a/src/Essentials/src/Geolocation/GeolocationRequest.shared.cs +++ b/src/Essentials/src/Geolocation/GeolocationRequest.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public enum GeolocationAccuracy diff --git a/src/Essentials/src/Geolocation/GeolocationRequest.uwp.cs b/src/Essentials/src/Geolocation/GeolocationRequest.uwp.cs index 42d30e739345..f4670c35d0b2 100644 --- a/src/Essentials/src/Geolocation/GeolocationRequest.uwp.cs +++ b/src/Essentials/src/Geolocation/GeolocationRequest.uwp.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public partial class GeolocationRequest { diff --git a/src/Essentials/src/Gyroscope/Gyroscope.android.cs b/src/Essentials/src/Gyroscope/Gyroscope.android.cs index 08c072b96e8a..5d53c292ebac 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.android.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.android.cs @@ -1,8 +1,9 @@ using System; using Android.Hardware; using Android.Runtime; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GyroscopeImplementation : IGyroscope { diff --git a/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs b/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs index 0f69f613379e..4e7614339254 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs @@ -1,7 +1,8 @@ using CoreMotion; using Foundation; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GyroscopeImplementation : IGyroscope { diff --git a/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs b/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs index 87b2efacc924..b52bbadcb062 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { /// public partial class GyroscopeImplementation : IGyroscope diff --git a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs index 69d5214aaa74..1a42ef1516a8 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs @@ -1,10 +1,11 @@ using System; using System.Numerics; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Sensors; +using Microsoft.Maui.Devices.Sensors.Implementations; +using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface IGyroscope { @@ -116,7 +117,7 @@ public override string ToString() => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GyroscopeImplementation : IGyroscope { diff --git a/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs b/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs index 14622f8ee2c5..a8ee5d8240a5 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs @@ -1,7 +1,7 @@ using Tizen.Sensor; using TizenGyroscope = Tizen.Sensor.Gyroscope; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GyroscopeImplementation : IGyroscope { diff --git a/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs b/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs index ebefe18143a6..cb4d23eb7cd8 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs @@ -1,7 +1,7 @@ using Windows.Devices.Sensors; using WindowsGyro = Windows.Devices.Sensors.Gyrometer; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class GyroscopeImplementation : IGyroscope { diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs index 5afa3db3f8a9..c61ced8ad7e6 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs @@ -2,8 +2,10 @@ using System.Diagnostics; using System.Threading.Tasks; using Android.Views; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class HapticFeedbackImplementation : IHapticFeedback { diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs index 04c00b74f133..4570b0b638a6 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs @@ -3,7 +3,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class HapticFeedbackImplementation : IHapticFeedback { diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs index 79402dd10ea3..03f7c14ce865 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using AppKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class HapticFeedbackImplementation : IHapticFeedback { diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs index b2d0129c5884..ba8b22f0afb6 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class HapticFeedbackImplementation : IHapticFeedback /// diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs index ae3ab407f35e..7edbfdacd4d8 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs @@ -1,9 +1,9 @@ using System; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Devices.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { public interface IHapticFeedback { diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs index eb7442b5eb90..de1fcdab9440 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using Tizen.System; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class HapticFeedbackImplementation : IHapticFeedback { diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs index a21973d3024d..4dc14f593ea1 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs @@ -4,7 +4,7 @@ using Windows.Devices.Haptics; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class HapticFeedbackImplementation : IHapticFeedback { diff --git a/src/Essentials/src/HapticFeedback/HapticFeedbackType.shared.cs b/src/Essentials/src/HapticFeedback/HapticFeedbackType.shared.cs index d5654b4b6647..5fcc65e588ba 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedbackType.shared.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedbackType.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public enum HapticFeedbackType diff --git a/src/Essentials/src/Launcher/Launcher.android.cs b/src/Essentials/src/Launcher/Launcher.android.cs index fd9fed408f12..26aec77a609b 100644 --- a/src/Essentials/src/Launcher/Launcher.android.cs +++ b/src/Essentials/src/Launcher/Launcher.android.cs @@ -3,10 +3,11 @@ using Android.App; using Android.Content; using Android.Content.PM; +using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; using Uri = System.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class LauncherImplementation { diff --git a/src/Essentials/src/Launcher/Launcher.ios.tvos.cs b/src/Essentials/src/Launcher/Launcher.ios.tvos.cs index f71d9dfe51ce..4c5e06ea24fa 100644 --- a/src/Essentials/src/Launcher/Launcher.ios.tvos.cs +++ b/src/Essentials/src/Launcher/Launcher.ios.tvos.cs @@ -2,12 +2,14 @@ using System.Threading.Tasks; using CoreGraphics; using Foundation; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Essentials; using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics.Platform; using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class LauncherImplementation { diff --git a/src/Essentials/src/Launcher/Launcher.macos.cs b/src/Essentials/src/Launcher/Launcher.macos.cs index 182b3dca13e0..ee953457bb2f 100644 --- a/src/Essentials/src/Launcher/Launcher.macos.cs +++ b/src/Essentials/src/Launcher/Launcher.macos.cs @@ -4,7 +4,7 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class LauncherImplementation { diff --git a/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs b/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs index 29b3e1ca3849..db96003003ec 100644 --- a/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs +++ b/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { /// public partial class LauncherImplementation diff --git a/src/Essentials/src/Launcher/Launcher.shared.cs b/src/Essentials/src/Launcher/Launcher.shared.cs index c2d81a85ef10..b9d67dab1b5c 100644 --- a/src/Essentials/src/Launcher/Launcher.shared.cs +++ b/src/Essentials/src/Launcher/Launcher.shared.cs @@ -2,8 +2,9 @@ using System.ComponentModel; using System.Threading.Tasks; using Microsoft.Maui.Graphics; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public interface ILauncher { @@ -99,7 +100,7 @@ public OpenFileRequest(string title, FileBase file) } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class LauncherImplementation : ILauncher { diff --git a/src/Essentials/src/Launcher/Launcher.tizen.cs b/src/Essentials/src/Launcher/Launcher.tizen.cs index 160029826bf6..677436018349 100644 --- a/src/Essentials/src/Launcher/Launcher.tizen.cs +++ b/src/Essentials/src/Launcher/Launcher.tizen.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class LauncherImplementation { diff --git a/src/Essentials/src/Launcher/Launcher.uwp.cs b/src/Essentials/src/Launcher/Launcher.uwp.cs index a42e1386fba4..b99acfea751d 100644 --- a/src/Essentials/src/Launcher/Launcher.uwp.cs +++ b/src/Essentials/src/Launcher/Launcher.uwp.cs @@ -5,7 +5,7 @@ using Windows.System; using WinLauncher = Windows.System.Launcher; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public partial class LauncherImplementation { diff --git a/src/Essentials/src/Magnetometer/Magnetometer.android.cs b/src/Essentials/src/Magnetometer/Magnetometer.android.cs index 2ce7eefdc0b0..9dc21beaee28 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.android.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.android.cs @@ -1,8 +1,9 @@ using System; using Android.Hardware; using Android.Runtime; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class MagnetometerImplementation : IMagnetometer { diff --git a/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs b/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs index e2d02e7b4f95..0c50dc5dc390 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs @@ -1,7 +1,8 @@ using CoreMotion; using Foundation; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class MagnetometerImplementation : IMagnetometer { diff --git a/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs b/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs index c667c5df5553..6e3766adbfd9 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { /// public partial class MagnetometerImplementation diff --git a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs index c85d25b848e0..e0c84a7326cc 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs @@ -1,10 +1,11 @@ using System; using System.Numerics; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Sensors; +using Microsoft.Maui.Devices.Sensors.Implementations; +using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface IMagnetometer { @@ -116,7 +117,7 @@ public override string ToString() => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class MagnetometerImplementation : IMagnetometer { diff --git a/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs b/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs index be58f6a9673e..6490272bdc26 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs @@ -1,7 +1,7 @@ using Tizen.Sensor; using TizenMagnetometer = Tizen.Sensor.Magnetometer; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class MagnetometerImplementation : IMagnetometer { diff --git a/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs b/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs index aec26a744c0e..c2c569410bc1 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs @@ -2,7 +2,7 @@ using Windows.Devices.Sensors; using WindowsMagnetometer = Windows.Devices.Sensors.Magnetometer; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class MagnetometerImplementation : IMagnetometer { diff --git a/src/Essentials/src/MainThread/MainThread.android.cs b/src/Essentials/src/MainThread/MainThread.android.cs index 02fda402f142..89eb32c12971 100644 --- a/src/Essentials/src/MainThread/MainThread.android.cs +++ b/src/Essentials/src/MainThread/MainThread.android.cs @@ -1,7 +1,7 @@ using System; using Android.OS; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs b/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs index 831ea5568d9c..0f68e146703a 100644 --- a/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs @@ -1,7 +1,7 @@ using System; using Foundation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThread.netstandard.cs b/src/Essentials/src/MainThread/MainThread.netstandard.cs index 7dc88ea70cbc..ca59c050df85 100644 --- a/src/Essentials/src/MainThread/MainThread.netstandard.cs +++ b/src/Essentials/src/MainThread/MainThread.netstandard.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public static partial class MainThread diff --git a/src/Essentials/src/MainThread/MainThread.shared.cs b/src/Essentials/src/MainThread/MainThread.shared.cs index c4ab286a54cf..1f80e010689b 100644 --- a/src/Essentials/src/MainThread/MainThread.shared.cs +++ b/src/Essentials/src/MainThread/MainThread.shared.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public static partial class MainThread diff --git a/src/Essentials/src/MainThread/MainThread.tizen.cs b/src/Essentials/src/MainThread/MainThread.tizen.cs index 7ac48aaaced8..99eb7576daf1 100644 --- a/src/Essentials/src/MainThread/MainThread.tizen.cs +++ b/src/Essentials/src/MainThread/MainThread.tizen.cs @@ -1,7 +1,7 @@ using System; using ElmSharp; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThread.uwp.cs b/src/Essentials/src/MainThread/MainThread.uwp.cs index a2b3d0a7b92d..60258c4b2e39 100644 --- a/src/Essentials/src/MainThread/MainThread.uwp.cs +++ b/src/Essentials/src/MainThread/MainThread.uwp.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Microsoft.Maui.Essentials; #if WINDOWS_UWP using Windows.ApplicationModel.Core; @@ -8,7 +9,7 @@ using Microsoft.UI.Dispatching; #endif -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs b/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs index 7f3cde057d34..86b81476f8df 100644 --- a/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs +++ b/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Windows.Foundation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { internal static partial class MainThreadExtensions { diff --git a/src/Essentials/src/Map/Map.android.cs b/src/Essentials/src/Map/Map.android.cs index 5848a7fb9eb0..2834966116c1 100644 --- a/src/Essentials/src/Map/Map.android.cs +++ b/src/Essentials/src/Map/Map.android.cs @@ -1,9 +1,11 @@ using System.Globalization; using System.Threading.Tasks; using Android.Content; +using Microsoft.Maui.Devices.Sensors; +using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class MapImplementation : IMap { diff --git a/src/Essentials/src/Map/Map.ios.watchos.macos.cs b/src/Essentials/src/Map/Map.ios.watchos.macos.cs index 99d00e840404..97c6872f80ac 100644 --- a/src/Essentials/src/Map/Map.ios.watchos.macos.cs +++ b/src/Essentials/src/Map/Map.ios.watchos.macos.cs @@ -5,8 +5,9 @@ using CoreLocation; using Foundation; using MapKit; +using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class MapImplementation : IMap { diff --git a/src/Essentials/src/Map/Map.netstandard.tvos.cs b/src/Essentials/src/Map/Map.netstandard.tvos.cs index f784da869e58..bbc72436e90f 100644 --- a/src/Essentials/src/Map/Map.netstandard.tvos.cs +++ b/src/Essentials/src/Map/Map.netstandard.tvos.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; +using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { /// public class MapImplementation : IMap diff --git a/src/Essentials/src/Map/Map.shared.cs b/src/Essentials/src/Map/Map.shared.cs index 9109853076c7..12c5ab064695 100644 --- a/src/Essentials/src/Map/Map.shared.cs +++ b/src/Essentials/src/Map/Map.shared.cs @@ -2,9 +2,10 @@ using System; using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Sensors; +using Microsoft.Maui.ApplicationModel.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public interface IMap { diff --git a/src/Essentials/src/Map/Map.tizen.cs b/src/Essentials/src/Map/Map.tizen.cs index 506aec525f3d..8aa5f76df68c 100644 --- a/src/Essentials/src/Map/Map.tizen.cs +++ b/src/Essentials/src/Map/Map.tizen.cs @@ -1,8 +1,9 @@ using System.Globalization; using System.Threading.Tasks; using Tizen.Applications; +using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Map { diff --git a/src/Essentials/src/Map/Map.uwp.cs b/src/Essentials/src/Map/Map.uwp.cs index d0cf40fc94d7..c980bbc50dce 100644 --- a/src/Essentials/src/Map/Map.uwp.cs +++ b/src/Essentials/src/Map/Map.uwp.cs @@ -1,8 +1,9 @@ using System; using System.Globalization; using System.Threading.Tasks; +using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class MapImplementation:IMap { diff --git a/src/Essentials/src/Map/MapLaunchOptions.shared.cs b/src/Essentials/src/Map/MapLaunchOptions.shared.cs index 2c4d2375dd7d..c45c163ac598 100644 --- a/src/Essentials/src/Map/MapLaunchOptions.shared.cs +++ b/src/Essentials/src/Map/MapLaunchOptions.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public class MapLaunchOptions diff --git a/src/Essentials/src/Map/NavigationMode.shared.cs b/src/Essentials/src/Map/NavigationMode.shared.cs index a65759eaff2e..4c7b7621e60d 100644 --- a/src/Essentials/src/Map/NavigationMode.shared.cs +++ b/src/Essentials/src/Map/NavigationMode.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public enum NavigationMode diff --git a/src/Essentials/src/MediaPicker/MediaPicker.android.cs b/src/Essentials/src/MediaPicker/MediaPicker.android.cs index 1ce438bff161..b81da98b739c 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.android.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.android.cs @@ -3,9 +3,12 @@ using Android.Content; using Android.Content.PM; using Android.Provider; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class MediaPickerImplementation : IMediaPicker { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs index 03f8f40eb86e..1c2630e212a2 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs @@ -2,12 +2,16 @@ using System.Linq; using System.Threading.Tasks; using Foundation; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; using MobileCoreServices; using ObjCRuntime; using Photos; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class MediaPickerImplementation : IMediaPicker { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.macos.cs b/src/Essentials/src/MediaPicker/MediaPicker.macos.cs index 31b05fe77707..1e0e0d472a9d 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.macos.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.macos.cs @@ -3,7 +3,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class MediaPickerImplementation : IMediaPicker { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs b/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs index 963c95c9e8c1..3f60715366f1 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs @@ -1,8 +1,9 @@ using System; using System.IO; using System.Threading.Tasks; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { /// public partial class MediaPickerImplementation : IMediaPicker diff --git a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs index e6e032e5cc33..892be3ecd189 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs @@ -2,10 +2,11 @@ using System.ComponentModel; using System.IO; using System.Threading.Tasks; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Media; +using Microsoft.Maui.Media.Implementations; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { public interface IMediaPicker { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs b/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs index 6693e34255ab..a5f9ca337ea1 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class MediaPickerImplementation : IMediaPicker { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs b/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs index 518cd76569de..10c1d1fdddc1 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs @@ -1,10 +1,12 @@ using System; using System.Linq; using System.Threading.Tasks; +using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; using Windows.Media.Capture; using Windows.Storage.Pickers; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class MediaPickerImplementation : IMediaPicker { diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs index 314a3310cb33..2dd7127c908f 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs @@ -1,8 +1,9 @@ using System; using Android.Hardware; using Android.Runtime; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class OrientationSensorImplementation : IOrientationSensor { diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs index cd5b4bce8448..c630c0f1c243 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs @@ -2,8 +2,9 @@ using System.Numerics; using CoreMotion; using Foundation; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class OrientationSensorImplementation : IOrientationSensor { diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs index 95fd5d01a390..87c1ec56dc99 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { /// public partial class OrientationSensorImplementation : IOrientationSensor diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs index c55fad8d5a3b..235d581f3bd8 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs @@ -1,11 +1,11 @@ using System; using System.Numerics; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices.Sensors; +using Microsoft.Maui.Devices.Sensors.Implementations; +using Microsoft.Maui.ApplicationModel; - -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public interface IOrientationSensor { @@ -117,7 +117,7 @@ public override string ToString() => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class OrientationSensorImplementation : IOrientationSensor { diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs index 4f13ecdbdbf6..d215f7722b85 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs @@ -1,7 +1,7 @@ using Tizen.Sensor; using TizenRotationVectorSensor = Tizen.Sensor.RotationVectorSensor; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class OrientationSensorImplementation : IOrientationSensor { diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs index 63065c6953fa..ce542f087964 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs @@ -1,7 +1,7 @@ using Windows.Devices.Sensors; using WindowsOrientationSensor = Windows.Devices.Sensors.OrientationSensor; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Sensors.Implementations { public partial class OrientationSensorImplementation : IOrientationSensor { diff --git a/src/Essentials/src/Permissions/Permissions.android.cs b/src/Essentials/src/Permissions/Permissions.android.cs index 1e2546e7f7a6..7d3b5702d274 100644 --- a/src/Essentials/src/Permissions/Permissions.android.cs +++ b/src/Essentials/src/Permissions/Permissions.android.cs @@ -7,8 +7,9 @@ using Android.OS; using AndroidX.Core.App; using AndroidX.Core.Content; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/Permissions/Permissions.ios.cs b/src/Essentials/src/Permissions/Permissions.ios.cs index 8646fd7745e2..21fcb4ecc9b9 100644 --- a/src/Essentials/src/Permissions/Permissions.ios.cs +++ b/src/Essentials/src/Permissions/Permissions.ios.cs @@ -7,7 +7,7 @@ using MediaPlayer; using Speech; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs b/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs index 710bac08067a..f06ee85523bf 100644 --- a/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs +++ b/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs @@ -2,9 +2,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; +using Microsoft.Maui.Essentials; using Photos; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/Permissions/Permissions.ios.tvos.watchos.cs b/src/Essentials/src/Permissions/Permissions.ios.tvos.watchos.cs index eaf48fd753b9..6a815686cddd 100644 --- a/src/Essentials/src/Permissions/Permissions.ios.tvos.watchos.cs +++ b/src/Essentials/src/Permissions/Permissions.ios.tvos.watchos.cs @@ -4,8 +4,9 @@ using System.Threading.Tasks; using CoreLocation; using Foundation; +using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/Permissions/Permissions.ios.watchos.cs b/src/Essentials/src/Permissions/Permissions.ios.watchos.cs index ab122b6f9a5a..4d244370634a 100644 --- a/src/Essentials/src/Permissions/Permissions.ios.watchos.cs +++ b/src/Essentials/src/Permissions/Permissions.ios.watchos.cs @@ -6,7 +6,7 @@ using EventKit; using Foundation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/Permissions/Permissions.macos.cs b/src/Essentials/src/Permissions/Permissions.macos.cs index 73517b0b7f90..50319daaf129 100644 --- a/src/Essentials/src/Permissions/Permissions.macos.cs +++ b/src/Essentials/src/Permissions/Permissions.macos.cs @@ -4,7 +4,7 @@ using CoreLocation; using Foundation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/Permissions/Permissions.netstandard.cs b/src/Essentials/src/Permissions/Permissions.netstandard.cs index dbcca02f519a..396442164b07 100644 --- a/src/Essentials/src/Permissions/Permissions.netstandard.cs +++ b/src/Essentials/src/Permissions/Permissions.netstandard.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public static partial class Permissions diff --git a/src/Essentials/src/Permissions/Permissions.shared.cs b/src/Essentials/src/Permissions/Permissions.shared.cs index 13af1d50ad4b..0a99941cb025 100644 --- a/src/Essentials/src/Permissions/Permissions.shared.cs +++ b/src/Essentials/src/Permissions/Permissions.shared.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public static partial class Permissions diff --git a/src/Essentials/src/Permissions/Permissions.shared.enums.cs b/src/Essentials/src/Permissions/Permissions.shared.enums.cs index 401e1f666cc6..e5a62acc0336 100644 --- a/src/Essentials/src/Permissions/Permissions.shared.enums.cs +++ b/src/Essentials/src/Permissions/Permissions.shared.enums.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public enum PermissionStatus diff --git a/src/Essentials/src/Permissions/Permissions.tizen.cs b/src/Essentials/src/Permissions/Permissions.tizen.cs index ef53a31f7ff0..9fb9308667ee 100644 --- a/src/Essentials/src/Permissions/Permissions.tizen.cs +++ b/src/Essentials/src/Permissions/Permissions.tizen.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Tizen.Security; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/Permissions/Permissions.uwp.cs b/src/Essentials/src/Permissions/Permissions.uwp.cs index a95e3db3d227..be8a570795bd 100644 --- a/src/Essentials/src/Permissions/Permissions.uwp.cs +++ b/src/Essentials/src/Permissions/Permissions.uwp.cs @@ -6,12 +6,13 @@ using System.Xml; using System.Xml.Linq; using System.Xml.XPath; +using Microsoft.Maui.Essentials; using Windows.ApplicationModel; using Windows.ApplicationModel.Contacts; using Windows.Devices.Enumeration; using Windows.Devices.Geolocation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public static partial class Permissions { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs index 64c28a224025..c2c27ee46c88 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs @@ -5,9 +5,10 @@ using Android.Telephony; using Java.Net; using Java.Util; +using Microsoft.Maui.Essentials; using Uri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class PhoneDialerImplementation : IPhoneDialer { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs index 297115f0bf2c..268a90214a3d 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs @@ -3,7 +3,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class PhoneDialerImplementation : IPhoneDialer { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs index 65126629458b..e826404058ad 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs @@ -1,7 +1,7 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class PhoneDialerImplementation : IPhoneDialer { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs index ad617707c871..61b8503c4352 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class PhoneDialerImplementation : IPhoneDialer { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs index 1c219196c48f..03826f439fc8 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs @@ -1,10 +1,10 @@ #nullable enable using System; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.Communication; +using Microsoft.Maui.ApplicationModel.Communication.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { public interface IPhoneDialer { @@ -34,7 +34,7 @@ public static void SetCurrent(IPhoneDialer? implementation) => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { partial class PhoneDialerImplementation { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs index bd2175993939..037008d71627 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs @@ -1,6 +1,6 @@ using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class PhoneDialerImplementation : IPhoneDialer { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs index cdfaeeaaf745..1e429c78bb7f 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs @@ -1,7 +1,7 @@ using Windows.ApplicationModel.Calls; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public partial class PhoneDialerImplementation : IPhoneDialer { diff --git a/src/Essentials/src/Platform/Platform.android.cs b/src/Essentials/src/Platform/Platform.android.cs index 2a799188c307..6a4158f6e5b1 100644 --- a/src/Essentials/src/Platform/Platform.android.cs +++ b/src/Essentials/src/Platform/Platform.android.cs @@ -12,9 +12,11 @@ using Android.Net.Wifi; using Android.OS; using Android.Views; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.ApplicationModel.Implementations; +using Microsoft.Maui.Storage; using AndroidIntent = Android.Content.Intent; using AndroidUri = Android.Net.Uri; -using Microsoft.Maui.Essentials.Implementations; namespace Microsoft.Maui.Essentials { @@ -252,7 +254,7 @@ internal static void SetLocale(Java.Util.Locale locale) else #endif #pragma warning disable CS0618 // Type or member is obsolete - config.Locale = locale; + config.Locale = locale; #pragma warning restore CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete diff --git a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs index 57ec02785f44..3ef5fee95142 100644 --- a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs +++ b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs @@ -5,6 +5,9 @@ using Foundation; using ObjCRuntime; using UIKit; +using Microsoft.Maui.Authentication; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.ApplicationModel.Implementations; #if __IOS__ using CoreMotion; @@ -12,8 +15,6 @@ using CoreMotion; #endif -using Microsoft.Maui.Essentials.Implementations; - namespace Microsoft.Maui.Essentials { public static partial class Platform diff --git a/src/Essentials/src/Platform/Platform.uwp.cs b/src/Essentials/src/Platform/Platform.uwp.cs index 659f9514de21..60ac0634f2a7 100644 --- a/src/Essentials/src/Platform/Platform.uwp.cs +++ b/src/Essentials/src/Platform/Platform.uwp.cs @@ -5,6 +5,7 @@ using WindowActivationState = Windows.UI.Core.CoreWindowActivationState; #elif WINDOWS using System; +using Microsoft.Maui.ApplicationModel; using Microsoft.UI.Windowing; using Microsoft.UI.Xaml; #endif diff --git a/src/Essentials/src/Preferences/Preferences.android.cs b/src/Essentials/src/Preferences/Preferences.android.cs index cef8c2ede4b7..b9f84c2d4470 100644 --- a/src/Essentials/src/Preferences/Preferences.android.cs +++ b/src/Essentials/src/Preferences/Preferences.android.cs @@ -4,7 +4,7 @@ using Android.Content; using Android.Preferences; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public class PreferencesImplementation : IPreferences { diff --git a/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs b/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs index d7057cf73d12..3e936f32e7bf 100644 --- a/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs @@ -2,7 +2,7 @@ using System.Globalization; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public class PreferencesImplementation : IPreferences { diff --git a/src/Essentials/src/Preferences/Preferences.netstandard.cs b/src/Essentials/src/Preferences/Preferences.netstandard.cs index 5d17050b531b..2a76d5961f09 100644 --- a/src/Essentials/src/Preferences/Preferences.netstandard.cs +++ b/src/Essentials/src/Preferences/Preferences.netstandard.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { /// public class PreferencesImplementation : IPreferences diff --git a/src/Essentials/src/Preferences/Preferences.shared.cs b/src/Essentials/src/Preferences/Preferences.shared.cs index 8448d3816fdb..41e9bced9c2e 100644 --- a/src/Essentials/src/Preferences/Preferences.shared.cs +++ b/src/Essentials/src/Preferences/Preferences.shared.cs @@ -1,9 +1,10 @@ #nullable enable using System; using System.ComponentModel; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Storage.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public interface IPreferences { diff --git a/src/Essentials/src/Preferences/Preferences.tizen.cs b/src/Essentials/src/Preferences/Preferences.tizen.cs index 4f1cb238c093..419e15414d1f 100644 --- a/src/Essentials/src/Preferences/Preferences.tizen.cs +++ b/src/Essentials/src/Preferences/Preferences.tizen.cs @@ -1,7 +1,7 @@ using System.Linq; using Tizen.Applications; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public static partial class Preferences { diff --git a/src/Essentials/src/Preferences/Preferences.uwp.cs b/src/Essentials/src/Preferences/Preferences.uwp.cs index 8ee69314e3c0..fff9238c9f87 100644 --- a/src/Essentials/src/Preferences/Preferences.uwp.cs +++ b/src/Essentials/src/Preferences/Preferences.uwp.cs @@ -1,6 +1,6 @@ using Windows.Storage; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public class PreferencesImplementation:IPreferences { diff --git a/src/Essentials/src/Screenshot/Screenshot.android.cs b/src/Essentials/src/Screenshot/Screenshot.android.cs index 91c9b461168e..aa14a332518d 100644 --- a/src/Essentials/src/Screenshot/Screenshot.android.cs +++ b/src/Essentials/src/Screenshot/Screenshot.android.cs @@ -3,8 +3,9 @@ using System.Threading.Tasks; using Android.Graphics; using Android.Views; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { public static partial class Screenshot { @@ -100,7 +101,7 @@ public static Bitmap Render(this View view) } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/Screenshot/Screenshot.ios.cs b/src/Essentials/src/Screenshot/Screenshot.ios.cs index ca06b57eb732..dbb0cfe2afdd 100644 --- a/src/Essentials/src/Screenshot/Screenshot.ios.cs +++ b/src/Essentials/src/Screenshot/Screenshot.ios.cs @@ -11,7 +11,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { public static partial class Screenshot { @@ -224,7 +224,7 @@ static UIView FindSubview(UIView view, IEnumerator classNames) } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs index 281d84eb04eb..f05a910626da 100644 --- a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs +++ b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs @@ -1,7 +1,7 @@ using System.IO; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/Screenshot/Screenshot.shared.cs b/src/Essentials/src/Screenshot/Screenshot.shared.cs index 93f6a3e9fadd..911ee69a34c9 100644 --- a/src/Essentials/src/Screenshot/Screenshot.shared.cs +++ b/src/Essentials/src/Screenshot/Screenshot.shared.cs @@ -4,7 +4,7 @@ using System.IO; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { public interface IScreenshot { @@ -63,7 +63,7 @@ public enum ScreenshotFormat } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { internal partial class ScreenshotResult : IScreenshotResult { diff --git a/src/Essentials/src/Screenshot/Screenshot.tvos.cs b/src/Essentials/src/Screenshot/Screenshot.tvos.cs index e4b73d04d52a..181bd960d715 100644 --- a/src/Essentials/src/Screenshot/Screenshot.tvos.cs +++ b/src/Essentials/src/Screenshot/Screenshot.tvos.cs @@ -3,7 +3,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class ScreenshotImplementation : IScreenshot { @@ -18,7 +18,10 @@ public Task CaptureAsync() return Task.FromResult(result); } } +} +namespace Microsoft.Maui.Media +{ internal partial class ScreenshotResult { readonly UIImage uiImage; diff --git a/src/Essentials/src/Screenshot/Screenshot.uwp.cs b/src/Essentials/src/Screenshot/Screenshot.uwp.cs index 1774642ca5f6..cbe7c8a6ac33 100644 --- a/src/Essentials/src/Screenshot/Screenshot.uwp.cs +++ b/src/Essentials/src/Screenshot/Screenshot.uwp.cs @@ -12,7 +12,7 @@ using Windows.UI.Xaml.Media.Imaging; #endif -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { public static partial class Screenshot { @@ -62,7 +62,7 @@ public static async Task AsImageBytesAsync(this RenderTargetBitmap bitma } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/SecureStorage/SecureStorage.android.cs b/src/Essentials/src/SecureStorage/SecureStorage.android.cs index da1fcdaf7d4c..ccaebbf45cf1 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.android.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.android.cs @@ -4,7 +4,7 @@ using AndroidX.Security.Crypto; using Javax.Crypto; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class SecureStorageImplementation : ISecureStorage { diff --git a/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs b/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs index 262ca87ed4f3..bbba147c627d 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs @@ -5,7 +5,7 @@ using Foundation; using Security; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class SecureStorageImplementation : ISecureStorage, IPlatformSecureStorage { diff --git a/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs b/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs index e311e1d7cfcd..9eff1ed48367 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { /// public partial class SecureStorageImplementation : ISecureStorage diff --git a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs index 09b6509b79dc..f802576a6438 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs @@ -2,9 +2,9 @@ using System; using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Storage.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { public interface ISecureStorage { @@ -102,7 +102,7 @@ public static void SetCurrent(ISecureStorage? implementation) } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class SecureStorageImplementation { diff --git a/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs b/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs index c4cd9dd26749..0e5d784340f7 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Tizen.Security.SecureRepository; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class SecureStorageImplementation : ISecureStorage { diff --git a/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs b/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs index 57cc815f4bae..b7d8fe1d5fd4 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs @@ -5,7 +5,7 @@ using Windows.Security.Cryptography.DataProtection; using Windows.Storage; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Storage.Implementations { public partial class SecureStorageImplementation : ISecureStorage { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs index ad2f98db5b40..01be52b1356e 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs @@ -1,6 +1,6 @@ using Android.Views.Accessibility; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Accessibility.Implementations { public partial class SemanticScreenReaderImplementation : ISemanticScreenReader { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs index 42fdce28d45e..3386084a8032 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs @@ -2,7 +2,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Accessibility.Implementations { public partial class SemanticScreenReaderImplementation : ISemanticScreenReader { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs index 916a7c970f24..18235e915613 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Accessibility.Implementations { public partial class SemanticScreenReaderImplementation : ISemanticScreenReader { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs index c6f1fceab79b..d77b2e9ff4d9 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs @@ -1,9 +1,9 @@ #nullable enable using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Accessibility.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Accessibility { public interface ISemanticScreenReader { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs index dc8cbe84a6b6..78e26786a086 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs @@ -3,6 +3,7 @@ using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Media; #elif WINDOWS +using Microsoft.Maui.Essentials; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; @@ -12,7 +13,7 @@ -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Accessibility.Implementations { public partial class SemanticScreenReaderImplementation : ISemanticScreenReader { diff --git a/src/Essentials/src/Share/Share.android.cs b/src/Essentials/src/Share/Share.android.cs index 7440e472ace0..694056efd345 100644 --- a/src/Essentials/src/Share/Share.android.cs +++ b/src/Essentials/src/Share/Share.android.cs @@ -2,8 +2,10 @@ using System.Threading.Tasks; using Android.Content; using Android.OS; +using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public class ShareImplementation : IShare { diff --git a/src/Essentials/src/Share/Share.ios.cs b/src/Essentials/src/Share/Share.ios.cs index 07823709e292..6147c627be94 100644 --- a/src/Essentials/src/Share/Share.ios.cs +++ b/src/Essentials/src/Share/Share.ios.cs @@ -2,12 +2,13 @@ using System.Collections.Generic; using System.Threading.Tasks; using Foundation; +using Microsoft.Maui.Essentials; using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics.Platform; using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public class ShareImplementation : IShare { diff --git a/src/Essentials/src/Share/Share.macos.cs b/src/Essentials/src/Share/Share.macos.cs index 210f6591bd4f..e39a35738a12 100644 --- a/src/Essentials/src/Share/Share.macos.cs +++ b/src/Essentials/src/Share/Share.macos.cs @@ -4,7 +4,7 @@ using Foundation; using Microsoft.Maui.Graphics.Platform; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public class ShareImplementation : IShare { diff --git a/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs b/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs index 20813bcd6927..2193f2a9b9b7 100644 --- a/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { /// public class ShareImplementation : IShare diff --git a/src/Essentials/src/Share/Share.shared.cs b/src/Essentials/src/Share/Share.shared.cs index 13ba17b12f02..6672c5601ca0 100644 --- a/src/Essentials/src/Share/Share.shared.cs +++ b/src/Essentials/src/Share/Share.shared.cs @@ -3,10 +3,11 @@ using System.ComponentModel; using System.Linq; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.DataTransfer.Implementations; using Microsoft.Maui.Graphics; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.DataTransfer { public interface IShare { diff --git a/src/Essentials/src/Share/Share.tizen.cs b/src/Essentials/src/Share/Share.tizen.cs index 58697bf1eaff..37335159d06e 100644 --- a/src/Essentials/src/Share/Share.tizen.cs +++ b/src/Essentials/src/Share/Share.tizen.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public class ShareImplementation : IShare { diff --git a/src/Essentials/src/Share/Share.uwp.cs b/src/Essentials/src/Share/Share.uwp.cs index f378263072a1..265c82db7ce2 100644 --- a/src/Essentials/src/Share/Share.uwp.cs +++ b/src/Essentials/src/Share/Share.uwp.cs @@ -2,11 +2,12 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Microsoft.Maui.Essentials; using Windows.ApplicationModel.DataTransfer; using Windows.Storage; using WinRT; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations { public class ShareImplementation : IShare { diff --git a/src/Essentials/src/Sms/Sms.android.cs b/src/Essentials/src/Sms/Sms.android.cs index 21d366d50f61..e5be51d69407 100644 --- a/src/Essentials/src/Sms/Sms.android.cs +++ b/src/Essentials/src/Sms/Sms.android.cs @@ -4,10 +4,11 @@ using Android.Content; using Android.OS; using Android.Provider; - +using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public class SmsImplementation : ISms { diff --git a/src/Essentials/src/Sms/Sms.ios.cs b/src/Essentials/src/Sms/Sms.ios.cs index 7e50656425a9..97e2e8a23492 100644 --- a/src/Essentials/src/Sms/Sms.ios.cs +++ b/src/Essentials/src/Sms/Sms.ios.cs @@ -2,9 +2,10 @@ using System.Threading.Tasks; #if !(MACCATALYST || MACOS) using MessageUI; +using Microsoft.Maui.Essentials; #endif -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public class SmsImplementation : ISms { diff --git a/src/Essentials/src/Sms/Sms.macos.cs b/src/Essentials/src/Sms/Sms.macos.cs index feff1d63a824..95018298c545 100644 --- a/src/Essentials/src/Sms/Sms.macos.cs +++ b/src/Essentials/src/Sms/Sms.macos.cs @@ -4,7 +4,7 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { public static partial class Sms { diff --git a/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs b/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs index e2d98947c75e..d7b49aeffc60 100644 --- a/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { /// public class SmsImplementation : ISms diff --git a/src/Essentials/src/Sms/Sms.shared.cs b/src/Essentials/src/Sms/Sms.shared.cs index 0e7f77e3e6f8..c2c6ce4128ea 100644 --- a/src/Essentials/src/Sms/Sms.shared.cs +++ b/src/Essentials/src/Sms/Sms.shared.cs @@ -3,9 +3,9 @@ using System.ComponentModel; using System.Linq; using System.Threading.Tasks; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.ApplicationModel.Communication.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { public interface ISms { diff --git a/src/Essentials/src/Sms/Sms.tizen.cs b/src/Essentials/src/Sms/Sms.tizen.cs index 23f8385ae9f3..0aa8384f9d2c 100644 --- a/src/Essentials/src/Sms/Sms.tizen.cs +++ b/src/Essentials/src/Sms/Sms.tizen.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { public static partial class Sms { diff --git a/src/Essentials/src/Sms/Sms.uwp.cs b/src/Essentials/src/Sms/Sms.uwp.cs index 7efaa8be3be5..44f320082a56 100644 --- a/src/Essentials/src/Sms/Sms.uwp.cs +++ b/src/Essentials/src/Sms/Sms.uwp.cs @@ -3,7 +3,7 @@ using Windows.ApplicationModel.Chat; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication.Implementations { public class SmsImplementation:ISms { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs index 1d0efd86b51b..7694a900b7aa 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs @@ -6,11 +6,12 @@ using System.Threading.Tasks; using Android.OS; using Android.Speech.Tts; +using Microsoft.Maui.Essentials; using AndroidTextToSpeech = Android.Speech.Tts.TextToSpeech; using Debug = System.Diagnostics.Debug; using JavaLocale = Java.Util.Locale; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class TextToSpeechImplementation : ITextToSpeech { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs index 5b9324a08124..520811a08db0 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using AVFoundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class TextToSpeechImplementation : ITextToSpeech { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs index 1f6a9c696b8e..a0619ac8c710 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using AppKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class TextToSpeechImplementation : ITextToSpeech { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs index ef69a9547ee5..31416f584eb3 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { /// public partial class TextToSpeechImplementation : ITextToSpeech diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs index daafe983c153..55793f613258 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs @@ -3,10 +3,10 @@ using System.Threading; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Media; +using Microsoft.Maui.Media.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { public interface ITextToSpeech { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs index a119941ce518..be2ca286994c 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Tizen.Uix.Tts; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class TextToSpeechImplementation : ITextToSpeech { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs index 96f167fa8890..ea01b14d0cdd 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs @@ -10,7 +10,7 @@ using Windows.Media.Playback; using Windows.Media.SpeechSynthesis; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Media.Implementations { public partial class TextToSpeechImplementation : ITextToSpeech { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs index 28b337f9d955..61887beccce4 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Diagnostics; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { internal static partial class TextToSpeechExtensions { diff --git a/src/Essentials/src/Types/Contact.shared.cs b/src/Essentials/src/Types/Contact.shared.cs index 51b5b78551e2..5bdb3e193ecf 100644 --- a/src/Essentials/src/Types/Contact.shared.cs +++ b/src/Essentials/src/Types/Contact.shared.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { /// public class Contact diff --git a/src/Essentials/src/Types/DeviceIdiom.shared.cs b/src/Essentials/src/Types/DeviceIdiom.shared.cs index 9f381f11386d..5731f0e9f99b 100644 --- a/src/Essentials/src/Types/DeviceIdiom.shared.cs +++ b/src/Essentials/src/Types/DeviceIdiom.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public readonly struct DeviceIdiom : IEquatable diff --git a/src/Essentials/src/Types/DevicePlatform.shared.cs b/src/Essentials/src/Types/DevicePlatform.shared.cs index a254c24168a5..dd4e99665f64 100644 --- a/src/Essentials/src/Types/DevicePlatform.shared.cs +++ b/src/Essentials/src/Types/DevicePlatform.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public readonly struct DevicePlatform : IEquatable diff --git a/src/Essentials/src/Types/DisplayInfo.shared.cs b/src/Essentials/src/Types/DisplayInfo.shared.cs index 9697929cede3..4bc96cee41b6 100644 --- a/src/Essentials/src/Types/DisplayInfo.shared.cs +++ b/src/Essentials/src/Types/DisplayInfo.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// [Preserve(AllMembers = true)] diff --git a/src/Essentials/src/Types/DisplayOrientation.shared.cs b/src/Essentials/src/Types/DisplayOrientation.shared.cs index 9bb96dbd6315..1c7f899aa641 100644 --- a/src/Essentials/src/Types/DisplayOrientation.shared.cs +++ b/src/Essentials/src/Types/DisplayOrientation.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public enum DisplayOrientation diff --git a/src/Essentials/src/Types/DisplayRotation.shared.cs b/src/Essentials/src/Types/DisplayRotation.shared.cs index fc9228fdc522..3b0ab35e9193 100644 --- a/src/Essentials/src/Types/DisplayRotation.shared.cs +++ b/src/Essentials/src/Types/DisplayRotation.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public enum DisplayRotation diff --git a/src/Essentials/src/Types/ExperimentalFeatures.shared.cs b/src/Essentials/src/Types/ExperimentalFeatures.shared.cs deleted file mode 100644 index 74a191903c50..000000000000 --- a/src/Essentials/src/Types/ExperimentalFeatures.shared.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Runtime.CompilerServices; - -namespace Microsoft.Maui.Essentials -{ - /// - public static class ExperimentalFeatures - { - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("ExperimentalFeatures.ShareFileRequest is obsolete as of version 1.3.0 and no longer required to use the feature.")] - public const string ShareFileRequest = "ShareFileRequest_Experimental"; - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("ExperimentalFeatures.OpenFileRequest is obsolete as of version 1.3.0 and no longer required to use the feature.")] - public const string OpenFileRequest = "OpenFileRequest_Experimental"; - - /// - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("ExperimentalFeatures.EmailAttachments is obsolete as of version 1.3.0 and no longer required to use the feature.")] - public const string EmailAttachments = "EmailAttachments_Experimental"; - /// - public const string MediaPicker = "MediaPicker_Experimental"; - - static HashSet enabledFeatures; - - /// - public static void Enable(params string[] featureNames) - { - if (enabledFeatures == null) - enabledFeatures = new HashSet(); - - foreach (var featureName in featureNames) - { - if (!enabledFeatures.Contains(featureName)) - enabledFeatures.Add(featureName); - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - internal static void VerifyEnabled( - string featureName, - [CallerMemberName] string memberName = "") - { - if (enabledFeatures == null || !enabledFeatures.Contains(featureName)) - { - var call = string.IsNullOrEmpty(memberName) ? string.Empty : $"('{memberName}'), which is "; - - var errorMessage = $"The class, property, or method you are attempting to use {call}an experimental feature;" - + " to use it, you must opt-in by calling " - + $"ExperimentalFeatures.Enable(\"{featureName}\") before using this feature."; - - throw new InvalidOperationException(errorMessage); - } - } - } -} diff --git a/src/Essentials/src/Types/FileProvider.android.cs b/src/Essentials/src/Types/FileProvider.android.cs index 08e162f9f941..5df623366533 100644 --- a/src/Essentials/src/Types/FileProvider.android.cs +++ b/src/Essentials/src/Types/FileProvider.android.cs @@ -3,11 +3,12 @@ using Android.App; using Android.Content; using Android.OS; +using Microsoft.Maui.Essentials; using AndroidEnvironment = Android.OS.Environment; using AndroidUri = Android.Net.Uri; using ContentFileProvider = AndroidX.Core.Content.FileProvider; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { [ContentProvider( new[] { "${applicationId}.fileProvider" }, diff --git a/src/Essentials/src/Types/Location.shared.cs b/src/Essentials/src/Types/Location.shared.cs index f0357d4990b3..cbc5eb0a74db 100644 --- a/src/Essentials/src/Types/Location.shared.cs +++ b/src/Essentials/src/Types/Location.shared.cs @@ -1,8 +1,8 @@ using System; - +using Microsoft.Maui.Essentials; using static System.Math; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public enum DistanceUnits diff --git a/src/Essentials/src/Types/LocationExtensions.android.cs b/src/Essentials/src/Types/LocationExtensions.android.cs index a9786b71fe67..39270357308c 100644 --- a/src/Essentials/src/Types/LocationExtensions.android.cs +++ b/src/Essentials/src/Types/LocationExtensions.android.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; - +using Microsoft.Maui.Essentials; using AndroidAddress = Android.Locations.Address; using AndroidLocation = Android.Locations.Location; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public static partial class LocationExtensions { diff --git a/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs b/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs index 3dc521e963f4..a6fb5be8f3e8 100644 --- a/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs @@ -4,7 +4,7 @@ using CoreLocation; using Foundation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public static partial class LocationExtensions { diff --git a/src/Essentials/src/Types/LocationExtensions.shared.cs b/src/Essentials/src/Types/LocationExtensions.shared.cs index becd0e737073..a776d645092f 100644 --- a/src/Essentials/src/Types/LocationExtensions.shared.cs +++ b/src/Essentials/src/Types/LocationExtensions.shared.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static partial class LocationExtensions diff --git a/src/Essentials/src/Types/LocationExtensions.uwp.cs b/src/Essentials/src/Types/LocationExtensions.uwp.cs index 7c752a109f0d..013632bef1a5 100644 --- a/src/Essentials/src/Types/LocationExtensions.uwp.cs +++ b/src/Essentials/src/Types/LocationExtensions.uwp.cs @@ -5,7 +5,7 @@ using Windows.Services.Maps; using WindowsARS = Windows.Devices.Geolocation.AltitudeReferenceSystem; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public static partial class LocationExtensions { diff --git a/src/Essentials/src/Types/Placemark.shared.cs b/src/Essentials/src/Types/Placemark.shared.cs index 5bd96e7edbcf..1d178d9a3b13 100644 --- a/src/Essentials/src/Types/Placemark.shared.cs +++ b/src/Essentials/src/Types/Placemark.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public class Placemark diff --git a/src/Essentials/src/Types/PlacemarkExtensions.android.cs b/src/Essentials/src/Types/PlacemarkExtensions.android.cs index 9fc7112b2bc6..a2334775d63f 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.android.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.android.cs @@ -3,7 +3,7 @@ using AndroidAddress = Android.Locations.Address; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public static partial class PlacemarkExtensions { diff --git a/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs b/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs index 76cf08b1d6ba..5aec17db2937 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs @@ -2,7 +2,7 @@ using System.Linq; using CoreLocation; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public static partial class PlacemarkExtensions { diff --git a/src/Essentials/src/Types/PlacemarkExtensions.shared.cs b/src/Essentials/src/Types/PlacemarkExtensions.shared.cs index ab89a8d15b03..148230e7ad7d 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.shared.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.shared.cs @@ -1,7 +1,8 @@ using System; using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static partial class PlacemarkExtensions diff --git a/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs b/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs index f48bd8b39a4b..b42132741ea4 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs @@ -2,7 +2,7 @@ using System.Linq; using Windows.Services.Maps; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { public static partial class LocationExtensions { diff --git a/src/Essentials/src/Types/SensorSpeed.android.cs b/src/Essentials/src/Types/SensorSpeed.android.cs index 58a66eb759c0..75776f59755c 100644 --- a/src/Essentials/src/Types/SensorSpeed.android.cs +++ b/src/Essentials/src/Types/SensorSpeed.android.cs @@ -1,6 +1,6 @@ using Android.Hardware; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { static class SensorSpeedExtensions { diff --git a/src/Essentials/src/Types/SensorSpeed.ios.tvos.watchos.cs b/src/Essentials/src/Types/SensorSpeed.ios.tvos.watchos.cs index 8305ba29b9b0..fce68ef36ad7 100644 --- a/src/Essentials/src/Types/SensorSpeed.ios.tvos.watchos.cs +++ b/src/Essentials/src/Types/SensorSpeed.ios.tvos.watchos.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { static class SensorSpeedExtensions { diff --git a/src/Essentials/src/Types/SensorSpeed.shared.cs b/src/Essentials/src/Types/SensorSpeed.shared.cs index a4589ba118da..9433398b2761 100644 --- a/src/Essentials/src/Types/SensorSpeed.shared.cs +++ b/src/Essentials/src/Types/SensorSpeed.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public enum SensorSpeed diff --git a/src/Essentials/src/Types/SensorSpeed.tizen.cs b/src/Essentials/src/Types/SensorSpeed.tizen.cs index eab71edfe997..6080e39027a3 100644 --- a/src/Essentials/src/Types/SensorSpeed.tizen.cs +++ b/src/Essentials/src/Types/SensorSpeed.tizen.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { static class SensorSpeedExtensions { diff --git a/src/Essentials/src/Types/SensorSpeed.uwp.cs b/src/Essentials/src/Types/SensorSpeed.uwp.cs index d8e8fedee18a..384c61c89703 100644 --- a/src/Essentials/src/Types/SensorSpeed.uwp.cs +++ b/src/Essentials/src/Types/SensorSpeed.uwp.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { static class SensorSpeedExtensions { diff --git a/src/Essentials/src/Types/Shared/Exceptions.shared.cs b/src/Essentials/src/Types/Shared/Exceptions.shared.cs index f3aa2a1d537c..2b9bc9a55927 100644 --- a/src/Essentials/src/Types/Shared/Exceptions.shared.cs +++ b/src/Essentials/src/Types/Shared/Exceptions.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui { static class ExceptionUtils { @@ -24,16 +24,6 @@ public NotImplementedInReferenceAssemblyException() } } - /// - public class PermissionException : UnauthorizedAccessException - { - /// - public PermissionException(string message) - : base(message) - { - } - } - /// public class FeatureNotSupportedException : NotSupportedException { @@ -76,3 +66,16 @@ public FeatureNotEnabledException(string message, Exception innerException) } } } + +namespace Microsoft.Maui.ApplicationModel +{ + /// + public class PermissionException : UnauthorizedAccessException + { + /// + public PermissionException(string message) + : base(message) + { + } + } +} diff --git a/src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs b/src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs index 88dce991bb12..2f7003eab5f7 100644 --- a/src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs +++ b/src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs @@ -1,7 +1,7 @@ using System; using System.ComponentModel; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui { [AttributeUsage(AttributeTargets.All)] [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Essentials/src/Types/Shared/Utils.shared.cs b/src/Essentials/src/Types/Shared/Utils.shared.cs index 377a3dbcae37..b1f80d008677 100644 --- a/src/Essentials/src/Types/Shared/Utils.shared.cs +++ b/src/Essentials/src/Types/Shared/Utils.shared.cs @@ -3,7 +3,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui { static class Utils { diff --git a/src/Essentials/src/Types/Shared/WebUtils.shared.cs b/src/Essentials/src/Types/Shared/WebUtils.shared.cs index b0f8eb9d0bde..a0faa0d648dc 100644 --- a/src/Essentials/src/Types/Shared/WebUtils.shared.cs +++ b/src/Essentials/src/Types/Shared/WebUtils.shared.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui { static class WebUtils { diff --git a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs index 6aff6b7f3478..7a0decc9bc4b 100644 --- a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs +++ b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs @@ -3,8 +3,9 @@ using System.ComponentModel; using System.Linq; using System.Text; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { public interface IVersionTracking { @@ -114,7 +115,7 @@ public static void SetCurrent(IVersionTracking? implementation) => } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.ApplicationModel.Implementations { public class VersionTrackingImplementation : IVersionTracking { diff --git a/src/Essentials/src/Vibration/Vibration.android.cs b/src/Essentials/src/Vibration/Vibration.android.cs index 91c44cab9c6e..597cbece9e72 100644 --- a/src/Essentials/src/Vibration/Vibration.android.cs +++ b/src/Essentials/src/Vibration/Vibration.android.cs @@ -2,9 +2,11 @@ #if __ANDROID_26__ using Android; using Android.OS; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Essentials; #endif -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class VibrationImplementation : IVibration { diff --git a/src/Essentials/src/Vibration/Vibration.ios.cs b/src/Essentials/src/Vibration/Vibration.ios.cs index 068e3185dcfd..4a401a33adee 100644 --- a/src/Essentials/src/Vibration/Vibration.ios.cs +++ b/src/Essentials/src/Vibration/Vibration.ios.cs @@ -1,7 +1,7 @@ using System; using AudioToolbox; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class VibrationImplementation : IVibration { diff --git a/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs b/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs index 6b7b89fa4761..bfff90e12c4c 100644 --- a/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs +++ b/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class VibrationImplementation : IVibration /// diff --git a/src/Essentials/src/Vibration/Vibration.shared.cs b/src/Essentials/src/Vibration/Vibration.shared.cs index c8d3878dc8af..afd34ed470e8 100644 --- a/src/Essentials/src/Vibration/Vibration.shared.cs +++ b/src/Essentials/src/Vibration/Vibration.shared.cs @@ -1,9 +1,9 @@ using System; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Devices; +using Microsoft.Maui.Devices.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { public interface IVibration { diff --git a/src/Essentials/src/Vibration/Vibration.tizen.cs b/src/Essentials/src/Vibration/Vibration.tizen.cs index e0e463c35a27..1e48e65a0f5d 100644 --- a/src/Essentials/src/Vibration/Vibration.tizen.cs +++ b/src/Essentials/src/Vibration/Vibration.tizen.cs @@ -2,7 +2,7 @@ using System.Linq; using Tizen.System; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class VibrationImplementation : IVibration { diff --git a/src/Essentials/src/Vibration/Vibration.uwp.cs b/src/Essentials/src/Vibration/Vibration.uwp.cs index 7c0ed76f20b8..73b82d545efa 100644 --- a/src/Essentials/src/Vibration/Vibration.uwp.cs +++ b/src/Essentials/src/Vibration/Vibration.uwp.cs @@ -2,7 +2,7 @@ using Windows.Devices.Haptics; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Devices.Implementations { public partial class VibrationImplementation : IVibration { diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs index 5e14053ad3f9..de096332342c 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs @@ -4,10 +4,11 @@ using System.Threading.Tasks; using AuthenticationServices; using Foundation; +using Microsoft.Maui.Essentials; using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { public partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator { diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs index 2054de02003e..9429d3fb41f9 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { /// public partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs index 0c5cc9a8b248..8272a127b133 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs @@ -3,10 +3,10 @@ using System.Text; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Authentication; +using Microsoft.Maui.Authentication.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Authentication { public interface IAppleSignInAuthenticator { diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs index 5b8005a477a0..ae5d370a823a 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs @@ -2,8 +2,9 @@ using System.Threading.Tasks; using Android.Content; using AndroidX.Browser.CustomTabs; +using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { public partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback { diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs index db0ee488f42a..03554945d45a 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs @@ -11,9 +11,11 @@ using ObjCRuntime; using UIKit; using WebKit; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Authentication.Implementations; +using Microsoft.Maui.Essentials; +using Microsoft.Maui.ApplicationModel.Implementations; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { public partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback { diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs index 614fcdb4ec46..a0633d23a727 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs @@ -4,7 +4,7 @@ using AuthenticationServices; using Foundation; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { public partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback { diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs index cf1089bb2bc3..da7d1eeaf14b 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs @@ -3,7 +3,7 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { /// public partial class WebAuthenticatorImplementation : IWebAuthenticator diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs index 74c3e1b6fd73..bc6278e8691a 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs @@ -4,10 +4,10 @@ using System.Text; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Essentials.Implementations; +using Microsoft.Maui.Authentication; +using Microsoft.Maui.Authentication.Implementations; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Authentication { public interface IWebAuthenticator { @@ -75,11 +75,11 @@ public class WebAuthenticatorOptions } } -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { public partial class WebAuthenticatorImplementation { public Task AuthenticateAsync(Uri url, Uri callbackUrl) - => AuthenticateAsync(new Microsoft.Maui.Essentials.WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl }); + => AuthenticateAsync(new WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl }); } } diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs index f9147b4bb33d..f7c26073a94b 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs @@ -8,9 +8,10 @@ using System.Xml; using System.Xml.Linq; using System.Xml.XPath; +using Microsoft.Maui.Essentials; using Windows.Security.Authentication.Web; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { public partial class WebAuthenticatorImplementation : IWebAuthenticator { diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs index be5e09c62d72..d5fd8179cc87 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs @@ -2,7 +2,7 @@ using Android.Content; using Android.OS; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Authentication { public abstract class WebAuthenticatorCallbackActivity : Activity { diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs index a9798364db36..45501b9b994b 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs @@ -3,7 +3,7 @@ using Android.Content.PM; using Android.OS; -namespace Microsoft.Maui.Essentials.Implementations +namespace Microsoft.Maui.Authentication.Implementations { [Activity(ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, Exported = true)] class WebAuthenticatorIntermediateActivity : Activity diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticatorResult.shared.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticatorResult.shared.cs index 2780666270f0..8b7f902c4fda 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticatorResult.shared.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticatorResult.shared.cs @@ -3,7 +3,7 @@ using System.Linq; using System.Text; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Authentication { /// public class WebAuthenticatorResult From 5e3038da5e18138e22cc39402c7e5863bd0d343b Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sat, 19 Mar 2022 02:57:51 +0200 Subject: [PATCH 02/45] Trying things with essentials --- .../Core/src/Essentials/Accelerometer.cs | 33 ++++ .../Core/src/Essentials/AppActions.cs | 49 ++++++ .../Core/src/Essentials/AppInfo.cs | 37 ++++ .../Core/src/Essentials/Barometer.cs | 32 ++++ .../Core/src/Essentials/Battery.cs | 65 +++++++ .../Core/src/Essentials/Browser.cs | 31 ++++ .../Core/src/Essentials/Clipboard.cs | 43 +++++ .../Core/src/Essentials/Platform.cs | 33 ++++ .../Accelerometer/Accelerometer.android.cs | 48 ++++-- .../Accelerometer.ios.watchos.cs | 5 +- .../Accelerometer.netstandard.tvos.macos.cs | 4 +- .../src/Accelerometer/Accelerometer.shared.cs | 89 +++------- .../src/Accelerometer/Accelerometer.tizen.cs | 4 +- .../src/Accelerometer/Accelerometer.uwp.cs | 4 +- .../AccelerometerQueue.shared.cs | 2 +- .../src/AppActions/AppActions.android.cs | 57 ++++--- .../src/AppActions/AppActions.ios.cs | 29 ++-- ...ns.netstandard.tvos.watchos.macos.tizen.cs | 12 +- .../src/AppActions/AppActions.shared.cs | 63 +++---- .../src/AppActions/AppActions.uwp.cs | 85 ++++------ src/Essentials/src/AppInfo/AppInfo.android.cs | 5 +- .../AppInfo/AppInfo.ios.tvos.watchos.macos.cs | 5 +- .../src/AppInfo/AppInfo.netstandard.cs | 4 +- src/Essentials/src/AppInfo/AppInfo.shared.cs | 32 +--- src/Essentials/src/AppInfo/AppInfo.tizen.cs | 4 +- src/Essentials/src/AppInfo/AppInfo.uwp.cs | 4 +- .../src/Barometer/Barometer.android.cs | 5 +- .../src/Barometer/Barometer.ios.watchos.cs | 5 +- .../Barometer.netstandard.tvos.macos.cs | 4 +- .../src/Barometer/Barometer.shared.cs | 47 +---- .../src/Barometer/Barometer.tizen.cs | 4 +- src/Essentials/src/Barometer/Barometer.uwp.cs | 4 +- src/Essentials/src/Battery/Battery.android.cs | 17 +- .../src/Battery/Battery.ios.watchos.cs | 20 +-- src/Essentials/src/Battery/Battery.macos.cs | 12 +- .../src/Battery/Battery.netstandard.tvos.cs | 12 +- src/Essentials/src/Battery/Battery.shared.cs | 111 ++++-------- src/Essentials/src/Battery/Battery.tizen.cs | 4 +- src/Essentials/src/Battery/Battery.uwp.cs | 4 +- src/Essentials/src/Browser/Browser.android.cs | 160 +++++++----------- src/Essentials/src/Browser/Browser.ios.cs | 98 +++-------- src/Essentials/src/Browser/Browser.macos.cs | 66 +------- .../Browser.netstandard.tvos.watchos.cs | 66 +------- src/Essentials/src/Browser/Browser.shared.cs | 88 +++------- src/Essentials/src/Browser/Browser.tizen.cs | 66 +------- src/Essentials/src/Browser/Browser.uwp.cs | 66 +------- .../src/Browser/BrowserLaunchMode.shared.cs | 1 + .../Browser/BrowserLaunchOptions.shared.cs | 8 +- .../src/Browser/BrowserTitleMode.shared.cs | 1 + .../src/Clipboard/Clipboard.android.cs | 48 ++++-- src/Essentials/src/Clipboard/Clipboard.ios.cs | 4 +- .../src/Clipboard/Clipboard.macos.cs | 4 +- ...lipboard.netstandard.tvos.watchos.tizen.cs | 4 +- .../src/Clipboard/Clipboard.shared.cs | 70 +++----- src/Essentials/src/Clipboard/Clipboard.uwp.cs | 4 +- src/Essentials/src/Compass/Compass.android.cs | 5 +- src/Essentials/src/Compass/Compass.ios.cs | 4 +- .../Compass.netstandard.tvos.watchos.macos.cs | 4 +- src/Essentials/src/Compass/Compass.shared.cs | 19 +-- src/Essentials/src/Compass/Compass.tizen.cs | 4 +- src/Essentials/src/Compass/Compass.uwp.cs | 4 +- .../src/Connectivity/Connectivity.android.cs | 5 +- .../Connectivity.ios.tvos.macos.cs | 4 +- ...onnectivity.ios.tvos.macos.reachability.cs | 2 +- .../Connectivity.netstandard.watchos.cs | 4 +- .../src/Connectivity/Connectivity.shared.cs | 16 +- .../src/Connectivity/Connectivity.tizen.cs | 4 +- .../src/Connectivity/Connectivity.uwp.cs | 4 +- .../src/Contacts/Contacts.android.cs | 5 +- .../src/Contacts/Contacts.ios.macos.cs | 5 +- .../Contacts.netstandard.tvos.watchos.cs | 4 +- .../src/Contacts/Contacts.shared.cs | 6 +- src/Essentials/src/Contacts/Contacts.tizen.cs | 2 +- src/Essentials/src/Contacts/Contacts.uwp.cs | 4 +- .../DeviceDisplay/DeviceDisplay.android.cs | 5 +- .../src/DeviceDisplay/DeviceDisplay.ios.cs | 4 +- .../src/DeviceDisplay/DeviceDisplay.macos.cs | 4 +- .../DeviceDisplay.netstandard.tvos.watchos.cs | 4 +- .../src/DeviceDisplay/DeviceDisplay.shared.cs | 12 +- .../src/DeviceDisplay/DeviceDisplay.tizen.cs | 4 +- .../src/DeviceDisplay/DeviceDisplay.uwp.cs | 5 +- .../src/DeviceInfo/DeviceInfo.android.cs | 16 +- .../DeviceInfo/DeviceInfo.ios.tvos.watchos.cs | 6 +- .../src/DeviceInfo/DeviceInfo.macos.cs | 4 +- .../src/DeviceInfo/DeviceInfo.netstandard.cs | 4 +- .../src/DeviceInfo/DeviceInfo.shared.cs | 12 +- .../src/DeviceInfo/DeviceInfo.tizen.cs | 20 +-- .../src/DeviceInfo/DeviceInfo.uwp.cs | 6 +- src/Essentials/src/Email/Email.android.cs | 5 +- src/Essentials/src/Email/Email.ios.cs | 5 +- src/Essentials/src/Email/Email.macos.cs | 4 +- .../Email/Email.netstandard.tvos.watchos.cs | 7 +- src/Essentials/src/Email/Email.shared.cs | 17 +- src/Essentials/src/Email/Email.tizen.cs | 4 +- src/Essentials/src/Email/Email.uwp.cs | 4 +- src/Essentials/src/Essentials.csproj | 3 + .../src/FilePicker/FilePicker.android.cs | 8 +- .../src/FilePicker/FilePicker.ios.cs | 8 +- .../src/FilePicker/FilePicker.macos.cs | 6 +- .../FilePicker.netstandard.watchos.tvos.cs | 7 +- .../src/FilePicker/FilePicker.shared.cs | 7 +- .../src/FilePicker/FilePicker.tizen.cs | 6 +- .../src/FilePicker/FilePicker.uwp.cs | 8 +- .../src/FileSystem/FileSystem.android.cs | 8 +- .../src/FileSystem/FileSystem.ios.cs | 4 +- .../FileSystem.ios.tvos.watchos.macos.cs | 7 +- .../src/FileSystem/FileSystem.netstandard.cs | 7 +- .../src/FileSystem/FileSystem.shared.cs | 140 ++++++++------- .../src/FileSystem/FileSystem.tizen.cs | 7 +- .../src/FileSystem/FileSystem.uwp.cs | 7 +- .../src/Flashlight/Flashlight.android.cs | 5 +- .../src/Flashlight/Flashlight.ios.cs | 4 +- ...ashlight.netstandard.tvos.watchos.macos.cs | 4 +- .../src/Flashlight/Flashlight.shared.cs | 5 +- .../src/Flashlight/Flashlight.tizen.cs | 6 +- .../src/Flashlight/Flashlight.uwp.cs | 4 +- .../src/Geocoding/Geocoding.android.cs | 5 +- .../Geocoding.ios.tvos.watchos.macos.cs | 4 +- .../src/Geocoding/Geocoding.netstandard.cs | 4 +- .../src/Geocoding/Geocoding.shared.cs | 9 +- .../src/Geocoding/Geocoding.tizen.cs | 6 +- src/Essentials/src/Geocoding/Geocoding.uwp.cs | 5 +- .../src/Geolocation/Geolocation.android.cs | 5 +- .../src/Geolocation/Geolocation.ios.macos.cs | 4 +- .../Geolocation.netstandard.tvos.watchos.cs | 4 +- .../src/Geolocation/Geolocation.shared.cs | 9 +- .../src/Geolocation/Geolocation.tizen.cs | 4 +- .../src/Geolocation/Geolocation.uwp.cs | 4 +- .../src/Gyroscope/Gyroscope.android.cs | 5 +- .../src/Gyroscope/Gyroscope.ios.watchos.cs | 5 +- .../Gyroscope.netstandard.tvos.macos.cs | 4 +- .../src/Gyroscope/Gyroscope.shared.cs | 19 +-- .../src/Gyroscope/Gyroscope.tizen.cs | 4 +- src/Essentials/src/Gyroscope/Gyroscope.uwp.cs | 4 +- .../HapticFeedback/HapticFeedback.android.cs | 5 +- .../src/HapticFeedback/HapticFeedback.ios.cs | 4 +- .../HapticFeedback/HapticFeedback.macos.cs | 4 +- ...HapticFeedback.netstandard.tvos.watchos.cs | 4 +- .../HapticFeedback/HapticFeedback.shared.cs | 11 +- .../HapticFeedback/HapticFeedback.tizen.cs | 4 +- .../src/HapticFeedback/HapticFeedback.uwp.cs | 4 +- .../src/Launcher/Launcher.android.cs | 5 +- .../src/Launcher/Launcher.ios.tvos.cs | 5 +- src/Essentials/src/Launcher/Launcher.macos.cs | 4 +- .../Launcher/Launcher.netstandard.watchos.cs | 4 +- .../src/Launcher/Launcher.shared.cs | 19 ++- src/Essentials/src/Launcher/Launcher.tizen.cs | 4 +- src/Essentials/src/Launcher/Launcher.uwp.cs | 4 +- .../src/Magnetometer/Magnetometer.android.cs | 5 +- .../Magnetometer/Magnetometer.ios.watchos.cs | 5 +- .../Magnetometer.netstandard.tvos.macos.cs | 4 +- .../src/Magnetometer/Magnetometer.shared.cs | 19 +-- .../src/Magnetometer/Magnetometer.tizen.cs | 4 +- .../src/Magnetometer/Magnetometer.uwp.cs | 4 +- .../src/MainThread/MainThread.android.cs | 2 +- .../MainThread.ios.tvos.watchos.macos.cs | 2 +- .../src/MainThread/MainThread.netstandard.cs | 2 +- .../src/MainThread/MainThread.shared.cs | 2 +- .../src/MainThread/MainThread.tizen.cs | 2 +- .../src/MainThread/MainThread.uwp.cs | 3 +- .../MainThread/MainThreadExtensions.uwp.cs | 4 +- src/Essentials/src/Map/Map.android.cs | 5 +- .../src/Map/Map.ios.watchos.macos.cs | 4 +- .../src/Map/Map.netstandard.tvos.cs | 4 +- src/Essentials/src/Map/Map.shared.cs | 10 +- src/Essentials/src/Map/Map.tizen.cs | 6 +- src/Essentials/src/Map/Map.uwp.cs | 4 +- .../src/MediaPicker/MediaPicker.android.cs | 5 +- .../src/MediaPicker/MediaPicker.ios.cs | 5 +- .../src/MediaPicker/MediaPicker.macos.cs | 4 +- .../MediaPicker.netstandard.watchos.tvos.cs | 4 +- .../src/MediaPicker/MediaPicker.shared.cs | 15 +- .../src/MediaPicker/MediaPicker.tizen.cs | 4 +- .../src/MediaPicker/MediaPicker.uwp.cs | 5 +- .../OrientationSensor.android.cs | 5 +- .../OrientationSensor.ios.watchos.cs | 5 +- ...rientationSensor.netstandard.tvos.macos.cs | 4 +- .../OrientationSensor.shared.cs | 18 +- .../OrientationSensor.tizen.cs | 4 +- .../OrientationSensor.uwp.cs | 4 +- .../src/Permissions/Permissions.android.cs | 1 - .../Permissions/Permissions.ios.tvos.macos.cs | 1 - .../src/Permissions/Permissions.shared.cs | 3 - .../src/Permissions/Permissions.uwp.cs | 1 - .../src/PhoneDialer/PhoneDialer.android.cs | 5 +- .../src/PhoneDialer/PhoneDialer.ios.cs | 4 +- .../src/PhoneDialer/PhoneDialer.macos.cs | 4 +- .../PhoneDialer.netstandard.tvos.watchos.cs | 4 +- .../src/PhoneDialer/PhoneDialer.shared.cs | 7 +- .../src/PhoneDialer/PhoneDialer.tizen.cs | 4 +- .../src/PhoneDialer/PhoneDialer.uwp.cs | 4 +- .../src/Platform/Platform.android.cs | 26 --- .../src/Platform/Platform.ios.tvos.watchos.cs | 13 -- src/Essentials/src/Platform/Platform.uwp.cs | 3 - .../src/Preferences/Preferences.android.cs | 4 +- .../Preferences.ios.tvos.watchos.macos.cs | 4 +- .../Preferences/Preferences.netstandard.cs | 4 +- .../src/Preferences/Preferences.shared.cs | 10 +- .../src/Preferences/Preferences.tizen.cs | 12 +- .../src/Preferences/Preferences.uwp.cs | 4 +- .../src/Screenshot/Screenshot.android.cs | 3 +- .../src/Screenshot/Screenshot.ios.cs | 2 +- ...eenshot.netstandard.tizen.watchos.macos.cs | 2 +- .../src/Screenshot/Screenshot.shared.cs | 4 +- .../src/Screenshot/Screenshot.tvos.cs | 2 +- .../src/Screenshot/Screenshot.uwp.cs | 2 +- .../SecureStorage/SecureStorage.android.cs | 4 +- .../SecureStorage.ios.tvos.watchos.macos.cs | 4 +- .../SecureStorage.netstandard.cs | 4 +- .../src/SecureStorage/SecureStorage.shared.cs | 14 +- .../src/SecureStorage/SecureStorage.tizen.cs | 4 +- .../src/SecureStorage/SecureStorage.uwp.cs | 4 +- .../SemanticScreenReader.android.cs | 4 +- .../SemanticScreenReader.ios.cs | 4 +- ...er.netstandard.tvos.watchos.macos.tizen.cs | 4 +- .../SemanticScreenReader.shared.cs | 10 +- .../SemanticScreenReader.uwp.cs | 5 +- src/Essentials/src/Share/Share.android.cs | 5 +- src/Essentials/src/Share/Share.ios.cs | 5 +- src/Essentials/src/Share/Share.macos.cs | 4 +- .../Share/Share.netstandard.tvos.watchos.cs | 4 +- src/Essentials/src/Share/Share.shared.cs | 14 +- src/Essentials/src/Share/Share.tizen.cs | 4 +- src/Essentials/src/Share/Share.uwp.cs | 5 +- src/Essentials/src/Sms/Sms.android.cs | 5 +- src/Essentials/src/Sms/Sms.ios.cs | 5 +- src/Essentials/src/Sms/Sms.macos.cs | 4 +- .../src/Sms/Sms.netstandard.tvos.watchos.cs | 4 +- src/Essentials/src/Sms/Sms.shared.cs | 23 +-- src/Essentials/src/Sms/Sms.tizen.cs | 4 +- src/Essentials/src/Sms/Sms.uwp.cs | 4 +- .../src/TextToSpeech/TextToSpeech.android.cs | 5 +- .../TextToSpeech.ios.tvos.watchos.cs | 4 +- .../src/TextToSpeech/TextToSpeech.macos.cs | 4 +- .../TextToSpeech/TextToSpeech.netstandard.cs | 4 +- .../src/TextToSpeech/TextToSpeech.shared.cs | 15 +- .../src/TextToSpeech/TextToSpeech.tizen.cs | 4 +- .../src/TextToSpeech/TextToSpeech.uwp.cs | 4 +- .../TextToSpeechExtensions.shared.cs | 2 +- .../src/Types/FileProvider.android.cs | 1 - src/Essentials/src/Types/Location.shared.cs | 1 - .../src/Types/LocationExtensions.android.cs | 1 - .../VersionTracking/VersionTracking.shared.cs | 14 +- .../src/Vibration/Vibration.android.cs | 5 +- src/Essentials/src/Vibration/Vibration.ios.cs | 4 +- ...ibration.netstandard.tvos.watchos.macos.cs | 4 +- .../src/Vibration/Vibration.shared.cs | 10 +- .../src/Vibration/Vibration.tizen.cs | 4 +- src/Essentials/src/Vibration/Vibration.uwp.cs | 4 +- .../AppleSignInAuthenticator.ios.cs | 5 +- ...rd.android.tvos.watchos.uwp.tizen.macos.cs | 5 +- .../AppleSignInAuthenticator.shared.cs | 28 +-- .../WebAuthenticator.android.cs | 5 +- .../WebAuthenticator.ios.tvos.cs | 9 +- .../WebAuthenticator.macos.cs | 4 +- ...Authenticator.netstandard.watchos.tizen.cs | 4 +- .../WebAuthenticator.shared.cs | 14 +- .../WebAuthenticator/WebAuthenticator.uwp.cs | 5 +- ...ebAuthenticatorCallbackActivity.android.cs | 2 +- ...thenticatorIntermediateActivity.android.cs | 2 +- 260 files changed, 1402 insertions(+), 1713 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/Accelerometer.cs create mode 100644 src/Compatibility/Core/src/Essentials/AppActions.cs create mode 100644 src/Compatibility/Core/src/Essentials/AppInfo.cs create mode 100644 src/Compatibility/Core/src/Essentials/Barometer.cs create mode 100644 src/Compatibility/Core/src/Essentials/Battery.cs create mode 100644 src/Compatibility/Core/src/Essentials/Browser.cs create mode 100644 src/Compatibility/Core/src/Essentials/Clipboard.cs create mode 100644 src/Compatibility/Core/src/Essentials/Platform.cs diff --git a/src/Compatibility/Core/src/Essentials/Accelerometer.cs b/src/Compatibility/Core/src/Essentials/Accelerometer.cs new file mode 100644 index 000000000000..a8c78b55eb24 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Accelerometer.cs @@ -0,0 +1,33 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Accelerometer + { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + public static event EventHandler ShakeDetected + { + add => Current.ShakeDetected += value; + remove => Current.ShakeDetected -= value; + } + + /// + public static bool IsMonitoring => Current.IsMonitoring; + + /// + public static void Start(SensorSpeed sensorSpeed) => Current.Start(sensorSpeed); + + /// + public static void Stop() => Current.Stop(); + + static IAccelerometer Current => Devices.Sensors.Accelerometer.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/AppActions.cs b/src/Compatibility/Core/src/Essentials/AppActions.cs new file mode 100644 index 000000000000..68ef79005395 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/AppActions.cs @@ -0,0 +1,49 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class AppActions + { + static event EventHandler? OnAppActionInternal; + + /// + public static Task> GetAsync() + => Current.GetAsync(); + + /// + public static Task SetAsync(params AppAction[] actions) + => Current.SetAsync(actions); + + /// + public static Task SetAsync(IEnumerable actions) + => Current.SetAsync(actions); + + public static event EventHandler? OnAppAction + { + add + { + if (OnAppActionInternal == null) + Current.AppActionActivated += OnAppActionActivated; + + OnAppActionInternal += value; + } + remove + { + OnAppActionInternal -= value; + + if (OnAppActionInternal == null) + Current.AppActionActivated -= OnAppActionActivated; + } + } + + static void OnAppActionActivated(object? sender, AppActionEventArgs e) => + OnAppActionInternal?.Invoke(sender, e); + + static IAppActions Current => ApplicationModel.AppActions.Current; + } +} diff --git a/src/Compatibility/Core/src/Essentials/AppInfo.cs b/src/Compatibility/Core/src/Essentials/AppInfo.cs new file mode 100644 index 000000000000..69e557f91288 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/AppInfo.cs @@ -0,0 +1,37 @@ +#nullable enable +using System; +using Microsoft.Maui.ApplicationModel; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class AppInfo + { + /// + public static string PackageName => Current.PackageName; + + /// + public static string Name => Current.Name; + + /// + public static string VersionString => Current.VersionString; + + /// + public static Version Version => Current.Version; + + /// + public static string BuildString => Current.BuildString; + + /// + public static void ShowSettingsUI() => Current.ShowSettingsUI(); + + /// + public static AppTheme RequestedTheme => Current.RequestedTheme; + + public static AppPackagingModel PackagingModel => Current.PackagingModel; + + public static LayoutDirection RequestedLayoutDirection => Current.RequestedLayoutDirection; + + static IAppInfo Current => ApplicationModel.AppInfo.Current; + } +} \ No newline at end of file diff --git a/src/Compatibility/Core/src/Essentials/Barometer.cs b/src/Compatibility/Core/src/Essentials/Barometer.cs new file mode 100644 index 000000000000..e92a218175c2 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Barometer.cs @@ -0,0 +1,32 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Barometer + { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + public static bool IsSupported => Current.IsSupported; + + /// + public static bool IsMonitoring + => Current.IsMonitoring; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Current.Start(sensorSpeed); + + /// + public static void Stop() + => Current.Stop(); + + static IBarometer Current => Devices.Sensors.Barometer.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Battery.cs b/src/Compatibility/Core/src/Essentials/Battery.cs new file mode 100644 index 000000000000..50d5b6196f7d --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Battery.cs @@ -0,0 +1,65 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Battery + { + static event EventHandler? BatteryInfoChangedInternal; + static event EventHandler? EnergySaverStatusChangedInternal; + + /// + public static double ChargeLevel => Current.ChargeLevel; + + /// + public static BatteryState State => Current.State; + + /// + public static BatteryPowerSource PowerSource => Current.PowerSource; + + /// + public static EnergySaverStatus EnergySaverStatus => Current.EnergySaverStatus; + + public static event EventHandler BatteryInfoChanged + { + add + { + if (BatteryInfoChangedInternal == null) + Current.BatteryInfoChanged += OnBatteryInfoChanged; + BatteryInfoChangedInternal += value; + } + remove + { + BatteryInfoChangedInternal -= value; + if (BatteryInfoChangedInternal == null) + Current.BatteryInfoChanged -= OnBatteryInfoChanged; + } + } + + public static event EventHandler EnergySaverStatusChanged + { + add + { + if (EnergySaverStatusChangedInternal == null) + Current.EnergySaverStatusChanged += OnEnergySaverStatusChanged; + EnergySaverStatusChangedInternal += value; + } + remove + { + EnergySaverStatusChangedInternal -= value; + if (EnergySaverStatusChangedInternal == null) + Current.EnergySaverStatusChanged -= OnEnergySaverStatusChanged; + } + } + + static void OnBatteryInfoChanged(object? sender, BatteryInfoChangedEventArgs e) => + BatteryInfoChangedInternal?.Invoke(sender, e); + + static void OnEnergySaverStatusChanged(object? sender, EnergySaverStatusChangedEventArgs e) => + EnergySaverStatusChangedInternal?.Invoke(sender, e); + + static IBattery Current => Devices.Battery.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Browser.cs b/src/Compatibility/Core/src/Essentials/Browser.cs new file mode 100644 index 000000000000..de92ed043d06 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Browser.cs @@ -0,0 +1,31 @@ +#nullable enable +using System; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Browser + { + /// + public static Task OpenAsync(string uri) => Current.OpenAsync(uri); + + /// + public static Task OpenAsync(string uri, BrowserLaunchMode launchMode) => Current.OpenAsync(uri, launchMode); + + /// + public static Task OpenAsync(string uri, BrowserLaunchOptions options) => Current.OpenAsync(uri, options); + + /// + public static Task OpenAsync(Uri uri) => Current.OpenAsync(uri); + + /// + public static Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) => Current.OpenAsync(uri, launchMode); + + /// + public static Task OpenAsync(Uri uri, BrowserLaunchOptions options) => Current.OpenAsync(uri, options); + + public static IBrowser Current => ApplicationModel.Browser.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Clipboard.cs b/src/Compatibility/Core/src/Essentials/Clipboard.cs new file mode 100644 index 000000000000..b5dd9296b4d6 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Clipboard.cs @@ -0,0 +1,43 @@ +#nullable enable +using System; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel.DataTransfer; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Clipboard + { + static event EventHandler ClipboardContentChangedInternal; + + /// + public static Task SetTextAsync(string text) + => Current.SetTextAsync(text ?? string.Empty); + + /// + public static bool HasText + => Current.HasText; + + /// + public static Task GetTextAsync() + => Current.GetTextAsync(); + + public static event EventHandler ClipboardContentChanged + { + add + { + if (ClipboardContentChangedInternal == null) + Current.ClipboardContentChanged += OnClipboardContentChanged; + ClipboardContentChangedInternal += value; + } + remove + { + ClipboardContentChangedInternal -= value; + if (ClipboardContentChangedInternal == null) + Current.ClipboardContentChanged -= OnClipboardContentChanged; + } + } + + static IClipboard Current => ApplicationModel.DataTransfer.Clipboard.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Platform.cs b/src/Compatibility/Core/src/Essentials/Platform.cs new file mode 100644 index 000000000000..79bff7f8281d --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Platform.cs @@ -0,0 +1,33 @@ +using Microsoft.Maui.ApplicationModel; + +namespace Microsoft.Maui.Essentials +{ + public static class Platform + { +#if ANDROID + public static void OnNewIntent(Android.Content.Intent intent) + { + if (ApplicationModel.AppActions.Current is IPlatformAppActions platform) + platform.OnNewIntent(intent); + } + + public static void OnResume(Android.App.Activity activity = null) + { + if (ApplicationModel.AppActions.Current is IPlatformAppActions platform) + platform.OnNewIntent(activity?.Intent); + } +#elif IOS || MACCATALYST + public static void PerformActionForShortcutItem(UIKit.UIApplication application, UIKit.UIApplicationShortcutItem shortcutItem, UIKit.UIOperationHandler completionHandler) + { + if (ApplicationModel.AppActions.Current is IPlatformAppActions platform) + platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler); + } +#elif WINDOWS + public static async void OnLaunched(UI.Xaml.LaunchActivatedEventArgs e) + { + if (ApplicationModel.AppActions.Current is IPlatformAppActions platform) + await platform.OnLaunched(e); + } +#endif + } +} diff --git a/src/Essentials/src/Accelerometer/Accelerometer.android.cs b/src/Essentials/src/Accelerometer/Accelerometer.android.cs index 69f275efc16a..848244dd45ae 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.android.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.android.cs @@ -1,23 +1,37 @@ +#nullable enable +using System; +using Android.App; +using Android.Content; using Android.Hardware; -using Android.Runtime; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class AccelerometerImplementation + partial class AccelerometerImplementation { + static SensorManager? _sensorManager; + + static SensorManager? SensorManager => + _sensorManager ??= Application.Context.GetSystemService(Context.SensorService) as SensorManager; + public bool IsSupported => - Platform.SensorManager?.GetDefaultSensor(SensorType.Accelerometer) != null; + SensorManager?.GetDefaultSensor(SensorType.Accelerometer) != null; - AccelerometerListener listener; - Sensor accelerometer; + AccelerometerListener? listener; + Sensor? accelerometer; void PlatformStart(SensorSpeed sensorSpeed) { - var delay = sensorSpeed.ToPlatform(); - listener = new AccelerometerListener(this); - accelerometer = Platform.SensorManager.GetDefaultSensor(SensorType.Accelerometer); - Platform.SensorManager.RegisterListener(listener, accelerometer, delay); + if (SensorManager is null) + return; + + accelerometer = SensorManager.GetDefaultSensor(SensorType.Accelerometer); + if (accelerometer is not null) + { + listener = new AccelerometerListener(this); + + var delay = sensorSpeed.ToPlatform(); + SensorManager.RegisterListener(listener, accelerometer, delay); + } } void PlatformStop() @@ -25,7 +39,8 @@ void PlatformStop() if (listener == null || accelerometer == null) return; - Platform.SensorManager.UnregisterListener(listener, accelerometer); + SensorManager?.UnregisterListener(listener, accelerometer); + listener.Dispose(); listener = null; } @@ -43,16 +58,17 @@ internal AccelerometerListener(AccelerometerImplementation accelerometer) _accelerometer = accelerometer; } - void ISensorEventListener.OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy) + void ISensorEventListener.OnAccuracyChanged(Sensor? sensor, SensorStatus accuracy) { } - void ISensorEventListener.OnSensorChanged(SensorEvent e) + void ISensorEventListener.OnSensorChanged(SensorEvent? e) { - if ((e?.Values?.Count ?? 0) < 3) + var values = e?.Values ?? Array.Empty(); + if (values.Count < 3) return; - var data = new AccelerometerData(e.Values[0] / gravity, e.Values[1] / gravity, e.Values[2] / gravity); + var data = new AccelerometerData(values[0] / gravity, values[1] / gravity, values[2] / gravity); _accelerometer.OnChanged(data); } } diff --git a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs index 011cdab2b991..db22a804a44f 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs @@ -1,10 +1,9 @@ using CoreMotion; using Foundation; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class AccelerometerImplementation + partial class AccelerometerImplementation { public bool IsSupported => Platform.MotionManager?.AccelerometerAvailable ?? false; diff --git a/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs b/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs index 0b97d55e98c7..6c24a9db8a81 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs @@ -1,7 +1,7 @@ -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { /// - public partial class AccelerometerImplementation + partial class AccelerometerImplementation { public bool IsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs index 35017efdd2d6..7e287675b8e3 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs @@ -1,75 +1,33 @@ #nullable enable using System; -using System.ComponentModel; using System.Numerics; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Devices.Sensors.Implementations; namespace Microsoft.Maui.Devices.Sensors { public interface IAccelerometer { event EventHandler? ReadingChanged; + event EventHandler? ShakeDetected; + bool IsSupported { get; } + bool IsMonitoring { get; } + void Start(SensorSpeed sensorSpeed); + void Stop(); } - /// - public static partial class Accelerometer + public static class Accelerometer { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - public static event EventHandler ShakeDetected - { - add => Current.ShakeDetected += value; - remove => Current.ShakeDetected -= value; - } - - internal static bool IsSupported => Current.IsSupported; - - /// - public static bool IsMonitoring => Current.IsMonitoring; - - /// - public static void Start(SensorSpeed sensorSpeed) - { - if (!Current.IsSupported) - throw new FeatureNotSupportedException(); - - if (Current.IsMonitoring) - throw new InvalidOperationException("Accelerometer has already been started."); - - Current.Start(sensorSpeed); - } - - /// - public static void Stop() - { - if (!Current.IsSupported) - throw new FeatureNotSupportedException(); - - if (!Current.IsMonitoring) - return; - - Current.Stop(); - } - - static IAccelerometer? currentImplementation; + static IAccelerometer? defaultImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] - public static IAccelerometer Current => - currentImplementation ??= new AccelerometerImplementation(); + public static IAccelerometer Default => + defaultImplementation ??= new AccelerometerImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IAccelerometer? implementation) => - currentImplementation = implementation; + internal static void SetDefault(IAccelerometer? implementation) => + defaultImplementation = implementation; } /// @@ -110,7 +68,7 @@ public bool Equals(AccelerometerData other) => left.Equals(right); public static bool operator !=(AccelerometerData left, AccelerometerData right) => - !left.Equals(right); + !left.Equals(right); /// public override int GetHashCode() => @@ -122,11 +80,8 @@ public override string ToString() => $"{nameof(Acceleration.Y)}: {Acceleration.Y}, " + $"{nameof(Acceleration.Z)}: {Acceleration.Z}"; } -} -namespace Microsoft.Maui.Devices.Sensors.Implementations -{ - public partial class AccelerometerImplementation : IAccelerometer + partial class AccelerometerImplementation : IAccelerometer { const double accelerationThreshold = 169; @@ -144,6 +99,12 @@ public partial class AccelerometerImplementation : IAccelerometer public void Start(SensorSpeed sensorSpeed) { + if (!IsSupported) + throw new FeatureNotSupportedException(); + + if (IsMonitoring) + throw new InvalidOperationException("Accelerometer has already been started."); + IsMonitoring = true; useSyncContext = sensorSpeed == SensorSpeed.Default || sensorSpeed == SensorSpeed.UI; @@ -151,25 +112,29 @@ public void Start(SensorSpeed sensorSpeed) { PlatformStart(sensorSpeed); } - catch + finally { IsMonitoring = false; - throw; } } public void Stop() { + if (!IsSupported) + throw new FeatureNotSupportedException(); + + if (!IsMonitoring) + return; + IsMonitoring = false; try { PlatformStop(); } - catch + finally { IsMonitoring = true; - throw; } } diff --git a/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs b/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs index 655ff08b847c..d0054512a9cd 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.tizen.cs @@ -1,9 +1,9 @@ using Tizen.Sensor; using TizenAccelerometer = Tizen.Sensor.Accelerometer; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class AccelerometerImplementation + partial class AccelerometerImplementation { internal static TizenAccelerometer DefaultSensor => (TizenAccelerometer)Platform.GetDefaultSensor(SensorType.Accelerometer); diff --git a/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs b/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs index dd83b864f502..6ad719be2a94 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.uwp.cs @@ -1,9 +1,9 @@ using Windows.Devices.Sensors; using WindowsAccelerometer = Windows.Devices.Sensors.Accelerometer; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class AccelerometerImplementation + partial class AccelerometerImplementation { // keep around a reference so we can stop this same instance WindowsAccelerometer sensor; diff --git a/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs b/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs index c2ffae04c0c1..729bf69b46f5 100644 --- a/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs +++ b/src/Essentials/src/Accelerometer/AccelerometerQueue.shared.cs @@ -1,4 +1,4 @@ -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { // Detect if 3/4ths of the accelerometer events in the last half second are accelerating // this means we are free falling or shaking diff --git a/src/Essentials/src/AppActions/AppActions.android.cs b/src/Essentials/src/AppActions/AppActions.android.cs index 0971bc76daaf..dd7c155386f3 100755 --- a/src/Essentials/src/AppActions/AppActions.android.cs +++ b/src/Essentials/src/AppActions/AppActions.android.cs @@ -1,19 +1,20 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Android.App; using Android.Content; using Android.Content.PM; using Android.Graphics.Drawables; using Android.Runtime; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class AppActionsImplementation : IAppActions + class AppActionsImplementation : IAppActions, IPlatformAppActions { - public string Type => "XE_APP_ACTION_TYPE"; - public bool IsSupported - => Platform.HasApiLevelNMr1; + public const string IntentAction = "ACTION_XE_APP_ACTION"; + + public bool IsSupported => OperatingSystem.IsAndroidVersionAtLeast(25); public Task> GetAsync() { @@ -21,9 +22,12 @@ public Task> GetAsync() throw new FeatureNotSupportedException(); #if __ANDROID_25__ - return Task.FromResult(Platform.ShortcutManager.DynamicShortcuts.Select(s => s.ToAppAction())); + if (Application.Context.GetSystemService(Context.ShortcutService) is not ShortcutManager manager) + throw new FeatureNotSupportedException(); + + return Task.FromResult(manager.DynamicShortcuts.Select(s => s.ToAppAction())); #else - return Task.FromResult < IEnumerable < AppAction >> (null); + return Task.FromResult>(null); #endif } @@ -33,19 +37,30 @@ public Task SetAsync(IEnumerable actions) throw new FeatureNotSupportedException(); #if __ANDROID_25__ + if (Application.Context.GetSystemService(Context.ShortcutService) is not ShortcutManager manager) + throw new FeatureNotSupportedException(); + using var list = new JavaList(actions.Select(a => a.ToShortcutInfo())); - Platform.ShortcutManager.SetDynamicShortcuts(list); + manager.SetDynamicShortcuts(list); #endif return Task.CompletedTask; } - public Task SetAsync(params AppAction[] actions) - { - return SetAsync(actions); + public event EventHandler AppActionActivated; + + public void OnNewIntent(Intent intent) + { + if (intent?.Action == IntentAction) + { + var appAction = intent.ToAppAction(); + + if (!string.IsNullOrEmpty(appAction?.Id)) + AppActionActivated?.Invoke(null, new AppActionEventArgs(appAction)); + } } } - internal static partial class AppActionsExtensions + static partial class AppActionsExtensions { internal static AppAction ToAppAction(this ShortcutInfo shortcutInfo) => new AppAction(shortcutInfo.Id, shortcutInfo.ShortLabel, shortcutInfo.LongLabel); @@ -61,10 +76,12 @@ internal static AppAction ToAppAction(this Intent intent) intent.GetStringExtra(extraAppActionTitle), intent.GetStringExtra(extraAppActionSubtitle), intent.GetStringExtra(extraAppActionIcon)); - + internal static ShortcutInfo ToShortcutInfo(this AppAction action) { - var shortcut = new ShortcutInfo.Builder(Platform.AppContext, action.Id) + var context = Application.Context; + + var shortcut = new ShortcutInfo.Builder(context, action.Id) .SetShortLabel(action.Title); if (!string.IsNullOrWhiteSpace(action.Subtitle)) @@ -74,13 +91,13 @@ internal static ShortcutInfo ToShortcutInfo(this AppAction action) if (!string.IsNullOrWhiteSpace(action.Icon)) { - var iconResId = Platform.AppContext.Resources.GetIdentifier(action.Icon, "drawable", Platform.AppContext.PackageName); + var iconResId = context.Resources.GetIdentifier(action.Icon, "drawable", context.PackageName); - shortcut.SetIcon(Icon.CreateWithResource(Platform.AppContext, iconResId)); + shortcut.SetIcon(Icon.CreateWithResource(context, iconResId)); } - var intent = new Intent(Platform.Intent.ActionAppAction); - intent.SetPackage(Platform.AppContext.PackageName); + var intent = new Intent(AppActionsImplementation.IntentAction); + intent.SetPackage(context.PackageName); intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop); intent.PutExtra(extraAppActionId, action.Id); intent.PutExtra(extraAppActionTitle, action.Title); @@ -91,5 +108,5 @@ internal static ShortcutInfo ToShortcutInfo(this AppAction action) return shortcut.Build(); } - } + } } diff --git a/src/Essentials/src/AppActions/AppActions.ios.cs b/src/Essentials/src/AppActions/AppActions.ios.cs index 7930faff9cea..9eb640b5e758 100755 --- a/src/Essentials/src/AppActions/AppActions.ios.cs +++ b/src/Essentials/src/AppActions/AppActions.ios.cs @@ -1,18 +1,17 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Foundation; -using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class AppActionsImplementation : IAppActions + partial class AppActionsImplementation : IAppActions, IPlatformAppActions { - public string Type => "XE_APP_ACTION_TYPE"; + public const string ShortcutType = "XE_APP_ACTION_TYPE"; - public bool IsSupported - => true; + public bool IsSupported => true; public Task> GetAsync() { @@ -32,13 +31,20 @@ public Task SetAsync(IEnumerable actions) return Task.CompletedTask; } - public Task SetAsync(params AppAction[] actions) - { - return SetAsync(actions.AsEnumerable()); + public event EventHandler AppActionActivated; + + public void PerformActionForShortcutItem(UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler) + { + if (shortcutItem.Type == ShortcutType) + { + var appAction = shortcutItem.ToAppAction(); + + AppActionActivated?.Invoke(null, new AppActionEventArgs(appAction)); + } } } - internal static partial class AppActionsExtensions + static partial class AppActionsExtensions { internal static AppAction ToAppAction(this UIApplicationShortcutItem shortcutItem) { @@ -70,12 +76,11 @@ internal static UIApplicationShortcutItem ToShortcutItem(this AppAction action) } return new UIApplicationShortcutItem( - action.Type, + AppActionsImplementation.ShortcutType, action.Title, action.Subtitle, action.Icon != null ? UIApplicationShortcutIcon.FromTemplateImageName(action.Icon) : null, new NSDictionary(keys.ToArray(), values.ToArray())); } - } } diff --git a/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs b/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs index 31cf550ad0df..47a253b1a1d0 100755 --- a/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs +++ b/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs @@ -2,14 +2,13 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { /// - public partial class AppActionsImplementation : IAppActions + partial class AppActionsImplementation : IAppActions { - public string Type => "XE_APP_ACTION_TYPE"; - public bool IsSupported - => throw ExceptionUtils.NotSupportedOrImplementedException; + public bool IsSupported => + throw ExceptionUtils.NotSupportedOrImplementedException; public Task> GetAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; @@ -17,7 +16,6 @@ public Task> GetAsync() => public Task SetAsync(IEnumerable actions) => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task SetAsync(params AppAction[] actions) => - throw ExceptionUtils.NotSupportedOrImplementedException; + public event EventHandler AppActionActivated; } } diff --git a/src/Essentials/src/AppActions/AppActions.shared.cs b/src/Essentials/src/AppActions/AppActions.shared.cs index 8b6ea38d8117..99076fd7ab5f 100755 --- a/src/Essentials/src/AppActions/AppActions.shared.cs +++ b/src/Essentials/src/AppActions/AppActions.shared.cs @@ -1,8 +1,9 @@ +#nullable enable using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel.Implementations; +using Microsoft.UI.Xaml; namespace Microsoft.Maui.ApplicationModel { @@ -10,53 +11,33 @@ public interface IAppActions { bool IsSupported { get; } - string Type { get; } + Task> GetAsync(); - Task> GetAsync (); - Task SetAsync (IEnumerable actions); + Task SetAsync(IEnumerable actions); - Task SetAsync (params AppAction[] actions); + event EventHandler? AppActionActivated; } - /// - public static partial class AppActions + public interface IPlatformAppActions { - internal static bool IsSupported - => Current.IsSupported; - - internal static string Type - => Current.Type; - - /// - public static Task> GetAsync() - => Current.GetAsync(); - - /// - public static Task SetAsync(params AppAction[] actions) - => Current.SetAsync(actions); - - /// - public static Task SetAsync(IEnumerable actions) - => Current.SetAsync(actions); - - public static event EventHandler OnAppAction; - - internal static void InvokeOnAppAction(object sender, AppAction appAction) - => OnAppAction?.Invoke(sender, new AppActionEventArgs(appAction)); +#if WINDOWS + Task OnLaunched(LaunchActivatedEventArgs e); +#elif IOS || MACCATALYST + void PerformActionForShortcutItem(UIKit.UIApplication application, UIKit.UIApplicationShortcutItem shortcutItem, UIKit.UIOperationHandler completionHandler); +#elif ANDROID + void OnNewIntent(Android.Content.Intent? intent); +#endif + } -#nullable enable + public static class AppActions + { static IAppActions? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IAppActions Current => currentImplementation ??= new AppActionsImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IAppActions? implementation) => + internal static void SetCurrent(IAppActions? implementation) => currentImplementation = implementation; -#nullable disable } /// @@ -74,7 +55,7 @@ public AppActionEventArgs(AppAction appAction) public class AppAction { /// - public AppAction(string id, string title, string subtitle = null, string icon = null) + public AppAction(string id, string title, string? subtitle = null, string? icon = null) { Id = id ?? throw new ArgumentNullException(nameof(id)); Title = title ?? throw new ArgumentNullException(nameof(title)); @@ -82,18 +63,16 @@ public AppAction(string id, string title, string subtitle = null, string icon = Subtitle = subtitle; Icon = icon; } - public string Type => "XE_APP_ACTION_TYPE"; /// public string Title { get; set; } /// - public string Subtitle { get; set; } + public string? Subtitle { get; set; } /// public string Id { get; set; } - internal string Icon { get; set; } - + internal string? Icon { get; set; } } } diff --git a/src/Essentials/src/AppActions/AppActions.uwp.cs b/src/Essentials/src/AppActions/AppActions.uwp.cs index e8fb8c292207..2fe5f816c20a 100755 --- a/src/Essentials/src/AppActions/AppActions.uwp.cs +++ b/src/Essentials/src/AppActions/AppActions.uwp.cs @@ -4,58 +4,13 @@ using System.Text; using System.Threading.Tasks; using Windows.UI.StartScreen; - -#if WINDOWS_UWP -using Windows.ApplicationModel.Activation; -#elif WINDOWS using Microsoft.UI.Xaml; -#endif namespace Microsoft.Maui.ApplicationModel { - public static partial class AppActions - { - public static string IconDirectory { get; set; } = ""; - - public static string IconExtension { get; set; } = "png"; - - internal static async Task OnLaunched(LaunchActivatedEventArgs e) - { - var args = e?.Arguments; -#if !WINDOWS_UWP - if (string.IsNullOrEmpty(args)) - { - var cliArgs = Environment.GetCommandLineArgs(); - if (cliArgs?.Length > 1) - args = cliArgs[1]; - } -#endif - - if (args?.StartsWith(Implementations.AppActionsExtensions.AppActionPrefix) ?? false) - { - var id = Implementations.AppActionsExtensions.ArgumentsToId(args); - - if (!string.IsNullOrEmpty(id)) - { - var actions = await AppActions.GetAsync(); - var appAction = actions.FirstOrDefault(a => a.Id == id); - - if (appAction != null) - InvokeOnAppAction(null, appAction); - } - } - } - } -} - -namespace Microsoft.Maui.ApplicationModel.Implementations -{ - public class AppActionsImplementation : IAppActions + class AppActionsImplementation : IAppActions, IPlatformAppActions { - public string Type => "XE_APP_ACTION_TYPE"; - - public bool IsSupported - => true; + public bool IsSupported => true; public async Task> GetAsync() { @@ -88,13 +43,37 @@ public async Task SetAsync(IEnumerable actions) await jumpList.SaveAsync(); } - public Task SetAsync(params AppAction[] actions) - { - return SetAsync(actions.AsEnumerable()); + public event EventHandler AppActionActivated; + + public async Task OnLaunched(LaunchActivatedEventArgs e) + { + var args = e?.Arguments; +#if !WINDOWS_UWP + if (string.IsNullOrEmpty(args)) + { + var cliArgs = Environment.GetCommandLineArgs(); + if (cliArgs?.Length > 1) + args = cliArgs[1]; + } +#endif + + if (args?.StartsWith(AppActionsExtensions.AppActionPrefix) ?? false) + { + var id = AppActionsExtensions.ArgumentsToId(args); + + if (!string.IsNullOrEmpty(id)) + { + var actions = await GetAsync(); + var appAction = actions.FirstOrDefault(a => a.Id == id); + + if (appAction != null) + AppActionActivated?.Invoke(null, new AppActionEventArgs(appAction)); + } + } } } - internal static class AppActionsExtensions + static partial class AppActionsExtensions { internal const string AppActionPrefix = "XE_APP_ACTIONS-"; @@ -119,11 +98,11 @@ internal static JumpListItem ToJumpListItem(this AppAction action) if (!string.IsNullOrEmpty(action.Icon)) { - var dir = AppActions.IconDirectory.Trim('/', '\\').Replace('\\', '/'); + var dir = iconDirectory?.Trim('/', '\\').Replace('\\', '/'); if (!string.IsNullOrEmpty(dir)) dir += "/"; - var ext = AppActions.IconExtension; + var ext = iconExtension; if (!string.IsNullOrEmpty(ext) && !ext.StartsWith(".")) ext = "." + ext; diff --git a/src/Essentials/src/AppInfo/AppInfo.android.cs b/src/Essentials/src/AppInfo/AppInfo.android.cs index 0cdf2fcbb40e..61159189a981 100644 --- a/src/Essentials/src/AppInfo/AppInfo.android.cs +++ b/src/Essentials/src/AppInfo/AppInfo.android.cs @@ -5,11 +5,10 @@ using Android.Content.Res; using Android.Provider; using AndroidX.Core.Content.PM; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class AppInfoImplementation : IAppInfo + class AppInfoImplementation : IAppInfo { public string PackageName => Platform.AppContext.PackageName; diff --git a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs index 85a21716c463..d658ca979eb9 100644 --- a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using Foundation; -using Microsoft.Maui.Essentials; #if __IOS__ || __TVOS__ using ObjCRuntime; using UIKit; @@ -10,9 +9,9 @@ using AppKit; #endif -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class AppInfoImplementation : IAppInfo + class AppInfoImplementation : IAppInfo { public AppPackagingModel PackagingModel => AppPackagingModel.Packaged; diff --git a/src/Essentials/src/AppInfo/AppInfo.netstandard.cs b/src/Essentials/src/AppInfo/AppInfo.netstandard.cs index 8d36ebb5f816..8b2caef63399 100644 --- a/src/Essentials/src/AppInfo/AppInfo.netstandard.cs +++ b/src/Essentials/src/AppInfo/AppInfo.netstandard.cs @@ -1,7 +1,7 @@ -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { /// - public class AppInfoImplementation : IAppInfo + class AppInfoImplementation : IAppInfo { public string PackageName => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/AppInfo/AppInfo.shared.cs b/src/Essentials/src/AppInfo/AppInfo.shared.cs index 9a83e4352158..dc7f6a587d3d 100644 --- a/src/Essentials/src/AppInfo/AppInfo.shared.cs +++ b/src/Essentials/src/AppInfo/AppInfo.shared.cs @@ -1,7 +1,5 @@ #nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel.Implementations; namespace Microsoft.Maui.ApplicationModel { @@ -26,42 +24,14 @@ public interface IAppInfo LayoutDirection RequestedLayoutDirection { get; } } - /// public static class AppInfo { - /// - public static string PackageName => Current.PackageName; - - /// - public static string Name => Current.Name; - - /// - public static string VersionString => Current.VersionString; - - /// - public static Version Version => Current.Version; - - /// - public static string BuildString => Current.BuildString; - - /// - public static void ShowSettingsUI() => Current.ShowSettingsUI(); - - /// - public static AppTheme RequestedTheme => Current.RequestedTheme; - - public static AppPackagingModel PackagingModel => Current.PackagingModel; - - public static LayoutDirection RequestedLayoutDirection => Current.RequestedLayoutDirection; - static IAppInfo? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IAppInfo Current => currentImplementation ??= new AppInfoImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IAppInfo? implementation) => + internal static void SetCurrent(IAppInfo? implementation) => currentImplementation = implementation; } diff --git a/src/Essentials/src/AppInfo/AppInfo.tizen.cs b/src/Essentials/src/AppInfo/AppInfo.tizen.cs index a31091baadbb..c0d8f0595259 100644 --- a/src/Essentials/src/AppInfo/AppInfo.tizen.cs +++ b/src/Essentials/src/AppInfo/AppInfo.tizen.cs @@ -1,9 +1,9 @@ using System.Globalization; using Tizen.Applications; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class AppInfoImplementation + class AppInfoImplementation { public string PackageName => Application.Current.ApplicationInfo.PackageId; diff --git a/src/Essentials/src/AppInfo/AppInfo.uwp.cs b/src/Essentials/src/AppInfo/AppInfo.uwp.cs index 65b672b2d85d..b294cc158294 100644 --- a/src/Essentials/src/AppInfo/AppInfo.uwp.cs +++ b/src/Essentials/src/AppInfo/AppInfo.uwp.cs @@ -7,9 +7,9 @@ using Windows.UI.Xaml; #endif -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class AppInfoImplementation : IAppInfo + class AppInfoImplementation : IAppInfo { static Lazy _isPackagedAppLazy = new Lazy(() => { diff --git a/src/Essentials/src/Barometer/Barometer.android.cs b/src/Essentials/src/Barometer/Barometer.android.cs index cf3b2b379635..c2aa761a8c00 100644 --- a/src/Essentials/src/Barometer/Barometer.android.cs +++ b/src/Essentials/src/Barometer/Barometer.android.cs @@ -1,11 +1,10 @@ using System; using Android.Hardware; using Android.Runtime; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class BarometerImplementation : IBarometer + partial class BarometerImplementation : IBarometer { Sensor DefaultBarometer => Platform.SensorManager?.GetDefaultSensor(SensorType.Pressure); diff --git a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs index 15a32c611347..c8c772ee2ec9 100644 --- a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs +++ b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs @@ -1,11 +1,10 @@ using System; using CoreMotion; using Foundation; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class BarometerImplementation : IBarometer + partial class BarometerImplementation : IBarometer { CMAltimeter altitudeManager; diff --git a/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs b/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs index 6774194fa4e0..1a7ce57834aa 100644 --- a/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs @@ -1,8 +1,8 @@ using System; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class BarometerImplementation : IBarometer + partial class BarometerImplementation : IBarometer { void PlatformStart(SensorSpeed sensorSpeed) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Barometer/Barometer.shared.cs b/src/Essentials/src/Barometer/Barometer.shared.cs index 60acee498924..95bfccd58222 100644 --- a/src/Essentials/src/Barometer/Barometer.shared.cs +++ b/src/Essentials/src/Barometer/Barometer.shared.cs @@ -1,7 +1,8 @@ +#nullable enable using System; using System.ComponentModel; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Devices.Sensors.Implementations; +using Microsoft.Maui.Devices.Sensors; namespace Microsoft.Maui.Devices.Sensors { @@ -15,47 +16,20 @@ public interface IBarometer void Start(SensorSpeed sensorSpeed); - event EventHandler ReadingChanged; + event EventHandler? ReadingChanged; void Stop(); } - /// public static class Barometer { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - public static bool IsSupported => Current.IsSupported; - - /// - public static bool IsMonitoring - => Current.IsMonitoring; - - /// - public static void Start(SensorSpeed sensorSpeed) - => Current.Start(sensorSpeed); + static IBarometer? defaultImplementation; - /// - public static void Stop() - => Current.Stop(); + public static IBarometer Default => + defaultImplementation ??= new BarometerImplementation(); -#nullable enable - static IBarometer? currentImplementation; -#nullable disable - - [EditorBrowsable(EditorBrowsableState.Never)] - public static IBarometer Current => - currentImplementation ??= new BarometerImplementation(); - - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IBarometer? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IBarometer? implementation) => + defaultImplementation = implementation; } /// @@ -100,11 +74,8 @@ public override int GetHashCode() => /// public override string ToString() => $"{nameof(PressureInHectopascals)}: {PressureInHectopascals}"; } -} -namespace Microsoft.Maui.Devices.Sensors.Implementations -{ - public partial class BarometerImplementation : IBarometer + partial class BarometerImplementation : IBarometer { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; diff --git a/src/Essentials/src/Barometer/Barometer.tizen.cs b/src/Essentials/src/Barometer/Barometer.tizen.cs index 83e071a334c5..dfbc29993fb2 100644 --- a/src/Essentials/src/Barometer/Barometer.tizen.cs +++ b/src/Essentials/src/Barometer/Barometer.tizen.cs @@ -2,9 +2,9 @@ using Tizen.Sensor; using TizenBarometerSensor = Tizen.Sensor.PressureSensor; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public class BarometerImplementation : IBarometer + class BarometerImplementation : IBarometer { bool PlatformIsSupported => TizenBarometerSensor.IsSupported; diff --git a/src/Essentials/src/Barometer/Barometer.uwp.cs b/src/Essentials/src/Barometer/Barometer.uwp.cs index 08b5d38992cb..7b77c67fcc43 100644 --- a/src/Essentials/src/Barometer/Barometer.uwp.cs +++ b/src/Essentials/src/Barometer/Barometer.uwp.cs @@ -2,9 +2,9 @@ using Windows.Devices.Sensors; using WinBarometer = Windows.Devices.Sensors.Barometer; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class BarometerImplementation : IBarometer + partial class BarometerImplementation : IBarometer { WinBarometer sensor; diff --git a/src/Essentials/src/Battery/Battery.android.cs b/src/Essentials/src/Battery/Battery.android.cs index 7a1f02a69cb6..f9cc6f23d1db 100755 --- a/src/Essentials/src/Battery/Battery.android.cs +++ b/src/Essentials/src/Battery/Battery.android.cs @@ -2,22 +2,21 @@ using Android.Content; using Android.OS; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class BatteryImplementation : IBattery + partial class BatteryImplementation : IBattery { BatteryBroadcastReceiver batteryReceiver; EnergySaverBroadcastReceiver powerReceiver; - public void StartEnergySaverListeners() + void StartEnergySaverListeners() { - powerReceiver = new EnergySaverBroadcastReceiver(Battery.OnEnergySaverChanged); + powerReceiver = new EnergySaverBroadcastReceiver(OnEnergySaverChanged); Platform.AppContext.RegisterReceiver(powerReceiver, new IntentFilter(PowerManager.ActionPowerSaveModeChanged)); } - public void StopEnergySaverListeners() + void StopEnergySaverListeners() { try { @@ -40,15 +39,15 @@ public EnergySaverStatus EnergySaverStatus } } - public void StartBatteryListeners() + void StartBatteryListeners() { Permissions.EnsureDeclared(); - batteryReceiver = new BatteryBroadcastReceiver(Battery.OnBatteryInfoChanged); + batteryReceiver = new BatteryBroadcastReceiver(OnBatteryInfoChanged); Platform.AppContext.RegisterReceiver(batteryReceiver, new IntentFilter(Intent.ActionBatteryChanged)); } - public void StopBatteryListeners() + void StopBatteryListeners() { try { diff --git a/src/Essentials/src/Battery/Battery.ios.watchos.cs b/src/Essentials/src/Battery/Battery.ios.watchos.cs index 50bffd2e364e..d189919061b1 100755 --- a/src/Essentials/src/Battery/Battery.ios.watchos.cs +++ b/src/Essentials/src/Battery/Battery.ios.watchos.cs @@ -8,9 +8,9 @@ using UIDeviceBatteryState = WatchKit.WKInterfaceDeviceBatteryState; #endif -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class BatteryImplementation : IBattery + partial class BatteryImplementation : IBattery { #if !__WATCHOS__ NSObject levelObserver; @@ -19,27 +19,27 @@ public partial class BatteryImplementation : IBattery NSObject saverStatusObserver; - public void StartEnergySaverListeners() + void StartEnergySaverListeners() { saverStatusObserver = NSNotificationCenter.DefaultCenter.AddObserver(NSProcessInfo.PowerStateDidChangeNotification, PowerChangedNotification); } - public void StopEnergySaverListeners() + void StopEnergySaverListeners() { saverStatusObserver?.Dispose(); saverStatusObserver = null; } void PowerChangedNotification(NSNotification notification) - => MainThread.BeginInvokeOnMainThread(Battery.OnEnergySaverChanged); + => MainThread.BeginInvokeOnMainThread(OnEnergySaverChanged); public EnergySaverStatus EnergySaverStatus => NSProcessInfo.ProcessInfo?.LowPowerModeEnabled == true ? EnergySaverStatus.On : EnergySaverStatus.Off; - public void StartBatteryListeners() + void StartBatteryListeners() { #if __WATCHOS__ - throw new FeatureNotSupportedException(); + throw new FeatureNotSupportedException(); #else UIDevice.CurrentDevice.BatteryMonitoringEnabled = true; levelObserver = UIDevice.Notifications.ObserveBatteryLevelDidChange(BatteryInfoChangedNotification); @@ -47,10 +47,10 @@ public void StartBatteryListeners() #endif } - public void StopBatteryListeners() + void StopBatteryListeners() { #if __WATCHOS__ - throw new FeatureNotSupportedException(); + throw new FeatureNotSupportedException(); #else UIDevice.CurrentDevice.BatteryMonitoringEnabled = false; levelObserver?.Dispose(); @@ -61,7 +61,7 @@ public void StopBatteryListeners() } void BatteryInfoChangedNotification(object sender, NSNotificationEventArgs args) - => MainThread.BeginInvokeOnMainThread(Battery.OnBatteryInfoChanged); + => MainThread.BeginInvokeOnMainThread(OnBatteryInfoChanged); public double ChargeLevel { diff --git a/src/Essentials/src/Battery/Battery.macos.cs b/src/Essentials/src/Battery/Battery.macos.cs index 4dc8fcbc9914..9b7ae837897c 100755 --- a/src/Essentials/src/Battery/Battery.macos.cs +++ b/src/Essentials/src/Battery/Battery.macos.cs @@ -1,19 +1,19 @@ using System; using CoreFoundation; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class BatteryImplementation : IBattery + partial class BatteryImplementation : IBattery { CFRunLoopSource powerSourceNotification; - public void StartBatteryListeners() + void StartBatteryListeners() { powerSourceNotification = IOKit.CreatePowerSourceNotification(PowerSourceNotification); CFRunLoop.Current.AddSource(powerSourceNotification, CFRunLoop.ModeDefault); } - public void StopBatteryListeners() + void StopBatteryListeners() { if (powerSourceNotification != null) { @@ -31,11 +31,11 @@ public void PowerSourceNotification() public BatteryPowerSource PowerSource => IOKit.GetProvidingPowerSource(); - public void StartEnergySaverListeners() + void StartEnergySaverListeners() { } - public void StopEnergySaverListeners() + void StopEnergySaverListeners() { } diff --git a/src/Essentials/src/Battery/Battery.netstandard.tvos.cs b/src/Essentials/src/Battery/Battery.netstandard.tvos.cs index 6820dea276b1..185dc3f118ef 100755 --- a/src/Essentials/src/Battery/Battery.netstandard.tvos.cs +++ b/src/Essentials/src/Battery/Battery.netstandard.tvos.cs @@ -1,12 +1,12 @@ -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { /// - public partial class BatteryImplementation : IBattery + partial class BatteryImplementation : IBattery { - public void StartBatteryListeners() => + void StartBatteryListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; - public void StopBatteryListeners() => + void StopBatteryListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; public double ChargeLevel => @@ -18,10 +18,10 @@ public void StopBatteryListeners() => public BatteryPowerSource PowerSource => throw ExceptionUtils.NotSupportedOrImplementedException; - public void StartEnergySaverListeners() => + void StartEnergySaverListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; - public void StopEnergySaverListeners() => + void StopEnergySaverListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; public EnergySaverStatus EnergySaverStatus => diff --git a/src/Essentials/src/Battery/Battery.shared.cs b/src/Essentials/src/Battery/Battery.shared.cs index 1fbbc2c46dfc..b6368db31165 100755 --- a/src/Essentials/src/Battery/Battery.shared.cs +++ b/src/Essentials/src/Battery/Battery.shared.cs @@ -1,6 +1,5 @@ +#nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.Devices.Implementations; namespace Microsoft.Maui.Devices { @@ -14,89 +13,66 @@ public interface IBattery EnergySaverStatus EnergySaverStatus { get; } - void StartEnergySaverListeners(); - - void StopEnergySaverListeners(); - - void StartBatteryListeners(); + event EventHandler BatteryInfoChanged; - void StopBatteryListeners(); + event EventHandler EnergySaverStatusChanged; } - /// - public static partial class Battery + public static class Battery { - static event EventHandler BatteryInfoChangedInternal; + static IBattery? defaultImplementation; - static event EventHandler EnergySaverStatusChangedInternal; - - // a cache so that events aren't fired unnecessarily - // this is mainly an issue on Android, but we can stiil do this everywhere - static double currentLevel; - static BatteryPowerSource currentSource; - static BatteryState currentState; + public static IBattery Default => + defaultImplementation ??= new BatteryImplementation(); - /// - public static double ChargeLevel => Current.ChargeLevel; - - /// - public static BatteryState State => Current.State; + internal static void SetDefault(IBattery? implementation) => + defaultImplementation = implementation; + } - /// - public static BatteryPowerSource PowerSource => Current.PowerSource; + partial class BatteryImplementation : IBattery + { + event EventHandler? BatteryInfoChangedInternal; - /// - public static EnergySaverStatus EnergySaverStatus => Current.EnergySaverStatus; + event EventHandler? EnergySaverStatusChangedInternal; - public static event EventHandler BatteryInfoChanged + public event EventHandler BatteryInfoChanged { add { - var wasRunning = BatteryInfoChangedInternal != null; - + if (BatteryInfoChangedInternal == null) + StartBatteryListeners(); BatteryInfoChangedInternal += value; - - if (!wasRunning && BatteryInfoChangedInternal != null) - { - SetCurrent(); - Current.StartBatteryListeners(); - } } - remove { - var wasRunning = BatteryInfoChangedInternal != null; - BatteryInfoChangedInternal -= value; - - if (wasRunning && BatteryInfoChangedInternal == null) - Current.StopBatteryListeners(); + if (BatteryInfoChangedInternal == null) + StopBatteryListeners(); } } - public static event EventHandler EnergySaverStatusChanged + public event EventHandler EnergySaverStatusChanged { add { - var wasRunning = EnergySaverStatusChangedInternal != null; - + if (EnergySaverStatusChangedInternal == null) + StartEnergySaverListeners(); EnergySaverStatusChangedInternal += value; - - if (!wasRunning && EnergySaverStatusChangedInternal != null) - Current.StartEnergySaverListeners(); } - remove { - var wasRunning = EnergySaverStatusChangedInternal != null; - EnergySaverStatusChangedInternal -= value; - - if (wasRunning && EnergySaverStatusChangedInternal == null) - Current.StopEnergySaverListeners(); + if (EnergySaverStatusChangedInternal == null) + StopEnergySaverListeners(); } } + // a cache so that events aren't fired unnecessarily + // this is mainly an issue on Android, but we can stiil do this everywhere + static double currentLevel; + static BatteryPowerSource currentSource; + static BatteryState currentState; + static void SetCurrent() { currentLevel = Battery.ChargeLevel; @@ -104,13 +80,13 @@ static void SetCurrent() currentState = Battery.State; } - internal static void OnBatteryInfoChanged(double level, BatteryState state, BatteryPowerSource source) + static void OnBatteryInfoChanged(double level, BatteryState state, BatteryPowerSource source) => OnBatteryInfoChanged(new BatteryInfoChangedEventArgs(level, state, source)); - internal static void OnBatteryInfoChanged() + static void OnBatteryInfoChanged() => OnBatteryInfoChanged(ChargeLevel, State, PowerSource); - internal static void OnBatteryInfoChanged(BatteryInfoChangedEventArgs e) + static void OnBatteryInfoChanged(BatteryInfoChangedEventArgs e) { if (currentLevel != e.ChargeLevel || currentSource != e.PowerSource || currentState != e.State) { @@ -119,29 +95,14 @@ internal static void OnBatteryInfoChanged(BatteryInfoChangedEventArgs e) } } - internal static void OnEnergySaverChanged() + static void OnEnergySaverChanged() => OnEnergySaverChanged(EnergySaverStatus); - internal static void OnEnergySaverChanged(EnergySaverStatus saverStatus) + static void OnEnergySaverChanged(EnergySaverStatus saverStatus) => OnEnergySaverChanged(new EnergySaverStatusChangedEventArgs(saverStatus)); - internal static void OnEnergySaverChanged(EnergySaverStatusChangedEventArgs e) + static void OnEnergySaverChanged(EnergySaverStatusChangedEventArgs e) => EnergySaverStatusChangedInternal?.Invoke(null, e); - - -#nullable enable - static IBattery? currentImplementation; -#nullable disable - - [EditorBrowsable(EditorBrowsableState.Never)] - public static IBattery Current => - currentImplementation ??= new BatteryImplementation(); - - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IBattery? implementation) => - currentImplementation = implementation; -#nullable disable } /// diff --git a/src/Essentials/src/Battery/Battery.tizen.cs b/src/Essentials/src/Battery/Battery.tizen.cs index 4e3cff415c28..64db5ca6c53f 100755 --- a/src/Essentials/src/Battery/Battery.tizen.cs +++ b/src/Essentials/src/Battery/Battery.tizen.cs @@ -1,9 +1,9 @@ using System; using TizenBattery = Tizen.System.Battery; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class BatteryImplementation : IBattery + partial class BatteryImplementation : IBattery { void OnChanged(object sender, object e) => MainThread.BeginInvokeOnMainThread(OnBatteryInfoChanged); diff --git a/src/Essentials/src/Battery/Battery.uwp.cs b/src/Essentials/src/Battery/Battery.uwp.cs index f9d4840361c0..fae013c04039 100755 --- a/src/Essentials/src/Battery/Battery.uwp.cs +++ b/src/Essentials/src/Battery/Battery.uwp.cs @@ -1,9 +1,9 @@ using Microsoft.Maui.ApplicationModel; using Windows.System.Power; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class BatteryImplementation : IBattery + partial class BatteryImplementation : IBattery { public void StartEnergySaverListeners() => PowerManager.EnergySaverStatusChanged += ReportEnergySaverUpdated; diff --git a/src/Essentials/src/Browser/Browser.android.cs b/src/Essentials/src/Browser/Browser.android.cs index 53b56a0021a0..d41ebcf96fbf 100755 --- a/src/Essentials/src/Browser/Browser.android.cs +++ b/src/Essentials/src/Browser/Browser.android.cs @@ -1,13 +1,14 @@ +#nullable enable using System; using System.Threading.Tasks; +using Android.App; using Android.Content; using AndroidX.Browser.CustomTabs; -using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class BrowserImplementation : IBrowser + partial class BrowserImplementation : IBrowser { public Task OpenAsync(Uri uri, BrowserLaunchOptions options) { @@ -16,123 +17,78 @@ public Task OpenAsync(Uri uri, BrowserLaunchOptions options) switch (options.LaunchMode) { case BrowserLaunchMode.SystemPreferred: - var tabsBuilder = new CustomTabsIntent.Builder(); - tabsBuilder.SetShowTitle(true); - if (options.PreferredToolbarColor != null) + LaunchChromeTabs(options, nativeUri); + break; + case BrowserLaunchMode.External: + LaunchExternalBrowser(options, nativeUri); + break; + } + + return Task.FromResult(true); + } + + static void LaunchChromeTabs(BrowserLaunchOptions options, AndroidUri? nativeUri) + { + var tabsBuilder = new CustomTabsIntent.Builder(); + tabsBuilder.SetShowTitle(true); #pragma warning disable CS0618 // Type or member is obsolete - tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.ToInt()); + if (options.PreferredToolbarColor != null) + tabsBuilder.SetToolbarColor(options.PreferredToolbarColor.ToInt()); #pragma warning restore CS0618 // Type or member is obsolete - if (options.TitleMode != BrowserTitleMode.Default) - tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show); + if (options.TitleMode != BrowserTitleMode.Default) + tabsBuilder.SetShowTitle(options.TitleMode == BrowserTitleMode.Show); - var tabsIntent = tabsBuilder.Build(); - ActivityFlags? tabsFlags = null; + var tabsIntent = tabsBuilder.Build(); + ActivityFlags? tabsFlags = null; - Context context = Platform.GetCurrentActivity(false); + Context context = Platform.GetCurrentActivity(false); - if (context == null) - { - context = Platform.AppContext; + if (context == null) + { + context = Application.Context; - // If using ApplicationContext we need to set ClearTop/NewTask (See #225) - tabsFlags = ActivityFlags.ClearTop | ActivityFlags.NewTask; - } + // If using ApplicationContext we need to set ClearTop/NewTask (See #225) + tabsFlags = ActivityFlags.ClearTop | ActivityFlags.NewTask; + } #if __ANDROID_24__ - if (Platform.HasApiLevelN && options.HasFlag(BrowserLaunchFlags.LaunchAdjacent)) - { - if (tabsFlags.HasValue) - tabsFlags |= ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; - else - tabsFlags = ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; - } -#endif - - // Check if there's flags specified to use + if (OperatingSystem.IsAndroidVersionAtLeast(24)) + { + if (options.HasFlag(BrowserLaunchFlags.LaunchAdjacent)) + { if (tabsFlags.HasValue) - tabsIntent.Intent.SetFlags(tabsFlags.Value); - - tabsIntent.LaunchUrl(context, nativeUri); - - break; - case BrowserLaunchMode.External: - var intent = new Intent(Intent.ActionView, nativeUri); - var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; -#if __ANDROID_24__ - if (Platform.HasApiLevelN && options.HasFlag(BrowserLaunchFlags.LaunchAdjacent)) - flags |= ActivityFlags.LaunchAdjacent; + tabsFlags |= ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; + else + tabsFlags = ActivityFlags.LaunchAdjacent | ActivityFlags.NewTask; + } + } #endif - intent.SetFlags(flags); - - if (!Platform.IsIntentSupported(intent)) - throw new FeatureNotSupportedException(); - Platform.AppContext.StartActivity(intent); - break; - } + // Check if there's flags specified to use + if (tabsFlags.HasValue) + tabsIntent.Intent.SetFlags(tabsFlags.Value); - return Task.FromResult(true); + tabsIntent.LaunchUrl(context, nativeUri); } - public Task OpenAsync(string uri) + static void LaunchExternalBrowser(BrowserLaunchOptions options, AndroidUri? nativeUri) { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } + var intent = new Intent(Intent.ActionView, nativeUri); + var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; - public Task OpenAsync(string uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchOptions options) - { - return OpenAsync(new Uri(uri), options); - } +#if __ANDROID_24__ + if (OperatingSystem.IsAndroidVersionAtLeast(24)) + { + if (options.HasFlag(BrowserLaunchFlags.LaunchAdjacent)) + flags |= ActivityFlags.LaunchAdjacent; + } +#endif + intent.SetFlags(flags); - public Task OpenAsync(Uri uri) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } + if (!Platform.IsIntentSupported(intent)) + throw new FeatureNotSupportedException(); - public Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); + Application.Context.StartActivity(intent); } } } diff --git a/src/Essentials/src/Browser/Browser.ios.cs b/src/Essentials/src/Browser/Browser.ios.cs index 92271fb709a1..647605e87a1d 100755 --- a/src/Essentials/src/Browser/Browser.ios.cs +++ b/src/Essentials/src/Browser/Browser.ios.cs @@ -1,40 +1,22 @@ +#nullable enable using System; using System.Threading.Tasks; using Foundation; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Graphics.Platform; using ObjCRuntime; using SafariServices; using UIKit; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class BrowserImplementation : IBrowser + partial class BrowserImplementation : IBrowser { public async Task OpenAsync(Uri uri, BrowserLaunchOptions options) { switch (options.LaunchMode) { case BrowserLaunchMode.SystemPreferred: - var nativeUrl = new NSUrl(uri.AbsoluteUri); - var sfViewController = new SFSafariViewController(nativeUrl, false); - var vc = Platform.GetCurrentViewController(); - - if (options.PreferredToolbarColor != null) - sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.AsUIColor(); - - if (options.PreferredControlColor != null) - sfViewController.PreferredControlTintColor = options.PreferredControlColor.AsUIColor(); - - if (sfViewController.PopoverPresentationController != null) - sfViewController.PopoverPresentationController.SourceView = vc.View; - - if (options.HasFlag(BrowserLaunchFlags.PresentAsFormSheet)) - sfViewController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; - else if (options.HasFlag(BrowserLaunchFlags.PresentAsPageSheet)) - sfViewController.ModalPresentationStyle = UIModalPresentationStyle.PageSheet; - - await vc.PresentViewControllerAsync(sfViewController, true); + await LaunchSafariViewController(uri, options); break; case BrowserLaunchMode.External: return await Launcher.OpenAsync(uri); @@ -43,65 +25,27 @@ public async Task OpenAsync(Uri uri, BrowserLaunchOptions options) return true; } - public Task OpenAsync(string uri) + private static async Task LaunchSafariViewController(Uri uri, BrowserLaunchOptions options) { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } + var nativeUrl = new NSUrl(uri.AbsoluteUri); + var sfViewController = new SFSafariViewController(nativeUrl, false); + var vc = Platform.GetCurrentViewController(); - public Task OpenAsync(string uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchOptions options) - { - return OpenAsync(new Uri(uri), options); - } + if (options.PreferredToolbarColor != null) + sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.AsUIColor(); - public Task OpenAsync(Uri uri) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } + if (options.PreferredControlColor != null) + sfViewController.PreferredControlTintColor = options.PreferredControlColor.AsUIColor(); - public Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); + if (sfViewController.PopoverPresentationController != null) + sfViewController.PopoverPresentationController.SourceView = vc.View; + + if (options.HasFlag(BrowserLaunchFlags.PresentAsFormSheet)) + sfViewController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; + else if (options.HasFlag(BrowserLaunchFlags.PresentAsPageSheet)) + sfViewController.ModalPresentationStyle = UIModalPresentationStyle.PageSheet; + + await vc.PresentViewControllerAsync(sfViewController, true); } } } diff --git a/src/Essentials/src/Browser/Browser.macos.cs b/src/Essentials/src/Browser/Browser.macos.cs index 0fccc43e30b9..18121cc912b3 100755 --- a/src/Essentials/src/Browser/Browser.macos.cs +++ b/src/Essentials/src/Browser/Browser.macos.cs @@ -1,74 +1,14 @@ +#nullable enable using System; using System.Threading.Tasks; using AppKit; using Foundation; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class BrowserImplementation : IBrowser + partial class BrowserImplementation : IBrowser { static Task OpenAsync(Uri uri, BrowserLaunchOptions options) => Task.FromResult(NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(uri.AbsoluteUri))); - - public Task OpenAsync(string uri) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchOptions options) - { - return OpenAsync(new Uri(uri), options); - } - - public Task OpenAsync(Uri uri) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } } } diff --git a/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs b/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs index d022c8cd9473..1480311e3cde 100755 --- a/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Browser/Browser.netstandard.tvos.watchos.cs @@ -1,73 +1,13 @@ +#nullable enable using System; using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { /// - public partial class BrowserImplementation : IBrowser + partial class BrowserImplementation : IBrowser { public Task OpenAsync(Uri uri, BrowserLaunchOptions options) => throw ExceptionUtils.NotSupportedOrImplementedException; - - public Task OpenAsync(string uri) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchOptions options) - { - return OpenAsync(new Uri(uri), options); - } - - public Task OpenAsync(Uri uri) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } } } diff --git a/src/Essentials/src/Browser/Browser.shared.cs b/src/Essentials/src/Browser/Browser.shared.cs index e14bab27e762..c88b13c5cb29 100755 --- a/src/Essentials/src/Browser/Browser.shared.cs +++ b/src/Essentials/src/Browser/Browser.shared.cs @@ -1,88 +1,40 @@ +#nullable enable using System; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.ApplicationModel.Implementations; - namespace Microsoft.Maui.ApplicationModel { public interface IBrowser { - Task OpenAsync(string uri); - - Task OpenAsync(string uri, BrowserLaunchMode launchMode); - - Task OpenAsync(string uri, BrowserLaunchOptions options); - - Task OpenAsync(Uri uri); - - Task OpenAsync(Uri uri, BrowserLaunchMode launchMode); - Task OpenAsync(Uri uri, BrowserLaunchOptions options); } - /// - public static partial class Browser + public static class Browser { - /// - public static Task OpenAsync(string uri) => - Current.OpenAsync(uri, BrowserLaunchMode.SystemPreferred); - - /// - public static Task OpenAsync(string uri, BrowserLaunchMode launchMode) => - Current.OpenAsync(uri, new BrowserLaunchOptions() - { - LaunchMode = launchMode - }); + static IBrowser? defaultImplementation; - /// - public static Task OpenAsync(string uri, BrowserLaunchOptions options) - { - if (string.IsNullOrWhiteSpace(uri)) - { - throw new ArgumentNullException(nameof(uri), $"Uri cannot be empty."); - } + public static IBrowser Default => + defaultImplementation ??= new BrowserImplementation(); - return Current.OpenAsync(new Uri(uri), options); - } - - /// - public static Task OpenAsync(Uri uri) => - Current.OpenAsync(uri, BrowserLaunchMode.SystemPreferred); - - /// - public static Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) => - Current.OpenAsync(uri, new BrowserLaunchOptions() - { - LaunchMode = launchMode - }); - - /// - public static Task OpenAsync(Uri uri, BrowserLaunchOptions options) => - Current.OpenAsync(EscapeUri(uri), options); + internal static void SetDefault(IBrowser? implementation) => + defaultImplementation = implementation; + } - internal static Uri EscapeUri(Uri uri) - { - if (uri == null) - throw new ArgumentNullException(nameof(uri)); + public static class BrowserExtensions + { + public static Task OpenAsync(this IBrowser browser, string uri) => + browser.OpenAsync(new Uri(uri), new BrowserLaunchOptions()); - var idn = new global::System.Globalization.IdnMapping(); - return new Uri(uri.Scheme + "://" + idn.GetAscii(uri.Authority) + uri.PathAndQuery + uri.Fragment); - } + public static Task OpenAsync(this IBrowser browser, string uri, BrowserLaunchMode launchMode) => + browser.OpenAsync(new Uri(uri), new BrowserLaunchOptions { LaunchMode = launchMode }); -#nullable enable - static IBrowser? currentImplementation; -#nullable disable + public static Task OpenAsync(this IBrowser browser, string uri, BrowserLaunchOptions options) => + browser.OpenAsync(new Uri(uri), options); - [EditorBrowsable(EditorBrowsableState.Never)] - public static IBrowser Current => - currentImplementation ??= new BrowserImplementation(); + public static Task OpenAsync(this IBrowser browser, Uri uri) => + browser.OpenAsync(uri, new BrowserLaunchOptions()); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IBrowser? implementation) => - currentImplementation = implementation; -#nullable disable + public static Task OpenAsync(this IBrowser browser, Uri uri, BrowserLaunchMode launchMode) => + browser.OpenAsync(uri, new BrowserLaunchOptions { LaunchMode = launchMode }); } } diff --git a/src/Essentials/src/Browser/Browser.tizen.cs b/src/Essentials/src/Browser/Browser.tizen.cs index ac0b21d2a748..ae06dc054beb 100755 --- a/src/Essentials/src/Browser/Browser.tizen.cs +++ b/src/Essentials/src/Browser/Browser.tizen.cs @@ -1,11 +1,12 @@ +#nullable enable using System; using System.Linq; using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class BrowserImplementation : IBrowser + partial class BrowserImplementation : IBrowser { public Task PlatformOpenAsync(Uri uri, BrowserLaunchOptions launchMode) { @@ -27,66 +28,5 @@ public Task PlatformOpenAsync(Uri uri, BrowserLaunchOptions launchMode) return Task.FromResult(hasMatches); } - - public Task OpenAsync(string uri) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchOptions options) - { - return OpenAsync(new Uri(uri), options); - } - - public Task OpenAsync(Uri uri) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } } } diff --git a/src/Essentials/src/Browser/Browser.uwp.cs b/src/Essentials/src/Browser/Browser.uwp.cs index 2bbb7d65e719..01f9b4ae0ee8 100755 --- a/src/Essentials/src/Browser/Browser.uwp.cs +++ b/src/Essentials/src/Browser/Browser.uwp.cs @@ -1,72 +1,12 @@ +#nullable enable using System; using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class BrowserImplementation : IBrowser + partial class BrowserImplementation : IBrowser { public Task OpenAsync(Uri uri, BrowserLaunchOptions options) => global::Windows.System.Launcher.LaunchUriAsync(uri).AsTask(); - - public Task OpenAsync(string uri) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - new Uri(uri), - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(string uri, BrowserLaunchOptions options) - { - return OpenAsync(new Uri(uri), options); - } - - public Task OpenAsync(Uri uri) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = BrowserLaunchMode.SystemPreferred, - TitleMode = BrowserTitleMode.Default - } - ); - } - - public Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) - { - return OpenAsync - ( - uri, - new BrowserLaunchOptions - { - Flags = BrowserLaunchFlags.None, - LaunchMode = launchMode, - TitleMode = BrowserTitleMode.Default - } - ); - } } } diff --git a/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs b/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs index 28dfe788bc49..e044819dba37 100755 --- a/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs +++ b/src/Essentials/src/Browser/BrowserLaunchMode.shared.cs @@ -1,3 +1,4 @@ +#nullable enable namespace Microsoft.Maui.ApplicationModel { /// diff --git a/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs b/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs index 6c72348e84b3..c59046d5d3f6 100755 --- a/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs +++ b/src/Essentials/src/Browser/BrowserLaunchOptions.shared.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using Microsoft.Maui.Graphics; @@ -7,10 +8,10 @@ namespace Microsoft.Maui.ApplicationModel public class BrowserLaunchOptions { /// - public Color PreferredToolbarColor { get; set; } + public Color? PreferredToolbarColor { get; set; } /// - public Color PreferredControlColor { get; set; } + public Color? PreferredControlColor { get; set; } /// public BrowserLaunchMode LaunchMode { get; set; } = BrowserLaunchMode.SystemPreferred; @@ -21,8 +22,7 @@ public class BrowserLaunchOptions /// public BrowserLaunchFlags Flags { get; set; } = BrowserLaunchFlags.None; - internal bool HasFlag(BrowserLaunchFlags flag) - => Flags.HasFlag(flag); + internal bool HasFlag(BrowserLaunchFlags flag) => Flags.HasFlag(flag); } /// diff --git a/src/Essentials/src/Browser/BrowserTitleMode.shared.cs b/src/Essentials/src/Browser/BrowserTitleMode.shared.cs index 51512bd51268..3729bf8a363a 100755 --- a/src/Essentials/src/Browser/BrowserTitleMode.shared.cs +++ b/src/Essentials/src/Browser/BrowserTitleMode.shared.cs @@ -1,3 +1,4 @@ +#nullable enable namespace Microsoft.Maui.ApplicationModel { /// diff --git a/src/Essentials/src/Clipboard/Clipboard.android.cs b/src/Essentials/src/Clipboard/Clipboard.android.cs index b25acd1160be..028d12778a0c 100644 --- a/src/Essentials/src/Clipboard/Clipboard.android.cs +++ b/src/Essentials/src/Clipboard/Clipboard.android.cs @@ -1,38 +1,56 @@ -using System; +#nullable enable using System.Threading.Tasks; +using Android.App; using Android.Content; -using Microsoft.Maui.Essentials; using static Android.Content.ClipboardManager; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public partial class ClipboardImplementation : IClipboard + partial class ClipboardImplementation : IClipboard { - static readonly Lazy clipboardListener - = new Lazy(() => new ClipboardChangeListener()); + static ClipboardManager? clipboardManager; - public Task SetTextAsync(string text) + static ClipboardManager? ClipboardManager => + clipboardManager ??= Application.Context.GetSystemService(Context.ClipboardService) as ClipboardManager; + + ClipboardChangeListener? clipboardListener; + + ClipboardChangeListener ClipboardListener => + clipboardListener ??= new ClipboardChangeListener(this); + + public Task SetTextAsync(string? text) { - Platform.ClipboardManager.PrimaryClip = ClipData.NewPlainText("Text", text); + if (ClipboardManager is not null) + ClipboardManager.PrimaryClip = ClipData.NewPlainText("Text", text ?? string.Empty); + return Task.CompletedTask; } - public bool HasText - => Platform.ClipboardManager.HasPrimaryClip && !string.IsNullOrEmpty(Platform.ClipboardManager.PrimaryClip?.GetItemAt(0)?.Text); + public bool HasText => + ClipboardManager is not null && + ClipboardManager.HasPrimaryClip && + !string.IsNullOrEmpty(ClipboardManager.PrimaryClip?.GetItemAt(0)?.Text); - public Task GetTextAsync() - => Task.FromResult(Platform.ClipboardManager.PrimaryClip?.GetItemAt(0)?.Text); + public Task GetTextAsync() => + Task.FromResult(ClipboardManager?.PrimaryClip?.GetItemAt(0)?.Text); public void StartClipboardListeners() - => Platform.ClipboardManager.AddPrimaryClipChangedListener(clipboardListener.Value); + => ClipboardManager?.AddPrimaryClipChangedListener(ClipboardListener); public void StopClipboardListeners() - => Platform.ClipboardManager.RemovePrimaryClipChangedListener(clipboardListener.Value); + => ClipboardManager?.RemovePrimaryClipChangedListener(ClipboardListener); } class ClipboardChangeListener : Java.Lang.Object, IOnPrimaryClipChangedListener { + ClipboardImplementation clipboard; + + public ClipboardChangeListener(ClipboardImplementation clipboard) + { + this.clipboard = clipboard; + } + void IOnPrimaryClipChangedListener.OnPrimaryClipChanged() => - Clipboard.ClipboardChangedInternal(); + clipboard.OnClipboardContentChanged(); } } diff --git a/src/Essentials/src/Clipboard/Clipboard.ios.cs b/src/Essentials/src/Clipboard/Clipboard.ios.cs index f1c59f3c1bc9..94b9206da58a 100644 --- a/src/Essentials/src/Clipboard/Clipboard.ios.cs +++ b/src/Essentials/src/Clipboard/Clipboard.ios.cs @@ -4,9 +4,9 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public partial class ClipboardImplementation : IClipboard + partial class ClipboardImplementation : IClipboard { public Task SetTextAsync(string text) { diff --git a/src/Essentials/src/Clipboard/Clipboard.macos.cs b/src/Essentials/src/Clipboard/Clipboard.macos.cs index 79a5a4217e01..437281bf012f 100644 --- a/src/Essentials/src/Clipboard/Clipboard.macos.cs +++ b/src/Essentials/src/Clipboard/Clipboard.macos.cs @@ -3,9 +3,9 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public partial class ClipboardImplementation : IClipboard + partial class ClipboardImplementation : IClipboard { readonly string pasteboardType = NSPasteboard.NSPasteboardTypeString; readonly string[] pasteboardTypes = { pasteboardType }; diff --git a/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs b/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs index 65914bcc2699..521bf47079c1 100644 --- a/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs +++ b/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { /// - public partial class ClipboardImplementation : IClipboard + partial class ClipboardImplementation : IClipboard { public Task SetTextAsync(string text) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Clipboard/Clipboard.shared.cs b/src/Essentials/src/Clipboard/Clipboard.shared.cs index 34c3d3200782..ca6ba85af57c 100644 --- a/src/Essentials/src/Clipboard/Clipboard.shared.cs +++ b/src/Essentials/src/Clipboard/Clipboard.shared.cs @@ -1,8 +1,6 @@ +#nullable enable using System; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel.DataTransfer; -using Microsoft.Maui.ApplicationModel.DataTransfer.Implementations; namespace Microsoft.Maui.ApplicationModel.DataTransfer { @@ -10,71 +8,45 @@ public interface IClipboard { bool HasText { get; } - Task SetTextAsync(string text); - - Task GetTextAsync(); + Task SetTextAsync(string? text); - void StartClipboardListeners(); + Task GetTextAsync(); - void StopClipboardListeners(); + event EventHandler ClipboardContentChanged; } - /// public static partial class Clipboard { - /// - public static Task SetTextAsync(string text) - => Current.SetTextAsync(text ?? string.Empty); + static IClipboard? defaultImplementation; - /// - public static bool HasText - => Current.HasText; + public static IClipboard Default => + defaultImplementation ??= new ClipboardImplementation(); + + internal static void SetDefault(IClipboard? implementation) => + defaultImplementation = implementation; + } - /// - public static Task GetTextAsync() - => Current.GetTextAsync(); + partial class ClipboardImplementation : IClipboard + { + event EventHandler? ClipboardContentChangedInternal; - public static event EventHandler ClipboardContentChanged + public event EventHandler ClipboardContentChanged { add { - var wasRunning = ClipboardContentChangedInternal != null; - + if (ClipboardContentChangedInternal == null) + StartClipboardListeners(); ClipboardContentChangedInternal += value; - - if (!wasRunning && ClipboardContentChangedInternal != null) - { - Current.StartClipboardListeners(); - } } - remove { - var wasRunning = ClipboardContentChangedInternal != null; - ClipboardContentChangedInternal -= value; - - if (wasRunning && ClipboardContentChangedInternal == null) - Current.StopClipboardListeners(); + if (ClipboardContentChangedInternal == null) + StopClipboardListeners(); } } - static event EventHandler ClipboardContentChangedInternal; - - internal static void ClipboardChangedInternal() => ClipboardContentChangedInternal?.Invoke(null, EventArgs.Empty); - -#nullable enable - static IClipboard? currentImplementation; -#nullable disable - - [EditorBrowsable(EditorBrowsableState.Never)] - public static IClipboard Current => - currentImplementation ??= new ClipboardImplementation(); - - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IClipboard? implementation) => - currentImplementation = implementation; -#nullable disable + internal void OnClipboardContentChanged() => + ClipboardContentChangedInternal?.Invoke(this, EventArgs.Empty); } } diff --git a/src/Essentials/src/Clipboard/Clipboard.uwp.cs b/src/Essentials/src/Clipboard/Clipboard.uwp.cs index 24e52b6b2cc4..76623e21fc00 100644 --- a/src/Essentials/src/Clipboard/Clipboard.uwp.cs +++ b/src/Essentials/src/Clipboard/Clipboard.uwp.cs @@ -4,9 +4,9 @@ using WindowsClipboard = Windows.ApplicationModel.DataTransfer.Clipboard; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public partial class ClipboardImplementation : IClipboard + partial class ClipboardImplementation : IClipboard { public Task SetTextAsync(string text) { diff --git a/src/Essentials/src/Compass/Compass.android.cs b/src/Essentials/src/Compass/Compass.android.cs index f389f70300e4..992e456b6cf4 100644 --- a/src/Essentials/src/Compass/Compass.android.cs +++ b/src/Essentials/src/Compass/Compass.android.cs @@ -1,11 +1,10 @@ using System; using Android.Hardware; using Android.Runtime; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class CompassImplementation : ICompass + partial class CompassImplementation : ICompass { bool PlatformIsSupported => Platform.SensorManager?.GetDefaultSensor(SensorType.Accelerometer) != null && diff --git a/src/Essentials/src/Compass/Compass.ios.cs b/src/Essentials/src/Compass/Compass.ios.cs index 50ae74c15076..9526784d0b1a 100644 --- a/src/Essentials/src/Compass/Compass.ios.cs +++ b/src/Essentials/src/Compass/Compass.ios.cs @@ -1,8 +1,8 @@ using CoreLocation; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class CompassImplementation : ICompass, IPlatformCompass + partial class CompassImplementation : ICompass, IPlatformCompass { // The angular distance is measured relative to the last delivered heading event. Align with UWP numbers internal const double FastestFilter = .01; diff --git a/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs b/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs index ca3c645619c2..3c9931c3bf3b 100644 --- a/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs +++ b/src/Essentials/src/Compass/Compass.netstandard.tvos.watchos.macos.cs @@ -1,6 +1,6 @@ -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class CompassImplementation : ICompass + partial class CompassImplementation : ICompass { bool PlatformIsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index 56edbac155d6..cd331b34e006 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -2,7 +2,6 @@ using System.ComponentModel; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.Devices.Sensors.Implementations; namespace Microsoft.Maui.Devices.Sensors { @@ -29,7 +28,9 @@ public interface IPlatformCompass bool ShouldDisplayHeadingCalibration { get; set; } #endif } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Compass { @@ -76,19 +77,18 @@ public static bool ShouldDisplayHeadingCalibration #nullable enable static ICompass? currentImplementation; -#nullable disable [EditorBrowsable(EditorBrowsableState.Never)] public static ICompass Current => currentImplementation ??= new CompassImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(ICompass? implementation) => + internal static void SetCurrent(ICompass? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.Devices.Sensors +{ /// public class CompassChangedEventArgs : EventArgs { @@ -132,11 +132,8 @@ public override int GetHashCode() => public override string ToString() => $"{nameof(HeadingMagneticNorth)}: {HeadingMagneticNorth}"; } -} -namespace Microsoft.Maui.Devices.Sensors.Implementations -{ - public partial class CompassImplementation : ICompass + partial class CompassImplementation : ICompass { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; diff --git a/src/Essentials/src/Compass/Compass.tizen.cs b/src/Essentials/src/Compass/Compass.tizen.cs index 82deb70a001e..97f081d4b18f 100644 --- a/src/Essentials/src/Compass/Compass.tizen.cs +++ b/src/Essentials/src/Compass/Compass.tizen.cs @@ -1,9 +1,9 @@ using Tizen.Sensor; using TizenCompass = Tizen.Sensor.OrientationSensor; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class CompassImplementation : ICompass + partial class CompassImplementation : ICompass { static TizenCompass DefaultSensor => (TizenCompass)Platform.GetDefaultSensor(SensorType.Compass); diff --git a/src/Essentials/src/Compass/Compass.uwp.cs b/src/Essentials/src/Compass/Compass.uwp.cs index 564b9bd27347..456aa8b53b32 100644 --- a/src/Essentials/src/Compass/Compass.uwp.cs +++ b/src/Essentials/src/Compass/Compass.uwp.cs @@ -2,9 +2,9 @@ using WindowsCompass = Windows.Devices.Sensors.Compass; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class CompassImplementation : ICompass + partial class CompassImplementation : ICompass { // Magic numbers from https://docs.microsoft.com/en-us/uwp/api/windows.devices.sensors.compass.reportinterval#Windows_Devices_Sensors_Compass_ReportInterval internal const uint FastestInterval = 8; diff --git a/src/Essentials/src/Connectivity/Connectivity.android.cs b/src/Essentials/src/Connectivity/Connectivity.android.cs index d07d98e629ec..534c478489f4 100644 --- a/src/Essentials/src/Connectivity/Connectivity.android.cs +++ b/src/Essentials/src/Connectivity/Connectivity.android.cs @@ -5,12 +5,11 @@ using Android.Net; using Android.OS; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; using Debug = System.Diagnostics.Debug; -namespace Microsoft.Maui.Networking.Implementations +namespace Microsoft.Maui.Networking { - public partial class ConnectivityImplementation : IConnectivity + partial class ConnectivityImplementation : IConnectivity { static ConnectivityBroadcastReceiver conectivityReceiver; static Intent connectivityIntent = new Intent(Platform.EssentialsConnectivityChanged); diff --git a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs index 4689d7e0d6ac..08d110332a5b 100644 --- a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs +++ b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs @@ -4,9 +4,9 @@ using System; using System.Collections.Generic; -namespace Microsoft.Maui.Networking.Implementations +namespace Microsoft.Maui.Networking { - public partial class ConnectivityImplementation : IConnectivity + partial class ConnectivityImplementation : IConnectivity { #if !(MACCATALYST || MACOS) // TODO: Use NWPathMonitor on > iOS 12 diff --git a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs index 484dff8a16a9..6b55eca968ae 100644 --- a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs +++ b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs @@ -8,7 +8,7 @@ using CoreFoundation; using SystemConfiguration; -namespace Microsoft.Maui.Networking.Implementations +namespace Microsoft.Maui.Networking { enum NetworkStatus { diff --git a/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs b/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs index 617a32b828b5..fce77b649c07 100644 --- a/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs +++ b/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -namespace Microsoft.Maui.Networking.Implementations +namespace Microsoft.Maui.Networking { /// - public partial class ConnectivityImplementation : IConnectivity + partial class ConnectivityImplementation : IConnectivity { public NetworkAccess NetworkAccess => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Connectivity/Connectivity.shared.cs b/src/Essentials/src/Connectivity/Connectivity.shared.cs index 87da8ff1251b..b1cdfc3a5a90 100644 --- a/src/Essentials/src/Connectivity/Connectivity.shared.cs +++ b/src/Essentials/src/Connectivity/Connectivity.shared.cs @@ -2,8 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.Networking.Implementations; +using Microsoft.Maui.Networking; using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Networking @@ -18,7 +17,9 @@ public interface IConnectivity void StopListeners(); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Connectivity { @@ -84,19 +85,18 @@ internal static void OnConnectivityChanged(ConnectivityChangedEventArgs e) #nullable enable static IConnectivity? currentImplementation; -#nullable disable [EditorBrowsable(EditorBrowsableState.Never)] public static IConnectivity Current => currentImplementation ??= new ConnectivityImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IConnectivity? implementation) => + internal static void SetCurrent(IConnectivity? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.Networking +{ /// public class ConnectivityChangedEventArgs : EventArgs { diff --git a/src/Essentials/src/Connectivity/Connectivity.tizen.cs b/src/Essentials/src/Connectivity/Connectivity.tizen.cs index 1756cee9049e..fc348632fe11 100644 --- a/src/Essentials/src/Connectivity/Connectivity.tizen.cs +++ b/src/Essentials/src/Connectivity/Connectivity.tizen.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using Tizen.Network.Connection; -namespace Microsoft.Maui.Networking.Implementations +namespace Microsoft.Maui.Networking { - public partial class ConnectivityImplementation : IConnectivity + partial class ConnectivityImplementation : IConnectivity { static IList profiles = new List(); diff --git a/src/Essentials/src/Connectivity/Connectivity.uwp.cs b/src/Essentials/src/Connectivity/Connectivity.uwp.cs index 747ee69b7e2b..a58220c8a8d7 100644 --- a/src/Essentials/src/Connectivity/Connectivity.uwp.cs +++ b/src/Essentials/src/Connectivity/Connectivity.uwp.cs @@ -3,9 +3,9 @@ using System.Linq; using Windows.Networking.Connectivity; -namespace Microsoft.Maui.Networking.Implementations +namespace Microsoft.Maui.Networking { - public partial class ConnectivityImplementation : IConnectivity + partial class ConnectivityImplementation : IConnectivity { public void StartListeners() => NetworkInformation.NetworkStatusChanged += NetworkStatusChanged; diff --git a/src/Essentials/src/Contacts/Contacts.android.cs b/src/Essentials/src/Contacts/Contacts.android.cs index cfc951b63c79..c0308f895bff 100644 --- a/src/Essentials/src/Contacts/Contacts.android.cs +++ b/src/Essentials/src/Contacts/Contacts.android.cs @@ -5,13 +5,12 @@ using Android.Content; using Android.Database; using Android.Provider; -using Microsoft.Maui.Essentials; using CommonDataKinds = Android.Provider.ContactsContract.CommonDataKinds; using StructuredName = Android.Provider.ContactsContract.CommonDataKinds.StructuredName; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public class ContactsImplementation : IContacts + class ContactsImplementation : IContacts { const string idCol = ContactsContract.Contacts.InterfaceConsts.Id; const string displayNameCol = ContactsContract.Contacts.InterfaceConsts.DisplayName; diff --git a/src/Essentials/src/Contacts/Contacts.ios.macos.cs b/src/Essentials/src/Contacts/Contacts.ios.macos.cs index bf17e8c0a235..2fb799af3034 100644 --- a/src/Essentials/src/Contacts/Contacts.ios.macos.cs +++ b/src/Essentials/src/Contacts/Contacts.ios.macos.cs @@ -6,12 +6,11 @@ using Contacts; #if __IOS__ using ContactsUI; -using Microsoft.Maui.Essentials; #endif -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public class ContactsImplementation : IContacts + class ContactsImplementation : IContacts { #if __MACOS__ static Task PlatformPickContactAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs b/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs index 0a66b1244c28..e88e3c3f95e3 100644 --- a/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs @@ -2,10 +2,10 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { /// - public class ContactsImplementation : IContacts + class ContactsImplementation : IContacts { public Task PickContactAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Contacts/Contacts.shared.cs b/src/Essentials/src/Contacts/Contacts.shared.cs index 33976c55fade..547d18f59d00 100644 --- a/src/Essentials/src/Contacts/Contacts.shared.cs +++ b/src/Essentials/src/Contacts/Contacts.shared.cs @@ -3,7 +3,8 @@ using System.ComponentModel; using System.Threading; using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.Communication.Implementations; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.ApplicationModel.Communication; using Microsoft.Maui.Devices; namespace Microsoft.Maui.ApplicationModel.Communication @@ -13,6 +14,9 @@ public interface IContacts Task PickContactAsync(); Task> GetAllAsync(CancellationToken cancellationToken = default); } +} +namespace Microsoft.Maui.Essentials +{ /// public static class Contacts { diff --git a/src/Essentials/src/Contacts/Contacts.tizen.cs b/src/Essentials/src/Contacts/Contacts.tizen.cs index 32e1722bb70c..699c28ee8dad 100644 --- a/src/Essentials/src/Contacts/Contacts.tizen.cs +++ b/src/Essentials/src/Contacts/Contacts.tizen.cs @@ -11,7 +11,7 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - public static partial class Contacts + static partial class Contacts { static ContactsManager manager = new ContactsManager(); diff --git a/src/Essentials/src/Contacts/Contacts.uwp.cs b/src/Essentials/src/Contacts/Contacts.uwp.cs index 4fa8a3cd3014..7d1e58c8f54f 100644 --- a/src/Essentials/src/Contacts/Contacts.uwp.cs +++ b/src/Essentials/src/Contacts/Contacts.uwp.cs @@ -5,9 +5,9 @@ using System.Threading.Tasks; using Windows.ApplicationModel.Contacts; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public class ContactsImplementation:IContacts + class ContactsImplementation:IContacts { public async Task PickContactAsync() { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs index 515feba118ce..0718d230dc70 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs @@ -8,11 +8,10 @@ using Android.Runtime; using Android.Util; using Android.Views; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceDisplayImplementation : IDeviceDisplay + class DeviceDisplayImplementation : IDeviceDisplay { OrientationEventListener? orientationListener; diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs index 62f1f73613ab..55f942c9db20 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs @@ -4,9 +4,9 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceDisplayImplementation : IDeviceDisplay + class DeviceDisplayImplementation : IDeviceDisplay { NSObject? observer; diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs index 8a34c404aaaf..9bbdb4fa675b 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs @@ -4,9 +4,9 @@ using CoreVideo; using Foundation; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceDisplayImplementation : IDeviceDisplay + class DeviceDisplayImplementation : IDeviceDisplay { uint keepScreenOnId = 0; NSObject? screenMetricsObserver; diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs index fa251c8d754c..7a6891d7814d 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs @@ -1,9 +1,9 @@ #nullable enable using System; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceDisplayImplementation : IDeviceDisplay + class DeviceDisplayImplementation : IDeviceDisplay { public event EventHandler? MainDisplayInfoChanged { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs index e74ba8b0491d..00bbb4f0c1fe 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs @@ -1,9 +1,9 @@ #nullable enable using System; using System.ComponentModel; -using Microsoft.Maui.Devices.Implementations; +using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Devices +namespace Microsoft.Maui.Essentials { /// public static partial class DeviceDisplay @@ -24,12 +24,10 @@ static DeviceDisplay() } /// - [EditorBrowsable(EditorBrowsableState.Never)] public static IDeviceDisplay Current => currentImplementation; /// - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IDeviceDisplay? implementation) + internal static void SetCurrent(IDeviceDisplay? implementation) { lock (locker) { @@ -121,7 +119,9 @@ static void OnMainDisplayInfoChanged(DisplayInfoChangedEventArgs e) } } } - +} +namespace Microsoft.Maui.Devices +{ /// public class DisplayInfoChangedEventArgs : EventArgs { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs index 5a145780a2b9..9cd5cd21c21d 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs @@ -2,9 +2,9 @@ using System; using System.Runtime.InteropServices; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceDisplayImplementation : IDeviceDisplay + class DeviceDisplayImplementation : IDeviceDisplay { [DllImport("libcapi-system-device.so.0", EntryPoint = "device_power_request_lock")] static extern void RequestKeepScreenOn(int type = 1, int timeout = 0); diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs index 53becf169591..a7a7732c4503 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs @@ -2,15 +2,14 @@ using System; using System.Runtime.InteropServices; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; using Microsoft.UI.Windowing; using Windows.Graphics.Display; using Windows.Graphics.Display.Core; using Windows.System.Display; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceDisplayImplementation : IDeviceDisplay + class DeviceDisplayImplementation : IDeviceDisplay { readonly object locker = new object(); DisplayRequest? displayRequest; diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs index 5b416ecd1eef..028d0ab1ea86 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs @@ -4,9 +4,9 @@ using Android.OS; using Android.Provider; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceInfoImplementation : IDeviceInfo + class DeviceInfoImplementation : IDeviceInfo { const int tabletCrossover = 600; @@ -40,7 +40,7 @@ public DeviceIdiom Idiom var currentIdiom = DeviceIdiom.Unknown; // first try UIModeManager - using var uiModeManager = UiModeManager.FromContext(Essentials.Platform.AppContext); + using var uiModeManager = UiModeManager.FromContext(Platform.AppContext); try { @@ -55,7 +55,7 @@ public DeviceIdiom Idiom // then try Configuration if (currentIdiom == DeviceIdiom.Unknown) { - var configuration = Essentials.Platform.AppContext.Resources?.Configuration; + var configuration = Platform.AppContext.Resources?.Configuration; if (configuration != null) { var minWidth = configuration.SmallestScreenWidthDp; @@ -65,7 +65,7 @@ public DeviceIdiom Idiom else { // start clutching at straws - using var metrics = Essentials.Platform.AppContext.Resources?.DisplayMetrics; + using var metrics = Platform.AppContext.Resources?.DisplayMetrics; if (metrics != null) { var minSize = Math.Min(metrics.WidthPixels, metrics.HeightPixels); @@ -126,10 +126,10 @@ public DeviceType DeviceType static string GetSystemSetting(string name, bool isGlobal = false) { - if (isGlobal && Essentials.Platform.HasApiLevelNMr1) - return Settings.Global.GetString(Essentials.Platform.AppContext.ContentResolver, name); + if (isGlobal && Platform.HasApiLevelNMr1) + return Settings.Global.GetString(Platform.AppContext.ContentResolver, name); else - return Settings.System.GetString(Essentials.Platform.AppContext.ContentResolver, name); + return Settings.System.GetString(Platform.AppContext.ContentResolver, name); } } } diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs index 5dd7a2a78e71..f3a175049e3f 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs @@ -9,9 +9,9 @@ using ObjCRuntime; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceInfoImplementation : IDeviceInfo + class DeviceInfoImplementation : IDeviceInfo { public string Model { @@ -19,7 +19,7 @@ public string Model { try { - return Essentials.Platform.GetSystemLibraryProperty("hw.machine"); + return Platform.GetSystemLibraryProperty("hw.machine"); } catch (Exception) { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs index b3e19f8bd90f..c1378060a7c6 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.macos.cs @@ -3,9 +3,9 @@ using Foundation; using ObjCRuntime; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceInfoImplementation : IDeviceInfo + class DeviceInfoImplementation : IDeviceInfo { [DllImport(Constants.SystemConfigurationLibrary)] static extern IntPtr SCDynamicStoreCopyComputerName(IntPtr store, IntPtr encoding); diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs index 05863fcc36f3..505b76a395ad 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.netstandard.cs @@ -1,8 +1,8 @@ using System; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceInfoImplementation : IDeviceInfo + class DeviceInfoImplementation : IDeviceInfo { public string Model => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs index 6205b07982f6..b4f63474f12f 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs @@ -1,21 +1,19 @@ #nullable enable using System; using System.ComponentModel; -using Microsoft.Maui.Devices.Implementations; +using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Devices +namespace Microsoft.Maui.Essentials { /// public static class DeviceInfo { static IDeviceInfo? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IDeviceInfo Current => currentImplementation ??= new DeviceInfoImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IDeviceInfo? implementation) => + internal static void SetCurrent(IDeviceInfo? implementation) => currentImplementation = implementation; @@ -43,7 +41,9 @@ public static void SetCurrent(IDeviceInfo? implementation) => /// public static DeviceType DeviceType => Current.DeviceType; } - +} +namespace Microsoft.Maui.Devices +{ /// public enum DeviceType { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs index c6c4925e38a0..79e9e8eb8df9 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.tizen.cs @@ -1,20 +1,18 @@ -using Plat = Microsoft.Maui.Essentials.Platform; - -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceInfoImplementation : IDeviceInfo + class DeviceInfoImplementation : IDeviceInfo { public string Model - => Plat.GetSystemInfo("model_name"); + => Platform.GetSystemInfo("model_name"); public string Manufacturer - => Plat.GetSystemInfo("manufacturer"); + => Platform.GetSystemInfo("manufacturer"); public string Name - => Plat.GetSystemInfo("device_name"); + => Platform.GetSystemInfo("device_name"); public string VersionString - => Plat.GetFeatureInfo("platform.version"); + => Platform.GetFeatureInfo("platform.version"); public Version Version => Utils.ParseVersion(VersionString); @@ -45,9 +43,9 @@ public DeviceType DeviceType { get { - var arch = Plat.GetFeatureInfo("platform.core.cpu.arch"); - var armv7 = Plat.GetFeatureInfo("platform.core.cpu.arch.armv7"); - var x86 = Plat.GetFeatureInfo("platform.core.cpu.arch.x86"); + var arch = Platform.GetFeatureInfo("platform.core.cpu.arch"); + var armv7 = Platform.GetFeatureInfo("platform.core.cpu.arch.armv7"); + var x86 = Platform.GetFeatureInfo("platform.core.cpu.arch.x86"); if (arch != null && arch.Equals("armv7") && armv7 && !x86) return DeviceType.Physical; diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs index 097f814b810b..b8f88ebf0c54 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs @@ -4,9 +4,9 @@ using Windows.System.Profile; using Windows.UI.ViewManagement; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class DeviceInfoImplementation : IDeviceInfo + class DeviceInfoImplementation : IDeviceInfo { readonly EasClientDeviceInformation deviceInfo; DeviceIdiom currentIdiom; @@ -70,7 +70,7 @@ public DeviceIdiom Idiom { try { - var currentHandle = Essentials.Platform.CurrentWindowHandle; + var currentHandle = Platform.CurrentWindowHandle; var settings = UIViewSettingsInterop.GetForWindow(currentHandle); var uiMode = settings.UserInteractionMode; currentIdiom = uiMode == UserInteractionMode.Mouse ? DeviceIdiom.Desktop : DeviceIdiom.Tablet; diff --git a/src/Essentials/src/Email/Email.android.cs b/src/Essentials/src/Email/Email.android.cs index 657b2524a14a..2c3c6fdb04d0 100644 --- a/src/Essentials/src/Email/Email.android.cs +++ b/src/Essentials/src/Email/Email.android.cs @@ -6,13 +6,12 @@ using Android.OS; using Android.Text; using Android.Webkit; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Storage; using Uri = Android.Net.Uri; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class EmailImplementation : IEmail + partial class EmailImplementation : IEmail { static EmailMessage testEmail => new ("Testing Microsoft.Maui.Essentials", "This is a test email.", "Microsoft.Maui.Essentials@example.org"); diff --git a/src/Essentials/src/Email/Email.ios.cs b/src/Essentials/src/Email/Email.ios.cs index 0cc45904d99c..5407fef2b99d 100644 --- a/src/Essentials/src/Email/Email.ios.cs +++ b/src/Essentials/src/Email/Email.ios.cs @@ -7,11 +7,10 @@ #endif using ObjCRuntime; using UIKit; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class EmailImplementation : IEmail + partial class EmailImplementation : IEmail { public bool IsComposeSupported => #if !(MACCATALYST || MACOS) diff --git a/src/Essentials/src/Email/Email.macos.cs b/src/Essentials/src/Email/Email.macos.cs index ea28d8398a54..f7e685d254c7 100644 --- a/src/Essentials/src/Email/Email.macos.cs +++ b/src/Essentials/src/Email/Email.macos.cs @@ -2,9 +2,9 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class EmailImplementation : IEmail + partial class EmailImplementation : IEmail { public bool IsComposeSupported => MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString("mailto:")) != null); diff --git a/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs b/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs index bd51595af2a8..1dbfffd3983b 100644 --- a/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { /// - public partial class EmailImplementation : IEmail + partial class EmailImplementation : IEmail { public bool IsComposeSupported => throw ExceptionUtils.NotSupportedOrImplementedException; @@ -17,10 +17,7 @@ public Task ComposeAsync(string subject, string body, params string[] to) public Task ComposeAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; } -} -namespace Microsoft.Maui.ApplicationModel.Communication -{ #if NETSTANDARD || NET6_0 /// public partial class EmailAttachment diff --git a/src/Essentials/src/Email/Email.shared.cs b/src/Essentials/src/Email/Email.shared.cs index 43d7cb7e4cee..6f4c58b26b08 100644 --- a/src/Essentials/src/Email/Email.shared.cs +++ b/src/Essentials/src/Email/Email.shared.cs @@ -3,8 +3,7 @@ using System.Linq; using System.Threading.Tasks; using System.ComponentModel; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.ApplicationModel.Communication.Implementations; +using Microsoft.Maui.ApplicationModel.Communication; using Microsoft.Maui.Storage; namespace Microsoft.Maui.ApplicationModel.Communication @@ -19,7 +18,9 @@ public interface IEmail Task ComposeAsync(EmailMessage message); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Email { @@ -68,19 +69,17 @@ internal static string GetMailToUri(EmailMessage message) #nullable enable static IEmail? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IEmail Current => currentImplementation ??= new EmailImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IEmail? implementation) => + internal static void SetCurrent(IEmail? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.ApplicationModel.Communication +{ /// public class EmailMessage { diff --git a/src/Essentials/src/Email/Email.tizen.cs b/src/Essentials/src/Email/Email.tizen.cs index 277ffc8754ca..15aa4b132d15 100644 --- a/src/Essentials/src/Email/Email.tizen.cs +++ b/src/Essentials/src/Email/Email.tizen.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class EmailImplementation : IEmail + partial class EmailImplementation : IEmail { public bool IsComposeSupported => Platform.GetFeatureInfo("email"); diff --git a/src/Essentials/src/Email/Email.uwp.cs b/src/Essentials/src/Email/Email.uwp.cs index 1a405a5fa8bd..1664fa9b53f8 100644 --- a/src/Essentials/src/Email/Email.uwp.cs +++ b/src/Essentials/src/Email/Email.uwp.cs @@ -10,9 +10,9 @@ using PlatformEmailAttachment = Windows.ApplicationModel.Email.EmailAttachment; using PlatformEmailMessage = Windows.ApplicationModel.Email.EmailMessage; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class EmailImplementation : IEmail + partial class EmailImplementation : IEmail { public bool IsComposeSupported => ApiInformation.IsTypePresent("Windows.ApplicationModel.Email.EmailManager"); diff --git a/src/Essentials/src/Essentials.csproj b/src/Essentials/src/Essentials.csproj index aed47109f44c..3cc8b3c88205 100644 --- a/src/Essentials/src/Essentials.csproj +++ b/src/Essentials/src/Essentials.csproj @@ -6,6 +6,8 @@ false BI1234 false + true + --writer TypeList @@ -13,6 +15,7 @@ + diff --git a/src/Essentials/src/FilePicker/FilePicker.android.cs b/src/Essentials/src/FilePicker/FilePicker.android.cs index 17ee54ef28a2..824cb5d9c50b 100644 --- a/src/Essentials/src/FilePicker/FilePicker.android.cs +++ b/src/Essentials/src/FilePicker/FilePicker.android.cs @@ -5,9 +5,9 @@ using System.Threading.Tasks; using Android.Content; using Microsoft.Maui.Devices; -using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Storage +namespace Microsoft.Maui.Essentials { public static partial class FilePicker { @@ -61,7 +61,9 @@ void OnResult(Intent intent) } } } - +} +namespace Microsoft.Maui.Storage +{ public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FilePicker/FilePicker.ios.cs b/src/Essentials/src/FilePicker/FilePicker.ios.cs index bdb3988b4180..aa7213b8b383 100644 --- a/src/Essentials/src/FilePicker/FilePicker.ios.cs +++ b/src/Essentials/src/FilePicker/FilePicker.ios.cs @@ -7,10 +7,10 @@ using MobileCoreServices; using ObjCRuntime; using UIKit; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Devices; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Storage +namespace Microsoft.Maui.Essentials { public static partial class FilePicker { @@ -77,7 +77,9 @@ public override void DidPickDocument(UIDocumentPickerViewController controller, } } - +} +namespace Microsoft.Maui.Storage +{ public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FilePicker/FilePicker.macos.cs b/src/Essentials/src/FilePicker/FilePicker.macos.cs index 847535d4d408..150d8512b16d 100644 --- a/src/Essentials/src/FilePicker/FilePicker.macos.cs +++ b/src/Essentials/src/FilePicker/FilePicker.macos.cs @@ -4,7 +4,7 @@ using AppKit; using MobileCoreServices; -namespace Microsoft.Maui.Storage +namespace Microsoft.Maui.Essentials { public static partial class FilePicker { @@ -48,7 +48,9 @@ static void SetFileTypes(PickOptions options, NSOpenPanel panel) panel.AllowedFileTypes = allowedFileTypes.ToArray(); } } - +} +namespace Microsoft.Maui.Storage +{ public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs b/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs index e1027b74c844..52f1157e69bc 100644 --- a/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs +++ b/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Storage +namespace Microsoft.Maui.Essentials { /// public static partial class FilePicker @@ -10,7 +11,9 @@ public static partial class FilePicker static Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) => throw new NotImplementedInReferenceAssemblyException(); } - +} +namespace Microsoft.Maui.Storage +{ /// public partial class FilePickerFileType { diff --git a/src/Essentials/src/FilePicker/FilePicker.shared.cs b/src/Essentials/src/FilePicker/FilePicker.shared.cs index 1f3dc56ab0f0..f976ba38190f 100644 --- a/src/Essentials/src/FilePicker/FilePicker.shared.cs +++ b/src/Essentials/src/FilePicker/FilePicker.shared.cs @@ -4,8 +4,9 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Maui.Devices; +using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Storage +namespace Microsoft.Maui.Essentials { /// public static partial class FilePicker @@ -18,7 +19,9 @@ public static async Task PickAsync(PickOptions options = null) => public static Task> PickMultipleAsync(PickOptions options = null) => PlatformPickAsync(options ?? PickOptions.Default, true); } - +} +namespace Microsoft.Maui.Storage +{ /// public partial class FilePickerFileType { diff --git a/src/Essentials/src/FilePicker/FilePicker.tizen.cs b/src/Essentials/src/FilePicker/FilePicker.tizen.cs index a5e06a2b27bc..8232e5cb410d 100644 --- a/src/Essentials/src/FilePicker/FilePicker.tizen.cs +++ b/src/Essentials/src/FilePicker/FilePicker.tizen.cs @@ -7,7 +7,7 @@ using Tizen; using Tizen.Applications; -namespace Microsoft.Maui.Storage +namespace Microsoft.Maui.Essentials { public static partial class FilePicker { @@ -45,7 +45,9 @@ static async Task> PlatformPickAsync(PickOptions options return await tcs.Task; } } - +} +namespace Microsoft.Maui.Storage +{ public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FilePicker/FilePicker.uwp.cs b/src/Essentials/src/FilePicker/FilePicker.uwp.cs index ffcc82932486..4d8b5282f313 100644 --- a/src/Essentials/src/FilePicker/FilePicker.uwp.cs +++ b/src/Essentials/src/FilePicker/FilePicker.uwp.cs @@ -3,12 +3,12 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Maui.Devices; -using Microsoft.Maui.Essentials; +using Microsoft.Maui.Storage; using Windows.Storage; using Windows.Storage.AccessCache; using Windows.Storage.Pickers; -namespace Microsoft.Maui.Storage +namespace Microsoft.Maui.Essentials { public static partial class FilePicker { @@ -67,7 +67,9 @@ static void SetFileTypes(PickOptions options, FileOpenPicker picker) picker.FileTypeFilter.Add("*"); } } - +} +namespace Microsoft.Maui.Storage +{ public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FileSystem/FileSystem.android.cs b/src/Essentials/src/FileSystem/FileSystem.android.cs index eb7ef1320842..dd3e3d055235 100644 --- a/src/Essentials/src/FileSystem/FileSystem.android.cs +++ b/src/Essentials/src/FileSystem/FileSystem.android.cs @@ -5,12 +5,11 @@ using Android.Provider; using Android.Webkit; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem + partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem { internal const string EssentialsFolderHash = "2203693cc04e0be7f4f024d5f9499e13"; @@ -386,10 +385,7 @@ static string QueryContentResolverColumn(AndroidUri contentUri, string columnNam } } -} -namespace Microsoft.Maui.Storage -{ public partial class FileBase { internal FileBase(Java.IO.File file) diff --git a/src/Essentials/src/FileSystem/FileSystem.ios.cs b/src/Essentials/src/FileSystem/FileSystem.ios.cs index 2d9834ed056d..91cb7a518ec0 100644 --- a/src/Essentials/src/FileSystem/FileSystem.ios.cs +++ b/src/Essentials/src/FileSystem/FileSystem.ios.cs @@ -8,9 +8,9 @@ using Photos; using UIKit; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem + partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem { public async Task EnsurePhysicalFileResultsAsync(params NSUrl[] urls) { diff --git a/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs b/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs index 5a48057a38e7..3c449eba803b 100644 --- a/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs @@ -4,9 +4,9 @@ using Foundation; using MobileCoreServices; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class FileSystemImplementation : IFileSystem + partial class FileSystemImplementation : IFileSystem { string PlatformCacheDirectory => GetDirectory(NSSearchPathDirectory.CachesDirectory); @@ -54,10 +54,7 @@ static string GetDirectory(NSSearchPathDirectory directory) return dirs[0]; } } -} -namespace Microsoft.Maui.Storage -{ public partial class FileBase { internal FileBase(NSUrl file) diff --git a/src/Essentials/src/FileSystem/FileSystem.netstandard.cs b/src/Essentials/src/FileSystem/FileSystem.netstandard.cs index f5812e6b5479..0ff60985832d 100644 --- a/src/Essentials/src/FileSystem/FileSystem.netstandard.cs +++ b/src/Essentials/src/FileSystem/FileSystem.netstandard.cs @@ -1,10 +1,10 @@ using System.IO; using System.Threading.Tasks; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class FileSystemImplementation : IFileSystem /// + partial class FileSystemImplementation : IFileSystem { string PlatformCacheDirectory => throw ExceptionUtils.NotSupportedOrImplementedException; @@ -18,10 +18,7 @@ Task PlatformOpenAppPackageFileAsync(string filename) Task PlatformAppPackageFileExistsAsync(string filename) => throw ExceptionUtils.NotSupportedOrImplementedException; } -} -namespace Microsoft.Maui.Storage -{ /// public partial class FileBase { diff --git a/src/Essentials/src/FileSystem/FileSystem.shared.cs b/src/Essentials/src/FileSystem/FileSystem.shared.cs index baee42f62432..d1a25295633c 100644 --- a/src/Essentials/src/FileSystem/FileSystem.shared.cs +++ b/src/Essentials/src/FileSystem/FileSystem.shared.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using System.ComponentModel; using Microsoft.Maui.Storage; -using Microsoft.Maui.Storage.Implementations; namespace Microsoft.Maui.Storage { @@ -29,7 +28,9 @@ public interface IPlatformFileSystem Task EnsurePhysicalFileResultsAsync(params Foundation.NSUrl[] urls); #endif } - +} +namespace Microsoft.Maui.Essentials +{ /// public static class FileSystem { @@ -77,92 +78,89 @@ internal static Task EnsurePhysicalFileResultsAsync(params Foundat } #endif +#nullable enable + static IFileSystem? currentImplementation; - internal static class MimeTypes - { - internal const string All = "*/*"; + public static IFileSystem Current => + currentImplementation ??= new FileSystemImplementation(); - internal const string ImageAll = "image/*"; - internal const string ImagePng = "image/png"; - internal const string ImageJpg = "image/jpeg"; + internal static void SetCurrent(IFileSystem? implementation) => + currentImplementation = implementation; +#nullable disable + } +} +namespace Microsoft.Maui.Storage +{ + static class FileMimeTypes + { + internal const string All = "*/*"; - internal const string VideoAll = "video/*"; + internal const string ImageAll = "image/*"; + internal const string ImagePng = "image/png"; + internal const string ImageJpg = "image/jpeg"; - internal const string EmailMessage = "message/rfc822"; + internal const string VideoAll = "video/*"; - internal const string Pdf = "application/pdf"; + internal const string EmailMessage = "message/rfc822"; - internal const string TextPlain = "text/plain"; + internal const string Pdf = "application/pdf"; - internal const string OctetStream = "application/octet-stream"; - } + internal const string TextPlain = "text/plain"; - internal static class Extensions + internal const string OctetStream = "application/octet-stream"; + } + + static class FileExtensions + { + internal const string Png = ".png"; + internal const string Jpg = ".jpg"; + internal const string Jpeg = ".jpeg"; + internal const string Gif = ".gif"; + internal const string Bmp = ".bmp"; + + internal const string Avi = ".avi"; + internal const string Flv = ".flv"; + internal const string Gifv = ".gifv"; + internal const string Mp4 = ".mp4"; + internal const string M4v = ".m4v"; + internal const string Mpg = ".mpg"; + internal const string Mpeg = ".mpeg"; + internal const string Mp2 = ".mp2"; + internal const string Mkv = ".mkv"; + internal const string Mov = ".mov"; + internal const string Qt = ".qt"; + internal const string Wmv = ".wmv"; + + internal const string Pdf = ".pdf"; + + internal static string[] AllImage => + new[] { Png, Jpg, Jpeg, Gif, Bmp }; + + internal static string[] AllJpeg => + new[] { Jpg, Jpeg }; + + internal static string[] AllVideo => + new[] { Mp4, Mov, Avi, Wmv, M4v, Mpg, Mpeg, Mp2, Mkv, Flv, Gifv, Qt }; + + internal static string Clean(string extension, bool trimLeadingPeriod = false) { - internal const string Png = ".png"; - internal const string Jpg = ".jpg"; - internal const string Jpeg = ".jpeg"; - internal const string Gif = ".gif"; - internal const string Bmp = ".bmp"; - - internal const string Avi = ".avi"; - internal const string Flv = ".flv"; - internal const string Gifv = ".gifv"; - internal const string Mp4 = ".mp4"; - internal const string M4v = ".m4v"; - internal const string Mpg = ".mpg"; - internal const string Mpeg = ".mpeg"; - internal const string Mp2 = ".mp2"; - internal const string Mkv = ".mkv"; - internal const string Mov = ".mov"; - internal const string Qt = ".qt"; - internal const string Wmv = ".wmv"; - - internal const string Pdf = ".pdf"; - - internal static string[] AllImage => - new[] { Png, Jpg, Jpeg, Gif, Bmp }; - - internal static string[] AllJpeg => - new[] { Jpg, Jpeg }; - - internal static string[] AllVideo => - new[] { Mp4, Mov, Avi, Wmv, M4v, Mpg, Mpeg, Mp2, Mkv, Flv, Gifv, Qt }; - - internal static string Clean(string extension, bool trimLeadingPeriod = false) - { - if (string.IsNullOrWhiteSpace(extension)) - return string.Empty; + if (string.IsNullOrWhiteSpace(extension)) + return string.Empty; - extension = extension.TrimStart('*'); - extension = extension.TrimStart('.'); + extension = extension.TrimStart('*'); + extension = extension.TrimStart('.'); - if (!trimLeadingPeriod) - extension = "." + extension; + if (!trimLeadingPeriod) + extension = "." + extension; - return extension; - } + return extension; } - -#nullable enable - static IFileSystem? currentImplementation; -#nullable disable - - [EditorBrowsable(EditorBrowsableState.Never)] - public static IFileSystem Current => - currentImplementation ??= new FileSystemImplementation(); - - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IFileSystem? implementation) => - currentImplementation = implementation; -#nullable disable } /// public abstract partial class FileBase { - internal const string DefaultContentType = FileSystem.MimeTypes.OctetStream; + internal const string DefaultContentType = FileMimeTypes.OctetStream; string contentType; @@ -305,7 +303,7 @@ public FileResult(FileBase file) } } -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { public partial class FileSystemImplementation { diff --git a/src/Essentials/src/FileSystem/FileSystem.tizen.cs b/src/Essentials/src/FileSystem/FileSystem.tizen.cs index eedad97643ef..caecca7029e4 100644 --- a/src/Essentials/src/FileSystem/FileSystem.tizen.cs +++ b/src/Essentials/src/FileSystem/FileSystem.tizen.cs @@ -3,9 +3,9 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class FileSystemImplementation : IFileSystem + partial class FileSystemImplementation : IFileSystem { string PlatformCacheDirectory => Application.Current.DirectoryInfo.Cache; @@ -38,10 +38,7 @@ static string PlatformGetFullAppPackageFilePath(string filename) static string NormalizePath(string filename) => filename.Replace('\\', Path.DirectorySeparatorChar); } -} -namespace Microsoft.Maui.Storage -{ public partial class FileBase { string PlatformGetContentType(string extension) diff --git a/src/Essentials/src/FileSystem/FileSystem.uwp.cs b/src/Essentials/src/FileSystem/FileSystem.uwp.cs index 890fd2f937ce..43b6d9303537 100644 --- a/src/Essentials/src/FileSystem/FileSystem.uwp.cs +++ b/src/Essentials/src/FileSystem/FileSystem.uwp.cs @@ -5,9 +5,9 @@ using Windows.Storage; using Package = Windows.ApplicationModel.Package; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class FileSystemImplementation : IFileSystem + partial class FileSystemImplementation : IFileSystem { string PlatformCacheDirectory => ApplicationData.Current.LocalCacheFolder.Path; @@ -64,10 +64,7 @@ static string PlatformGetFullAppPackageFilePath(string filename) internal static string NormalizePath(string path) => path.Replace('/', Path.DirectorySeparatorChar); } -} -namespace Microsoft.Maui.Storage -{ public partial class FileBase { internal FileBase(IStorageFile file) diff --git a/src/Essentials/src/Flashlight/Flashlight.android.cs b/src/Essentials/src/Flashlight/Flashlight.android.cs index 20232d1702b4..f651ef5314e8 100644 --- a/src/Essentials/src/Flashlight/Flashlight.android.cs +++ b/src/Essentials/src/Flashlight/Flashlight.android.cs @@ -5,12 +5,11 @@ using Android.Hardware.Camera2; using Android.OS; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; using Camera = Android.Hardware.Camera; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class FlashlightImplementation : IFlashlight + class FlashlightImplementation : IFlashlight { static readonly object locker = new object(); diff --git a/src/Essentials/src/Flashlight/Flashlight.ios.cs b/src/Essentials/src/Flashlight/Flashlight.ios.cs index 80017bc4471f..46ea5f365dcc 100644 --- a/src/Essentials/src/Flashlight/Flashlight.ios.cs +++ b/src/Essentials/src/Flashlight/Flashlight.ios.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; using AVFoundation; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class FlashlightImplementation : IFlashlight + class FlashlightImplementation : IFlashlight { public Task TurnOnAsync() { diff --git a/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs b/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs index 62f6b1964843..a2274b14f922 100644 --- a/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs +++ b/src/Essentials/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { /// - public class FlashlightImplementation : IFlashlight + class FlashlightImplementation : IFlashlight { public Task TurnOnAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Flashlight/Flashlight.shared.cs b/src/Essentials/src/Flashlight/Flashlight.shared.cs index 4847ece4c512..79c15b71ce25 100644 --- a/src/Essentials/src/Flashlight/Flashlight.shared.cs +++ b/src/Essentials/src/Flashlight/Flashlight.shared.cs @@ -1,7 +1,7 @@ #nullable enable using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Devices.Implementations; +using Microsoft.Maui.Devices; namespace Microsoft.Maui.Devices { @@ -10,6 +10,9 @@ public interface IFlashlight Task TurnOnAsync(); Task TurnOffAsync(); } +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Flashlight { diff --git a/src/Essentials/src/Flashlight/Flashlight.tizen.cs b/src/Essentials/src/Flashlight/Flashlight.tizen.cs index c07a57eca641..126882ebfacc 100644 --- a/src/Essentials/src/Flashlight/Flashlight.tizen.cs +++ b/src/Essentials/src/Flashlight/Flashlight.tizen.cs @@ -3,7 +3,7 @@ namespace Microsoft.Maui.Devices { - public static partial class Flashlight + class FlashlightImplementation : IFlashlight { internal static bool IsSupported => Platform.GetFeatureInfo("camera.back.flash"); @@ -23,12 +23,12 @@ internal static Task SwitchFlashlight(bool switchOn) }); } - static Task PlatformTurnOnAsync() + public Task TurnOnAsync() { return SwitchFlashlight(true); } - static Task PlatformTurnOffAsync() + public Task TurnOffAsync() { return SwitchFlashlight(false); } diff --git a/src/Essentials/src/Flashlight/Flashlight.uwp.cs b/src/Essentials/src/Flashlight/Flashlight.uwp.cs index bfc3040044d3..88facf140fec 100644 --- a/src/Essentials/src/Flashlight/Flashlight.uwp.cs +++ b/src/Essentials/src/Flashlight/Flashlight.uwp.cs @@ -5,9 +5,9 @@ using Windows.Devices.Enumeration; using Windows.Devices.Lights; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public class FlashlightImplementation:IFlashlight + class FlashlightImplementation : IFlashlight { static readonly object locker = new object(); bool hasLoadedLamp; diff --git a/src/Essentials/src/Geocoding/Geocoding.android.cs b/src/Essentials/src/Geocoding/Geocoding.android.cs index 4d05acf12da8..69be319c3a46 100644 --- a/src/Essentials/src/Geocoding/Geocoding.android.cs +++ b/src/Essentials/src/Geocoding/Geocoding.android.cs @@ -3,11 +3,10 @@ using System.Threading.Tasks; using Android.App; using Android.Locations; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public class GeocodingImplementation : IGeocoding + class GeocodingImplementation : IGeocoding { public async Task> GetPlacemarksAsync(double latitude, double longitude) { diff --git a/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs b/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs index 1cfdbea7c45c..3f0b4507b856 100644 --- a/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using CoreLocation; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public class GeocodingImplementation : IGeocoding + class GeocodingImplementation : IGeocoding { public async Task> GetPlacemarksAsync(double latitude, double longitude) { diff --git a/src/Essentials/src/Geocoding/Geocoding.netstandard.cs b/src/Essentials/src/Geocoding/Geocoding.netstandard.cs index 3384bc7a8034..12b3f6d0d957 100644 --- a/src/Essentials/src/Geocoding/Geocoding.netstandard.cs +++ b/src/Essentials/src/Geocoding/Geocoding.netstandard.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { /// - public class GeocodingImplementation : IGeocoding + class GeocodingImplementation : IGeocoding { public Task> GetPlacemarksAsync(double latitude, double longitude) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Geocoding/Geocoding.shared.cs b/src/Essentials/src/Geocoding/Geocoding.shared.cs index c7ef7d2ee36a..ef9bc91519a6 100644 --- a/src/Essentials/src/Geocoding/Geocoding.shared.cs +++ b/src/Essentials/src/Geocoding/Geocoding.shared.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Devices.Sensors.Implementations; +using Microsoft.Maui.Devices.Sensors; namespace Microsoft.Maui.Devices.Sensors { @@ -12,6 +12,9 @@ public interface IGeocoding Task> GetPlacemarksAsync(double latitude, double longitude); Task> GetLocationsAsync(string address); } +} +namespace Microsoft.Maui.Essentials +{ /// public static class Geocoding { @@ -34,12 +37,10 @@ public static Task> GetLocationsAsync(string address) static IGeocoding? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IGeocoding Current => currentImplementation ??= new GeocodingImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IGeocoding? implementation) => + internal static void SetCurrent(IGeocoding? implementation) => currentImplementation = implementation; } } diff --git a/src/Essentials/src/Geocoding/Geocoding.tizen.cs b/src/Essentials/src/Geocoding/Geocoding.tizen.cs index ced919897279..5ff5985b07e8 100644 --- a/src/Essentials/src/Geocoding/Geocoding.tizen.cs +++ b/src/Essentials/src/Geocoding/Geocoding.tizen.cs @@ -4,9 +4,9 @@ namespace Microsoft.Maui.Devices.Sensors { - public static partial class Geocoding + class GeocodingImplementation : IGeocoding { - static async Task> PlatformGetPlacemarksAsync(double latitude, double longitude) + public async Task> GetPlacemarksAsync(double latitude, double longitude) { Permissions.EnsureDeclared(); if (string.IsNullOrWhiteSpace(Platform.MapServiceToken)) @@ -35,7 +35,7 @@ static async Task> PlatformGetPlacemarksAsync(double lati return list; } - static async Task> PlatformGetLocationsAsync(string address) + public async Task> GetLocationsAsync(string address) { Permissions.EnsureDeclared(); if (string.IsNullOrWhiteSpace(Platform.MapServiceToken)) diff --git a/src/Essentials/src/Geocoding/Geocoding.uwp.cs b/src/Essentials/src/Geocoding/Geocoding.uwp.cs index 0fac8a3d14a3..59116a08d528 100644 --- a/src/Essentials/src/Geocoding/Geocoding.uwp.cs +++ b/src/Essentials/src/Geocoding/Geocoding.uwp.cs @@ -1,13 +1,12 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Maui.Essentials; using Windows.Devices.Geolocation; using Windows.Services.Maps; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public class GeocodingImplementation: IGeocoding + class GeocodingImplementation: IGeocoding { public async Task> GetPlacemarksAsync(double latitude, double longitude) { diff --git a/src/Essentials/src/Geolocation/Geolocation.android.cs b/src/Essentials/src/Geolocation/Geolocation.android.cs index 860badc3c35b..227ecb168705 100644 --- a/src/Essentials/src/Geolocation/Geolocation.android.cs +++ b/src/Essentials/src/Geolocation/Geolocation.android.cs @@ -7,13 +7,12 @@ using Android.OS; using Android.Runtime; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; using AndroidLocation = Android.Locations.Location; using LocationPower = Android.Locations.Power; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GeolocationImplementation : IGeolocation + partial class GeolocationImplementation : IGeolocation { const long twoMinutes = 120000; static readonly string[] ignoredProviders = new string[] { LocationManager.PassiveProvider, "local_database" }; diff --git a/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs b/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs index 8d51b9144afd..bbc66e4f4880 100644 --- a/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs +++ b/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs @@ -6,9 +6,9 @@ using Foundation; using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GeolocationImplementation : IGeolocation + partial class GeolocationImplementation : IGeolocation { public async Task GetLastKnownLocationAsync() { diff --git a/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs b/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs index 5f28dff636ed..b31968e6058a 100644 --- a/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs @@ -2,10 +2,10 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { /// - public partial class GeolocationImplementation : IGeolocation + partial class GeolocationImplementation : IGeolocation { public Task GetLastKnownLocationAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Geolocation/Geolocation.shared.cs b/src/Essentials/src/Geolocation/Geolocation.shared.cs index b151b1dc2075..f409decda845 100644 --- a/src/Essentials/src/Geolocation/Geolocation.shared.cs +++ b/src/Essentials/src/Geolocation/Geolocation.shared.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using System.ComponentModel; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.Devices.Sensors.Implementations; namespace Microsoft.Maui.Devices.Sensors @@ -19,7 +18,9 @@ public interface IGeolocation Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Geolocation { @@ -55,9 +56,9 @@ public static void SetCurrent(IGeolocation? implementation) => } } -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GeolocationImplementation : IGeolocation + partial class GeolocationImplementation : IGeolocation { public Task GetLocationAsync() => GetLocationAsync(new GeolocationRequest(), default); diff --git a/src/Essentials/src/Geolocation/Geolocation.tizen.cs b/src/Essentials/src/Geolocation/Geolocation.tizen.cs index ef6f1fdc9faf..d0574227be5b 100644 --- a/src/Essentials/src/Geolocation/Geolocation.tizen.cs +++ b/src/Essentials/src/Geolocation/Geolocation.tizen.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Tizen.Location; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GeolocationImplementation : IGeolocation + partial class GeolocationImplementation : IGeolocation { Location lastKnownLocation = new Location(); diff --git a/src/Essentials/src/Geolocation/Geolocation.uwp.cs b/src/Essentials/src/Geolocation/Geolocation.uwp.cs index b8f0adfd8ef0..d464f98db59c 100644 --- a/src/Essentials/src/Geolocation/Geolocation.uwp.cs +++ b/src/Essentials/src/Geolocation/Geolocation.uwp.cs @@ -4,9 +4,9 @@ using Microsoft.Maui.ApplicationModel; using Windows.Devices.Geolocation; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GeolocationImplementation : IGeolocation + partial class GeolocationImplementation : IGeolocation { public async Task GetLastKnownLocationAsync() { diff --git a/src/Essentials/src/Gyroscope/Gyroscope.android.cs b/src/Essentials/src/Gyroscope/Gyroscope.android.cs index 5d53c292ebac..f1dbc94c99af 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.android.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.android.cs @@ -1,11 +1,10 @@ using System; using Android.Hardware; using Android.Runtime; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GyroscopeImplementation : IGyroscope + partial class GyroscopeImplementation : IGyroscope { bool PlatformIsSupported => Platform.SensorManager?.GetDefaultSensor(SensorType.Gyroscope) != null; diff --git a/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs b/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs index 4e7614339254..63cf3a114fe4 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs @@ -1,10 +1,9 @@ using CoreMotion; using Foundation; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GyroscopeImplementation : IGyroscope + partial class GyroscopeImplementation : IGyroscope { bool PlatformIsSupported => Platform.MotionManager?.GyroAvailable ?? false; diff --git a/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs b/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs index b52bbadcb062..851dadfb80cf 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs @@ -1,7 +1,7 @@ -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { /// - public partial class GyroscopeImplementation : IGyroscope + partial class GyroscopeImplementation : IGyroscope { bool PlatformIsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs index 1a42ef1516a8..fb5edda464d3 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs @@ -2,7 +2,6 @@ using System.Numerics; using System.ComponentModel; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.Devices.Sensors.Implementations; using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors @@ -21,7 +20,9 @@ public interface IGyroscope event EventHandler ReadingChanged; } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Gyroscope { @@ -51,19 +52,17 @@ public static void Stop() #nullable enable static IGyroscope? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IGyroscope Current => currentImplementation ??= new GyroscopeImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IGyroscope? implementation) => + internal static void SetCurrent(IGyroscope? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.Devices.Sensors +{ /// public class GyroscopeChangedEventArgs : EventArgs { @@ -117,9 +116,9 @@ public override string ToString() => } } -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GyroscopeImplementation : IGyroscope + partial class GyroscopeImplementation : IGyroscope { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; diff --git a/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs b/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs index a8ee5d8240a5..4c70da914290 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs @@ -1,9 +1,9 @@ using Tizen.Sensor; using TizenGyroscope = Tizen.Sensor.Gyroscope; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GyroscopeImplementation : IGyroscope + class GyroscopeImplementation : IGyroscope { static TizenGyroscope DefaultSensor => (TizenGyroscope)Platform.GetDefaultSensor(SensorType.Gyroscope); diff --git a/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs b/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs index cb4d23eb7cd8..a226b8114046 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs @@ -1,9 +1,9 @@ using Windows.Devices.Sensors; using WindowsGyro = Windows.Devices.Sensors.Gyrometer; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class GyroscopeImplementation : IGyroscope + partial class GyroscopeImplementation : IGyroscope { // keep around a reference so we can stop this same instance WindowsGyro sensor; diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs index c61ced8ad7e6..6d9a9682fa39 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.android.cs @@ -3,11 +3,10 @@ using System.Threading.Tasks; using Android.Views; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class HapticFeedbackImplementation : IHapticFeedback + partial class HapticFeedbackImplementation : IHapticFeedback { public bool IsSupported => true; diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs index 4570b0b638a6..b37dad29c746 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs @@ -3,9 +3,9 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class HapticFeedbackImplementation : IHapticFeedback + partial class HapticFeedbackImplementation : IHapticFeedback { public bool IsSupported => true; diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs index 03f7c14ce865..910253060cdc 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.macos.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using AppKit; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class HapticFeedbackImplementation : IHapticFeedback + partial class HapticFeedbackImplementation : IHapticFeedback { public bool IsSupported => true; diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs index ba8b22f0afb6..ed12a3cf38fe 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs @@ -1,10 +1,10 @@ using System; using System.Threading.Tasks; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class HapticFeedbackImplementation : IHapticFeedback /// + partial class HapticFeedbackImplementation : IHapticFeedback { public bool IsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs index 7edbfdacd4d8..dd89d6da3d45 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel; using Microsoft.Maui.Devices; -using Microsoft.Maui.Devices.Implementations; namespace Microsoft.Maui.Devices { @@ -11,7 +10,9 @@ public interface IHapticFeedback void Perform(HapticFeedbackType type); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class HapticFeedback { @@ -25,15 +26,11 @@ public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click) #nullable enable static IHapticFeedback? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IHapticFeedback Current => currentImplementation ??= new HapticFeedbackImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IHapticFeedback? implementation) => + internal static void SetCurrent(IHapticFeedback? implementation) => currentImplementation = implementation; #nullable disable } diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs index de1fcdab9440..914ef60c2690 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.tizen.cs @@ -2,9 +2,9 @@ using System.Diagnostics; using Tizen.System; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class HapticFeedbackImplementation : IHapticFeedback + partial class HapticFeedbackImplementation : IHapticFeedback { public bool IsSupported => true; diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs index 4dc14f593ea1..a87588b6b94d 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.uwp.cs @@ -4,9 +4,9 @@ using Windows.Devices.Haptics; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class HapticFeedbackImplementation : IHapticFeedback + partial class HapticFeedbackImplementation : IHapticFeedback { const string vibrationDeviceApiType = "Windows.Devices.Haptics.VibrationDevice"; diff --git a/src/Essentials/src/Launcher/Launcher.android.cs b/src/Essentials/src/Launcher/Launcher.android.cs index 26aec77a609b..c397c057dec2 100644 --- a/src/Essentials/src/Launcher/Launcher.android.cs +++ b/src/Essentials/src/Launcher/Launcher.android.cs @@ -3,13 +3,12 @@ using Android.App; using Android.Content; using Android.Content.PM; -using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; using Uri = System.Uri; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class LauncherImplementation + partial class LauncherImplementation { Task PlatformCanOpenAsync(Uri uri) { diff --git a/src/Essentials/src/Launcher/Launcher.ios.tvos.cs b/src/Essentials/src/Launcher/Launcher.ios.tvos.cs index 4c5e06ea24fa..0f96e4c7e794 100644 --- a/src/Essentials/src/Launcher/Launcher.ios.tvos.cs +++ b/src/Essentials/src/Launcher/Launcher.ios.tvos.cs @@ -3,15 +3,14 @@ using CoreGraphics; using Foundation; using Microsoft.Maui.Devices; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics.Platform; using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class LauncherImplementation + partial class LauncherImplementation { Task PlatformCanOpenAsync(Uri uri) => Task.FromResult(UIApplication.SharedApplication.CanOpenUrl(WebUtils.GetNativeUrl(uri))); diff --git a/src/Essentials/src/Launcher/Launcher.macos.cs b/src/Essentials/src/Launcher/Launcher.macos.cs index ee953457bb2f..da10deb9f460 100644 --- a/src/Essentials/src/Launcher/Launcher.macos.cs +++ b/src/Essentials/src/Launcher/Launcher.macos.cs @@ -4,9 +4,9 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class LauncherImplementation + partial class LauncherImplementation { Task PlatformCanOpenAsync(Uri uri) => Task.FromResult(NSWorkspace.SharedWorkspace.UrlForApplication(WebUtils.GetNativeUrl(uri)) != null); diff --git a/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs b/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs index db96003003ec..d8df625bc8b8 100644 --- a/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs +++ b/src/Essentials/src/Launcher/Launcher.netstandard.watchos.cs @@ -1,10 +1,10 @@ using System; using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { /// - public partial class LauncherImplementation + partial class LauncherImplementation { Task PlatformCanOpenAsync(Uri uri) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Launcher/Launcher.shared.cs b/src/Essentials/src/Launcher/Launcher.shared.cs index b9d67dab1b5c..5dcf61fc11dc 100644 --- a/src/Essentials/src/Launcher/Launcher.shared.cs +++ b/src/Essentials/src/Launcher/Launcher.shared.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Graphics; using Microsoft.Maui.Storage; @@ -22,7 +23,9 @@ public interface ILauncher Task TryOpenAsync(Uri uri); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Launcher { @@ -57,16 +60,16 @@ public static Task TryOpenAsync(Uri uri) #nullable enable static ILauncher? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static ILauncher Current => - currentImplementation ??= new Implementations.LauncherImplementation(); + currentImplementation ??= new LauncherImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(ILauncher? implementation) => + internal static void SetCurrent(ILauncher? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.ApplicationModel +{ /// public class OpenFileRequest { @@ -100,9 +103,9 @@ public OpenFileRequest(string title, FileBase file) } } -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class LauncherImplementation : ILauncher + partial class LauncherImplementation : ILauncher { public Task CanOpenAsync(string uri) { diff --git a/src/Essentials/src/Launcher/Launcher.tizen.cs b/src/Essentials/src/Launcher/Launcher.tizen.cs index 677436018349..26291fe053f0 100644 --- a/src/Essentials/src/Launcher/Launcher.tizen.cs +++ b/src/Essentials/src/Launcher/Launcher.tizen.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class LauncherImplementation + partial class LauncherImplementation { Task PlatformCanOpenAsync(Uri uri) => Task.FromResult(uri.IsWellFormedOriginalString()); diff --git a/src/Essentials/src/Launcher/Launcher.uwp.cs b/src/Essentials/src/Launcher/Launcher.uwp.cs index b99acfea751d..18297eb5702d 100644 --- a/src/Essentials/src/Launcher/Launcher.uwp.cs +++ b/src/Essentials/src/Launcher/Launcher.uwp.cs @@ -5,9 +5,9 @@ using Windows.System; using WinLauncher = Windows.System.Launcher; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public partial class LauncherImplementation + partial class LauncherImplementation { async Task PlatformCanOpenAsync(Uri uri) { diff --git a/src/Essentials/src/Magnetometer/Magnetometer.android.cs b/src/Essentials/src/Magnetometer/Magnetometer.android.cs index 9dc21beaee28..8b230c587f29 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.android.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.android.cs @@ -1,11 +1,10 @@ using System; using Android.Hardware; using Android.Runtime; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class MagnetometerImplementation : IMagnetometer + partial class MagnetometerImplementation : IMagnetometer { bool PlatformIsSupported => Platform.SensorManager?.GetDefaultSensor(SensorType.MagneticField) != null; diff --git a/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs b/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs index 0c50dc5dc390..d0bab8dc7ed5 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs @@ -1,10 +1,9 @@ using CoreMotion; using Foundation; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class MagnetometerImplementation : IMagnetometer + partial class MagnetometerImplementation : IMagnetometer { bool PlatformIsSupported => Platform.MotionManager?.MagnetometerAvailable ?? false; diff --git a/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs b/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs index 6e3766adbfd9..9863e84c1fd7 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs @@ -1,7 +1,7 @@ -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { /// - public partial class MagnetometerImplementation + partial class MagnetometerImplementation { bool PlatformIsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs index e0c84a7326cc..080f12dc5ee1 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs @@ -2,7 +2,6 @@ using System.Numerics; using System.ComponentModel; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.Devices.Sensors.Implementations; using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors @@ -21,7 +20,9 @@ public interface IMagnetometer event EventHandler ReadingChanged; } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Magnetometer { @@ -51,19 +52,17 @@ public static void Stop() #nullable enable static IMagnetometer? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IMagnetometer Current => currentImplementation ??= new MagnetometerImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IMagnetometer? implementation) => + internal static void SetCurrent(IMagnetometer? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.Devices.Sensors +{ /// public class MagnetometerChangedEventArgs : EventArgs { @@ -117,9 +116,9 @@ public override string ToString() => } } -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class MagnetometerImplementation : IMagnetometer + partial class MagnetometerImplementation : IMagnetometer { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; diff --git a/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs b/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs index 6490272bdc26..941c39305bcd 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.tizen.cs @@ -1,9 +1,9 @@ using Tizen.Sensor; using TizenMagnetometer = Tizen.Sensor.Magnetometer; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class MagnetometerImplementation : IMagnetometer + partial class MagnetometerImplementation : IMagnetometer { static TizenMagnetometer DefaultSensor => (TizenMagnetometer)Platform.GetDefaultSensor(SensorType.Magnetometer); diff --git a/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs b/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs index c2c569410bc1..fe207d3d88ca 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.uwp.cs @@ -2,9 +2,9 @@ using Windows.Devices.Sensors; using WindowsMagnetometer = Windows.Devices.Sensors.Magnetometer; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class MagnetometerImplementation : IMagnetometer + partial class MagnetometerImplementation : IMagnetometer { // keep around a reference so we can stop this same instance WindowsMagnetometer sensor; diff --git a/src/Essentials/src/MainThread/MainThread.android.cs b/src/Essentials/src/MainThread/MainThread.android.cs index 89eb32c12971..02fda402f142 100644 --- a/src/Essentials/src/MainThread/MainThread.android.cs +++ b/src/Essentials/src/MainThread/MainThread.android.cs @@ -1,7 +1,7 @@ using System; using Android.OS; -namespace Microsoft.Maui.ApplicationModel +namespace Microsoft.Maui.Essentials { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs b/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs index 0f68e146703a..831ea5568d9c 100644 --- a/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/MainThread/MainThread.ios.tvos.watchos.macos.cs @@ -1,7 +1,7 @@ using System; using Foundation; -namespace Microsoft.Maui.ApplicationModel +namespace Microsoft.Maui.Essentials { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThread.netstandard.cs b/src/Essentials/src/MainThread/MainThread.netstandard.cs index ca59c050df85..7dc88ea70cbc 100644 --- a/src/Essentials/src/MainThread/MainThread.netstandard.cs +++ b/src/Essentials/src/MainThread/MainThread.netstandard.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.ApplicationModel +namespace Microsoft.Maui.Essentials { /// public static partial class MainThread diff --git a/src/Essentials/src/MainThread/MainThread.shared.cs b/src/Essentials/src/MainThread/MainThread.shared.cs index 1f80e010689b..c4ab286a54cf 100644 --- a/src/Essentials/src/MainThread/MainThread.shared.cs +++ b/src/Essentials/src/MainThread/MainThread.shared.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel +namespace Microsoft.Maui.Essentials { /// public static partial class MainThread diff --git a/src/Essentials/src/MainThread/MainThread.tizen.cs b/src/Essentials/src/MainThread/MainThread.tizen.cs index 99eb7576daf1..7ac48aaaced8 100644 --- a/src/Essentials/src/MainThread/MainThread.tizen.cs +++ b/src/Essentials/src/MainThread/MainThread.tizen.cs @@ -1,7 +1,7 @@ using System; using ElmSharp; -namespace Microsoft.Maui.ApplicationModel +namespace Microsoft.Maui.Essentials { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThread.uwp.cs b/src/Essentials/src/MainThread/MainThread.uwp.cs index 60258c4b2e39..a2b3d0a7b92d 100644 --- a/src/Essentials/src/MainThread/MainThread.uwp.cs +++ b/src/Essentials/src/MainThread/MainThread.uwp.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using Microsoft.Maui.Essentials; #if WINDOWS_UWP using Windows.ApplicationModel.Core; @@ -9,7 +8,7 @@ using Microsoft.UI.Dispatching; #endif -namespace Microsoft.Maui.ApplicationModel +namespace Microsoft.Maui.Essentials { public static partial class MainThread { diff --git a/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs b/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs index 86b81476f8df..7b0df7dfa8fe 100644 --- a/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs +++ b/src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs @@ -3,9 +3,9 @@ using System.Threading.Tasks; using Windows.Foundation; -namespace Microsoft.Maui.ApplicationModel +namespace Microsoft.Maui.Essentials { - internal static partial class MainThreadExtensions + static partial class MainThreadExtensions { internal static void WatchForError(this IAsyncAction self) => self.AsTask().WatchForError(); diff --git a/src/Essentials/src/Map/Map.android.cs b/src/Essentials/src/Map/Map.android.cs index 2834966116c1..001addd02a58 100644 --- a/src/Essentials/src/Map/Map.android.cs +++ b/src/Essentials/src/Map/Map.android.cs @@ -2,12 +2,11 @@ using System.Threading.Tasks; using Android.Content; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.Essentials; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class MapImplementation : IMap + class MapImplementation : IMap { public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) { diff --git a/src/Essentials/src/Map/Map.ios.watchos.macos.cs b/src/Essentials/src/Map/Map.ios.watchos.macos.cs index 97c6872f80ac..dd5c54ca4a58 100644 --- a/src/Essentials/src/Map/Map.ios.watchos.macos.cs +++ b/src/Essentials/src/Map/Map.ios.watchos.macos.cs @@ -7,9 +7,9 @@ using MapKit; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class MapImplementation : IMap + class MapImplementation : IMap { public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) { diff --git a/src/Essentials/src/Map/Map.netstandard.tvos.cs b/src/Essentials/src/Map/Map.netstandard.tvos.cs index bbc72436e90f..733180b3ce02 100644 --- a/src/Essentials/src/Map/Map.netstandard.tvos.cs +++ b/src/Essentials/src/Map/Map.netstandard.tvos.cs @@ -1,10 +1,10 @@ using System.Threading.Tasks; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { /// - public class MapImplementation : IMap + class MapImplementation : IMap { public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Map/Map.shared.cs b/src/Essentials/src/Map/Map.shared.cs index 12c5ab064695..7b41da2700f5 100644 --- a/src/Essentials/src/Map/Map.shared.cs +++ b/src/Essentials/src/Map/Map.shared.cs @@ -3,7 +3,7 @@ using System.ComponentModel; using System.Threading.Tasks; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.ApplicationModel.Implementations; +using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.ApplicationModel { @@ -12,6 +12,9 @@ public interface IMap Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options); Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options); } +} +namespace Microsoft.Maui.Essentials +{ /// public static class Map { @@ -59,14 +62,13 @@ public static Task OpenAsync(Placemark placemark, MapLaunchOptions options) return Current.OpenMapsAsync(placemark, options); } + static IMap? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IMap Current => currentImplementation ??= new MapImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IMap? implementation) => + internal static void SetCurrent(IMap? implementation) => currentImplementation = implementation; } } diff --git a/src/Essentials/src/Map/Map.tizen.cs b/src/Essentials/src/Map/Map.tizen.cs index 8aa5f76df68c..c1c3799ca050 100644 --- a/src/Essentials/src/Map/Map.tizen.cs +++ b/src/Essentials/src/Map/Map.tizen.cs @@ -5,9 +5,9 @@ namespace Microsoft.Maui.ApplicationModel { - public static partial class Map + class MapImplementation : IMap { - internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) + public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) { Permissions.EnsureDeclared(); @@ -24,7 +24,7 @@ internal static Task PlatformOpenMapsAsync(double latitude, double longitude, Ma return Task.CompletedTask; } - internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options) + public Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options) { Permissions.EnsureDeclared(); diff --git a/src/Essentials/src/Map/Map.uwp.cs b/src/Essentials/src/Map/Map.uwp.cs index c980bbc50dce..dc7cd2ce6fed 100644 --- a/src/Essentials/src/Map/Map.uwp.cs +++ b/src/Essentials/src/Map/Map.uwp.cs @@ -3,9 +3,9 @@ using System.Threading.Tasks; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class MapImplementation:IMap + class MapImplementation:IMap { public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.android.cs b/src/Essentials/src/MediaPicker/MediaPicker.android.cs index b81da98b739c..53416768e738 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.android.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.android.cs @@ -4,13 +4,12 @@ using Android.Content.PM; using Android.Provider; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Storage; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class MediaPickerImplementation : IMediaPicker + partial class MediaPickerImplementation : IMediaPicker { public bool IsCaptureSupported => Platform.AppContext.PackageManager.HasSystemFeature(PackageManager.FeatureCameraAny); diff --git a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs index 1c2630e212a2..82a3d2e8a9c7 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs @@ -4,16 +4,15 @@ using Foundation; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Storage; using MobileCoreServices; using ObjCRuntime; using Photos; using UIKit; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class MediaPickerImplementation : IMediaPicker + partial class MediaPickerImplementation : IMediaPicker { static UIImagePickerController picker; diff --git a/src/Essentials/src/MediaPicker/MediaPicker.macos.cs b/src/Essentials/src/MediaPicker/MediaPicker.macos.cs index 1e0e0d472a9d..b3d0c7371962 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.macos.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.macos.cs @@ -3,9 +3,9 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class MediaPickerImplementation : IMediaPicker + partial class MediaPickerImplementation : IMediaPicker { public bool PlatformIsCaptureSupported => false; diff --git a/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs b/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs index 3f60715366f1..7d1e75f71d54 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs @@ -3,10 +3,10 @@ using System.Threading.Tasks; using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { /// - public partial class MediaPickerImplementation : IMediaPicker + partial class MediaPickerImplementation : IMediaPicker { public bool IsCaptureSupported => throw new NotImplementedInReferenceAssemblyException(); diff --git a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs index 892be3ecd189..5d45fac3200f 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs @@ -3,7 +3,6 @@ using System.IO; using System.Threading.Tasks; using Microsoft.Maui.Media; -using Microsoft.Maui.Media.Implementations; using Microsoft.Maui.Storage; namespace Microsoft.Maui.Media @@ -20,7 +19,9 @@ public interface IMediaPicker Task CaptureVideoAsync(MediaPickerOptions options); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class MediaPicker { @@ -56,19 +57,17 @@ public static Task CaptureVideoAsync(MediaPickerOptions options = nu #nullable enable static IMediaPicker? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IMediaPicker Current => currentImplementation ??= new MediaPickerImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IMediaPicker? implementation) => + internal static void SetCurrent(IMediaPicker? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.Media +{ /// public class MediaPickerOptions { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs b/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs index a5f9ca337ea1..28e84bda0456 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs @@ -5,9 +5,9 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class MediaPickerImplementation : IMediaPicker + partial class MediaPickerImplementation : IMediaPicker { public bool IsCaptureSupported => true; diff --git a/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs b/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs index 10c1d1fdddc1..f830bdfcd093 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.uwp.cs @@ -1,14 +1,13 @@ using System; using System.Linq; using System.Threading.Tasks; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Storage; using Windows.Media.Capture; using Windows.Storage.Pickers; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class MediaPickerImplementation : IMediaPicker + partial class MediaPickerImplementation : IMediaPicker { public bool IsCaptureSupported => true; diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs index 2dd7127c908f..0c850db82b80 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs @@ -1,11 +1,10 @@ using System; using Android.Hardware; using Android.Runtime; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class OrientationSensorImplementation : IOrientationSensor + partial class OrientationSensorImplementation : IOrientationSensor { bool PlatformIsSupported => Platform.SensorManager?.GetDefaultSensor(SensorType.RotationVector) != null; diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs index c630c0f1c243..44b7975d5339 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs @@ -2,11 +2,10 @@ using System.Numerics; using CoreMotion; using Foundation; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class OrientationSensorImplementation : IOrientationSensor + partial class OrientationSensorImplementation : IOrientationSensor { bool PlatformIsSupported => Platform.MotionManager?.DeviceMotionAvailable ?? false; diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs index 87c1ec56dc99..1ff4b9971789 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs @@ -1,7 +1,7 @@ -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { /// - public partial class OrientationSensorImplementation : IOrientationSensor + partial class OrientationSensorImplementation : IOrientationSensor { bool PlatformIsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs index 235d581f3bd8..503918aea8a7 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs @@ -2,7 +2,6 @@ using System.Numerics; using System.ComponentModel; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.Devices.Sensors.Implementations; using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors @@ -21,7 +20,9 @@ public interface IOrientationSensor event EventHandler ReadingChanged; } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class OrientationSensor { @@ -50,19 +51,17 @@ public static void Stop() #nullable enable static IOrientationSensor? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IOrientationSensor Current => currentImplementation ??= new OrientationSensorImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IOrientationSensor? implementation) => + internal static void SetCurrent(IOrientationSensor? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.Devices.Sensors +{ /// public class OrientationSensorChangedEventArgs : EventArgs { @@ -115,10 +114,7 @@ public override string ToString() => $"{nameof(Orientation.Z)}: {Orientation.Z}, " + $"{nameof(Orientation.W)}: {Orientation.W}"; } -} -namespace Microsoft.Maui.Devices.Sensors.Implementations -{ public partial class OrientationSensorImplementation : IOrientationSensor { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs index d215f7722b85..c9e468e3648f 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.tizen.cs @@ -1,9 +1,9 @@ using Tizen.Sensor; using TizenRotationVectorSensor = Tizen.Sensor.RotationVectorSensor; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class OrientationSensorImplementation : IOrientationSensor + partial class OrientationSensorImplementation : IOrientationSensor { static TizenRotationVectorSensor DefaultSensor => (TizenRotationVectorSensor)Platform.GetDefaultSensor(SensorType.OrientationSensor); diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs index ce542f087964..52d88d68f4fc 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs @@ -1,9 +1,9 @@ using Windows.Devices.Sensors; using WindowsOrientationSensor = Windows.Devices.Sensors.OrientationSensor; -namespace Microsoft.Maui.Devices.Sensors.Implementations +namespace Microsoft.Maui.Devices.Sensors { - public partial class OrientationSensorImplementation : IOrientationSensor + partial class OrientationSensorImplementation : IOrientationSensor { // keep around a reference so we can stop this same instance WindowsOrientationSensor sensor; diff --git a/src/Essentials/src/Permissions/Permissions.android.cs b/src/Essentials/src/Permissions/Permissions.android.cs index 7d3b5702d274..1adbcb4df994 100644 --- a/src/Essentials/src/Permissions/Permissions.android.cs +++ b/src/Essentials/src/Permissions/Permissions.android.cs @@ -7,7 +7,6 @@ using Android.OS; using AndroidX.Core.App; using AndroidX.Core.Content; -using Microsoft.Maui.Essentials; namespace Microsoft.Maui.ApplicationModel { diff --git a/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs b/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs index f06ee85523bf..8d1b05b19864 100644 --- a/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs +++ b/src/Essentials/src/Permissions/Permissions.ios.tvos.macos.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; -using Microsoft.Maui.Essentials; using Photos; namespace Microsoft.Maui.ApplicationModel diff --git a/src/Essentials/src/Permissions/Permissions.shared.cs b/src/Essentials/src/Permissions/Permissions.shared.cs index 0a99941cb025..2203c6cf6efb 100644 --- a/src/Essentials/src/Permissions/Permissions.shared.cs +++ b/src/Essentials/src/Permissions/Permissions.shared.cs @@ -49,7 +49,6 @@ public BasePermission() public abstract bool ShouldShowRationale(); } - /// public partial class Battery { } @@ -74,7 +73,6 @@ public partial class ContactsWrite { } - /// public partial class Flashlight { } @@ -127,7 +125,6 @@ public partial class Sensors { } - /// public partial class Sms { } diff --git a/src/Essentials/src/Permissions/Permissions.uwp.cs b/src/Essentials/src/Permissions/Permissions.uwp.cs index be8a570795bd..a208300f5043 100644 --- a/src/Essentials/src/Permissions/Permissions.uwp.cs +++ b/src/Essentials/src/Permissions/Permissions.uwp.cs @@ -6,7 +6,6 @@ using System.Xml; using System.Xml.Linq; using System.Xml.XPath; -using Microsoft.Maui.Essentials; using Windows.ApplicationModel; using Windows.ApplicationModel.Contacts; using Windows.Devices.Enumeration; diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs index c2c27ee46c88..6e1f31f112b9 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs @@ -5,12 +5,11 @@ using Android.Telephony; using Java.Net; using Java.Util; -using Microsoft.Maui.Essentials; using Uri = Android.Net.Uri; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class PhoneDialerImplementation : IPhoneDialer + partial class PhoneDialerImplementation : IPhoneDialer { const string intentCheck = "00000000000"; diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs index 268a90214a3d..1df52dc378da 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs @@ -3,9 +3,9 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class PhoneDialerImplementation : IPhoneDialer + partial class PhoneDialerImplementation : IPhoneDialer { const string noNetworkProviderCode = "65535"; diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs index e826404058ad..2770d3c6a971 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs @@ -1,9 +1,9 @@ using AppKit; using Foundation; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class PhoneDialerImplementation : IPhoneDialer + partial class PhoneDialerImplementation : IPhoneDialer { public bool IsSupported => MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString($"tel:0000000000")) != null); diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs index 61b8503c4352..0696dabcf443 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs @@ -1,6 +1,6 @@ -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class PhoneDialerImplementation : IPhoneDialer + partial class PhoneDialerImplementation : IPhoneDialer { public bool IsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs index 03826f439fc8..1d9edee553bc 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs @@ -2,7 +2,6 @@ using System; using System.ComponentModel; using Microsoft.Maui.ApplicationModel.Communication; -using Microsoft.Maui.ApplicationModel.Communication.Implementations; namespace Microsoft.Maui.ApplicationModel.Communication { @@ -12,7 +11,9 @@ public interface IPhoneDialer void Open(string number); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static class PhoneDialer { @@ -34,7 +35,7 @@ public static void SetCurrent(IPhoneDialer? implementation) => } } -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { partial class PhoneDialerImplementation { diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs index 037008d71627..87b79477e541 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs @@ -1,8 +1,8 @@ using Tizen.Applications; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class PhoneDialerImplementation : IPhoneDialer + partial class PhoneDialerImplementation : IPhoneDialer { public bool IsSupported => Platform.GetFeatureInfo("contact"); diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs index 1e429c78bb7f..92a4894ab060 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.uwp.cs @@ -1,9 +1,9 @@ using Windows.ApplicationModel.Calls; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public partial class PhoneDialerImplementation : IPhoneDialer + partial class PhoneDialerImplementation : IPhoneDialer { public bool IsSupported => ApiInformation.IsTypePresent("Windows.ApplicationModel.Calls.PhoneCallManager"); diff --git a/src/Essentials/src/Platform/Platform.android.cs b/src/Essentials/src/Platform/Platform.android.cs index 6a4158f6e5b1..39a52da56027 100644 --- a/src/Essentials/src/Platform/Platform.android.cs +++ b/src/Essentials/src/Platform/Platform.android.cs @@ -13,7 +13,6 @@ using Android.OS; using Android.Views; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.ApplicationModel.Implementations; using Microsoft.Maui.Storage; using AndroidIntent = Android.Content.Intent; using AndroidUri = Android.Net.Uri; @@ -102,26 +101,6 @@ public static void Init(Activity activity, Bundle bundle) public static void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) => Permissions.OnRequestPermissionsResult(requestCode, permissions, grantResults); - public static void OnNewIntent(AndroidIntent intent) - => CheckAppActions(intent); - - public static void OnResume(Activity activity = null) - { - if (activity != null) - CheckAppActions(activity.Intent); - } - - static void CheckAppActions(AndroidIntent intent) - { - if (intent?.Action == Intent.ActionAppAction) - { - var appAction = intent.ToAppAction(); - - if (!string.IsNullOrEmpty(appAction?.Id)) - AppActions.InvokeOnAppAction(Platform.CurrentActivity, appAction); - } - } - internal static bool HasSystemFeature(string systemFeature) { var packageManager = AppContext.PackageManager; @@ -261,11 +240,6 @@ internal static void SetLocale(Java.Util.Locale locale) resources.UpdateConfiguration(config, resources.DisplayMetrics); #pragma warning restore CS0618 // Type or member is obsolete } - - public static class Intent - { - public const string ActionAppAction = "ACTION_XE_APP_ACTION"; - } } public enum ActivityState diff --git a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs index 3ef5fee95142..a68a8364af8a 100644 --- a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs +++ b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs @@ -7,7 +7,6 @@ using UIKit; using Microsoft.Maui.Authentication; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.ApplicationModel.Implementations; #if __IOS__ using CoreMotion; @@ -27,18 +26,6 @@ public static bool ContinueUserActivity(UIApplication application, NSUserActivit => WebAuthenticator.OpenUrl(new Uri(userActivity?.WebPageUrl?.AbsoluteString)); #endif -#if __IOS__ - public static void PerformActionForShortcutItem(UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler) - { - if (shortcutItem.Type == AppActions.Type) - { - var appAction = shortcutItem.ToAppAction(); - - AppActions.InvokeOnAppAction(application, shortcutItem.ToAppAction()); - } - } -#endif - #if __IOS__ [DllImport(Constants.SystemLibrary, EntryPoint = "sysctlbyname")] #else diff --git a/src/Essentials/src/Platform/Platform.uwp.cs b/src/Essentials/src/Platform/Platform.uwp.cs index 60ac0634f2a7..b1e722bb0411 100644 --- a/src/Essentials/src/Platform/Platform.uwp.cs +++ b/src/Essentials/src/Platform/Platform.uwp.cs @@ -69,9 +69,6 @@ internal static void NewWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr public static string MapServiceToken { get; set; } - public static async void OnLaunched(LaunchActivatedEventArgs e) - => await AppActions.OnLaunched(e); - public static void OnActivated(Window window, WindowActivatedEventArgs args) { if (args.WindowActivationState != WindowActivationState.Deactivated) diff --git a/src/Essentials/src/Preferences/Preferences.android.cs b/src/Essentials/src/Preferences/Preferences.android.cs index b9f84c2d4470..10f0c4d2c28b 100644 --- a/src/Essentials/src/Preferences/Preferences.android.cs +++ b/src/Essentials/src/Preferences/Preferences.android.cs @@ -4,9 +4,9 @@ using Android.Content; using Android.Preferences; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public class PreferencesImplementation : IPreferences + class PreferencesImplementation : IPreferences { static readonly object locker = new object(); diff --git a/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs b/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs index 3e936f32e7bf..cc97b54260b0 100644 --- a/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Preferences/Preferences.ios.tvos.watchos.macos.cs @@ -2,9 +2,9 @@ using System.Globalization; using Foundation; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public class PreferencesImplementation : IPreferences + class PreferencesImplementation : IPreferences { static readonly object locker = new object(); diff --git a/src/Essentials/src/Preferences/Preferences.netstandard.cs b/src/Essentials/src/Preferences/Preferences.netstandard.cs index 2a76d5961f09..0fc111a26a29 100644 --- a/src/Essentials/src/Preferences/Preferences.netstandard.cs +++ b/src/Essentials/src/Preferences/Preferences.netstandard.cs @@ -1,7 +1,7 @@ -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { /// - public class PreferencesImplementation : IPreferences + class PreferencesImplementation : IPreferences { public bool ContainsKey(string key, string sharedName) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Preferences/Preferences.shared.cs b/src/Essentials/src/Preferences/Preferences.shared.cs index 41e9bced9c2e..9fa63fcbb3d7 100644 --- a/src/Essentials/src/Preferences/Preferences.shared.cs +++ b/src/Essentials/src/Preferences/Preferences.shared.cs @@ -2,7 +2,7 @@ using System; using System.ComponentModel; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Storage.Implementations; +using Microsoft.Maui.Storage; namespace Microsoft.Maui.Storage { @@ -14,7 +14,9 @@ public interface IPreferences void Set(string key, T value, string? sharedName); T Get(string key, T defaultValue, string? sharedName); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static class Preferences { @@ -165,12 +167,10 @@ public static void Set(string key, DateTime value, string? sharedName) => static IPreferences? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IPreferences Current => currentImplementation ??= new PreferencesImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IPreferences? implementation) => + internal static void SetCurrent(IPreferences? implementation) => currentImplementation = implementation; } } diff --git a/src/Essentials/src/Preferences/Preferences.tizen.cs b/src/Essentials/src/Preferences/Preferences.tizen.cs index 419e15414d1f..48b522733886 100644 --- a/src/Essentials/src/Preferences/Preferences.tizen.cs +++ b/src/Essentials/src/Preferences/Preferences.tizen.cs @@ -3,13 +3,13 @@ namespace Microsoft.Maui.Storage { - public static partial class Preferences + class PreferencesImplementation : IPreferences { const string separator = "~"; static readonly object locker = new object(); - static bool PlatformContainsKey(string key, string sharedName) + public bool ContainsKey(string key, string sharedName) { lock (locker) { @@ -17,7 +17,7 @@ static bool PlatformContainsKey(string key, string sharedName) } } - static void PlatformRemove(string key, string sharedName) + public void Remove(string key, string sharedName) { lock (locker) { @@ -27,7 +27,7 @@ static void PlatformRemove(string key, string sharedName) } } - static void PlatformClear(string sharedName) + public void Clear(string sharedName) { lock (locker) { @@ -44,7 +44,7 @@ static void PlatformClear(string sharedName) } } - static void PlatformSet(string key, T value, string sharedName) + public void Set(string key, T value, string sharedName) { lock (locker) { @@ -56,7 +56,7 @@ static void PlatformSet(string key, T value, string sharedName) } } - static T PlatformGet(string key, T defaultValue, string sharedName) + public T Get(string key, T defaultValue, string sharedName) { lock (locker) { diff --git a/src/Essentials/src/Preferences/Preferences.uwp.cs b/src/Essentials/src/Preferences/Preferences.uwp.cs index fff9238c9f87..80bf7b82154b 100644 --- a/src/Essentials/src/Preferences/Preferences.uwp.cs +++ b/src/Essentials/src/Preferences/Preferences.uwp.cs @@ -1,8 +1,8 @@ using Windows.Storage; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public class PreferencesImplementation:IPreferences + class PreferencesImplementation : IPreferences { static readonly object locker = new object(); diff --git a/src/Essentials/src/Screenshot/Screenshot.android.cs b/src/Essentials/src/Screenshot/Screenshot.android.cs index 8512c4cf0d42..7ed5541da8fd 100644 --- a/src/Essentials/src/Screenshot/Screenshot.android.cs +++ b/src/Essentials/src/Screenshot/Screenshot.android.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using Android.Graphics; using Android.Views; -using Microsoft.Maui.Essentials; using Java.Nio; namespace Microsoft.Maui.Media @@ -115,7 +114,7 @@ public static Bitmap Render(this View view) } } -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/Screenshot/Screenshot.ios.cs b/src/Essentials/src/Screenshot/Screenshot.ios.cs index b3c45aa88307..593036470b49 100644 --- a/src/Essentials/src/Screenshot/Screenshot.ios.cs +++ b/src/Essentials/src/Screenshot/Screenshot.ios.cs @@ -315,7 +315,7 @@ static void SetLong(this byte[] data, nint offset, nint value) } } -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs index f05a910626da..5831013e8680 100644 --- a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs +++ b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs @@ -1,7 +1,7 @@ using System.IO; using System.Threading.Tasks; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/Screenshot/Screenshot.shared.cs b/src/Essentials/src/Screenshot/Screenshot.shared.cs index 911ee69a34c9..f26909ff1c3f 100644 --- a/src/Essentials/src/Screenshot/Screenshot.shared.cs +++ b/src/Essentials/src/Screenshot/Screenshot.shared.cs @@ -46,7 +46,7 @@ public static Task CaptureAsync() [EditorBrowsable(EditorBrowsableState.Never)] public static IScreenshot Current => - currentImplementation ??= new Implementations.ScreenshotImplementation(); + currentImplementation ??= new ScreenshotImplementation(); [EditorBrowsable(EditorBrowsableState.Never)] public static void SetCurrent(IScreenshot? implementation) => @@ -63,7 +63,7 @@ public enum ScreenshotFormat } } -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { internal partial class ScreenshotResult : IScreenshotResult { diff --git a/src/Essentials/src/Screenshot/Screenshot.tvos.cs b/src/Essentials/src/Screenshot/Screenshot.tvos.cs index 181bd960d715..a0854757bcbf 100644 --- a/src/Essentials/src/Screenshot/Screenshot.tvos.cs +++ b/src/Essentials/src/Screenshot/Screenshot.tvos.cs @@ -3,7 +3,7 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/Screenshot/Screenshot.uwp.cs b/src/Essentials/src/Screenshot/Screenshot.uwp.cs index 0158cf42c6bc..9d90d43a0c83 100644 --- a/src/Essentials/src/Screenshot/Screenshot.uwp.cs +++ b/src/Essentials/src/Screenshot/Screenshot.uwp.cs @@ -69,7 +69,7 @@ public static async Task AsImageBytesAsync(this RenderTargetBitmap bitma } } -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { public partial class ScreenshotImplementation : IScreenshot { diff --git a/src/Essentials/src/SecureStorage/SecureStorage.android.cs b/src/Essentials/src/SecureStorage/SecureStorage.android.cs index ccaebbf45cf1..09f6bdee3ae7 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.android.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.android.cs @@ -4,9 +4,9 @@ using AndroidX.Security.Crypto; using Javax.Crypto; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class SecureStorageImplementation : ISecureStorage + partial class SecureStorageImplementation : ISecureStorage { static readonly object locker = new object(); diff --git a/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs b/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs index bbba147c627d..add165ab5427 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs @@ -5,9 +5,9 @@ using Foundation; using Security; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class SecureStorageImplementation : ISecureStorage, IPlatformSecureStorage + partial class SecureStorageImplementation : ISecureStorage, IPlatformSecureStorage { public SecAccessible DefaultAccessible { get; set; } diff --git a/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs b/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs index 9eff1ed48367..189601d14285 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { /// - public partial class SecureStorageImplementation : ISecureStorage + partial class SecureStorageImplementation : ISecureStorage { Task PlatformGetAsync(string key) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs index f802576a6438..4aed6567f1cd 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs @@ -2,7 +2,7 @@ using System; using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Storage.Implementations; +using Microsoft.Maui.Storage; namespace Microsoft.Maui.Storage { @@ -21,7 +21,9 @@ public interface IPlatformSecureStorage Task SetAsync(string key, string value, Security.SecAccessible accessible); #endif } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class SecureStorage { @@ -90,21 +92,19 @@ public static Task SetAsync(string key, string value, Security.SecAccessible acc static ISecureStorage? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static ISecureStorage Current => currentImplementation ??= new SecureStorageImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(ISecureStorage? implementation) + internal static void SetCurrent(ISecureStorage? implementation) { currentImplementation = implementation; } } } -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class SecureStorageImplementation + partial class SecureStorageImplementation { #if !NETSTANDARD // Special Alias that is only used for Secure Storage. All others should use: Preferences.GetPrivatePreferencesSharedName diff --git a/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs b/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs index 0e5d784340f7..3b753d07fb98 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.tizen.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Tizen.Security.SecureRepository; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class SecureStorageImplementation : ISecureStorage + partial class SecureStorageImplementation : ISecureStorage { Task PlatformGetAsync(string key) { diff --git a/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs b/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs index b7d8fe1d5fd4..5093a7f240c3 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.uwp.cs @@ -5,9 +5,9 @@ using Windows.Security.Cryptography.DataProtection; using Windows.Storage; -namespace Microsoft.Maui.Storage.Implementations +namespace Microsoft.Maui.Storage { - public partial class SecureStorageImplementation : ISecureStorage + partial class SecureStorageImplementation : ISecureStorage { async Task PlatformGetAsync(string key) { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs index 01be52b1356e..f41d7863dd20 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.android.cs @@ -1,8 +1,8 @@ using Android.Views.Accessibility; -namespace Microsoft.Maui.Accessibility.Implementations +namespace Microsoft.Maui.Accessibility { - public partial class SemanticScreenReaderImplementation : ISemanticScreenReader + partial class SemanticScreenReaderImplementation : ISemanticScreenReader { public void Announce(string text) { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs index 3386084a8032..72c58ab4584b 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.ios.cs @@ -2,9 +2,9 @@ using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Accessibility.Implementations +namespace Microsoft.Maui.Accessibility { - public partial class SemanticScreenReaderImplementation : ISemanticScreenReader + partial class SemanticScreenReaderImplementation : ISemanticScreenReader { public void Announce(string text) { diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs index 18235e915613..9ecf7981a56b 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.tizen.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Text; -namespace Microsoft.Maui.Accessibility.Implementations +namespace Microsoft.Maui.Accessibility { - public partial class SemanticScreenReaderImplementation : ISemanticScreenReader + partial class SemanticScreenReaderImplementation : ISemanticScreenReader { public void Announce(string text) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs index d77b2e9ff4d9..09e46a388462 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs @@ -1,7 +1,7 @@ #nullable enable using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Accessibility.Implementations; +using Microsoft.Maui.Accessibility; namespace Microsoft.Maui.Accessibility { @@ -9,7 +9,9 @@ public interface ISemanticScreenReader { void Announce(string text); } - +} +namespace Microsoft.Maui.Essentials +{ public static partial class SemanticScreenReader { public static void Announce(string text) @@ -19,12 +21,10 @@ public static void Announce(string text) static ISemanticScreenReader? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static ISemanticScreenReader Current => currentImplementation ??= new SemanticScreenReaderImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(ISemanticScreenReader? implementation) => + internal static void SetCurrent(ISemanticScreenReader? implementation) => currentImplementation = implementation; } } diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs index 78e26786a086..cafb8d9a7fac 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs @@ -3,7 +3,6 @@ using Windows.UI.Xaml.Automation.Peers; using Windows.UI.Xaml.Media; #elif WINDOWS -using Microsoft.Maui.Essentials; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Automation; using Microsoft.UI.Xaml.Automation.Peers; @@ -13,9 +12,9 @@ -namespace Microsoft.Maui.Accessibility.Implementations +namespace Microsoft.Maui.Accessibility { - public partial class SemanticScreenReaderImplementation : ISemanticScreenReader + partial class SemanticScreenReaderImplementation : ISemanticScreenReader { public void Announce(string text) { diff --git a/src/Essentials/src/Share/Share.android.cs b/src/Essentials/src/Share/Share.android.cs index 694056efd345..61ee44fdf14a 100644 --- a/src/Essentials/src/Share/Share.android.cs +++ b/src/Essentials/src/Share/Share.android.cs @@ -2,12 +2,11 @@ using System.Threading.Tasks; using Android.Content; using Android.OS; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Storage; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public class ShareImplementation : IShare + class ShareImplementation : IShare { public Task RequestAsync(ShareTextRequest request) { diff --git a/src/Essentials/src/Share/Share.ios.cs b/src/Essentials/src/Share/Share.ios.cs index 6147c627be94..36ede0320bfc 100644 --- a/src/Essentials/src/Share/Share.ios.cs +++ b/src/Essentials/src/Share/Share.ios.cs @@ -2,15 +2,14 @@ using System.Collections.Generic; using System.Threading.Tasks; using Foundation; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics.Platform; using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public class ShareImplementation : IShare + class ShareImplementation : IShare { public Task RequestAsync(ShareTextRequest request) { diff --git a/src/Essentials/src/Share/Share.macos.cs b/src/Essentials/src/Share/Share.macos.cs index e39a35738a12..5e567533d07a 100644 --- a/src/Essentials/src/Share/Share.macos.cs +++ b/src/Essentials/src/Share/Share.macos.cs @@ -4,9 +4,9 @@ using Foundation; using Microsoft.Maui.Graphics.Platform; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public class ShareImplementation : IShare + class ShareImplementation : IShare { public Task RequestAsync(ShareTextRequest request) { diff --git a/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs b/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs index 2193f2a9b9b7..0fdc5530bd75 100644 --- a/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { /// - public class ShareImplementation : IShare + class ShareImplementation : IShare { public Task RequestAsync(ShareTextRequest request) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Share/Share.shared.cs b/src/Essentials/src/Share/Share.shared.cs index 6672c5601ca0..113e78d4f8e6 100644 --- a/src/Essentials/src/Share/Share.shared.cs +++ b/src/Essentials/src/Share/Share.shared.cs @@ -3,7 +3,7 @@ using System.ComponentModel; using System.Linq; using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.DataTransfer.Implementations; +using Microsoft.Maui.ApplicationModel.DataTransfer; using Microsoft.Maui.Graphics; using Microsoft.Maui.Storage; @@ -14,7 +14,9 @@ public interface IShare Task RequestAsync(ShareTextRequest request); Task RequestAsync(ShareMultipleFilesRequest request); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Share { @@ -71,16 +73,16 @@ static string FileNullExeption(string file) #nullable enable static IShare? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IShare Current => currentImplementation ??= new ShareImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IShare? implementation) => + internal static void SetCurrent(IShare? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.ApplicationModel.DataTransfer +{ /// public abstract class ShareRequestBase { diff --git a/src/Essentials/src/Share/Share.tizen.cs b/src/Essentials/src/Share/Share.tizen.cs index 37335159d06e..afd3a52abd5f 100644 --- a/src/Essentials/src/Share/Share.tizen.cs +++ b/src/Essentials/src/Share/Share.tizen.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Tizen.Applications; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public class ShareImplementation : IShare + class ShareImplementation : IShare { public Task RequestAsync(ShareTextRequest request) { diff --git a/src/Essentials/src/Share/Share.uwp.cs b/src/Essentials/src/Share/Share.uwp.cs index 265c82db7ce2..c30a2a14b388 100644 --- a/src/Essentials/src/Share/Share.uwp.cs +++ b/src/Essentials/src/Share/Share.uwp.cs @@ -2,14 +2,13 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.Maui.Essentials; using Windows.ApplicationModel.DataTransfer; using Windows.Storage; using WinRT; -namespace Microsoft.Maui.ApplicationModel.DataTransfer.Implementations +namespace Microsoft.Maui.ApplicationModel.DataTransfer { - public class ShareImplementation : IShare + class ShareImplementation : IShare { public Task RequestAsync(ShareTextRequest request) { diff --git a/src/Essentials/src/Sms/Sms.android.cs b/src/Essentials/src/Sms/Sms.android.cs index e5be51d69407..8b699f4b4807 100644 --- a/src/Essentials/src/Sms/Sms.android.cs +++ b/src/Essentials/src/Sms/Sms.android.cs @@ -4,13 +4,12 @@ using Android.Content; using Android.OS; using Android.Provider; -using Microsoft.Maui.Essentials; using Microsoft.Maui.Storage; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public class SmsImplementation : ISms + class SmsImplementation : ISms { static readonly string smsRecipientSeparator = ";"; diff --git a/src/Essentials/src/Sms/Sms.ios.cs b/src/Essentials/src/Sms/Sms.ios.cs index 97e2e8a23492..c887760baf0c 100644 --- a/src/Essentials/src/Sms/Sms.ios.cs +++ b/src/Essentials/src/Sms/Sms.ios.cs @@ -2,12 +2,11 @@ using System.Threading.Tasks; #if !(MACCATALYST || MACOS) using MessageUI; -using Microsoft.Maui.Essentials; #endif -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public class SmsImplementation : ISms + class SmsImplementation : ISms { internal static bool IsComposeSupported #if !(MACCATALYST || MACOS) diff --git a/src/Essentials/src/Sms/Sms.macos.cs b/src/Essentials/src/Sms/Sms.macos.cs index 95018298c545..a34941d8ac1d 100644 --- a/src/Essentials/src/Sms/Sms.macos.cs +++ b/src/Essentials/src/Sms/Sms.macos.cs @@ -6,12 +6,12 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - public static partial class Sms + class SmsImplementation : ISms { internal static bool IsComposeSupported => MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString("sms:")) != null); - static Task PlatformComposeAsync(SmsMessage message) + public Task ComposeAsync(SmsMessage message) { var recipients = string.Join(",", message.Recipients.Select(r => Uri.EscapeDataString(r))); diff --git a/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs b/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs index d7b49aeffc60..7808d2215f2a 100644 --- a/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { /// - public class SmsImplementation : ISms + class SmsImplementation : ISms { internal static bool IsComposeSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Sms/Sms.shared.cs b/src/Essentials/src/Sms/Sms.shared.cs index c2c6ce4128ea..50f5b4e093ce 100644 --- a/src/Essentials/src/Sms/Sms.shared.cs +++ b/src/Essentials/src/Sms/Sms.shared.cs @@ -3,7 +3,7 @@ using System.ComponentModel; using System.Linq; using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.Communication.Implementations; +using Microsoft.Maui.ApplicationModel.Communication; namespace Microsoft.Maui.ApplicationModel.Communication { @@ -11,7 +11,9 @@ public interface ISms { Task ComposeAsync(SmsMessage? message); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static class Sms { @@ -33,16 +35,15 @@ public static Task ComposeAsync(SmsMessage message) } static ISms? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static ISms Current => currentImplementation ??= new SmsImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(ISms? implementation) => + internal static void SetCurrent(ISms? implementation) => currentImplementation = implementation; } -#nullable restore - +} +namespace Microsoft.Maui.ApplicationModel.Communication +{ /// public class SmsMessage { @@ -52,15 +53,15 @@ public SmsMessage() } /// - public SmsMessage(string body, string recipient) + public SmsMessage(string body, string? recipient) { Body = body; if (!string.IsNullOrWhiteSpace(recipient)) - Recipients.Add(recipient); + Recipients.Add(recipient!); } /// - public SmsMessage(string body, IEnumerable recipients) + public SmsMessage(string body, IEnumerable? recipients) { Body = body; if (recipients != null) @@ -70,7 +71,7 @@ public SmsMessage(string body, IEnumerable recipients) } /// - public string Body { get; set; } + public string? Body { get; set; } /// public List Recipients { get; set; } = new List(); diff --git a/src/Essentials/src/Sms/Sms.tizen.cs b/src/Essentials/src/Sms/Sms.tizen.cs index 0aa8384f9d2c..a9d6cc126130 100644 --- a/src/Essentials/src/Sms/Sms.tizen.cs +++ b/src/Essentials/src/Sms/Sms.tizen.cs @@ -3,12 +3,12 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - public static partial class Sms + class SmsImplementation : ISms { internal static bool IsComposeSupported => Platform.GetFeatureInfo("network.telephony.sms"); - static Task PlatformComposeAsync(SmsMessage message) + public Task ComposeAsync(SmsMessage message) { Permissions.EnsureDeclared(); diff --git a/src/Essentials/src/Sms/Sms.uwp.cs b/src/Essentials/src/Sms/Sms.uwp.cs index 44f320082a56..362035c76ec6 100644 --- a/src/Essentials/src/Sms/Sms.uwp.cs +++ b/src/Essentials/src/Sms/Sms.uwp.cs @@ -3,9 +3,9 @@ using Windows.ApplicationModel.Chat; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.ApplicationModel.Communication.Implementations +namespace Microsoft.Maui.ApplicationModel.Communication { - public class SmsImplementation:ISms + class SmsImplementation : ISms { internal static bool IsComposeSupported => ApiInformation.IsTypePresent("Windows.ApplicationModel.Chat.ChatMessageManager"); diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs index 7694a900b7aa..784b329a059a 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs @@ -6,14 +6,13 @@ using System.Threading.Tasks; using Android.OS; using Android.Speech.Tts; -using Microsoft.Maui.Essentials; using AndroidTextToSpeech = Android.Speech.Tts.TextToSpeech; using Debug = System.Diagnostics.Debug; using JavaLocale = Java.Util.Locale; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class TextToSpeechImplementation : ITextToSpeech + partial class TextToSpeechImplementation : ITextToSpeech { const int maxSpeechInputLengthDefault = 4000; diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs index 520811a08db0..3a5024bc156c 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs @@ -5,9 +5,9 @@ using System.Threading.Tasks; using AVFoundation; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class TextToSpeechImplementation : ITextToSpeech + partial class TextToSpeechImplementation : ITextToSpeech { static readonly Lazy speechSynthesizer = new Lazy(); diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs index a0619ac8c710..03cf9db7bcd0 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs @@ -5,9 +5,9 @@ using System.Threading.Tasks; using AppKit; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class TextToSpeechImplementation : ITextToSpeech + partial class TextToSpeechImplementation : ITextToSpeech { static readonly Lazy speechSynthesizer = new Lazy(() => new NSSpeechSynthesizer { Delegate = new SpeechSynthesizerDelegate() }); diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs index 31416f584eb3..579511e7394c 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs @@ -2,10 +2,10 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { /// - public partial class TextToSpeechImplementation : ITextToSpeech + partial class TextToSpeechImplementation : ITextToSpeech { public Task SpeakAsync(string text, CancellationToken cancelToken) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs index 55793f613258..f87d9d16e153 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using System.ComponentModel; using Microsoft.Maui.Media; -using Microsoft.Maui.Media.Implementations; namespace Microsoft.Maui.Media { @@ -17,7 +16,9 @@ public interface ITextToSpeech Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken); } - +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class TextToSpeech { @@ -81,19 +82,17 @@ internal static float Normalize(float min, float max, float percent) #nullable enable static ITextToSpeech? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static ITextToSpeech Current => currentImplementation ??= new TextToSpeechImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(ITextToSpeech? implementation) => + internal static void SetCurrent(ITextToSpeech? implementation) => currentImplementation = implementation; #nullable disable } - +} +namespace Microsoft.Maui.Media +{ /// public class Locale { diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs index be2ca286994c..9f68df593dc4 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs @@ -4,9 +4,9 @@ using System.Threading.Tasks; using Tizen.Uix.Tts; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class TextToSpeechImplementation : ITextToSpeech + partial class TextToSpeechImplementation : ITextToSpeech { static TtsClient tts = null; static TaskCompletionSource tcsInitialize = null; diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs index ea01b14d0cdd..2c56e1b1cffc 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs @@ -10,9 +10,9 @@ using Windows.Media.Playback; using Windows.Media.SpeechSynthesis; -namespace Microsoft.Maui.Media.Implementations +namespace Microsoft.Maui.Media { - public partial class TextToSpeechImplementation : ITextToSpeech + partial class TextToSpeechImplementation : ITextToSpeech { public Task> GetLocalesAsync() => Task.FromResult(SpeechSynthesizer.AllVoices.Select(v => new Locale(v.Language, null, v.DisplayName, v.Id))); diff --git a/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs index 61887beccce4..19246cc0f5cb 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs @@ -3,7 +3,7 @@ namespace Microsoft.Maui.Media { - internal static partial class TextToSpeechExtensions + static partial class TextToSpeechExtensions { internal static List SplitSpeak(this string text, int max) { diff --git a/src/Essentials/src/Types/FileProvider.android.cs b/src/Essentials/src/Types/FileProvider.android.cs index 5df623366533..1ac727d94c81 100644 --- a/src/Essentials/src/Types/FileProvider.android.cs +++ b/src/Essentials/src/Types/FileProvider.android.cs @@ -3,7 +3,6 @@ using Android.App; using Android.Content; using Android.OS; -using Microsoft.Maui.Essentials; using AndroidEnvironment = Android.OS.Environment; using AndroidUri = Android.Net.Uri; using ContentFileProvider = AndroidX.Core.Content.FileProvider; diff --git a/src/Essentials/src/Types/Location.shared.cs b/src/Essentials/src/Types/Location.shared.cs index cbc5eb0a74db..2895448502dd 100644 --- a/src/Essentials/src/Types/Location.shared.cs +++ b/src/Essentials/src/Types/Location.shared.cs @@ -1,5 +1,4 @@ using System; -using Microsoft.Maui.Essentials; using static System.Math; namespace Microsoft.Maui.Devices.Sensors diff --git a/src/Essentials/src/Types/LocationExtensions.android.cs b/src/Essentials/src/Types/LocationExtensions.android.cs index 39270357308c..9d237c923747 100644 --- a/src/Essentials/src/Types/LocationExtensions.android.cs +++ b/src/Essentials/src/Types/LocationExtensions.android.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.Maui.Essentials; using AndroidAddress = Android.Locations.Address; using AndroidLocation = Android.Locations.Location; diff --git a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs index 7a0decc9bc4b..55645cabc5a0 100644 --- a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs +++ b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using Microsoft.Maui.Storage; +using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.ApplicationModel { @@ -37,7 +38,10 @@ public interface IVersionTracking bool IsFirstLaunchForBuild(string build); } +} +namespace Microsoft.Maui.Essentials +{ /// public static class VersionTracking { @@ -104,20 +108,18 @@ public static bool IsFirstLaunchForBuild(string build) #nullable enable static IVersionTracking? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IVersionTracking Current => - currentImplementation ??= new Implementations.VersionTrackingImplementation(); + currentImplementation ??= new VersionTrackingImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IVersionTracking? implementation) => + internal static void SetCurrent(IVersionTracking? implementation) => currentImplementation = implementation; #nullable disable } } -namespace Microsoft.Maui.ApplicationModel.Implementations +namespace Microsoft.Maui.ApplicationModel { - public class VersionTrackingImplementation : IVersionTracking + class VersionTrackingImplementation : IVersionTracking { const string versionTrailKey = "VersionTracking.Trail"; const string versionsKey = "VersionTracking.Versions"; diff --git a/src/Essentials/src/Vibration/Vibration.android.cs b/src/Essentials/src/Vibration/Vibration.android.cs index 597cbece9e72..34c68a452a10 100644 --- a/src/Essentials/src/Vibration/Vibration.android.cs +++ b/src/Essentials/src/Vibration/Vibration.android.cs @@ -3,12 +3,11 @@ using Android; using Android.OS; using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Essentials; #endif -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class VibrationImplementation : IVibration + partial class VibrationImplementation : IVibration { public bool IsSupported => true; diff --git a/src/Essentials/src/Vibration/Vibration.ios.cs b/src/Essentials/src/Vibration/Vibration.ios.cs index 4a401a33adee..d785ce66828f 100644 --- a/src/Essentials/src/Vibration/Vibration.ios.cs +++ b/src/Essentials/src/Vibration/Vibration.ios.cs @@ -1,9 +1,9 @@ using System; using AudioToolbox; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class VibrationImplementation : IVibration + partial class VibrationImplementation : IVibration { public bool IsSupported => true; diff --git a/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs b/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs index bfff90e12c4c..d87c5def510e 100644 --- a/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs +++ b/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs @@ -1,9 +1,9 @@ using System; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class VibrationImplementation : IVibration /// + partial class VibrationImplementation : IVibration { public bool IsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/Vibration/Vibration.shared.cs b/src/Essentials/src/Vibration/Vibration.shared.cs index afd34ed470e8..4b73b297a16b 100644 --- a/src/Essentials/src/Vibration/Vibration.shared.cs +++ b/src/Essentials/src/Vibration/Vibration.shared.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel; using Microsoft.Maui.Devices; -using Microsoft.Maui.Devices.Implementations; namespace Microsoft.Maui.Devices { @@ -17,7 +16,10 @@ public interface IVibration void Cancel(); } +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class Vibration { @@ -54,15 +56,11 @@ public static void Cancel() #nullable enable static IVibration? currentImplementation; -#nullable disable - [EditorBrowsable(EditorBrowsableState.Never)] public static IVibration Current => currentImplementation ??= new VibrationImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IVibration? implementation) => + internal static void SetCurrent(IVibration? implementation) => currentImplementation = implementation; #nullable disable } diff --git a/src/Essentials/src/Vibration/Vibration.tizen.cs b/src/Essentials/src/Vibration/Vibration.tizen.cs index 1e48e65a0f5d..e2331210918e 100644 --- a/src/Essentials/src/Vibration/Vibration.tizen.cs +++ b/src/Essentials/src/Vibration/Vibration.tizen.cs @@ -2,9 +2,9 @@ using System.Linq; using Tizen.System; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class VibrationImplementation : IVibration + partial class VibrationImplementation : IVibration { public bool IsSupported => Vibrator.NumberOfVibrators > 0; diff --git a/src/Essentials/src/Vibration/Vibration.uwp.cs b/src/Essentials/src/Vibration/Vibration.uwp.cs index 73b82d545efa..cfcf3b0dd827 100644 --- a/src/Essentials/src/Vibration/Vibration.uwp.cs +++ b/src/Essentials/src/Vibration/Vibration.uwp.cs @@ -2,9 +2,9 @@ using Windows.Devices.Haptics; using Windows.Foundation.Metadata; -namespace Microsoft.Maui.Devices.Implementations +namespace Microsoft.Maui.Devices { - public partial class VibrationImplementation : IVibration + partial class VibrationImplementation : IVibration { public bool IsSupported => ApiInformation.IsTypePresent("Windows.Phone.Devices.Notification.VibrationDevice") && DefaultDevice != null; diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs index de096332342c..4c7b2e07a86e 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs @@ -4,17 +4,16 @@ using System.Threading.Tasks; using AuthenticationServices; using Foundation; -using Microsoft.Maui.Essentials; using ObjCRuntime; using UIKit; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { public partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator { AuthManager authManager; - public async Task AuthenticateAsync(AppleSignInAuthenticator.Options options) + public async Task AuthenticateAsync(AppleSignInAuthenticatorOptions options) { if (!OperatingSystem.IsIOSVersionAtLeast(13)) throw new FeatureNotSupportedException(); diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs index 9429d3fb41f9..4ffaca22ae2f 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs @@ -2,14 +2,13 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { /// public partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator { - public Task AuthenticateAsync(AppleSignInAuthenticator.Options options) => + public Task AuthenticateAsync(AppleSignInAuthenticatorOptions options) => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs index 8272a127b133..0c397c1997ae 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs @@ -4,38 +4,38 @@ using System.Threading.Tasks; using System.ComponentModel; using Microsoft.Maui.Authentication; -using Microsoft.Maui.Authentication.Implementations; namespace Microsoft.Maui.Authentication { public interface IAppleSignInAuthenticator { - Task AuthenticateAsync(AppleSignInAuthenticator.Options options = null); + Task AuthenticateAsync(AppleSignInAuthenticatorOptions options = null); } + public class AppleSignInAuthenticatorOptions + { + public bool IncludeFullNameScope { get; set; } = false; + + public bool IncludeEmailScope { get; set; } = false; + } +} + +namespace Microsoft.Maui.Essentials +{ /// public static class AppleSignInAuthenticator { /// - public static Task AuthenticateAsync(Options options = null) - => Current.AuthenticateAsync(options ?? new AppleSignInAuthenticator.Options()); - - public class Options - { - public bool IncludeFullNameScope { get; set; } = false; - - public bool IncludeEmailScope { get; set; } = false; - } + public static Task AuthenticateAsync(AppleSignInAuthenticatorOptions options = null) + => Current.AuthenticateAsync(options ?? new AppleSignInAuthenticatorOptions()); #nullable enable static IAppleSignInAuthenticator? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IAppleSignInAuthenticator Current => currentImplementation ??= new AppleSignInAuthenticatorImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IAppleSignInAuthenticator? implementation) => + internal static void SetCurrent(IAppleSignInAuthenticator? implementation) => currentImplementation = implementation; #nullable disable } diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs index ae5d370a823a..5aeaf9633ecf 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs @@ -2,11 +2,10 @@ using System.Threading.Tasks; using Android.Content; using AndroidX.Browser.CustomTabs; -using Microsoft.Maui.Essentials; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { - public partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback + partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback { TaskCompletionSource tcsResponse = null; Uri currentRedirectUri = null; diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs index 03554945d45a..24ac016e396d 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.ios.tvos.cs @@ -11,13 +11,12 @@ using ObjCRuntime; using UIKit; using WebKit; -using Microsoft.Maui.Authentication.Implementations; -using Microsoft.Maui.Essentials; -using Microsoft.Maui.ApplicationModel.Implementations; +using Microsoft.Maui.Authentication; +using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { - public partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback + partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback { #if __IOS__ const int asWebAuthenticationSessionErrorCodeCanceledLogin = 1; diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs index a0633d23a727..5bb5812edf43 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.macos.cs @@ -4,9 +4,9 @@ using AuthenticationServices; using Foundation; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { - public partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback + partial class WebAuthenticatorImplementation : IWebAuthenticator, IPlatformWebAuthenticatorCallback { const int asWebAuthenticationSessionErrorCodeCanceledLogin = 1; const string asWebAuthenticationSessionErrorDomain = "com.apple.AuthenticationServices.WebAuthenticationSession"; diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs index da7d1eeaf14b..1b7bc545ce37 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs @@ -3,10 +3,10 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { /// - public partial class WebAuthenticatorImplementation : IWebAuthenticator + partial class WebAuthenticatorImplementation : IWebAuthenticator { public Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs index bc6278e8691a..8dfa31df61b1 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using System.ComponentModel; using Microsoft.Maui.Authentication; -using Microsoft.Maui.Authentication.Implementations; namespace Microsoft.Maui.Authentication { @@ -24,7 +23,10 @@ public interface IPlatformWebAuthenticatorCallback bool OnResumeCallback(global::Android.Content.Intent intent); #endif } +} +namespace Microsoft.Maui.Essentials +{ /// public static partial class WebAuthenticator { @@ -55,16 +57,17 @@ internal static bool OnResume(global::Android.Content.Intent intent) #nullable enable static IWebAuthenticator? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IWebAuthenticator Current => currentImplementation ??= new WebAuthenticatorImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IWebAuthenticator? implementation) => + internal static void SetCurrent(IWebAuthenticator? implementation) => currentImplementation = implementation; #nullable disable } +} +namespace Microsoft.Maui.Authentication +{ public class WebAuthenticatorOptions { public Uri Url { get; set; } @@ -73,10 +76,7 @@ public class WebAuthenticatorOptions public bool PrefersEphemeralWebBrowserSession { get; set; } } -} -namespace Microsoft.Maui.Authentication.Implementations -{ public partial class WebAuthenticatorImplementation { public Task AuthenticateAsync(Uri url, Uri callbackUrl) diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs index f7c26073a94b..1e5c6491882f 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.uwp.cs @@ -8,12 +8,11 @@ using System.Xml; using System.Xml.Linq; using System.Xml.XPath; -using Microsoft.Maui.Essentials; using Windows.Security.Authentication.Web; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { - public partial class WebAuthenticatorImplementation : IWebAuthenticator + partial class WebAuthenticatorImplementation : IWebAuthenticator { public async Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) { diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs index d5fd8179cc87..62a9379b3567 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs @@ -11,7 +11,7 @@ protected override void OnCreate(Bundle savedInstanceState) base.OnCreate(savedInstanceState); // start the intermediate activity again with flags to close the custom tabs - var intent = new Intent(this, typeof(Implementations.WebAuthenticatorIntermediateActivity)); + var intent = new Intent(this, typeof(WebAuthenticatorIntermediateActivity)); intent.SetData(Intent.Data); intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop); StartActivity(intent); diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs index 45501b9b994b..6f3904a00d50 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticatorIntermediateActivity.android.cs @@ -3,7 +3,7 @@ using Android.Content.PM; using Android.OS; -namespace Microsoft.Maui.Authentication.Implementations +namespace Microsoft.Maui.Authentication { [Activity(ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, Exported = true)] class WebAuthenticatorIntermediateActivity : Activity From 0c54a818d0c8c5b809e08faceaf5ec3ab1b9027c Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sat, 19 Mar 2022 06:17:19 +0200 Subject: [PATCH 03/45] moar --- .../Core/src/Essentials/Clipboard.cs | 9 ++- .../Core/src/Essentials/Compass.cs | 54 +++++++++++++ .../Accelerometer/Accelerometer.android.cs | 42 +++++------ .../src/Barometer/Barometer.android.cs | 46 ++++++------ .../src/Barometer/Barometer.ios.watchos.cs | 2 +- .../Barometer.netstandard.tvos.macos.cs | 2 +- .../src/Barometer/Barometer.shared.cs | 5 +- .../src/Barometer/Barometer.tizen.cs | 2 +- src/Essentials/src/Barometer/Barometer.uwp.cs | 2 +- .../src/Clipboard/Clipboard.android.cs | 4 +- src/Essentials/src/Clipboard/Clipboard.ios.cs | 20 +++-- .../src/Clipboard/Clipboard.macos.cs | 4 +- ...lipboard.netstandard.tvos.watchos.tizen.cs | 9 ++- src/Essentials/src/Clipboard/Clipboard.uwp.cs | 13 ++-- src/Essentials/src/Compass/Compass.android.cs | 34 +++++---- src/Essentials/src/Compass/Compass.shared.cs | 75 +++---------------- 16 files changed, 167 insertions(+), 156 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/Compass.cs diff --git a/src/Compatibility/Core/src/Essentials/Clipboard.cs b/src/Compatibility/Core/src/Essentials/Clipboard.cs index b5dd9296b4d6..5fa66e4a21c5 100644 --- a/src/Compatibility/Core/src/Essentials/Clipboard.cs +++ b/src/Compatibility/Core/src/Essentials/Clipboard.cs @@ -8,10 +8,10 @@ namespace Microsoft.Maui.Essentials /// public static partial class Clipboard { - static event EventHandler ClipboardContentChangedInternal; + static event EventHandler? ClipboardContentChangedInternal; /// - public static Task SetTextAsync(string text) + public static Task SetTextAsync(string? text) => Current.SetTextAsync(text ?? string.Empty); /// @@ -19,7 +19,7 @@ public static bool HasText => Current.HasText; /// - public static Task GetTextAsync() + public static Task GetTextAsync() => Current.GetTextAsync(); public static event EventHandler ClipboardContentChanged @@ -39,5 +39,8 @@ public static event EventHandler ClipboardContentChanged } static IClipboard Current => ApplicationModel.DataTransfer.Clipboard.Default; + + static void OnClipboardContentChanged(object? sender, EventArgs e) => + ClipboardContentChangedInternal?.Invoke(sender, e); } } diff --git a/src/Compatibility/Core/src/Essentials/Compass.cs b/src/Compatibility/Core/src/Essentials/Compass.cs new file mode 100644 index 000000000000..64abcfa43908 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Compass.cs @@ -0,0 +1,54 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Compass + { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + /// + public static bool IsSupported + => Current.IsSupported; + + public static bool IsMonitoring + => Current.IsMonitoring; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Start(sensorSpeed, true); + + /// + public static void Start(SensorSpeed sensorSpeed, bool applyLowPassFilter) + => Current.Start(sensorSpeed, applyLowPassFilter); + + /// + public static void Stop() + => Current.Stop(); + +#if IOS || MACCATALYST + public static bool ShouldDisplayHeadingCalibration + { + get + { + if (Current is IPlatformCompass c) + return c.ShouldDisplayHeadingCalibration; + return false; + } + set + { + if (Current is IPlatformCompass c) + c.ShouldDisplayHeadingCalibration = value; + } + } +#endif + + static ICompass Current => Devices.Sensors.Compass.Default; + } +} diff --git a/src/Essentials/src/Accelerometer/Accelerometer.android.cs b/src/Essentials/src/Accelerometer/Accelerometer.android.cs index 848244dd45ae..2e2ac279f8ed 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.android.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.android.cs @@ -9,40 +9,32 @@ namespace Microsoft.Maui.Devices.Sensors partial class AccelerometerImplementation { static SensorManager? _sensorManager; + static Sensor? _accelerometer; static SensorManager? SensorManager => _sensorManager ??= Application.Context.GetSystemService(Context.SensorService) as SensorManager; - public bool IsSupported => - SensorManager?.GetDefaultSensor(SensorType.Accelerometer) != null; + static Sensor? Sensor => + _accelerometer ??= SensorManager?.GetDefaultSensor(SensorType.Accelerometer); - AccelerometerListener? listener; - Sensor? accelerometer; + public bool IsSupported => Sensor is not null; + + AccelerometerListener? _listener; void PlatformStart(SensorSpeed sensorSpeed) { - if (SensorManager is null) - return; + _listener = new AccelerometerListener(this); - accelerometer = SensorManager.GetDefaultSensor(SensorType.Accelerometer); - if (accelerometer is not null) - { - listener = new AccelerometerListener(this); - - var delay = sensorSpeed.ToPlatform(); - SensorManager.RegisterListener(listener, accelerometer, delay); - } + var delay = sensorSpeed.ToPlatform(); + SensorManager!.RegisterListener(_listener, Sensor, delay); } void PlatformStop() { - if (listener == null || accelerometer == null) - return; + SensorManager!.UnregisterListener(_listener, Sensor); - SensorManager?.UnregisterListener(listener, accelerometer); - - listener.Dispose(); - listener = null; + _listener!.Dispose(); + _listener = null; } } @@ -51,13 +43,13 @@ class AccelerometerListener : Java.Lang.Object, ISensorEventListener // acceleration due to gravity const double gravity = 9.81; - AccelerometerImplementation _accelerometer; - - internal AccelerometerListener(AccelerometerImplementation accelerometer) + public AccelerometerListener(Action changeHandler) { - _accelerometer = accelerometer; + ChangeHandler = changeHandler; } + public readonly Action ChangeHandler; + void ISensorEventListener.OnAccuracyChanged(Sensor? sensor, SensorStatus accuracy) { } @@ -69,7 +61,7 @@ void ISensorEventListener.OnSensorChanged(SensorEvent? e) return; var data = new AccelerometerData(values[0] / gravity, values[1] / gravity, values[2] / gravity); - _accelerometer.OnChanged(data); + ChangeHandler?.Invoke(data); } } } diff --git a/src/Essentials/src/Barometer/Barometer.android.cs b/src/Essentials/src/Barometer/Barometer.android.cs index c2aa761a8c00..58499c2e94cd 100644 --- a/src/Essentials/src/Barometer/Barometer.android.cs +++ b/src/Essentials/src/Barometer/Barometer.android.cs @@ -1,36 +1,37 @@ +#nullable enable using System; +using Android.App; +using Android.Content; using Android.Hardware; -using Android.Runtime; namespace Microsoft.Maui.Devices.Sensors { partial class BarometerImplementation : IBarometer { - Sensor DefaultBarometer - => Platform.SensorManager?.GetDefaultSensor(SensorType.Pressure); - - Sensor barometer; - BarometerListener listener; + static SensorManager? _sensorManager; + static Sensor? _sensor; - bool PlatformIsSupported - => DefaultBarometer != null; + static SensorManager? SensorManager => + _sensorManager ??= Application.Context.GetSystemService(Context.SensorService) as SensorManager; + + static Sensor? Sensor => + _sensor ??= SensorManager?.GetDefaultSensor(SensorType.Accelerometer); + + public bool IsSupported => Sensor is not null; + + BarometerListener? _listener; void PlatformStart(SensorSpeed sensorSpeed) { - listener = new BarometerListener(RaiseReadingChanged); - barometer = DefaultBarometer; - Platform.SensorManager.RegisterListener(listener, barometer, sensorSpeed.ToPlatform()); + _listener = new BarometerListener(RaiseReadingChanged); + SensorManager!.RegisterListener(_listener, Sensor, sensorSpeed.ToPlatform()); } void PlatformStop() { - if (listener == null) - return; - - Platform.SensorManager.UnregisterListener(listener, barometer); - listener.Dispose(); - listener = null; - barometer = null; + SensorManager!.UnregisterListener(_listener, Sensor); + _listener!.Dispose(); + _listener = null; } } @@ -43,16 +44,17 @@ public BarometerListener(Action changeHandler) public readonly Action ChangeHandler; - void ISensorEventListener.OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy) + void ISensorEventListener.OnAccuracyChanged(Sensor? sensor, SensorStatus accuracy) { } - void ISensorEventListener.OnSensorChanged(SensorEvent e) + void ISensorEventListener.OnSensorChanged(SensorEvent? e) { - if ((e?.Values?.Count ?? 0) <= 0) + var values = e?.Values ?? Array.Empty(); + if (values.Count < 1) return; - ChangeHandler?.Invoke(new BarometerData(e.Values[0])); + ChangeHandler?.Invoke(new BarometerData(values[0])); } } } diff --git a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs index c8c772ee2ec9..372ed6ce52a2 100644 --- a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs +++ b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs @@ -8,7 +8,7 @@ partial class BarometerImplementation : IBarometer { CMAltimeter altitudeManager; - bool PlatformIsSupported + public bool IsSupported => CMAltimeter.IsRelativeAltitudeAvailable; void PlatformStart(SensorSpeed sensorSpeed) diff --git a/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs b/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs index 1a7ce57834aa..93b7a865d7e2 100644 --- a/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Barometer/Barometer.netstandard.tvos.macos.cs @@ -10,7 +10,7 @@ void PlatformStart(SensorSpeed sensorSpeed) void PlatformStop() => throw ExceptionUtils.NotSupportedOrImplementedException; - bool PlatformIsSupported + public bool IsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Barometer/Barometer.shared.cs b/src/Essentials/src/Barometer/Barometer.shared.cs index 95bfccd58222..5435709bc684 100644 --- a/src/Essentials/src/Barometer/Barometer.shared.cs +++ b/src/Essentials/src/Barometer/Barometer.shared.cs @@ -80,12 +80,9 @@ partial class BarometerImplementation : IBarometer bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; #pragma warning disable CS0067 - public event EventHandler ReadingChanged; + public event EventHandler? ReadingChanged; #pragma warning restore CS0067 - public bool IsSupported - => PlatformIsSupported; - public bool IsMonitoring { get; private set; } public SensorSpeed SensorSpeed { get; private set; } = SensorSpeed.Default; diff --git a/src/Essentials/src/Barometer/Barometer.tizen.cs b/src/Essentials/src/Barometer/Barometer.tizen.cs index dfbc29993fb2..fd4f95478a2e 100644 --- a/src/Essentials/src/Barometer/Barometer.tizen.cs +++ b/src/Essentials/src/Barometer/Barometer.tizen.cs @@ -6,7 +6,7 @@ namespace Microsoft.Maui.Devices.Sensors { class BarometerImplementation : IBarometer { - bool PlatformIsSupported + public bool IsSupported => TizenBarometerSensor.IsSupported; TizenBarometerSensor DefaultSensor diff --git a/src/Essentials/src/Barometer/Barometer.uwp.cs b/src/Essentials/src/Barometer/Barometer.uwp.cs index 7b77c67fcc43..862a93a5627f 100644 --- a/src/Essentials/src/Barometer/Barometer.uwp.cs +++ b/src/Essentials/src/Barometer/Barometer.uwp.cs @@ -10,7 +10,7 @@ partial class BarometerImplementation : IBarometer WinBarometer DefaultBarometer => WinBarometer.GetDefault(); - bool PlatformIsSupported => + public bool IsSupported => DefaultBarometer != null; void PlatformStart(SensorSpeed sensorSpeed) diff --git a/src/Essentials/src/Clipboard/Clipboard.android.cs b/src/Essentials/src/Clipboard/Clipboard.android.cs index 028d12778a0c..79b3973447b5 100644 --- a/src/Essentials/src/Clipboard/Clipboard.android.cs +++ b/src/Essentials/src/Clipboard/Clipboard.android.cs @@ -34,10 +34,10 @@ ClipboardManager is not null && public Task GetTextAsync() => Task.FromResult(ClipboardManager?.PrimaryClip?.GetItemAt(0)?.Text); - public void StartClipboardListeners() + void StartClipboardListeners() => ClipboardManager?.AddPrimaryClipChangedListener(ClipboardListener); - public void StopClipboardListeners() + void StopClipboardListeners() => ClipboardManager?.RemovePrimaryClipChangedListener(ClipboardListener); } diff --git a/src/Essentials/src/Clipboard/Clipboard.ios.cs b/src/Essentials/src/Clipboard/Clipboard.ios.cs index 94b9206da58a..cd0c6858b212 100644 --- a/src/Essentials/src/Clipboard/Clipboard.ios.cs +++ b/src/Essentials/src/Clipboard/Clipboard.ios.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Threading.Tasks; using Foundation; @@ -8,31 +9,34 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer { partial class ClipboardImplementation : IClipboard { - public Task SetTextAsync(string text) + NSObject? observer; + + public Task SetTextAsync(string? text) { UIPasteboard.General.String = text; return Task.CompletedTask; } - NSObject observer; - public bool HasText => UIPasteboard.General.HasStrings; - public Task GetTextAsync() + public Task GetTextAsync() => Task.FromResult(UIPasteboard.General.String); - public void StartClipboardListeners() + void StartClipboardListeners() { observer = NSNotificationCenter.DefaultCenter.AddObserver( UIPasteboard.ChangedNotification, ClipboardChangedObserver); } - public void StopClipboardListeners() - => NSNotificationCenter.DefaultCenter.RemoveObserver(observer); + void StopClipboardListeners() + { + if (observer is not null) + NSNotificationCenter.DefaultCenter.RemoveObserver(observer); + } public void ClipboardChangedObserver(NSNotification notification) - => Clipboard.ClipboardChangedInternal(); + => OnClipboardContentChanged(); } } diff --git a/src/Essentials/src/Clipboard/Clipboard.macos.cs b/src/Essentials/src/Clipboard/Clipboard.macos.cs index 437281bf012f..d1e3ed0b66b7 100644 --- a/src/Essentials/src/Clipboard/Clipboard.macos.cs +++ b/src/Essentials/src/Clipboard/Clipboard.macos.cs @@ -32,10 +32,10 @@ string GetPasteboardText() new ObjCRuntime.Class[] { new ObjCRuntime.Class(typeof(NSString)) }, null)?[0]?.ToString(); - internal void StartClipboardListeners() + void StartClipboardListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; - internal void StopClipboardListeners() + void StopClipboardListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs b/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs index 521bf47079c1..f4a678bd5dd9 100644 --- a/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs +++ b/src/Essentials/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs @@ -1,3 +1,4 @@ +#nullable enable using System.Threading.Tasks; namespace Microsoft.Maui.ApplicationModel.DataTransfer @@ -5,19 +6,19 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer /// partial class ClipboardImplementation : IClipboard { - public Task SetTextAsync(string text) + public Task SetTextAsync(string? text) => throw ExceptionUtils.NotSupportedOrImplementedException; public bool HasText => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task GetTextAsync() + public Task GetTextAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; - public void StartClipboardListeners() + void StartClipboardListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; - public void StopClipboardListeners() + void StopClipboardListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Clipboard/Clipboard.uwp.cs b/src/Essentials/src/Clipboard/Clipboard.uwp.cs index 76623e21fc00..6b1194e3595d 100644 --- a/src/Essentials/src/Clipboard/Clipboard.uwp.cs +++ b/src/Essentials/src/Clipboard/Clipboard.uwp.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Threading.Tasks; using Windows.ApplicationModel.DataTransfer; @@ -8,7 +9,7 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer { partial class ClipboardImplementation : IClipboard { - public Task SetTextAsync(string text) + public Task SetTextAsync(string? text) { var dataPackage = new DataPackage(); dataPackage.SetText(text); @@ -19,20 +20,20 @@ public Task SetTextAsync(string text) public bool HasText => WindowsClipboard.GetContent().Contains(StandardDataFormats.Text); - public Task GetTextAsync() + public Task GetTextAsync() { var clipboardContent = WindowsClipboard.GetContent(); return clipboardContent.Contains(StandardDataFormats.Text) ? clipboardContent.GetTextAsync().AsTask() - : Task.FromResult(null); + : Task.FromResult(null); } - public void StartClipboardListeners() + void StartClipboardListeners() => WindowsClipboard.ContentChanged += ClipboardChangedEventListener; - public void StopClipboardListeners() + void StopClipboardListeners() => WindowsClipboard.ContentChanged -= ClipboardChangedEventListener; - public void ClipboardChangedEventListener(object sender, object val) => Clipboard.ClipboardChangedInternal(); + public void ClipboardChangedEventListener(object? sender, object val) => OnClipboardContentChanged(); } } diff --git a/src/Essentials/src/Compass/Compass.android.cs b/src/Essentials/src/Compass/Compass.android.cs index 992e456b6cf4..e4812170e1be 100644 --- a/src/Essentials/src/Compass/Compass.android.cs +++ b/src/Essentials/src/Compass/Compass.android.cs @@ -1,27 +1,35 @@ using System; +using Android.App; +using Android.Content; using Android.Hardware; -using Android.Runtime; namespace Microsoft.Maui.Devices.Sensors { partial class CompassImplementation : ICompass { - bool PlatformIsSupported => - Platform.SensorManager?.GetDefaultSensor(SensorType.Accelerometer) != null && - Platform.SensorManager?.GetDefaultSensor(SensorType.MagneticField) != null; + static SensorManager _sensorManager; + static Sensor _accelerometer; + static Sensor _magnetic; + + static SensorManager SensorManager => + _sensorManager ??= Application.Context.GetSystemService(Context.SensorService) as SensorManager; + + static Sensor Accelerometer => + _accelerometer ??= SensorManager?.GetDefaultSensor(SensorType.Accelerometer); + + static Sensor MagneticField => + _magnetic ??= SensorManager?.GetDefaultSensor(SensorType.MagneticField); + + bool PlatformIsSupported => Accelerometer is not null && MagneticField is not null; SensorListener listener; - Sensor magnetometer; - Sensor accelerometer; void PlatformStart(SensorSpeed sensorSpeed, bool applyLowPassFilter) { var delay = sensorSpeed.ToPlatform(); - accelerometer = Platform.SensorManager.GetDefaultSensor(SensorType.Accelerometer); - magnetometer = Platform.SensorManager.GetDefaultSensor(SensorType.MagneticField); - listener = new SensorListener(accelerometer.Name, magnetometer.Name, delay, applyLowPassFilter, RaiseReadingChanged); - Platform.SensorManager.RegisterListener(listener, accelerometer, delay); - Platform.SensorManager.RegisterListener(listener, magnetometer, delay); + listener = new SensorListener(Accelerometer.Name, MagneticField.Name, delay, applyLowPassFilter, RaiseReadingChanged); + SensorManager.RegisterListener(listener, Accelerometer, delay); + SensorManager.RegisterListener(listener, MagneticField, delay); } void PlatformStop() @@ -29,8 +37,8 @@ void PlatformStop() if (listener == null) return; - Platform.SensorManager.UnregisterListener(listener, accelerometer); - Platform.SensorManager.UnregisterListener(listener, magnetometer); + SensorManager.UnregisterListener(listener, Accelerometer); + SensorManager.UnregisterListener(listener, MagneticField); listener.Dispose(); listener = null; } diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index cd331b34e006..82610d5c7c91 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -1,7 +1,5 @@ +#nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Devices.Sensors; namespace Microsoft.Maui.Devices.Sensors { @@ -16,7 +14,7 @@ public interface ICompass void Start(SensorSpeed sensorSpeed); void Start(SensorSpeed sensorSpeed, bool applyLowPassFilter); - + void Stop(); event EventHandler ReadingChanged; @@ -28,67 +26,18 @@ public interface IPlatformCompass bool ShouldDisplayHeadingCalibration { get; set; } #endif } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Compass - { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - /// - public static bool IsSupported - => Current.IsSupported; - - public static bool IsMonitoring - => Current.IsMonitoring; - - /// - public static void Start(SensorSpeed sensorSpeed) => Start(sensorSpeed, true); - - /// - public static void Start(SensorSpeed sensorSpeed, bool applyLowPassFilter) - => Current.Start(sensorSpeed, applyLowPassFilter); - - /// - public static void Stop() - => Current.Stop(); - -#if IOS || MACCATALYST - public static bool ShouldDisplayHeadingCalibration - { - get - { - if (Current is IPlatformCompass c) - return c.ShouldDisplayHeadingCalibration; - return false; - } - set - { - if (Current is IPlatformCompass c) - c.ShouldDisplayHeadingCalibration = value; - } - } -#endif -#nullable enable - static ICompass? currentImplementation; + public static class Compass + { + static ICompass? defaultImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] - public static ICompass Current => - currentImplementation ??= new CompassImplementation(); + public static ICompass Default => + defaultImplementation ??= new CompassImplementation(); - internal static void SetCurrent(ICompass? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(ICompass? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.Devices.Sensors -{ + /// public class CompassChangedEventArgs : EventArgs { @@ -137,7 +86,7 @@ partial class CompassImplementation : ICompass { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; - public event EventHandler ReadingChanged; + public event EventHandler? ReadingChanged; public bool IsSupported => PlatformIsSupported; @@ -157,7 +106,7 @@ public void Start(SensorSpeed sensorSpeed, bool applyLowPassFilter) throw new InvalidOperationException("Compass has already been started."); IsMonitoring = true; - + try { From 558f84736ece2b59fd0cff0e1338c9d06ad5b105 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sat, 19 Mar 2022 17:36:18 +0200 Subject: [PATCH 04/45] more --- .../Core/src/Essentials/AppActions.cs | 22 +-- .../Core/src/Essentials/Battery.cs | 39 +---- .../Core/src/Essentials/Clipboard.cs | 20 +-- .../Core/src/Essentials/Connectivity.cs | 27 +++ .../Core/src/Essentials/Contacts.cs | 29 ++++ .../Core/src/Essentials/DeviceDisplay.cs | 29 ++++ .../Core/src/Essentials/DeviceInfo.cs | 36 ++++ .../src/Connectivity/Connectivity.android.cs | 63 ++++--- .../Connectivity.ios.tvos.macos.cs | 8 +- .../Connectivity.netstandard.watchos.cs | 4 +- .../src/Connectivity/Connectivity.shared.cs | 75 ++++---- .../src/Connectivity/Connectivity.tizen.cs | 10 +- .../src/Connectivity/Connectivity.uwp.cs | 12 +- .../src/Contacts/Contacts.ios.macos.cs | 6 +- .../Contacts.netstandard.tvos.watchos.cs | 6 +- .../src/Contacts/Contacts.shared.cs | 30 +--- src/Essentials/src/Contacts/Contacts.uwp.cs | 2 +- .../DeviceDisplay/DeviceDisplay.android.cs | 42 ++--- .../src/DeviceDisplay/DeviceDisplay.ios.cs | 64 +++---- .../src/DeviceDisplay/DeviceDisplay.macos.cs | 28 +-- .../DeviceDisplay.netstandard.tvos.watchos.cs | 15 +- .../src/DeviceDisplay/DeviceDisplay.shared.cs | 162 ++++++------------ .../src/DeviceDisplay/DeviceDisplay.tizen.cs | 15 +- .../src/DeviceDisplay/DeviceDisplay.uwp.cs | 118 ++----------- .../src/DeviceInfo/DeviceInfo.android.cs | 12 +- .../src/DeviceInfo/DeviceInfo.shared.cs | 52 ++---- .../src/DeviceInfo/DeviceInfo.uwp.cs | 2 +- .../src/Platform/Platform.android.cs | 8 +- .../src/Platform/Platform.ios.tvos.watchos.cs | 4 +- src/Essentials/src/Platform/Platform.macos.cs | 10 +- .../src/Platform/Platform.shared.cs | 4 +- src/Essentials/src/Platform/Platform.tizen.cs | 6 +- src/Essentials/src/Platform/Platform.uwp.cs | 4 +- 33 files changed, 384 insertions(+), 580 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/Connectivity.cs create mode 100644 src/Compatibility/Core/src/Essentials/Contacts.cs create mode 100644 src/Compatibility/Core/src/Essentials/DeviceDisplay.cs create mode 100644 src/Compatibility/Core/src/Essentials/DeviceInfo.cs diff --git a/src/Compatibility/Core/src/Essentials/AppActions.cs b/src/Compatibility/Core/src/Essentials/AppActions.cs index 68ef79005395..60c91ae6a389 100644 --- a/src/Compatibility/Core/src/Essentials/AppActions.cs +++ b/src/Compatibility/Core/src/Essentials/AppActions.cs @@ -9,8 +9,6 @@ namespace Microsoft.Maui.Essentials /// public static partial class AppActions { - static event EventHandler? OnAppActionInternal; - /// public static Task> GetAsync() => Current.GetAsync(); @@ -23,27 +21,13 @@ public static Task SetAsync(params AppAction[] actions) public static Task SetAsync(IEnumerable actions) => Current.SetAsync(actions); + /// public static event EventHandler? OnAppAction { - add - { - if (OnAppActionInternal == null) - Current.AppActionActivated += OnAppActionActivated; - - OnAppActionInternal += value; - } - remove - { - OnAppActionInternal -= value; - - if (OnAppActionInternal == null) - Current.AppActionActivated -= OnAppActionActivated; - } + add => Current.AppActionActivated += value; + remove => Current.AppActionActivated -= value; } - static void OnAppActionActivated(object? sender, AppActionEventArgs e) => - OnAppActionInternal?.Invoke(sender, e); - static IAppActions Current => ApplicationModel.AppActions.Current; } } diff --git a/src/Compatibility/Core/src/Essentials/Battery.cs b/src/Compatibility/Core/src/Essentials/Battery.cs index 50d5b6196f7d..e7f160e2ef13 100644 --- a/src/Compatibility/Core/src/Essentials/Battery.cs +++ b/src/Compatibility/Core/src/Essentials/Battery.cs @@ -7,9 +7,6 @@ namespace Microsoft.Maui.Essentials /// public static partial class Battery { - static event EventHandler? BatteryInfoChangedInternal; - static event EventHandler? EnergySaverStatusChangedInternal; - /// public static double ChargeLevel => Current.ChargeLevel; @@ -22,44 +19,20 @@ public static partial class Battery /// public static EnergySaverStatus EnergySaverStatus => Current.EnergySaverStatus; + /// public static event EventHandler BatteryInfoChanged { - add - { - if (BatteryInfoChangedInternal == null) - Current.BatteryInfoChanged += OnBatteryInfoChanged; - BatteryInfoChangedInternal += value; - } - remove - { - BatteryInfoChangedInternal -= value; - if (BatteryInfoChangedInternal == null) - Current.BatteryInfoChanged -= OnBatteryInfoChanged; - } + add => Current.BatteryInfoChanged += value; + remove => Current.BatteryInfoChanged -= value; } + /// public static event EventHandler EnergySaverStatusChanged { - add - { - if (EnergySaverStatusChangedInternal == null) - Current.EnergySaverStatusChanged += OnEnergySaverStatusChanged; - EnergySaverStatusChangedInternal += value; - } - remove - { - EnergySaverStatusChangedInternal -= value; - if (EnergySaverStatusChangedInternal == null) - Current.EnergySaverStatusChanged -= OnEnergySaverStatusChanged; - } + add => Current.EnergySaverStatusChanged += value; + remove => Current.EnergySaverStatusChanged -= value; } - static void OnBatteryInfoChanged(object? sender, BatteryInfoChangedEventArgs e) => - BatteryInfoChangedInternal?.Invoke(sender, e); - - static void OnEnergySaverStatusChanged(object? sender, EnergySaverStatusChangedEventArgs e) => - EnergySaverStatusChangedInternal?.Invoke(sender, e); - static IBattery Current => Devices.Battery.Default; } } diff --git a/src/Compatibility/Core/src/Essentials/Clipboard.cs b/src/Compatibility/Core/src/Essentials/Clipboard.cs index 5fa66e4a21c5..72f6f035750e 100644 --- a/src/Compatibility/Core/src/Essentials/Clipboard.cs +++ b/src/Compatibility/Core/src/Essentials/Clipboard.cs @@ -8,8 +8,6 @@ namespace Microsoft.Maui.Essentials /// public static partial class Clipboard { - static event EventHandler? ClipboardContentChangedInternal; - /// public static Task SetTextAsync(string? text) => Current.SetTextAsync(text ?? string.Empty); @@ -22,25 +20,13 @@ public static bool HasText public static Task GetTextAsync() => Current.GetTextAsync(); + /// public static event EventHandler ClipboardContentChanged { - add - { - if (ClipboardContentChangedInternal == null) - Current.ClipboardContentChanged += OnClipboardContentChanged; - ClipboardContentChangedInternal += value; - } - remove - { - ClipboardContentChangedInternal -= value; - if (ClipboardContentChangedInternal == null) - Current.ClipboardContentChanged -= OnClipboardContentChanged; - } + add => Current.ClipboardContentChanged += value; + remove => Current.ClipboardContentChanged -= value; } static IClipboard Current => ApplicationModel.DataTransfer.Clipboard.Default; - - static void OnClipboardContentChanged(object? sender, EventArgs e) => - ClipboardContentChangedInternal?.Invoke(sender, e); } } diff --git a/src/Compatibility/Core/src/Essentials/Connectivity.cs b/src/Compatibility/Core/src/Essentials/Connectivity.cs new file mode 100644 index 000000000000..fd5249800037 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Connectivity.cs @@ -0,0 +1,27 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Maui.Networking; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Connectivity + { + /// + public static NetworkAccess NetworkAccess => Current.NetworkAccess; + + /// + public static IEnumerable ConnectionProfiles => Current.ConnectionProfiles.Distinct(); + + /// + public static event EventHandler ConnectivityChanged + { + add => Current.ConnectivityChanged += value; + remove => Current.ConnectivityChanged -= value; + } + + static IConnectivity Current => Networking.Connectivity.Current; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Contacts.cs b/src/Compatibility/Core/src/Essentials/Contacts.cs new file mode 100644 index 000000000000..7d95c3665ba6 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Contacts.cs @@ -0,0 +1,29 @@ +#nullable enable +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel.Communication; +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Contacts + { + /// + public static async Task PickContactAsync() + { + // iOS does not require permissions for the picker + if (DeviceInfo.Platform != DevicePlatform.iOS) + await Permissions.EnsureGrantedAsync(); + + return await Current.PickContactAsync(); + } + + /// + public static Task> GetAllAsync(CancellationToken cancellationToken = default) + => Current.GetAllAsync(cancellationToken); + + static IContacts Current => ApplicationModel.Communication.Contacts.Current; + } +} diff --git a/src/Compatibility/Core/src/Essentials/DeviceDisplay.cs b/src/Compatibility/Core/src/Essentials/DeviceDisplay.cs new file mode 100644 index 000000000000..f1ced6aa28fa --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/DeviceDisplay.cs @@ -0,0 +1,29 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class DeviceDisplay + { + static IDeviceDisplay Current => Devices.DeviceDisplay.Current; + + /// + public static bool KeepScreenOn + { + get => Current.KeepScreenOn; + set => Current.KeepScreenOn = value; + } + + /// + public static DisplayInfo MainDisplayInfo => Current.MainDisplayInfo; + + /// + public static event EventHandler MainDisplayInfoChanged + { + add => Current.MainDisplayInfoChanged += value; + remove => Current.MainDisplayInfoChanged -= value; + } + } +} diff --git a/src/Compatibility/Core/src/Essentials/DeviceInfo.cs b/src/Compatibility/Core/src/Essentials/DeviceInfo.cs new file mode 100644 index 000000000000..6e2bc611d348 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/DeviceInfo.cs @@ -0,0 +1,36 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class DeviceInfo + { + static IDeviceInfo Current => Devices.DeviceInfo.Current; + + /// + public static string Model => Current.Model; + + /// + public static string Manufacturer => Current.Manufacturer; + + /// + public static string Name => Current.Name; + + /// + public static string VersionString => Current.VersionString; + + /// + public static Version Version => Current.Version; + + /// + public static DevicePlatform Platform => Current.Platform; + + /// + public static DeviceIdiom Idiom => Current.Idiom; + + /// + public static DeviceType DeviceType => Current.DeviceType; + } +} diff --git a/src/Essentials/src/Connectivity/Connectivity.android.cs b/src/Essentials/src/Connectivity/Connectivity.android.cs index 534c478489f4..1726762b7a2d 100644 --- a/src/Essentials/src/Connectivity/Connectivity.android.cs +++ b/src/Essentials/src/Connectivity/Connectivity.android.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Android.App; using Android.Content; using Android.Net; -using Android.OS; using Microsoft.Maui.ApplicationModel; using Debug = System.Diagnostics.Debug; @@ -11,20 +11,27 @@ namespace Microsoft.Maui.Networking { partial class ConnectivityImplementation : IConnectivity { - static ConnectivityBroadcastReceiver conectivityReceiver; - static Intent connectivityIntent = new Intent(Platform.EssentialsConnectivityChanged); - static EssentialsNetworkCallback networkCallback; + public const string ConnectivityChangedAction = "com.maui.essentials.ESSENTIALS_CONNECTIVITY_CHANGED"; + static Intent connectivityIntent = new Intent(ConnectivityChangedAction); - public void StartListeners() + static ConnectivityManager connectivityManager; + + static ConnectivityManager ConnectivityManager => + connectivityManager ??= Application.Context.GetSystemService(Context.ConnectivityService) as ConnectivityManager; + + ConnectivityBroadcastReceiver conectivityReceiver; + EssentialsNetworkCallback networkCallback; + + void StartListeners() { Permissions.EnsureDeclared(); var filter = new IntentFilter(); - if (Platform.HasApiLevelN) + if (OperatingSystem.IsAndroidVersionAtLeast(24)) { RegisterNetworkCallback(); - filter.AddAction(Platform.EssentialsConnectivityChanged); + filter.AddAction(ConnectivityChangedAction); } else { @@ -33,12 +40,12 @@ public void StartListeners() #pragma warning restore CS0618 // Type or member is obsolete } - conectivityReceiver = new ConnectivityBroadcastReceiver(Connectivity.OnConnectivityChanged); + conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged); - Platform.AppContext.RegisterReceiver(conectivityReceiver, filter); + Application.Context.RegisterReceiver(conectivityReceiver, filter); } - public void StopListeners() + void StopListeners() { if (conectivityReceiver == null) return; @@ -54,21 +61,23 @@ public void StopListeners() try { - Platform.AppContext.UnregisterReceiver(conectivityReceiver); + Application.Context.UnregisterReceiver(conectivityReceiver); } catch (Java.Lang.IllegalArgumentException) { Debug.WriteLine("Connectivity receiver already unregistered. Disposing of it."); } + conectivityReceiver.Dispose(); conectivityReceiver = null; } + void RegisterNetworkCallback() { - if (!Platform.HasApiLevelN) + if (!OperatingSystem.IsAndroidVersionAtLeast(24)) return; - var manager = Platform.ConnectivityManager; + var manager = ConnectivityManager; if (manager == null) return; @@ -79,10 +88,10 @@ void RegisterNetworkCallback() void UnregisterNetworkCallback() { - if (!Platform.HasApiLevelN) + if (!OperatingSystem.IsAndroidVersionAtLeast(24)) return; - var manager = Platform.ConnectivityManager; + var manager = ConnectivityManager; if (manager == null || networkCallback == null) return; @@ -94,17 +103,23 @@ void UnregisterNetworkCallback() class EssentialsNetworkCallback : ConnectivityManager.NetworkCallback { - public override void OnAvailable(Network network) => Platform.AppContext.SendBroadcast(connectivityIntent); + public override void OnAvailable(Network network) => + Application.Context.SendBroadcast(connectivityIntent); - public override void OnLost(Network network) => Platform.AppContext.SendBroadcast(connectivityIntent); + public override void OnLost(Network network) => + Application.Context.SendBroadcast(connectivityIntent); - public override void OnCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) => Platform.AppContext.SendBroadcast(connectivityIntent); + public override void OnCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) => + Application.Context.SendBroadcast(connectivityIntent); - public override void OnUnavailable() => Platform.AppContext.SendBroadcast(connectivityIntent); + public override void OnUnavailable() => + Application.Context.SendBroadcast(connectivityIntent); - public override void OnLinkPropertiesChanged(Network network, LinkProperties linkProperties) => Platform.AppContext.SendBroadcast(connectivityIntent); + public override void OnLinkPropertiesChanged(Network network, LinkProperties linkProperties) => + Application.Context.SendBroadcast(connectivityIntent); - public override void OnLosing(Network network, int maxMsToLive) => Platform.AppContext.SendBroadcast(connectivityIntent); + public override void OnLosing(Network network, int maxMsToLive) => + Application.Context.SendBroadcast(connectivityIntent); } static NetworkAccess IsBetterAccess(NetworkAccess currentAccess, NetworkAccess newAccess) => @@ -119,7 +134,7 @@ public NetworkAccess NetworkAccess try { var currentAccess = NetworkAccess.None; - var manager = Platform.ConnectivityManager; + var manager = ConnectivityManager; #pragma warning disable CS0618 // Type or member is obsolete var networks = manager.GetAllNetworks(); @@ -204,7 +219,7 @@ public IEnumerable ConnectionProfiles { Permissions.EnsureDeclared(); - var manager = Platform.ConnectivityManager; + var manager = ConnectivityManager; #pragma warning disable CS0618 // Type or member is obsolete var networks = manager.GetAllNetworks(); #pragma warning restore CS0618 // Type or member is obsolete @@ -296,7 +311,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 && intent.Action != Platform.EssentialsConnectivityChanged) + if (intent.Action != ConnectivityManager.ConnectivityAction && intent.Action != ConnectivityImplementation.ConnectivityChangedAction) #pragma warning restore CS0618 // Type or member is obsolete return; diff --git a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs index 08d110332a5b..0375bed85658 100644 --- a/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs +++ b/src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cs @@ -19,18 +19,18 @@ partial class ConnectivityImplementation : IConnectivity static ReachabilityListener listener; - public void StartListeners() + void StartListeners() { listener = new ReachabilityListener(); - listener.ReachabilityChanged += Connectivity.OnConnectivityChanged; + listener.ReachabilityChanged += OnConnectivityChanged; } - public void StopListeners() + void StopListeners() { if (listener == null) return; - listener.ReachabilityChanged -= Connectivity.OnConnectivityChanged; + listener.ReachabilityChanged -= OnConnectivityChanged; listener.Dispose(); listener = null; } diff --git a/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs b/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs index fce77b649c07..0a3b662972b3 100644 --- a/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs +++ b/src/Essentials/src/Connectivity/Connectivity.netstandard.watchos.cs @@ -11,10 +11,10 @@ partial class ConnectivityImplementation : IConnectivity public IEnumerable ConnectionProfiles => throw ExceptionUtils.NotSupportedOrImplementedException; - public void StartListeners() => + void StartListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; - public void StopListeners() => + void StopListeners() => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Connectivity/Connectivity.shared.cs b/src/Essentials/src/Connectivity/Connectivity.shared.cs index b1cdfc3a5a90..0604c7df409b 100644 --- a/src/Essentials/src/Connectivity/Connectivity.shared.cs +++ b/src/Essentials/src/Connectivity/Connectivity.shared.cs @@ -13,68 +13,64 @@ public interface IConnectivity NetworkAccess NetworkAccess { get; } - void StartListeners(); + event EventHandler ConnectivityChanged; + } + +#nullable enable + public static class Connectivity + { + static IConnectivity? currentImplementation; - void StopListeners(); + public static IConnectivity Current => + currentImplementation ??= new ConnectivityImplementation(); + + internal static void SetCurrent(IConnectivity? implementation) => + currentImplementation = implementation; } -} -namespace Microsoft.Maui.Essentials -{ +#nullable disable + /// - public static partial class Connectivity + partial class ConnectivityImplementation : IConnectivity { - static event EventHandler ConnectivityChangedInternal; + event EventHandler ConnectivityChangedInternal; // a cache so that events aren't fired unnecessarily // this is mainly an issue on Android, but we can stiil do this everywhere - static NetworkAccess currentAccess; - static List currentProfiles; - - /// - public static NetworkAccess NetworkAccess => Current.NetworkAccess; + NetworkAccess currentAccess; + List currentProfiles; - /// - public static IEnumerable ConnectionProfiles => Current.ConnectionProfiles.Distinct(); - - public static event EventHandler ConnectivityChanged + public event EventHandler ConnectivityChanged { add { - var wasRunning = ConnectivityChangedInternal != null; - - ConnectivityChangedInternal += value; - - if (!wasRunning && ConnectivityChangedInternal != null) + if (ConnectivityChangedInternal is null) { SetCurrent(); - Current.StartListeners(); + StartListeners(); } + ConnectivityChangedInternal += value; } - remove { - var wasRunning = ConnectivityChangedInternal != null; - ConnectivityChangedInternal -= value; - - if (wasRunning && ConnectivityChangedInternal == null) - Current.StopListeners(); + if (ConnectivityChangedInternal is null) + StopListeners(); } } - static void SetCurrent() + void SetCurrent() { currentAccess = NetworkAccess; currentProfiles = new List(ConnectionProfiles); } - internal static void OnConnectivityChanged(NetworkAccess access, IEnumerable profiles) + void OnConnectivityChanged(NetworkAccess access, IEnumerable profiles) => OnConnectivityChanged(new ConnectivityChangedEventArgs(access, profiles)); - internal static void OnConnectivityChanged() + void OnConnectivityChanged() => OnConnectivityChanged(NetworkAccess, ConnectionProfiles); - internal static void OnConnectivityChanged(ConnectivityChangedEventArgs e) + void OnConnectivityChanged(ConnectivityChangedEventArgs e) { if (currentAccess != e.NetworkAccess || !currentProfiles.SequenceEqual(e.ConnectionProfiles)) { @@ -82,21 +78,8 @@ internal static void OnConnectivityChanged(ConnectivityChangedEventArgs e) MainThread.BeginInvokeOnMainThread(() => ConnectivityChangedInternal?.Invoke(null, e)); } } - -#nullable enable - static IConnectivity? currentImplementation; - - [EditorBrowsable(EditorBrowsableState.Never)] - public static IConnectivity Current => - currentImplementation ??= new ConnectivityImplementation(); - - internal static void SetCurrent(IConnectivity? implementation) => - currentImplementation = implementation; -#nullable disable } -} -namespace Microsoft.Maui.Networking -{ + /// public class ConnectivityChangedEventArgs : EventArgs { diff --git a/src/Essentials/src/Connectivity/Connectivity.tizen.cs b/src/Essentials/src/Connectivity/Connectivity.tizen.cs index fc348632fe11..259f6faa803b 100644 --- a/src/Essentials/src/Connectivity/Connectivity.tizen.cs +++ b/src/Essentials/src/Connectivity/Connectivity.tizen.cs @@ -5,14 +5,14 @@ namespace Microsoft.Maui.Networking { partial class ConnectivityImplementation : IConnectivity { - static IList profiles = new List(); + IList profiles = new List(); - internal static void OnChanged(object sender, object e) + void OnChanged(object sender, object e) { GetProfileListAsync(); } - internal static async void GetProfileListAsync() + async void GetProfileListAsync() { var list = await ConnectionProfileManager.GetProfileListAsync(ProfileListType.Connected); profiles.Clear(); @@ -66,14 +66,14 @@ public IEnumerable ConnectionProfiles } } - public void StartListeners() + void StartListeners() { Permissions.EnsureDeclared(); ConnectionManager.ConnectionTypeChanged += OnChanged; GetProfileListAsync(); } - public void StopListeners() + void StopListeners() { ConnectionManager.ConnectionTypeChanged -= OnChanged; } diff --git a/src/Essentials/src/Connectivity/Connectivity.uwp.cs b/src/Essentials/src/Connectivity/Connectivity.uwp.cs index a58220c8a8d7..84dedc99e84d 100644 --- a/src/Essentials/src/Connectivity/Connectivity.uwp.cs +++ b/src/Essentials/src/Connectivity/Connectivity.uwp.cs @@ -7,14 +7,14 @@ namespace Microsoft.Maui.Networking { partial class ConnectivityImplementation : IConnectivity { - public void StartListeners() => - NetworkInformation.NetworkStatusChanged += NetworkStatusChanged; + void StartListeners() => + NetworkInformation.NetworkStatusChanged += NetworkStatusChanged; - static void NetworkStatusChanged(object sender) => - Connectivity.OnConnectivityChanged(); + void StopListeners() => + NetworkInformation.NetworkStatusChanged -= NetworkStatusChanged; - public void StopListeners() => - NetworkInformation.NetworkStatusChanged -= NetworkStatusChanged; + void NetworkStatusChanged(object sender) => + OnConnectivityChanged(); public NetworkAccess NetworkAccess { diff --git a/src/Essentials/src/Contacts/Contacts.ios.macos.cs b/src/Essentials/src/Contacts/Contacts.ios.macos.cs index 2fb799af3034..85143b5f47f8 100644 --- a/src/Essentials/src/Contacts/Contacts.ios.macos.cs +++ b/src/Essentials/src/Contacts/Contacts.ios.macos.cs @@ -13,8 +13,8 @@ namespace Microsoft.Maui.ApplicationModel.Communication class ContactsImplementation : IContacts { #if __MACOS__ - static Task PlatformPickContactAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; - + public Task PickContactAsync() => + throw ExceptionUtils.NotSupportedOrImplementedException; #elif __IOS__ public Task PickContactAsync() { @@ -49,8 +49,8 @@ public Task PickContactAsync() return source.Task; } - #endif + public Task> GetAllAsync(CancellationToken cancellationToken) { var keys = new[] diff --git a/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs b/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs index e88e3c3f95e3..17d8af73fc6e 100644 --- a/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Contacts/Contacts.netstandard.tvos.watchos.cs @@ -7,8 +7,10 @@ namespace Microsoft.Maui.ApplicationModel.Communication /// class ContactsImplementation : IContacts { - public Task PickContactAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; + public Task PickContactAsync() => + throw ExceptionUtils.NotSupportedOrImplementedException; - public Task> GetAllAsync(CancellationToken cancellationToken) => throw ExceptionUtils.NotSupportedOrImplementedException; + public Task> GetAllAsync(CancellationToken cancellationToken) => + throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Contacts/Contacts.shared.cs b/src/Essentials/src/Contacts/Contacts.shared.cs index 547d18f59d00..d16a84d95c4b 100644 --- a/src/Essentials/src/Contacts/Contacts.shared.cs +++ b/src/Essentials/src/Contacts/Contacts.shared.cs @@ -1,47 +1,25 @@ #nullable enable using System.Collections.Generic; -using System.ComponentModel; using System.Threading; using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.ApplicationModel.Communication; -using Microsoft.Maui.Devices; namespace Microsoft.Maui.ApplicationModel.Communication { public interface IContacts { - Task PickContactAsync(); + Task PickContactAsync(); + Task> GetAllAsync(CancellationToken cancellationToken = default); } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static class Contacts { - /// - public static async Task PickContactAsync() - { - // iOS does not require permissions for the picker - if (DeviceInfo.Platform != DevicePlatform.iOS) - await Permissions.EnsureGrantedAsync(); - - return await Current.PickContactAsync(); - } - - /// - public static Task> GetAllAsync(CancellationToken cancellationToken = default) - => Current.GetAllAsync(cancellationToken); - static IContacts? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IContacts Current => currentImplementation ??= new ContactsImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IContacts? implementation) => + internal static void SetCurrent(IContacts? implementation) => currentImplementation = implementation; } } diff --git a/src/Essentials/src/Contacts/Contacts.uwp.cs b/src/Essentials/src/Contacts/Contacts.uwp.cs index 7d1e58c8f54f..a58de49e0978 100644 --- a/src/Essentials/src/Contacts/Contacts.uwp.cs +++ b/src/Essentials/src/Contacts/Contacts.uwp.cs @@ -7,7 +7,7 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - class ContactsImplementation:IContacts + class ContactsImplementation : IContacts { public async Task PickContactAsync() { diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs index 0718d230dc70..233d95a9881d 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs @@ -2,21 +2,20 @@ using System; using System.Diagnostics; using System.Threading.Tasks; +using Android.App; using Android.Content; using Android.Content.Res; -using Android.Provider; using Android.Runtime; using Android.Util; using Android.Views; +using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices { - class DeviceDisplayImplementation : IDeviceDisplay + partial class DeviceDisplayImplementation : IDeviceDisplay { OrientationEventListener? orientationListener; - public event EventHandler? MainDisplayInfoChanged; - public bool KeepScreenOn { get @@ -25,7 +24,6 @@ public bool KeepScreenOn var flags = window?.Attributes?.Flags ?? 0; return flags.HasFlag(WindowManagerFlags.KeepScreenOn); } - set { var window = Platform.GetCurrentActivity(true)?.Window; @@ -36,7 +34,7 @@ public bool KeepScreenOn } } - public DisplayInfo GetMainDisplayInfo() + DisplayInfo GetMainDisplayInfo() { using var displayMetrics = new DisplayMetrics(); var display = GetDefaultDisplay(); @@ -49,34 +47,25 @@ public DisplayInfo GetMainDisplayInfo() height: displayMetrics?.HeightPixels ?? 0, density: displayMetrics?.Density ?? 0, orientation: CalculateOrientation(), - rotation: CalculateRotation(), + rotation: CalculateRotation(display), rate: display?.RefreshRate ?? 0); } - public void StartScreenMetricsListeners() + void StartScreenMetricsListeners() { - orientationListener = new Listener(Platform.AppContext, OnScreenMetricsChanged); + orientationListener = new Listener(Application.Context, OnMainDisplayInfoChanged); orientationListener.Enable(); } - public void StopScreenMetricsListeners() + void StopScreenMetricsListeners() { orientationListener?.Disable(); orientationListener?.Dispose(); orientationListener = null; } - void OnScreenMetricsChanged() - { - var metrics = GetMainDisplayInfo(); - MainDisplayInfoChanged?.Invoke(this, new DisplayInfoChangedEventArgs(metrics)); - } - - DisplayRotation CalculateRotation() - { - var display = GetDefaultDisplay(); - - return display?.Rotation switch + static DisplayRotation CalculateRotation(Display? display) => + display?.Rotation switch { SurfaceOrientation.Rotation270 => DisplayRotation.Rotation270, SurfaceOrientation.Rotation180 => DisplayRotation.Rotation180, @@ -84,24 +73,21 @@ DisplayRotation CalculateRotation() SurfaceOrientation.Rotation0 => DisplayRotation.Rotation0, _ => DisplayRotation.Unknown, }; - } - DisplayOrientation CalculateOrientation() - { - return Platform.AppContext.Resources?.Configuration?.Orientation switch + static DisplayOrientation CalculateOrientation() => + Application.Context.Resources?.Configuration?.Orientation switch { Orientation.Landscape => DisplayOrientation.Landscape, Orientation.Portrait => DisplayOrientation.Portrait, Orientation.Square => DisplayOrientation.Portrait, _ => DisplayOrientation.Unknown }; - } - Display? GetDefaultDisplay() + static Display? GetDefaultDisplay() { try { - using var service = Platform.AppContext.GetSystemService(Context.WindowService); + using var service = Application.Context.GetSystemService(Context.WindowService); using var windowManager = service?.JavaCast(); return windowManager?.DefaultDisplay; } diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs index 55f942c9db20..1a9a3dde3ea6 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.ios.cs @@ -1,83 +1,67 @@ #nullable enable using System; using Foundation; -using ObjCRuntime; using UIKit; namespace Microsoft.Maui.Devices { - class DeviceDisplayImplementation : IDeviceDisplay + partial class DeviceDisplayImplementation : IDeviceDisplay { NSObject? observer; - public event EventHandler? MainDisplayInfoChanged; - public bool KeepScreenOn { get => UIApplication.SharedApplication.IdleTimerDisabled; set => UIApplication.SharedApplication.IdleTimerDisabled = value; } - public DisplayInfo GetMainDisplayInfo() + DisplayInfo GetMainDisplayInfo() { var bounds = UIScreen.MainScreen.Bounds; var scale = UIScreen.MainScreen.Scale; + var rate = (OperatingSystem.IsIOSVersionAtLeast(10, 3) || OperatingSystem.IsTvOSVersionAtLeast(10, 3)) + ? UIScreen.MainScreen.MaximumFramesPerSecond + : 0; + return new DisplayInfo( width: bounds.Width * scale, height: bounds.Height * scale, density: scale, orientation: CalculateOrientation(), rotation: CalculateRotation(), - rate: (OperatingSystem.IsIOSVersionAtLeast(10, 3) || OperatingSystem.IsTvOSVersionAtLeast(10, 3)) ? UIScreen.MainScreen.MaximumFramesPerSecond : 0); + rate: rate); } - public void StartScreenMetricsListeners() + void StartScreenMetricsListeners() { var notificationCenter = NSNotificationCenter.DefaultCenter; var notification = UIApplication.DidChangeStatusBarOrientationNotification; - observer = notificationCenter.AddObserver(notification, OnScreenMetricsChanged); + observer = notificationCenter.AddObserver(notification, OnMainDisplayInfoChanged); } - public void StopScreenMetricsListeners() + void StopScreenMetricsListeners() { observer?.Dispose(); observer = null; } - void OnScreenMetricsChanged(NSNotification obj) - { - var metrics = GetMainDisplayInfo(); - MainDisplayInfoChanged?.Invoke(this, new DisplayInfoChangedEventArgs(metrics)); - } - - DisplayOrientation CalculateOrientation() - { - var orientation = UIApplication.SharedApplication.StatusBarOrientation; - - if (orientation.IsLandscape()) - return DisplayOrientation.Landscape; - - return DisplayOrientation.Portrait; - } + void OnMainDisplayInfoChanged(NSNotification obj) => + OnMainDisplayInfoChanged(); - DisplayRotation CalculateRotation() - { - var orientation = UIApplication.SharedApplication.StatusBarOrientation; + static DisplayOrientation CalculateOrientation() => + UIApplication.SharedApplication.StatusBarOrientation.IsLandscape() + ? DisplayOrientation.Landscape + : DisplayOrientation.Portrait; - switch (orientation) + static DisplayRotation CalculateRotation() => + UIApplication.SharedApplication.StatusBarOrientation switch { - case UIInterfaceOrientation.Portrait: - return DisplayRotation.Rotation0; - case UIInterfaceOrientation.PortraitUpsideDown: - return DisplayRotation.Rotation180; - case UIInterfaceOrientation.LandscapeLeft: - return DisplayRotation.Rotation270; - case UIInterfaceOrientation.LandscapeRight: - return DisplayRotation.Rotation90; - } - - return DisplayRotation.Unknown; - } + UIInterfaceOrientation.Portrait => DisplayRotation.Rotation0, + UIInterfaceOrientation.PortraitUpsideDown => DisplayRotation.Rotation180, + UIInterfaceOrientation.LandscapeLeft => DisplayRotation.Rotation270, + UIInterfaceOrientation.LandscapeRight => DisplayRotation.Rotation90, + _ => DisplayRotation.Unknown, + }; } } diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs index 9bbdb4fa675b..68e2bc6a9bca 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.macos.cs @@ -11,15 +11,9 @@ class DeviceDisplayImplementation : IDeviceDisplay uint keepScreenOnId = 0; NSObject? screenMetricsObserver; - public event EventHandler? MainDisplayInfoChanged; - public bool KeepScreenOn { - get - { - return keepScreenOnId != 0; - } - + get => keepScreenOnId != 0; set { if (KeepScreenOn == value) @@ -37,7 +31,7 @@ public bool KeepScreenOn } } - public DisplayInfo GetMainDisplayInfo() + DisplayInfo GetMainDisplayInfo() { var mainScreen = NSScreen.MainScreen; var frame = mainScreen.Frame; @@ -61,23 +55,19 @@ public DisplayInfo GetMainDisplayInfo() rate: (float)refreshRate); } - public void StartScreenMetricsListeners() + void StartScreenMetricsListeners() { - if (screenMetricsObserver == null) - { - screenMetricsObserver = NSNotificationCenter.DefaultCenter.AddObserver(NSApplication.DidChangeScreenParametersNotification, OnDidChangeScreenParameters); - } + screenMetricsObserver ??= NSNotificationCenter.DefaultCenter.AddObserver( + NSApplication.DidChangeScreenParametersNotification, OnDidChangeScreenParameters); } - public void StopScreenMetricsListeners() + void StopScreenMetricsListeners() { screenMetricsObserver?.Dispose(); + screenMetricsObserver = null; } - public void OnDidChangeScreenParameters(NSNotification notification) - { - var metrics = GetMainDisplayInfo(); - MainDisplayInfoChanged?.Invoke(this, new DisplayInfoChangedEventArgs(metrics)); - } + void OnDidChangeScreenParameters(NSNotification notification) => + OnMainDisplayInfoChanged(); } } diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs index 7a6891d7814d..bb157a6d5aad 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs @@ -1,22 +1,15 @@ #nullable enable -using System; namespace Microsoft.Maui.Devices { - class DeviceDisplayImplementation : IDeviceDisplay + partial class DeviceDisplayImplementation : IDeviceDisplay { - public event EventHandler? MainDisplayInfoChanged - { - add { } - remove { } - } - public bool KeepScreenOn { get => false; set { } } - public DisplayInfo GetMainDisplayInfo() => default; + DisplayInfo GetMainDisplayInfo() => default; - public void StartScreenMetricsListeners() { } + void StartScreenMetricsListeners() { } - public void StopScreenMetricsListeners() { } + void StopScreenMetricsListeners() { } } } diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs index 00bbb4f0c1fe..20bcd0952858 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs @@ -1,12 +1,29 @@ #nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { - /// - public static partial class DeviceDisplay + public interface IDeviceDisplay + { + bool KeepScreenOn { get; set; } + + DisplayInfo MainDisplayInfo { get; } + + event EventHandler MainDisplayInfoChanged; + } + + /// + public class DisplayInfoChangedEventArgs : EventArgs + { + /// + public DisplayInfoChangedEventArgs(DisplayInfo displayInfo) => + DisplayInfo = displayInfo; + + /// + public DisplayInfo DisplayInfo { get; } + } + + public static class DeviceDisplay { #if WINDOWS internal const float BaseLogicalDpi = 96.0f; @@ -14,103 +31,52 @@ public static partial class DeviceDisplay internal const float BaseLogicalDpi = 160.0f; #endif - static readonly object locker = new object(); - static IDeviceDisplay currentImplementation; - - static DeviceDisplay() - { - currentImplementation = new DeviceDisplayImplementation(); - currentImplementation.MainDisplayInfoChanged += OnMainDisplayInfoChanged; - } + static IDeviceDisplay? currentImplementation; - /// - public static IDeviceDisplay Current => currentImplementation; + public static IDeviceDisplay Current => + currentImplementation ?? new DeviceDisplayImplementation(); /// - internal static void SetCurrent(IDeviceDisplay? implementation) - { - lock (locker) - { - if (currentImplementation == implementation) - return; - - var newImplementation = implementation ?? new DeviceDisplayImplementation(); - - var oldImplementation = currentImplementation; - currentImplementation = newImplementation; - - if (oldImplementation is not null) - { - oldImplementation.MainDisplayInfoChanged -= OnMainDisplayInfoChanged; - - var wasAlwaysOn = oldImplementation.KeepScreenOn; - if (wasAlwaysOn) - { - oldImplementation.KeepScreenOn = false; - newImplementation.KeepScreenOn = true; - } - - var wasRunning = MainDisplayInfoChangedInternal != null; - if (wasRunning) - { - oldImplementation.StopScreenMetricsListeners(); - newImplementation.StartScreenMetricsListeners(); - } - } - - newImplementation.MainDisplayInfoChanged += OnMainDisplayInfoChanged; - - SetCurrent(newImplementation.GetMainDisplayInfo()); - } - } - - static event EventHandler? MainDisplayInfoChangedInternal; - - static DisplayInfo currentMetrics; + internal static void SetCurrent(IDeviceDisplay? implementation) => + currentImplementation = implementation; + } - /// - public static bool KeepScreenOn - { - get => Current.KeepScreenOn; - set => Current.KeepScreenOn = value; - } + partial class DeviceDisplayImplementation : IDeviceDisplay + { + event EventHandler? MainDisplayInfoChangedInternal; - /// - public static DisplayInfo MainDisplayInfo => Current.GetMainDisplayInfo(); + DisplayInfo currentMetrics; - static void SetCurrent(DisplayInfo metrics) => - currentMetrics = new DisplayInfo(metrics.Width, metrics.Height, metrics.Density, metrics.Orientation, metrics.Rotation, metrics.RefreshRate); + public DisplayInfo MainDisplayInfo => GetMainDisplayInfo(); - public static event EventHandler MainDisplayInfoChanged + public event EventHandler MainDisplayInfoChanged { add { - var wasRunning = MainDisplayInfoChangedInternal != null; - - MainDisplayInfoChangedInternal += value; - - if (!wasRunning && MainDisplayInfoChangedInternal != null) + if (MainDisplayInfoChangedInternal is null) { - SetCurrent(Current.GetMainDisplayInfo()); - Current.StartScreenMetricsListeners(); + SetCurrent(MainDisplayInfo); + StartScreenMetricsListeners(); } + MainDisplayInfoChangedInternal += value; } - remove { - var wasRunning = MainDisplayInfoChangedInternal != null; - MainDisplayInfoChangedInternal -= value; - - if (wasRunning && MainDisplayInfoChangedInternal == null) - Current.StopScreenMetricsListeners(); + if (MainDisplayInfoChangedInternal is null) + StopScreenMetricsListeners(); } } - static void OnMainDisplayInfoChanged(object? sender, DisplayInfoChangedEventArgs e) => - OnMainDisplayInfoChanged(e); + void SetCurrent(DisplayInfo metrics) => + currentMetrics = new DisplayInfo( + metrics.Width, metrics.Height, + metrics.Density, + metrics.Orientation, + metrics.Rotation, + metrics.RefreshRate); - static void OnMainDisplayInfoChanged(DisplayInfoChangedEventArgs e) + void OnMainDisplayInfoChanged(DisplayInfoChangedEventArgs e) { if (!currentMetrics.Equals(e.DisplayInfo)) { @@ -118,31 +84,11 @@ static void OnMainDisplayInfoChanged(DisplayInfoChangedEventArgs e) MainDisplayInfoChangedInternal?.Invoke(null, e); } } - } -} -namespace Microsoft.Maui.Devices -{ - /// - public class DisplayInfoChangedEventArgs : EventArgs - { - /// - public DisplayInfoChangedEventArgs(DisplayInfo displayInfo) => - DisplayInfo = displayInfo; - /// - public DisplayInfo DisplayInfo { get; } - } - - public interface IDeviceDisplay - { - bool KeepScreenOn { get; set; } - - void StartScreenMetricsListeners(); - - void StopScreenMetricsListeners(); - - DisplayInfo GetMainDisplayInfo(); - - event EventHandler MainDisplayInfoChanged; + void OnMainDisplayInfoChanged() + { + var metrics = GetMainDisplayInfo(); + OnMainDisplayInfoChanged(new DisplayInfoChangedEventArgs(metrics)); + } } -} +} \ No newline at end of file diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs index 9cd5cd21c21d..959196851091 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.tizen.cs @@ -4,7 +4,7 @@ namespace Microsoft.Maui.Devices { - class DeviceDisplayImplementation : IDeviceDisplay + partial class DeviceDisplayImplementation : IDeviceDisplay { [DllImport("libcapi-system-device.so.0", EntryPoint = "device_power_request_lock")] static extern void RequestKeepScreenOn(int type = 1, int timeout = 0); @@ -14,8 +14,6 @@ class DeviceDisplayImplementation : IDeviceDisplay bool keepScreenOn = false; - public event EventHandler? MainDisplayInfoChanged; - public bool KeepScreenOn { get => keepScreenOn; @@ -64,20 +62,17 @@ static DisplayRotation GetRotation() }; } - public void StartScreenMetricsListeners() + void StartScreenMetricsListeners() { Platform.MainWindow.RotationChanged += OnRotationChanged; } - public void StopScreenMetricsListeners() + void StopScreenMetricsListeners() { Platform.MainWindow.RotationChanged -= OnRotationChanged; } - void OnRotationChanged(object s, EventArgs e) - { - var metrics = GetMainDisplayInfo(); - MainDisplayInfoChanged?.Invoke(this, new DisplayInfoChangedEventArgs(metrics)); - } + void OnRotationChanged(object s, EventArgs e) => + OnMainDisplayInfoChanged(); } } diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs index a7a7732c4503..4c3901143b1c 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs @@ -4,18 +4,15 @@ using Microsoft.Maui.ApplicationModel; using Microsoft.UI.Windowing; using Windows.Graphics.Display; -using Windows.Graphics.Display.Core; using Windows.System.Display; namespace Microsoft.Maui.Devices { - class DeviceDisplayImplementation : IDeviceDisplay + partial class DeviceDisplayImplementation : IDeviceDisplay { readonly object locker = new object(); DisplayRequest? displayRequest; - public event EventHandler? MainDisplayInfoChanged; - public bool KeepScreenOn { get @@ -25,7 +22,6 @@ public bool KeepScreenOn return displayRequest != null; } } - set { lock (locker) @@ -84,10 +80,9 @@ static DisplayRotation CalculateRotation(DisplayOrientations native, DisplayOrie return DisplayRotation.Unknown; } -#if WINDOWS - AppWindow? _currentAppWindowListeningTo; - public DisplayInfo GetMainDisplayInfo() + + DisplayInfo GetMainDisplayInfo() { if (Platform.CurrentWindow == null) return new DisplayInfo(); @@ -137,22 +132,19 @@ public DisplayInfo GetMainDisplayInfo() return null; } - public void StartScreenMetricsListeners() + void StartScreenMetricsListeners() { MainThread.BeginInvokeOnMainThread(() => { Platform.CurrentWindowDisplayChanged += OnWindowDisplayChanged; Platform.CurrentWindowChanged += OnCurrentWindowChanged; - if (Platform.CurrentWindow != null) - { - _currentAppWindowListeningTo = Platform.CurrentAppWindow; - _currentAppWindowListeningTo.Changed += OnAppWindowChanged; - } + _currentAppWindowListeningTo = Platform.CurrentAppWindow; + _currentAppWindowListeningTo.Changed += OnAppWindowChanged; }); } - public void StopScreenMetricsListeners() + void StopScreenMetricsListeners() { MainThread.BeginInvokeOnMainThread(() => { @@ -169,27 +161,17 @@ public void StopScreenMetricsListeners() void OnCurrentWindowChanged(object? sender, EventArgs e) { if (_currentAppWindowListeningTo != null) - { _currentAppWindowListeningTo.Changed -= OnAppWindowChanged; - } _currentAppWindowListeningTo = Platform.CurrentAppWindow; _currentAppWindowListeningTo.Changed += OnAppWindowChanged; } - void OnWindowDisplayChanged(object? sender, EventArgs e) - { - WindowDisplayPropertiesChanged(); - } - - void WindowDisplayPropertiesChanged() - { - var metrics = GetMainDisplayInfo(); - MainDisplayInfoChanged?.Invoke(this, new DisplayInfoChangedEventArgs(metrics)); - } + void OnWindowDisplayChanged(object? sender, EventArgs e) => + OnMainDisplayInfoChanged(); void OnAppWindowChanged(AppWindow sender, AppWindowChangedEventArgs args) => - WindowDisplayPropertiesChanged(); + OnMainDisplayInfoChanged(); static DisplayRotation CalculateRotation(DEVMODE devMode, AppWindow appWindow) { @@ -339,85 +321,5 @@ struct DEVMODE public int dmPanningWidth; public int dmPanningHeight; } -#elif WINDOWS_UWP - public DisplayInfo GetMainDisplayInfo() => - GetMainDisplayInfo(null); - - DisplayInfo GetMainDisplayInfo(DisplayInformation? di = null) - { - di ??= DisplayInformation.GetForCurrentView(); - - var rotation = CalculateRotation(di); - var perpendicular = - rotation == DisplayRotation.Rotation90 || - rotation == DisplayRotation.Rotation270; - - var w = di.ScreenWidthInRawPixels; - var h = di.ScreenHeightInRawPixels; - - var hdi = HdmiDisplayInformation.GetForCurrentView(); - var hdm = hdi?.GetCurrentDisplayMode(); - - return new DisplayInfo( - width: perpendicular ? h : w, - height: perpendicular ? w : h, - density: di.LogicalDpi / DeviceDisplay.BaseLogicalDpi, - orientation: CalculateOrientation(di), - rotation: rotation, - rate: (float)(hdm?.RefreshRate ?? 0)); - } - - public void StartScreenMetricsListeners() - { - MainThread.BeginInvokeOnMainThread(() => - { - var di = DisplayInformation.GetForCurrentView(); - - di.DpiChanged += OnDisplayInformationChanged; - di.OrientationChanged += OnDisplayInformationChanged; - }); - } - - public void StopScreenMetricsListeners() - { - MainThread.BeginInvokeOnMainThread(() => - { - var di = DisplayInformation.GetForCurrentView(); - - di.DpiChanged -= OnDisplayInformationChanged; - di.OrientationChanged -= OnDisplayInformationChanged; - }); - } - - void OnDisplayInformationChanged(DisplayInformation di, object args) - { - var metrics = GetMainDisplayInfo(di); - MainDisplayInfoChanged?.Invoke(this, new DisplayInfoChangedEventArgs(metrics)); - } - - DisplayOrientation CalculateOrientation(DisplayInformation di) - { - switch (di.CurrentOrientation) - { - case DisplayOrientations.Landscape: - case DisplayOrientations.LandscapeFlipped: - return DisplayOrientation.Landscape; - case DisplayOrientations.Portrait: - case DisplayOrientations.PortraitFlipped: - return DisplayOrientation.Portrait; - } - - return DisplayOrientation.Unknown; - } - - static DisplayRotation CalculateRotation(DisplayInformation di) - { - var native = di.NativeOrientation; - var current = di.CurrentOrientation; - - return CalculateRotation(native, current); - } - } -#endif } } diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs index 028d0ab1ea86..d8ead41eec37 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.android.cs @@ -40,7 +40,7 @@ public DeviceIdiom Idiom var currentIdiom = DeviceIdiom.Unknown; // first try UIModeManager - using var uiModeManager = UiModeManager.FromContext(Platform.AppContext); + using var uiModeManager = UiModeManager.FromContext(Application.Context); try { @@ -55,7 +55,7 @@ public DeviceIdiom Idiom // then try Configuration if (currentIdiom == DeviceIdiom.Unknown) { - var configuration = Platform.AppContext.Resources?.Configuration; + var configuration = Application.Context.Resources?.Configuration; if (configuration != null) { var minWidth = configuration.SmallestScreenWidthDp; @@ -65,7 +65,7 @@ public DeviceIdiom Idiom else { // start clutching at straws - using var metrics = Platform.AppContext.Resources?.DisplayMetrics; + using var metrics = Application.Context.Resources?.DisplayMetrics; if (metrics != null) { var minSize = Math.Min(metrics.WidthPixels, metrics.HeightPixels); @@ -126,10 +126,10 @@ public DeviceType DeviceType static string GetSystemSetting(string name, bool isGlobal = false) { - if (isGlobal && Platform.HasApiLevelNMr1) - return Settings.Global.GetString(Platform.AppContext.ContentResolver, name); + if (isGlobal && OperatingSystem.IsAndroidVersionAtLeast(25)) + return Settings.Global.GetString(Application.Context.ContentResolver, name); else - return Settings.System.GetString(Platform.AppContext.ContentResolver, name); + return Settings.System.GetString(Application.Context.ContentResolver, name); } } } diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs index b4f63474f12f..205be16f478e 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs @@ -1,47 +1,6 @@ #nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Essentials -{ - /// - public static class DeviceInfo - { - static IDeviceInfo? currentImplementation; - - public static IDeviceInfo Current => - currentImplementation ??= new DeviceInfoImplementation(); - - internal static void SetCurrent(IDeviceInfo? implementation) => - currentImplementation = implementation; - - - /// - public static string Model => Current.Model; - - /// - public static string Manufacturer => Current.Manufacturer; - - /// - public static string Name => Current.Name; - - /// - public static string VersionString => Current.VersionString; - - /// - public static Version Version => Current.Version; - - /// - public static DevicePlatform Platform => Current.Platform; - - /// - public static DeviceIdiom Idiom => Current.Idiom; - - /// - public static DeviceType DeviceType => Current.DeviceType; - } -} namespace Microsoft.Maui.Devices { /// @@ -73,4 +32,15 @@ public interface IDeviceInfo DeviceType DeviceType { get; } } + + public static class DeviceInfo + { + static IDeviceInfo? currentImplementation; + + public static IDeviceInfo Current => + currentImplementation ??= new DeviceInfoImplementation(); + + internal static void SetCurrent(IDeviceInfo? implementation) => + currentImplementation = implementation; + } } diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs index b8f88ebf0c54..956416f0ef9f 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs @@ -70,7 +70,7 @@ public DeviceIdiom Idiom { try { - var currentHandle = Platform.CurrentWindowHandle; + var currentHandle = ApplicationModel.Platform.CurrentWindowHandle; var settings = UIViewSettingsInterop.GetForWindow(currentHandle); var uiMode = settings.UserInteractionMode; currentIdiom = uiMode == UserInteractionMode.Mouse ? DeviceIdiom.Desktop : DeviceIdiom.Tablet; diff --git a/src/Essentials/src/Platform/Platform.android.cs b/src/Essentials/src/Platform/Platform.android.cs index 39a52da56027..3c35559b518e 100644 --- a/src/Essentials/src/Platform/Platform.android.cs +++ b/src/Essentials/src/Platform/Platform.android.cs @@ -17,20 +17,16 @@ using AndroidIntent = Android.Content.Intent; using AndroidUri = Android.Net.Uri; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { - public static partial class Platform + static partial class Platform { static ActivityLifecycleContextListener lifecycleListener; - public static Context AppContext => Application.Context; - public static Activity CurrentActivity => lifecycleListener?.Activity; public static event EventHandler ActivityStateChanged; - internal const string EssentialsConnectivityChanged = "com.maui.essentials.ESSENTIALS_CONNECTIVITY_CHANGED"; - internal const int requestCodeFilePicker = 11001; internal const int requestCodeMediaPicker = 11002; internal const int requestCodeMediaCapture = 11003; diff --git a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs index a68a8364af8a..24af0f186d3c 100644 --- a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs +++ b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs @@ -14,9 +14,9 @@ using CoreMotion; #endif -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { - public static partial class Platform + static partial class Platform { #if __IOS__ || __TVOS__ public static bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) diff --git a/src/Essentials/src/Platform/Platform.macos.cs b/src/Essentials/src/Platform/Platform.macos.cs index ab944254649e..ecb5f5d7a40e 100644 --- a/src/Essentials/src/Platform/Platform.macos.cs +++ b/src/Essentials/src/Platform/Platform.macos.cs @@ -6,9 +6,9 @@ using Foundation; using ObjCRuntime; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { - public static partial class Platform + static partial class Platform { internal static NSWindow GetCurrentWindow(bool throwIfNull = true) { @@ -21,7 +21,7 @@ internal static NSWindow GetCurrentWindow(bool throwIfNull = true) } } - internal static class CoreGraphicsInterop + static class CoreGraphicsInterop { public static uint MainDisplayId => CGMainDisplayID(); @@ -51,7 +51,7 @@ public static double GetRefreshRate(uint display) } } - internal static class CVDisplayLinkInterop + static class CVDisplayLinkInterop { [DllImport(Constants.CoreGraphicsLibrary)] static extern int CVDisplayLinkCreateWithCGDisplay(uint display, out IntPtr handle); @@ -72,7 +72,7 @@ public static double GetRefreshRate(uint display) } } - internal static class IOKit + static class IOKit { const string IOKitLibrary = "/System/Library/Frameworks/IOKit.framework/IOKit"; const string IOPlatformExpertDeviceClassName = "IOPlatformExpertDevice"; diff --git a/src/Essentials/src/Platform/Platform.shared.cs b/src/Essentials/src/Platform/Platform.shared.cs index f1c4daebe136..b732fb42b974 100644 --- a/src/Essentials/src/Platform/Platform.shared.cs +++ b/src/Essentials/src/Platform/Platform.shared.cs @@ -1,7 +1,7 @@ -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { #if !NETSTANDARD - public static partial class Platform + static partial class Platform { } #endif diff --git a/src/Essentials/src/Platform/Platform.tizen.cs b/src/Essentials/src/Platform/Platform.tizen.cs index 0afe86ef89f1..d8115ac097a9 100644 --- a/src/Essentials/src/Platform/Platform.tizen.cs +++ b/src/Essentials/src/Platform/Platform.tizen.cs @@ -10,9 +10,9 @@ using TizenMagnetometer = Tizen.Sensor.Magnetometer; using TizenOrientationSensor = Tizen.Sensor.RotationVectorSensor; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { - public static partial class Platform + static partial class Platform { static TizenAccelerometer accelerometer = null; static TizenBarometer barometer = null; @@ -100,7 +100,7 @@ internal static async Task GetMapServiceAsync(string key) public static string MapServiceToken { get; set; } } - public enum SensorType + enum SensorType { Accelerometer, Barometer, diff --git a/src/Essentials/src/Platform/Platform.uwp.cs b/src/Essentials/src/Platform/Platform.uwp.cs index b1e722bb0411..0a7160221b7f 100644 --- a/src/Essentials/src/Platform/Platform.uwp.cs +++ b/src/Essentials/src/Platform/Platform.uwp.cs @@ -10,9 +10,9 @@ using Microsoft.UI.Xaml; #endif -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { - public static partial class Platform + static partial class Platform { const uint DISPLAY_CHANGED = 126; const uint DPI_CHANGED = 736; From 05e6f217fe19cefafbf58b98d89b6c0b63c83cf4 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sat, 19 Mar 2022 23:35:41 +0200 Subject: [PATCH 05/45] more --- .../Core/src/Essentials/Email.cs | 24 +++ .../Core/src/Essentials/FilePicker.cs | 21 +++ .../Core/src/Essentials/FileSystem.cs | 28 ++++ .../Core/src/Essentials/Flashlight.cs | 20 +++ .../Core/src/Essentials/Launcher.cs | 41 +++++ .../AppInfo/AppInfo.ios.tvos.watchos.macos.cs | 26 +-- src/Essentials/src/AppInfo/AppInfo.uwp.cs | 39 +++-- src/Essentials/src/Email/Email.android.cs | 27 +-- src/Essentials/src/Email/Email.ios.cs | 29 +--- src/Essentials/src/Email/Email.macos.cs | 2 +- .../Email/Email.netstandard.tvos.watchos.cs | 17 +- src/Essentials/src/Email/Email.shared.cs | 67 ++++---- src/Essentials/src/Email/Email.tizen.cs | 14 +- src/Essentials/src/Email/Email.uwp.cs | 17 +- .../src/FilePicker/FilePicker.android.cs | 29 ++-- .../src/FilePicker/FilePicker.ios.cs | 18 +- .../src/FilePicker/FilePicker.macos.cs | 10 +- .../FilePicker.netstandard.watchos.tvos.cs | 13 +- .../src/FilePicker/FilePicker.shared.cs | 37 +++-- .../src/FilePicker/FilePicker.tizen.cs | 10 +- .../src/FilePicker/FilePicker.uwp.cs | 29 ++-- .../src/FileSystem/FileSystem.android.cs | 75 +++++---- .../src/FileSystem/FileSystem.ios.cs | 10 +- .../FileSystem.ios.tvos.watchos.macos.cs | 19 +-- .../src/FileSystem/FileSystem.netstandard.cs | 4 +- .../src/FileSystem/FileSystem.shared.cs | 115 ++++--------- .../src/FileSystem/FileSystem.uwp.cs | 20 +-- .../src/Flashlight/Flashlight.shared.cs | 19 +-- .../src/Launcher/Launcher.android.cs | 8 +- .../src/Launcher/Launcher.shared.cs | 157 ++++++------------ src/Essentials/src/Launcher/Launcher.uwp.cs | 1 - 31 files changed, 433 insertions(+), 513 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/Email.cs create mode 100644 src/Compatibility/Core/src/Essentials/FilePicker.cs create mode 100644 src/Compatibility/Core/src/Essentials/FileSystem.cs create mode 100644 src/Compatibility/Core/src/Essentials/Flashlight.cs create mode 100644 src/Compatibility/Core/src/Essentials/Launcher.cs diff --git a/src/Compatibility/Core/src/Essentials/Email.cs b/src/Compatibility/Core/src/Essentials/Email.cs new file mode 100644 index 000000000000..f6eff1245dee --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Email.cs @@ -0,0 +1,24 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel.Communication; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Email + { + /// + public static Task ComposeAsync() => + Current.ComposeAsync(); + + /// + public static Task ComposeAsync(string subject, string body, params string[] to) => + Current.ComposeAsync(subject, body, to); + + /// + public static Task ComposeAsync(EmailMessage message) => + Current.ComposeAsync(message); + + static IEmail Current => ApplicationModel.Communication.Email.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/FilePicker.cs b/src/Compatibility/Core/src/Essentials/FilePicker.cs new file mode 100644 index 000000000000..396fb8b6b649 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/FilePicker.cs @@ -0,0 +1,21 @@ +#nullable enable +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Maui.Storage; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class FilePicker + { + /// + public static Task PickAsync(PickOptions? options = null) => + Current.PickAsync(options); + + /// + public static Task> PickMultipleAsync(PickOptions? options = null) => + Current.PickMultipleAsync(options); + + static IFilePicker Current => Storage.FilePicker.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/FileSystem.cs b/src/Compatibility/Core/src/Essentials/FileSystem.cs new file mode 100644 index 000000000000..6ee2d4cc1888 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/FileSystem.cs @@ -0,0 +1,28 @@ +#nullable enable +using System.IO; +using System.Threading.Tasks; +using Microsoft.Maui.Storage; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class FileSystem + { + /// + public static string CacheDirectory + => Current.CacheDirectory; + + /// + public static string AppDataDirectory + => Current.AppDataDirectory; + + /// + public static Task OpenAppPackageFileAsync(string filename) + => Current.OpenAppPackageFileAsync(filename); + + public static Task AppPackageFileExistsAsync(string filename) + => Current.AppPackageFileExistsAsync(filename); + + static IFileSystem Current => Storage.FileSystem.Current; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Flashlight.cs b/src/Compatibility/Core/src/Essentials/Flashlight.cs new file mode 100644 index 000000000000..f74208195e76 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Flashlight.cs @@ -0,0 +1,20 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Flashlight + { + /// + public static Task TurnOnAsync() => + Current.TurnOnAsync(); + + /// + public static Task TurnOffAsync() => + Current.TurnOffAsync(); + + static IFlashlight Current => Devices.Flashlight.Current; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Launcher.cs b/src/Compatibility/Core/src/Essentials/Launcher.cs new file mode 100644 index 000000000000..aac36a2a410b --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Launcher.cs @@ -0,0 +1,41 @@ +#nullable enable +using System; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Launcher + { + /// + public static Task CanOpenAsync(string uri) + => Current.CanOpenAsync(uri); + + /// + public static Task CanOpenAsync(Uri uri) + => Current.CanOpenAsync(uri); + + /// + public static Task OpenAsync(string uri) + => Current.OpenAsync(uri); + + /// + public static Task OpenAsync(Uri uri) + => Current.OpenAsync(uri); + + /// + public static Task OpenAsync(OpenFileRequest request) + => Current.OpenAsync(request); + + /// + public static Task TryOpenAsync(string uri) + => Current.TryOpenAsync(uri); + + /// + public static Task TryOpenAsync(Uri uri) + => Current.TryOpenAsync(uri); + + static ILauncher Current => ApplicationModel.Launcher.Default; + } +} diff --git a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs index d658ca979eb9..a8cbe32b1b52 100644 --- a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs @@ -26,21 +26,21 @@ class AppInfoImplementation : IAppInfo public string BuildString => GetBundleValue("CFBundleVersion"); string GetBundleValue(string key) - => NSBundle.MainBundle.ObjectForInfoDictionary(key)?.ToString(); + => NSBundle.MainBundle.ObjectForInfoDictionary(key)?.ToString(); #if __IOS__ || __TVOS__ public async void ShowSettingsUI() => await Launcher.OpenAsync(UIApplication.OpenSettingsUrlString); #elif __MACOS__ - public void ShowSettingsUI() - { - MainThread.BeginInvokeOnMainThread(() => - { - var prefsApp = ScriptingBridge.SBApplication.FromBundleIdentifier("com.apple.systempreferences"); - prefsApp.SendMode = ScriptingBridge.AESendMode.NoReply; - prefsApp.Activate(); - }); - } + public void ShowSettingsUI() + { + MainThread.BeginInvokeOnMainThread(() => + { + var prefsApp = ScriptingBridge.SBApplication.FromBundleIdentifier("com.apple.systempreferences"); + prefsApp.SendMode = ScriptingBridge.AESendMode.NoReply; + prefsApp.Activate(); + }); + } #else public void ShowSettingsUI() => throw new FeatureNotSupportedException(); @@ -69,8 +69,8 @@ public AppTheme RequestedTheme } } #elif __MACOS__ - public AppTheme RequestedTheme - { + public AppTheme RequestedTheme + { get { if (OperatingSystem.IsMacOSVersionAtLeast(10, 14)) @@ -89,7 +89,7 @@ public AppTheme RequestedTheme } return AppTheme.Light; } - } + } #else public AppTheme RequestedTheme => AppTheme.Unspecified; diff --git a/src/Essentials/src/AppInfo/AppInfo.uwp.cs b/src/Essentials/src/AppInfo/AppInfo.uwp.cs index b294cc158294..25ddf08ac84f 100644 --- a/src/Essentials/src/AppInfo/AppInfo.uwp.cs +++ b/src/Essentials/src/AppInfo/AppInfo.uwp.cs @@ -11,26 +11,11 @@ namespace Microsoft.Maui.ApplicationModel { class AppInfoImplementation : IAppInfo { - static Lazy _isPackagedAppLazy = new Lazy(() => - { - try - { - if (Package.Current != null) - return true; - } - catch - { - // no-op - } - - return false; - }); - public string PackageName => Package.Current.Id.Name; public string Name => Package.Current.DisplayName; - public System.Version Version => Utils.ParseVersion(VersionString); + public Version Version => Utils.ParseVersion(VersionString); public string VersionString { @@ -50,11 +35,31 @@ public void ShowSettingsUI() => public AppTheme RequestedTheme => Application.Current.RequestedTheme == ApplicationTheme.Dark ? AppTheme.Dark : AppTheme.Light; - public AppPackagingModel PackagingModel => _isPackagedAppLazy.Value + public AppPackagingModel PackagingModel => AppInfoUtils.IsPackagedApp ? AppPackagingModel.Packaged : AppPackagingModel.Unpackaged; public LayoutDirection RequestedLayoutDirection => CultureInfo.CurrentCulture.TextInfo.IsRightToLeft ? LayoutDirection.RightToLeft : LayoutDirection.LeftToRight; } + + static class AppInfoUtils + { + static readonly Lazy _isPackagedAppLazy = new Lazy(() => + { + try + { + if (Package.Current != null) + return true; + } + catch + { + // no-op + } + + return false; + }); + + public static bool IsPackagedApp => _isPackagedAppLazy.Value; + } } \ No newline at end of file diff --git a/src/Essentials/src/Email/Email.android.cs b/src/Essentials/src/Email/Email.android.cs index 2c3c6fdb04d0..4056f51c9999 100644 --- a/src/Essentials/src/Email/Email.android.cs +++ b/src/Essentials/src/Email/Email.android.cs @@ -1,11 +1,10 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; +using Android.App; using Android.Content; using Android.OS; using Android.Text; -using Android.Webkit; using Microsoft.Maui.Storage; using Uri = Android.Net.Uri; @@ -14,38 +13,26 @@ namespace Microsoft.Maui.ApplicationModel.Communication partial class EmailImplementation : IEmail { static EmailMessage testEmail => - new ("Testing Microsoft.Maui.Essentials", "This is a test email.", "Microsoft.Maui.Essentials@example.org"); + new("Testing Microsoft.Maui.Essentials", "This is a test email.", "Microsoft.Maui.Essentials@example.org"); public bool IsComposeSupported => Platform.IsIntentSupported(CreateIntent(testEmail)); - public Task ComposeAsync(EmailMessage message) + Task PlatformComposeAsync(EmailMessage message) { var intent = CreateIntent(message); var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; #if __ANDROID_24__ - if (Platform.HasApiLevelN) + if (OperatingSystem.IsAndroidVersionAtLeast(24)) flags |= ActivityFlags.LaunchAdjacent; #endif intent.SetFlags(flags); - Platform.AppContext.StartActivity(intent); + Application.Context.StartActivity(intent); return Task.FromResult(true); } - public Task ComposeAsync(string subject, string body, params string[] to) - => ComposeAsync( - new EmailMessage() - { - Subject = subject, - Body = body, - To = to.ToList() - }); - - public Task ComposeAsync() - => ComposeAsync(null); - static Intent CreateIntent(EmailMessage message) { var action = (message?.Attachments?.Count ?? 0) switch @@ -59,7 +46,7 @@ static Intent CreateIntent(EmailMessage message) if (action == Intent.ActionSendto) intent.SetData(Uri.Parse("mailto:")); else - intent.SetType(FileSystem.MimeTypes.EmailMessage); + intent.SetType(FileMimeTypes.EmailMessage); if (!string.IsNullOrEmpty(message?.Body)) { @@ -67,7 +54,7 @@ static Intent CreateIntent(EmailMessage message) { ISpanned html; #if __ANDROID_24__ - if (Platform.HasApiLevelN) + if (OperatingSystem.IsAndroidVersionAtLeast(24)) { html = Html.FromHtml(message.Body, FromHtmlOptions.ModeLegacy); } diff --git a/src/Essentials/src/Email/Email.ios.cs b/src/Essentials/src/Email/Email.ios.cs index 5407fef2b99d..718159b8304c 100644 --- a/src/Essentials/src/Email/Email.ios.cs +++ b/src/Essentials/src/Email/Email.ios.cs @@ -1,12 +1,10 @@ using System.IO; using System.Threading.Tasks; -using System.Linq; using Foundation; +using UIKit; #if !(MACCATALYST || MACOS) using MessageUI; #endif -using ObjCRuntime; -using UIKit; namespace Microsoft.Maui.ApplicationModel.Communication { @@ -15,12 +13,12 @@ partial class EmailImplementation : IEmail public bool IsComposeSupported => #if !(MACCATALYST || MACOS) MFMailComposeViewController.CanSendMail || - MainThread.InvokeOnMainThread(() => UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("mailto:"))); + MainThread.InvokeOnMainThread(() => UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("mailto:"))); #else false; #endif - public Task ComposeAsync(EmailMessage message) + Task PlatformComposeAsync(EmailMessage message) { #if !(MACCATALYST || MACOS) if (MFMailComposeViewController.CanSendMail) @@ -32,20 +30,7 @@ public Task ComposeAsync(EmailMessage message) #endif } - public Task ComposeAsync(string subject, string body, params string[] to) - => ComposeAsync( - new EmailMessage() - { - Subject = subject, - Body = body, - To = to.ToList() - }); - - public Task ComposeAsync() - => ComposeAsync(null); - - - internal Task ComposeWithMailCompose(EmailMessage message) + Task ComposeWithMailCompose(EmailMessage message) { #if !(MACCATALYST || MACOS) // do this first so we can throw as early as possible @@ -98,11 +83,11 @@ internal Task ComposeWithMailCompose(EmailMessage message) #endif } - internal async Task ComposeWithUrl(EmailMessage message) + Task ComposeWithUrl(EmailMessage message) { - var url = Email.GetMailToUri(message); + var url = GetMailToUri(message); var nsurl = NSUrl.FromString(url); - await Launcher.OpenAsync(nsurl); + return Launcher.OpenAsync(nsurl); } } } diff --git a/src/Essentials/src/Email/Email.macos.cs b/src/Essentials/src/Email/Email.macos.cs index f7e685d254c7..d87771b88082 100644 --- a/src/Essentials/src/Email/Email.macos.cs +++ b/src/Essentials/src/Email/Email.macos.cs @@ -9,7 +9,7 @@ partial class EmailImplementation : IEmail public bool IsComposeSupported => MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString("mailto:")) != null); - public Task ComposeAsync(EmailMessage message) + Task PlatformComposeAsync(EmailMessage message) { var url = GetMailToUri(message); diff --git a/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs b/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs index 1dbfffd3983b..4fe873391a93 100644 --- a/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Email/Email.netstandard.tvos.watchos.cs @@ -8,22 +8,7 @@ partial class EmailImplementation : IEmail public bool IsComposeSupported => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task ComposeAsync(EmailMessage message) => - throw ExceptionUtils.NotSupportedOrImplementedException; - - public Task ComposeAsync(string subject, string body, params string[] to) - => throw ExceptionUtils.NotSupportedOrImplementedException; - - public Task ComposeAsync() => - throw ExceptionUtils.NotSupportedOrImplementedException; - } - -#if NETSTANDARD || NET6_0 -/// - public partial class EmailAttachment - { - string PlatformGetContentType(string extension) => + Task PlatformComposeAsync(EmailMessage message) => throw ExceptionUtils.NotSupportedOrImplementedException; } -#endif } diff --git a/src/Essentials/src/Email/Email.shared.cs b/src/Essentials/src/Email/Email.shared.cs index 6f4c58b26b08..87f4c453f5aa 100644 --- a/src/Essentials/src/Email/Email.shared.cs +++ b/src/Essentials/src/Email/Email.shared.cs @@ -1,9 +1,8 @@ +#nullable enable using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel.Communication; using Microsoft.Maui.Storage; namespace Microsoft.Maui.ApplicationModel.Communication @@ -11,37 +10,30 @@ namespace Microsoft.Maui.ApplicationModel.Communication public interface IEmail { bool IsComposeSupported { get; } - - Task ComposeAsync(); - - Task ComposeAsync(string subject, string body, params string[] to); - Task ComposeAsync(EmailMessage message); + Task ComposeAsync(EmailMessage? message); } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Email + + public static class EmailExtensions { - /// - public static Task ComposeAsync() - => ComposeAsync(null); + public static Task ComposeAsync(this IEmail email) => + email.ComposeAsync(null); - /// - public static Task ComposeAsync(string subject, string body, params string[] to) - => ComposeAsync(new EmailMessage(subject, body, to)); + public static Task ComposeAsync(this IEmail email, string subject, string body, params string[] to) => + email.ComposeAsync(new EmailMessage(subject, body, to)); + } - /// - public static Task ComposeAsync(EmailMessage message) + partial class EmailImplementation : IEmail + { + public Task ComposeAsync(EmailMessage? message) { - if (!Current.IsComposeSupported) + if (!IsComposeSupported) throw new FeatureNotSupportedException(); - return Current.ComposeAsync(message); + return PlatformComposeAsync(message); } - internal static string GetMailToUri(EmailMessage message) + static string GetMailToUri(EmailMessage message) { if (message != null && message.BodyFormat != EmailBodyFormat.PlainText) throw new FeatureNotSupportedException("Only EmailBodyFormat.PlainText is supported if no email account is set up."); @@ -66,20 +58,19 @@ internal static string GetMailToUri(EmailMessage message) return uri; } + } -#nullable enable - static IEmail? currentImplementation; + public static class Email + { + static IEmail? defaultImplementation; - public static IEmail Current => - currentImplementation ??= new EmailImplementation(); + public static IEmail Default => + defaultImplementation ??= new EmailImplementation(); internal static void SetCurrent(IEmail? implementation) => - currentImplementation = implementation; -#nullable disable + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.ApplicationModel.Communication -{ + /// public class EmailMessage { @@ -97,25 +88,25 @@ public EmailMessage(string subject, string body, params string[] to) } /// - public string Subject { get; set; } + public string? Subject { get; set; } /// - public string Body { get; set; } + public string? Body { get; set; } /// public EmailBodyFormat BodyFormat { get; set; } /// - public List To { get; set; } = new List(); + public List? To { get; set; } = new List(); /// - public List Cc { get; set; } = new List(); + public List? Cc { get; set; } = new List(); /// - public List Bcc { get; set; } = new List(); + public List? Bcc { get; set; } = new List(); /// - public List Attachments { get; set; } = new List(); + public List? Attachments { get; set; } = new List(); } /// diff --git a/src/Essentials/src/Email/Email.tizen.cs b/src/Essentials/src/Email/Email.tizen.cs index 15aa4b132d15..a28815452f38 100644 --- a/src/Essentials/src/Email/Email.tizen.cs +++ b/src/Essentials/src/Email/Email.tizen.cs @@ -9,7 +9,7 @@ partial class EmailImplementation : IEmail public bool IsComposeSupported => Platform.GetFeatureInfo("email"); - public Task ComposeAsync(EmailMessage message) + Task PlatformComposeAsync(EmailMessage message) { Permissions.EnsureDeclared(); @@ -34,17 +34,5 @@ public Task ComposeAsync(EmailMessage message) return Task.CompletedTask; } - - public Task ComposeAsync(string subject, string body, params string[] to) - => ComposeAsync( - new EmailMessage - { - Subject = subject, - Body = body, - To = to.List() - }); - - public Task ComposeAsync() - => ComposeAsync(null); } } diff --git a/src/Essentials/src/Email/Email.uwp.cs b/src/Essentials/src/Email/Email.uwp.cs index 1664fa9b53f8..cb5f55659969 100644 --- a/src/Essentials/src/Email/Email.uwp.cs +++ b/src/Essentials/src/Email/Email.uwp.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Threading.Tasks; using Windows.ApplicationModel.Email; using Windows.Foundation.Metadata; @@ -17,7 +16,7 @@ partial class EmailImplementation : IEmail public bool IsComposeSupported => ApiInformation.IsTypePresent("Windows.ApplicationModel.Email.EmailManager"); - public async Task ComposeAsync(EmailMessage message) + async Task PlatformComposeAsync(EmailMessage message) { if (message != null && message.BodyFormat != EmailBodyFormat.PlainText) throw new FeatureNotSupportedException("UWP can only compose plain text email messages."); @@ -53,21 +52,9 @@ public async Task ComposeAsync(EmailMessage message) await EmailManager.ShowComposeNewEmailAsync(platformEmailMessage); } - internal static string NormalizePath(string path) + static string NormalizePath(string path) => path.Replace('/', Path.DirectorySeparatorChar); - public Task ComposeAsync(string subject, string body, params string[] to) - => ComposeAsync( - new EmailMessage() - { - Subject = subject, - Body = body, - To = to.ToList() - }); - - public Task ComposeAsync() - => ComposeAsync(null); - void Sync(List recipients, IList nativeRecipients) { if (recipients == null) diff --git a/src/Essentials/src/FilePicker/FilePicker.android.cs b/src/Essentials/src/FilePicker/FilePicker.android.cs index 824cb5d9c50b..815b914b078a 100644 --- a/src/Essentials/src/FilePicker/FilePicker.android.cs +++ b/src/Essentials/src/FilePicker/FilePicker.android.cs @@ -1,23 +1,22 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using Android.Content; +using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices; -using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { - public static partial class FilePicker + partial class FilePickerImplementation : IFilePicker { - static async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) + async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) { // Essentials supports >= API 19 where this action is available var action = Intent.ActionOpenDocument; var intent = new Intent(action); - intent.SetType(FileSystem.MimeTypes.All); + intent.SetType(FileMimeTypes.All); intent.PutExtra(Intent.ExtraAllowMultiple, allowMultiple); var allowedTypes = options?.FileTypes?.Value?.ToArray(); @@ -37,7 +36,7 @@ void OnResult(Intent intent) if (intent.ClipData == null) { - var path = FileSystem.EnsurePhysicalPath(intent.Data); + var path = FileSystemUtils.EnsurePhysicalPath(intent.Data); resultList.Add(new FileResult(path)); } else @@ -45,7 +44,7 @@ void OnResult(Intent intent) for (var i = 0; i < intent.ClipData.ItemCount; i++) { var uri = intent.ClipData.GetItemAt(i).Uri; - var path = FileSystem.EnsurePhysicalPath(uri); + var path = FileSystemUtils.EnsurePhysicalPath(uri); resultList.Add(new FileResult(path)); } } @@ -61,39 +60,37 @@ void OnResult(Intent intent) } } } -} -namespace Microsoft.Maui.Storage -{ + public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.Android, new[] { FileSystem.MimeTypes.ImagePng, FileSystem.MimeTypes.ImageJpg } } + { DevicePlatform.Android, new[] { FileMimeTypes.ImagePng, FileMimeTypes.ImageJpg } } }); static FilePickerFileType PlatformPngFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.Android, new[] { FileSystem.MimeTypes.ImagePng } } + { DevicePlatform.Android, new[] { FileMimeTypes.ImagePng } } }); static FilePickerFileType PlatformJpegFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.Android, new[] { FileSystem.MimeTypes.ImageJpg } } + { DevicePlatform.Android, new[] { FileMimeTypes.ImageJpg } } }); static FilePickerFileType PlatformVideoFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.Android, new[] { FileSystem.MimeTypes.VideoAll } } + { DevicePlatform.Android, new[] { FileMimeTypes.VideoAll } } }); static FilePickerFileType PlatformPdfFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.Android, new[] { FileSystem.MimeTypes.Pdf } } + { DevicePlatform.Android, new[] { FileMimeTypes.Pdf } } }); } } diff --git a/src/Essentials/src/FilePicker/FilePicker.ios.cs b/src/Essentials/src/FilePicker/FilePicker.ios.cs index aa7213b8b383..160b09619ced 100644 --- a/src/Essentials/src/FilePicker/FilePicker.ios.cs +++ b/src/Essentials/src/FilePicker/FilePicker.ios.cs @@ -1,20 +1,17 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading.Tasks; using Foundation; +using Microsoft.Maui.Devices; using MobileCoreServices; -using ObjCRuntime; using UIKit; -using Microsoft.Maui.Devices; -using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { - public static partial class FilePicker + partial class FilePickerImplementation : IFilePicker { - static async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) + async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) { var allowedUtis = options?.FileTypes?.Value?.ToArray() ?? new string[] { @@ -52,7 +49,7 @@ static async void GetFileResults(NSUrl[] urls, TaskCompletionSource PickHandler?.Invoke(new NSUrl[] { url }); } - } -} -namespace Microsoft.Maui.Storage -{ + public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FilePicker/FilePicker.macos.cs b/src/Essentials/src/FilePicker/FilePicker.macos.cs index 150d8512b16d..a0f8ec2ecd67 100644 --- a/src/Essentials/src/FilePicker/FilePicker.macos.cs +++ b/src/Essentials/src/FilePicker/FilePicker.macos.cs @@ -4,11 +4,11 @@ using AppKit; using MobileCoreServices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { - public static partial class FilePicker + partial class FilePickerImplementation : IFilePicker { - static Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) + Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) { var openPanel = new NSOpenPanel { @@ -48,9 +48,7 @@ static void SetFileTypes(PickOptions options, NSOpenPanel panel) panel.AllowedFileTypes = allowedFileTypes.ToArray(); } } -} -namespace Microsoft.Maui.Storage -{ + public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs b/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs index 52f1157e69bc..bb64dd47702a 100644 --- a/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs +++ b/src/Essentials/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs @@ -1,19 +1,14 @@ using System.Collections.Generic; -using System.IO; using System.Threading.Tasks; -using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { - /// - public static partial class FilePicker + partial class FilePickerImplementation : IFilePicker { - static Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) + Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) => throw new NotImplementedInReferenceAssemblyException(); } -} -namespace Microsoft.Maui.Storage -{ + /// public partial class FilePickerFileType { diff --git a/src/Essentials/src/FilePicker/FilePicker.shared.cs b/src/Essentials/src/FilePicker/FilePicker.shared.cs index f976ba38190f..b92514c3fc30 100644 --- a/src/Essentials/src/FilePicker/FilePicker.shared.cs +++ b/src/Essentials/src/FilePicker/FilePicker.shared.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.IO; @@ -6,22 +7,36 @@ using Microsoft.Maui.Devices; using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { + public interface IFilePicker + { + Task PickAsync(PickOptions? options = null); + + Task> PickMultipleAsync(PickOptions? options = null); + } + /// - public static partial class FilePicker + public static class FilePicker + { + static IFilePicker? defaultImplementation; + + public static IFilePicker Default => + defaultImplementation ??= new FilePickerImplementation(); + + internal static void SetDefault(IFilePicker? implementation) => + defaultImplementation = implementation; + } + + partial class FilePickerImplementation : IFilePicker { - /// - public static async Task PickAsync(PickOptions options = null) => + public async Task PickAsync(PickOptions? options = null) => (await PlatformPickAsync(options))?.FirstOrDefault(); - /// - public static Task> PickMultipleAsync(PickOptions options = null) => + public Task> PickMultipleAsync(PickOptions? options = null) => PlatformPickAsync(options ?? PickOptions.Default, true); } -} -namespace Microsoft.Maui.Storage -{ + /// public partial class FilePickerFileType { @@ -76,9 +91,9 @@ public class PickOptions }; /// - public string PickerTitle { get; set; } + public string? PickerTitle { get; set; } /// - public FilePickerFileType FileTypes { get; set; } + public FilePickerFileType? FileTypes { get; set; } } } diff --git a/src/Essentials/src/FilePicker/FilePicker.tizen.cs b/src/Essentials/src/FilePicker/FilePicker.tizen.cs index 8232e5cb410d..c330a306856f 100644 --- a/src/Essentials/src/FilePicker/FilePicker.tizen.cs +++ b/src/Essentials/src/FilePicker/FilePicker.tizen.cs @@ -7,11 +7,11 @@ using Tizen; using Tizen.Applications; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { - public static partial class FilePicker + partial class FilePickerImplementation : IFilePicker { - static async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) + async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) { Permissions.EnsureDeclared(); await Permissions.EnsureGrantedAsync(); @@ -45,9 +45,7 @@ static async Task> PlatformPickAsync(PickOptions options return await tcs.Task; } } -} -namespace Microsoft.Maui.Storage -{ + public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => diff --git a/src/Essentials/src/FilePicker/FilePicker.uwp.cs b/src/Essentials/src/FilePicker/FilePicker.uwp.cs index 4d8b5282f313..990b43f54e40 100644 --- a/src/Essentials/src/FilePicker/FilePicker.uwp.cs +++ b/src/Essentials/src/FilePicker/FilePicker.uwp.cs @@ -3,16 +3,15 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.Maui.Devices; -using Microsoft.Maui.Storage; using Windows.Storage; using Windows.Storage.AccessCache; using Windows.Storage.Pickers; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { - public static partial class FilePicker + partial class FilePickerImplementation : IFilePicker { - static async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) + async Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false) { var picker = new FileOpenPicker { @@ -54,7 +53,7 @@ static void SetFileTypes(PickOptions options, FileOpenPicker picker) { foreach (var type in options.FileTypes.Value) { - var ext = FileSystem.Extensions.Clean(type); + var ext = FileExtensions.Clean(type); if (!string.IsNullOrWhiteSpace(ext)) { picker.FileTypeFilter.Add(ext); @@ -67,39 +66,37 @@ static void SetFileTypes(PickOptions options, FileOpenPicker picker) picker.FileTypeFilter.Add("*"); } } -} -namespace Microsoft.Maui.Storage -{ + public partial class FilePickerFileType { static FilePickerFileType PlatformImageFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.WinUI, FileSystem.Extensions.AllImage } + { DevicePlatform.WinUI, FileExtensions.AllImage } }); static FilePickerFileType PlatformPngFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.WinUI, new[] { FileSystem.Extensions.Png } } + { DevicePlatform.WinUI, new[] { FileExtensions.Png } } }); static FilePickerFileType PlatformJpegFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.WinUI, FileSystem.Extensions.AllJpeg } + { DevicePlatform.WinUI, FileExtensions.AllJpeg } }); static FilePickerFileType PlatformVideoFileType() => - new FilePickerFileType(new Dictionary> - { - { DevicePlatform.WinUI, FileSystem.Extensions.AllVideo } - }); + new FilePickerFileType(new Dictionary> + { + { DevicePlatform.WinUI, FileExtensions.AllVideo } + }); static FilePickerFileType PlatformPdfFileType() => new FilePickerFileType(new Dictionary> { - { DevicePlatform.WinUI, new[] { FileSystem.Extensions.Pdf } } + { DevicePlatform.WinUI, new[] { FileExtensions.Pdf } } }); } } diff --git a/src/Essentials/src/FileSystem/FileSystem.android.cs b/src/Essentials/src/FileSystem/FileSystem.android.cs index dd3e3d055235..e5052314db7f 100644 --- a/src/Essentials/src/FileSystem/FileSystem.android.cs +++ b/src/Essentials/src/FileSystem/FileSystem.android.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Threading.Tasks; +using Android.App; using Android.Provider; using Android.Webkit; using Microsoft.Maui.ApplicationModel; @@ -9,34 +10,13 @@ namespace Microsoft.Maui.Storage { - partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem + partial class FileSystemImplementation : IFileSystem { - internal const string EssentialsFolderHash = "2203693cc04e0be7f4f024d5f9499e13"; - - const string storageTypePrimary = "primary"; - const string storageTypeRaw = "raw"; - const string storageTypeImage = "image"; - const string storageTypeVideo = "video"; - const string storageTypeAudio = "audio"; - static readonly string[] contentUriPrefixes = - { - "content://downloads/public_downloads", - "content://downloads/my_downloads", - "content://downloads/all_downloads", - }; - - internal const string UriSchemeFile = "file"; - internal const string UriSchemeContent = "content"; - - internal const string UriAuthorityExternalStorage = "com.android.externalstorage.documents"; - internal const string UriAuthorityDownloads = "com.android.providers.downloads.documents"; - internal const string UriAuthorityMedia = "com.android.providers.media.documents"; - string PlatformCacheDirectory - => Platform.AppContext.CacheDir.AbsolutePath; + => Application.Context.CacheDir.AbsolutePath; string PlatformAppDataDirectory - => Platform.AppContext.FilesDir.AbsolutePath; + => Application.Context.FilesDir.AbsolutePath; Task PlatformOpenAppPackageFileAsync(string filename) => Task.FromResult(PlatformOpenAppPackageFile(filename)); @@ -59,22 +39,43 @@ Stream PlatformOpenAppPackageFile(string filename) if (filename == null) throw new ArgumentNullException(nameof(filename)); - filename = NormalizePath(filename); + filename = FileSystemUtils.NormalizePath(filename); try { - return Platform.AppContext.Assets.Open(filename); + return Application.Context.Assets.Open(filename); } catch (Java.IO.FileNotFoundException ex) { throw new FileNotFoundException(ex.Message, filename, ex); } } + } - static string NormalizePath(string filename) => - filename.Replace('\\', Path.DirectorySeparatorChar); + static partial class FileSystemUtils + { + internal const string EssentialsFolderHash = "2203693cc04e0be7f4f024d5f9499e13"; + + const string storageTypePrimary = "primary"; + const string storageTypeRaw = "raw"; + const string storageTypeImage = "image"; + const string storageTypeVideo = "video"; + const string storageTypeAudio = "audio"; + static readonly string[] contentUriPrefixes = + { + "content://downloads/public_downloads", + "content://downloads/my_downloads", + "content://downloads/all_downloads", + }; + + internal const string UriSchemeFile = "file"; + internal const string UriSchemeContent = "content"; - public Java.IO.File GetTemporaryFile(Java.IO.File root, string fileName) + internal const string UriAuthorityExternalStorage = "com.android.externalstorage.documents"; + internal const string UriAuthorityDownloads = "com.android.providers.downloads.documents"; + internal const string UriAuthorityMedia = "com.android.providers.media.documents"; + + public static Java.IO.File GetTemporaryFile(Java.IO.File root, string fileName) { // create the directory for all Essentials files var rootDir = new Java.IO.File(root, EssentialsFolderHash); @@ -93,8 +94,7 @@ public Java.IO.File GetTemporaryFile(Java.IO.File root, string fileName) return tmpFile; } - - public string EnsurePhysicalPath(AndroidUri uri, bool requireExtendedAccess = true) + public static string EnsurePhysicalPath(AndroidUri uri, bool requireExtendedAccess = true) { // if this is a file, use that if (uri.Scheme.Equals(UriSchemeFile, StringComparison.OrdinalIgnoreCase)) @@ -127,7 +127,7 @@ static string ResolvePhysicalPath(AndroidUri uri, bool requireExtendedAccess = t { // if this is on an older OS version, or we just need it now - if (Platform.HasApiLevelKitKat && DocumentsContract.IsDocumentUri(Platform.AppContext, uri)) + if (Platform.HasApiLevelKitKat && DocumentsContract.IsDocumentUri(Application.Context, uri)) { var resolved = ResolveDocumentPath(uri); if (File.Exists(resolved)) @@ -247,7 +247,7 @@ static string ResolveContentPath(AndroidUri uri) return null; } - string CacheContentFile(AndroidUri uri) + static string CacheContentFile(AndroidUri uri) { if (!uri.Scheme.Equals(UriSchemeContent, StringComparison.OrdinalIgnoreCase)) return null; @@ -270,8 +270,8 @@ string CacheContentFile(AndroidUri uri) // create a temporary file var hasPermission = Permissions.IsDeclaredInManifest(global::Android.Manifest.Permission.WriteExternalStorage); var root = hasPermission - ? Platform.AppContext.ExternalCacheDir - : Platform.AppContext.CacheDir; + ? Application.Context.ExternalCacheDir + : Application.Context.CacheDir; var tmpFile = GetTemporaryFile(root, filename); // copy to the destination @@ -296,7 +296,7 @@ static Stream OpenContentStream(AndroidUri uri, out string extension) static bool IsVirtualFile(AndroidUri uri) { - if (!DocumentsContract.IsDocumentUri(Platform.AppContext, uri)) + if (!DocumentsContract.IsDocumentUri(Application.Context, uri)) return false; var value = GetColumnValue(uri, DocumentsContract.Document.ColumnFlags); @@ -311,7 +311,7 @@ static bool IsVirtualFile(AndroidUri uri) static Stream GetVirtualFileStream(AndroidUri uri, out string extension) { - var mimeTypes = Platform.ContentResolver.GetStreamTypes(uri, FileSystem.MimeTypes.All); + var mimeTypes = Platform.ContentResolver.GetStreamTypes(uri, FileMimeTypes.All); if (mimeTypes?.Length >= 1) { var mimeType = mimeTypes[0]; @@ -383,7 +383,6 @@ static string QueryContentResolverColumn(AndroidUri contentUri, string columnNam return text; } - } public partial class FileBase diff --git a/src/Essentials/src/FileSystem/FileSystem.ios.cs b/src/Essentials/src/FileSystem/FileSystem.ios.cs index 91cb7a518ec0..2604435873b1 100644 --- a/src/Essentials/src/FileSystem/FileSystem.ios.cs +++ b/src/Essentials/src/FileSystem/FileSystem.ios.cs @@ -4,15 +4,14 @@ using System.Linq; using System.Threading.Tasks; using Foundation; -using ObjCRuntime; using Photos; using UIKit; namespace Microsoft.Maui.Storage { - partial class FileSystemImplementation : IFileSystem, IPlatformFileSystem + static partial class FileSystemUtils { - public async Task EnsurePhysicalFileResultsAsync(params NSUrl[] urls) + public static async Task EnsurePhysicalFileResultsAsync(params NSUrl[] urls) { if (urls == null || urls.Length == 0) return Array.Empty(); @@ -47,10 +46,7 @@ public async Task EnsurePhysicalFileResultsAsync(params NSUrl[] ur return await tcs.Task; } } -} -namespace Microsoft.Maui.Storage -{ class BookmarkDataFileResult : FileResult { NSData bookmark; @@ -190,7 +186,7 @@ internal UIImageFileResult(UIImage image) { uiImage = image; - FullPath = Guid.NewGuid().ToString() + FileSystem.Extensions.Png; + FullPath = Guid.NewGuid().ToString() + FileExtensions.Png; FileName = FullPath; } diff --git a/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs b/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs index 3c449eba803b..eaa83c5485b6 100644 --- a/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs @@ -2,31 +2,33 @@ using System.IO; using System.Threading.Tasks; using Foundation; -using MobileCoreServices; namespace Microsoft.Maui.Storage { partial class FileSystemImplementation : IFileSystem { string PlatformCacheDirectory - => GetDirectory(NSSearchPathDirectory.CachesDirectory); + => FileSystemUtils.GetDirectory(NSSearchPathDirectory.CachesDirectory); string PlatformAppDataDirectory - => GetDirectory(NSSearchPathDirectory.LibraryDirectory); + => FileSystemUtils.GetDirectory(NSSearchPathDirectory.LibraryDirectory); Task PlatformOpenAppPackageFileAsync(string filename) { - var file = PlatformGetFullAppPackageFilePath(filename); + var file = FileSystemUtils.PlatformGetFullAppPackageFilePath(filename); return Task.FromResult((Stream)File.OpenRead(file)); } Task PlatformAppPackageFileExistsAsync(string filename) { - var file = PlatformGetFullAppPackageFilePath(filename); + var file = FileSystemUtils.PlatformGetFullAppPackageFilePath(filename); return Task.FromResult(File.Exists(file)); } + } - static string PlatformGetFullAppPackageFilePath(string filename) + static partial class FileSystemUtils + { + public static string PlatformGetFullAppPackageFilePath(string filename) { if (filename == null) throw new ArgumentNullException(nameof(filename)); @@ -40,10 +42,7 @@ static string PlatformGetFullAppPackageFilePath(string filename) return Path.Combine(root, filename); } - static string NormalizePath(string filename) => - filename.Replace('\\', Path.DirectorySeparatorChar); - - static string GetDirectory(NSSearchPathDirectory directory) + public static string GetDirectory(NSSearchPathDirectory directory) { var dirs = NSSearchPath.GetDirectories(directory, NSSearchPathDomain.User); if (dirs == null || dirs.Length == 0) diff --git a/src/Essentials/src/FileSystem/FileSystem.netstandard.cs b/src/Essentials/src/FileSystem/FileSystem.netstandard.cs index 0ff60985832d..14510eeaa42f 100644 --- a/src/Essentials/src/FileSystem/FileSystem.netstandard.cs +++ b/src/Essentials/src/FileSystem/FileSystem.netstandard.cs @@ -13,10 +13,10 @@ string PlatformAppDataDirectory => throw ExceptionUtils.NotSupportedOrImplementedException; Task PlatformOpenAppPackageFileAsync(string filename) - => throw ExceptionUtils.NotSupportedOrImplementedException; + => throw ExceptionUtils.NotSupportedOrImplementedException; Task PlatformAppPackageFileExistsAsync(string filename) - => throw ExceptionUtils.NotSupportedOrImplementedException; + => throw ExceptionUtils.NotSupportedOrImplementedException; } /// diff --git a/src/Essentials/src/FileSystem/FileSystem.shared.cs b/src/Essentials/src/FileSystem/FileSystem.shared.cs index d1a25295633c..d47a3f1b03d1 100644 --- a/src/Essentials/src/FileSystem/FileSystem.shared.cs +++ b/src/Essentials/src/FileSystem/FileSystem.shared.cs @@ -1,8 +1,7 @@ +#nullable enable using System; using System.IO; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.Storage; namespace Microsoft.Maui.Storage { @@ -17,68 +16,8 @@ public interface IFileSystem Task AppPackageFileExistsAsync(string filename); } - public interface IPlatformFileSystem - { -#if ANDROID - Java.IO.File GetTemporaryFile(Java.IO.File root, string fileName); - - string EnsurePhysicalPath(Android.Net.Uri uri, bool requireExtendedAccess = true); -#endif -#if IOS || MACCATALYST - Task EnsurePhysicalFileResultsAsync(params Foundation.NSUrl[] urls); -#endif - } -} -namespace Microsoft.Maui.Essentials -{ - /// public static class FileSystem { - /// - public static string CacheDirectory - => Current.CacheDirectory; - - /// - public static string AppDataDirectory - => Current.AppDataDirectory; - - /// - public static Task OpenAppPackageFileAsync(string filename) - => Current.OpenAppPackageFileAsync(filename); - - public static Task AppPackageFileExistsAsync(string filename) - => Current.AppPackageFileExistsAsync(filename); - - -#if ANDROID - internal static Java.IO.File GetTemporaryFile(Java.IO.File root, string fileName) - { - if (Current is IPlatformFileSystem p) - return p.GetTemporaryFile(root, fileName); - - throw ExceptionUtils.NotSupportedOrImplementedException; - } - - internal static string EnsurePhysicalPath(Android.Net.Uri uri, bool requireExtendedAccess = true) - { - if (Current is IPlatformFileSystem p) - return p.EnsurePhysicalPath(uri, requireExtendedAccess); - - throw ExceptionUtils.NotSupportedOrImplementedException; - } -#endif - -#if IOS || MACCATALYST - internal static Task EnsurePhysicalFileResultsAsync(params Foundation.NSUrl[] urls) - { - if (Current is IPlatformFileSystem p) - return p.EnsurePhysicalFileResultsAsync(urls); - - throw ExceptionUtils.NotSupportedOrImplementedException; - } -#endif - -#nullable enable static IFileSystem? currentImplementation; public static IFileSystem Current => @@ -86,11 +25,31 @@ internal static Task EnsurePhysicalFileResultsAsync(params Foundat internal static void SetCurrent(IFileSystem? implementation) => currentImplementation = implementation; -#nullable disable } -} -namespace Microsoft.Maui.Storage -{ + + public partial class FileSystemImplementation + { + public string CacheDirectory + => PlatformCacheDirectory; + + public string AppDataDirectory + => PlatformAppDataDirectory; + + public Task OpenAppPackageFileAsync(string filename) + => PlatformOpenAppPackageFileAsync(filename); + + public Task AppPackageFileExistsAsync(string filename) + => PlatformAppPackageFileExistsAsync(filename); + } + + static partial class FileSystemUtils + { + public static string NormalizePath(string filename) => + filename + .Replace('\\', Path.DirectorySeparatorChar) + .Replace('/', Path.DirectorySeparatorChar); + } + static class FileMimeTypes { internal const string All = "*/*"; @@ -162,7 +121,7 @@ public abstract partial class FileBase { internal const string DefaultContentType = FileMimeTypes.OctetStream; - string contentType; + string? contentType; // The caller must setup FullPath at least!!! internal FileBase() @@ -198,7 +157,7 @@ internal FileBase(string fullPath, string contentType) } /// - public string FullPath { get; internal set; } + public string FullPath { get; internal set; } = null!; /// public string ContentType @@ -225,7 +184,7 @@ internal string GetContentType() return DefaultContentType; } - string fileName; + string? fileName; /// public string FileName @@ -301,22 +260,4 @@ public FileResult(FileBase file) { } } -} - -namespace Microsoft.Maui.Storage -{ - public partial class FileSystemImplementation - { - public string CacheDirectory - => PlatformCacheDirectory; - - public string AppDataDirectory - => PlatformAppDataDirectory; - - public Task OpenAppPackageFileAsync(string filename) - => PlatformOpenAppPackageFileAsync(filename); - - public Task AppPackageFileExistsAsync(string filename) - => PlatformAppPackageFileExistsAsync(filename); - } } \ No newline at end of file diff --git a/src/Essentials/src/FileSystem/FileSystem.uwp.cs b/src/Essentials/src/FileSystem/FileSystem.uwp.cs index 43b6d9303537..76ec2f27acdd 100644 --- a/src/Essentials/src/FileSystem/FileSystem.uwp.cs +++ b/src/Essentials/src/FileSystem/FileSystem.uwp.cs @@ -20,32 +20,35 @@ Task PlatformOpenAppPackageFileAsync(string filename) if (filename == null) throw new ArgumentNullException(nameof(filename)); - if (AppInfo.PackagingModel == AppPackagingModel.Packaged) + if (AppInfoUtils.IsPackagedApp) { - filename = NormalizePath(filename); + filename = FileSystemUtils.NormalizePath(filename); return Package.Current.InstalledLocation.OpenStreamForReadAsync(filename); } else { - var file = PlatformGetFullAppPackageFilePath(filename); + var file = FileSystemUtils.PlatformGetFullAppPackageFilePath(filename); return Task.FromResult((Stream)File.OpenRead(file)); } } Task PlatformAppPackageFileExistsAsync(string filename) { - var file = PlatformGetFullAppPackageFilePath(filename); + var file = FileSystemUtils.PlatformGetFullAppPackageFilePath(filename); return Task.FromResult(File.Exists(file)); } + } - internal static bool AppPackageFileExists(string filename) + static partial class FileSystemUtils + { + public static bool AppPackageFileExists(string filename) { var file = PlatformGetFullAppPackageFilePath(filename); return File.Exists(file); } - static string PlatformGetFullAppPackageFilePath(string filename) + public static string PlatformGetFullAppPackageFilePath(string filename) { if (filename == null) throw new ArgumentNullException(nameof(filename)); @@ -53,16 +56,13 @@ static string PlatformGetFullAppPackageFilePath(string filename) filename = NormalizePath(filename); string root; - if (AppInfo.PackagingModel == AppPackagingModel.Packaged) + if (AppInfoUtils.IsPackagedApp) root = Package.Current.InstalledLocation.Path; else root = AppContext.BaseDirectory; return Path.Combine(root, filename); } - - internal static string NormalizePath(string path) - => path.Replace('/', Path.DirectorySeparatorChar); } public partial class FileBase diff --git a/src/Essentials/src/Flashlight/Flashlight.shared.cs b/src/Essentials/src/Flashlight/Flashlight.shared.cs index 79c15b71ce25..a7c5d542287a 100644 --- a/src/Essentials/src/Flashlight/Flashlight.shared.cs +++ b/src/Essentials/src/Flashlight/Flashlight.shared.cs @@ -1,37 +1,24 @@ #nullable enable -using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Devices; namespace Microsoft.Maui.Devices { public interface IFlashlight { Task TurnOnAsync(); + Task TurnOffAsync(); } -} -namespace Microsoft.Maui.Essentials -{ + /// public static partial class Flashlight { - /// - public static Task TurnOnAsync() => - Current.TurnOnAsync(); - - /// - public static Task TurnOffAsync() => - Current.TurnOffAsync(); - static IFlashlight? currentImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] public static IFlashlight Current => currentImplementation ??= new FlashlightImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IFlashlight? implementation) => + internal static void SetCurrent(IFlashlight? implementation) => currentImplementation = implementation; } } diff --git a/src/Essentials/src/Launcher/Launcher.android.cs b/src/Essentials/src/Launcher/Launcher.android.cs index c397c057dec2..ee7aa2e69e16 100644 --- a/src/Essentials/src/Launcher/Launcher.android.cs +++ b/src/Essentials/src/Launcher/Launcher.android.cs @@ -14,10 +14,10 @@ Task PlatformCanOpenAsync(Uri uri) { var intent = new Intent(Intent.ActionView, AndroidUri.Parse(uri.OriginalString)); - if (Platform.AppContext == null) + if (Application.Context == null) return Task.FromResult(false); - var manager = Platform.AppContext.PackageManager; + var manager = Application.Context.PackageManager; var supportedResolvedInfos = manager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly); return Task.FromResult(supportedResolvedInfos.Any()); } @@ -32,7 +32,7 @@ Task PlatformOpenAsync(Uri uri) #endif intent.SetFlags(flags); - Platform.AppContext.StartActivity(intent); + Application.Context.StartActivity(intent); return Task.FromResult(true); } @@ -52,7 +52,7 @@ Task PlatformOpenAsync(OpenFileRequest request) #endif chooserIntent.SetFlags(flags); - Platform.AppContext.StartActivity(chooserIntent); + Application.Context.StartActivity(chooserIntent); return Task.FromResult(true); } diff --git a/src/Essentials/src/Launcher/Launcher.shared.cs b/src/Essentials/src/Launcher/Launcher.shared.cs index 5dcf61fc11dc..42aceed7f716 100644 --- a/src/Essentials/src/Launcher/Launcher.shared.cs +++ b/src/Essentials/src/Launcher/Launcher.shared.cs @@ -1,7 +1,6 @@ +#nullable enable using System; -using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Graphics; using Microsoft.Maui.Storage; @@ -9,112 +8,28 @@ namespace Microsoft.Maui.ApplicationModel { public interface ILauncher { - Task CanOpenAsync(string uri); - Task CanOpenAsync(Uri uri); - Task OpenAsync(string uri); - Task OpenAsync(Uri uri); Task OpenAsync(OpenFileRequest request); - - Task TryOpenAsync(string uri); Task TryOpenAsync(Uri uri); } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static partial class Launcher { - /// - public static Task CanOpenAsync(string uri) - => Current.CanOpenAsync(uri); - - /// - public static Task CanOpenAsync(Uri uri) - => Current.CanOpenAsync(uri); - - /// - public static Task OpenAsync(string uri) - => Current.OpenAsync(uri); - - /// - public static Task OpenAsync(Uri uri) - => Current.OpenAsync(uri); - - /// - public static Task OpenAsync(OpenFileRequest request) - => Current.OpenAsync(request); - - /// - public static Task TryOpenAsync(string uri) - => Current.TryOpenAsync(uri); - - /// - public static Task TryOpenAsync(Uri uri) - => Current.TryOpenAsync(uri); - -#nullable enable - static ILauncher? currentImplementation; + static ILauncher? defaultImplementation; - public static ILauncher Current => - currentImplementation ??= new LauncherImplementation(); + public static ILauncher Default => + defaultImplementation ??= new LauncherImplementation(); - internal static void SetCurrent(ILauncher? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(ILauncher? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.ApplicationModel -{ - /// - public class OpenFileRequest - { - /// - public OpenFileRequest() - { - } - /// - public OpenFileRequest(string title, ReadOnlyFile file) - { - Title = title; - File = file; - } - - /// - public OpenFileRequest(string title, FileBase file) - { - Title = title; - File = new ReadOnlyFile(file); - } - - /// - public string Title { get; set; } - - /// - public ReadOnlyFile File { get; set; } - - /// - public Rect PresentationSourceBounds { get; set; } = Rect.Zero; - } -} - -namespace Microsoft.Maui.ApplicationModel -{ partial class LauncherImplementation : ILauncher { - public Task CanOpenAsync(string uri) - { - if (string.IsNullOrWhiteSpace(uri)) - throw new ArgumentNullException(nameof(uri)); - - return CanOpenAsync(new Uri(uri)); - } - public Task CanOpenAsync(Uri uri) { if (uri == null) @@ -123,14 +38,6 @@ public Task CanOpenAsync(Uri uri) return PlatformCanOpenAsync(uri); } - public Task OpenAsync(string uri) - { - if (string.IsNullOrWhiteSpace(uri)) - throw new ArgumentNullException(nameof(uri)); - - return OpenAsync(new Uri(uri)); - } - public Task OpenAsync(Uri uri) { if (uri == null) @@ -149,20 +56,56 @@ public Task OpenAsync(OpenFileRequest request) return PlatformOpenAsync(request); } - public Task TryOpenAsync(string uri) + public Task TryOpenAsync(Uri uri) { - if (string.IsNullOrWhiteSpace(uri)) + if (uri == null) throw new ArgumentNullException(nameof(uri)); - return TryOpenAsync(new Uri(uri)); + return PlatformTryOpenAsync(uri); } + } - public Task TryOpenAsync(Uri uri) + public static class LauncherExtensions + { + public static Task CanOpenAsync(this ILauncher launcher, string uri) => + launcher.CanOpenAsync(new Uri(uri)); + + public static Task OpenAsync(this ILauncher launcher, string uri) => + launcher.OpenAsync(new Uri(uri)); + + public static Task TryOpenAsync(this ILauncher launcher, string uri) => + launcher.TryOpenAsync(new Uri(uri)); + } + + /// + public class OpenFileRequest + { + /// + public OpenFileRequest() { - if (uri == null) - throw new ArgumentNullException(nameof(uri)); + } - return PlatformTryOpenAsync(uri); + /// + public OpenFileRequest(string title, ReadOnlyFile file) + { + Title = title; + File = file; } + + /// + public OpenFileRequest(string title, FileBase file) + { + Title = title; + File = new ReadOnlyFile(file); + } + + /// + public string? Title { get; set; } + + /// + public ReadOnlyFile? File { get; set; } + + /// + public Rect PresentationSourceBounds { get; set; } = Rect.Zero; } } \ No newline at end of file diff --git a/src/Essentials/src/Launcher/Launcher.uwp.cs b/src/Essentials/src/Launcher/Launcher.uwp.cs index 18297eb5702d..c4cbfbe05737 100644 --- a/src/Essentials/src/Launcher/Launcher.uwp.cs +++ b/src/Essentials/src/Launcher/Launcher.uwp.cs @@ -1,6 +1,5 @@ using System; using System.Threading.Tasks; -using Windows.ApplicationModel.DataTransfer; using Windows.Storage; using Windows.System; using WinLauncher = Windows.System.Launcher; From f42b4e48ead93d6de887611db6eaf98a270c7c77 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Mon, 21 Mar 2022 12:19:18 +0200 Subject: [PATCH 06/45] more --- .../Core/src/Essentials/Geocoding.cs | 26 +++++++++ src/Essentials/src/Compass/Compass.shared.cs | 13 ++++- .../src/Geocoding/Geocoding.android.cs | 9 ++-- .../Geocoding.ios.tvos.watchos.macos.cs | 6 ++- .../src/Geocoding/Geocoding.netstandard.cs | 1 - .../src/Geocoding/Geocoding.shared.cs | 54 ++++++++++--------- .../src/Geocoding/Geocoding.tizen.cs | 23 +++++--- src/Essentials/src/Geocoding/Geocoding.uwp.cs | 19 ++++--- 8 files changed, 104 insertions(+), 47 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/Geocoding.cs diff --git a/src/Compatibility/Core/src/Essentials/Geocoding.cs b/src/Compatibility/Core/src/Essentials/Geocoding.cs new file mode 100644 index 000000000000..026c5b60db26 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Geocoding.cs @@ -0,0 +1,26 @@ +#nullable enable +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Geocoding + { + /// + public static Task> GetPlacemarksAsync(Location location) => + Current.GetPlacemarksAsync(location); + + /// + public static Task> GetPlacemarksAsync(double latitude, double longitude) => + Current.GetPlacemarksAsync(latitude, longitude); + + /// + public static Task> GetLocationsAsync(string address) => + Current.GetLocationsAsync(address); + + static IGeocoding Current => Devices.Sensors.Geocoding.Default; + } +} diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index 82610d5c7c91..64bf38710529 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -38,6 +38,17 @@ internal static void SetDefault(ICompass? implementation) => defaultImplementation = implementation; } + public static class CompassExtensions + { + public static void SetShouldDisplayHeadingCalibration(this ICompass compass, bool shouldDisplay) + { + if (compass is IPlatformCompass platform) + { + platform.ShouldDisplayHeadingCalibration = shouldDisplay; + } + } + } + /// public class CompassChangedEventArgs : EventArgs { @@ -60,7 +71,7 @@ public CompassData(double headingMagneticNorth) => public double HeadingMagneticNorth { get; } /// - public override bool Equals(object obj) => + public override bool Equals(object? obj) => (obj is CompassData data) && Equals(data); /// diff --git a/src/Essentials/src/Geocoding/Geocoding.android.cs b/src/Essentials/src/Geocoding/Geocoding.android.cs index 69be319c3a46..722078bc9c13 100644 --- a/src/Essentials/src/Geocoding/Geocoding.android.cs +++ b/src/Essentials/src/Geocoding/Geocoding.android.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -10,10 +11,10 @@ class GeocodingImplementation : IGeocoding { public async Task> GetPlacemarksAsync(double latitude, double longitude) { - using (var geocoder = new Geocoder(Platform.AppContext)) + using (var geocoder = new Geocoder(Application.Context)) { var addressList = await geocoder.GetFromLocationAsync(latitude, longitude, 10); - return addressList?.ToPlacemarks(); + return addressList?.ToPlacemarks() ?? Array.Empty(); } } @@ -22,11 +23,11 @@ public async Task> GetLocationsAsync(string address) if (address == null) throw new ArgumentNullException(nameof(address)); - using (var geocoder = new Geocoder(Platform.AppContext)) + using (var geocoder = new Geocoder(Application.Context)) { var addressList = await geocoder.GetFromLocationNameAsync(address, 10); - return addressList?.ToLocations(); + return addressList?.ToLocations() ?? Array.Empty(); } } } diff --git a/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs b/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs index 3f0b4507b856..c677dd47e3dc 100644 --- a/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs @@ -1,3 +1,5 @@ +#nullable enable +using System; using System.Collections.Generic; using System.Threading.Tasks; using CoreLocation; @@ -12,7 +14,7 @@ public async Task> GetPlacemarksAsync(double latitude, do { var addressList = await geocoder.ReverseGeocodeLocationAsync(new CLLocation(latitude, longitude)); - return addressList?.ToPlacemarks(); + return addressList?.ToPlacemarks() ?? Array.Empty(); } } @@ -22,7 +24,7 @@ public async Task> GetLocationsAsync(string address) { var positionList = await geocoder.GeocodeAddressAsync(address); - return positionList?.ToLocations(); + return positionList?.ToLocations() ?? Array.Empty(); } } } diff --git a/src/Essentials/src/Geocoding/Geocoding.netstandard.cs b/src/Essentials/src/Geocoding/Geocoding.netstandard.cs index 12b3f6d0d957..b96510cf65ee 100644 --- a/src/Essentials/src/Geocoding/Geocoding.netstandard.cs +++ b/src/Essentials/src/Geocoding/Geocoding.netstandard.cs @@ -3,7 +3,6 @@ namespace Microsoft.Maui.Devices.Sensors { - /// class GeocodingImplementation : IGeocoding { public Task> GetPlacemarksAsync(double latitude, double longitude) => diff --git a/src/Essentials/src/Geocoding/Geocoding.shared.cs b/src/Essentials/src/Geocoding/Geocoding.shared.cs index ef9bc91519a6..c9f665411094 100644 --- a/src/Essentials/src/Geocoding/Geocoding.shared.cs +++ b/src/Essentials/src/Geocoding/Geocoding.shared.cs @@ -1,46 +1,50 @@ #nullable enable using System; using System.Collections.Generic; -using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Devices.Sensors; namespace Microsoft.Maui.Devices.Sensors { public interface IGeocoding { Task> GetPlacemarksAsync(double latitude, double longitude); + Task> GetLocationsAsync(string address); } -} -namespace Microsoft.Maui.Essentials -{ - /// + + public interface IPlatformGeocoding : IGeocoding + { +#if WINDOWS || TIZEN + string? MapServiceToken { get; set; } +#endif + } + public static class Geocoding { - /// - public static Task> GetPlacemarksAsync(Location location) + static IGeocoding? defaultImplementation; + + public static IGeocoding Default => + defaultImplementation ??= new GeocodingImplementation(); + + internal static void SetCurrent(IGeocoding? implementation) => + defaultImplementation = implementation; + } + + public static class GeocodingExtensions + { + public static Task> GetPlacemarksAsync(this IGeocoding geocoding, Location location) { if (location == null) throw new ArgumentNullException(nameof(location)); - return GetPlacemarksAsync(location.Latitude, location.Longitude); + return geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude); + } + public static void SetMapServiceToken(this IGeocoding geocoding, string? mapServiceToken) + { + if (geocoding is IPlatformGeocoding platform) + { + platform.MapServiceToken = mapServiceToken; + } } - - /// - public static Task> GetPlacemarksAsync(double latitude, double longitude) - => Current.GetPlacemarksAsync(latitude, longitude); - - /// - public static Task> GetLocationsAsync(string address) - => Current.GetLocationsAsync(address); - - static IGeocoding? currentImplementation; - - public static IGeocoding Current => - currentImplementation ??= new GeocodingImplementation(); - - internal static void SetCurrent(IGeocoding? implementation) => - currentImplementation = implementation; } } diff --git a/src/Essentials/src/Geocoding/Geocoding.tizen.cs b/src/Essentials/src/Geocoding/Geocoding.tizen.cs index 5ff5985b07e8..6f146c7111e8 100644 --- a/src/Essentials/src/Geocoding/Geocoding.tizen.cs +++ b/src/Essentials/src/Geocoding/Geocoding.tizen.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -6,12 +7,15 @@ namespace Microsoft.Maui.Devices.Sensors { class GeocodingImplementation : IGeocoding { + public string? MapServiceToken { get; set; } + public async Task> GetPlacemarksAsync(double latitude, double longitude) { + ValidateMapServiceToken(); + Permissions.EnsureDeclared(); - if (string.IsNullOrWhiteSpace(Platform.MapServiceToken)) - throw new ArgumentNullException(nameof(Platform.MapServiceToken)); - var map = await Platform.GetMapServiceAsync(Platform.MapServiceToken); + + var map = await Platform.GetMapServiceAsync(MapServiceToken); var request = map.CreateReverseGeocodeRequest(latitude, longitude); var list = new List(); @@ -37,15 +41,22 @@ public async Task> GetPlacemarksAsync(double latitude, do public async Task> GetLocationsAsync(string address) { + ValidateMapServiceToken(); + Permissions.EnsureDeclared(); - if (string.IsNullOrWhiteSpace(Platform.MapServiceToken)) - throw new ArgumentNullException(nameof(Platform.MapServiceToken)); - var map = await Platform.GetMapServiceAsync(Platform.MapServiceToken); + + var map = await Platform.GetMapServiceAsync(MapServiceToken); var request = map.CreateGeocodeRequest(address); var list = new List(); foreach (var position in await request.GetResponseAsync()) list.Add(new Location(position.Latitude, position.Longitude)); return list; } + + void ValidateMapServiceToken() + { + if (string.IsNullOrWhiteSpace(MapServiceToken) && string.IsNullOrWhiteSpace(MapService.ServiceToken)) + throw new ArgumentNullException(nameof(MapServiceToken), "Please set the map service token to be able to use this API."); + } } } diff --git a/src/Essentials/src/Geocoding/Geocoding.uwp.cs b/src/Essentials/src/Geocoding/Geocoding.uwp.cs index 59116a08d528..74bfd0b2b32f 100644 --- a/src/Essentials/src/Geocoding/Geocoding.uwp.cs +++ b/src/Essentials/src/Geocoding/Geocoding.uwp.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -6,8 +7,10 @@ namespace Microsoft.Maui.Devices.Sensors { - class GeocodingImplementation: IGeocoding + class GeocodingImplementation : IPlatformGeocoding, IGeocoding { + public string? MapServiceToken { get; set; } + public async Task> GetPlacemarksAsync(double latitude, double longitude) { ValidateMapServiceToken(); @@ -16,7 +19,7 @@ public async Task> GetPlacemarksAsync(double latitude, do var queryResults = await MapLocationFinder.FindLocationsAtAsync(point).AsTask(); - return queryResults?.Locations?.ToPlacemarks(); + return queryResults?.Locations?.ToPlacemarks() ?? Array.Empty(); } public async Task> GetLocationsAsync(string address) @@ -25,16 +28,16 @@ public async Task> GetLocationsAsync(string address) var queryResults = await MapLocationFinder.FindLocationsAsync(address, null, 10); - return queryResults?.Locations?.ToLocations(); + return queryResults?.Locations?.ToLocations() ?? Array.Empty(); } - internal static void ValidateMapServiceToken() + void ValidateMapServiceToken() { - if (string.IsNullOrWhiteSpace(Platform.MapServiceToken) && string.IsNullOrWhiteSpace(MapService.ServiceToken)) - throw new ArgumentNullException(nameof(Platform.MapServiceToken), "Please set the map service token(MapService.ServiceToken) to be able to use this API."); + if (string.IsNullOrWhiteSpace(MapServiceToken) && string.IsNullOrWhiteSpace(MapService.ServiceToken)) + throw new ArgumentNullException(nameof(MapServiceToken), "Please set the map service token to be able to use this API."); - if (!string.IsNullOrWhiteSpace(Platform.MapServiceToken)) - MapService.ServiceToken = Platform.MapServiceToken; + if (!string.IsNullOrWhiteSpace(MapServiceToken)) + MapService.ServiceToken = MapServiceToken; } } } From 095c31b29e515771476ad541922c2b396fa4e971 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 22 Mar 2022 17:46:30 +0200 Subject: [PATCH 07/45] more --- .../Core/src/Essentials/Geolocation.cs | 29 ++++++++ .../Core/src/Essentials/Gyroscope.cs | 33 +++++++++ .../Core/src/Essentials/HapticFeedback.cs | 15 ++++ .../Core/src/Essentials/Magnetometer.cs | 33 +++++++++ src/Compatibility/Core/src/Essentials/Map.cs | 59 ++++++++++++++++ .../Accelerometer.ios.watchos.cs | 15 ++-- .../src/Barometer/Barometer.shared.cs | 4 +- src/Essentials/src/Compass/Compass.shared.cs | 4 +- .../src/Geocoding/Geocoding.shared.cs | 3 + .../src/Geocoding/Geocoding.tizen.cs | 2 +- .../src/Geolocation/Geolocation.android.cs | 5 +- .../src/Geolocation/Geolocation.ios.macos.cs | 3 +- .../Geolocation.netstandard.tvos.watchos.cs | 2 - .../src/Geolocation/Geolocation.shared.cs | 66 ++++------------- .../src/Geolocation/Geolocation.tizen.cs | 2 + .../src/Geolocation/Geolocation.uwp.cs | 9 ++- .../src/Gyroscope/Gyroscope.android.cs | 34 +++++---- .../src/Gyroscope/Gyroscope.ios.watchos.cs | 15 ++-- .../Gyroscope.netstandard.tvos.macos.cs | 1 - .../src/Gyroscope/Gyroscope.shared.cs | 61 +++------------- .../src/Gyroscope/Gyroscope.tizen.cs | 4 +- src/Essentials/src/Gyroscope/Gyroscope.uwp.cs | 2 +- .../src/HapticFeedback/HapticFeedback.ios.cs | 5 +- .../HapticFeedback/HapticFeedback.shared.cs | 31 +++----- .../src/Magnetometer/Magnetometer.android.cs | 24 +++++-- .../Magnetometer/Magnetometer.ios.watchos.cs | 15 ++-- .../src/Magnetometer/Magnetometer.shared.cs | 58 +++------------ src/Essentials/src/Map/Map.android.cs | 16 ++++- .../src/Map/Map.ios.watchos.macos.cs | 13 +++- .../src/Map/Map.netstandard.tvos.cs | 4 +- src/Essentials/src/Map/Map.shared.cs | 70 ++++++------------- src/Essentials/src/Map/Map.tizen.cs | 13 +++- src/Essentials/src/Map/Map.uwp.cs | 15 +++- .../OrientationSensor.shared.cs | 7 +- .../src/Platform/Platform.ios.tvos.watchos.cs | 10 --- 35 files changed, 377 insertions(+), 305 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/Geolocation.cs create mode 100644 src/Compatibility/Core/src/Essentials/Gyroscope.cs create mode 100644 src/Compatibility/Core/src/Essentials/HapticFeedback.cs create mode 100644 src/Compatibility/Core/src/Essentials/Magnetometer.cs create mode 100644 src/Compatibility/Core/src/Essentials/Map.cs diff --git a/src/Compatibility/Core/src/Essentials/Geolocation.cs b/src/Compatibility/Core/src/Essentials/Geolocation.cs new file mode 100644 index 000000000000..c3b6907988fe --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Geolocation.cs @@ -0,0 +1,29 @@ +#nullable enable +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Geolocation + { + /// + public static Task GetLastKnownLocationAsync() => + Current.GetLastKnownLocationAsync(); + + /// + public static Task GetLocationAsync() => + Current.GetLocationAsync(); + + /// + public static Task GetLocationAsync(GeolocationRequest request) => + Current.GetLocationAsync(request); + + /// + public static Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken) => + Current.GetLocationAsync(request, cancelToken); + + static IGeolocation Current => Devices.Sensors.Geolocation.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Gyroscope.cs b/src/Compatibility/Core/src/Essentials/Gyroscope.cs new file mode 100644 index 000000000000..be7fa44a2450 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Gyroscope.cs @@ -0,0 +1,33 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Gyroscope + { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + /// + public static bool IsMonitoring + => Current.IsMonitoring; + + public static bool IsSupported + => Current.IsSupported; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Current.Start(sensorSpeed); + + /// + public static void Stop() + => Current.Stop(); + + static IGyroscope Current => Devices.Sensors.Gyroscope.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/HapticFeedback.cs b/src/Compatibility/Core/src/Essentials/HapticFeedback.cs new file mode 100644 index 000000000000..a6e54d554d38 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/HapticFeedback.cs @@ -0,0 +1,15 @@ +#nullable enable +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class HapticFeedback + { + /// + public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click) => + Current.Perform(type); + + public static IHapticFeedback Current => Devices.HapticFeedback.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Magnetometer.cs b/src/Compatibility/Core/src/Essentials/Magnetometer.cs new file mode 100644 index 000000000000..bb88d06cb023 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Magnetometer.cs @@ -0,0 +1,33 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Magnetometer + { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + /// + public static bool IsMonitoring + => Current.IsMonitoring; + + public static bool IsSupported + => Current.IsSupported; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Current.Start(sensorSpeed); + + /// + public static void Stop() + => Current.Stop(); + + static IMagnetometer Current => Devices.Sensors.Magnetometer.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Map.cs b/src/Compatibility/Core/src/Essentials/Map.cs new file mode 100644 index 000000000000..04ac16a49736 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Map.cs @@ -0,0 +1,59 @@ +#nullable enable +using System; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Map + { + /// + public static Task OpenAsync(Location location) => + OpenAsync(location, new MapLaunchOptions()); + + /// + public static Task OpenAsync(Location location, MapLaunchOptions options) + { + if (location == null) + throw new ArgumentNullException(nameof(location)); + + if (options == null) + throw new ArgumentNullException(nameof(options)); + + return Current.OpenAsync(location.Latitude, location.Longitude, options); + } + + /// + public static Task OpenAsync(double latitude, double longitude) => + OpenAsync(latitude, longitude, new MapLaunchOptions()); + + /// + public static Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + return Current.OpenAsync(latitude, longitude, options); + } + + /// + public static Task OpenAsync(Placemark placemark) => + OpenAsync(placemark, new MapLaunchOptions()); + + /// + public static Task OpenAsync(Placemark placemark, MapLaunchOptions options) + { + if (placemark == null) + throw new ArgumentNullException(nameof(placemark)); + + if (options == null) + throw new ArgumentNullException(nameof(options)); + + return Current.OpenAsync(placemark, options); + } + + static IMap Current => ApplicationModel.Map.Default; + } +} diff --git a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs index db22a804a44f..530f2078e5bc 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs @@ -1,3 +1,4 @@ +#nullable enable using CoreMotion; using Foundation; @@ -5,14 +6,18 @@ namespace Microsoft.Maui.Devices.Sensors { partial class AccelerometerImplementation { + static CMMotionManager? motionManager; + + static CMMotionManager MotionManager => + motionManager ??= new CMMotionManager(); + public bool IsSupported => - Platform.MotionManager?.AccelerometerAvailable ?? false; + MotionManager.AccelerometerAvailable; void PlatformStart(SensorSpeed sensorSpeed) { - var manager = Platform.MotionManager; - manager.AccelerometerUpdateInterval = sensorSpeed.ToPlatform(); - manager.StartAccelerometerUpdates(Platform.GetCurrentQueue(), DataUpdated); + MotionManager.AccelerometerUpdateInterval = sensorSpeed.ToPlatform(); + MotionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, DataUpdated); } void DataUpdated(CMAccelerometerData data, NSError error) @@ -26,6 +31,6 @@ void DataUpdated(CMAccelerometerData data, NSError error) } void PlatformStop() => - Platform.MotionManager?.StopAccelerometerUpdates(); + MotionManager.StopAccelerometerUpdates(); } } diff --git a/src/Essentials/src/Barometer/Barometer.shared.cs b/src/Essentials/src/Barometer/Barometer.shared.cs index 5435709bc684..dce9350f2c7c 100644 --- a/src/Essentials/src/Barometer/Barometer.shared.cs +++ b/src/Essentials/src/Barometer/Barometer.shared.cs @@ -12,8 +12,6 @@ public interface IBarometer bool IsMonitoring { get; } - SensorSpeed SensorSpeed { get; } - void Start(SensorSpeed sensorSpeed); event EventHandler? ReadingChanged; @@ -85,7 +83,7 @@ partial class BarometerImplementation : IBarometer public bool IsMonitoring { get; private set; } - public SensorSpeed SensorSpeed { get; private set; } = SensorSpeed.Default; + SensorSpeed SensorSpeed { get; set; } = SensorSpeed.Default; void RaiseReadingChanged(BarometerData reading) { diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index 64bf38710529..ba751658031e 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -9,8 +9,6 @@ public interface ICompass bool IsMonitoring { get; } - SensorSpeed SensorSpeed { get; } - void Start(SensorSpeed sensorSpeed); void Start(SensorSpeed sensorSpeed, bool applyLowPassFilter); @@ -104,7 +102,7 @@ public bool IsSupported public bool IsMonitoring { get; private set; } - public SensorSpeed SensorSpeed { get; private set; } + SensorSpeed SensorSpeed { get; set; } public void Start(SensorSpeed sensorSpeed) => Start(sensorSpeed, true); diff --git a/src/Essentials/src/Geocoding/Geocoding.shared.cs b/src/Essentials/src/Geocoding/Geocoding.shared.cs index c9f665411094..2946851ce3e2 100644 --- a/src/Essentials/src/Geocoding/Geocoding.shared.cs +++ b/src/Essentials/src/Geocoding/Geocoding.shared.cs @@ -39,12 +39,15 @@ public static Task> GetPlacemarksAsync(this IGeocoding ge return geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude); } + public static void SetMapServiceToken(this IGeocoding geocoding, string? mapServiceToken) { +#if WINDOWS || TIZEN if (geocoding is IPlatformGeocoding platform) { platform.MapServiceToken = mapServiceToken; } +#endif } } } diff --git a/src/Essentials/src/Geocoding/Geocoding.tizen.cs b/src/Essentials/src/Geocoding/Geocoding.tizen.cs index 6f146c7111e8..9e094975e0b4 100644 --- a/src/Essentials/src/Geocoding/Geocoding.tizen.cs +++ b/src/Essentials/src/Geocoding/Geocoding.tizen.cs @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Devices.Sensors { - class GeocodingImplementation : IGeocoding + class GeocodingImplementation : IPlatformGeocoding, IGeocoding { public string? MapServiceToken { get; set; } diff --git a/src/Essentials/src/Geolocation/Geolocation.android.cs b/src/Essentials/src/Geolocation/Geolocation.android.cs index 227ecb168705..0edd3869596d 100644 --- a/src/Essentials/src/Geolocation/Geolocation.android.cs +++ b/src/Essentials/src/Geolocation/Geolocation.android.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using Android.Locations; using Android.OS; -using Android.Runtime; using Microsoft.Maui.ApplicationModel; using AndroidLocation = Android.Locations.Location; using LocationPower = Android.Locations.Power; @@ -37,6 +36,8 @@ public async Task GetLastKnownLocationAsync() public async Task GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) { + _ = request ?? throw new ArgumentNullException(nameof(request)); + await Permissions.EnsureGrantedAsync(); var locationManager = Platform.LocationManager; @@ -257,7 +258,7 @@ void ILocationListener.OnProviderEnabled(string provider) activeProviders.Add(provider); } - void ILocationListener.OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras) + void ILocationListener.OnStatusChanged(string provider, Availability status, Bundle extras) { switch (status) { diff --git a/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs b/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs index bbc66e4f4880..64188fe6e347 100644 --- a/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs +++ b/src/Essentials/src/Geolocation/Geolocation.ios.macos.cs @@ -3,7 +3,6 @@ using System.Threading; using System.Threading.Tasks; using CoreLocation; -using Foundation; using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors @@ -25,6 +24,8 @@ public async Task GetLastKnownLocationAsync() public async Task GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) { + _ = request ?? throw new ArgumentNullException(nameof(request)); + if (!CLLocationManager.LocationServicesEnabled) throw new FeatureNotEnabledException("Location services are not enabled on device."); diff --git a/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs b/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs index b31968e6058a..84a3bee4efbd 100644 --- a/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs @@ -1,10 +1,8 @@ -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace Microsoft.Maui.Devices.Sensors { - /// partial class GeolocationImplementation : IGeolocation { public Task GetLastKnownLocationAsync() => diff --git a/src/Essentials/src/Geolocation/Geolocation.shared.cs b/src/Essentials/src/Geolocation/Geolocation.shared.cs index f409decda845..5b42f8ad4603 100644 --- a/src/Essentials/src/Geolocation/Geolocation.shared.cs +++ b/src/Essentials/src/Geolocation/Geolocation.shared.cs @@ -1,69 +1,33 @@ -using System; -using System.Collections.Generic; +#nullable enable using System.Threading; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.Devices.Sensors; - namespace Microsoft.Maui.Devices.Sensors { public interface IGeolocation { - Task GetLastKnownLocationAsync(); - - Task GetLocationAsync(); - - Task GetLocationAsync(GeolocationRequest request); + Task GetLastKnownLocationAsync(); - Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken); + Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken); } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Geolocation - { - /// - public static Task GetLastKnownLocationAsync() => - Current.GetLastKnownLocationAsync(); - - /// - public static Task GetLocationAsync() => - Current.GetLocationAsync(new GeolocationRequest(), default); - /// - public static Task GetLocationAsync(GeolocationRequest request) => - Current.GetLocationAsync(request ?? new GeolocationRequest(), default); - - /// - public static Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken) => - Current.GetLocationAsync(request ?? new GeolocationRequest(), cancelToken); - -#nullable enable - static IGeolocation? currentImplementation; -#nullable disable + public static class Geolocation + { + static IGeolocation? defaultImplementation; - [EditorBrowsable(EditorBrowsableState.Never)] - public static IGeolocation Current => - currentImplementation ??= new GeolocationImplementation(); + public static IGeolocation Default => + defaultImplementation ??= new GeolocationImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] -#nullable enable - public static void SetCurrent(IGeolocation? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IGeolocation? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.Devices.Sensors -{ - partial class GeolocationImplementation : IGeolocation + public static class GeolocationExtensions { - public Task GetLocationAsync() - => GetLocationAsync(new GeolocationRequest(), default); + public static Task GetLocationAsync(this IGeolocation geolocation) => + geolocation.GetLocationAsync(new GeolocationRequest(), default); - public Task GetLocationAsync(GeolocationRequest request) - => GetLocationAsync(request ?? new GeolocationRequest(), default); + public static Task GetLocationAsync(this IGeolocation geolocation, GeolocationRequest request) => + geolocation.GetLocationAsync(request ?? new GeolocationRequest(), default); } } \ No newline at end of file diff --git a/src/Essentials/src/Geolocation/Geolocation.tizen.cs b/src/Essentials/src/Geolocation/Geolocation.tizen.cs index d0574227be5b..95fa65fd41a0 100644 --- a/src/Essentials/src/Geolocation/Geolocation.tizen.cs +++ b/src/Essentials/src/Geolocation/Geolocation.tizen.cs @@ -12,6 +12,8 @@ partial class GeolocationImplementation : IGeolocation public async Task GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) { + _ = request ?? throw new ArgumentNullException(nameof(request)); + await Permissions.EnsureGrantedAsync(); Locator service = null; diff --git a/src/Essentials/src/Geolocation/Geolocation.uwp.cs b/src/Essentials/src/Geolocation/Geolocation.uwp.cs index d464f98db59c..ce9778380055 100644 --- a/src/Essentials/src/Geolocation/Geolocation.uwp.cs +++ b/src/Essentials/src/Geolocation/Geolocation.uwp.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Threading; using System.Threading.Tasks; @@ -8,7 +9,7 @@ namespace Microsoft.Maui.Devices.Sensors { partial class GeolocationImplementation : IGeolocation { - public async Task GetLastKnownLocationAsync() + public async Task GetLastKnownLocationAsync() { // no need for permissions as AllowFallbackToConsentlessPositions // will allow the device to return a location regardless @@ -24,8 +25,10 @@ public async Task GetLastKnownLocationAsync() return location?.Coordinate?.ToLocation(); } - public async Task GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) + public async Task GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) { + _ = request ?? throw new ArgumentNullException(nameof(request)); + await Permissions.EnsureGrantedAsync(); var geolocator = new Geolocator @@ -41,7 +44,7 @@ public async Task GetLocationAsync(GeolocationRequest request, Cancell return location?.Coordinate?.ToLocation(); - void CheckStatus(PositionStatus status) + static void CheckStatus(PositionStatus status) { switch (status) { diff --git a/src/Essentials/src/Gyroscope/Gyroscope.android.cs b/src/Essentials/src/Gyroscope/Gyroscope.android.cs index f1dbc94c99af..2ef22215b5a0 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.android.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.android.cs @@ -1,32 +1,41 @@ +#nullable enable using System; +using Android.App; +using Android.Content; using Android.Hardware; -using Android.Runtime; namespace Microsoft.Maui.Devices.Sensors { partial class GyroscopeImplementation : IGyroscope { + static SensorManager? _sensorManager; + static Sensor? gyroscope; + + static SensorManager? SensorManager => + _sensorManager ??= Application.Context.GetSystemService(Context.SensorService) as SensorManager; + + static Sensor? Sensor => + gyroscope ??= SensorManager?.GetDefaultSensor(SensorType.Gyroscope); + bool PlatformIsSupported => - Platform.SensorManager?.GetDefaultSensor(SensorType.Gyroscope) != null; + Sensor is not null; - GyroscopeListener listener; - Sensor gyroscope; + GyroscopeListener? listener; void PlatformStart(SensorSpeed sensorSpeed) { var delay = sensorSpeed.ToPlatform(); listener = new GyroscopeListener(RaiseReadingChanged); - gyroscope = Platform.SensorManager.GetDefaultSensor(SensorType.Gyroscope); - Platform.SensorManager.RegisterListener(listener, gyroscope, delay); + SensorManager!.RegisterListener(listener, Sensor, delay); } void PlatformStop() { - if (listener == null || gyroscope == null) + if (listener == null || Sensor == null) return; - Platform.SensorManager.UnregisterListener(listener, gyroscope); + SensorManager!.UnregisterListener(listener, Sensor); listener.Dispose(); listener = null; } @@ -41,16 +50,17 @@ internal GyroscopeListener(Action callback) readonly Action Callback; - void ISensorEventListener.OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy) + void ISensorEventListener.OnAccuracyChanged(Sensor? sensor, SensorStatus accuracy) { } - void ISensorEventListener.OnSensorChanged(SensorEvent e) + void ISensorEventListener.OnSensorChanged(SensorEvent? e) { - if ((e?.Values?.Count ?? 0) < 3) + var values = e?.Values ?? Array.Empty(); + if (values.Count < 3) return; - var data = new GyroscopeData(e.Values[0], e.Values[1], e.Values[2]); + var data = new GyroscopeData(values[0], values[1], values[2]); Callback?.Invoke(data); } } diff --git a/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs b/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs index 63cf3a114fe4..dbd080380d82 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.ios.watchos.cs @@ -1,3 +1,4 @@ +#nullable enable using CoreMotion; using Foundation; @@ -5,14 +6,18 @@ namespace Microsoft.Maui.Devices.Sensors { partial class GyroscopeImplementation : IGyroscope { + static CMMotionManager? motionManager; + + static CMMotionManager MotionManager => + motionManager ??= new CMMotionManager(); + bool PlatformIsSupported => - Platform.MotionManager?.GyroAvailable ?? false; + MotionManager.GyroAvailable; void PlatformStart(SensorSpeed sensorSpeed) { - var manager = Platform.MotionManager; - manager.GyroUpdateInterval = sensorSpeed.ToPlatform(); - manager.StartGyroUpdates(Platform.GetCurrentQueue(), DataUpdated); + MotionManager.GyroUpdateInterval = sensorSpeed.ToPlatform(); + MotionManager.StartGyroUpdates(NSOperationQueue.CurrentQueue, DataUpdated); } void DataUpdated(CMGyroData data, NSError error) @@ -26,6 +31,6 @@ void DataUpdated(CMGyroData data, NSError error) } void PlatformStop() => - Platform.MotionManager?.StopGyroUpdates(); + MotionManager.StopGyroUpdates(); } } diff --git a/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs b/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs index 851dadfb80cf..4f59354e6909 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs @@ -1,6 +1,5 @@ namespace Microsoft.Maui.Devices.Sensors { - /// partial class GyroscopeImplementation : IGyroscope { bool PlatformIsSupported => diff --git a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs index fb5edda464d3..00d5d11672c4 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs @@ -1,8 +1,6 @@ +#nullable enable using System; using System.Numerics; -using System.ComponentModel; -using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors { @@ -12,57 +10,24 @@ public interface IGyroscope bool IsMonitoring { get; } - SensorSpeed SensorSpeed { get; } - void Start(SensorSpeed sensorSpeed); void Stop(); event EventHandler ReadingChanged; } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Gyroscope - { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - /// - public static bool IsMonitoring - => Current.IsMonitoring; - - public static bool IsSupported - => Current.IsSupported; - - public static SensorSpeed SensorSpeed - => Current.SensorSpeed; - - /// - public static void Start(SensorSpeed sensorSpeed) - => Current.Start(sensorSpeed); - /// - public static void Stop() - => Current.Stop(); - -#nullable enable - static IGyroscope? currentImplementation; + public static class Gyroscope + { + static IGyroscope? defaultImplementation; - public static IGyroscope Current => - currentImplementation ??= new GyroscopeImplementation(); + public static IGyroscope Default => + defaultImplementation ??= new GyroscopeImplementation(); - internal static void SetCurrent(IGyroscope? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IGyroscope? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.Devices.Sensors -{ + /// public class GyroscopeChangedEventArgs : EventArgs { @@ -114,17 +79,14 @@ public override string ToString() => $"{nameof(AngularVelocity.Y)}: {AngularVelocity.Y}, " + $"{nameof(AngularVelocity.Z)}: {AngularVelocity.Z}"; } -} -namespace Microsoft.Maui.Devices.Sensors -{ partial class GyroscopeImplementation : IGyroscope { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; - public SensorSpeed SensorSpeed { get; private set; } = SensorSpeed.Default; + SensorSpeed SensorSpeed { get; set; } = SensorSpeed.Default; - public event EventHandler ReadingChanged; + public event EventHandler? ReadingChanged; public bool IsMonitoring { get; private set; } @@ -151,7 +113,6 @@ public void Start(SensorSpeed sensorSpeed) } } - /// public void Stop() { if (!PlatformIsSupported) diff --git a/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs b/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs index 4c70da914290..e75660860c49 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.tizen.cs @@ -13,7 +13,7 @@ class GyroscopeImplementation : IGyroscope TizenGyroscope sensor; - public void PlatformStart(SensorSpeed sensorSpeed) + void PlatformStart(SensorSpeed sensorSpeed) { sensor = DefaultSensor; sensor.Interval = sensorSpeed.ToPlatform(); @@ -21,7 +21,7 @@ public void PlatformStart(SensorSpeed sensorSpeed) sensor.Start(); } - public void PlatformStop() + void PlatformStop() { sensor.DataUpdated -= DataUpdated; sensor.Stop(); diff --git a/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs b/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs index a226b8114046..9958640395c7 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.uwp.cs @@ -14,7 +14,7 @@ partial class GyroscopeImplementation : IGyroscope bool PlatformIsSupported => DefaultSensor != null; - public void PlatformStart(SensorSpeed sensorSpeed) + void PlatformStart(SensorSpeed sensorSpeed) { sensor = DefaultSensor; diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs index b37dad29c746..f453f11540c2 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.ios.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading.Tasks; -using ObjCRuntime; using UIKit; namespace Microsoft.Maui.Devices @@ -30,7 +27,7 @@ void Click() impact.Dispose(); } - public void LongPress() + void LongPress() { var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium); impact.Prepare(); diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs index dd89d6da3d45..724e39603966 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs @@ -1,37 +1,22 @@ -using System; -using System.ComponentModel; -using Microsoft.Maui.Devices; +#nullable enable namespace Microsoft.Maui.Devices { public interface IHapticFeedback { bool IsSupported { get; } - + void Perform(HapticFeedbackType type); } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static partial class HapticFeedback { - /// - public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click) - { - if (!Current.IsSupported) - throw new FeatureNotSupportedException(); - Current.Perform(type); - } - -#nullable enable - static IHapticFeedback? currentImplementation; + static IHapticFeedback? defaultImplementation; - public static IHapticFeedback Current => - currentImplementation ??= new HapticFeedbackImplementation(); + public static IHapticFeedback Default => + defaultImplementation ??= new HapticFeedbackImplementation(); - internal static void SetCurrent(IHapticFeedback? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IHapticFeedback? implementation) => + defaultImplementation = implementation; } } diff --git a/src/Essentials/src/Magnetometer/Magnetometer.android.cs b/src/Essentials/src/Magnetometer/Magnetometer.android.cs index 8b230c587f29..1c013221d05b 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.android.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.android.cs @@ -1,4 +1,7 @@ +#nullable enable using System; +using Android.App; +using Android.Content; using Android.Hardware; using Android.Runtime; @@ -6,27 +9,34 @@ namespace Microsoft.Maui.Devices.Sensors { partial class MagnetometerImplementation : IMagnetometer { + static SensorManager? _sensorManager; + static Sensor? magnetometer; + + static SensorManager? SensorManager => + _sensorManager ??= Application.Context.GetSystemService(Context.SensorService) as SensorManager; + + static Sensor? Sensor => + magnetometer ??= SensorManager?.GetDefaultSensor(SensorType.MagneticField); + bool PlatformIsSupported => - Platform.SensorManager?.GetDefaultSensor(SensorType.MagneticField) != null; + Sensor is not null; - MagnetometerListener listener; - Sensor magnetometer; + MagnetometerListener? listener; void PlatformStart(SensorSpeed sensorSpeed) { var delay = sensorSpeed.ToPlatform(); listener = new MagnetometerListener(RaiseReadingChanged); - magnetometer = Platform.SensorManager.GetDefaultSensor(SensorType.MagneticField); - Platform.SensorManager.RegisterListener(listener, magnetometer, delay); + SensorManager!.RegisterListener(listener, Sensor, delay); } void PlatformStop() { - if (listener == null || magnetometer == null) + if (listener == null || Sensor == null) return; - Platform.SensorManager.UnregisterListener(listener, magnetometer); + SensorManager!.UnregisterListener(listener, Sensor); listener.Dispose(); listener = null; } diff --git a/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs b/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs index d0bab8dc7ed5..e636b8483a08 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.ios.watchos.cs @@ -1,3 +1,4 @@ +#nullable enable using CoreMotion; using Foundation; @@ -5,14 +6,18 @@ namespace Microsoft.Maui.Devices.Sensors { partial class MagnetometerImplementation : IMagnetometer { + static CMMotionManager? motionManager; + + static CMMotionManager MotionManager => + motionManager ??= new CMMotionManager(); + bool PlatformIsSupported => - Platform.MotionManager?.MagnetometerAvailable ?? false; + MotionManager.MagnetometerAvailable; void PlatformStart(SensorSpeed sensorSpeed) { - var manager = Platform.MotionManager; - manager.MagnetometerUpdateInterval = sensorSpeed.ToPlatform(); - manager.StartMagnetometerUpdates(Platform.GetCurrentQueue(), DataUpdated); + MotionManager.MagnetometerUpdateInterval = sensorSpeed.ToPlatform(); + MotionManager.StartMagnetometerUpdates(NSOperationQueue.CurrentQueue, DataUpdated); } void DataUpdated(CMMagnetometerData data, NSError error) @@ -26,6 +31,6 @@ void DataUpdated(CMMagnetometerData data, NSError error) } void PlatformStop() => - Platform.MotionManager?.StopMagnetometerUpdates(); + MotionManager.StopMagnetometerUpdates(); } } diff --git a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs index 080f12dc5ee1..4921748f45f0 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs @@ -1,8 +1,6 @@ +#nullable enable using System; using System.Numerics; -using System.ComponentModel; -using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors { @@ -12,57 +10,24 @@ public interface IMagnetometer bool IsMonitoring { get; } - SensorSpeed SensorSpeed { get; } - void Start(SensorSpeed sensorSpeed); void Stop(); event EventHandler ReadingChanged; } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static partial class Magnetometer { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - /// - public static bool IsMonitoring - => Current.IsMonitoring; - - public static bool IsSupported - => Current.IsSupported; - - public static SensorSpeed SensorSpeed - => Current.SensorSpeed; - - /// - public static void Start(SensorSpeed sensorSpeed) - => Current.Start(sensorSpeed); + static IMagnetometer? defaultImplementation; - /// - public static void Stop() - => Current.Stop(); + public static IMagnetometer Default => + defaultImplementation ??= new MagnetometerImplementation(); -#nullable enable - static IMagnetometer? currentImplementation; - - public static IMagnetometer Current => - currentImplementation ??= new MagnetometerImplementation(); - - internal static void SetCurrent(IMagnetometer? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IMagnetometer? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.Devices.Sensors -{ + /// public class MagnetometerChangedEventArgs : EventArgs { @@ -114,21 +79,18 @@ public override string ToString() => $"{nameof(MagneticField.Y)}: {MagneticField.Y}, " + $"{nameof(MagneticField.Z)}: {MagneticField.Z}"; } -} -namespace Microsoft.Maui.Devices.Sensors -{ partial class MagnetometerImplementation : IMagnetometer { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; - public event EventHandler ReadingChanged; + public event EventHandler? ReadingChanged; public bool IsMonitoring { get; private set; } public bool IsSupported => PlatformIsSupported; - public SensorSpeed SensorSpeed { get; private set; } = SensorSpeed.Default; + SensorSpeed SensorSpeed { get; set; } = SensorSpeed.Default; public void Start(SensorSpeed sensorSpeed) { diff --git a/src/Essentials/src/Map/Map.android.cs b/src/Essentials/src/Map/Map.android.cs index 001addd02a58..86fc2c4552ca 100644 --- a/src/Essentials/src/Map/Map.android.cs +++ b/src/Essentials/src/Map/Map.android.cs @@ -1,3 +1,4 @@ +using System; using System.Globalization; using System.Threading.Tasks; using Android.Content; @@ -8,8 +9,11 @@ namespace Microsoft.Maui.ApplicationModel { class MapImplementation : IMap { - public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) + public Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) { + if (options == null) + throw new ArgumentNullException(nameof(options)); + var uri = string.Empty; var lat = latitude.ToString(CultureInfo.InvariantCulture); var lng = longitude.ToString(CultureInfo.InvariantCulture); @@ -30,7 +34,7 @@ public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions op return Task.CompletedTask; } - internal static string GetMode(NavigationMode mode) + static string GetMode(NavigationMode mode) { switch (mode) { @@ -44,8 +48,14 @@ internal static string GetMode(NavigationMode mode) return string.Empty; } - public Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options) + public Task OpenAsync(Placemark placemark, MapLaunchOptions options) { + if (placemark == null) + throw new ArgumentNullException(nameof(placemark)); + + if (options == null) + throw new ArgumentNullException(nameof(options)); + var uri = string.Empty; if (options.NavigationMode == NavigationMode.None) { diff --git a/src/Essentials/src/Map/Map.ios.watchos.macos.cs b/src/Essentials/src/Map/Map.ios.watchos.macos.cs index dd5c54ca4a58..40b7f6a84c0a 100644 --- a/src/Essentials/src/Map/Map.ios.watchos.macos.cs +++ b/src/Essentials/src/Map/Map.ios.watchos.macos.cs @@ -11,8 +11,11 @@ namespace Microsoft.Maui.ApplicationModel { class MapImplementation : IMap { - public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) + public Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) { + if (options == null) + throw new ArgumentNullException(nameof(options)); + if (string.IsNullOrWhiteSpace(options.Name)) options.Name = string.Empty; @@ -21,8 +24,14 @@ public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions op return OpenPlacemark(placemark, options); } - public async Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options) + public async Task OpenAsync(Placemark placemark, MapLaunchOptions options) { + if (placemark == null) + throw new ArgumentNullException(nameof(placemark)); + + if (options == null) + throw new ArgumentNullException(nameof(options)); + #if __IOS__ var address = new MKPlacemarkAddress { diff --git a/src/Essentials/src/Map/Map.netstandard.tvos.cs b/src/Essentials/src/Map/Map.netstandard.tvos.cs index 733180b3ce02..766f7de89d93 100644 --- a/src/Essentials/src/Map/Map.netstandard.tvos.cs +++ b/src/Essentials/src/Map/Map.netstandard.tvos.cs @@ -6,10 +6,10 @@ namespace Microsoft.Maui.ApplicationModel /// class MapImplementation : IMap { - public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) + public Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options) + public Task OpenAsync(Placemark placemark, MapLaunchOptions options) => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Map/Map.shared.cs b/src/Essentials/src/Map/Map.shared.cs index 7b41da2700f5..10694a9e7746 100644 --- a/src/Essentials/src/Map/Map.shared.cs +++ b/src/Essentials/src/Map/Map.shared.cs @@ -1,74 +1,48 @@ #nullable enable using System; -using System.ComponentModel; using System.Threading.Tasks; using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.ApplicationModel { public interface IMap { - Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options); - Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options); + Task OpenAsync(double latitude, double longitude, MapLaunchOptions options); + + Task OpenAsync(Placemark placemark, MapLaunchOptions options); } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static class Map { - /// - public static Task OpenAsync(Location location) => - OpenAsync(location, new MapLaunchOptions()); - - /// - public static Task OpenAsync(Location location, MapLaunchOptions options) - { - if (location == null) - throw new ArgumentNullException(nameof(location)); - - if (options == null) - throw new ArgumentNullException(nameof(options)); + static IMap? defaultImplementation; - return Current.OpenMapsAsync(location.Latitude, location.Longitude, options); - } + public static IMap Default => + defaultImplementation ??= new MapImplementation(); - /// - public static Task OpenAsync(double latitude, double longitude) => - OpenAsync(latitude, longitude, new MapLaunchOptions()); - - /// - public static Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) - { - if (options == null) - throw new ArgumentNullException(nameof(options)); - - return Current.OpenMapsAsync(latitude, longitude, options); - } + internal static void SetDefault(IMap? implementation) => + defaultImplementation = implementation; + } - /// - public static Task OpenAsync(Placemark placemark) => - OpenAsync(placemark, new MapLaunchOptions()); + public static class MapExtensions + { + public static Task OpenAsync(this IMap map, Location location) => + map.OpenAsync(location, new MapLaunchOptions()); - /// - public static Task OpenAsync(Placemark placemark, MapLaunchOptions options) + public static Task OpenAsync(this IMap map, Location location, MapLaunchOptions options) { - if (placemark == null) - throw new ArgumentNullException(nameof(placemark)); + if (location == null) + throw new ArgumentNullException(nameof(location)); if (options == null) throw new ArgumentNullException(nameof(options)); - return Current.OpenMapsAsync(placemark, options); + return map.OpenAsync(location.Latitude, location.Longitude, options); } - static IMap? currentImplementation; - - public static IMap Current => - currentImplementation ??= new MapImplementation(); + public static Task OpenAsync(this IMap map, double latitude, double longitude) => + map.OpenAsync(latitude, longitude, new MapLaunchOptions()); - internal static void SetCurrent(IMap? implementation) => - currentImplementation = implementation; + public static Task OpenAsync(this IMap map, Placemark placemark) => + map.OpenAsync(placemark, new MapLaunchOptions()); } } diff --git a/src/Essentials/src/Map/Map.tizen.cs b/src/Essentials/src/Map/Map.tizen.cs index c1c3799ca050..cabb655ff04a 100644 --- a/src/Essentials/src/Map/Map.tizen.cs +++ b/src/Essentials/src/Map/Map.tizen.cs @@ -7,8 +7,11 @@ namespace Microsoft.Maui.ApplicationModel { class MapImplementation : IMap { - public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) + public Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) { + if (options == null) + throw new ArgumentNullException(nameof(options)); + Permissions.EnsureDeclared(); var appControl = new AppControl @@ -24,8 +27,14 @@ public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions op return Task.CompletedTask; } - public Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options) + public Task OpenAsync(Placemark placemark, MapLaunchOptions options) { + if (placemark == null) + throw new ArgumentNullException(nameof(placemark)); + + if (options == null) + throw new ArgumentNullException(nameof(options)); + Permissions.EnsureDeclared(); var appControl = new AppControl diff --git a/src/Essentials/src/Map/Map.uwp.cs b/src/Essentials/src/Map/Map.uwp.cs index dc7cd2ce6fed..feb66c939313 100644 --- a/src/Essentials/src/Map/Map.uwp.cs +++ b/src/Essentials/src/Map/Map.uwp.cs @@ -7,8 +7,11 @@ namespace Microsoft.Maui.ApplicationModel { class MapImplementation:IMap { - public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions options) + public Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) { + if (options == null) + throw new ArgumentNullException(nameof(options)); + var lat = latitude.ToString(CultureInfo.InvariantCulture); var lng = longitude.ToString(CultureInfo.InvariantCulture); var name = options.Name ?? string.Empty; @@ -26,7 +29,7 @@ public Task OpenMapsAsync(double latitude, double longitude, MapLaunchOptions op return LaunchUri(new Uri(uri)); } - internal static string GetMode(NavigationMode mode) + static string GetMode(NavigationMode mode) { switch (mode) { @@ -40,8 +43,14 @@ internal static string GetMode(NavigationMode mode) return string.Empty; } - public Task OpenMapsAsync(Placemark placemark, MapLaunchOptions options) + public Task OpenAsync(Placemark placemark, MapLaunchOptions options) { + if (placemark == null) + throw new ArgumentNullException(nameof(placemark)); + + if (options == null) + throw new ArgumentNullException(nameof(options)); + var uri = string.Empty; if (options.NavigationMode == NavigationMode.None) diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs index 503918aea8a7..cce4a7cab137 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs @@ -12,8 +12,6 @@ public interface IOrientationSensor bool IsMonitoring { get; } - SensorSpeed SensorSpeed { get; } - void Start(SensorSpeed sensorSpeed); void Stop(); @@ -35,9 +33,6 @@ public static event EventHandler ReadingChang public static bool IsSupported => Current.IsSupported; - public static SensorSpeed SensorSpeed - => Current.SensorSpeed; - /// public static bool IsMonitoring { get; private set; } @@ -119,7 +114,7 @@ public partial class OrientationSensorImplementation : IOrientationSensor { bool UseSyncContext => SensorSpeed == SensorSpeed.Default || SensorSpeed == SensorSpeed.UI; - public SensorSpeed SensorSpeed { get; private set; } = SensorSpeed.Default; + SensorSpeed SensorSpeed { get; set; } = SensorSpeed.Default; public event EventHandler ReadingChanged; diff --git a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs index 24af0f186d3c..fb7722f55c6e 100644 --- a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs +++ b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs @@ -123,16 +123,6 @@ internal static UIWindow GetCurrentWindow(bool throwIfNull = true) } #endif -#if __IOS__ || __WATCHOS__ - static CMMotionManager motionManager; - - internal static CMMotionManager MotionManager => - motionManager ?? (motionManager = new CMMotionManager()); -#endif - - internal static NSOperationQueue GetCurrentQueue() => - NSOperationQueue.CurrentQueue ?? new NSOperationQueue(); - #if __IOS__ internal class UIPresentationControllerDelegate : UIAdaptivePresentationControllerDelegate { From c81443d3f18f0efb118f5a54231a979d6fb9d39f Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Wed, 23 Mar 2022 04:06:06 +0200 Subject: [PATCH 08/45] more --- .../Core/src/Essentials/MediaPicker.cs | 49 ++ .../Core/src/Essentials/OrientationSensor.cs | 32 ++ .../Core/src/Essentials/PhoneDialer.cs | 18 + .../Core/src/Essentials/Preferences.cs | 154 +++++++ .../Core/src/Essentials/Screenshot.cs | 25 ++ .../src/Launcher/Launcher.ios.tvos.cs | 1 - .../src/MediaPicker/MediaPicker.android.cs | 16 +- .../src/MediaPicker/MediaPicker.ios.cs | 15 +- .../src/MediaPicker/MediaPicker.shared.cs | 68 +-- .../src/MediaPicker/MediaPicker.tizen.cs | 2 +- .../OrientationSensor.android.cs | 41 +- .../OrientationSensor.ios.watchos.cs | 15 +- .../OrientationSensor.shared.cs | 53 +-- .../OrientationSensor.uwp.cs | 2 +- .../src/PhoneDialer/PhoneDialer.android.cs | 4 +- .../src/PhoneDialer/PhoneDialer.ios.cs | 1 - .../src/PhoneDialer/PhoneDialer.macos.cs | 2 +- .../src/PhoneDialer/PhoneDialer.shared.cs | 32 +- .../src/PhoneDialer/PhoneDialer.tizen.cs | 2 +- .../src/Preferences/Preferences.android.cs | 2 +- .../Preferences/Preferences.netstandard.cs | 1 - .../src/Preferences/Preferences.shared.cs | 175 +------- .../src/Screenshot/Screenshot.android.cs | 137 +++--- .../src/Screenshot/Screenshot.ios.cs | 420 ++++++++---------- ...eenshot.netstandard.tizen.watchos.macos.cs | 2 +- .../src/Screenshot/Screenshot.shared.cs | 102 +++-- .../src/Screenshot/Screenshot.tvos.cs | 5 +- .../src/Screenshot/Screenshot.uwp.cs | 110 ++--- 28 files changed, 741 insertions(+), 745 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/MediaPicker.cs create mode 100644 src/Compatibility/Core/src/Essentials/OrientationSensor.cs create mode 100644 src/Compatibility/Core/src/Essentials/PhoneDialer.cs create mode 100644 src/Compatibility/Core/src/Essentials/Preferences.cs create mode 100644 src/Compatibility/Core/src/Essentials/Screenshot.cs diff --git a/src/Compatibility/Core/src/Essentials/MediaPicker.cs b/src/Compatibility/Core/src/Essentials/MediaPicker.cs new file mode 100644 index 000000000000..21b9fc167c12 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/MediaPicker.cs @@ -0,0 +1,49 @@ +#nullable enable +using System.Threading.Tasks; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class MediaPicker + { + /// + public static bool IsCaptureSupported + => Current.IsCaptureSupported; + + /// + public static Task PickPhotoAsync(MediaPickerOptions options = null) => + Current.PickPhotoAsync(options); + + /// + public static Task CapturePhotoAsync(MediaPickerOptions options = null) + { + if (!IsCaptureSupported) + throw new FeatureNotSupportedException(); + + return Current.CapturePhotoAsync(options); + } + + /// + public static Task PickVideoAsync(MediaPickerOptions options = null) => + Current.PickVideoAsync(options); + + /// + public static Task CaptureVideoAsync(MediaPickerOptions options = null) + { + if (!IsCaptureSupported) + throw new FeatureNotSupportedException(); + + return Current.CaptureVideoAsync(options); + } + +#nullable enable + static IMediaPicker? currentImplementation; + + public static IMediaPicker Current => + currentImplementation ??= new MediaPickerImplementation(); + + internal static void SetCurrent(IMediaPicker? implementation) => + currentImplementation = implementation; +#nullable disable + } +} diff --git a/src/Compatibility/Core/src/Essentials/OrientationSensor.cs b/src/Compatibility/Core/src/Essentials/OrientationSensor.cs new file mode 100644 index 000000000000..79e001a7819a --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/OrientationSensor.cs @@ -0,0 +1,32 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class OrientationSensor + { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + public static bool IsSupported + => Current.IsSupported; + + /// + public static bool IsMonitoring { get; private set; } + + /// + public static void Start(SensorSpeed sensorSpeed) + => Current.Start(sensorSpeed); + + /// + public static void Stop() + => Current.Stop(); + + static IOrientationSensor Current => Devices.Sensors.OrientationSensor.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/PhoneDialer.cs b/src/Compatibility/Core/src/Essentials/PhoneDialer.cs new file mode 100644 index 000000000000..f82b5b11a029 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/PhoneDialer.cs @@ -0,0 +1,18 @@ +#nullable enable +using Microsoft.Maui.ApplicationModel.Communication; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class PhoneDialer + { + public static bool IsSupported => + Current.IsSupported; + + /// + public static void Open(string number) + => Current.Open(number); + + public static IPhoneDialer Current => ApplicationModel.Communication.PhoneDialer.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Preferences.cs b/src/Compatibility/Core/src/Essentials/Preferences.cs new file mode 100644 index 000000000000..1f14c258150a --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Preferences.cs @@ -0,0 +1,154 @@ +#nullable enable +using System; +using Microsoft.Maui.Storage; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Preferences + { + // overloads + + /// + public static bool ContainsKey(string key) => + ContainsKey(key, null); + + /// + public static void Remove(string key) => + Remove(key, null); + + /// + public static void Clear() => + Clear(null); + + /// + public static string Get(string key, string defaultValue) => + Get(key, defaultValue, null); + + /// + public static bool Get(string key, bool defaultValue) => + Get(key, defaultValue, null); + + /// + public static int Get(string key, int defaultValue) => + Get(key, defaultValue, null); + + /// + public static double Get(string key, double defaultValue) => + Get(key, defaultValue, null); + + /// + public static float Get(string key, float defaultValue) => + Get(key, defaultValue, null); + + /// + public static long Get(string key, long defaultValue) => + Get(key, defaultValue, null); + + /// + public static void Set(string key, string value) => + Set(key, value, null); + + /// + public static void Set(string key, bool value) => + Set(key, value, null); + + /// + public static void Set(string key, int value) => + Set(key, value, null); + + /// + public static void Set(string key, double value) => + Set(key, value, null); + + /// + public static void Set(string key, float value) => + Set(key, value, null); + + /// + public static void Set(string key, long value) => + Set(key, value, null); + + // shared -> platform + + /// + public static bool ContainsKey(string key, string? sharedName) => + Current.ContainsKey(key, sharedName); + + /// + public static void Remove(string key, string? sharedName) => + Current.Remove(key, sharedName); + + /// + public static void Clear(string? sharedName) => + Current.Clear(sharedName); + + /// + public static string Get(string key, string defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static bool Get(string key, bool defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static int Get(string key, int defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static double Get(string key, double defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static float Get(string key, float defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static long Get(string key, long defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static void Set(string key, string value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, bool value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, int value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, double value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, float value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, long value, string? sharedName) => + Current.Set(key, value, sharedName); + + // DateTime + + /// + public static DateTime Get(string key, DateTime defaultValue) => + Get(key, defaultValue, null); + + /// + public static void Set(string key, DateTime value) => + Set(key, value, null); + + /// + public static DateTime Get(string key, DateTime defaultValue, string? sharedName) => + DateTime.FromBinary(Current.Get(key, defaultValue.ToBinary(), sharedName)); + + /// + public static void Set(string key, DateTime value, string? sharedName) => + Current.Set(key, value.ToBinary(), sharedName); + + static IPreferences Current => Storage.Preferences.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Screenshot.cs b/src/Compatibility/Core/src/Essentials/Screenshot.cs new file mode 100644 index 000000000000..eb93d032eb2f --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Screenshot.cs @@ -0,0 +1,25 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.Media; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Screenshot + { + /// + public static bool IsCaptureSupported + => Current.IsCaptureSupported; + + /// + public static Task CaptureAsync() + { + if (!IsCaptureSupported) + throw new FeatureNotSupportedException(); + + return Current.CaptureAsync(); + } + + static IScreenshot Current => Media.Screenshot.Current; + } +} diff --git a/src/Essentials/src/Launcher/Launcher.ios.tvos.cs b/src/Essentials/src/Launcher/Launcher.ios.tvos.cs index 0f96e4c7e794..e59ca89bec1e 100644 --- a/src/Essentials/src/Launcher/Launcher.ios.tvos.cs +++ b/src/Essentials/src/Launcher/Launcher.ios.tvos.cs @@ -5,7 +5,6 @@ using Microsoft.Maui.Devices; using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics.Platform; -using ObjCRuntime; using UIKit; namespace Microsoft.Maui.ApplicationModel diff --git a/src/Essentials/src/MediaPicker/MediaPicker.android.cs b/src/Essentials/src/MediaPicker/MediaPicker.android.cs index 53416768e738..27050590ef63 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.android.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.android.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Android.App; using Android.Content; using Android.Content.PM; using Android.Provider; @@ -12,7 +13,7 @@ namespace Microsoft.Maui.Media partial class MediaPickerImplementation : IMediaPicker { public bool IsCaptureSupported - => Platform.AppContext.PackageManager.HasSystemFeature(PackageManager.FeatureCameraAny); + => Application.Context.PackageManager.HasSystemFeature(PackageManager.FeatureCameraAny); public Task PickPhotoAsync(MediaPickerOptions options) => PickAsync(options, true); @@ -23,7 +24,7 @@ public Task PickVideoAsync(MediaPickerOptions options) public async Task PickAsync(MediaPickerOptions options, bool photo) { var intent = new Intent(Intent.ActionGetContent); - intent.SetType(photo ? FileSystem.MimeTypes.ImageAll : FileSystem.MimeTypes.VideoAll); + intent.SetType(photo ? FileMimeTypes.ImageAll : FileMimeTypes.VideoAll); var pickerIntent = Intent.CreateChooser(intent, options?.Title); @@ -36,7 +37,7 @@ void OnResult(Intent intent) // so this means that it will always be cleaned up by the time we need it because we are using // an intermediate activity. - path = FileSystem.EnsurePhysicalPath(intent.Data); + path = FileSystemUtils.EnsurePhysicalPath(intent.Data); } await IntermediateActivity.StartAsync(pickerIntent, Platform.requestCodeMediaPicker, onResult: OnResult); @@ -57,6 +58,9 @@ public Task CaptureVideoAsync(MediaPickerOptions options) public async Task CaptureAsync(MediaPickerOptions options, bool photo) { + if (!IsCaptureSupported) + throw new FeatureNotSupportedException(); + await Permissions.EnsureGrantedAsync(); await Permissions.EnsureGrantedAsync(); @@ -74,10 +78,10 @@ public async Task CaptureAsync(MediaPickerOptions options, bool phot // Create the temporary file var ext = photo - ? FileSystem.Extensions.Jpg - : FileSystem.Extensions.Mp4; + ? FileExtensions.Jpg + : FileExtensions.Mp4; var fileName = Guid.NewGuid().ToString("N") + ext; - var tmpFile = FileSystem.GetTemporaryFile(Platform.AppContext.CacheDir, fileName); + var tmpFile = FileSystemUtils.GetTemporaryFile(Application.Context.CacheDir, fileName); // Set up the content:// uri AndroidUri outputUri = null; diff --git a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs index 82a3d2e8a9c7..2e6922577041 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.ios.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.ios.cs @@ -6,7 +6,6 @@ using Microsoft.Maui.Devices; using Microsoft.Maui.Storage; using MobileCoreServices; -using ObjCRuntime; using Photos; using UIKit; @@ -23,13 +22,23 @@ public Task PickPhotoAsync(MediaPickerOptions options) => PhotoAsync(options, true, true); public Task CapturePhotoAsync(MediaPickerOptions options) - => PhotoAsync(options, true, false); + { + if (!IsCaptureSupported) + throw new FeatureNotSupportedException(); + + return PhotoAsync(options, true, false); + } public Task PickVideoAsync(MediaPickerOptions options) => PhotoAsync(options, false, true); public Task CaptureVideoAsync(MediaPickerOptions options) - => PhotoAsync(options, false, false); + { + if (!IsCaptureSupported) + throw new FeatureNotSupportedException(); + + return PhotoAsync(options, false, false); + } public async Task PhotoAsync(MediaPickerOptions options, bool photo, bool pickExisting) { diff --git a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs index 5d45fac3200f..2d3881b75bb8 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs @@ -1,8 +1,5 @@ -using System; -using System.ComponentModel; -using System.IO; +#nullable enable using System.Threading.Tasks; -using Microsoft.Maui.Media; using Microsoft.Maui.Storage; namespace Microsoft.Maui.Media @@ -11,67 +8,30 @@ public interface IMediaPicker { bool IsCaptureSupported { get; } - Task PickPhotoAsync(MediaPickerOptions options); + Task PickPhotoAsync(MediaPickerOptions? options = null); - Task CapturePhotoAsync(MediaPickerOptions options); + Task CapturePhotoAsync(MediaPickerOptions? options = null); - Task PickVideoAsync(MediaPickerOptions options); + Task PickVideoAsync(MediaPickerOptions? options = null); - Task CaptureVideoAsync(MediaPickerOptions options); + Task CaptureVideoAsync(MediaPickerOptions? options = null); } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class MediaPicker - { - /// - public static bool IsCaptureSupported - => Current.IsCaptureSupported; - - /// - public static Task PickPhotoAsync(MediaPickerOptions options = null) => - Current.PickPhotoAsync(options); - - /// - public static Task CapturePhotoAsync(MediaPickerOptions options = null) - { - if (!IsCaptureSupported) - throw new FeatureNotSupportedException(); - - return Current.CapturePhotoAsync(options); - } - - /// - public static Task PickVideoAsync(MediaPickerOptions options = null) => - Current.PickVideoAsync(options); - /// - public static Task CaptureVideoAsync(MediaPickerOptions options = null) - { - if (!IsCaptureSupported) - throw new FeatureNotSupportedException(); - - return Current.CaptureVideoAsync(options); - } - -#nullable enable - static IMediaPicker? currentImplementation; + public static class MediaPicker + { + static IMediaPicker? defaultImplementation; - public static IMediaPicker Current => - currentImplementation ??= new MediaPickerImplementation(); + public static IMediaPicker Default => + defaultImplementation ??= new MediaPickerImplementation(); - internal static void SetCurrent(IMediaPicker? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IMediaPicker? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.Media -{ + /// public class MediaPickerOptions { /// - public string Title { get; set; } + public string? Title { get; set; } } } diff --git a/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs b/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs index 28e84bda0456..f5dbd42cb1ce 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.tizen.cs @@ -10,7 +10,7 @@ namespace Microsoft.Maui.Media partial class MediaPickerImplementation : IMediaPicker { public bool IsCaptureSupported - => true; + => true; public async Task PickPhotoAsync(MediaPickerOptions options) => await FilePicker.PickAsync(new PickOptions diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs index 0c850db82b80..75c9d1d7734b 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.android.cs @@ -1,32 +1,41 @@ +#nullable enable using System; +using Android.App; +using Android.Content; using Android.Hardware; -using Android.Runtime; namespace Microsoft.Maui.Devices.Sensors { partial class OrientationSensorImplementation : IOrientationSensor { + static SensorManager? _sensorManager; + static Sensor? orientationSensor; + + static SensorManager? SensorManager => + _sensorManager ??= Application.Context.GetSystemService(Context.SensorService) as SensorManager; + + static Sensor? Sensor => + orientationSensor ??= SensorManager?.GetDefaultSensor(SensorType.RotationVector); + bool PlatformIsSupported => - Platform.SensorManager?.GetDefaultSensor(SensorType.RotationVector) != null; + Sensor is not null; - OrientationSensorListener listener; - Sensor orientationSensor; + OrientationSensorListener? listener; void PlatformStart(SensorSpeed sensorSpeed) { var delay = sensorSpeed.ToPlatform(); listener = new OrientationSensorListener(RaiseReadingChanged); - orientationSensor = Platform.SensorManager.GetDefaultSensor(SensorType.RotationVector); - Platform.SensorManager.RegisterListener(listener, orientationSensor, delay); + SensorManager!.RegisterListener(listener, Sensor, delay); } void PlatformStop() { - if (listener == null || orientationSensor == null) + if (listener == null || Sensor == null) return; - Platform.SensorManager.UnregisterListener(listener, orientationSensor); + SensorManager!.UnregisterListener(listener, Sensor); listener.Dispose(); listener = null; } @@ -41,25 +50,25 @@ internal OrientationSensorListener(Action callback) readonly Action Callback; - void ISensorEventListener.OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy) + void ISensorEventListener.OnAccuracyChanged(Sensor? sensor, SensorStatus accuracy) { } - void ISensorEventListener.OnSensorChanged(SensorEvent e) + void ISensorEventListener.OnSensorChanged(SensorEvent? e) { - var count = e?.Values?.Count ?? 0; - if (count < 3) + var values = e?.Values ?? Array.Empty(); + if (values.Count < 3) return; OrientationSensorData? data; - // Docs: https://developer.android.com/reference/android/hardware/SensorEvent#sensor.type_rotation_vector-: + // Docs: https://developer.android.com/reference/android/hardware/SensorEvent#sensor.type_rotation_vector: // values[3], originally optional, will always be present from SDK Level 18 onwards. values[4] is a new value that has been added in SDK Level 18. - if (count < 4) - data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], -1); + if (values.Count < 4) + data = new OrientationSensorData(values[0], values[1], values[2], -1); else - data = new OrientationSensorData(e.Values[0], e.Values[1], e.Values[2], e.Values[3]); + data = new OrientationSensorData(values[0], values[1], values[2], values[3]); Callback?.Invoke(data.Value); } diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs index 44b7975d5339..f270074b6a47 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.ios.watchos.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Numerics; using CoreMotion; @@ -7,16 +8,20 @@ namespace Microsoft.Maui.Devices.Sensors { partial class OrientationSensorImplementation : IOrientationSensor { + static CMMotionManager? motionManager; + + static CMMotionManager MotionManager => + motionManager ??= new CMMotionManager(); + bool PlatformIsSupported => - Platform.MotionManager?.DeviceMotionAvailable ?? false; + MotionManager.GyroAvailable; void PlatformStart(SensorSpeed sensorSpeed) { - var manager = Platform.MotionManager; - manager.DeviceMotionUpdateInterval = sensorSpeed.ToPlatform(); + MotionManager.DeviceMotionUpdateInterval = sensorSpeed.ToPlatform(); // use a fixed reference frame where X points north and Z points vertically into the sky - manager.StartDeviceMotionUpdates(CMAttitudeReferenceFrame.XTrueNorthZVertical, Platform.GetCurrentQueue(), DataUpdated); + MotionManager.StartDeviceMotionUpdates(CMAttitudeReferenceFrame.XTrueNorthZVertical, NSOperationQueue.CurrentQueue, DataUpdated); } void DataUpdated(CMDeviceMotion data, NSError error) @@ -41,6 +46,6 @@ void DataUpdated(CMDeviceMotion data, NSError error) } void PlatformStop() => - Platform.MotionManager?.StopDeviceMotionUpdates(); + MotionManager.StopDeviceMotionUpdates(); } } diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs index cce4a7cab137..4734864d5c3c 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs @@ -1,8 +1,6 @@ +#nullable enable using System; using System.Numerics; -using System.ComponentModel; -using Microsoft.Maui.Devices.Sensors; -using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors { @@ -18,45 +16,18 @@ public interface IOrientationSensor event EventHandler ReadingChanged; } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static partial class OrientationSensor { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - public static bool IsSupported - => Current.IsSupported; - - /// - public static bool IsMonitoring { get; private set; } - - /// - public static void Start(SensorSpeed sensorSpeed) - => Current.Start(sensorSpeed); + static IOrientationSensor? defaultImplementation; - /// - public static void Stop() - => Current.Stop(); + public static IOrientationSensor Default => + defaultImplementation ??= new OrientationSensorImplementation(); -#nullable enable - static IOrientationSensor? currentImplementation; - - public static IOrientationSensor Current => - currentImplementation ??= new OrientationSensorImplementation(); - - internal static void SetCurrent(IOrientationSensor? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IOrientationSensor? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.Devices.Sensors -{ + /// public class OrientationSensorChangedEventArgs : EventArgs { @@ -96,7 +67,7 @@ public bool Equals(OrientationSensorData other) => left.Equals(right); public static bool operator !=(OrientationSensorData left, OrientationSensorData right) => - !left.Equals(right); + !left.Equals(right); /// public override int GetHashCode() => @@ -116,7 +87,7 @@ public partial class OrientationSensorImplementation : IOrientationSensor SensorSpeed SensorSpeed { get; set; } = SensorSpeed.Default; - public event EventHandler ReadingChanged; + public event EventHandler? ReadingChanged; public bool IsSupported => PlatformIsSupported; @@ -145,7 +116,6 @@ public void Start(SensorSpeed sensorSpeed) } } - /// public void Stop() { if (!PlatformIsSupported) @@ -170,12 +140,11 @@ public void Stop() internal void RaiseReadingChanged(OrientationSensorData reading) { var args = new OrientationSensorChangedEventArgs(reading); - + if (UseSyncContext) MainThread.BeginInvokeOnMainThread(() => ReadingChanged?.Invoke(null, args)); else ReadingChanged?.Invoke(null, args); } - } } diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs index 52d88d68f4fc..bd395d922a1f 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.uwp.cs @@ -9,7 +9,7 @@ partial class OrientationSensorImplementation : IOrientationSensor WindowsOrientationSensor sensor; static WindowsOrientationSensor DefaultSensor => - WindowsOrientationSensor.GetDefault(); + WindowsOrientationSensor.GetDefault(); bool PlatformIsSupported => DefaultSensor != null; diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs index 6e1f31f112b9..9768dccdea1c 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.android.cs @@ -1,10 +1,8 @@ using System; using Android.App; using Android.Content; -using Android.OS; using Android.Telephony; using Java.Net; -using Java.Util; using Uri = Android.Net.Uri; namespace Microsoft.Maui.ApplicationModel.Communication @@ -43,7 +41,7 @@ public void Open(string number) flags |= ActivityFlags.LaunchAdjacent; dialIntent.SetFlags(flags); - Platform.AppContext.StartActivity(dialIntent); + Application.Context.StartActivity(dialIntent); } static Intent ResolveDialIntent(string number) diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs index 1df52dc378da..e662252d60dc 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.ios.cs @@ -1,6 +1,5 @@ using System; using Foundation; -using ObjCRuntime; using UIKit; namespace Microsoft.Maui.ApplicationModel.Communication diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs index 2770d3c6a971..25dc7403e84a 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.macos.cs @@ -8,7 +8,7 @@ partial class PhoneDialerImplementation : IPhoneDialer public bool IsSupported => MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString($"tel:0000000000")) != null); - public void PlatformOpen(string number) + public void Open(string number) { ValidateOpen(number); diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs index 1d9edee553bc..c1f96b0cfbd5 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs @@ -1,7 +1,5 @@ #nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel.Communication; namespace Microsoft.Maui.ApplicationModel.Communication { @@ -11,35 +9,21 @@ public interface IPhoneDialer void Open(string number); } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static class PhoneDialer { - public static bool IsSupported => Current.IsSupported; - - /// - public static void Open(string number) - => Current.Open(number); + static IPhoneDialer? defaultImplementation; - static IPhoneDialer? currentImplementation; + public static IPhoneDialer Default => + defaultImplementation ??= new PhoneDialerImplementation(); - [EditorBrowsable(EditorBrowsableState.Never)] - public static IPhoneDialer Current => - currentImplementation ??= new PhoneDialerImplementation(); - - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IPhoneDialer? implementation) => - currentImplementation = implementation; + internal static void SetDefault(IPhoneDialer? implementation) => + defaultImplementation = implementation; } -} -namespace Microsoft.Maui.ApplicationModel.Communication -{ - partial class PhoneDialerImplementation + partial class PhoneDialerImplementation : IPhoneDialer { - internal void ValidateOpen(string number) + void ValidateOpen(string number) { if (string.IsNullOrWhiteSpace(number)) throw new ArgumentNullException(nameof(number)); diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs index 87b79477e541..880d8bf58441 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.tizen.cs @@ -7,7 +7,7 @@ partial class PhoneDialerImplementation : IPhoneDialer public bool IsSupported => Platform.GetFeatureInfo("contact"); - public void PlatformOpen(string number) + public void Open(string number) { ValidateOpen(number); diff --git a/src/Essentials/src/Preferences/Preferences.android.cs b/src/Essentials/src/Preferences/Preferences.android.cs index 10f0c4d2c28b..c47c1575002b 100644 --- a/src/Essentials/src/Preferences/Preferences.android.cs +++ b/src/Essentials/src/Preferences/Preferences.android.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Storage { class PreferencesImplementation : IPreferences { - static readonly object locker = new object(); + readonly object locker = new object(); public bool ContainsKey(string key, string sharedName) { diff --git a/src/Essentials/src/Preferences/Preferences.netstandard.cs b/src/Essentials/src/Preferences/Preferences.netstandard.cs index 0fc111a26a29..21f4ab862624 100644 --- a/src/Essentials/src/Preferences/Preferences.netstandard.cs +++ b/src/Essentials/src/Preferences/Preferences.netstandard.cs @@ -1,6 +1,5 @@ namespace Microsoft.Maui.Storage { - /// class PreferencesImplementation : IPreferences { public bool ContainsKey(string key, string sharedName) => diff --git a/src/Essentials/src/Preferences/Preferences.shared.cs b/src/Essentials/src/Preferences/Preferences.shared.cs index 9fa63fcbb3d7..972051dec747 100644 --- a/src/Essentials/src/Preferences/Preferences.shared.cs +++ b/src/Essentials/src/Preferences/Preferences.shared.cs @@ -1,176 +1,31 @@ #nullable enable -using System; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Storage; namespace Microsoft.Maui.Storage { public interface IPreferences { - bool ContainsKey(string key, string? sharedName); - void Remove(string key, string? sharedName); - void Clear(string? sharedName); - void Set(string key, T value, string? sharedName); - T Get(string key, T defaultValue, string? sharedName); - } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static class Preferences - { - internal static string GetPrivatePreferencesSharedName(string feature) => - $"{AppInfo.PackageName}.microsoft.maui.essentials.{feature}"; - - // overloads - - /// - public static bool ContainsKey(string key) => - ContainsKey(key, null); - - /// - public static void Remove(string key) => - Remove(key, null); - - /// - public static void Clear() => - Clear(null); - - /// - public static string Get(string key, string defaultValue) => - Get(key, defaultValue, null); - - /// - public static bool Get(string key, bool defaultValue) => - Get(key, defaultValue, null); - - /// - public static int Get(string key, int defaultValue) => - Get(key, defaultValue, null); - - /// - public static double Get(string key, double defaultValue) => - Get(key, defaultValue, null); - - /// - public static float Get(string key, float defaultValue) => - Get(key, defaultValue, null); - - /// - public static long Get(string key, long defaultValue) => - Get(key, defaultValue, null); - - /// - public static void Set(string key, string value) => - Set(key, value, null); - - /// - public static void Set(string key, bool value) => - Set(key, value, null); - - /// - public static void Set(string key, int value) => - Set(key, value, null); - - /// - public static void Set(string key, double value) => - Set(key, value, null); - - /// - public static void Set(string key, float value) => - Set(key, value, null); + bool ContainsKey(string key, string? sharedName = null); - /// - public static void Set(string key, long value) => - Set(key, value, null); + void Remove(string key, string? sharedName = null); - // shared -> platform + void Clear(string? sharedName = null); - /// - public static bool ContainsKey(string key, string? sharedName) => - Current.ContainsKey(key, sharedName); + void Set(string key, T value, string? sharedName = null); - /// - public static void Remove(string key, string? sharedName) => - Current.Remove(key, sharedName); - - /// - public static void Clear(string? sharedName) => - Current.Clear(sharedName); - - /// - public static string Get(string key, string defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static bool Get(string key, bool defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static int Get(string key, int defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static double Get(string key, double defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static float Get(string key, float defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static long Get(string key, long defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static void Set(string key, string value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, bool value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, int value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, double value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, float value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, long value, string? sharedName) => - Current.Set(key, value, sharedName); - - // DateTime - - /// - public static DateTime Get(string key, DateTime defaultValue) => - Get(key, defaultValue, null); - - /// - public static void Set(string key, DateTime value) => - Set(key, value, null); - - /// - public static DateTime Get(string key, DateTime defaultValue, string? sharedName) => - DateTime.FromBinary(Current.Get(key, defaultValue.ToBinary(), sharedName)); + T Get(string key, T defaultValue, string? sharedName = null); + } - /// - public static void Set(string key, DateTime value, string? sharedName) => - Current.Set(key, value.ToBinary(), sharedName); + public static class Preferences + { + internal static string GetPrivatePreferencesSharedName(string feature) => + $"{AppInfo.PackageName}.microsoft.maui.essentials.{feature}"; - static IPreferences? currentImplementation; + static IPreferences? defaultImplementation; - public static IPreferences Current => - currentImplementation ??= new PreferencesImplementation(); + public static IPreferences Default => + defaultImplementation ??= new PreferencesImplementation(); - internal static void SetCurrent(IPreferences? implementation) => - currentImplementation = implementation; + internal static void SetDefault(IPreferences? implementation) => + defaultImplementation = implementation; } } diff --git a/src/Essentials/src/Screenshot/Screenshot.android.cs b/src/Essentials/src/Screenshot/Screenshot.android.cs index 7ed5541da8fd..c038a21667c4 100644 --- a/src/Essentials/src/Screenshot/Screenshot.android.cs +++ b/src/Essentials/src/Screenshot/Screenshot.android.cs @@ -2,60 +2,56 @@ using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Android.App; +using Android.Content; using Android.Graphics; using Android.Views; using Java.Nio; namespace Microsoft.Maui.Media { - public static partial class Screenshot + public partial class ScreenshotImplementation : IPlatformScreenshot, IScreenshot { - public static byte[] RenderAsJPEG(this View view, int quality = 100) => view?.RenderAsImage(Bitmap.CompressFormat.Jpeg, quality); + static IWindowManager windowManager; - public static byte[] RenderAsPNG(this View view, int quality = 100) => view?.RenderAsImage(Bitmap.CompressFormat.Png, quality); + static IWindowManager WindowManager => + windowManager ??= Application.Context.GetSystemService(Context.WindowService) as IWindowManager; - public static byte[] RenderAsBMP(this View view) + public bool IsCaptureSupported => true; + + public Task CaptureAsync() { - using (var bitmap = view.Render()) - { - var byteBuffer = ByteBuffer.AllocateDirect(bitmap.ByteCount); - bitmap.CopyPixelsToBuffer(byteBuffer); - byte[] byt = new byte[bitmap.ByteCount]; - Marshal.Copy(byteBuffer.GetDirectBufferAddress(), byt, 0, bitmap.ByteCount); - return byt; - } + if (WindowManager?.DefaultDisplay?.Flags.HasFlag(DisplayFlags.Secure) == true) + throw new UnauthorizedAccessException("Unable to take a screenshot of a secure window."); + + var view = Platform.GetCurrentActivity(true)?.Window?.DecorView?.RootView; + if (view == null) + throw new InvalidOperationException("Unable to find the main window."); + + return CaptureAsync(view); } - public static byte[] RenderAsImage(this View view, Bitmap.CompressFormat format, int quality = 100) + public Task CaptureAsync(View view) { - byte[] imageBytes = null; + _ = view ?? throw new ArgumentNullException(nameof(view)); - using (var bitmap = view.Render()) - { - if (bitmap != null) - { - imageBytes = bitmap.AsImageBytes(format, quality); - if (!bitmap.IsRecycled) - bitmap.Recycle(); - } - } + var bitmap = Render(view); + var result = new ScreenshotResult(bitmap); - return imageBytes; + return Task.FromResult(result); } - public static byte[] AsImageBytes(this Bitmap bitmap, Bitmap.CompressFormat format, int quality = 100) + static Bitmap Render(View view) { - byte[] byteArray = null; - using (var mem = new MemoryStream()) - { - bitmap.Compress(format, quality, mem); - byteArray = mem.ToArray(); - } + var bitmap = RenderUsingCanvasDrawing(view); + + if (bitmap == null) + bitmap = RenderUsingDrawingCache(view); - return byteArray; + return bitmap; } - public static Bitmap RenderUsingCanvasDrawing(this View view) + static Bitmap RenderUsingCanvasDrawing(View view) { try { @@ -79,7 +75,7 @@ public static Bitmap RenderUsingCanvasDrawing(this View view) } } - static Bitmap RenderUsingDrawingCache(this View view) + static Bitmap RenderUsingDrawingCache(View view) { #pragma warning disable CS0618 // Type or member is obsolete try @@ -99,45 +95,10 @@ static Bitmap RenderUsingDrawingCache(this View view) return null; } #pragma warning restore CS0618 // Type or member is obsolete - - } - - public static Bitmap Render(this View view) - { - var bitmap = view.RenderUsingCanvasDrawing(); - - if (bitmap == null) - bitmap = view.RenderUsingDrawingCache(); - - return bitmap; } } -} -namespace Microsoft.Maui.Media -{ - public partial class ScreenshotImplementation : IScreenshot - { - public bool IsCaptureSupported => - true; - - public Task CaptureAsync() - { - if (Platform.WindowManager?.DefaultDisplay?.Flags.HasFlag(DisplayFlags.Secure) == true) - throw new UnauthorizedAccessException("Unable to take a screenshot of a secure window."); - - var view = Platform.GetCurrentActivity(true)?.Window?.DecorView?.RootView; - if (view == null) - throw new InvalidOperationException("Unable to find the main window."); - - var result = new ScreenshotResult(view.Render()); - - return Task.FromResult(result); - } - - } - - internal partial class ScreenshotResult + partial class ScreenshotResult { readonly Bitmap bmp; @@ -150,16 +111,36 @@ internal ScreenshotResult(Bitmap bmp) Height = bmp.Height; } - internal Task PlatformOpenReadAsync(ScreenshotFormat format) + Task PlatformOpenReadAsync(ScreenshotFormat format, int quality) { - var f = format switch - { - ScreenshotFormat.Jpeg => Bitmap.CompressFormat.Jpeg, - _ => Bitmap.CompressFormat.Png, - }; + var result = new MemoryStream(); + PlatformCopyToAsync(result, format, quality); + result.Position = 0; + return Task.FromResult(result); + } - var result = new MemoryStream(bmp.AsImageBytes(f, 100)) as Stream; - return Task.FromResult(result); + Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) + { + var f = ToCompressFormat(format); + bmp.Compress(f, quality, destination); + return Task.CompletedTask; } + + Task PlatformToPixelBufferAsync() + { + var byteBuffer = ByteBuffer.AllocateDirect(bmp.ByteCount); + bmp.CopyPixelsToBuffer(byteBuffer); + byte[] byt = new byte[bmp.ByteCount]; + Marshal.Copy(byteBuffer.GetDirectBufferAddress(), byt, 0, bmp.ByteCount); + return Task.FromResult(byt); + } + + static Bitmap.CompressFormat ToCompressFormat(ScreenshotFormat format) => + format switch + { + ScreenshotFormat.Png => Bitmap.CompressFormat.Png!, + ScreenshotFormat.Jpeg => Bitmap.CompressFormat.Jpeg!, + _ => throw new ArgumentOutOfRangeException(nameof(format)), + }; } } diff --git a/src/Essentials/src/Screenshot/Screenshot.ios.cs b/src/Essentials/src/Screenshot/Screenshot.ios.cs index 593036470b49..35ef201238f2 100644 --- a/src/Essentials/src/Screenshot/Screenshot.ios.cs +++ b/src/Essentials/src/Screenshot/Screenshot.ios.cs @@ -1,124 +1,127 @@ -using System; +#nullable enable +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; -using System.Text; using System.Threading.Tasks; using CoreAnimation; using CoreGraphics; -using Foundation; using ObjCRuntime; using UIKit; namespace Microsoft.Maui.Media { - public static partial class Screenshot + partial class ScreenshotImplementation : IPlatformScreenshot, IScreenshot { - [DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSend")] - static extern bool bool_objc_msgSend_IntPtr(IntPtr receiver, IntPtr selector, IntPtr arg1); - - [DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSend")] - static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector); + public bool IsCaptureSupported => + true; - public static byte[] RenderAsBmp(this UIWindow window, object obj, nfloat scale, bool skipChildren = true) + public Task CaptureAsync() { - using (var image = Render(window, obj, scale, skipChildren)) - return image != null ? image.RenderAsBmp() : null; - } + var scenes = UIApplication.SharedApplication.ConnectedScenes; + var currentScene = scenes.ToArray().Where(n => n.ActivationState == UISceneActivationState.ForegroundActive).FirstOrDefault(); + if (currentScene == null) + throw new InvalidOperationException("Unable to find current scene."); - public static byte[] RenderAsPng(this UIWindow window, object obj, nfloat scale, bool skipChildren = true) - { - using (var image = Render(window, obj, scale, skipChildren)) - return image != null ? image.RenderAsPng() : null; + var uiWindowScene = currentScene as UIWindowScene; + if (uiWindowScene == null) + throw new InvalidOperationException("Unable to find current window scene."); + + var currentWindow = uiWindowScene.Windows.FirstOrDefault(n => n.IsKeyWindow); + if (currentWindow == null) + throw new InvalidOperationException("Unable to find current window."); + + return CaptureAsync(currentWindow.Layer, true); } - public static byte[] RenderAsJpeg(this UIWindow window, object obj, nfloat scale, bool skipChildren = true) + public Task CaptureAsync(UIWindow window) { - using (var image = Render(window, obj, scale, skipChildren)) - return image != null ? image.RenderAsJpeg() : null; - } + _ = window ?? throw new ArgumentNullException(nameof(window)); - public static byte[] RenderAsBmp(this UIImage image) => image.AsBMP(); + // NOTE: We rely on the window frame having been set to the correct size when this method is invoked. + UIGraphics.BeginImageContextWithOptions(window.Bounds.Size, false, window.Screen.Scale); + var ctx = UIGraphics.GetCurrentContext(); - public static byte[] RenderAsPng(this UIImage image) => image.AsPNG().AsImageBytes(); + if (!TryRender(window, out var error)) + { + // FIXME: test/handle this case + } - public static byte[] RenderAsJpeg(this UIImage image) => image.AsJPEG().AsImageBytes(); + // Render the status bar with the correct frame size + TryHideStatusClockView(UIApplication.SharedApplication); + var statusbarWindow = GetStatusBarWindow(UIApplication.SharedApplication); + if (statusbarWindow != null/* && metrics.StatusBar != null*/) + { + statusbarWindow.Frame = window.Frame; + statusbarWindow.Layer.RenderInContext(ctx); + } - public static UIImage Render(this UIWindow window, object obj, nfloat scale, bool skipChildren = true) - { - CGContext ctx = null; - Exception error = null; + var image = UIGraphics.GetImageFromCurrentImageContext(); + UIGraphics.EndImageContext(); - var viewController = obj as UIViewController; - if (viewController != null) - { - // NOTE: We rely on the window frame having been set to the correct size when this method is invoked. - UIGraphics.BeginImageContextWithOptions(window.Bounds.Size, false, scale); - ctx = UIGraphics.GetCurrentContext(); + var result = new ScreenshotResult(image); - if (!TryRender(window, ctx, ref error)) - { - //FIXME: test/handle this case - } + return Task.FromResult(result); + } - // Render the status bar with the correct frame size - UIApplication.SharedApplication.TryHideStatusClockView(); - var statusbarWindow = UIApplication.SharedApplication.GetStatusBarWindow(); - if (statusbarWindow != null/* && metrics.StatusBar != null*/) - { - statusbarWindow.Frame = window.Frame; - statusbarWindow.Layer.RenderInContext(ctx); - } - } + public Task CaptureAsync(UIView view) + { + _ = view ?? throw new ArgumentNullException(nameof(view)); - var view = obj as UIView; - if (view != null) - { - UIGraphics.BeginImageContextWithOptions(view.Bounds.Size, false, scale); - ctx = UIGraphics.GetCurrentContext(); - // ctx will be null if the width/height of the view is zero - if (ctx != null) - TryRender(view, ctx, ref error); - } + // NOTE: We rely on the view frame having been set to the correct size when this method is invoked. + UIGraphics.BeginImageContextWithOptions(view.Bounds.Size, false, view.Window.Screen.Scale); + var ctx = UIGraphics.GetCurrentContext(); - var layer = obj as CALayer; - if (layer != null) + // ctx will be null if the width/height of the view is zero + if (ctx != null) { - UIGraphics.BeginImageContextWithOptions(layer.Bounds.Size, false, scale); - ctx = UIGraphics.GetCurrentContext(); - if (ctx != null) - TryRender(layer, ctx, skipChildren, ref error); + if (!TryRender(view, out var error)) + { + // FIXME: test/handle this case + } } - if (ctx == null) - return null; - var image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); - return image; - } + var result = new ScreenshotResult(image); - static byte[] AsImageBytes(this NSData data) + return Task.FromResult(result); + } + + public Task CaptureAsync(CALayer layer, bool skipChildren) { - try - { - var result = new byte[data.Length]; - Marshal.Copy(data.Bytes, result, 0, (int)data.Length); - return result; - } - finally + _ = layer ?? throw new ArgumentNullException(nameof(layer)); + + // NOTE: We rely on the layer frame having been set to the correct size when this method is invoked. + UIGraphics.BeginImageContextWithOptions(layer.Bounds.Size, false, layer.RasterizationScale); + var ctx = UIGraphics.GetCurrentContext(); + + // ctx will be null if the width/height of the view is zero + if (ctx != null) { - data.Dispose(); + if (!TryRender(layer, ctx, skipChildren, out var error)) + { + // FIXME: test/handle this case + } } + + var image = UIGraphics.GetImageFromCurrentImageContext(); + UIGraphics.EndImageContext(); + + var result = new ScreenshotResult(image); + + return Task.FromResult(result); } - internal static bool TryRender(UIView view, CGContext ctx, ref Exception error) + static bool TryRender(UIView view, out Exception? error) { try { view.DrawViewHierarchy(view.Bounds, afterScreenUpdates: true); + + error = null; return true; } catch (Exception e) @@ -128,16 +131,18 @@ internal static bool TryRender(UIView view, CGContext ctx, ref Exception error) } } - internal static bool TryRender(CALayer layer, CGContext ctx, bool skipChildren, ref Exception error) + static bool TryRender(CALayer layer, CGContext ctx, bool skipChildren, out Exception? error) { + var visibilitySnapshot = new Dictionary(); + try { - Dictionary visibilitySnapshot = null; if (skipChildren) - visibilitySnapshot = GetVisibilitySnapshotAndHideLayers(layer); + HideSublayers(layer, visibilitySnapshot); + layer.RenderInContext(ctx); - if (skipChildren) - ResetLayerVisibilitiesFromSnapshot(layer, visibilitySnapshot); + + error = null; return true; } catch (Exception e) @@ -145,222 +150,153 @@ internal static bool TryRender(CALayer layer, CGContext ctx, bool skipChildren, error = e; return false; } + finally + { + if (skipChildren) + RestoreSublayers(layer, visibilitySnapshot); + } } - static Dictionary GetVisibilitySnapshotAndHideLayers(CALayer layer) + static void HideSublayers(CALayer layer, Dictionary visibilitySnapshot) { - var visibilitySnapshot = new Dictionary(); if (layer.Sublayers == null) - return visibilitySnapshot; + return; + foreach (var sublayer in layer.Sublayers) { - var subSnapshot = GetVisibilitySnapshotAndHideLayers(sublayer); - foreach (var kvp in subSnapshot) - visibilitySnapshot.Add(kvp.Key, kvp.Value); - visibilitySnapshot.Add(sublayer.Handle, sublayer.Hidden); + HideSublayers(sublayer, visibilitySnapshot); + + visibilitySnapshot.Add(sublayer, sublayer.Hidden); sublayer.Hidden = true; } - return visibilitySnapshot; } - static void ResetLayerVisibilitiesFromSnapshot( - CALayer layer, - Dictionary visibilitySnapshot) + static void RestoreSublayers(CALayer layer, Dictionary visibilitySnapshot) { if (layer.Sublayers == null) return; - foreach (var sublayer in layer.Sublayers) + + foreach (var sublayer in visibilitySnapshot) { - ResetLayerVisibilitiesFromSnapshot(sublayer, visibilitySnapshot); - if (visibilitySnapshot != null) - sublayer.Hidden = visibilitySnapshot[sublayer.Handle]; + sublayer.Key.Hidden = sublayer.Value; } } - static void TryHideStatusClockView(this UIApplication app) + static void TryHideStatusClockView(UIApplication app) { - var statusBarWindow = app.GetStatusBarWindow(); + var statusBarWindow = GetStatusBarWindow(app); if (statusBarWindow == null) return; - var clockView = statusBarWindow.FindSubview( - "UIStatusBar", - "UIStatusBarForegroundView", - "UIStatusBarTimeItemView" - ); - + var clockView = GetClockView(statusBarWindow); if (clockView != null) clockView.Hidden = true; } - static UIWindow GetStatusBarWindow(this UIApplication app) + static UIView? GetClockView(UIWindow window) { - if (!bool_objc_msgSend_IntPtr(app.Handle, - Selectors.respondsToSelector.Handle, - Selectors.statusBarWindow.Handle)) - return null; - - var ptr = IntPtr_objc_msgSend(app.Handle, Selectors.statusBarWindow.Handle); - return ptr != IntPtr.Zero ? ObjCRuntime.Runtime.GetNSObject(ptr) as UIWindow : null; - } - - static class Selectors - { - public static readonly Selector statusBarWindow = new Selector("statusBarWindow"); - public static readonly Selector respondsToSelector = new Selector("respondsToSelector:"); - } + var classNames = new[] { + "UIStatusBar", + "UIStatusBarForegroundView", + "UIStatusBarTimeItemView" + }; - static UIView FindSubview(this UIView view, params string[] classNames) - { - return FindSubview(view, ((IEnumerable)classNames).GetEnumerator()); - } + return FindSubview(window, ((IEnumerable)classNames).GetEnumerator()); - static UIView FindSubview(UIView view, IEnumerator classNames) - { - if (!classNames.MoveNext()) - return view; - - foreach (var subview in view.Subviews) + static UIView? FindSubview(UIView view, IEnumerator classNames) { - if (subview.ToString().StartsWith("<" + classNames.Current + ":", StringComparison.Ordinal)) - return FindSubview(subview, classNames); - } - - return null; - } - } + if (!classNames.MoveNext()) + return view; - public static class ScreenshotExtensions - { - const int PixelDataOffset = 54; - - public static byte[] AsBMP (this UIImage image) - { - var cgimage = image.CGImage; - var width = cgimage.Width; - var height = cgimage.Height; - - var data = InitializeByteArray(width, height); - var colorSpace = CGColorSpace.CreateDeviceRGB(); - var rawData = Marshal.AllocHGlobal(height * width * 4); - var context = new CGBitmapContext( - rawData, width, height, 8, 4 * width, colorSpace, CGImageAlphaInfo.PremultipliedLast - ); - context.DrawImage(new CGRect(0.0f, 0.0f, (float)width, (float)height), cgimage); - byte[] pixelData = new byte[height * width * 4]; - Marshal.Copy(rawData, pixelData, 0, pixelData.Length); - Marshal.FreeHGlobal(rawData); - - nint di = PixelDataOffset; - nint si; - for (int y = 0; y < height; y++) - { - si = (height - y - 1) * 4 * width; - for (int x = 0; x < width; x++) + foreach (var subview in view.Subviews) { - pixelData.CopyFlipPixel(si, data, di); - di += 4; - si += 4; + if (subview.ToString().StartsWith($"<{classNames.Current}:", StringComparison.Ordinal)) + return FindSubview(subview, classNames); } + + return null; } - return data; } - private static void CopyFlipPixel(this byte[] source, nint sourceOffset, byte[] destination, nint destinationOffset) + static UIWindow? GetStatusBarWindow(UIApplication app) { - nint S = sourceOffset; - nint D = destinationOffset + 2; - destination[D--] = source[S++]; - destination[D--] = source[S++]; - destination[D--] = source[S++]; - destination[destinationOffset + 3] = source[S]; - } + if (!app.RespondsToSelector(statusBarWindowSelector)) + return null; - static byte[] InitializeByteArray(nint width, nint height) - { - var rawPixelDataSize = width * height * 4; - var size = rawPixelDataSize + 14 + 40; - var data = new byte[size]; - data[0] = 0x42; - data[1] = 0x4D; - data.SetLong(0x2, size); - data.SetLong(0xA, PixelDataOffset); - data.SetLong(0xE, 40); - data.SetLong(0x12, width); - data.SetLong(0x16, height); - data.SetShort(0x1A, 1); - data.SetShort(0x1C, 32); - data.SetLong(0x22, rawPixelDataSize); - data.SetLong(0x26, 2835); - data.SetLong(0x2A, 2835); - - return data; + var ptr = IntPtr_objc_msgSend(app.Handle, statusBarWindowSelector.Handle); + return ptr != IntPtr.Zero ? Runtime.GetNSObject(ptr) as UIWindow : null; } - static void SetShort(this byte[] data, int offset, nint value) - { - var byts = BitConverter.GetBytes(value); - if (!BitConverter.IsLittleEndian) - Array.Reverse(byts); - Array.Copy(byts, 0, data, offset, byts.Length); - } + static readonly Selector statusBarWindowSelector = new Selector("statusBarWindow"); - static void SetLong(this byte[] data, nint offset, nint value) - { - var byts = BitConverter.GetBytes(value); - if (!BitConverter.IsLittleEndian) - Array.Reverse(byts); - Array.Copy(byts, 0, data, offset, byts.Length); - } + [DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSend")] + static extern IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector); } -} -namespace Microsoft.Maui.Media -{ - public partial class ScreenshotImplementation : IScreenshot + partial class ScreenshotResult { - public bool IsCaptureSupported => - true; + readonly UIImage bmp; - public Task CaptureAsync() + internal ScreenshotResult(UIImage bmp) + : base() { - var scenes = UIApplication.SharedApplication.ConnectedScenes; - var currentScene = scenes.ToArray().Where(n => n.ActivationState == UISceneActivationState.ForegroundActive).FirstOrDefault(); - if (currentScene == null) - throw new InvalidOperationException("Unable to find current scene."); + this.bmp = bmp; - var uiWindowScene = currentScene as UIWindowScene; - if (uiWindowScene == null) - throw new InvalidOperationException("Unable to find current uiwindow scene."); + Width = (int)bmp.Size.Width; + Height = (int)bmp.Size.Height; + } - var currentWindow = uiWindowScene.Windows.FirstOrDefault(n => n.IsKeyWindow); - if (currentWindow == null) - throw new InvalidOperationException("Unable to find current window."); + Task PlatformOpenReadAsync(ScreenshotFormat format, int quality) + { + var data = format switch + { + ScreenshotFormat.Png => bmp.AsPNG(), + ScreenshotFormat.Jpeg => bmp.AsJPEG(quality / 100.0f), + _ => throw new ArgumentOutOfRangeException(nameof(format)) + }; - var image = currentWindow.Render(currentWindow.Layer, UIScreen.MainScreen.Scale); - var result = new ScreenshotResult(image); + var result = data.AsStream(); - return Task.FromResult(result); + return Task.FromResult(result); } - } - internal partial class ScreenshotResult - { - readonly UIImage bmp; - - internal ScreenshotResult(UIImage bmp) - : base() + Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) { - this.bmp = bmp; + using var data = format switch + { + ScreenshotFormat.Png => bmp.AsPNG(), + ScreenshotFormat.Jpeg => bmp.AsJPEG(quality / 100.0f), + _ => throw new ArgumentOutOfRangeException(nameof(format)) + }; - Width = (int)bmp.Size.Width; - Height = (int)bmp.Size.Height; + using var result = data.AsStream(); + + result.CopyTo(destination); + + return Task.CompletedTask; } - internal Task PlatformOpenReadAsync(ScreenshotFormat format) + Task PlatformToPixelBufferAsync() { - var data = format == ScreenshotFormat.Png ? bmp.RenderAsPng() : bmp.RenderAsJpeg(); - return Task.FromResult(new MemoryStream(data) as Stream); + var cgimage = bmp.CGImage!; + var width = cgimage.Width; + var height = cgimage.Height; + + var pixelData = new byte[height * width * 4]; + var gchandle = GCHandle.Alloc(pixelData, GCHandleType.Pinned); + var data = gchandle.AddrOfPinnedObject(); + try + { + var colorSpace = CGColorSpace.CreateDeviceRGB(); + var context = new CGBitmapContext(data, width, height, 8, 4 * width, colorSpace, CGImageAlphaInfo.PremultipliedLast); + context.DrawImage(new CGRect(0, 0, width, height), cgimage); + } + finally + { + gchandle.Free(); + } + + return Task.FromResult(pixelData); } } } diff --git a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs index 5831013e8680..3643022f8ae4 100644 --- a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs +++ b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs @@ -12,7 +12,7 @@ public Task CaptureAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; } - internal partial class ScreenshotResult + partial class ScreenshotResult { ScreenshotResult() { diff --git a/src/Essentials/src/Screenshot/Screenshot.shared.cs b/src/Essentials/src/Screenshot/Screenshot.shared.cs index f26909ff1c3f..ff855ffe4717 100644 --- a/src/Essentials/src/Screenshot/Screenshot.shared.cs +++ b/src/Essentials/src/Screenshot/Screenshot.shared.cs @@ -1,6 +1,5 @@ #nullable enable - -using System.ComponentModel; +using System; using System.IO; using System.Threading.Tasks; @@ -13,6 +12,19 @@ public interface IScreenshot Task CaptureAsync(); } + public interface IPlatformScreenshot : IScreenshot + { +#if ANDROID + Task CaptureAsync(Android.Views.View view); +#elif IOS || MACCATALYST + Task CaptureAsync(UIKit.UIWindow window); + Task CaptureAsync(UIKit.UIView view); + Task CaptureAsync(CoreAnimation.CALayer layer, bool skipChildren); +#elif WINDOWS + Task CaptureAsync(UI.Xaml.UIElement element); +#endif + } + /// public interface IScreenshotResult { @@ -23,34 +35,67 @@ public interface IScreenshotResult int Height { get; } /// - Task OpenReadAsync(ScreenshotFormat format = ScreenshotFormat.Png); + Task OpenReadAsync(ScreenshotFormat format = ScreenshotFormat.Png, int quality = 100); + + /// + Task CopyToAsync(Stream destination, ScreenshotFormat format = ScreenshotFormat.Png, int quality = 100); + + /// + Task ToPixelBufferAsync(); } - /// - public static partial class Screenshot + public static class Screenshot { - /// - public static bool IsCaptureSupported - => Current.IsCaptureSupported; + static IScreenshot? currentImplementation; - /// - public static Task CaptureAsync() + public static IScreenshot Current => + currentImplementation ??= new ScreenshotImplementation(); + + internal static void SetCurrent(IScreenshot? implementation) => + currentImplementation = implementation; + } + + public static class ScreenshotExtensions + { +#if ANDROID + public static Task CaptureAsync(this IScreenshot screenshot, Android.Views.View view) { - if (!IsCaptureSupported) - throw new FeatureNotSupportedException(); + if (screenshot is not IPlatformScreenshot platform) + throw new PlatformNotSupportedException("This implementation of IScreenshot does not implement IPlatformScreenshot."); - return Current.CaptureAsync(); + return platform.CaptureAsync(view); } +#elif IOS || MACCATALYST + public static Task CaptureAsync(this IScreenshot screenshot, UIKit.UIWindow window) + { + if (screenshot is not IPlatformScreenshot platform) + throw new PlatformNotSupportedException("This implementation of IScreenshot does not implement IPlatformScreenshot."); - static IScreenshot? currentImplementation; + return platform.CaptureAsync(window); + } + public static Task CaptureAsync(this IScreenshot screenshot, UIKit.UIView view) + { + if (screenshot is not IPlatformScreenshot platform) + throw new PlatformNotSupportedException("This implementation of IScreenshot does not implement IPlatformScreenshot."); - [EditorBrowsable(EditorBrowsableState.Never)] - public static IScreenshot Current => - currentImplementation ??= new ScreenshotImplementation(); + return platform.CaptureAsync(view); + } + public static Task CaptureAsync(this IScreenshot screenshot, CoreAnimation.CALayer layer, bool skipChildren) + { + if (screenshot is not IPlatformScreenshot platform) + throw new PlatformNotSupportedException("This implementation of IScreenshot does not implement IPlatformScreenshot."); - [EditorBrowsable(EditorBrowsableState.Never)] - public static void SetCurrent(IScreenshot? implementation) => - currentImplementation = implementation; + return platform.CaptureAsync(layer, skipChildren); + } +#elif WINDOWS + public static Task CaptureAsync(this IScreenshot screenshot, UI.Xaml.UIElement element) + { + if (screenshot is not IPlatformScreenshot platform) + throw new PlatformNotSupportedException("This implementation of IScreenshot does not implement IPlatformScreenshot."); + + return platform.CaptureAsync(element); + } +#endif } /// @@ -61,17 +106,20 @@ public enum ScreenshotFormat /// Jpeg } -} -namespace Microsoft.Maui.Media -{ - internal partial class ScreenshotResult : IScreenshotResult + partial class ScreenshotResult : IScreenshotResult { public int Width { get; } - + public int Height { get; } - public Task OpenReadAsync(ScreenshotFormat format = ScreenshotFormat.Png) - => PlatformOpenReadAsync(format); + public Task OpenReadAsync(ScreenshotFormat format = ScreenshotFormat.Png, int quality = 100) + => PlatformOpenReadAsync(format, quality); + + public Task CopyToAsync(Stream destination, ScreenshotFormat format = ScreenshotFormat.Png, int quality = 100) + => PlatformCopyToAsync(destination, format, quality); + + public Task ToPixelBufferAsync() + => PlatformToPixelBufferAsync(); } } diff --git a/src/Essentials/src/Screenshot/Screenshot.tvos.cs b/src/Essentials/src/Screenshot/Screenshot.tvos.cs index a0854757bcbf..fbd6e806307e 100644 --- a/src/Essentials/src/Screenshot/Screenshot.tvos.cs +++ b/src/Essentials/src/Screenshot/Screenshot.tvos.cs @@ -18,11 +18,8 @@ public Task CaptureAsync() return Task.FromResult(result); } } -} -namespace Microsoft.Maui.Media -{ - internal partial class ScreenshotResult + partial class ScreenshotResult { readonly UIImage uiImage; diff --git a/src/Essentials/src/Screenshot/Screenshot.uwp.cs b/src/Essentials/src/Screenshot/Screenshot.uwp.cs index 9d90d43a0c83..4544ec0eb995 100644 --- a/src/Essentials/src/Screenshot/Screenshot.uwp.cs +++ b/src/Essentials/src/Screenshot/Screenshot.uwp.cs @@ -14,90 +14,40 @@ namespace Microsoft.Maui.Media { - public static partial class Screenshot - { - public static async Task RenderAsync(this FrameworkElement element) - { - var bitmap = new RenderTargetBitmap(); - await bitmap.RenderAsync(element); - return bitmap; - } - - public static async Task RenderAsJPEGAsync(this FrameworkElement element) - { - using var memoryStream = new InMemoryRandomAccessStream(); - BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, memoryStream); - return await element.RenderAsImageAsync(enc, memoryStream); - } - - public static async Task RenderAsPNGAsync(this FrameworkElement element) - { - using var memoryStream = new InMemoryRandomAccessStream(); - BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, memoryStream); - return await element.RenderAsImageAsync(enc, memoryStream); - } - - public static async Task RenderAsBMPAsync(this FrameworkElement element) - { - using var memoryStream = new InMemoryRandomAccessStream(); - BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, memoryStream); - return await element.RenderAsImageAsync(enc, memoryStream); - } - - public static async Task RenderAsImageAsync(this FrameworkElement element, BitmapEncoder enc, IRandomAccessStream memoryStream) - { - var bitmap = await element.RenderAsync(); - var pixels = await bitmap.AsPixelsAsync(); - return await bitmap.AsImageBytesAsync(pixels, enc, memoryStream); - } - - public static async Task AsPixelsAsync(this RenderTargetBitmap bitmap) => - await bitmap.GetPixelsAsync().AsTask().ConfigureAwait(false); - - - public static async Task AsImageBytesAsync(this RenderTargetBitmap bitmap, IBuffer pixelBuffer, BitmapEncoder enc, IRandomAccessStream memoryStream) - { - var alphaMode = enc.EncoderInformation.CodecId == BitmapEncoder.JpegEncoderId ? BitmapAlphaMode.Ignore : BitmapAlphaMode.Premultiplied; - enc.SetPixelData(BitmapPixelFormat.Bgra8, alphaMode, (uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight, 1, 1, pixelBuffer.ToArray()); - await enc.FlushAsync(); - await memoryStream.FlushAsync(); - var stream = memoryStream.AsStream(); - byte[] result = new byte[stream.Length]; - stream.Read(result, 0, result.Length); - return result; - } - } -} - -namespace Microsoft.Maui.Media -{ - public partial class ScreenshotImplementation : IScreenshot + public partial class ScreenshotImplementation : IPlatformScreenshot, IScreenshot { public bool IsCaptureSupported => true; - public async Task CaptureAsync() + public Task CaptureAsync() { - var element = Window.Current?.Content as FrameworkElement; + var element = Window.Current?.Content; if (element == null) throw new InvalidOperationException("Unable to find main window content."); + return CaptureAsync(element); + } + + public async Task CaptureAsync(UIElement element) + { + var bmp = new RenderTargetBitmap(); + // NOTE: Return to the main thread so we can access view properties such as // width and height. Do not ConfigureAwait! - var bmp = await element.RenderAsync(); + await bmp.RenderAsync(element); // get the view information first var width = bmp.PixelWidth; var height = bmp.PixelHeight; // then potentially move to a different thread - var pixels = await bmp.AsPixelsAsync(); + var pixels = await bmp.GetPixelsAsync().AsTask().ConfigureAwait(false); return new ScreenshotResult(width, height, pixels); } } - internal partial class ScreenshotResult + partial class ScreenshotResult { readonly byte[] bytes; @@ -108,21 +58,37 @@ public ScreenshotResult(int width, int height, IBuffer pixels) bytes = pixels?.ToArray() ?? throw new ArgumentNullException(nameof(pixels)); } - internal async Task PlatformOpenReadAsync(ScreenshotFormat format) + async Task PlatformOpenReadAsync(ScreenshotFormat format, int quality) { - var f = format switch - { - ScreenshotFormat.Jpeg => BitmapEncoder.JpegEncoderId, - _ => BitmapEncoder.PngEncoderId - }; - var ms = new InMemoryRandomAccessStream(); + await EncodeAsync(format, ms).ConfigureAwait(false); + return ms.AsStreamForRead(); + } + + Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) + { + var ms = destination.AsRandomAccessStream(); + return EncodeAsync(format, ms); + } + + Task PlatformToPixelBufferAsync() => + Task.FromResult(bytes); + + async Task EncodeAsync(ScreenshotFormat format, IRandomAccessStream ms) + { + var f = ToBitmapEncoder(format); var encoder = await BitmapEncoder.CreateAsync(f, ms).AsTask().ConfigureAwait(false); encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)Width, (uint)Height, 96, 96, bytes); await encoder.FlushAsync().AsTask().ConfigureAwait(false); - - return ms.AsStreamForRead(); } + + static Guid ToBitmapEncoder(ScreenshotFormat format) => + format switch + { + ScreenshotFormat.Jpeg => BitmapEncoder.JpegEncoderId, + ScreenshotFormat.Png => BitmapEncoder.PngEncoderId, + _ => throw new ArgumentOutOfRangeException(nameof(format)) + }; } } From 736de5c70cb1b26e4bc8e2901ba6cbda720e48ba Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Wed, 23 Mar 2022 05:14:03 +0200 Subject: [PATCH 09/45] near the end --- .../Core/src/Essentials/SecureStorage.cs | 39 +++++++ .../src/Essentials/SemanticScreenReader.cs | 15 +++ .../Core/src/Essentials/Share.cs | 32 ++++++ .../src/AppActions/AppActions.shared.cs | 3 +- .../SecureStorage/SecureStorage.android.cs | 33 +++--- .../SecureStorage.ios.tvos.watchos.macos.cs | 4 - .../SecureStorage.netstandard.cs | 1 - .../src/SecureStorage/SecureStorage.shared.cs | 102 +++++------------- .../SemanticScreenReader.shared.cs | 22 ++-- .../SemanticScreenReader.uwp.cs | 6 +- src/Essentials/src/Share/Share.android.cs | 18 ++-- src/Essentials/src/Share/Share.ios.cs | 9 +- src/Essentials/src/Share/Share.macos.cs | 9 +- .../Share/Share.netstandard.tvos.watchos.cs | 10 +- src/Essentials/src/Share/Share.shared.cs | 98 +++++++++-------- src/Essentials/src/Share/Share.tizen.cs | 9 +- src/Essentials/src/Share/Share.uwp.cs | 9 +- 17 files changed, 226 insertions(+), 193 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/SecureStorage.cs create mode 100644 src/Compatibility/Core/src/Essentials/SemanticScreenReader.cs create mode 100644 src/Compatibility/Core/src/Essentials/Share.cs diff --git a/src/Compatibility/Core/src/Essentials/SecureStorage.cs b/src/Compatibility/Core/src/Essentials/SecureStorage.cs new file mode 100644 index 000000000000..7f2886dbebcb --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/SecureStorage.cs @@ -0,0 +1,39 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.Storage; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class SecureStorage + { + /// + public static Task GetAsync(string key) => + Current.GetAsync(key); + + /// + public static Task SetAsync(string key, string value) => + Current.SetAsync(key, value); + + /// + public static bool Remove(string key) => + Current.Remove(key); + + /// + public static void RemoveAll() => + Current.RemoveAll(); + +#if IOS || MACCATALYST || MACOS || TVOS || WATCHOS + public static Security.SecAccessible DefaultAccessible + { + get => Current.GetDefaultAccessible(); + set => Current.SetDefaultAccessible(value); + } + + public static Task SetAsync(string key, string value, Security.SecAccessible accessible) => + Current.SetAsync(key, value, accessible); +#endif + + static ISecureStorage Current => Storage.SecureStorage.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/SemanticScreenReader.cs b/src/Compatibility/Core/src/Essentials/SemanticScreenReader.cs new file mode 100644 index 000000000000..d5e0298e423a --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/SemanticScreenReader.cs @@ -0,0 +1,15 @@ +#nullable enable +using Microsoft.Maui.Accessibility; + +namespace Microsoft.Maui.Essentials +{ + public static partial class SemanticScreenReader + { + public static void Announce(string text) + { + Current.Announce(text); + } + + static ISemanticScreenReader Current => Accessibility.SemanticScreenReader.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Share.cs b/src/Compatibility/Core/src/Essentials/Share.cs new file mode 100644 index 000000000000..224b6e93e46f --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Share.cs @@ -0,0 +1,32 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel.DataTransfer; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class Share + { + /// + public static Task RequestAsync(string text) => + Current.RequestAsync(text); + + /// + public static Task RequestAsync(string text, string title) => + Current.RequestAsync(text, title); + + /// + public static Task RequestAsync(ShareTextRequest request) => + Current.RequestAsync(request); + + /// + public static Task RequestAsync(ShareFileRequest request) => + Current.RequestAsync(request); + + /// + public static Task RequestAsync(ShareMultipleFilesRequest request) => + Current.RequestAsync(request); + + static IShare Current => ApplicationModel.DataTransfer.Share.Default; + } +} diff --git a/src/Essentials/src/AppActions/AppActions.shared.cs b/src/Essentials/src/AppActions/AppActions.shared.cs index 99076fd7ab5f..4af709ca325b 100755 --- a/src/Essentials/src/AppActions/AppActions.shared.cs +++ b/src/Essentials/src/AppActions/AppActions.shared.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.UI.Xaml; namespace Microsoft.Maui.ApplicationModel { @@ -21,7 +20,7 @@ public interface IAppActions public interface IPlatformAppActions { #if WINDOWS - Task OnLaunched(LaunchActivatedEventArgs e); + Task OnLaunched(UI.Xaml.LaunchActivatedEventArgs e); #elif IOS || MACCATALYST void PerformActionForShortcutItem(UIKit.UIApplication application, UIKit.UIApplicationShortcutItem shortcutItem, UIKit.UIOperationHandler completionHandler); #elif ANDROID diff --git a/src/Essentials/src/SecureStorage/SecureStorage.android.cs b/src/Essentials/src/SecureStorage/SecureStorage.android.cs index 09f6bdee3ae7..7e221c874b4c 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.android.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.android.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Storage { partial class SecureStorageImplementation : ISecureStorage { - static readonly object locker = new object(); + readonly object locker = new object(); Task PlatformGetAsync(string key) { @@ -44,18 +44,14 @@ Task PlatformSetAsync(string key, string data) { lock (locker) { - using (var editor = GetEncryptedSharedPreferences().Edit()) - { - if (data == null) - { - editor.Remove(key); - } - else - { - editor.PutString(key, data); - } - editor.Apply(); - } + using var editor = GetEncryptedSharedPreferences().Edit(); + + if (data == null) + editor.Remove(key); + else + editor.PutString(key, data); + + editor.Apply(); } }); } @@ -77,14 +73,12 @@ void PlatformRemoveAll() { lock (locker) { - using (var editor = PreferencesImplementation.GetSharedPreferences(Alias).Edit()) - { - editor.Clear().Apply(); - } + using var editor = PreferencesImplementation.GetSharedPreferences(Alias).Edit(); + editor.Clear().Apply(); } } - ISharedPreferences GetEncryptedSharedPreferences() + static ISharedPreferences GetEncryptedSharedPreferences() { var context = Application.Context; @@ -97,8 +91,7 @@ ISharedPreferences GetEncryptedSharedPreferences() Alias, prefsMainKey, EncryptedSharedPreferences.PrefKeyEncryptionScheme.Aes256Siv, - EncryptedSharedPreferences.PrefValueEncryptionScheme.Aes256Gcm - ); + EncryptedSharedPreferences.PrefValueEncryptionScheme.Aes256Gcm); return sharedPreferences; } diff --git a/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs b/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs index add165ab5427..7d300cf1c879 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.ios.tvos.watchos.macos.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.Threading.Tasks; - using Foundation; using Security; @@ -15,7 +14,6 @@ public Task SetAsync(string key, string value, SecAccessible accessible) { if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key)); - if (value == null) throw new ArgumentNullException(nameof(value)); @@ -39,14 +37,12 @@ Task PlatformSetAsync(string key, string data) => bool PlatformRemove(string key) { var kc = new KeyChain(DefaultAccessible); - return kc.Remove(key, Alias); } void PlatformRemoveAll() { var kc = new KeyChain(DefaultAccessible); - kc.RemoveAll(Alias); } } diff --git a/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs b/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs index 189601d14285..6652e69802b9 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.netstandard.cs @@ -2,7 +2,6 @@ namespace Microsoft.Maui.Storage { - /// partial class SecureStorageImplementation : ISecureStorage { Task PlatformGetAsync(string key) => diff --git a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs index 4aed6567f1cd..e3b95b1aeeb3 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs @@ -1,16 +1,17 @@ #nullable enable using System; -using System.ComponentModel; using System.Threading.Tasks; -using Microsoft.Maui.Storage; namespace Microsoft.Maui.Storage { public interface ISecureStorage { Task GetAsync(string key); + Task SetAsync(string key, string value); + bool Remove(string key); + void RemoveAll(); } @@ -18,100 +19,59 @@ public interface IPlatformSecureStorage { #if IOS || MACCATALYST || MACOS || TVOS || WATCHOS Security.SecAccessible DefaultAccessible { get; set; } + Task SetAsync(string key, string value, Security.SecAccessible accessible); #endif } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static partial class SecureStorage { - /// - public static Task GetAsync(string key) - { - if (string.IsNullOrWhiteSpace(key)) - throw new ArgumentNullException(nameof(key)); + static ISecureStorage? defaultImplementation; - return Current.GetAsync(key); - } + public static ISecureStorage Default => + defaultImplementation ??= new SecureStorageImplementation(); - /// - public static Task SetAsync(string key, string value) + internal static void SetDefault(ISecureStorage? implementation) { - if (string.IsNullOrWhiteSpace(key)) - throw new ArgumentNullException(nameof(key)); - - if (value == null) - throw new ArgumentNullException(nameof(value)); - - return Current.SetAsync(key, value); + defaultImplementation = implementation; } + } - /// - public static bool Remove(string key) - => Current.Remove(key); - - /// - public static void RemoveAll() - => Current.RemoveAll(); - + public static class SecureStorageExtensions + { #if IOS || MACCATALYST || MACOS || TVOS || WATCHOS - public static Security.SecAccessible DefaultAccessible + public static Security.SecAccessible GetDefaultAccessible(this ISecureStorage secureStorage) { - get - { - if (Current is IPlatformSecureStorage p) - { - return p.DefaultAccessible; - } - - throw new NotImplementedException(); - } - set - { - if (Current is IPlatformSecureStorage p) - { - p.DefaultAccessible = value; - } - - throw new NotImplementedException(); - } - } + if (secureStorage is not IPlatformSecureStorage platform) + throw new PlatformNotSupportedException("This implementation of ISecureStorage does not implement IPlatformSecureStorage."); - public static Task SetAsync(string key, string value, Security.SecAccessible accessible) + return platform.DefaultAccessible; + } + public static void SetDefaultAccessible(this ISecureStorage secureStorage, Security.SecAccessible accessible) { - if (Current is IPlatformSecureStorage p) - { - return p.SetAsync(key, value, accessible); - } + if (secureStorage is not IPlatformSecureStorage platform) + throw new PlatformNotSupportedException("This implementation of ISecureStorage does not implement IPlatformSecureStorage."); - throw new NotImplementedException(); + platform.DefaultAccessible = accessible; } -#endif - static ISecureStorage? currentImplementation; - - public static ISecureStorage Current => - currentImplementation ??= new SecureStorageImplementation(); - - internal static void SetCurrent(ISecureStorage? implementation) + public static Task SetAsync(this ISecureStorage secureStorage, string key, string value, Security.SecAccessible accessible) { - currentImplementation = implementation; + if (secureStorage is not IPlatformSecureStorage platform) + throw new PlatformNotSupportedException("This implementation of ISecureStorage does not implement IPlatformSecureStorage."); + + return platform.SetAsync(key, value, accessible); } +#endif } -} -namespace Microsoft.Maui.Storage -{ partial class SecureStorageImplementation { #if !NETSTANDARD // Special Alias that is only used for Secure Storage. All others should use: Preferences.GetPrivatePreferencesSharedName - internal static readonly string Alias = Preferences.GetPrivatePreferencesSharedName("preferences"); + static readonly string Alias = Preferences.GetPrivatePreferencesSharedName("preferences"); #endif - /// public Task GetAsync(string key) { if (string.IsNullOrWhiteSpace(key)) @@ -120,7 +80,6 @@ public Task GetAsync(string key) return PlatformGetAsync(key); } - /// public Task SetAsync(string key, string value) { if (string.IsNullOrWhiteSpace(key)) @@ -132,13 +91,10 @@ public Task SetAsync(string key, string value) return PlatformSetAsync(key, value); } - /// public bool Remove(string key) => PlatformRemove(key); - /// public void RemoveAll() => PlatformRemoveAll(); - } } diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs index 09e46a388462..a9afe5e9fc61 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs @@ -1,7 +1,4 @@ #nullable enable -using System.ComponentModel; -using System.Threading.Tasks; -using Microsoft.Maui.Accessibility; namespace Microsoft.Maui.Accessibility { @@ -9,22 +6,15 @@ public interface ISemanticScreenReader { void Announce(string text); } -} -namespace Microsoft.Maui.Essentials -{ + public static partial class SemanticScreenReader { - public static void Announce(string text) - { - Current.Announce(text); - } - - static ISemanticScreenReader? currentImplementation; + static ISemanticScreenReader? defaultImplementation; - public static ISemanticScreenReader Current => - currentImplementation ??= new SemanticScreenReaderImplementation(); + public static ISemanticScreenReader Default => + defaultImplementation ??= new SemanticScreenReaderImplementation(); - internal static void SetCurrent(ISemanticScreenReader? implementation) => - currentImplementation = implementation; + internal static void SetDefault(ISemanticScreenReader? implementation) => + defaultImplementation = implementation; } } diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs index cafb8d9a7fac..6dc950771489 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.uwp.cs @@ -10,8 +10,6 @@ using Microsoft.UI.Xaml.Media; #endif - - namespace Microsoft.Maui.Accessibility { partial class SemanticScreenReaderImplementation : ISemanticScreenReader @@ -34,8 +32,8 @@ public void Announce(string text) } // This isn't great but it's the only way I've found to announce with WinUI. - // You have to locate a control that has an automation peer and then use that - // to perform the announce operation. This creates scenarios where the + // You have to locate a control that has an automation peer and then use that + // to perform the announce operation. This creates scenarios where the // screen might not have any automation peers on it to use but in those cases // you really shouldn't be using the announce API static AutomationPeer FindAutomationPeer(DependencyObject depObj) diff --git a/src/Essentials/src/Share/Share.android.cs b/src/Essentials/src/Share/Share.android.cs index 61ee44fdf14a..d0eb8baf7864 100644 --- a/src/Essentials/src/Share/Share.android.cs +++ b/src/Essentials/src/Share/Share.android.cs @@ -1,14 +1,15 @@ using System.Collections.Generic; using System.Threading.Tasks; +using Android.App; using Android.Content; using Android.OS; using Microsoft.Maui.Storage; namespace Microsoft.Maui.ApplicationModel.DataTransfer { - class ShareImplementation : IShare + partial class ShareImplementation : IShare { - public Task RequestAsync(ShareTextRequest request) + Task PlatformRequestAsync(ShareTextRequest request) { var items = new List(); if (!string.IsNullOrWhiteSpace(request.Text)) @@ -22,7 +23,7 @@ public Task RequestAsync(ShareTextRequest request) } var intent = new Intent(Intent.ActionSend); - intent.SetType(FileSystem.MimeTypes.TextPlain); + intent.SetType(FileMimeTypes.TextPlain); intent.PutExtra(Intent.ExtraText, string.Join(System.Environment.NewLine, items)); if (!string.IsNullOrWhiteSpace(request.Subject)) @@ -33,12 +34,15 @@ public Task RequestAsync(ShareTextRequest request) var chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty); var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; chooserIntent.SetFlags(flags); - Platform.AppContext.StartActivity(chooserIntent); + Application.Context.StartActivity(chooserIntent); return Task.CompletedTask; } - public Task RequestAsync(ShareMultipleFilesRequest request) + Task PlatformRequestAsync(ShareFileRequest request) => + PlatformRequestAsync((ShareMultipleFilesRequest)request); + + Task PlatformRequestAsync(ShareMultipleFilesRequest request) { // load the data we need var contentUris = new List(request.Files.Count); @@ -50,7 +54,7 @@ public Task RequestAsync(ShareMultipleFilesRequest request) if (contentType == null) contentType = file.ContentType; else if (contentType != file.ContentType) - contentType = FileSystem.MimeTypes.All; + contentType = FileMimeTypes.All; } var intentType = contentUris.Count > 1 @@ -72,7 +76,7 @@ public Task RequestAsync(ShareMultipleFilesRequest request) var chooserIntent = Intent.CreateChooser(intent, request.Title ?? string.Empty); var flags = ActivityFlags.ClearTop | ActivityFlags.NewTask; chooserIntent.SetFlags(flags); - Platform.AppContext.StartActivity(chooserIntent); + Application.Context.StartActivity(chooserIntent); return Task.CompletedTask; } diff --git a/src/Essentials/src/Share/Share.ios.cs b/src/Essentials/src/Share/Share.ios.cs index 36ede0320bfc..ead417bdbfaa 100644 --- a/src/Essentials/src/Share/Share.ios.cs +++ b/src/Essentials/src/Share/Share.ios.cs @@ -9,9 +9,9 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer { - class ShareImplementation : IShare + partial class ShareImplementation : IShare { - public Task RequestAsync(ShareTextRequest request) + Task PlatformRequestAsync(ShareTextRequest request) { var items = new List(); if (!string.IsNullOrWhiteSpace(request.Text)) @@ -39,7 +39,10 @@ public Task RequestAsync(ShareTextRequest request) return vc.PresentViewControllerAsync(activityController, true); } - public Task RequestAsync(ShareMultipleFilesRequest request) + Task PlatformRequestAsync(ShareFileRequest request) => + PlatformRequestAsync((ShareMultipleFilesRequest)request); + + Task PlatformRequestAsync(ShareMultipleFilesRequest request) { var items = new List(); diff --git a/src/Essentials/src/Share/Share.macos.cs b/src/Essentials/src/Share/Share.macos.cs index 5e567533d07a..28a95f93c54e 100644 --- a/src/Essentials/src/Share/Share.macos.cs +++ b/src/Essentials/src/Share/Share.macos.cs @@ -6,9 +6,9 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer { - class ShareImplementation : IShare + partial class ShareImplementation : IShare { - public Task RequestAsync(ShareTextRequest request) + Task PlatformRequestAsync(ShareTextRequest request) { var items = new List(); if (!string.IsNullOrWhiteSpace(request.Title)) @@ -21,7 +21,10 @@ public Task RequestAsync(ShareTextRequest request) return PlatformShowRequestAsync(request, items); } - public Task RequestAsync(ShareMultipleFilesRequest request) + Task PlatformRequestAsync(ShareFileRequest request) => + PlatformRequestAsync((ShareMultipleFilesRequest)request); + + Task PlatformRequestAsync(ShareMultipleFilesRequest request) { var items = new List(); diff --git a/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs b/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs index 0fdc5530bd75..e2c1513c829f 100644 --- a/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs @@ -2,13 +2,15 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer { - /// - class ShareImplementation : IShare + partial class ShareImplementation : IShare { - public Task RequestAsync(ShareTextRequest request) => + Task PlatformRequestAsync(ShareTextRequest request) => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task RequestAsync(ShareMultipleFilesRequest request) => + Task PlatformRequestAsync(ShareFileRequest request) => + throw ExceptionUtils.NotSupportedOrImplementedException; + + Task PlatformRequestAsync(ShareMultipleFilesRequest request) => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Share/Share.shared.cs b/src/Essentials/src/Share/Share.shared.cs index 113e78d4f8e6..c16842045f8d 100644 --- a/src/Essentials/src/Share/Share.shared.cs +++ b/src/Essentials/src/Share/Share.shared.cs @@ -1,9 +1,8 @@ +#nullable enable using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.DataTransfer; using Microsoft.Maui.Graphics; using Microsoft.Maui.Storage; @@ -12,24 +11,26 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer public interface IShare { Task RequestAsync(ShareTextRequest request); + + Task RequestAsync(ShareFileRequest request); + Task RequestAsync(ShareMultipleFilesRequest request); } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Share + + public static class Share { - /// - public static Task RequestAsync(string text) => - RequestAsync(new ShareTextRequest(text)); + static IShare? defaultImplementation; - /// - public static Task RequestAsync(string text, string title) => - RequestAsync(new ShareTextRequest(text, title)); + public static IShare Default => + defaultImplementation ??= new ShareImplementation(); - /// - public static Task RequestAsync(ShareTextRequest request) + internal static void SetDefault(IShare? implementation) => + defaultImplementation = implementation; + } + + partial class ShareImplementation : IShare + { + public Task RequestAsync(ShareTextRequest request) { if (request == null) throw new ArgumentNullException(nameof(request)); @@ -37,11 +38,10 @@ public static Task RequestAsync(ShareTextRequest request) if (string.IsNullOrEmpty(request.Text) && string.IsNullOrEmpty(request.Uri)) throw new ArgumentException($"Both the {nameof(request.Text)} and {nameof(request.Uri)} are invalid. Make sure to include at least one of them in the request."); - return Current.RequestAsync(request); + return PlatformRequestAsync(request); } - /// - public static Task RequestAsync(ShareFileRequest request) + public Task RequestAsync(ShareFileRequest request) { if (request == null) throw new ArgumentNullException(nameof(request)); @@ -49,45 +49,41 @@ public static Task RequestAsync(ShareFileRequest request) if (request.File == null) throw new ArgumentException(FileNullExeption(nameof(request.File))); - return Current.RequestAsync((ShareMultipleFilesRequest)request); + return PlatformRequestAsync(request); } - /// - public static Task RequestAsync(ShareMultipleFilesRequest request) + public Task RequestAsync(ShareMultipleFilesRequest request) { if (request == null) throw new ArgumentNullException(nameof(request)); - if (!(request.Files?.Count() > 0)) + if (!(request.Files?.Count > 0)) throw new ArgumentException(FileNullExeption(nameof(request.Files))); if (request.Files.Any(file => file == null)) throw new ArgumentException(FileNullExeption(nameof(request.Files))); - return Current.RequestAsync(request); + return PlatformRequestAsync(request); } static string FileNullExeption(string file) => $"The {file} parameter in the request files is invalid"; + } -#nullable enable - static IShare? currentImplementation; - - public static IShare Current => - currentImplementation ??= new ShareImplementation(); + public static class ShareExtensions + { + public static Task RequestAsync(this IShare share, string text) => + share.RequestAsync(new ShareTextRequest(text)); - internal static void SetCurrent(IShare? implementation) => - currentImplementation = implementation; -#nullable disable + public static Task RequestAsync(this IShare share, string text, string title) => + share.RequestAsync(new ShareTextRequest(text, title)); } -} -namespace Microsoft.Maui.ApplicationModel.DataTransfer -{ + /// public abstract class ShareRequestBase { /// - public string Title { get; set; } + public string? Title { get; set; } /// public Rect PresentationSourceBounds { get; set; } = Rect.Zero; @@ -102,20 +98,21 @@ public ShareTextRequest() } /// - public ShareTextRequest(string text) => Text = text; + public ShareTextRequest(string text) => + Text = text; /// public ShareTextRequest(string text, string title) : this(text) => Title = title; - /// - public string Subject { get; set; } - /// - public string Text { get; set; } + public string? Text { get; set; } + + /// + public string? Subject { get; set; } /// - public string Uri { get; set; } + public string? Uri { get; set; } } /// @@ -149,7 +146,7 @@ public ShareFileRequest(FileBase file) => File = new ShareFile(file); /// - public ShareFile File { get; set; } + public ShareFile? File { get; set; } } /// @@ -181,17 +178,18 @@ public ShareMultipleFilesRequest(string title, IEnumerable files) } /// - public List Files { get; set; } + public List Files { get; } = new List(); - public static explicit operator ShareMultipleFilesRequest(ShareFileRequest request) - { - var requestFiles = new ShareMultipleFilesRequest(request.Title, new ShareFile[] { request.File }); - requestFiles.PresentationSourceBounds = request.PresentationSourceBounds; - return requestFiles; - } + public static explicit operator ShareMultipleFilesRequest(ShareFileRequest request) => + new ShareMultipleFilesRequest + { + Title = request.Title, + Files = { request.File! }, + PresentationSourceBounds = request.PresentationSourceBounds + }; static IEnumerable ConvertList(IEnumerable files) - => files?.Select(file => new ShareFile(file)); + => files?.Select(file => new ShareFile(file)) ?? Array.Empty(); } /// diff --git a/src/Essentials/src/Share/Share.tizen.cs b/src/Essentials/src/Share/Share.tizen.cs index afd3a52abd5f..0339307db87c 100644 --- a/src/Essentials/src/Share/Share.tizen.cs +++ b/src/Essentials/src/Share/Share.tizen.cs @@ -4,9 +4,9 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer { - class ShareImplementation : IShare + partial class ShareImplementation : IShare { - public Task RequestAsync(ShareTextRequest request) + Task PlatformRequestAsync(ShareTextRequest request) { Permissions.EnsureDeclared(); @@ -29,7 +29,10 @@ public Task RequestAsync(ShareTextRequest request) return Task.CompletedTask; } - public Task RequestAsync(ShareMultipleFilesRequest request) + Task PlatformRequestAsync(ShareFileRequest request) => + PlatformRequestAsync((ShareMultipleFilesRequest)request); + + Task PlatformRequestAsync(ShareMultipleFilesRequest request) { Permissions.EnsureDeclared(); diff --git a/src/Essentials/src/Share/Share.uwp.cs b/src/Essentials/src/Share/Share.uwp.cs index c30a2a14b388..27ebbca4c9da 100644 --- a/src/Essentials/src/Share/Share.uwp.cs +++ b/src/Essentials/src/Share/Share.uwp.cs @@ -8,9 +8,9 @@ namespace Microsoft.Maui.ApplicationModel.DataTransfer { - class ShareImplementation : IShare + partial class ShareImplementation : IShare { - public Task RequestAsync(ShareTextRequest request) + Task PlatformRequestAsync(ShareTextRequest request) { var hwnd = Platform.CurrentWindowHandle; var dataTransferManager = DataTransferManagerHelper.GetDataTransferManager(hwnd); @@ -41,7 +41,10 @@ void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e) return Task.CompletedTask; } - public async Task RequestAsync(ShareMultipleFilesRequest request) + Task PlatformRequestAsync(ShareFileRequest request) => + PlatformRequestAsync((ShareMultipleFilesRequest)request); + + async Task PlatformRequestAsync(ShareMultipleFilesRequest request) { var storageFiles = new List(); foreach (var file in request.Files) From 9bc09c23bddeeef3aa7551d8b53ac5e18910fa51 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Wed, 23 Mar 2022 05:58:29 +0200 Subject: [PATCH 10/45] sms --- src/Compatibility/Core/src/Essentials/Sms.cs | 20 +++++++++ src/Essentials/src/Share/Share.shared.cs | 4 +- src/Essentials/src/Sms/Sms.android.cs | 14 +++--- src/Essentials/src/Sms/Sms.ios.cs | 6 +-- src/Essentials/src/Sms/Sms.macos.cs | 6 +-- .../src/Sms/Sms.netstandard.tvos.watchos.cs | 6 +-- src/Essentials/src/Sms/Sms.shared.cs | 43 +++++++++---------- src/Essentials/src/Sms/Sms.tizen.cs | 6 +-- src/Essentials/src/Sms/Sms.uwp.cs | 6 +-- 9 files changed, 64 insertions(+), 47 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/Sms.cs diff --git a/src/Compatibility/Core/src/Essentials/Sms.cs b/src/Compatibility/Core/src/Essentials/Sms.cs new file mode 100644 index 000000000000..3cd31b897e0a --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Sms.cs @@ -0,0 +1,20 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel.Communication; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Sms + { + /// + public static Task ComposeAsync() + => Current.ComposeAsync(null); + + /// + public static Task ComposeAsync(SmsMessage? message) + => Current.ComposeAsync(message); + + static ISms Current => ApplicationModel.Communication.Sms.Default; + } +} diff --git a/src/Essentials/src/Share/Share.shared.cs b/src/Essentials/src/Share/Share.shared.cs index c16842045f8d..03d52e9e5ca2 100644 --- a/src/Essentials/src/Share/Share.shared.cs +++ b/src/Essentials/src/Share/Share.shared.cs @@ -178,13 +178,13 @@ public ShareMultipleFilesRequest(string title, IEnumerable files) } /// - public List Files { get; } = new List(); + public List? Files { get; set; } = new List(); public static explicit operator ShareMultipleFilesRequest(ShareFileRequest request) => new ShareMultipleFilesRequest { Title = request.Title, - Files = { request.File! }, + Files = new List { request.File! }, PresentationSourceBounds = request.PresentationSourceBounds }; diff --git a/src/Essentials/src/Sms/Sms.android.cs b/src/Essentials/src/Sms/Sms.android.cs index 8b699f4b4807..25355a43a261 100644 --- a/src/Essentials/src/Sms/Sms.android.cs +++ b/src/Essentials/src/Sms/Sms.android.cs @@ -1,22 +1,22 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Android.App; using Android.Content; -using Android.OS; using Android.Provider; using Microsoft.Maui.Storage; using AndroidUri = Android.Net.Uri; namespace Microsoft.Maui.ApplicationModel.Communication { - class SmsImplementation : ISms + partial class SmsImplementation : ISms { static readonly string smsRecipientSeparator = ";"; - internal static bool IsComposeSupported + public bool IsComposeSupported => Platform.IsIntentSupported(CreateIntent(null, new List { "0000000000" })); - public Task ComposeAsync(SmsMessage message) + Task PlatformComposeAsync(SmsMessage message) { var intent = CreateIntent(message?.Body, message?.Recipients); @@ -25,7 +25,7 @@ public Task ComposeAsync(SmsMessage message) flags |= ActivityFlags.LaunchAdjacent; intent.SetFlags(flags); - Platform.AppContext.StartActivity(intent); + Application.Context.StartActivity(intent); return Task.FromResult(true); } @@ -38,11 +38,11 @@ static Intent CreateIntent(string body, List recipients) if (recipients.All(x => string.IsNullOrWhiteSpace(x))) { - var packageName = Telephony.Sms.GetDefaultSmsPackage(Platform.AppContext); + var packageName = Telephony.Sms.GetDefaultSmsPackage(Application.Context); if (!string.IsNullOrWhiteSpace(packageName)) { intent = new Intent(Intent.ActionSend); - intent.SetType(FileSystem.MimeTypes.TextPlain); + intent.SetType(FileMimeTypes.TextPlain); intent.PutExtra(Intent.ExtraText, body); intent.SetPackage(packageName); diff --git a/src/Essentials/src/Sms/Sms.ios.cs b/src/Essentials/src/Sms/Sms.ios.cs index c887760baf0c..4880af2830e2 100644 --- a/src/Essentials/src/Sms/Sms.ios.cs +++ b/src/Essentials/src/Sms/Sms.ios.cs @@ -6,16 +6,16 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - class SmsImplementation : ISms + partial class SmsImplementation : ISms { - internal static bool IsComposeSupported + public bool IsComposeSupported #if !(MACCATALYST || MACOS) => MFMessageComposeViewController.CanSendText; #else => false; #endif - public Task ComposeAsync(SmsMessage message) + Task PlatformComposeAsync(SmsMessage message) { #if !(MACCATALYST || MACOS) // do this first so we can throw as early as possible diff --git a/src/Essentials/src/Sms/Sms.macos.cs b/src/Essentials/src/Sms/Sms.macos.cs index a34941d8ac1d..0abd3990d1a4 100644 --- a/src/Essentials/src/Sms/Sms.macos.cs +++ b/src/Essentials/src/Sms/Sms.macos.cs @@ -6,12 +6,12 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - class SmsImplementation : ISms + partial class SmsImplementation : ISms { - internal static bool IsComposeSupported => + public bool IsComposeSupported => MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString("sms:")) != null); - public Task ComposeAsync(SmsMessage message) + Task PlatformComposeAsync(SmsMessage message) { var recipients = string.Join(",", message.Recipients.Select(r => Uri.EscapeDataString(r))); diff --git a/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs b/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs index 7808d2215f2a..55bace335c10 100644 --- a/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs +++ b/src/Essentials/src/Sms/Sms.netstandard.tvos.watchos.cs @@ -3,12 +3,12 @@ namespace Microsoft.Maui.ApplicationModel.Communication { /// - class SmsImplementation : ISms + partial class SmsImplementation : ISms { - internal static bool IsComposeSupported + public bool IsComposeSupported => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task ComposeAsync(SmsMessage message) + Task PlatformComposeAsync(SmsMessage message) => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Sms/Sms.shared.cs b/src/Essentials/src/Sms/Sms.shared.cs index 50f5b4e093ce..4a92561b2224 100644 --- a/src/Essentials/src/Sms/Sms.shared.cs +++ b/src/Essentials/src/Sms/Sms.shared.cs @@ -1,49 +1,46 @@ #nullable enable using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.Communication; namespace Microsoft.Maui.ApplicationModel.Communication { public interface ISms { + bool IsComposeSupported { get; } + Task ComposeAsync(SmsMessage? message); } -} -namespace Microsoft.Maui.Essentials -{ - /// + public static class Sms { - /// - public static Task ComposeAsync() - => Current.ComposeAsync(null); + static ISms? defaultImplementation; - /// - public static Task ComposeAsync(SmsMessage message) + public static ISms Default => + defaultImplementation ??= new SmsImplementation(); + + internal static void SetDefault(ISms? implementation) => + defaultImplementation = implementation; + } + + partial class SmsImplementation : ISms + { + public Task ComposeAsync() => + ComposeAsync(null); + + public Task ComposeAsync(SmsMessage? message) { - if (!SmsImplementation.IsComposeSupported) + if (!IsComposeSupported) throw new FeatureNotSupportedException(); message ??= new SmsMessage(); message.Recipients ??= new List(); - return Current.ComposeAsync(message); + return PlatformComposeAsync(message); } - static ISms? currentImplementation; - - public static ISms Current => - currentImplementation ??= new SmsImplementation(); - - internal static void SetCurrent(ISms? implementation) => - currentImplementation = implementation; } -} -namespace Microsoft.Maui.ApplicationModel.Communication -{ + /// public class SmsMessage { diff --git a/src/Essentials/src/Sms/Sms.tizen.cs b/src/Essentials/src/Sms/Sms.tizen.cs index a9d6cc126130..e37504250f7c 100644 --- a/src/Essentials/src/Sms/Sms.tizen.cs +++ b/src/Essentials/src/Sms/Sms.tizen.cs @@ -3,12 +3,12 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - class SmsImplementation : ISms + partial class SmsImplementation : ISms { - internal static bool IsComposeSupported + public bool IsComposeSupported => Platform.GetFeatureInfo("network.telephony.sms"); - public Task ComposeAsync(SmsMessage message) + Task PlatformComposeAsync(SmsMessage message) { Permissions.EnsureDeclared(); diff --git a/src/Essentials/src/Sms/Sms.uwp.cs b/src/Essentials/src/Sms/Sms.uwp.cs index 362035c76ec6..389be914a144 100644 --- a/src/Essentials/src/Sms/Sms.uwp.cs +++ b/src/Essentials/src/Sms/Sms.uwp.cs @@ -5,12 +5,12 @@ namespace Microsoft.Maui.ApplicationModel.Communication { - class SmsImplementation : ISms + partial class SmsImplementation : ISms { - internal static bool IsComposeSupported + public bool IsComposeSupported => ApiInformation.IsTypePresent("Windows.ApplicationModel.Chat.ChatMessageManager"); - public Task ComposeAsync(SmsMessage message) + Task PlatformComposeAsync(SmsMessage message) { var chat = new ChatMessage(); if (!string.IsNullOrWhiteSpace(message?.Body)) From 633fd8f33f40a1c94aaa66508158e2089810c85f Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Wed, 23 Mar 2022 17:03:19 +0200 Subject: [PATCH 11/45] mostly done --- .../Essentials/AppleSignInAuthenticator.cs | 16 +++ .../Core/src/Essentials/TextToSpeech.cs | 26 ++++ .../Core/src/Essentials/VersionTracking.cs | 68 +++++++++ .../Core/src/Essentials/Vibration.cs | 28 ++++ .../Core/src/Essentials/WebAuthenticator.cs | 21 +++ .../src/Geocoding/Geocoding.shared.cs | 4 +- .../src/Platform/Platform.android.cs | 16 --- .../src/TextToSpeech/TextToSpeech.android.cs | 88 ++++++++++-- .../TextToSpeech.ios.tvos.watchos.cs | 23 +--- .../src/TextToSpeech/TextToSpeech.macos.cs | 9 +- .../TextToSpeech/TextToSpeech.netstandard.cs | 8 +- .../src/TextToSpeech/TextToSpeech.shared.cs | 63 +++------ .../src/TextToSpeech/TextToSpeech.tizen.cs | 15 +- .../src/TextToSpeech/TextToSpeech.uwp.cs | 7 +- .../TextToSpeechExtensions.shared.cs | 73 ---------- .../VersionTracking/VersionTracking.shared.cs | 129 +++++------------- .../src/Vibration/Vibration.android.cs | 48 +++++-- src/Essentials/src/Vibration/Vibration.ios.cs | 11 +- ...ibration.netstandard.tvos.watchos.macos.cs | 10 +- .../src/Vibration/Vibration.shared.cs | 64 +++++---- .../src/Vibration/Vibration.tizen.cs | 11 +- src/Essentials/src/Vibration/Vibration.uwp.cs | 9 +- .../AppleSignInAuthenticator.ios.cs | 4 +- ...rd.android.tvos.watchos.uwp.tizen.macos.cs | 6 +- .../AppleSignInAuthenticator.shared.cs | 28 +--- .../WebAuthenticator.android.cs | 3 +- .../WebAuthenticator.shared.cs | 75 ++++------ 27 files changed, 428 insertions(+), 435 deletions(-) create mode 100644 src/Compatibility/Core/src/Essentials/AppleSignInAuthenticator.cs create mode 100644 src/Compatibility/Core/src/Essentials/TextToSpeech.cs create mode 100644 src/Compatibility/Core/src/Essentials/VersionTracking.cs create mode 100644 src/Compatibility/Core/src/Essentials/Vibration.cs create mode 100644 src/Compatibility/Core/src/Essentials/WebAuthenticator.cs delete mode 100644 src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs diff --git a/src/Compatibility/Core/src/Essentials/AppleSignInAuthenticator.cs b/src/Compatibility/Core/src/Essentials/AppleSignInAuthenticator.cs new file mode 100644 index 000000000000..59f36d1402b6 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/AppleSignInAuthenticator.cs @@ -0,0 +1,16 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.Authentication; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class AppleSignInAuthenticator + { + /// + public static Task AuthenticateAsync(AppleSignInAuthenticatorOptions? options = null) + => Current.AuthenticateAsync(options ?? new AppleSignInAuthenticatorOptions()); + + static IAppleSignInAuthenticator Current => Authentication.AppleSignInAuthenticator.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/TextToSpeech.cs b/src/Compatibility/Core/src/Essentials/TextToSpeech.cs new file mode 100644 index 000000000000..738f68785e5d --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/TextToSpeech.cs @@ -0,0 +1,26 @@ +#nullable enable +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Maui.Media; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class TextToSpeech + { + /// + public static Task> GetLocalesAsync() => + Current.GetLocalesAsync(); + + /// + public static Task SpeakAsync(string text, CancellationToken cancelToken = default) => + Current.SpeakAsync(text, default, cancelToken); + + /// + public static Task SpeakAsync(string text, SpeechOptions? options, CancellationToken cancelToken = default) => + Current.SpeakAsync(text, options, cancelToken); + + static ITextToSpeech Current => Media.TextToSpeech.Current; + } +} diff --git a/src/Compatibility/Core/src/Essentials/VersionTracking.cs b/src/Compatibility/Core/src/Essentials/VersionTracking.cs new file mode 100644 index 000000000000..74aedd282eda --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/VersionTracking.cs @@ -0,0 +1,68 @@ +#nullable enable +using System.Collections.Generic; +using Microsoft.Maui.ApplicationModel; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class VersionTracking + { + /// + public static void Track() + => Current.Track(); + + /// + public static bool IsFirstLaunchEver + => Current.IsFirstLaunchEver; + + /// + public static bool IsFirstLaunchForCurrentVersion + => Current.IsFirstLaunchForCurrentVersion; + + /// + public static bool IsFirstLaunchForCurrentBuild + => Current.IsFirstLaunchForCurrentBuild; + + /// + public static string CurrentVersion + => Current.CurrentVersion; + + /// + public static string CurrentBuild + => Current.CurrentBuild; + + /// + public static string? PreviousVersion + => Current.PreviousVersion; + + /// + public static string? PreviousBuild + => Current.PreviousBuild; + + /// + public static string? FirstInstalledVersion + => Current.FirstInstalledVersion; + + /// + public static string? FirstInstalledBuild => + Current.FirstInstalledBuild; + + /// + public static IEnumerable VersionHistory + => Current.VersionHistory; + + /// + public static IEnumerable BuildHistory + => Current.BuildHistory; + + /// + public static bool IsFirstLaunchForVersion(string version) + => Current.IsFirstLaunchForVersion(version); + + /// + public static bool IsFirstLaunchForBuild(string build) + => Current.IsFirstLaunchForBuild(build); + + static IVersionTracking Current => ApplicationModel.VersionTracking.Current; + } +} diff --git a/src/Compatibility/Core/src/Essentials/Vibration.cs b/src/Compatibility/Core/src/Essentials/Vibration.cs new file mode 100644 index 000000000000..eab539b0776a --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/Vibration.cs @@ -0,0 +1,28 @@ +#nullable enable +using System; +using Microsoft.Maui.Devices; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class Vibration + { + /// + public static void Vibrate() => + Current.Vibrate(); + + /// + public static void Vibrate(double duration) => + Current.Vibrate(duration); + + /// + public static void Vibrate(TimeSpan duration) => + Current.Vibrate(duration); + + /// + public static void Cancel() => + Current.Cancel(); + + static IVibration Current => Devices.Vibration.Default; + } +} diff --git a/src/Compatibility/Core/src/Essentials/WebAuthenticator.cs b/src/Compatibility/Core/src/Essentials/WebAuthenticator.cs new file mode 100644 index 000000000000..1b927cfe6c90 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/WebAuthenticator.cs @@ -0,0 +1,21 @@ +#nullable enable +using System; +using System.Threading.Tasks; +using Microsoft.Maui.Authentication; + +namespace Microsoft.Maui.Essentials +{ + /// + public static class WebAuthenticator + { + /// + public static Task AuthenticateAsync(Uri url, Uri callbackUrl) + => Current.AuthenticateAsync(url, callbackUrl); + + /// + public static Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) + => Current.AuthenticateAsync(webAuthenticatorOptions); + + static IWebAuthenticator Current => Authentication.WebAuthenticator.Default; + } +} diff --git a/src/Essentials/src/Geocoding/Geocoding.shared.cs b/src/Essentials/src/Geocoding/Geocoding.shared.cs index 2946851ce3e2..885210207d1c 100644 --- a/src/Essentials/src/Geocoding/Geocoding.shared.cs +++ b/src/Essentials/src/Geocoding/Geocoding.shared.cs @@ -40,14 +40,14 @@ public static Task> GetPlacemarksAsync(this IGeocoding ge return geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude); } +#if WINDOWS || TIZEN public static void SetMapServiceToken(this IGeocoding geocoding, string? mapServiceToken) { -#if WINDOWS || TIZEN if (geocoding is IPlatformGeocoding platform) { platform.MapServiceToken = mapServiceToken; } -#endif } +#endif } } diff --git a/src/Essentials/src/Platform/Platform.android.cs b/src/Essentials/src/Platform/Platform.android.cs index 3c35559b518e..8062ddd2c28a 100644 --- a/src/Essentials/src/Platform/Platform.android.cs +++ b/src/Essentials/src/Platform/Platform.android.cs @@ -161,22 +161,6 @@ internal static AndroidUri GetShareableFileUri(FileBase file) internal static ConnectivityManager ConnectivityManager => AppContext.GetSystemService(Context.ConnectivityService) as ConnectivityManager; -#if __ANDROID_31__ - internal static VibratorManager VibratorManager => - HasApiLevelS - ? AppContext.GetSystemService(Context.VibratorManagerService) as VibratorManager - : null; -#endif - - internal static Vibrator Vibrator => -#if __ANDROID_31__ - HasApiLevelS - ? VibratorManager.DefaultVibrator : -#endif -#pragma warning disable CS0618 // Type or member is obsolete - AppContext.GetSystemService(Context.VibratorService) as Vibrator; -#pragma warning restore CS0618 // Type or member is obsolete - internal static WifiManager WifiManager => AppContext.GetSystemService(Context.WifiService) as WifiManager; diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs index 784b329a059a..e0b8edc7c8a6 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.android.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Android.OS; +using Android.App; using Android.Speech.Tts; using AndroidTextToSpeech = Android.Speech.Tts.TextToSpeech; using Debug = System.Diagnostics.Debug; @@ -16,9 +16,9 @@ partial class TextToSpeechImplementation : ITextToSpeech { const int maxSpeechInputLengthDefault = 4000; - static WeakReference textToSpeechRef = null; + WeakReference textToSpeechRef = null; - static TextToSpeechInternalImplementation GetTextToSpeech() + TextToSpeechInternalImplementation GetTextToSpeech() { if (textToSpeechRef == null || !textToSpeechRef.TryGetTarget(out var tts)) { @@ -29,27 +29,22 @@ static TextToSpeechInternalImplementation GetTextToSpeech() return tts; } - public Task SpeakAsync(string text, CancellationToken cancelToken) - => SpeakAsync(text, default, cancelToken); - - public Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken) + Task PlatformSpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken) { var textToSpeech = GetTextToSpeech(); - if (textToSpeech == null) throw new PlatformNotSupportedException("Unable to start text-to-speech engine, not supported on device."); var max = maxSpeechInputLengthDefault; - if (OperatingSystem.IsAndroidVersionAtLeast((int)BuildVersionCodes.JellyBeanMr2)) + if (OperatingSystem.IsAndroidVersionAtLeast(18)) max = AndroidTextToSpeech.MaxSpeechInputLength; return textToSpeech.SpeakAsync(text, max, options, cancelToken); } - public Task> GetLocalesAsync() + Task> PlatformGetLocalesAsync() { var textToSpeech = GetTextToSpeech(); - if (textToSpeech == null) throw new PlatformNotSupportedException("Unable to start text-to-speech engine, not supported on device."); @@ -75,7 +70,7 @@ Task Initialize() try { // set up the TextToSpeech object - tts = new AndroidTextToSpeech(Platform.AppContext, this); + tts = new AndroidTextToSpeech(Application.Context, this); #pragma warning disable CS0618 tts.SetOnUtteranceCompletedListener(this); #pragma warning restore CS0618 @@ -148,11 +143,11 @@ public async Task SpeakAsync(string text, int max, SpeechOptions options, Cancel if (options?.Pitch.HasValue ?? false) tts.SetPitch(options.Pitch.Value); else - tts.SetPitch(TextToSpeech.PitchDefault); + tts.SetPitch(TextToSpeechImplementation.PitchDefault); tts.SetSpeechRate(1.0f); - var parts = text.SplitSpeak(max); + var parts = SplitSpeak(text, max); numExpectedUtterances = parts.Count; @@ -248,5 +243,70 @@ void SetDefaultLanguage() } } #pragma warning restore 0618 + + static List SplitSpeak(string text, int max) + { + var parts = new List(); + if (text.Length <= max) + { + // no need to split + parts.Add(text); + } + else + { + var positionbegin = 0; + var positionend = max; + var position = positionbegin; + + var p = string.Empty; + while (position != text.Length) + { + while (positionend > positionbegin) + { + if (positionend >= text.Length) + { + // we just need the rest of it + p = text.Substring(positionbegin, text.Length - positionbegin); + parts.Add(p); + return parts; + } + + var ch = text[positionend]; + if (char.IsWhiteSpace(ch) || char.IsPunctuation(ch)) + { + p = text.Substring(positionbegin, positionend - positionbegin); + break; + } + else if (positionend == positionbegin) + { + // no whitespace or punctuation found + // grab the whole buffer (max) + p = text.Substring(positionbegin, positionbegin + max); + break; + } + + positionend--; + } + Debug.WriteLine($"p = {p}"); + Debug.WriteLine($"p.Length = {p.Length}"); + Debug.WriteLine($"positionbegin = {positionbegin}"); + Debug.WriteLine($"positionend = {positionend}"); + Debug.WriteLine($"position = {position}"); + + positionbegin = positionbegin + p.Length + 1; + positionend = positionbegin + max; + position = positionbegin; + + Debug.WriteLine($"------------------------------"); + Debug.WriteLine($"positionbegin = {positionbegin}"); + Debug.WriteLine($"positionend = {positionend}"); + Debug.WriteLine($"position = {position}"); + + parts.Add(p); + } + } + + return parts; + } } } diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs index 3a5024bc156c..998e4de7295d 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.ios.tvos.watchos.cs @@ -9,21 +9,16 @@ namespace Microsoft.Maui.Media { partial class TextToSpeechImplementation : ITextToSpeech { - static readonly Lazy speechSynthesizer = new Lazy(); + readonly Lazy speechSynthesizer = new(() => new AVSpeechSynthesizer()); - public Task> GetLocalesAsync() => + Task> PlatformGetLocalesAsync() => Task.FromResult(AVSpeechSynthesisVoice.GetSpeechVoices() .Select(v => new Locale(v.Language, null, v.Name, v.Identifier))); - - public Task SpeakAsync(string text, CancellationToken cancelToken) - => SpeakAsync(text, default, cancelToken); - - public async Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) + + async Task PlatformSpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken) { - using (var speechUtterance = GetSpeechUtterance(text, options)) - { - await SpeakUtterance(speechUtterance, cancelToken); - } + using var speechUtterance = GetSpeechUtterance(text, options); + await SpeakUtterance(speechUtterance, cancelToken); } static AVSpeechUtterance GetSpeechUtterance(string text, SpeechOptions options) @@ -49,15 +44,11 @@ static AVSpeechUtterance GetSpeechUtterance(string text, SpeechOptions options) return speechUtterance; } - internal static async Task SpeakUtterance(AVSpeechUtterance speechUtterance, CancellationToken cancelToken) + async Task SpeakUtterance(AVSpeechUtterance speechUtterance, CancellationToken cancelToken) { var tcsUtterance = new TaskCompletionSource(); try { - // Ensures linker doesn't remove. - if (DateTime.UtcNow.Ticks < 0) - new AVSpeechSynthesizer(); - speechSynthesizer.Value.DidFinishSpeechUtterance += OnFinishedSpeechUtterance; speechSynthesizer.Value.SpeakUtterance(speechUtterance); using (cancelToken.Register(TryCancel)) diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs index 03cf9db7bcd0..2aabf215ab0f 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.macos.cs @@ -9,18 +9,15 @@ namespace Microsoft.Maui.Media { partial class TextToSpeechImplementation : ITextToSpeech { - static readonly Lazy speechSynthesizer = new Lazy(() => + readonly Lazy speechSynthesizer = new Lazy(() => new NSSpeechSynthesizer { Delegate = new SpeechSynthesizerDelegate() }); - public Task> GetLocalesAsync() => + Task> PlatformGetLocalesAsync() => Task.FromResult(NSSpeechSynthesizer.AvailableVoices .Select(voice => NSSpeechSynthesizer.AttributesForVoice(voice)) .Select(attribute => new Locale(attribute["VoiceLanguage"]?.ToString(), null, attribute["VoiceName"]?.ToString(), attribute["VoiceIdentifier"]?.ToString()))); - public Task SpeakAsync(string text, CancellationToken cancelToken) - => SpeakAsync(text, default, cancelToken); - - public async Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) + async Task PlatformSpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) { var ss = speechSynthesizer.Value; var ssd = (SpeechSynthesizerDelegate)ss.Delegate; diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs index 579511e7394c..565ada14a7d7 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.netstandard.cs @@ -4,16 +4,12 @@ namespace Microsoft.Maui.Media { - /// partial class TextToSpeechImplementation : ITextToSpeech { - public Task SpeakAsync(string text, CancellationToken cancelToken) => + Task PlatformSpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken) => throw ExceptionUtils.NotSupportedOrImplementedException; - public Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken) => - throw ExceptionUtils.NotSupportedOrImplementedException; - - public Task> GetLocalesAsync() => + Task> PlatformGetLocalesAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs index f87d9d16e153..fc14744ca43f 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs @@ -1,26 +1,30 @@ +#nullable enable using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.Media; namespace Microsoft.Maui.Media { public interface ITextToSpeech { Task> GetLocalesAsync(); - - Task SpeakAsync(string text, CancellationToken cancelToken); - Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken); + Task SpeakAsync(string text, SpeechOptions? options = default, CancellationToken cancelToken = default); + } + + public static class TextToSpeech + { + static ITextToSpeech? currentImplementation; + + public static ITextToSpeech Current => + currentImplementation ??= new TextToSpeechImplementation(); + internal static void SetCurrent(ITextToSpeech? implementation) => + currentImplementation = implementation; } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class TextToSpeech + + partial class TextToSpeechImplementation : ITextToSpeech { internal const float PitchMax = 2.0f; internal const float PitchDefault = 1.0f; @@ -30,18 +34,12 @@ public static partial class TextToSpeech internal const float VolumeDefault = 0.5f; internal const float VolumeMin = 0.0f; - static SemaphoreSlim semaphore; - - /// - public static Task> GetLocalesAsync() => - Current.GetLocalesAsync(); + SemaphoreSlim? semaphore; - /// - public static Task SpeakAsync(string text, CancellationToken cancelToken = default) => - SpeakAsync(text, default, cancelToken); + public Task> GetLocalesAsync() => + PlatformGetLocalesAsync(); - /// - public static async Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) + public async Task SpeakAsync(string text, SpeechOptions? options = default, CancellationToken cancelToken = default) { if (string.IsNullOrEmpty(text)) throw new ArgumentNullException(nameof(text), "Text cannot be null or empty string"); @@ -64,7 +62,7 @@ public static async Task SpeakAsync(string text, SpeechOptions options, Cancella try { await semaphore.WaitAsync(cancelToken); - await Current.SpeakAsync(text, options, cancelToken); + await PlatformSpeakAsync(text, options, cancelToken); } finally { @@ -72,27 +70,8 @@ public static async Task SpeakAsync(string text, SpeechOptions options, Cancella semaphore.Release(); } } - - internal static float Normalize(float min, float max, float percent) - { - var range = max - min; - var add = range * percent; - return min + add; - } - -#nullable enable - static ITextToSpeech? currentImplementation; - - public static ITextToSpeech Current => - currentImplementation ??= new TextToSpeechImplementation(); - - internal static void SetCurrent(ITextToSpeech? implementation) => - currentImplementation = implementation; -#nullable disable } -} -namespace Microsoft.Maui.Media -{ + /// public class Locale { @@ -121,7 +100,7 @@ internal Locale(string language, string country, string name, string id) public class SpeechOptions { /// - public Locale Locale { get; set; } + public Locale? Locale { get; set; } /// public float? Pitch { get; set; } diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs index 9f68df593dc4..5e8dc37d5b94 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.tizen.cs @@ -8,14 +8,11 @@ namespace Microsoft.Maui.Media { partial class TextToSpeechImplementation : ITextToSpeech { - static TtsClient tts = null; - static TaskCompletionSource tcsInitialize = null; - static TaskCompletionSource tcsUtterances = null; + TtsClient tts = null; + TaskCompletionSource tcsInitialize = null; + TaskCompletionSource tcsUtterances = null; - public Task SpeakAsync(string text, CancellationToken cancelToken) - => SpeakAsync(text, default, cancelToken); - - public async Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) + async Task PlatformSpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) { await Initialize(); @@ -56,7 +53,7 @@ public async Task SpeakAsync(string text, SpeechOptions options, CancellationTok await tcsUtterances.Task; } - public async Task> GetLocalesAsync() + async Task> PlatformGetLocalesAsync() { await Initialize(); var list = new List(); @@ -65,7 +62,7 @@ public async Task> GetLocalesAsync() return list; } - static Task Initialize() + Task Initialize() { if (tcsInitialize != null && tts != null) return tcsInitialize.Task; diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs index 2c56e1b1cffc..794b9b18dd62 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.uwp.cs @@ -14,13 +14,10 @@ namespace Microsoft.Maui.Media { partial class TextToSpeechImplementation : ITextToSpeech { - public Task> GetLocalesAsync() => + Task> PlatformGetLocalesAsync() => Task.FromResult(SpeechSynthesizer.AllVoices.Select(v => new Locale(v.Language, null, v.DisplayName, v.Id))); - public Task SpeakAsync(string text, CancellationToken cancelToken) - => SpeakAsync(text, default, cancelToken); - - public async Task SpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) + async Task PlatformSpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken = default) { var tcsUtterance = new TaskCompletionSource(); diff --git a/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs deleted file mode 100644 index 19246cc0f5cb..000000000000 --- a/src/Essentials/src/TextToSpeech/TextToSpeechExtensions.shared.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics; - -namespace Microsoft.Maui.Media -{ - static partial class TextToSpeechExtensions - { - internal static List SplitSpeak(this string text, int max) - { - var parts = new List(); - if (text.Length <= max) - { - // no need to split - parts.Add(text); - } - else - { - var positionbegin = 0; - var positionend = max; - var position = positionbegin; - - var p = string.Empty; - while (position != text.Length) - { - while (positionend > positionbegin) - { - if (positionend >= text.Length) - { - // we just need the rest of it - p = text.Substring(positionbegin, text.Length - positionbegin); - parts.Add(p); - return parts; - } - - var ch = text[positionend]; - if (char.IsWhiteSpace(ch) || char.IsPunctuation(ch)) - { - p = text.Substring(positionbegin, positionend - positionbegin); - break; - } - else if (positionend == positionbegin) - { - // no whitespace or punctuation found - // grab the whole buffer (max) - p = text.Substring(positionbegin, positionbegin + max); - break; - } - - positionend--; - } - Debug.WriteLine($"p = {p}"); - Debug.WriteLine($"p.Length = {p.Length}"); - Debug.WriteLine($"positionbegin = {positionbegin}"); - Debug.WriteLine($"positionend = {positionend}"); - Debug.WriteLine($"position = {position}"); - - positionbegin = positionbegin + p.Length + 1; - positionend = positionbegin + max; - position = positionbegin; - - Debug.WriteLine($"------------------------------"); - Debug.WriteLine($"positionbegin = {positionbegin}"); - Debug.WriteLine($"positionend = {positionend}"); - Debug.WriteLine($"position = {position}"); - - parts.Add(p); - } - } - - return parts; - } - } -} diff --git a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs index 55645cabc5a0..8c0cd94eb6eb 100644 --- a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs +++ b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs @@ -1,10 +1,9 @@ +#nullable enable using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Text; using Microsoft.Maui.Storage; -using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.ApplicationModel { @@ -22,13 +21,13 @@ public interface IVersionTracking string CurrentBuild { get; } - string PreviousVersion { get; } + string? PreviousVersion { get; } - string PreviousBuild { get; } + string? PreviousBuild { get; } - string FirstInstalledVersion { get; } + string? FirstInstalledVersion { get; } - string FirstInstalledBuild { get; } + string? FirstInstalledBuild { get; } IReadOnlyList VersionHistory { get; } @@ -38,100 +37,45 @@ public interface IVersionTracking bool IsFirstLaunchForBuild(string build); } -} -namespace Microsoft.Maui.Essentials -{ - /// public static class VersionTracking { - /// - [Preserve] - public static void Track() - => Current.Track(); - - /// - public static bool IsFirstLaunchEver - => Current.IsFirstLaunchEver; - - /// - public static bool IsFirstLaunchForCurrentVersion - => Current.IsFirstLaunchForCurrentVersion; - - /// - public static bool IsFirstLaunchForCurrentBuild - => Current.IsFirstLaunchForCurrentBuild; - - /// - public static string CurrentVersion - => Current.CurrentVersion; - - /// - public static string CurrentBuild - => Current.CurrentBuild; - - /// - public static string PreviousVersion - => Current.PreviousVersion; - - /// - public static string PreviousBuild - => Current.PreviousBuild; - - /// - public static string FirstInstalledVersion - => Current.FirstInstalledVersion; - - /// - public static string FirstInstalledBuild => - Current.FirstInstalledBuild; - - /// - public static IEnumerable VersionHistory - => Current.VersionHistory; - - /// - public static IEnumerable BuildHistory - => Current.BuildHistory; - - /// - public static bool IsFirstLaunchForVersion(string version) - => Current.IsFirstLaunchForVersion(version); - - /// - public static bool IsFirstLaunchForBuild(string build) - => Current.IsFirstLaunchForBuild(build); - - //internal static string GetStatus() - // => Current.GetStatus(); - -#nullable enable static IVersionTracking? currentImplementation; public static IVersionTracking Current => - currentImplementation ??= new VersionTrackingImplementation(); + currentImplementation ??= new VersionTrackingImplementation(Preferences.Default, AppInfo.Current); internal static void SetCurrent(IVersionTracking? implementation) => currentImplementation = implementation; -#nullable disable } -} -namespace Microsoft.Maui.ApplicationModel -{ class VersionTrackingImplementation : IVersionTracking { const string versionTrailKey = "VersionTracking.Trail"; const string versionsKey = "VersionTracking.Versions"; const string buildsKey = "VersionTracking.Builds"; - readonly string sharedName = Preferences.GetPrivatePreferencesSharedName("versiontracking"); + static readonly string sharedName = Preferences.GetPrivatePreferencesSharedName("versiontracking"); - readonly Dictionary> versionTrail; + readonly IPreferences preferences; + readonly IAppInfo appInfo; - public VersionTrackingImplementation() + Dictionary> versionTrail = null!; + + public VersionTrackingImplementation(IPreferences preferences, IAppInfo appInfo) { - IsFirstLaunchEver = !Preferences.ContainsKey(versionsKey, sharedName) || !Preferences.ContainsKey(buildsKey, sharedName); + this.preferences = preferences; + this.appInfo = appInfo; + + Track(); + } + + public void Track() + { + if (versionTrail != null) + return; + + IsFirstLaunchEver = !preferences.ContainsKey(versionsKey, sharedName) || !preferences.ContainsKey(buildsKey, sharedName); if (IsFirstLaunchEver) { versionTrail = new Dictionary> @@ -168,28 +112,23 @@ public VersionTrackingImplementation() } } - [Preserve] - public void Track() - { - } - public bool IsFirstLaunchEver { get; private set; } public bool IsFirstLaunchForCurrentVersion { get; private set; } public bool IsFirstLaunchForCurrentBuild { get; private set; } - public string CurrentVersion => AppInfo.VersionString; + public string CurrentVersion => appInfo.VersionString; - public string CurrentBuild => AppInfo.BuildString; + public string CurrentBuild => appInfo.BuildString; - public string PreviousVersion => GetPrevious(versionsKey); + public string? PreviousVersion => GetPrevious(versionsKey); - public string PreviousBuild => GetPrevious(buildsKey); + public string? PreviousBuild => GetPrevious(buildsKey); - public string FirstInstalledVersion => versionTrail[versionsKey].FirstOrDefault(); + public string? FirstInstalledVersion => versionTrail[versionsKey].FirstOrDefault(); - public string FirstInstalledBuild => versionTrail[buildsKey].FirstOrDefault(); + public string? FirstInstalledBuild => versionTrail[buildsKey].FirstOrDefault(); public IReadOnlyList VersionHistory => versionTrail[versionsKey].ToArray(); @@ -201,7 +140,7 @@ public bool IsFirstLaunchForVersion(string version) public bool IsFirstLaunchForBuild(string build) => CurrentBuild == build && IsFirstLaunchForCurrentBuild; - string GetStatus() + public string GetStatus() { var sb = new StringBuilder(); sb.AppendLine(); @@ -223,12 +162,12 @@ string GetStatus() } string[] ReadHistory(string key) - => Preferences.Get(key, null, sharedName)?.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]; + => preferences.Get(key, null, sharedName)?.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]; void WriteHistory(string key, IEnumerable history) - => Preferences.Set(key, string.Join("|", history), sharedName); + => preferences.Set(key, string.Join("|", history), sharedName); - string GetPrevious(string key) + string? GetPrevious(string key) { var trail = versionTrail[key]; return (trail.Count >= 2) ? trail[trail.Count - 2] : null; diff --git a/src/Essentials/src/Vibration/Vibration.android.cs b/src/Essentials/src/Vibration/Vibration.android.cs index 34c68a452a10..f96501872d30 100644 --- a/src/Essentials/src/Vibration/Vibration.android.cs +++ b/src/Essentials/src/Vibration/Vibration.android.cs @@ -1,6 +1,8 @@ +#nullable enable using System; +using Android.App; +using Android.Content; #if __ANDROID_26__ -using Android; using Android.OS; using Microsoft.Maui.ApplicationModel; #endif @@ -9,37 +11,55 @@ namespace Microsoft.Maui.Devices { partial class VibrationImplementation : IVibration { - public bool IsSupported => true; + static VibratorManager? VibratorManager => + OperatingSystem.IsAndroidVersionAtLeast(31) + ? Application.Context.GetSystemService(Context.VibratorManagerService) as VibratorManager + : null; + + static Vibrator? VibratorManagerVibrator => + OperatingSystem.IsAndroidVersionAtLeast(31) + ? VibratorManager?.DefaultVibrator + : null; + + static Vibrator? VibratorServiceVibrator => +#pragma warning disable CS0618 // Type or member is obsolete + Application.Context.GetSystemService(Context.VibratorService) as Vibrator; +#pragma warning restore CS0618 // Type or member is obsolete - public void Vibrate() - => Vibrate(TimeSpan.FromMilliseconds(500)); + static Vibrator? vibrator; - public void Vibrate(double duration) - => Vibrate(TimeSpan.FromMilliseconds(duration)); + static Vibrator? Vibrator => + vibrator ??= (VibratorManagerVibrator ?? VibratorServiceVibrator); - public void Vibrate(TimeSpan duration) + public bool IsSupported => true; + + void PlatformVibrate() => + PlatformVibrate(TimeSpan.FromMilliseconds(500)); + + void PlatformVibrate(TimeSpan duration) { Permissions.EnsureDeclared(); var time = (long)duration.TotalMilliseconds; #if __ANDROID_26__ - if (Platform.HasApiLevelO) + if (OperatingSystem.IsAndroidVersionAtLeast(26)) { - Platform.Vibrator.Vibrate(VibrationEffect.CreateOneShot(time, VibrationEffect.DefaultAmplitude)); - return; + Vibrator?.Vibrate(VibrationEffect.CreateOneShot(time, VibrationEffect.DefaultAmplitude)); } + else #endif - + { #pragma warning disable CS0618 // Type or member is obsolete - Platform.Vibrator.Vibrate(time); + Vibrator?.Vibrate(time); #pragma warning restore CS0618 // Type or member is obsolete + } } - public void Cancel() + void PlatformCancel() { Permissions.EnsureDeclared(); - Platform.Vibrator.Cancel(); + Vibrator?.Cancel(); } } } diff --git a/src/Essentials/src/Vibration/Vibration.ios.cs b/src/Essentials/src/Vibration/Vibration.ios.cs index d785ce66828f..4aa765541016 100644 --- a/src/Essentials/src/Vibration/Vibration.ios.cs +++ b/src/Essentials/src/Vibration/Vibration.ios.cs @@ -7,16 +7,13 @@ partial class VibrationImplementation : IVibration { public bool IsSupported => true; - public void Vibrate() - => Vibrate(TimeSpan.FromMilliseconds(500)); - - public void Vibrate(double duration) - => Vibrate(TimeSpan.FromMilliseconds(duration)); + void PlatformVibrate() => + SystemSound.Vibrate.PlaySystemSound(); - public void Vibrate(TimeSpan duration) => + void PlatformVibrate(TimeSpan duration) => SystemSound.Vibrate.PlaySystemSound(); - public void Cancel() + void PlatformCancel() { } } diff --git a/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs b/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs index d87c5def510e..cf24d086fa1c 100644 --- a/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs +++ b/src/Essentials/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs @@ -2,22 +2,18 @@ namespace Microsoft.Maui.Devices { - /// partial class VibrationImplementation : IVibration { public bool IsSupported => throw ExceptionUtils.NotSupportedOrImplementedException; - public void Vibrate() + void PlatformVibrate() => throw ExceptionUtils.NotSupportedOrImplementedException; - public void Vibrate(double duration) + void PlatformVibrate(TimeSpan duration) => throw ExceptionUtils.NotSupportedOrImplementedException; - public void Vibrate(TimeSpan duration) - => throw ExceptionUtils.NotSupportedOrImplementedException; - - public void Cancel() + void PlatformCancel() => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Vibration/Vibration.shared.cs b/src/Essentials/src/Vibration/Vibration.shared.cs index 4b73b297a16b..5948534ae785 100644 --- a/src/Essentials/src/Vibration/Vibration.shared.cs +++ b/src/Essentials/src/Vibration/Vibration.shared.cs @@ -1,6 +1,5 @@ +#nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.Devices; namespace Microsoft.Maui.Devices { @@ -10,31 +9,41 @@ public interface IVibration void Vibrate(); - void Vibrate(double duration); - void Vibrate(TimeSpan duration); void Cancel(); } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Vibration + public static class Vibration { - /// - public static void Vibrate() - => Current.Vibrate(TimeSpan.FromMilliseconds(500)); + static IVibration? defaultImplementation; + + public static IVibration Default => + defaultImplementation ??= new VibrationImplementation(); - /// - public static void Vibrate(double duration) - => Current.Vibrate(TimeSpan.FromMilliseconds(duration)); + internal static void SetDefault(IVibration? implementation) => + defaultImplementation = implementation; + } - /// - public static void Vibrate(TimeSpan duration) + public static class VibrationExtensions + { + public static void Vibrate(this IVibration vibration, double duration) => + vibration.Vibrate(TimeSpan.FromMilliseconds(duration)); + } + + partial class VibrationImplementation : IVibration + { + public void Vibrate() { - if (!Current.IsSupported) + if (!IsSupported) + throw new FeatureNotSupportedException(); + + PlatformVibrate(); + } + + public void Vibrate(TimeSpan duration) + { + if (!IsSupported) throw new FeatureNotSupportedException(); if (duration.TotalMilliseconds < 0) @@ -42,26 +51,15 @@ public static void Vibrate(TimeSpan duration) else if (duration.TotalSeconds > 5) duration = TimeSpan.FromSeconds(5); - Current.Vibrate(duration); + PlatformVibrate(duration); } - /// - public static void Cancel() + public void Cancel() { - if (!Current.IsSupported) + if (!IsSupported) throw new FeatureNotSupportedException(); - Current.Cancel(); + PlatformCancel(); } - -#nullable enable - static IVibration? currentImplementation; - - public static IVibration Current => - currentImplementation ??= new VibrationImplementation(); - - internal static void SetCurrent(IVibration? implementation) => - currentImplementation = implementation; -#nullable disable } } diff --git a/src/Essentials/src/Vibration/Vibration.tizen.cs b/src/Essentials/src/Vibration/Vibration.tizen.cs index e2331210918e..38e833e1ff05 100644 --- a/src/Essentials/src/Vibration/Vibration.tizen.cs +++ b/src/Essentials/src/Vibration/Vibration.tizen.cs @@ -9,21 +9,20 @@ partial class VibrationImplementation : IVibration public bool IsSupported => Vibrator.NumberOfVibrators > 0; - public void Vibrate() + void PlatformVibrate() => Vibrate(TimeSpan.FromMilliseconds(500)); - public void Vibrate(double duration) - => Vibrate(TimeSpan.FromMilliseconds(duration)); - - public void Vibrate(TimeSpan duration) + void PlatformVibrate(TimeSpan duration) { Permissions.EnsureDeclared(); + Vibrator.Vibrators.FirstOrDefault()?.Vibrate((int)duration.TotalMilliseconds, 100); } - public void Cancel() + void PlatformCancel() { Permissions.EnsureDeclared(); + Vibrator.Vibrators.FirstOrDefault()?.Stop(); } } diff --git a/src/Essentials/src/Vibration/Vibration.uwp.cs b/src/Essentials/src/Vibration/Vibration.uwp.cs index cfcf3b0dd827..b3af60451c11 100644 --- a/src/Essentials/src/Vibration/Vibration.uwp.cs +++ b/src/Essentials/src/Vibration/Vibration.uwp.cs @@ -12,16 +12,13 @@ public bool IsSupported static VibrationDevice DefaultDevice => throw new NotImplementedException("WINUI"); //VibrationDevice.GetDefault(); - public void Vibrate() + void PlatformVibrate() => throw new NotImplementedException("WINUI");// DefaultDevice.Vibrate(duration); - public void Vibrate(double duration) - => throw new NotImplementedException("WINUI");// DefaultDevice.Vibrate(duration); - - public void Vibrate(TimeSpan duration) => + void PlatformVibrate(TimeSpan duration) => throw new NotImplementedException("WINUI");// DefaultDevice.Vibrate(duration); - public void Cancel() => + void PlatformCancel() => throw new NotImplementedException("WINUI");//DefaultDevice.Cancel(); } } diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs index 4c7b2e07a86e..561538309df5 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs @@ -1,15 +1,13 @@ using System; using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; using AuthenticationServices; using Foundation; -using ObjCRuntime; using UIKit; namespace Microsoft.Maui.Authentication { - public partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator + partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator { AuthManager authManager; diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs index 4ffaca22ae2f..92e23e704f25 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; namespace Microsoft.Maui.Authentication { - /// - public partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator + partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator { public Task AuthenticateAsync(AppleSignInAuthenticatorOptions options) => throw ExceptionUtils.NotSupportedOrImplementedException; diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs index 0c397c1997ae..c26c287670ec 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; +#nullable enable using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.Authentication; namespace Microsoft.Maui.Authentication { public interface IAppleSignInAuthenticator { - Task AuthenticateAsync(AppleSignInAuthenticatorOptions options = null); + Task AuthenticateAsync(AppleSignInAuthenticatorOptions? options = null); } public class AppleSignInAuthenticatorOptions @@ -18,25 +14,15 @@ public class AppleSignInAuthenticatorOptions public bool IncludeEmailScope { get; set; } = false; } -} -namespace Microsoft.Maui.Essentials -{ - /// public static class AppleSignInAuthenticator { - /// - public static Task AuthenticateAsync(AppleSignInAuthenticatorOptions options = null) - => Current.AuthenticateAsync(options ?? new AppleSignInAuthenticatorOptions()); - -#nullable enable - static IAppleSignInAuthenticator? currentImplementation; + static IAppleSignInAuthenticator? defaultImplementation; - public static IAppleSignInAuthenticator Current => - currentImplementation ??= new AppleSignInAuthenticatorImplementation(); + public static IAppleSignInAuthenticator Default => + defaultImplementation ??= new AppleSignInAuthenticatorImplementation(); - internal static void SetCurrent(IAppleSignInAuthenticator? implementation) => - currentImplementation = implementation; -#nullable disable + internal static void SetDefault(IAppleSignInAuthenticator? implementation) => + defaultImplementation = implementation; } } diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs index 5aeaf9633ecf..cc6c2491f3ca 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using Android.App; using Android.Content; using AndroidX.Browser.CustomTabs; @@ -47,7 +48,7 @@ public async Task AuthenticateAsync(WebAuthenticatorOpti { var url = webAuthenticatorOptions?.Url; var callbackUrl = webAuthenticatorOptions?.CallbackUrl; - var packageName = Platform.AppContext.PackageName; + var packageName = Application.Context.PackageName; // Create an intent to see if the app developer wired up the callback activity correctly var intent = new Intent(Intent.ActionView); diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs index 8dfa31df61b1..e06366da8bff 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs @@ -1,17 +1,11 @@ +#nullable enable using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Text; using System.Threading.Tasks; -using System.ComponentModel; -using Microsoft.Maui.Authentication; namespace Microsoft.Maui.Authentication { public interface IWebAuthenticator { - Task AuthenticateAsync(Uri url, Uri callbackUrl); - Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions); } @@ -20,66 +14,51 @@ public interface IPlatformWebAuthenticatorCallback #if IOS || MACCATALYST || MACOS bool OpenUrlCallback(Uri uri); #elif ANDROID - bool OnResumeCallback(global::Android.Content.Intent intent); + bool OnResumeCallback(Android.Content.Intent intent); #endif } -} -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class WebAuthenticator + public static class WebAuthenticator { - /// - public static Task AuthenticateAsync(Uri url, Uri callbackUrl) - => Current.AuthenticateAsync(url, callbackUrl); + static IWebAuthenticator? defaultImplementation; + + public static IWebAuthenticator Default => + defaultImplementation ??= new WebAuthenticatorImplementation(); - /// - public static Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) - => Current.AuthenticateAsync(webAuthenticatorOptions); + internal static void SetDefault(IWebAuthenticator? implementation) => + defaultImplementation = implementation; + } + + public static class WebAuthenticatorExtensions + { + public static Task AuthenticateAsync(this IWebAuthenticator webAuthenticator, Uri url, Uri callbackUrl) => + webAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl }); #if IOS || MACCATALYST || MACOS - internal static bool OpenUrl(Uri uri) + public static bool OpenUrl(this IWebAuthenticator webAuthenticator, Uri uri) { - if (Current is IPlatformWebAuthenticatorCallback c) - return c.OpenUrlCallback(uri); - return false; + if (webAuthenticator is not IPlatformWebAuthenticatorCallback platform) + throw new PlatformNotSupportedException("This implementation of IWebAuthenticator does not implement IPlatformWebAuthenticatorCallback."); + + return platform.OpenUrlCallback(uri); } #elif ANDROID - internal static bool OnResume(global::Android.Content.Intent intent) + public static bool OnResume(this IWebAuthenticator webAuthenticator, Android.Content.Intent intent) { - if (Current is IPlatformWebAuthenticatorCallback c) - return c.OnResumeCallback(intent); - return false; + if (webAuthenticator is not IPlatformWebAuthenticatorCallback platform) + throw new PlatformNotSupportedException("This implementation of IWebAuthenticator does not implement IPlatformWebAuthenticatorCallback."); + + return platform.OnResumeCallback(intent); } #endif - -#nullable enable - static IWebAuthenticator? currentImplementation; - - public static IWebAuthenticator Current => - currentImplementation ??= new WebAuthenticatorImplementation(); - - internal static void SetCurrent(IWebAuthenticator? implementation) => - currentImplementation = implementation; -#nullable disable } -} -namespace Microsoft.Maui.Authentication -{ public class WebAuthenticatorOptions { - public Uri Url { get; set; } + public Uri? Url { get; set; } - public Uri CallbackUrl { get; set; } + public Uri? CallbackUrl { get; set; } public bool PrefersEphemeralWebBrowserSession { get; set; } } - - public partial class WebAuthenticatorImplementation - { - public Task AuthenticateAsync(Uri url, Uri callbackUrl) - => AuthenticateAsync(new WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl }); - } } From f3e2a662294573acfdf971166987c43588830c83 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 24 Mar 2022 00:47:43 +0200 Subject: [PATCH 12/45] 2 to go --- .../src/Essentials/LocationExtensions.cs} | 7 +- src/Compatibility/Core/src/Essentials/Map.cs | 40 +- .../src/Essentials/PlacemarkExtensions.cs | 19 + .../Core/src/Essentials/Platform.cs | 68 +++- .../src/AppActions/AppActions.android.cs | 3 + .../src/AppActions/AppActions.shared.cs | 27 +- src/Essentials/src/AppInfo/AppInfo.android.cs | 23 +- .../src/Barometer/Barometer.shared.cs | 5 +- src/Essentials/src/Battery/Battery.android.cs | 22 +- src/Essentials/src/Battery/Battery.macos.cs | 2 +- src/Essentials/src/Battery/Battery.shared.cs | 20 +- src/Essentials/src/Battery/Battery.tizen.cs | 10 +- src/Essentials/src/Battery/Battery.uwp.cs | 11 +- src/Essentials/src/Compass/Compass.shared.cs | 2 + src/Essentials/src/Email/Email.shared.cs | 4 +- .../src/FileSystem/FileSystem.android.cs | 337 ---------------- .../src/FileSystem/FileSystem.shared.cs | 12 +- .../src/FileSystem/FileSystemUtils.android.cs | 374 +++++++++++++++++ .../src/FileSystem/FileSystemUtils.shared.cs | 13 + .../src/Permissions/Permissions.shared.cs | 1 - .../Platform/ActivityStateManager.android.cs | 174 ++++++++ .../Platform/IntermediateActivity.android.cs | 150 +++++++ .../src/Platform/Platform.android.cs | 376 +----------------- .../src/Platform/Platform.ios.tvos.watchos.cs | 110 +---- src/Essentials/src/Platform/Platform.macos.cs | 2 +- .../src/Platform/Platform.shared.cs | 8 - src/Essentials/src/Platform/Platform.tizen.cs | 2 +- src/Essentials/src/Platform/Platform.uwp.cs | 73 +--- .../UIPresentationControllerDelegate.ios.cs | 25 ++ .../src/Platform/WindowStateManager.ios.cs | 96 +++++ .../src/Platform/WindowStateManager.uwp.cs | 77 ++++ ...eenshot.netstandard.tizen.watchos.macos.cs | 8 +- .../src/Types/DisplayInfo.shared.cs | 1 - .../src/Types/FileProvider.android.cs | 22 +- src/Essentials/src/Types/Location.shared.cs | 4 +- .../src/Types/LocationExtensions.android.cs | 14 +- ...cationExtensions.ios.tvos.watchos.macos.cs | 6 +- .../src/Types/LocationExtensions.uwp.cs | 26 +- .../src/Types/PlacemarkExtensions.android.cs | 2 +- ...cemarkExtensions.ios.tvos.watchos.macos.cs | 2 +- .../src/Types/PlacemarkExtensions.shared.cs | 11 +- .../src/Types/PlacemarkExtensions.uwp.cs | 2 +- .../Types/Shared/PreserveAttribute.shared.cs | 25 -- .../src/Types/Shared/WebUtils.shared.cs | 24 +- .../UnitConverters.shared.cs | 12 +- .../WebAuthenticator.shared.cs | 25 +- .../test/UnitTests/UnitConverters_Tests.cs | 2 +- 47 files changed, 1171 insertions(+), 1108 deletions(-) rename src/{Essentials/src/Types/LocationExtensions.shared.cs => Compatibility/Core/src/Essentials/LocationExtensions.cs} (90%) create mode 100644 src/Compatibility/Core/src/Essentials/PlacemarkExtensions.cs create mode 100644 src/Essentials/src/FileSystem/FileSystemUtils.android.cs create mode 100644 src/Essentials/src/FileSystem/FileSystemUtils.shared.cs create mode 100644 src/Essentials/src/Platform/ActivityStateManager.android.cs create mode 100644 src/Essentials/src/Platform/IntermediateActivity.android.cs delete mode 100644 src/Essentials/src/Platform/Platform.shared.cs create mode 100644 src/Essentials/src/Platform/UIPresentationControllerDelegate.ios.cs create mode 100644 src/Essentials/src/Platform/WindowStateManager.ios.cs create mode 100644 src/Essentials/src/Platform/WindowStateManager.uwp.cs delete mode 100644 src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs rename src/Essentials/src/{Types => UnitConverters}/UnitConverters.shared.cs (97%) diff --git a/src/Essentials/src/Types/LocationExtensions.shared.cs b/src/Compatibility/Core/src/Essentials/LocationExtensions.cs similarity index 90% rename from src/Essentials/src/Types/LocationExtensions.shared.cs rename to src/Compatibility/Core/src/Essentials/LocationExtensions.cs index a776d645092f..906217a8bd8c 100644 --- a/src/Essentials/src/Types/LocationExtensions.shared.cs +++ b/src/Compatibility/Core/src/Essentials/LocationExtensions.cs @@ -1,10 +1,11 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Devices.Sensors +namespace Microsoft.Maui.Essentials { /// - public static partial class LocationExtensions + public static class LocationExtensions { /// public static double CalculateDistance(this Location locationStart, double latitudeEnd, double longitudeEnd, DistanceUnits units) => diff --git a/src/Compatibility/Core/src/Essentials/Map.cs b/src/Compatibility/Core/src/Essentials/Map.cs index 04ac16a49736..fe2a684ed25e 100644 --- a/src/Compatibility/Core/src/Essentials/Map.cs +++ b/src/Compatibility/Core/src/Essentials/Map.cs @@ -1,5 +1,4 @@ #nullable enable -using System; using System.Threading.Tasks; using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices.Sensors; @@ -11,48 +10,27 @@ public static class Map { /// public static Task OpenAsync(Location location) => - OpenAsync(location, new MapLaunchOptions()); + Current.OpenAsync(location); /// - public static Task OpenAsync(Location location, MapLaunchOptions options) - { - if (location == null) - throw new ArgumentNullException(nameof(location)); - - if (options == null) - throw new ArgumentNullException(nameof(options)); - - return Current.OpenAsync(location.Latitude, location.Longitude, options); - } + public static Task OpenAsync(Location location, MapLaunchOptions options) => + Current.OpenAsync(location, options); /// public static Task OpenAsync(double latitude, double longitude) => - OpenAsync(latitude, longitude, new MapLaunchOptions()); + Current.OpenAsync(latitude, longitude); /// - public static Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) - { - if (options == null) - throw new ArgumentNullException(nameof(options)); - - return Current.OpenAsync(latitude, longitude, options); - } + public static Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) => + Current.OpenAsync(latitude, longitude, options); /// public static Task OpenAsync(Placemark placemark) => - OpenAsync(placemark, new MapLaunchOptions()); + Current.OpenAsync(placemark); /// - public static Task OpenAsync(Placemark placemark, MapLaunchOptions options) - { - if (placemark == null) - throw new ArgumentNullException(nameof(placemark)); - - if (options == null) - throw new ArgumentNullException(nameof(options)); - - return Current.OpenAsync(placemark, options); - } + public static Task OpenAsync(Placemark placemark, MapLaunchOptions options) => + Current.OpenAsync(placemark, options); static IMap Current => ApplicationModel.Map.Default; } diff --git a/src/Compatibility/Core/src/Essentials/PlacemarkExtensions.cs b/src/Compatibility/Core/src/Essentials/PlacemarkExtensions.cs new file mode 100644 index 000000000000..f1b3a4c0f4b2 --- /dev/null +++ b/src/Compatibility/Core/src/Essentials/PlacemarkExtensions.cs @@ -0,0 +1,19 @@ +#nullable enable +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Devices.Sensors; + +namespace Microsoft.Maui.Essentials +{ + /// + public static partial class PlacemarkExtensions + { + /// + public static Task OpenMapsAsync(this Placemark placemark, MapLaunchOptions options) => + Map.OpenAsync(placemark, options); + + /// + public static Task OpenMapsAsync(this Placemark placemark) => + Map.OpenAsync(placemark); + } +} diff --git a/src/Compatibility/Core/src/Essentials/Platform.cs b/src/Compatibility/Core/src/Essentials/Platform.cs index 79bff7f8281d..fd15a296e900 100644 --- a/src/Compatibility/Core/src/Essentials/Platform.cs +++ b/src/Compatibility/Core/src/Essentials/Platform.cs @@ -1,27 +1,67 @@ -using Microsoft.Maui.ApplicationModel; +#nullable enable +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Maui.ApplicationModel; +using Microsoft.Maui.Authentication; namespace Microsoft.Maui.Essentials { public static class Platform { #if ANDROID - public static void OnNewIntent(Android.Content.Intent intent) - { - if (ApplicationModel.AppActions.Current is IPlatformAppActions platform) - platform.OnNewIntent(intent); - } - public static void OnResume(Android.App.Activity activity = null) + public static class Intent { - if (ApplicationModel.AppActions.Current is IPlatformAppActions platform) - platform.OnNewIntent(activity?.Intent); + public const string ActionAppAction = ApplicationModel.AppActionsImplementation.IntentAction; } + + public static Android.Content.Context AppContext => Android.App.Application.Context; + + // ActivityStateManager + + public static Android.App.Activity? CurrentActivity => + ActivityStateManager.Default.CurrentActivity; + + public static event EventHandler? ActivityStateChanged; + + public static Task WaitForActivityAsync(CancellationToken cancelToken = default) => + ActivityStateManager.Default.WaitForActivityAsync(cancelToken); + + public static void Init(Android.App.Application application) => + ActivityStateManager.Default.Init(application); + + public static void Init(Android.App.Activity activity, Android.OS.Bundle? bundle) => + ActivityStateManager.Default.Init(activity, bundle); + + // Permissions + + public static void OnRequestPermissionsResult(int requestCode, string[] permissions, Android.Content.PM.Permission[] grantResults) => + Permissions.Default.OnRequestPermissionsResult(requestCode, permissions, grantResults); + + // AppActions + + public static void OnNewIntent(Android.Content.Intent? intent) => + ApplicationModel.AppActions.Current.OnNewIntent(intent); + + public static void OnResume(Android.App.Activity? activity = null) => + ApplicationModel.AppActions.Current.OnResume(activity?.Intent); + #elif IOS || MACCATALYST - public static void PerformActionForShortcutItem(UIKit.UIApplication application, UIKit.UIApplicationShortcutItem shortcutItem, UIKit.UIOperationHandler completionHandler) - { - if (ApplicationModel.AppActions.Current is IPlatformAppActions platform) - platform.PerformActionForShortcutItem(application, shortcutItem, completionHandler); - } + + public static bool OpenUrl(UIKit.UIApplication app, Foundation.NSUrl url, Foundation.NSDictionary options) => + Authentication.WebAuthenticator.Default.OpenUrl(new Uri(url.AbsoluteString)); + + public static bool ContinueUserActivity(UIKit.UIApplication application, Foundation.NSUserActivity userActivity, UIKit.UIApplicationRestorationHandler completionHandler) => + Authentication.WebAuthenticator.Default.OpenUrl(new Uri(userActivity?.WebPageUrl?.AbsoluteString)); + + public static void PerformActionForShortcutItem(UIKit.UIApplication application, UIKit.UIApplicationShortcutItem shortcutItem, UIKit.UIOperationHandler completionHandler) => + ApplicationModel.AppActions.Current.PerformActionForShortcutItem(application, shortcutItem, completionHandler); + + public static void Init(Func getCurrentUIViewController); + + public static UIKit.UIViewController GetCurrentUIViewController(); + #elif WINDOWS public static async void OnLaunched(UI.Xaml.LaunchActivatedEventArgs e) { diff --git a/src/Essentials/src/AppActions/AppActions.android.cs b/src/Essentials/src/AppActions/AppActions.android.cs index dd7c155386f3..ef942df8252b 100755 --- a/src/Essentials/src/AppActions/AppActions.android.cs +++ b/src/Essentials/src/AppActions/AppActions.android.cs @@ -48,6 +48,9 @@ public Task SetAsync(IEnumerable actions) public event EventHandler AppActionActivated; + public void OnResume(Intent intent) => + OnNewIntent(intent); + public void OnNewIntent(Intent intent) { if (intent?.Action == IntentAction) diff --git a/src/Essentials/src/AppActions/AppActions.shared.cs b/src/Essentials/src/AppActions/AppActions.shared.cs index 4af709ca325b..1fe9ab540612 100755 --- a/src/Essentials/src/AppActions/AppActions.shared.cs +++ b/src/Essentials/src/AppActions/AppActions.shared.cs @@ -1,7 +1,6 @@ #nullable enable using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; namespace Microsoft.Maui.ApplicationModel @@ -25,6 +24,7 @@ public interface IPlatformAppActions void PerformActionForShortcutItem(UIKit.UIApplication application, UIKit.UIApplicationShortcutItem shortcutItem, UIKit.UIOperationHandler completionHandler); #elif ANDROID void OnNewIntent(Android.Content.Intent? intent); + void OnResume(Android.Content.Intent? intent); #endif } @@ -39,6 +39,31 @@ internal static void SetCurrent(IAppActions? implementation) => currentImplementation = implementation; } + public static partial class AppActionsExtensions + { + static IPlatformAppActions AsPlatform(this IAppActions appActions) + { + if (appActions is not IPlatformAppActions platform) + throw new PlatformNotSupportedException("This implementation of IAppActions does not implement IPlatformAppActions."); + + return platform; + } + +#if WINDOWS + public static Task OnLaunched(this IAppActions appActions, UI.Xaml.LaunchActivatedEventArgs e) => + appActions.AsPlatform().OnLaunched(e); +#elif IOS || MACCATALYST + public static void PerformActionForShortcutItem(this IAppActions appActions, UIKit.UIApplication application, UIKit.UIApplicationShortcutItem shortcutItem, UIKit.UIOperationHandler completionHandler) => + appActions.AsPlatform().PerformActionForShortcutItem(application, shortcutItem, completionHandler); +#elif ANDROID + public static void OnNewIntent(this IAppActions appActions, Android.Content.Intent? intent) => + appActions.AsPlatform().OnNewIntent(intent); + + public static void OnResume(this IAppActions appActions, Android.Content.Intent? intent) => + appActions.AsPlatform().OnResume(intent); +#endif + } + /// public class AppActionEventArgs : EventArgs { diff --git a/src/Essentials/src/AppInfo/AppInfo.android.cs b/src/Essentials/src/AppInfo/AppInfo.android.cs index 61159189a981..d5dbef42bf3e 100644 --- a/src/Essentials/src/AppInfo/AppInfo.android.cs +++ b/src/Essentials/src/AppInfo/AppInfo.android.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using Android.App; using Android.Content; using Android.Content.PM; using Android.Content.Res; @@ -10,14 +11,14 @@ namespace Microsoft.Maui.ApplicationModel { class AppInfoImplementation : IAppInfo { - public string PackageName => Platform.AppContext.PackageName; + public string PackageName => Application.Context.PackageName; public string Name { get { - var applicationInfo = Platform.AppContext.ApplicationInfo; - var packageManager = Platform.AppContext.PackageManager; + var applicationInfo = Application.Context.ApplicationInfo; + var packageManager = Application.Context.PackageManager; return applicationInfo.LoadLabel(packageManager); } } @@ -28,8 +29,8 @@ public string VersionString { get { - var pm = Platform.AppContext.PackageManager; - var packageName = Platform.AppContext.PackageName; + var pm = Application.Context.PackageManager; + var packageName = Application.Context.PackageName; using (var info = pm.GetPackageInfo(packageName, PackageInfoFlags.MetaData)) { return info.VersionName; @@ -41,8 +42,8 @@ public string BuildString { get { - var pm = Platform.AppContext.PackageManager; - var packageName = Platform.AppContext.PackageName; + var pm = Application.Context.PackageManager; + var packageName = Application.Context.PackageName; using (var info = pm.GetPackageInfo(packageName, PackageInfoFlags.MetaData)) { #if __ANDROID_28__ @@ -58,7 +59,7 @@ public string BuildString public void ShowSettingsUI() { - var context = Platform.GetCurrentActivity(false) ?? Platform.AppContext; + var context = Platform.GetCurrentActivity(false) ?? Application.Context; var settingsIntent = new Intent(); settingsIntent.SetAction(global::Android.Provider.Settings.ActionApplicationDetailsSettings); @@ -68,7 +69,7 @@ public void ShowSettingsUI() var flags = ActivityFlags.NewTask | ActivityFlags.NoHistory | ActivityFlags.ExcludeFromRecents; #if __ANDROID_24__ - if (Platform.HasApiLevelN) + if (OperatingSystem.IsAndroidVersionAtLeast(24)) flags |= ActivityFlags.LaunchAdjacent; #endif settingsIntent.SetFlags(flags); @@ -77,7 +78,7 @@ public void ShowSettingsUI() } public AppTheme RequestedTheme - => (Platform.AppContext.Resources.Configuration.UiMode & UiMode.NightMask) switch + => (Application.Context.Resources.Configuration.UiMode & UiMode.NightMask) switch { UiMode.NightYes => AppTheme.Dark, UiMode.NightNo => AppTheme.Light, @@ -93,7 +94,7 @@ public LayoutDirection RequestedLayoutDirection if (!OperatingSystem.IsAndroidVersionAtLeast(17)) return LayoutDirection.LeftToRight; - var config = Platform.AppContext.Resources?.Configuration; + var config = Application.Context.Resources?.Configuration; if (config == null) return LayoutDirection.Unknown; diff --git a/src/Essentials/src/Barometer/Barometer.shared.cs b/src/Essentials/src/Barometer/Barometer.shared.cs index dce9350f2c7c..a9a2045cfd01 100644 --- a/src/Essentials/src/Barometer/Barometer.shared.cs +++ b/src/Essentials/src/Barometer/Barometer.shared.cs @@ -1,8 +1,5 @@ #nullable enable using System; -using System.ComponentModel; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Devices.Sensors; namespace Microsoft.Maui.Devices.Sensors { @@ -97,7 +94,7 @@ void RaiseReadingChanged(BarometerData reading) public void Start(SensorSpeed sensorSpeed) { - if (!PlatformIsSupported) + if (!IsSupported) throw new FeatureNotSupportedException(); if (IsMonitoring) diff --git a/src/Essentials/src/Battery/Battery.android.cs b/src/Essentials/src/Battery/Battery.android.cs index f9cc6f23d1db..53b781210088 100755 --- a/src/Essentials/src/Battery/Battery.android.cs +++ b/src/Essentials/src/Battery/Battery.android.cs @@ -1,4 +1,5 @@ using System; +using Android.App; using Android.Content; using Android.OS; using Microsoft.Maui.ApplicationModel; @@ -7,20 +8,25 @@ namespace Microsoft.Maui.Devices { partial class BatteryImplementation : IBattery { + static PowerManager powerManager; + + static PowerManager PowerManager => + powerManager ??= Application.Context.GetSystemService(Context.PowerService) as PowerManager; + BatteryBroadcastReceiver batteryReceiver; EnergySaverBroadcastReceiver powerReceiver; void StartEnergySaverListeners() { powerReceiver = new EnergySaverBroadcastReceiver(OnEnergySaverChanged); - Platform.AppContext.RegisterReceiver(powerReceiver, new IntentFilter(PowerManager.ActionPowerSaveModeChanged)); + Application.Context.RegisterReceiver(powerReceiver, new IntentFilter(PowerManager.ActionPowerSaveModeChanged)); } void StopEnergySaverListeners() { try { - Platform.AppContext.UnregisterReceiver(powerReceiver); + Application.Context.UnregisterReceiver(powerReceiver); } catch (Java.Lang.IllegalArgumentException) { @@ -34,7 +40,7 @@ public EnergySaverStatus EnergySaverStatus { get { - var status = Platform.PowerManager?.IsPowerSaveMode ?? false; + var status = PowerManager?.IsPowerSaveMode ?? false; return status ? EnergySaverStatus.On : EnergySaverStatus.Off; } } @@ -44,14 +50,14 @@ void StartBatteryListeners() Permissions.EnsureDeclared(); batteryReceiver = new BatteryBroadcastReceiver(OnBatteryInfoChanged); - Platform.AppContext.RegisterReceiver(batteryReceiver, new IntentFilter(Intent.ActionBatteryChanged)); + Application.Context.RegisterReceiver(batteryReceiver, new IntentFilter(Intent.ActionBatteryChanged)); } void StopBatteryListeners() { try { - Platform.AppContext.UnregisterReceiver(batteryReceiver); + Application.Context.UnregisterReceiver(batteryReceiver); } catch (Java.Lang.IllegalArgumentException) { @@ -68,7 +74,7 @@ public double ChargeLevel Permissions.EnsureDeclared(); using (var filter = new IntentFilter(Intent.ActionBatteryChanged)) - using (var battery = Platform.AppContext.RegisterReceiver(null, filter)) + using (var battery = Application.Context.RegisterReceiver(null, filter)) { var level = battery.GetIntExtra(BatteryManager.ExtraLevel, -1); var scale = battery.GetIntExtra(BatteryManager.ExtraScale, -1); @@ -88,7 +94,7 @@ public BatteryState State Permissions.EnsureDeclared(); using (var filter = new IntentFilter(Intent.ActionBatteryChanged)) - using (var battery = Platform.AppContext.RegisterReceiver(null, filter)) + using (var battery = Application.Context.RegisterReceiver(null, filter)) { var status = battery.GetIntExtra(BatteryManager.ExtraStatus, -1); switch (status) @@ -115,7 +121,7 @@ public BatteryPowerSource PowerSource Permissions.EnsureDeclared(); using (var filter = new IntentFilter(Intent.ActionBatteryChanged)) - using (var battery = Platform.AppContext.RegisterReceiver(null, filter)) + using (var battery = Application.Context.RegisterReceiver(null, filter)) { var chargePlug = battery.GetIntExtra(BatteryManager.ExtraPlugged, -1); diff --git a/src/Essentials/src/Battery/Battery.macos.cs b/src/Essentials/src/Battery/Battery.macos.cs index 9b7ae837897c..b1b5a042bdc1 100755 --- a/src/Essentials/src/Battery/Battery.macos.cs +++ b/src/Essentials/src/Battery/Battery.macos.cs @@ -22,7 +22,7 @@ void StopBatteryListeners() } } - public void PowerSourceNotification() + void PowerSourceNotification() => MainThread.BeginInvokeOnMainThread(OnBatteryInfoChanged); public double ChargeLevel => IOKit.GetInternalBatteryChargeLevel(); diff --git a/src/Essentials/src/Battery/Battery.shared.cs b/src/Essentials/src/Battery/Battery.shared.cs index b6368db31165..b64d82de5ba4 100755 --- a/src/Essentials/src/Battery/Battery.shared.cs +++ b/src/Essentials/src/Battery/Battery.shared.cs @@ -73,20 +73,20 @@ public event EventHandler EnergySaverStatusCh static BatteryPowerSource currentSource; static BatteryState currentState; - static void SetCurrent() + void SetCurrent() { - currentLevel = Battery.ChargeLevel; - currentSource = Battery.PowerSource; - currentState = Battery.State; + currentLevel = ChargeLevel; + currentSource = PowerSource; + currentState = State; } - static void OnBatteryInfoChanged(double level, BatteryState state, BatteryPowerSource source) + void OnBatteryInfoChanged(double level, BatteryState state, BatteryPowerSource source) => OnBatteryInfoChanged(new BatteryInfoChangedEventArgs(level, state, source)); - static void OnBatteryInfoChanged() + void OnBatteryInfoChanged() => OnBatteryInfoChanged(ChargeLevel, State, PowerSource); - static void OnBatteryInfoChanged(BatteryInfoChangedEventArgs e) + void OnBatteryInfoChanged(BatteryInfoChangedEventArgs e) { if (currentLevel != e.ChargeLevel || currentSource != e.PowerSource || currentState != e.State) { @@ -95,13 +95,13 @@ static void OnBatteryInfoChanged(BatteryInfoChangedEventArgs e) } } - static void OnEnergySaverChanged() + void OnEnergySaverChanged() => OnEnergySaverChanged(EnergySaverStatus); - static void OnEnergySaverChanged(EnergySaverStatus saverStatus) + void OnEnergySaverChanged(EnergySaverStatus saverStatus) => OnEnergySaverChanged(new EnergySaverStatusChangedEventArgs(saverStatus)); - static void OnEnergySaverChanged(EnergySaverStatusChangedEventArgs e) + void OnEnergySaverChanged(EnergySaverStatusChangedEventArgs e) => EnergySaverStatusChangedInternal?.Invoke(null, e); } diff --git a/src/Essentials/src/Battery/Battery.tizen.cs b/src/Essentials/src/Battery/Battery.tizen.cs index 64db5ca6c53f..8631755f5423 100755 --- a/src/Essentials/src/Battery/Battery.tizen.cs +++ b/src/Essentials/src/Battery/Battery.tizen.cs @@ -8,21 +8,21 @@ partial class BatteryImplementation : IBattery void OnChanged(object sender, object e) => MainThread.BeginInvokeOnMainThread(OnBatteryInfoChanged); - public void StartBatteryListeners() + void StartBatteryListeners() { TizenBattery.PercentChanged += OnChanged; TizenBattery.ChargingStateChanged += OnChanged; TizenBattery.LevelChanged += OnChanged; } - public void StopBatteryListeners() + void StopBatteryListeners() { TizenBattery.PercentChanged -= OnChanged; TizenBattery.ChargingStateChanged -= OnChanged; TizenBattery.LevelChanged -= OnChanged; } - public double PlatformChargeLevel + public double ChargeLevel { get { @@ -50,10 +50,10 @@ public BatteryPowerSource PowerSource } } - public void StartEnergySaverListeners() + void StartEnergySaverListeners() => throw new FeatureNotSupportedException("This API is not currently supported on Tizen."); - public void StopEnergySaverListeners() + void StopEnergySaverListeners() => throw new FeatureNotSupportedException("This API is not currently supported on Tizen."); public EnergySaverStatus EnergySaverStatus diff --git a/src/Essentials/src/Battery/Battery.uwp.cs b/src/Essentials/src/Battery/Battery.uwp.cs index fae013c04039..5ec1d2a061c1 100755 --- a/src/Essentials/src/Battery/Battery.uwp.cs +++ b/src/Essentials/src/Battery/Battery.uwp.cs @@ -1,18 +1,17 @@ -using Microsoft.Maui.ApplicationModel; using Windows.System.Power; namespace Microsoft.Maui.Devices { partial class BatteryImplementation : IBattery { - public void StartEnergySaverListeners() => + void StartEnergySaverListeners() => PowerManager.EnergySaverStatusChanged += ReportEnergySaverUpdated; - public void StopEnergySaverListeners() => + void StopEnergySaverListeners() => PowerManager.EnergySaverStatusChanged -= ReportEnergySaverUpdated; void ReportEnergySaverUpdated(object sender, object e) - => MainThread.BeginInvokeOnMainThread(Battery.OnEnergySaverChanged); + => MainThread.BeginInvokeOnMainThread(OnEnergySaverChanged); public void StartBatteryListeners() => DefaultBattery.ReportUpdated += ReportUpdated; @@ -20,8 +19,8 @@ public void StartBatteryListeners() => public void StopBatteryListeners() => DefaultBattery.ReportUpdated -= ReportUpdated; - void ReportUpdated(object sender, object e) - => MainThread.BeginInvokeOnMainThread(Battery.OnBatteryInfoChanged); + void ReportUpdated(object sender, object e) + => MainThread.BeginInvokeOnMainThread(OnBatteryInfoChanged); global::Windows.Devices.Power.Battery DefaultBattery => global::Windows.Devices.Power.Battery.AggregateBattery; diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index ba751658031e..8f83927adc6e 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -38,6 +38,7 @@ internal static void SetDefault(ICompass? implementation) => public static class CompassExtensions { +#if IOS || MACCATALYST public static void SetShouldDisplayHeadingCalibration(this ICompass compass, bool shouldDisplay) { if (compass is IPlatformCompass platform) @@ -45,6 +46,7 @@ public static void SetShouldDisplayHeadingCalibration(this ICompass compass, boo platform.ShouldDisplayHeadingCalibration = shouldDisplay; } } +#endif } /// diff --git a/src/Essentials/src/Email/Email.shared.cs b/src/Essentials/src/Email/Email.shared.cs index 87f4c453f5aa..a6db9778b8de 100644 --- a/src/Essentials/src/Email/Email.shared.cs +++ b/src/Essentials/src/Email/Email.shared.cs @@ -40,9 +40,9 @@ static string GetMailToUri(EmailMessage message) var parts = new List(); if (!string.IsNullOrEmpty(message?.Body)) - parts.Add("body=" + Uri.EscapeDataString(message.Body)); + parts.Add("body=" + Uri.EscapeDataString(message!.Body)); if (!string.IsNullOrEmpty(message?.Subject)) - parts.Add("subject=" + Uri.EscapeDataString(message.Subject)); + parts.Add("subject=" + Uri.EscapeDataString(message!.Subject)); if (message?.Cc?.Count > 0) parts.Add("cc=" + Uri.EscapeDataString(string.Join(",", message.Cc))); if (message?.Bcc?.Count > 0) diff --git a/src/Essentials/src/FileSystem/FileSystem.android.cs b/src/Essentials/src/FileSystem/FileSystem.android.cs index e5052314db7f..8327da20eea1 100644 --- a/src/Essentials/src/FileSystem/FileSystem.android.cs +++ b/src/Essentials/src/FileSystem/FileSystem.android.cs @@ -1,12 +1,8 @@ using System; -using System.Diagnostics; using System.IO; using System.Threading.Tasks; using Android.App; -using Android.Provider; using Android.Webkit; -using Microsoft.Maui.ApplicationModel; -using AndroidUri = Android.Net.Uri; namespace Microsoft.Maui.Storage { @@ -52,339 +48,6 @@ Stream PlatformOpenAppPackageFile(string filename) } } - static partial class FileSystemUtils - { - internal const string EssentialsFolderHash = "2203693cc04e0be7f4f024d5f9499e13"; - - const string storageTypePrimary = "primary"; - const string storageTypeRaw = "raw"; - const string storageTypeImage = "image"; - const string storageTypeVideo = "video"; - const string storageTypeAudio = "audio"; - static readonly string[] contentUriPrefixes = - { - "content://downloads/public_downloads", - "content://downloads/my_downloads", - "content://downloads/all_downloads", - }; - - internal const string UriSchemeFile = "file"; - internal const string UriSchemeContent = "content"; - - internal const string UriAuthorityExternalStorage = "com.android.externalstorage.documents"; - internal const string UriAuthorityDownloads = "com.android.providers.downloads.documents"; - internal const string UriAuthorityMedia = "com.android.providers.media.documents"; - - public static Java.IO.File GetTemporaryFile(Java.IO.File root, string fileName) - { - // create the directory for all Essentials files - var rootDir = new Java.IO.File(root, EssentialsFolderHash); - rootDir.Mkdirs(); - rootDir.DeleteOnExit(); - - // create a unique directory just in case there are multiple file with the same name - var tmpDir = new Java.IO.File(rootDir, Guid.NewGuid().ToString("N")); - tmpDir.Mkdirs(); - tmpDir.DeleteOnExit(); - - // create the new temporary file - var tmpFile = new Java.IO.File(tmpDir, fileName); - tmpFile.DeleteOnExit(); - - return tmpFile; - } - - public static string EnsurePhysicalPath(AndroidUri uri, bool requireExtendedAccess = true) - { - // if this is a file, use that - if (uri.Scheme.Equals(UriSchemeFile, StringComparison.OrdinalIgnoreCase)) - return uri.Path; - - // try resolve using the content provider - var absolute = ResolvePhysicalPath(uri, requireExtendedAccess); - if (!string.IsNullOrWhiteSpace(absolute) && Path.IsPathRooted(absolute)) - return absolute; - - // fall back to just copying it - var cached = CacheContentFile(uri); - if (!string.IsNullOrWhiteSpace(cached) && Path.IsPathRooted(cached)) - return cached; - - throw new FileNotFoundException($"Unable to resolve absolute path or retrieve contents of URI '{uri}'."); - } - - static string ResolvePhysicalPath(AndroidUri uri, bool requireExtendedAccess = true) - { - if (uri.Scheme.Equals(UriSchemeFile, StringComparison.OrdinalIgnoreCase)) - { - // if it is a file, then return directly - - var resolved = uri.Path; - if (File.Exists(resolved)) - return resolved; - } - else if (!requireExtendedAccess || !OperatingSystem.IsAndroidVersionAtLeast(29)) - { - // if this is on an older OS version, or we just need it now - - if (Platform.HasApiLevelKitKat && DocumentsContract.IsDocumentUri(Application.Context, uri)) - { - var resolved = ResolveDocumentPath(uri); - if (File.Exists(resolved)) - return resolved; - } - else if (uri.Scheme.Equals(UriSchemeContent, StringComparison.OrdinalIgnoreCase)) - { - var resolved = ResolveContentPath(uri); - if (File.Exists(resolved)) - return resolved; - } - } - - return null; - } - - static string ResolveDocumentPath(AndroidUri uri) - { - Debug.WriteLine($"Trying to resolve document URI: '{uri}'"); - - var docId = DocumentsContract.GetDocumentId(uri); - - var docIdParts = docId?.Split(':'); - if (docIdParts == null || docIdParts.Length == 0) - return null; - - if (uri.Authority.Equals(UriAuthorityExternalStorage, StringComparison.OrdinalIgnoreCase)) - { - Debug.WriteLine($"Resolving external storage URI: '{uri}'"); - - if (docIdParts.Length == 2) - { - var storageType = docIdParts[0]; - var uriPath = docIdParts[1]; - - // This is the internal "external" memory, NOT the SD Card - if (storageType.Equals(storageTypePrimary, StringComparison.OrdinalIgnoreCase)) - { -#pragma warning disable CS0618 // Type or member is obsolete - var root = global::Android.OS.Environment.ExternalStorageDirectory.Path; -#pragma warning restore CS0618 // Type or member is obsolete - - return Path.Combine(root, uriPath); - } - - // TODO: support other types, such as actual SD Cards - } - } - else if (uri.Authority.Equals(UriAuthorityDownloads, StringComparison.OrdinalIgnoreCase)) - { - Debug.WriteLine($"Resolving downloads URI: '{uri}'"); - - // NOTE: This only really applies to older Android vesions since the privacy changes - - if (docIdParts.Length == 2) - { - var storageType = docIdParts[0]; - var uriPath = docIdParts[1]; - - if (storageType.Equals(storageTypeRaw, StringComparison.OrdinalIgnoreCase)) - return uriPath; - } - - // ID could be "###" or "msf:###" - var fileId = docIdParts.Length == 2 - ? docIdParts[1] - : docIdParts[0]; - - foreach (var prefix in contentUriPrefixes) - { - var uriString = prefix + "/" + fileId; - var contentUri = AndroidUri.Parse(uriString); - - if (GetDataFilePath(contentUri) is string filePath) - return filePath; - } - } - else if (uri.Authority.Equals(UriAuthorityMedia, StringComparison.OrdinalIgnoreCase)) - { - Debug.WriteLine($"Resolving media URI: '{uri}'"); - - if (docIdParts.Length == 2) - { - var storageType = docIdParts[0]; - var uriPath = docIdParts[1]; - - AndroidUri contentUri = null; - if (storageType.Equals(storageTypeImage, StringComparison.OrdinalIgnoreCase)) - contentUri = MediaStore.Images.Media.ExternalContentUri; - else if (storageType.Equals(storageTypeVideo, StringComparison.OrdinalIgnoreCase)) - contentUri = MediaStore.Video.Media.ExternalContentUri; - else if (storageType.Equals(storageTypeAudio, StringComparison.OrdinalIgnoreCase)) - contentUri = MediaStore.Audio.Media.ExternalContentUri; -#pragma warning disable CS0618 - if (contentUri != null && GetDataFilePath(contentUri, $"{MediaStore.MediaColumns.Id}=?", new[] { uriPath }) is string filePath) - return filePath; -#pragma warning restore CS0618 - } - } - - Debug.WriteLine($"Unable to resolve document URI: '{uri}'"); - - return null; - } - - static string ResolveContentPath(AndroidUri uri) - { - Debug.WriteLine($"Trying to resolve content URI: '{uri}'"); - - if (GetDataFilePath(uri) is string filePath) - return filePath; - - // TODO: support some additional things, like Google Photos if that is possible - - Debug.WriteLine($"Unable to resolve content URI: '{uri}'"); - - return null; - } - - static string CacheContentFile(AndroidUri uri) - { - if (!uri.Scheme.Equals(UriSchemeContent, StringComparison.OrdinalIgnoreCase)) - return null; - - Debug.WriteLine($"Copying content URI to local cache: '{uri}'"); - - // open the source stream - using var srcStream = OpenContentStream(uri, out var extension); - if (srcStream == null) - return null; - - // resolve or generate a valid destination path -#pragma warning disable CS0618 - var filename = GetColumnValue(uri, MediaStore.Files.FileColumns.DisplayName) ?? Guid.NewGuid().ToString("N"); -#pragma warning restore CS0618 - - if (!Path.HasExtension(filename) && !string.IsNullOrEmpty(extension)) - filename = Path.ChangeExtension(filename, extension); - - // create a temporary file - var hasPermission = Permissions.IsDeclaredInManifest(global::Android.Manifest.Permission.WriteExternalStorage); - var root = hasPermission - ? Application.Context.ExternalCacheDir - : Application.Context.CacheDir; - var tmpFile = GetTemporaryFile(root, filename); - - // copy to the destination - using var dstStream = File.Create(tmpFile.CanonicalPath); - srcStream.CopyTo(dstStream); - - return tmpFile.CanonicalPath; - } - - static Stream OpenContentStream(AndroidUri uri, out string extension) - { - var isVirtual = IsVirtualFile(uri); - if (isVirtual) - { - Debug.WriteLine($"Content URI was virtual: '{uri}'"); - return GetVirtualFileStream(uri, out extension); - } - - extension = GetFileExtension(uri); - return Platform.ContentResolver.OpenInputStream(uri); - } - - static bool IsVirtualFile(AndroidUri uri) - { - if (!DocumentsContract.IsDocumentUri(Application.Context, uri)) - return false; - - var value = GetColumnValue(uri, DocumentsContract.Document.ColumnFlags); - if (!string.IsNullOrEmpty(value) && int.TryParse(value, out var flagsInt)) - { - var flags = (DocumentContractFlags)flagsInt; - return flags.HasFlag(DocumentContractFlags.VirtualDocument); - } - - return false; - } - - static Stream GetVirtualFileStream(AndroidUri uri, out string extension) - { - var mimeTypes = Platform.ContentResolver.GetStreamTypes(uri, FileMimeTypes.All); - if (mimeTypes?.Length >= 1) - { - var mimeType = mimeTypes[0]; - - var stream = Platform.ContentResolver - .OpenTypedAssetFileDescriptor(uri, mimeType, null) - .CreateInputStream(); - - extension = MimeTypeMap.Singleton.GetExtensionFromMimeType(mimeType); - - return stream; - } - - extension = null; - return null; - } - - static string GetColumnValue(AndroidUri contentUri, string column, string selection = null, string[] selectionArgs = null) - { - try - { - var value = QueryContentResolverColumn(contentUri, column, selection, selectionArgs); - if (!string.IsNullOrEmpty(value)) - return value; - } - catch - { - // Ignore all exceptions and use null for the error indicator - } - - return null; - } - - static string GetDataFilePath(AndroidUri contentUri, string selection = null, string[] selectionArgs = null) - { -#pragma warning disable CS0618 // Type or member is obsolete - const string column = MediaStore.Files.FileColumns.Data; -#pragma warning restore CS0618 // Type or member is obsolete - - // ask the content provider for the data column, which may contain the actual file path - var path = GetColumnValue(contentUri, column, selection, selectionArgs); - if (!string.IsNullOrEmpty(path) && Path.IsPathRooted(path)) - return path; - - return null; - } - - static string GetFileExtension(AndroidUri uri) - { - var mimeType = Platform.ContentResolver.GetType(uri); - - return mimeType != null - ? MimeTypeMap.Singleton.GetExtensionFromMimeType(mimeType) - : null; - } - - static string QueryContentResolverColumn(AndroidUri contentUri, string columnName, string selection = null, string[] selectionArgs = null) - { - string text = null; - - var projection = new[] { columnName }; - using var cursor = Platform.ContentResolver.Query(contentUri, projection, selection, selectionArgs, null); - if (cursor?.MoveToFirst() == true) - { - var columnIndex = cursor.GetColumnIndex(columnName); - if (columnIndex != -1) - text = cursor.GetString(columnIndex); - } - - return text; - } - } - public partial class FileBase { internal FileBase(Java.IO.File file) diff --git a/src/Essentials/src/FileSystem/FileSystem.shared.cs b/src/Essentials/src/FileSystem/FileSystem.shared.cs index d47a3f1b03d1..37708e88164f 100644 --- a/src/Essentials/src/FileSystem/FileSystem.shared.cs +++ b/src/Essentials/src/FileSystem/FileSystem.shared.cs @@ -42,14 +42,6 @@ public Task AppPackageFileExistsAsync(string filename) => PlatformAppPackageFileExistsAsync(filename); } - static partial class FileSystemUtils - { - public static string NormalizePath(string filename) => - filename - .Replace('\\', Path.DirectorySeparatorChar) - .Replace('/', Path.DirectorySeparatorChar); - } - static class FileMimeTypes { internal const string All = "*/*"; @@ -170,7 +162,7 @@ internal string GetContentType() { // try the provided type if (!string.IsNullOrWhiteSpace(contentType)) - return contentType; + return contentType!; // try get from the file extension var ext = Path.GetExtension(FullPath); @@ -197,7 +189,7 @@ internal string GetFileName() { // try the provided file name if (!string.IsNullOrWhiteSpace(fileName)) - return fileName; + return fileName!; // try get from the path if (!string.IsNullOrWhiteSpace(FullPath)) diff --git a/src/Essentials/src/FileSystem/FileSystemUtils.android.cs b/src/Essentials/src/FileSystem/FileSystemUtils.android.cs new file mode 100644 index 000000000000..74cc61a8ccbc --- /dev/null +++ b/src/Essentials/src/FileSystem/FileSystemUtils.android.cs @@ -0,0 +1,374 @@ +using System; +using System.Diagnostics; +using System.IO; +using Android.App; +using Android.Provider; +using Android.Webkit; +using Microsoft.Maui.ApplicationModel; +using AndroidUri = Android.Net.Uri; + +namespace Microsoft.Maui.Storage +{ + static partial class FileSystemUtils + { + internal const string EssentialsFolderHash = "2203693cc04e0be7f4f024d5f9499e13"; + + const string storageTypePrimary = "primary"; + const string storageTypeRaw = "raw"; + const string storageTypeImage = "image"; + const string storageTypeVideo = "video"; + const string storageTypeAudio = "audio"; + + static readonly string[] contentUriPrefixes = + { + "content://downloads/public_downloads", + "content://downloads/my_downloads", + "content://downloads/all_downloads", + }; + + internal const string UriSchemeFile = "file"; + internal const string UriSchemeContent = "content"; + + internal const string UriAuthorityExternalStorage = "com.android.externalstorage.documents"; + internal const string UriAuthorityDownloads = "com.android.providers.downloads.documents"; + internal const string UriAuthorityMedia = "com.android.providers.media.documents"; + + public static Java.IO.File GetTemporaryFile(Java.IO.File root, string fileName) + { + // create the directory for all Essentials files + var rootDir = new Java.IO.File(root, EssentialsFolderHash); + rootDir.Mkdirs(); + rootDir.DeleteOnExit(); + + // create a unique directory just in case there are multiple file with the same name + var tmpDir = new Java.IO.File(rootDir, Guid.NewGuid().ToString("N")); + tmpDir.Mkdirs(); + tmpDir.DeleteOnExit(); + + // create the new temporary file + var tmpFile = new Java.IO.File(tmpDir, fileName); + tmpFile.DeleteOnExit(); + + return tmpFile; + } + + public static string EnsurePhysicalPath(AndroidUri uri, bool requireExtendedAccess = true) + { + // if this is a file, use that + if (uri.Scheme.Equals(UriSchemeFile, StringComparison.OrdinalIgnoreCase)) + return uri.Path; + + // try resolve using the content provider + var absolute = ResolvePhysicalPath(uri, requireExtendedAccess); + if (!string.IsNullOrWhiteSpace(absolute) && Path.IsPathRooted(absolute)) + return absolute; + + // fall back to just copying it + var cached = CacheContentFile(uri); + if (!string.IsNullOrWhiteSpace(cached) && Path.IsPathRooted(cached)) + return cached; + + throw new FileNotFoundException($"Unable to resolve absolute path or retrieve contents of URI '{uri}'."); + } + + static string ResolvePhysicalPath(AndroidUri uri, bool requireExtendedAccess = true) + { + if (uri.Scheme.Equals(UriSchemeFile, StringComparison.OrdinalIgnoreCase)) + { + // if it is a file, then return directly + + var resolved = uri.Path; + if (File.Exists(resolved)) + return resolved; + } + else if (!requireExtendedAccess || !OperatingSystem.IsAndroidVersionAtLeast(29)) + { + // if this is on an older OS version, or we just need it now + + if (OperatingSystem.IsAndroidVersionAtLeast(19) && DocumentsContract.IsDocumentUri(Application.Context, uri)) + { + var resolved = ResolveDocumentPath(uri); + if (File.Exists(resolved)) + return resolved; + } + else if (uri.Scheme.Equals(UriSchemeContent, StringComparison.OrdinalIgnoreCase)) + { + var resolved = ResolveContentPath(uri); + if (File.Exists(resolved)) + return resolved; + } + } + + return null; + } + + static string ResolveDocumentPath(AndroidUri uri) + { + Debug.WriteLine($"Trying to resolve document URI: '{uri}'"); + + var docId = DocumentsContract.GetDocumentId(uri); + + var docIdParts = docId?.Split(':'); + if (docIdParts == null || docIdParts.Length == 0) + return null; + + if (uri.Authority.Equals(UriAuthorityExternalStorage, StringComparison.OrdinalIgnoreCase)) + { + Debug.WriteLine($"Resolving external storage URI: '{uri}'"); + + if (docIdParts.Length == 2) + { + var storageType = docIdParts[0]; + var uriPath = docIdParts[1]; + + // This is the internal "external" memory, NOT the SD Card + if (storageType.Equals(storageTypePrimary, StringComparison.OrdinalIgnoreCase)) + { +#pragma warning disable CS0618 // Type or member is obsolete + var root = global::Android.OS.Environment.ExternalStorageDirectory.Path; +#pragma warning restore CS0618 // Type or member is obsolete + + return Path.Combine(root, uriPath); + } + + // TODO: support other types, such as actual SD Cards + } + } + else if (uri.Authority.Equals(UriAuthorityDownloads, StringComparison.OrdinalIgnoreCase)) + { + Debug.WriteLine($"Resolving downloads URI: '{uri}'"); + + // NOTE: This only really applies to older Android vesions since the privacy changes + + if (docIdParts.Length == 2) + { + var storageType = docIdParts[0]; + var uriPath = docIdParts[1]; + + if (storageType.Equals(storageTypeRaw, StringComparison.OrdinalIgnoreCase)) + return uriPath; + } + + // ID could be "###" or "msf:###" + var fileId = docIdParts.Length == 2 + ? docIdParts[1] + : docIdParts[0]; + + foreach (var prefix in contentUriPrefixes) + { + var uriString = prefix + "/" + fileId; + var contentUri = AndroidUri.Parse(uriString); + + if (GetDataFilePath(contentUri) is string filePath) + return filePath; + } + } + else if (uri.Authority.Equals(UriAuthorityMedia, StringComparison.OrdinalIgnoreCase)) + { + Debug.WriteLine($"Resolving media URI: '{uri}'"); + + if (docIdParts.Length == 2) + { + var storageType = docIdParts[0]; + var uriPath = docIdParts[1]; + + AndroidUri contentUri = null; + if (storageType.Equals(storageTypeImage, StringComparison.OrdinalIgnoreCase)) + contentUri = MediaStore.Images.Media.ExternalContentUri; + else if (storageType.Equals(storageTypeVideo, StringComparison.OrdinalIgnoreCase)) + contentUri = MediaStore.Video.Media.ExternalContentUri; + else if (storageType.Equals(storageTypeAudio, StringComparison.OrdinalIgnoreCase)) + contentUri = MediaStore.Audio.Media.ExternalContentUri; +#pragma warning disable CS0618 + if (contentUri != null && GetDataFilePath(contentUri, $"{MediaStore.MediaColumns.Id}=?", new[] { uriPath }) is string filePath) + return filePath; +#pragma warning restore CS0618 + } + } + + Debug.WriteLine($"Unable to resolve document URI: '{uri}'"); + + return null; + } + + static string ResolveContentPath(AndroidUri uri) + { + Debug.WriteLine($"Trying to resolve content URI: '{uri}'"); + + if (GetDataFilePath(uri) is string filePath) + return filePath; + + // TODO: support some additional things, like Google Photos if that is possible + + Debug.WriteLine($"Unable to resolve content URI: '{uri}'"); + + return null; + } + + static string CacheContentFile(AndroidUri uri) + { + if (!uri.Scheme.Equals(UriSchemeContent, StringComparison.OrdinalIgnoreCase)) + return null; + + Debug.WriteLine($"Copying content URI to local cache: '{uri}'"); + + // open the source stream + using var srcStream = OpenContentStream(uri, out var extension); + if (srcStream == null) + return null; + + // resolve or generate a valid destination path +#pragma warning disable CS0618 + var filename = GetColumnValue(uri, MediaStore.Files.FileColumns.DisplayName) ?? Guid.NewGuid().ToString("N"); +#pragma warning restore CS0618 + + if (!Path.HasExtension(filename) && !string.IsNullOrEmpty(extension)) + filename = Path.ChangeExtension(filename, extension); + + // create a temporary file + var hasPermission = Permissions.IsDeclaredInManifest(global::Android.Manifest.Permission.WriteExternalStorage); + var root = hasPermission + ? Application.Context.ExternalCacheDir + : Application.Context.CacheDir; + var tmpFile = GetTemporaryFile(root, filename); + + // copy to the destination + using var dstStream = File.Create(tmpFile.CanonicalPath); + srcStream.CopyTo(dstStream); + + return tmpFile.CanonicalPath; + } + + static Stream OpenContentStream(AndroidUri uri, out string extension) + { + var isVirtual = IsVirtualFile(uri); + if (isVirtual) + { + Debug.WriteLine($"Content URI was virtual: '{uri}'"); + return GetVirtualFileStream(uri, out extension); + } + + extension = GetFileExtension(uri); + return Application.Context.ContentResolver.OpenInputStream(uri); + } + + static bool IsVirtualFile(AndroidUri uri) + { + if (!DocumentsContract.IsDocumentUri(Application.Context, uri)) + return false; + + var value = GetColumnValue(uri, DocumentsContract.Document.ColumnFlags); + if (!string.IsNullOrEmpty(value) && int.TryParse(value, out var flagsInt)) + { + var flags = (DocumentContractFlags)flagsInt; + return flags.HasFlag(DocumentContractFlags.VirtualDocument); + } + + return false; + } + + static Stream GetVirtualFileStream(AndroidUri uri, out string extension) + { + var mimeTypes = Application.Context.ContentResolver.GetStreamTypes(uri, FileMimeTypes.All); + if (mimeTypes?.Length >= 1) + { + var mimeType = mimeTypes[0]; + + var stream = Application.Context.ContentResolver + .OpenTypedAssetFileDescriptor(uri, mimeType, null) + .CreateInputStream(); + + extension = MimeTypeMap.Singleton.GetExtensionFromMimeType(mimeType); + + return stream; + } + + extension = null; + return null; + } + + static string GetColumnValue(AndroidUri contentUri, string column, string selection = null, string[] selectionArgs = null) + { + try + { + var value = QueryContentResolverColumn(contentUri, column, selection, selectionArgs); + if (!string.IsNullOrEmpty(value)) + return value; + } + catch + { + // Ignore all exceptions and use null for the error indicator + } + + return null; + } + + static string GetDataFilePath(AndroidUri contentUri, string selection = null, string[] selectionArgs = null) + { +#pragma warning disable CS0618 // Type or member is obsolete + const string column = MediaStore.Files.FileColumns.Data; +#pragma warning restore CS0618 // Type or member is obsolete + + // ask the content provider for the data column, which may contain the actual file path + var path = GetColumnValue(contentUri, column, selection, selectionArgs); + if (!string.IsNullOrEmpty(path) && Path.IsPathRooted(path)) + return path; + + return null; + } + + static string GetFileExtension(AndroidUri uri) + { + var mimeType = Application.Context.ContentResolver.GetType(uri); + + return mimeType != null + ? MimeTypeMap.Singleton.GetExtensionFromMimeType(mimeType) + : null; + } + + static string QueryContentResolverColumn(AndroidUri contentUri, string columnName, string selection = null, string[] selectionArgs = null) + { + string text = null; + + var projection = new[] { columnName }; + using var cursor = Application.Context.ContentResolver.Query(contentUri, projection, selection, selectionArgs, null); + if (cursor?.MoveToFirst() == true) + { + var columnIndex = cursor.GetColumnIndex(columnName); + if (columnIndex != -1) + text = cursor.GetString(columnIndex); + } + + return text; + } + + internal static AndroidUri GetShareableFileUri(FileBase file) + { + Java.IO.File sharedFile; + if (FileProvider.IsFileInPublicLocation(file.FullPath)) + { + // we are sharing a file in a "shared/public" location + sharedFile = new Java.IO.File(file.FullPath); + } + else + { + var root = FileProvider.GetTemporaryRootDirectory(); + + var tmpFile = FileSystemUtils.GetTemporaryFile(root, file.FileName); + + System.IO.File.Copy(file.FullPath, tmpFile.CanonicalPath); + + sharedFile = tmpFile; + } + + // create the uri, if N use file provider + if (OperatingSystem.IsAndroidVersionAtLeast(24)) + { + return FileProvider.GetUriForFile(sharedFile); + } + + // use the shared file path created + return AndroidUri.FromFile(sharedFile); + } + } +} diff --git a/src/Essentials/src/FileSystem/FileSystemUtils.shared.cs b/src/Essentials/src/FileSystem/FileSystemUtils.shared.cs new file mode 100644 index 000000000000..3b3f0a3ad318 --- /dev/null +++ b/src/Essentials/src/FileSystem/FileSystemUtils.shared.cs @@ -0,0 +1,13 @@ +#nullable enable +using System.IO; + +namespace Microsoft.Maui.Storage +{ + static partial class FileSystemUtils + { + public static string NormalizePath(string filename) => + filename + .Replace('\\', Path.DirectorySeparatorChar) + .Replace('/', Path.DirectorySeparatorChar); + } +} \ No newline at end of file diff --git a/src/Essentials/src/Permissions/Permissions.shared.cs b/src/Essentials/src/Permissions/Permissions.shared.cs index 2203c6cf6efb..ffc0f6a417d6 100644 --- a/src/Essentials/src/Permissions/Permissions.shared.cs +++ b/src/Essentials/src/Permissions/Permissions.shared.cs @@ -35,7 +35,6 @@ internal static async Task EnsureGrantedAsync() public abstract partial class BasePermission { - [Preserve] public BasePermission() { } diff --git a/src/Essentials/src/Platform/ActivityStateManager.android.cs b/src/Essentials/src/Platform/ActivityStateManager.android.cs new file mode 100644 index 000000000000..882b38391d0a --- /dev/null +++ b/src/Essentials/src/Platform/ActivityStateManager.android.cs @@ -0,0 +1,174 @@ +#nullable enable +using System; +using System.Threading; +using System.Threading.Tasks; +using Android.App; +using Android.Content; +using Android.OS; + +namespace Microsoft.Maui.ApplicationModel +{ + public interface IActivityStateManager + { + void Init(Application application); + + void Init(Activity activity, Bundle? bundle); + + Activity? GetCurrentActivity(); + + event EventHandler ActivityStateChanged; + + Task WaitForActivityAsync(CancellationToken cancelToken = default); + } + + public static class ActivityStateManager + { + static IActivityStateManager? defaultImplementation; + + public static IActivityStateManager Default => + defaultImplementation ??= new ActivityStateManagerImplementation(); + + internal static void SetDefault(IActivityStateManager? implementation) => + defaultImplementation = implementation; + } + + class ActivityStateManagerImplementation : IActivityStateManager + { + ActivityLifecycleContextListener? lifecycleListener; + + public Activity? GetCurrentActivity() => lifecycleListener?.Activity; + + public event EventHandler? ActivityStateChanged; + + public void Init(Application application) + { + lifecycleListener = new ActivityLifecycleContextListener(OnActivityStateChanged); + application.RegisterActivityLifecycleCallbacks(lifecycleListener); + } + + public void Init(Activity activity, Bundle? bundle) + { + if (activity.Application is not Application application) + throw new InvalidOperationException("Activity was not attached to an application."); + + Init(application); + lifecycleListener!.Activity = activity; + } + + public async Task WaitForActivityAsync(CancellationToken cancelToken = default) + { + if (GetCurrentActivity() is Activity activity) + return activity; + + var tcs = new TaskCompletionSource(); + + try + { + using (cancelToken.Register(() => tcs.TrySetCanceled())) + { + ActivityStateChanged += handler; + return await tcs.Task.ConfigureAwait(false); + } + } + finally + { + ActivityStateChanged -= handler; + } + + void handler(object? sender, ActivityStateChangedEventArgs e) + { + if (e.State == ActivityState.Created || e.State == ActivityState.Resumed) + tcs.TrySetResult(e.Activity); + } + } + + void OnActivityStateChanged(Activity activity, ActivityState ev) + => ActivityStateChanged?.Invoke(null, new ActivityStateChangedEventArgs(activity, ev)); + } + + static class ActivityStateManagerExtensions + { + public static Activity? GetCurrentActivity(this IActivityStateManager manager, bool throwOnNull) + { + var activity = manager.GetCurrentActivity(); + if (throwOnNull && activity == null) + throw new NullReferenceException("The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class."); + + return activity; + } + } + + public enum ActivityState + { + Created, + Resumed, + Paused, + Destroyed, + SaveInstanceState, + Started, + Stopped + } + + public class ActivityStateChangedEventArgs : EventArgs + { + internal ActivityStateChangedEventArgs(Activity activity, ActivityState ev) + { + State = ev; + Activity = activity; + } + + public ActivityState State { get; } + + public Activity Activity { get; } + } + + class ActivityLifecycleContextListener : Java.Lang.Object, Application.IActivityLifecycleCallbacks + { + readonly Action _onActivityStateChanged; + readonly WeakReference _currentActivity = new(null); + + public ActivityLifecycleContextListener(Action onActivityStateChanged) + { + _onActivityStateChanged = onActivityStateChanged; + } + + public Context Context => + Activity ?? Application.Context; + + public Activity? Activity + { + get => _currentActivity.TryGetTarget(out var a) ? a : null; + set => _currentActivity.SetTarget(value); + } + + void Application.IActivityLifecycleCallbacks.OnActivityCreated(Activity activity, Bundle? savedInstanceState) + { + Activity = activity; + _onActivityStateChanged(activity, ActivityState.Created); + } + + void Application.IActivityLifecycleCallbacks.OnActivityDestroyed(Activity activity) => + _onActivityStateChanged(activity, ActivityState.Destroyed); + + void Application.IActivityLifecycleCallbacks.OnActivityPaused(Activity activity) + { + Activity = activity; + _onActivityStateChanged(activity, ActivityState.Paused); + } + + void Application.IActivityLifecycleCallbacks.OnActivityResumed(Activity activity) + { + Activity = activity; + _onActivityStateChanged(activity, ActivityState.Resumed); + } + + void Application.IActivityLifecycleCallbacks.OnActivitySaveInstanceState(Activity activity, Bundle outState) => + _onActivityStateChanged(activity, ActivityState.SaveInstanceState); + + void Application.IActivityLifecycleCallbacks.OnActivityStarted(Activity activity) => + _onActivityStateChanged(activity, ActivityState.Started); + + void Application.IActivityLifecycleCallbacks.OnActivityStopped(Activity activity) => + _onActivityStateChanged(activity, ActivityState.Stopped); + } +} diff --git a/src/Essentials/src/Platform/IntermediateActivity.android.cs b/src/Essentials/src/Platform/IntermediateActivity.android.cs new file mode 100644 index 000000000000..96907852240d --- /dev/null +++ b/src/Essentials/src/Platform/IntermediateActivity.android.cs @@ -0,0 +1,150 @@ +#nullable enable +using System; +using System.Collections.Concurrent; +using System.Threading.Tasks; +using Android.App; +using Android.Content; +using Android.Content.PM; +using Android.OS; + +namespace Microsoft.Maui.ApplicationModel +{ + [Activity(ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, Exported = true)] + class IntermediateActivity : Activity + { + const string launchedExtra = "launched"; + const string actualIntentExtra = "actual_intent"; + const string guidExtra = "guid"; + const string requestCodeExtra = "request_code"; + + static readonly ConcurrentDictionary pendingTasks = new(); + + bool launched; + Intent? actualIntent; + string? guid; + int requestCode; + + protected override void OnCreate(Bundle? savedInstanceState) + { + base.OnCreate(savedInstanceState); + + var extras = savedInstanceState ?? Intent?.Extras; + + // read the values + launched = extras?.GetBoolean(launchedExtra, false) ?? false; + actualIntent = extras?.GetParcelable(actualIntentExtra) as Intent; + guid = extras?.GetString(guidExtra); + requestCode = extras?.GetInt(requestCodeExtra, -1) ?? -1; + + if (GetIntermediateTask(guid) is IntermediateTask task) + { + task.OnCreate?.Invoke(actualIntent!); + } + + // if this is the first time, lauch the real activity + if (!launched) + StartActivityForResult(actualIntent, requestCode); + } + + protected override void OnSaveInstanceState(Bundle outState) + { + // make sure we mark this activity as launched + outState.PutBoolean(launchedExtra, true); + + // save the values + outState.PutParcelable(actualIntentExtra, actualIntent); + outState.PutString(guidExtra, guid); + outState.PutInt(requestCodeExtra, requestCode); + + base.OnSaveInstanceState(outState); + } + + protected override void OnActivityResult(int requestCode, Result resultCode, Intent? data) + { + base.OnActivityResult(requestCode, resultCode, data); + + // we have a valid GUID, so handle the task + if (GetIntermediateTask(guid, true) is IntermediateTask task) + { + if (resultCode == Result.Canceled) + { + task.TaskCompletionSource.TrySetCanceled(); + } + else + { + try + { + data ??= new Intent(); + + task.OnResult?.Invoke(data); + + task.TaskCompletionSource.TrySetResult(data); + } + catch (Exception ex) + { + task.TaskCompletionSource.TrySetException(ex); + } + } + } + + // close the intermediate activity + Finish(); + } + + public static Task StartAsync(Intent intent, int requestCode, Action onCreate, Action onResult) + { + // make sure we have the activity + var activity = ActivityStateManager.Default.GetCurrentActivity(true)!; + + // create a new task + var data = new IntermediateTask(onCreate, onResult); + pendingTasks[data.Id] = data; + + // create the intermediate intent, and add the real intent to it + var intermediateIntent = new Intent(activity, typeof(IntermediateActivity)); + intermediateIntent.PutExtra(actualIntentExtra, intent); + intermediateIntent.PutExtra(guidExtra, data.Id); + intermediateIntent.PutExtra(requestCodeExtra, requestCode); + + // start the intermediate activity + activity.StartActivityForResult(intermediateIntent, requestCode); + + return data.TaskCompletionSource.Task; + } + + static IntermediateTask? GetIntermediateTask(string? guid, bool remove = false) + { + if (string.IsNullOrEmpty(guid)) + return null; + + if (remove) + { + pendingTasks.TryRemove(guid, out var removedTask); + return removedTask; + } + + pendingTasks.TryGetValue(guid, out var task); + return task; + } + + class IntermediateTask + { + public IntermediateTask(Action onCreate, Action onResult) + { + Id = Guid.NewGuid().ToString(); + TaskCompletionSource = new TaskCompletionSource(); + + OnCreate = onCreate; + OnResult = onResult; + } + + public string Id { get; } + + public TaskCompletionSource TaskCompletionSource { get; } + + public Action OnCreate { get; } + + public Action OnResult { get; } + } + } +} diff --git a/src/Essentials/src/Platform/Platform.android.cs b/src/Essentials/src/Platform/Platform.android.cs index 8062ddd2c28a..c331d6e79cf8 100644 --- a/src/Essentials/src/Platform/Platform.android.cs +++ b/src/Essentials/src/Platform/Platform.android.cs @@ -1,32 +1,11 @@ using System; -using System.Collections.Concurrent; -using System.Threading; -using System.Threading.Tasks; using Android.App; using Android.Content; -using Android.Content.PM; -using Android.Hardware; -using Android.Hardware.Camera2; -using Android.Locations; -using Android.Net; -using Android.Net.Wifi; -using Android.OS; -using Android.Views; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Storage; -using AndroidIntent = Android.Content.Intent; -using AndroidUri = Android.Net.Uri; namespace Microsoft.Maui.ApplicationModel { - static partial class Platform + static class PlatformUtils { - static ActivityLifecycleContextListener lifecycleListener; - - public static Activity CurrentActivity => lifecycleListener?.Activity; - - public static event EventHandler ActivityStateChanged; - internal const int requestCodeFilePicker = 11001; internal const int requestCodeMediaPicker = 11002; internal const int requestCodeMediaCapture = 11003; @@ -44,62 +23,9 @@ internal static int NextRequestCode() return requestCode; } - internal static void OnActivityStateChanged(Activity activity, ActivityState ev) - => ActivityStateChanged?.Invoke(null, new ActivityStateChangedEventArgs(activity, ev)); - - public static async Task WaitForActivityAsync(CancellationToken cancelToken = default) - { - if (CurrentActivity != null) - return CurrentActivity; - - var tcs = new TaskCompletionSource(); - var handler = new EventHandler((sender, args) => - { - if (args.State == ActivityState.Created || args.State == ActivityState.Resumed) - tcs.TrySetResult(args.Activity); - }); - - try - { - using (cancelToken.Register(() => tcs.TrySetCanceled())) - { - ActivityStateChanged += handler; - return await tcs.Task.ConfigureAwait(false); - } - } - finally - { - ActivityStateChanged -= handler; - } - } - - internal static Activity GetCurrentActivity(bool throwOnNull) - { - var activity = lifecycleListener?.Activity; - if (throwOnNull && activity == null) - throw new NullReferenceException("The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class."); - - return activity; - } - - public static void Init(Application application) - { - lifecycleListener = new ActivityLifecycleContextListener(); - application.RegisterActivityLifecycleCallbacks(lifecycleListener); - } - - public static void Init(Activity activity, Bundle bundle) - { - Init(activity.Application); - lifecycleListener.Activity = activity; - } - - public static void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults) => - Permissions.OnRequestPermissionsResult(requestCode, permissions, grantResults); - internal static bool HasSystemFeature(string systemFeature) { - var packageManager = AppContext.PackageManager; + var packageManager = Application.Context.PackageManager; foreach (var feature in packageManager.GetSystemAvailableFeatures()) { if (feature?.Name?.Equals(systemFeature, StringComparison.OrdinalIgnoreCase) ?? false) @@ -108,91 +34,19 @@ internal static bool HasSystemFeature(string systemFeature) return false; } - internal static bool IsIntentSupported(AndroidIntent intent) => - intent.ResolveActivity(AppContext.PackageManager) != null; - - internal static bool IsIntentSupported(AndroidIntent intent, string expectedPackageName) => - intent.ResolveActivity(AppContext.PackageManager) is ComponentName c && c.PackageName == expectedPackageName; - - internal static AndroidUri GetShareableFileUri(FileBase file) - { - Java.IO.File sharedFile; - if (FileProvider.IsFileInPublicLocation(file.FullPath)) - { - // we are sharing a file in a "shared/public" location - sharedFile = new Java.IO.File(file.FullPath); - } - else - { - var root = FileProvider.GetTemporaryRootDirectory(); - - var tmpFile = FileSystem.GetTemporaryFile(root, file.FileName); - - System.IO.File.Copy(file.FullPath, tmpFile.CanonicalPath); - - sharedFile = tmpFile; - } - - // create the uri, if N use file provider - if (HasApiLevelN) - { - return FileProvider.GetUriForFile(sharedFile); - } - - // use the shared file path created - return AndroidUri.FromFile(sharedFile); - } - - internal static readonly bool HasApiLevelKitKat = OperatingSystem.IsAndroidVersionAtLeast((int)BuildVersionCodes.Kitkat); - - internal static readonly bool HasApiLevelN = OperatingSystem.IsAndroidVersionAtLeast(24); - - internal static readonly bool HasApiLevelS = OperatingSystem.IsAndroidVersionAtLeast(31); - - internal static readonly bool HasApiLevelNMr1 = OperatingSystem.IsAndroidVersionAtLeast(25); - - internal static readonly bool HasApiLevelO = OperatingSystem.IsAndroidVersionAtLeast(26); - - internal static readonly bool HasApiLevelQ = OperatingSystem.IsAndroidVersionAtLeast(29); - - internal static CameraManager CameraManager => - AppContext.GetSystemService(Context.CameraService) as CameraManager; - - internal static ConnectivityManager ConnectivityManager => - AppContext.GetSystemService(Context.ConnectivityService) as ConnectivityManager; - - internal static WifiManager WifiManager => - AppContext.GetSystemService(Context.WifiService) as WifiManager; - - internal static SensorManager SensorManager => - AppContext.GetSystemService(Context.SensorService) as SensorManager; - - internal static ClipboardManager ClipboardManager => - AppContext.GetSystemService(Context.ClipboardService) as ClipboardManager; - - internal static LocationManager LocationManager => - AppContext.GetSystemService(Context.LocationService) as LocationManager; + internal static bool IsIntentSupported(Intent intent) => + intent.ResolveActivity(Application.Context.PackageManager) != null; - internal static PowerManager PowerManager => - AppContext.GetSystemService(Context.PowerService) as PowerManager; - -#if __ANDROID_25__ - internal static ShortcutManager ShortcutManager => - AppContext.GetSystemService(Context.ShortcutService) as ShortcutManager; -#endif - - internal static IWindowManager WindowManager => - AppContext.GetSystemService(Context.WindowService) as IWindowManager; - - internal static ContentResolver ContentResolver => - AppContext.ContentResolver; + internal static bool IsIntentSupported(Intent intent, string expectedPackageName) => + intent.ResolveActivity(Application.Context.PackageManager) is ComponentName c && c.PackageName == expectedPackageName; internal static Java.Util.Locale GetLocale() { - var resources = AppContext.Resources; + var resources = Application.Context.Resources; var config = resources.Configuration; + #if __ANDROID_24__ - if (HasApiLevelN) + if (OperatingSystem.IsAndroidVersionAtLeast(24)) return config.Locales.Get(0); #endif @@ -204,11 +58,11 @@ internal static Java.Util.Locale GetLocale() internal static void SetLocale(Java.Util.Locale locale) { Java.Util.Locale.Default = locale; - var resources = AppContext.Resources; + var resources = Application.Context.Resources; var config = resources.Configuration; #if __ANDROID_24__ - if (HasApiLevelN) + if (OperatingSystem.IsAndroidVersionAtLeast(24)) config.SetLocale(locale); else #endif @@ -221,212 +75,4 @@ internal static void SetLocale(Java.Util.Locale locale) #pragma warning restore CS0618 // Type or member is obsolete } } - - public enum ActivityState - { - Created, - Resumed, - Paused, - Destroyed, - SaveInstanceState, - Started, - Stopped - } - - public class ActivityStateChangedEventArgs : EventArgs - { - internal ActivityStateChangedEventArgs(Activity activity, ActivityState ev) - { - State = ev; - Activity = activity; - } - - public ActivityState State { get; } - - public Activity Activity { get; } - } - - class ActivityLifecycleContextListener : Java.Lang.Object, Application.IActivityLifecycleCallbacks - { - WeakReference currentActivity = new WeakReference(null); - - internal Context Context => - Activity ?? Application.Context; - - internal Activity Activity - { - get => currentActivity.TryGetTarget(out var a) ? a : null; - set => currentActivity.SetTarget(value); - } - - void Application.IActivityLifecycleCallbacks.OnActivityCreated(Activity activity, Bundle savedInstanceState) - { - Activity = activity; - Platform.OnActivityStateChanged(activity, ActivityState.Created); - } - - void Application.IActivityLifecycleCallbacks.OnActivityDestroyed(Activity activity) => - Platform.OnActivityStateChanged(activity, ActivityState.Destroyed); - - void Application.IActivityLifecycleCallbacks.OnActivityPaused(Activity activity) - { - Activity = activity; - Platform.OnActivityStateChanged(activity, ActivityState.Paused); - } - - void Application.IActivityLifecycleCallbacks.OnActivityResumed(Activity activity) - { - Activity = activity; - Platform.OnActivityStateChanged(activity, ActivityState.Resumed); - } - - void Application.IActivityLifecycleCallbacks.OnActivitySaveInstanceState(Activity activity, Bundle outState) => - Platform.OnActivityStateChanged(activity, ActivityState.SaveInstanceState); - - void Application.IActivityLifecycleCallbacks.OnActivityStarted(Activity activity) => - Platform.OnActivityStateChanged(activity, ActivityState.Started); - - void Application.IActivityLifecycleCallbacks.OnActivityStopped(Activity activity) => - Platform.OnActivityStateChanged(activity, ActivityState.Stopped); - } - - [Activity(ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize, Exported = true)] - class IntermediateActivity : Activity - { - const string launchedExtra = "launched"; - const string actualIntentExtra = "actual_intent"; - const string guidExtra = "guid"; - const string requestCodeExtra = "request_code"; - - static readonly ConcurrentDictionary pendingTasks = - new ConcurrentDictionary(); - - bool launched; - Intent actualIntent; - string guid; - int requestCode; - - protected override void OnCreate(Bundle savedInstanceState) - { - base.OnCreate(savedInstanceState); - - var extras = savedInstanceState ?? Intent.Extras; - - // read the values - launched = extras.GetBoolean(launchedExtra, false); - actualIntent = extras.GetParcelable(actualIntentExtra) as Intent; - guid = extras.GetString(guidExtra); - requestCode = extras.GetInt(requestCodeExtra, -1); - - if (GetIntermediateTask(guid) is IntermediateTask task) - { - task.OnCreate?.Invoke(actualIntent); - } - - // if this is the first time, lauch the real activity - if (!launched) - StartActivityForResult(actualIntent, requestCode); - } - - protected override void OnSaveInstanceState(Bundle outState) - { - // make sure we mark this activity as launched - outState.PutBoolean(launchedExtra, true); - - // save the values - outState.PutParcelable(actualIntentExtra, actualIntent); - outState.PutString(guidExtra, guid); - outState.PutInt(requestCodeExtra, requestCode); - - base.OnSaveInstanceState(outState); - } - - protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) - { - base.OnActivityResult(requestCode, resultCode, data); - - // we have a valid GUID, so handle the task - if (GetIntermediateTask(guid, true) is IntermediateTask task) - { - if (resultCode == Result.Canceled) - { - task.TaskCompletionSource.TrySetCanceled(); - } - else - { - try - { - data ??= new AndroidIntent(); - - task.OnResult?.Invoke(data); - - task.TaskCompletionSource.TrySetResult(data); - } - catch (Exception ex) - { - task.TaskCompletionSource.TrySetException(ex); - } - } - } - - // close the intermediate activity - Finish(); - } - - public static Task StartAsync(Intent intent, int requestCode, Action onCreate = null, Action onResult = null) - { - // make sure we have the activity - var activity = Platform.GetCurrentActivity(true); - - // create a new task - var data = new IntermediateTask(onCreate, onResult); - pendingTasks[data.Id] = data; - - // create the intermediate intent, and add the real intent to it - var intermediateIntent = new Intent(activity, typeof(IntermediateActivity)); - intermediateIntent.PutExtra(actualIntentExtra, intent); - intermediateIntent.PutExtra(guidExtra, data.Id); - intermediateIntent.PutExtra(requestCodeExtra, requestCode); - - // start the intermediate activity - activity.StartActivityForResult(intermediateIntent, requestCode); - - return data.TaskCompletionSource.Task; - } - - static IntermediateTask GetIntermediateTask(string guid, bool remove = false) - { - if (string.IsNullOrEmpty(guid)) - return null; - - if (remove) - { - pendingTasks.TryRemove(guid, out var removedTask); - return removedTask; - } - - pendingTasks.TryGetValue(guid, out var task); - return task; - } - - class IntermediateTask - { - public IntermediateTask(Action onCreate, Action onResult) - { - Id = Guid.NewGuid().ToString(); - TaskCompletionSource = new TaskCompletionSource(); - - OnCreate = onCreate; - OnResult = onResult; - } - - public string Id { get; } - - public TaskCompletionSource TaskCompletionSource { get; } - - public Action OnCreate { get; } - - public Action OnResult { get; } - } - } } diff --git a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs index fb7722f55c6e..239f68cf2077 100644 --- a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs +++ b/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs @@ -1,31 +1,11 @@ using System; -using System.Linq; using System.Runtime.InteropServices; -using System.Threading.Tasks; -using Foundation; using ObjCRuntime; -using UIKit; -using Microsoft.Maui.Authentication; -using Microsoft.Maui.ApplicationModel; - -#if __IOS__ -using CoreMotion; -#elif __WATCHOS__ -using CoreMotion; -#endif namespace Microsoft.Maui.ApplicationModel { - static partial class Platform + static class PlatformUtils { -#if __IOS__ || __TVOS__ - public static bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options) - => WebAuthenticator.OpenUrl(new Uri(url.AbsoluteString)); - - public static bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) - => WebAuthenticator.OpenUrl(new Uri(userActivity?.WebPageUrl?.AbsoluteString)); -#endif - #if __IOS__ [DllImport(Constants.SystemLibrary, EntryPoint = "sysctlbyname")] #else @@ -56,93 +36,5 @@ internal static string GetSystemLibraryProperty(string property) return returnValue; } - -#if __IOS__ || __TVOS__ - - static Func getCurrentController; - - public static void Init(Func getCurrentUIViewController) - => getCurrentController = getCurrentUIViewController; - - public static UIViewController GetCurrentUIViewController() => - GetCurrentViewController(false); - - internal static UIViewController GetCurrentViewController(bool throwIfNull = true) - { - var viewController = getCurrentController?.Invoke(); - - if (viewController != null) - return viewController; - - var window = UIApplication.SharedApplication.KeyWindow; - - if (window != null && window.WindowLevel == UIWindowLevel.Normal) - viewController = window.RootViewController; - - if (viewController == null) - { - window = UIApplication.SharedApplication - .Windows - .OrderByDescending(w => w.WindowLevel) - .FirstOrDefault(w => w.RootViewController != null && w.WindowLevel == UIWindowLevel.Normal); - - if (window == null && throwIfNull) - throw new InvalidOperationException("Could not find current view controller."); - else - viewController = window?.RootViewController; - } - - while (viewController?.PresentedViewController != null) - viewController = viewController.PresentedViewController; - - if (throwIfNull && viewController == null) - throw new InvalidOperationException("Could not find current view controller."); - - return viewController; - } - - internal static UIWindow GetCurrentWindow(bool throwIfNull = true) - { - var window = UIApplication.SharedApplication.KeyWindow; - - if (window != null && window.WindowLevel == UIWindowLevel.Normal) - return window; - - if (window == null) - { - window = UIApplication.SharedApplication - .Windows - .OrderByDescending(w => w.WindowLevel) - .FirstOrDefault(w => w.RootViewController != null && w.WindowLevel == UIWindowLevel.Normal); - } - - if (throwIfNull && window == null) - throw new InvalidOperationException("Could not find current window."); - - return window; - } -#endif - -#if __IOS__ - internal class UIPresentationControllerDelegate : UIAdaptivePresentationControllerDelegate - { - Action dismissHandler; - - internal UIPresentationControllerDelegate(Action dismissHandler) - => this.dismissHandler = dismissHandler; - - public override void DidDismiss(UIPresentationController presentationController) - { - dismissHandler?.Invoke(); - dismissHandler = null; - } - - protected override void Dispose(bool disposing) - { - dismissHandler?.Invoke(); - base.Dispose(disposing); - } - } -#endif } } diff --git a/src/Essentials/src/Platform/Platform.macos.cs b/src/Essentials/src/Platform/Platform.macos.cs index ecb5f5d7a40e..4eb4c5d2a879 100644 --- a/src/Essentials/src/Platform/Platform.macos.cs +++ b/src/Essentials/src/Platform/Platform.macos.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.ApplicationModel { - static partial class Platform + static class PlatformUtils { internal static NSWindow GetCurrentWindow(bool throwIfNull = true) { diff --git a/src/Essentials/src/Platform/Platform.shared.cs b/src/Essentials/src/Platform/Platform.shared.cs deleted file mode 100644 index b732fb42b974..000000000000 --- a/src/Essentials/src/Platform/Platform.shared.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Microsoft.Maui.ApplicationModel -{ -#if !NETSTANDARD - static partial class Platform - { - } -#endif -} diff --git a/src/Essentials/src/Platform/Platform.tizen.cs b/src/Essentials/src/Platform/Platform.tizen.cs index d8115ac097a9..9bab3a037d7b 100644 --- a/src/Essentials/src/Platform/Platform.tizen.cs +++ b/src/Essentials/src/Platform/Platform.tizen.cs @@ -12,7 +12,7 @@ namespace Microsoft.Maui.ApplicationModel { - static partial class Platform + static class PlatformUtils { static TizenAccelerometer accelerometer = null; static TizenBarometer barometer = null; diff --git a/src/Essentials/src/Platform/Platform.uwp.cs b/src/Essentials/src/Platform/Platform.uwp.cs index 0a7160221b7f..ed68ee058859 100644 --- a/src/Essentials/src/Platform/Platform.uwp.cs +++ b/src/Essentials/src/Platform/Platform.uwp.cs @@ -1,80 +1,9 @@ -#if WINDOWS_UWP -using Windows.ApplicationModel.Activation; -using Windows.UI.Core; -using Windows.UI.Xaml; -using WindowActivationState = Windows.UI.Core.CoreWindowActivationState; -#elif WINDOWS -using System; -using Microsoft.Maui.ApplicationModel; -using Microsoft.UI.Windowing; -using Microsoft.UI.Xaml; -#endif - namespace Microsoft.Maui.ApplicationModel { - static partial class Platform + static class PlatformUtils { - const uint DISPLAY_CHANGED = 126; - const uint DPI_CHANGED = 736; - - static internal event EventHandler CurrentWindowChanged; - static internal event EventHandler CurrentWindowDisplayChanged; - - internal static Window CurrentWindow - { - get => _currentWindow ?? Window.Current; - set - { - bool changed = _currentWindow != value; - _currentWindow = value; - - if(changed) - CurrentWindowChanged?.Invoke(value, EventArgs.Empty); - } - } - - internal static IntPtr CurrentWindowHandle - => WinRT.Interop.WindowNative.GetWindowHandle(CurrentWindow); -#if WINDOWS - internal static UI.WindowId CurrentWindowId - => UI.Win32Interop.GetWindowIdFromWindow(CurrentWindowHandle); - - internal static AppWindow CurrentAppWindow - => AppWindow.GetFromWindowId(CurrentWindowId); - - // Currently there isn't a way to detect Orientation Changes unless you subclass the WinUI.Window and watch the messages - // Maui.Core forwards these messages to here so that WinUI can react accordingly. - // This is the "subtlest" way to currently wire this together. - // Hopefully there will be a more public API for this down the road so we can just use that directly from Essentials - internal static void NewWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) - { - if (CurrentWindowDisplayChanged == null) - return; - - // We only care about orientation or dpi changes - if (DISPLAY_CHANGED != msg && DPI_CHANGED != msg) - return; - - if (_currentWindow != null && hWnd == CurrentWindowHandle) - { - CurrentWindowDisplayChanged?.Invoke(CurrentWindow, EventArgs.Empty); - } - } -#endif - internal const string AppManifestFilename = "AppxManifest.xml"; internal const string AppManifestXmlns = "http://schemas.microsoft.com/appx/manifest/foundation/windows10"; internal const string AppManifestUapXmlns = "http://schemas.microsoft.com/appx/manifest/uap/windows10"; - private static Window _currentWindow; - - public static string MapServiceToken { get; set; } - - public static void OnActivated(Window window, WindowActivatedEventArgs args) - { - if (args.WindowActivationState != WindowActivationState.Deactivated) - { - CurrentWindow = window; - } - } } } diff --git a/src/Essentials/src/Platform/UIPresentationControllerDelegate.ios.cs b/src/Essentials/src/Platform/UIPresentationControllerDelegate.ios.cs new file mode 100644 index 000000000000..a3cd6a3dd44b --- /dev/null +++ b/src/Essentials/src/Platform/UIPresentationControllerDelegate.ios.cs @@ -0,0 +1,25 @@ +using System; +using UIKit; + +namespace Microsoft.Maui.ApplicationModel +{ + class UIPresentationControllerDelegate : UIAdaptivePresentationControllerDelegate + { + Action dismissHandler; + + internal UIPresentationControllerDelegate(Action dismissHandler) + => this.dismissHandler = dismissHandler; + + public override void DidDismiss(UIPresentationController presentationController) + { + dismissHandler?.Invoke(); + dismissHandler = null; + } + + protected override void Dispose(bool disposing) + { + dismissHandler?.Invoke(); + base.Dispose(disposing); + } + } +} diff --git a/src/Essentials/src/Platform/WindowStateManager.ios.cs b/src/Essentials/src/Platform/WindowStateManager.ios.cs new file mode 100644 index 000000000000..e9a742219627 --- /dev/null +++ b/src/Essentials/src/Platform/WindowStateManager.ios.cs @@ -0,0 +1,96 @@ +#nullable enable +using System; +using System.Linq; +using UIKit; + +namespace Microsoft.Maui.ApplicationModel +{ + public interface IWindowStateManager + { + void Init(Func? getCurrentUIViewController); + + UIViewController? GetCurrentUIViewController(); + + UIWindow? GetCurrentUIWindow(); + } + + public static class WindowStateManager + { + static IWindowStateManager? defaultImplementation; + + public static IWindowStateManager Default => + defaultImplementation ??= new WindowStateManagerImplementation(); + + internal static void SetDefault(IWindowStateManager? implementation) => + defaultImplementation = implementation; + } + + class WindowStateManagerImplementation : IWindowStateManager + { + Func? getCurrentController; + + public void Init(Func? getCurrentUIViewController) => + getCurrentController = getCurrentUIViewController; + + public UIViewController? GetCurrentUIViewController() => + GetCurrentViewController(false); + + public UIWindow? GetCurrentUIWindow() => + GetCurrentWindow(false); + + internal UIViewController? GetCurrentViewController(bool throwIfNull = true) + { + var viewController = getCurrentController?.Invoke(); + + if (viewController != null) + return viewController; + + var window = UIApplication.SharedApplication.KeyWindow; + + if (window != null && window.WindowLevel == UIWindowLevel.Normal) + viewController = window.RootViewController; + + if (viewController == null) + { + window = UIApplication.SharedApplication + .Windows + .OrderByDescending(w => w.WindowLevel) + .FirstOrDefault(w => w.RootViewController != null && w.WindowLevel == UIWindowLevel.Normal); + + if (window == null && throwIfNull) + throw new InvalidOperationException("Could not find current view controller."); + else + viewController = window?.RootViewController; + } + + while (viewController?.PresentedViewController != null) + viewController = viewController.PresentedViewController; + + if (throwIfNull && viewController == null) + throw new InvalidOperationException("Could not find current view controller."); + + return viewController; + } + + internal UIWindow? GetCurrentWindow(bool throwIfNull = true) + { + var window = UIApplication.SharedApplication.KeyWindow; + + if (window != null && window.WindowLevel == UIWindowLevel.Normal) + return window; + + if (window == null) + { + window = UIApplication.SharedApplication + .Windows + .OrderByDescending(w => w.WindowLevel) + .FirstOrDefault(w => w.RootViewController != null && w.WindowLevel == UIWindowLevel.Normal); + } + + if (throwIfNull && window == null) + throw new InvalidOperationException("Could not find current window."); + + return window; + } + } +} diff --git a/src/Essentials/src/Platform/WindowStateManager.uwp.cs b/src/Essentials/src/Platform/WindowStateManager.uwp.cs new file mode 100644 index 000000000000..7fc8d11118d0 --- /dev/null +++ b/src/Essentials/src/Platform/WindowStateManager.uwp.cs @@ -0,0 +1,77 @@ +#nullable enable +using System; +using Microsoft.UI.Xaml; + +namespace Microsoft.Maui.ApplicationModel +{ + public interface IWindowStateManager + { + event EventHandler ActiveWindowChanged; + + event EventHandler ActiveWindowDisplayChanged; + + Window? GetActiveWindow(); + + void OnActivated(Window window, WindowActivatedEventArgs args); + + void OnWindowMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); + } + + public static class WindowStateManager + { + static IWindowStateManager? defaultImplementation; + + public static IWindowStateManager Default => + defaultImplementation ??= new WindowStateManagerImplementation(); + + internal static void SetDefault(IWindowStateManager? implementation) => + defaultImplementation = implementation; + } + + class WindowStateManagerImplementation : IWindowStateManager + { + const uint DISPLAY_CHANGED = 126; + const uint DPI_CHANGED = 736; + + Window? _activeWindow; + + public event EventHandler? ActiveWindowChanged; + + public event EventHandler? ActiveWindowDisplayChanged; + + public Window? GetActiveWindow() => + _activeWindow; + + void SetActiveWindow(Window window) + { + if (_activeWindow == window) + return; + + _activeWindow = window; + ActiveWindowChanged?.Invoke(window, EventArgs.Empty); + } + + public void OnActivated(Window window, WindowActivatedEventArgs args) + { + if (args.WindowActivationState != WindowActivationState.Deactivated) + SetActiveWindow(window); + } + + // Currently there isn't a way to detect Orientation Changes unless you subclass the WinUI.Window and watch the messages + // Maui.Core forwards these messages to here so that WinUI can react accordingly. + // This is the "subtlest" way to currently wire this together. + // Hopefully there will be a more public API for this down the road so we can just use that directly from Essentials + public void OnWindowMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) + { + if (ActiveWindowDisplayChanged == null) + return; + + // We only care about orientation or dpi changes + if (DISPLAY_CHANGED != msg && DPI_CHANGED != msg) + return; + + if (_activeWindow != null && hWnd == WinRT.Interop.WindowNative.GetWindowHandle(_activeWindow)) + ActiveWindowDisplayChanged?.Invoke(_activeWindow, EventArgs.Empty); + } + } +} diff --git a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs index 3643022f8ae4..e803438f0ed2 100644 --- a/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs +++ b/src/Essentials/src/Screenshot/Screenshot.netstandard.tizen.watchos.macos.cs @@ -18,7 +18,13 @@ partial class ScreenshotResult { } - internal Task PlatformOpenReadAsync(ScreenshotFormat format) => + Task PlatformOpenReadAsync(ScreenshotFormat format, int quality) => + throw ExceptionUtils.NotSupportedOrImplementedException; + + Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) => + throw ExceptionUtils.NotSupportedOrImplementedException; + + Task PlatformToPixelBufferAsync() => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/Types/DisplayInfo.shared.cs b/src/Essentials/src/Types/DisplayInfo.shared.cs index 4bc96cee41b6..6d130c2f5646 100644 --- a/src/Essentials/src/Types/DisplayInfo.shared.cs +++ b/src/Essentials/src/Types/DisplayInfo.shared.cs @@ -3,7 +3,6 @@ namespace Microsoft.Maui.Devices { /// - [Preserve(AllMembers = true)] public readonly struct DisplayInfo : IEquatable { /// diff --git a/src/Essentials/src/Types/FileProvider.android.cs b/src/Essentials/src/Types/FileProvider.android.cs index 1ac727d94c81..0ea09ef51979 100644 --- a/src/Essentials/src/Types/FileProvider.android.cs +++ b/src/Essentials/src/Types/FileProvider.android.cs @@ -25,19 +25,19 @@ public class FileProvider : ContentFileProvider // We can choose external only, or internal only as alternative options public static FileProviderLocation TemporaryLocation { get; set; } = FileProviderLocation.PreferExternal; - internal static string Authority => Platform.AppContext.PackageName + ".fileProvider"; + internal static string Authority => Application.Context.PackageName + ".fileProvider"; internal static Java.IO.File GetTemporaryRootDirectory() { // If we specifically want the internal storage, no extra checks are needed, we have permission if (TemporaryLocation == FileProviderLocation.Internal) - return Platform.AppContext.CacheDir; + return Application.Context.CacheDir; // If we explicitly want only external locations we need to do some permissions checking var externalOnly = TemporaryLocation == FileProviderLocation.External; // make sure the external storage is available - var hasExternalMedia = Platform.AppContext.ExternalCacheDir != null && IsMediaMounted(Platform.AppContext.ExternalCacheDir); + var hasExternalMedia = Application.Context.ExternalCacheDir != null && IsMediaMounted(Application.Context.ExternalCacheDir); // undo all the work if we have requested a fail (mainly for testing) if (AlwaysFailExternalMediaAccess) @@ -50,8 +50,8 @@ internal static Java.IO.File GetTemporaryRootDirectory() // based on permssions, return the correct directory // if permission were required, then it would have already thrown return hasExternalMedia - ? Platform.AppContext.ExternalCacheDir - : Platform.AppContext.CacheDir; + ? Application.Context.ExternalCacheDir + : Application.Context.CacheDir; } static bool IsMediaMounted(Java.IO.File location) => @@ -68,18 +68,18 @@ internal static bool IsFileInPublicLocation(string filename) var publicLocations = new List { #if __ANDROID_29__ - Platform.AppContext?.GetExternalFilesDir(null)?.CanonicalPath, + Application.Context?.GetExternalFilesDir(null)?.CanonicalPath, #else #pragma warning disable CS0618 // Type or member is obsolete - AndroidEnvironment.ExternalStorageDirectory?.CanonicalPath, + AndroidEnvironment.ExternalStorageDirectory?.CanonicalPath, #pragma warning restore CS0618 // Type or member is obsolete #endif - Platform.AppContext?.ExternalCacheDir?.CanonicalPath + Application.Context?.ExternalCacheDir?.CanonicalPath }; // the internal cache path is available only by file provider in N+ - if (Platform.HasApiLevelN) - publicLocations.Add(Platform.AppContext?.CacheDir?.CanonicalPath); + if (OperatingSystem.IsAndroidVersionAtLeast(24)) + publicLocations.Add(Application.Context?.CacheDir?.CanonicalPath); foreach (var location in publicLocations) { @@ -100,7 +100,7 @@ internal static bool IsFileInPublicLocation(string filename) } internal static AndroidUri GetUriForFile(Java.IO.File file) => - FileProvider.GetUriForFile(Platform.AppContext, Authority, file); + FileProvider.GetUriForFile(Application.Context, Authority, file); } public enum FileProviderLocation diff --git a/src/Essentials/src/Types/Location.shared.cs b/src/Essentials/src/Types/Location.shared.cs index 2895448502dd..011b92bc9097 100644 --- a/src/Essentials/src/Types/Location.shared.cs +++ b/src/Essentials/src/Types/Location.shared.cs @@ -1,5 +1,5 @@ using System; -using static System.Math; +using Microsoft.Maui.Media; namespace Microsoft.Maui.Devices.Sensors { @@ -113,7 +113,7 @@ public static double CalculateDistance(double latitudeStart, double longitudeSta /// public static double CalculateDistance(Location locationStart, double latitudeEnd, double longitudeEnd, DistanceUnits units) => - CalculateDistance(locationStart.Latitude, locationStart.Longitude, latitudeEnd, longitudeEnd, units); + CalculateDistance(locationStart.Latitude, locationStart.Longitude, latitudeEnd, longitudeEnd, units); /// public static double CalculateDistance(Location locationStart, Location locationEnd, DistanceUnits units) => diff --git a/src/Essentials/src/Types/LocationExtensions.android.cs b/src/Essentials/src/Types/LocationExtensions.android.cs index 9d237c923747..167e8e971467 100644 --- a/src/Essentials/src/Types/LocationExtensions.android.cs +++ b/src/Essentials/src/Types/LocationExtensions.android.cs @@ -6,7 +6,7 @@ namespace Microsoft.Maui.Devices.Sensors { - public static partial class LocationExtensions + static partial class LocationExtensions { internal static Location ToLocation(this AndroidAddress address) => new Location @@ -27,15 +27,17 @@ internal static Location ToLocation(this AndroidLocation location) => Altitude = location.HasAltitude ? location.Altitude : default(double?), Timestamp = location.GetTimestamp().ToUniversalTime(), Accuracy = location.HasAccuracy ? location.Accuracy : default(float?), - VerticalAccuracy = - Platform.HasApiLevelO && location.HasVerticalAccuracy ? location.VerticalAccuracyMeters : default(float?), + VerticalAccuracy = + OperatingSystem.IsAndroidVersionAtLeast(26) && location.HasVerticalAccuracy + ? location.VerticalAccuracyMeters + : null, Course = location.HasBearing ? location.Bearing : default(double?), Speed = location.HasSpeed ? location.Speed : default(double?), IsFromMockProvider = - Platform.HasApiLevelS - ? location.Mock : + OperatingSystem.IsAndroidVersionAtLeast(31) + ? location.Mock #pragma warning disable CS0618 // Type or member is obsolete - location.IsFromMockProvider, + : location.IsFromMockProvider, #pragma warning restore CS0618 // Type or member is obsolete AltitudeReferenceSystem = AltitudeReferenceSystem.Ellipsoid }; diff --git a/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs b/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs index a6fb5be8f3e8..2db9649c7c45 100644 --- a/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Types/LocationExtensions.ios.tvos.watchos.macos.cs @@ -6,7 +6,7 @@ namespace Microsoft.Maui.Devices.Sensors { - public static partial class LocationExtensions + static partial class LocationExtensions { [System.Runtime.InteropServices.DllImport(ObjCRuntime.Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSend")] static extern CLAuthorizationStatus CLAuthorizationStatus_objc_msgSend(IntPtr receiver, IntPtr selector); @@ -34,8 +34,8 @@ internal static Location ToLocation(this CLLocation location) => VerticalAccuracy = location.VerticalAccuracy, Timestamp = location.Timestamp.ToDateTime(), #if __IOS__ || __WATCHOS__ - Course = location.Course < 0 ? default(double?) : location.Course, - Speed = location.Speed < 0 ? default(double?) : location.Speed, + Course = location.Course < 0 ? default(double?) : location.Course, + Speed = location.Speed < 0 ? default(double?) : location.Speed, #endif IsFromMockProvider = DeviceInfo.DeviceType == DeviceType.Virtual, AltitudeReferenceSystem = AltitudeReferenceSystem.Geoid diff --git a/src/Essentials/src/Types/LocationExtensions.uwp.cs b/src/Essentials/src/Types/LocationExtensions.uwp.cs index 013632bef1a5..0d7280c736fb 100644 --- a/src/Essentials/src/Types/LocationExtensions.uwp.cs +++ b/src/Essentials/src/Types/LocationExtensions.uwp.cs @@ -7,7 +7,7 @@ namespace Microsoft.Maui.Devices.Sensors { - public static partial class LocationExtensions + static partial class LocationExtensions { internal static Location ToLocation(this MapLocation mapLocation) => new Location @@ -41,18 +41,18 @@ internal static Location ToLocation(this Geoposition location) => }; internal static Location ToLocation(this Geocoordinate coordinate) => - new Location - { - Latitude = coordinate.Point.Position.Latitude, - Longitude = coordinate.Point.Position.Longitude, - Timestamp = coordinate.Timestamp, - Altitude = coordinate.Point.Position.Altitude, - Accuracy = coordinate.Accuracy, - VerticalAccuracy = coordinate.AltitudeAccuracy, - Speed = (!coordinate.Speed.HasValue || double.IsNaN(coordinate.Speed.Value)) ? default : coordinate.Speed, - Course = (!coordinate.Heading.HasValue || double.IsNaN(coordinate.Heading.Value)) ? default : coordinate.Heading, - AltitudeReferenceSystem = coordinate.Point.AltitudeReferenceSystem.ToEssentials() - }; + new Location + { + Latitude = coordinate.Point.Position.Latitude, + Longitude = coordinate.Point.Position.Longitude, + Timestamp = coordinate.Timestamp, + Altitude = coordinate.Point.Position.Altitude, + Accuracy = coordinate.Accuracy, + VerticalAccuracy = coordinate.AltitudeAccuracy, + Speed = (!coordinate.Speed.HasValue || double.IsNaN(coordinate.Speed.Value)) ? default : coordinate.Speed, + Course = (!coordinate.Heading.HasValue || double.IsNaN(coordinate.Heading.Value)) ? default : coordinate.Heading, + AltitudeReferenceSystem = coordinate.Point.AltitudeReferenceSystem.ToEssentials() + }; internal static AltitudeReferenceSystem ToEssentials(this WindowsARS altitudeReferenceSystem) => altitudeReferenceSystem switch diff --git a/src/Essentials/src/Types/PlacemarkExtensions.android.cs b/src/Essentials/src/Types/PlacemarkExtensions.android.cs index a2334775d63f..6d31a5751534 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.android.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.android.cs @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Devices.Sensors { - public static partial class PlacemarkExtensions + static partial class PlacemarkExtensions { internal static IEnumerable ToPlacemarks(this IEnumerable addresses) { diff --git a/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs b/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs index 5aec17db2937..41ed35afc13f 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs @@ -4,7 +4,7 @@ namespace Microsoft.Maui.Devices.Sensors { - public static partial class PlacemarkExtensions + static partial class PlacemarkExtensions { internal static IEnumerable ToPlacemarks(this IEnumerable addresses) { diff --git a/src/Essentials/src/Types/PlacemarkExtensions.shared.cs b/src/Essentials/src/Types/PlacemarkExtensions.shared.cs index 148230e7ad7d..31de4b32b1d3 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.shared.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.shared.cs @@ -4,17 +4,8 @@ namespace Microsoft.Maui.Devices.Sensors { - /// - public static partial class PlacemarkExtensions + static partial class PlacemarkExtensions { - /// - public static Task OpenMapsAsync(this Placemark placemark, MapLaunchOptions options) => - Map.OpenAsync(placemark, options); - - /// - public static Task OpenMapsAsync(this Placemark placemark) => - Map.OpenAsync(placemark); - internal static string GetEscapedAddress(this Placemark placemark) { if (placemark == null) diff --git a/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs b/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs index b42132741ea4..5b5da1a3863e 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.uwp.cs @@ -4,7 +4,7 @@ namespace Microsoft.Maui.Devices.Sensors { - public static partial class LocationExtensions + static partial class LocationExtensions { internal static IEnumerable ToPlacemarks(this IEnumerable mapLocations) { diff --git a/src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs b/src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs deleted file mode 100644 index 2f7003eab5f7..000000000000 --- a/src/Essentials/src/Types/Shared/PreserveAttribute.shared.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.ComponentModel; - -namespace Microsoft.Maui -{ - [AttributeUsage(AttributeTargets.All)] - [EditorBrowsable(EditorBrowsableState.Never)] - sealed class PreserveAttribute : Attribute - { -#pragma warning disable SA1401 // Fields should be private - public bool AllMembers; - public bool Conditional; -#pragma warning restore SA1401 // Fields should be private - - public PreserveAttribute(bool allMembers, bool conditional) - { - AllMembers = allMembers; - Conditional = conditional; - } - - public PreserveAttribute() - { - } - } -} diff --git a/src/Essentials/src/Types/Shared/WebUtils.shared.cs b/src/Essentials/src/Types/Shared/WebUtils.shared.cs index a0faa0d648dc..638e0e2d237e 100644 --- a/src/Essentials/src/Types/Shared/WebUtils.shared.cs +++ b/src/Essentials/src/Types/Shared/WebUtils.shared.cs @@ -57,18 +57,18 @@ internal static bool CanHandleCallback(Uri expectedUrl, Uri callbackUrl) } #if __IOS__ || __TVOS__ || __MACOS__ - internal static Foundation.NSUrl GetNativeUrl(Uri uri) - { - try - { - return new Foundation.NSUrl(uri.OriginalString); - } - catch (Exception ex) - { - Debug.WriteLine($"Unable to create NSUrl from Original string, trying Absolute URI: {ex.Message}"); - return new Foundation.NSUrl(uri.AbsoluteUri); - } - } + internal static Foundation.NSUrl GetNativeUrl(Uri uri) + { + try + { + return new Foundation.NSUrl(uri.OriginalString); + } + catch (Exception ex) + { + Debug.WriteLine($"Unable to create NSUrl from Original string, trying Absolute URI: {ex.Message}"); + return new Foundation.NSUrl(uri.AbsoluteUri); + } + } #endif } } diff --git a/src/Essentials/src/Types/UnitConverters.shared.cs b/src/Essentials/src/UnitConverters/UnitConverters.shared.cs similarity index 97% rename from src/Essentials/src/Types/UnitConverters.shared.cs rename to src/Essentials/src/UnitConverters/UnitConverters.shared.cs index 3d0290540dcd..d41f69209a0e 100644 --- a/src/Essentials/src/Types/UnitConverters.shared.cs +++ b/src/Essentials/src/UnitConverters/UnitConverters.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { /// public static class UnitConverters @@ -29,15 +29,15 @@ public static double FahrenheitToCelsius(double fahrenheit) => /// public static double CelsiusToFahrenheit(double celsius) => - (celsius * 1.8) + 32.0; + celsius * 1.8 + 32.0; /// public static double CelsiusToKelvin(double celsius) => - celsius + celsiusToKelvin; + celsius + celsiusToKelvin; /// public static double KelvinToCelsius(double kelvin) => - kelvin - celsiusToKelvin; + kelvin - celsiusToKelvin; /// public static double MilesToMeters(double miles) => @@ -69,7 +69,7 @@ public static double PoundsToStones(double pounds) => /// public static double StonesToPounds(double stones) => - stones * stonesToPounds; + stones * stonesToPounds; /// public static double KilogramsToPounds(double kilograms) => @@ -142,7 +142,7 @@ public static double CoordinatesToKilometers(double lat1, double lon1, double la var dLat2 = Math.Sin(dLat / 2) * Math.Sin(dLat / 2); var dLon2 = Math.Sin(dLon / 2) * Math.Sin(dLon / 2); - var a = dLat2 + (dLon2 * Math.Cos(lat1) * Math.Cos(lat2)); + var a = dLat2 + dLon2 * Math.Cos(lat1) * Math.Cos(lat2); var c = 2 * Math.Asin(Math.Sqrt(a)); return meanEarthRadiusInKilometers * c; diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs index e06366da8bff..16be6b2174e1 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs @@ -31,25 +31,22 @@ internal static void SetDefault(IWebAuthenticator? implementation) => public static class WebAuthenticatorExtensions { - public static Task AuthenticateAsync(this IWebAuthenticator webAuthenticator, Uri url, Uri callbackUrl) => - webAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl }); - -#if IOS || MACCATALYST || MACOS - public static bool OpenUrl(this IWebAuthenticator webAuthenticator, Uri uri) + static IPlatformWebAuthenticatorCallback AsPlatformCallback(this IWebAuthenticator webAuthenticator) { if (webAuthenticator is not IPlatformWebAuthenticatorCallback platform) throw new PlatformNotSupportedException("This implementation of IWebAuthenticator does not implement IPlatformWebAuthenticatorCallback."); - - return platform.OpenUrlCallback(uri); + return platform; } -#elif ANDROID - public static bool OnResume(this IWebAuthenticator webAuthenticator, Android.Content.Intent intent) - { - if (webAuthenticator is not IPlatformWebAuthenticatorCallback platform) - throw new PlatformNotSupportedException("This implementation of IWebAuthenticator does not implement IPlatformWebAuthenticatorCallback."); - return platform.OnResumeCallback(intent); - } + public static Task AuthenticateAsync(this IWebAuthenticator webAuthenticator, Uri url, Uri callbackUrl) => + webAuthenticator.AuthenticateAsync(new WebAuthenticatorOptions { Url = url, CallbackUrl = callbackUrl }); + +#if IOS || MACCATALYST || MACOS + public static bool OpenUrl(this IWebAuthenticator webAuthenticator, Uri uri) => + webAuthenticator.AsPlatformCallback().OpenUrlCallback(uri); +#elif ANDROID + public static bool OnResume(this IWebAuthenticator webAuthenticator, Android.Content.Intent intent) => + webAuthenticator.AsPlatformCallback().OnResumeCallback(intent); #endif } diff --git a/src/Essentials/test/UnitTests/UnitConverters_Tests.cs b/src/Essentials/test/UnitTests/UnitConverters_Tests.cs index 44065fe83962..a742b02f49f9 100644 --- a/src/Essentials/test/UnitTests/UnitConverters_Tests.cs +++ b/src/Essentials/test/UnitTests/UnitConverters_Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.Maui.Essentials; +using Microsoft.Maui.Essentials.UnitConverters; using Xunit; namespace Tests From 4d691e0a2b765ea98cefdd3747d8d1a4beb96f72 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 24 Mar 2022 06:05:07 +0200 Subject: [PATCH 13/45] done --- .../Core/src/Essentials/AppActions.cs | 33 ------------ .../Accelerometer/Accelerometer.android.cs | 2 +- .../Accelerometer.ios.watchos.cs | 2 +- .../src/Accelerometer/Accelerometer.shared.cs | 3 +- ...ns.netstandard.tvos.watchos.macos.tizen.cs | 2 + .../src/AppActions/AppActions.shared.cs | 2 +- .../src/AppActions/AppActions.uwp.cs | 3 ++ src/Essentials/src/AppInfo/AppInfo.android.cs | 2 +- .../AppInfo/AppInfo.ios.tvos.watchos.macos.cs | 6 +-- src/Essentials/src/AppInfo/AppInfo.shared.cs | 2 +- .../src/Barometer/Barometer.ios.watchos.cs | 3 +- .../src/Barometer/Barometer.shared.cs | 5 +- .../src/Battery/Battery.ios.watchos.cs | 4 +- src/Essentials/src/Battery/Battery.shared.cs | 2 +- src/Essentials/src/Battery/Battery.uwp.cs | 1 + src/Essentials/src/Browser/Browser.android.cs | 4 +- src/Essentials/src/Browser/Browser.ios.cs | 6 +-- src/Essentials/src/Browser/Browser.shared.cs | 2 +- src/Essentials/src/Compass/Compass.shared.cs | 1 + .../src/Contacts/Contacts.android.cs | 13 ++--- .../src/Contacts/Contacts.ios.macos.cs | 8 ++- .../src/Contacts/Contacts.shared.cs | 2 +- .../DeviceDisplay/DeviceDisplay.android.cs | 4 +- .../src/DeviceDisplay/DeviceDisplay.shared.cs | 3 +- .../src/DeviceDisplay/DeviceDisplay.uwp.cs | 22 ++++---- .../DeviceInfo/DeviceInfo.ios.tvos.watchos.cs | 3 +- .../src/DeviceInfo/DeviceInfo.shared.cs | 2 +- .../src/DeviceInfo/DeviceInfo.uwp.cs | 3 +- src/Essentials/src/Email/Email.android.cs | 4 +- src/Essentials/src/Email/Email.ios.cs | 6 +-- src/Essentials/src/Essentials.csproj | 44 +++++++++++++++- .../src/FilePicker/FilePicker.android.cs | 2 +- .../src/FilePicker/FilePicker.ios.cs | 5 +- .../src/FilePicker/FilePicker.shared.cs | 7 ++- .../src/FilePicker/FilePicker.uwp.cs | 3 +- .../src/Flashlight/Flashlight.android.cs | 16 ++++-- .../src/Geocoding/Geocoding.shared.cs | 15 ++++-- .../src/Geolocation/Geolocation.android.cs | 34 ++++++------ .../src/Gyroscope/Gyroscope.ios.watchos.cs | 2 +- .../src/Gyroscope/Gyroscope.shared.cs | 3 +- .../HapticFeedback/HapticFeedback.android.cs | 2 +- .../src/Launcher/Launcher.android.cs | 8 +-- .../src/Magnetometer/Magnetometer.android.cs | 9 ++-- .../Magnetometer/Magnetometer.ios.watchos.cs | 2 +- .../src/Magnetometer/Magnetometer.shared.cs | 3 +- .../src/MainThread/MainThread.android.cs | 2 +- .../MainThread.ios.tvos.watchos.macos.cs | 2 +- .../src/MainThread/MainThread.netstandard.cs | 2 +- .../src/MainThread/MainThread.shared.cs | 2 +- .../src/MainThread/MainThread.tizen.cs | 2 +- .../src/MainThread/MainThread.uwp.cs | 46 ++-------------- .../MainThread/MainThreadExtensions.uwp.cs | 33 ------------ src/Essentials/src/Map/Map.android.cs | 5 +- .../src/Map/Map.ios.watchos.macos.cs | 2 +- .../src/MediaPicker/MediaPicker.android.cs | 8 +-- .../src/MediaPicker/MediaPicker.ios.cs | 6 +-- .../src/MediaPicker/MediaPicker.shared.cs | 3 +- .../src/MediaPicker/MediaPicker.uwp.cs | 3 +- .../src/Obsolete}/Accelerometer.cs | 24 +++++---- src/Essentials/src/Obsolete/AppActions.cs | 34 ++++++++++++ .../src/Obsolete}/AppInfo.cs | 16 ++++-- .../src/Obsolete}/AppleSignInAuthenticator.cs | 11 ++-- .../src/Obsolete}/Barometer.cs | 24 +++++---- .../src/Obsolete}/Battery.cs | 27 +++++----- .../src/Obsolete}/Browser.cs | 23 ++++---- .../src/Obsolete}/Clipboard.cs | 19 +++---- .../src/Obsolete}/Compass.cs | 0 .../src/Obsolete}/Connectivity.cs | 0 .../src/Obsolete}/Contacts.cs | 12 ++--- .../src/Obsolete}/DeviceDisplay.cs | 0 .../src/Obsolete}/DeviceInfo.cs | 15 ++++-- .../src/Obsolete}/Email.cs | 0 .../src/Obsolete}/FilePicker.cs | 0 .../src/Obsolete}/FileSystem.cs | 0 .../src/Obsolete}/Flashlight.cs | 0 .../src/Obsolete}/Geocoding.cs | 0 .../src/Obsolete}/Geolocation.cs | 0 .../src/Obsolete}/Gyroscope.cs | 0 .../src/Obsolete}/HapticFeedback.cs | 0 .../src/Obsolete}/Launcher.cs | 0 .../src/Obsolete}/LocationExtensions.cs | 0 .../src/Obsolete}/Magnetometer.cs | 0 .../src/Obsolete}/Map.cs | 0 .../src/Obsolete}/MediaPicker.cs | 43 +++++---------- .../src/Obsolete}/OrientationSensor.cs | 0 .../src/Obsolete}/PhoneDialer.cs | 0 .../src/Obsolete}/PlacemarkExtensions.cs | 0 .../src/Obsolete}/Platform.cs | 51 ++++++++++++------ .../src/Obsolete}/Preferences.cs | 0 .../src/Obsolete}/Screenshot.cs | 0 .../src/Obsolete}/SecureStorage.cs | 0 .../src/Obsolete}/SemanticScreenReader.cs | 0 .../src/Obsolete}/Share.cs | 0 .../src/Obsolete}/Sms.cs | 0 .../src/Obsolete}/TextToSpeech.cs | 0 .../src/Obsolete}/VersionTracking.cs | 52 ++++++++++++------- .../src/Obsolete}/Vibration.cs | 0 .../src/Obsolete}/WebAuthenticator.cs | 0 .../OrientationSensor.ios.watchos.cs | 2 +- .../OrientationSensor.shared.cs | 3 +- .../src/Permissions/Permissions.android.cs | 17 +++--- .../Permissions/Permissions.ios.tvos.macos.cs | 14 ++--- .../src/Permissions/Permissions.uwp.cs | 6 +-- .../src/PhoneDialer/PhoneDialer.android.cs | 6 +-- .../src/PhoneDialer/PhoneDialer.ios.cs | 2 +- .../Platform/IntermediateActivity.android.cs | 8 +-- .../src/Platform/Platform.android.cs | 1 + .../src/Platform/Platform.ios.tvos.watchos.cs | 6 +++ src/Essentials/src/Platform/Platform.uwp.cs | 28 ++++++++++ .../src/Platform/WindowStateManager.ios.cs | 41 ++++++++------- .../src/Platform/WindowStateManager.uwp.cs | 43 +++++++++++++++ .../src/Preferences/Preferences.shared.cs | 2 +- .../src/Screenshot/Screenshot.android.cs | 3 +- .../SemanticScreenReader.uwp.cs | 13 ++--- src/Essentials/src/Share/Share.android.cs | 2 +- src/Essentials/src/Share/Share.ios.cs | 4 +- src/Essentials/src/Share/Share.uwp.cs | 8 +-- src/Essentials/src/Sms/Sms.android.cs | 6 ++- src/Essentials/src/Sms/Sms.ios.cs | 4 +- .../VersionTracking/VersionTracking.shared.cs | 12 ++--- .../AppleSignInAuthenticator.ios.cs | 3 +- .../AppleSignInAuthenticator.shared.cs | 2 +- .../WebAuthenticator.android.cs | 7 +-- .../WebAuthenticator.ios.tvos.cs | 4 +- .../WebAuthenticator.shared.cs | 16 ++++++ .../WebAuthenticator/WebAuthenticator.uwp.cs | 7 ++- ...thenticatorIntermediateActivity.android.cs | 2 +- 127 files changed, 594 insertions(+), 455 deletions(-) delete mode 100644 src/Compatibility/Core/src/Essentials/AppActions.cs delete mode 100644 src/Essentials/src/MainThread/MainThreadExtensions.uwp.cs rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Accelerometer.cs (50%) create mode 100644 src/Essentials/src/Obsolete/AppActions.cs rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/AppInfo.cs (69%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/AppleSignInAuthenticator.cs (64%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Barometer.cs (52%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Battery.cs (56%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Browser.cs (61%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Clipboard.cs (63%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Compass.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Connectivity.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Contacts.cs (74%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/DeviceDisplay.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/DeviceInfo.cs (70%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Email.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/FilePicker.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/FileSystem.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Flashlight.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Geocoding.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Geolocation.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Gyroscope.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/HapticFeedback.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Launcher.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/LocationExtensions.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Magnetometer.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Map.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/MediaPicker.cs (58%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/OrientationSensor.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/PhoneDialer.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/PlacemarkExtensions.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Platform.cs (50%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Preferences.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Screenshot.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/SecureStorage.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/SemanticScreenReader.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Share.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Sms.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/TextToSpeech.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/VersionTracking.cs (60%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/Vibration.cs (100%) rename src/{Compatibility/Core/src/Essentials => Essentials/src/Obsolete}/WebAuthenticator.cs (100%) diff --git a/src/Compatibility/Core/src/Essentials/AppActions.cs b/src/Compatibility/Core/src/Essentials/AppActions.cs deleted file mode 100644 index 60c91ae6a389..000000000000 --- a/src/Compatibility/Core/src/Essentials/AppActions.cs +++ /dev/null @@ -1,33 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel; - -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class AppActions - { - /// - public static Task> GetAsync() - => Current.GetAsync(); - - /// - public static Task SetAsync(params AppAction[] actions) - => Current.SetAsync(actions); - - /// - public static Task SetAsync(IEnumerable actions) - => Current.SetAsync(actions); - - /// - public static event EventHandler? OnAppAction - { - add => Current.AppActionActivated += value; - remove => Current.AppActionActivated -= value; - } - - static IAppActions Current => ApplicationModel.AppActions.Current; - } -} diff --git a/src/Essentials/src/Accelerometer/Accelerometer.android.cs b/src/Essentials/src/Accelerometer/Accelerometer.android.cs index 2e2ac279f8ed..8f175b2a8633 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.android.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.android.cs @@ -23,7 +23,7 @@ partial class AccelerometerImplementation void PlatformStart(SensorSpeed sensorSpeed) { - _listener = new AccelerometerListener(this); + _listener = new AccelerometerListener(OnChanged); var delay = sensorSpeed.ToPlatform(); SensorManager!.RegisterListener(_listener, Sensor, delay); diff --git a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs index 530f2078e5bc..15824d2d85d6 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.ios.watchos.cs @@ -17,7 +17,7 @@ partial class AccelerometerImplementation void PlatformStart(SensorSpeed sensorSpeed) { MotionManager.AccelerometerUpdateInterval = sensorSpeed.ToPlatform(); - MotionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue, DataUpdated); + MotionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue ?? new NSOperationQueue(), DataUpdated); } void DataUpdated(CMAccelerometerData data, NSError error) diff --git a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs index 7e287675b8e3..846366dde5af 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs @@ -1,6 +1,7 @@ #nullable enable using System; using System.Numerics; +using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors { @@ -19,7 +20,7 @@ public interface IAccelerometer void Stop(); } - public static class Accelerometer + public static partial class Accelerometer { static IAccelerometer? defaultImplementation; diff --git a/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs b/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs index 47a253b1a1d0..5cf70db8debc 100755 --- a/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs +++ b/src/Essentials/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs @@ -16,6 +16,8 @@ public Task> GetAsync() => public Task SetAsync(IEnumerable actions) => throw ExceptionUtils.NotSupportedOrImplementedException; +#pragma warning disable CS0067 // The event is never used public event EventHandler AppActionActivated; +#pragma warning restore CS0067 // The event is never used } } diff --git a/src/Essentials/src/AppActions/AppActions.shared.cs b/src/Essentials/src/AppActions/AppActions.shared.cs index 1fe9ab540612..f78b7803e110 100755 --- a/src/Essentials/src/AppActions/AppActions.shared.cs +++ b/src/Essentials/src/AppActions/AppActions.shared.cs @@ -28,7 +28,7 @@ public interface IPlatformAppActions #endif } - public static class AppActions + public static partial class AppActions { static IAppActions? currentImplementation; diff --git a/src/Essentials/src/AppActions/AppActions.uwp.cs b/src/Essentials/src/AppActions/AppActions.uwp.cs index 2fe5f816c20a..0295be5bf8f2 100755 --- a/src/Essentials/src/AppActions/AppActions.uwp.cs +++ b/src/Essentials/src/AppActions/AppActions.uwp.cs @@ -77,6 +77,9 @@ static partial class AppActionsExtensions { internal const string AppActionPrefix = "XE_APP_ACTIONS-"; + internal const string iconDirectory = ""; + internal const string iconExtension = ".png"; + internal static string ArgumentsToId(this string arguments) { if (arguments?.StartsWith(AppActionPrefix) ?? false) diff --git a/src/Essentials/src/AppInfo/AppInfo.android.cs b/src/Essentials/src/AppInfo/AppInfo.android.cs index d5dbef42bf3e..759918af81e5 100644 --- a/src/Essentials/src/AppInfo/AppInfo.android.cs +++ b/src/Essentials/src/AppInfo/AppInfo.android.cs @@ -59,7 +59,7 @@ public string BuildString public void ShowSettingsUI() { - var context = Platform.GetCurrentActivity(false) ?? Application.Context; + var context = ActivityStateManager.Default.GetCurrentActivity(false) ?? Application.Context; var settingsIntent = new Intent(); settingsIntent.SetAction(global::Android.Provider.Settings.ActionApplicationDetailsSettings); diff --git a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs index a8cbe32b1b52..3854698f4e96 100644 --- a/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs +++ b/src/Essentials/src/AppInfo/AppInfo.ios.tvos.watchos.macos.cs @@ -30,7 +30,7 @@ string GetBundleValue(string key) #if __IOS__ || __TVOS__ public async void ShowSettingsUI() - => await Launcher.OpenAsync(UIApplication.OpenSettingsUrlString); + => await Launcher.Default.OpenAsync(UIApplication.OpenSettingsUrlString); #elif __MACOS__ public void ShowSettingsUI() { @@ -55,7 +55,7 @@ public AppTheme RequestedTheme return AppTheme.Unspecified; var traits = - MainThread.InvokeOnMainThread(() => Platform.GetCurrentUIViewController()?.TraitCollection) ?? + MainThread.InvokeOnMainThread(() => WindowStateManager.Default.GetCurrentUIViewController()?.TraitCollection) ?? UITraitCollection.CurrentTraitCollection; var uiStyle = traits.UserInterfaceStyle; @@ -100,7 +100,7 @@ public LayoutDirection RequestedLayoutDirection { get { - var currentWindow = Platform.GetCurrentWindow(false); + var currentWindow = WindowStateManager.Default.GetCurrentUIWindow(false); UIUserInterfaceLayoutDirection layoutDirection = currentWindow?.EffectiveUserInterfaceLayoutDirection ?? UIApplication.SharedApplication.UserInterfaceLayoutDirection; diff --git a/src/Essentials/src/AppInfo/AppInfo.shared.cs b/src/Essentials/src/AppInfo/AppInfo.shared.cs index dc7f6a587d3d..1e0770a5df94 100644 --- a/src/Essentials/src/AppInfo/AppInfo.shared.cs +++ b/src/Essentials/src/AppInfo/AppInfo.shared.cs @@ -24,7 +24,7 @@ public interface IAppInfo LayoutDirection RequestedLayoutDirection { get; } } - public static class AppInfo + public static partial class AppInfo { static IAppInfo? currentImplementation; diff --git a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs index 372ed6ce52a2..d8f304795531 100644 --- a/src/Essentials/src/Barometer/Barometer.ios.watchos.cs +++ b/src/Essentials/src/Barometer/Barometer.ios.watchos.cs @@ -1,6 +1,7 @@ using System; using CoreMotion; using Foundation; +using Microsoft.Maui.Media; namespace Microsoft.Maui.Devices.Sensors { @@ -14,7 +15,7 @@ public bool IsSupported void PlatformStart(SensorSpeed sensorSpeed) { altitudeManager = new CMAltimeter(); - altitudeManager.StartRelativeAltitudeUpdates(Platform.GetCurrentQueue(), LocationManagerUpdatedHeading); + altitudeManager.StartRelativeAltitudeUpdates(NSOperationQueue.CurrentQueue ?? new NSOperationQueue(), LocationManagerUpdatedHeading); void LocationManagerUpdatedHeading(CMAltitudeData e, NSError error) { diff --git a/src/Essentials/src/Barometer/Barometer.shared.cs b/src/Essentials/src/Barometer/Barometer.shared.cs index a9a2045cfd01..89a93720b47e 100644 --- a/src/Essentials/src/Barometer/Barometer.shared.cs +++ b/src/Essentials/src/Barometer/Barometer.shared.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors { @@ -16,7 +17,7 @@ public interface IBarometer void Stop(); } - public static class Barometer + public static partial class Barometer { static IBarometer? defaultImplementation; @@ -55,7 +56,7 @@ public BarometerData(double pressure) => !left.Equals(right); /// - public override bool Equals(object obj) => + public override bool Equals(object? obj) => (obj is BarometerData data) && Equals(data); /// diff --git a/src/Essentials/src/Battery/Battery.ios.watchos.cs b/src/Essentials/src/Battery/Battery.ios.watchos.cs index d189919061b1..5bc354f995a2 100755 --- a/src/Essentials/src/Battery/Battery.ios.watchos.cs +++ b/src/Essentials/src/Battery/Battery.ios.watchos.cs @@ -31,7 +31,7 @@ void StopEnergySaverListeners() } void PowerChangedNotification(NSNotification notification) - => MainThread.BeginInvokeOnMainThread(OnEnergySaverChanged); + => PlatformUtils.BeginInvokeOnMainThread(OnEnergySaverChanged); public EnergySaverStatus EnergySaverStatus => NSProcessInfo.ProcessInfo?.LowPowerModeEnabled == true ? EnergySaverStatus.On : EnergySaverStatus.Off; @@ -61,7 +61,7 @@ void StopBatteryListeners() } void BatteryInfoChangedNotification(object sender, NSNotificationEventArgs args) - => MainThread.BeginInvokeOnMainThread(OnBatteryInfoChanged); + => PlatformUtils.BeginInvokeOnMainThread(OnBatteryInfoChanged); public double ChargeLevel { diff --git a/src/Essentials/src/Battery/Battery.shared.cs b/src/Essentials/src/Battery/Battery.shared.cs index b64d82de5ba4..c93c64ebd6a5 100755 --- a/src/Essentials/src/Battery/Battery.shared.cs +++ b/src/Essentials/src/Battery/Battery.shared.cs @@ -18,7 +18,7 @@ public interface IBattery event EventHandler EnergySaverStatusChanged; } - public static class Battery + public static partial class Battery { static IBattery? defaultImplementation; diff --git a/src/Essentials/src/Battery/Battery.uwp.cs b/src/Essentials/src/Battery/Battery.uwp.cs index 5ec1d2a061c1..fddfeb293da2 100755 --- a/src/Essentials/src/Battery/Battery.uwp.cs +++ b/src/Essentials/src/Battery/Battery.uwp.cs @@ -1,3 +1,4 @@ +using Microsoft.Maui.ApplicationModel; using Windows.System.Power; namespace Microsoft.Maui.Devices diff --git a/src/Essentials/src/Browser/Browser.android.cs b/src/Essentials/src/Browser/Browser.android.cs index d41ebcf96fbf..50998d41d5dd 100755 --- a/src/Essentials/src/Browser/Browser.android.cs +++ b/src/Essentials/src/Browser/Browser.android.cs @@ -41,7 +41,7 @@ static void LaunchChromeTabs(BrowserLaunchOptions options, AndroidUri? nativeUri var tabsIntent = tabsBuilder.Build(); ActivityFlags? tabsFlags = null; - Context context = Platform.GetCurrentActivity(false); + Context? context = ActivityStateManager.Default.GetCurrentActivity(false); if (context == null) { @@ -85,7 +85,7 @@ static void LaunchExternalBrowser(BrowserLaunchOptions options, AndroidUri? nati #endif intent.SetFlags(flags); - if (!Platform.IsIntentSupported(intent)) + if (!PlatformUtils.IsIntentSupported(intent)) throw new FeatureNotSupportedException(); Application.Context.StartActivity(intent); diff --git a/src/Essentials/src/Browser/Browser.ios.cs b/src/Essentials/src/Browser/Browser.ios.cs index 647605e87a1d..836c54bf8d9d 100755 --- a/src/Essentials/src/Browser/Browser.ios.cs +++ b/src/Essentials/src/Browser/Browser.ios.cs @@ -19,7 +19,7 @@ public async Task OpenAsync(Uri uri, BrowserLaunchOptions options) await LaunchSafariViewController(uri, options); break; case BrowserLaunchMode.External: - return await Launcher.OpenAsync(uri); + return await Launcher.Default.OpenAsync(uri); } return true; @@ -29,7 +29,7 @@ private static async Task LaunchSafariViewController(Uri uri, BrowserLaunchOptio { var nativeUrl = new NSUrl(uri.AbsoluteUri); var sfViewController = new SFSafariViewController(nativeUrl, false); - var vc = Platform.GetCurrentViewController(); + var vc = WindowStateManager.Default.GetCurrentUIViewController(true)!; if (options.PreferredToolbarColor != null) sfViewController.PreferredBarTintColor = options.PreferredToolbarColor.AsUIColor(); @@ -38,7 +38,7 @@ private static async Task LaunchSafariViewController(Uri uri, BrowserLaunchOptio sfViewController.PreferredControlTintColor = options.PreferredControlColor.AsUIColor(); if (sfViewController.PopoverPresentationController != null) - sfViewController.PopoverPresentationController.SourceView = vc.View; + sfViewController.PopoverPresentationController.SourceView = vc.View!; if (options.HasFlag(BrowserLaunchFlags.PresentAsFormSheet)) sfViewController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet; diff --git a/src/Essentials/src/Browser/Browser.shared.cs b/src/Essentials/src/Browser/Browser.shared.cs index c88b13c5cb29..0904189b74f7 100755 --- a/src/Essentials/src/Browser/Browser.shared.cs +++ b/src/Essentials/src/Browser/Browser.shared.cs @@ -9,7 +9,7 @@ public interface IBrowser Task OpenAsync(Uri uri, BrowserLaunchOptions options); } - public static class Browser + public static partial class Browser { static IBrowser? defaultImplementation; diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index 8f83927adc6e..653c25d3f3f2 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices.Sensors { diff --git a/src/Essentials/src/Contacts/Contacts.android.cs b/src/Essentials/src/Contacts/Contacts.android.cs index c0308f895bff..5f1cd535ea4b 100644 --- a/src/Essentials/src/Contacts/Contacts.android.cs +++ b/src/Essentials/src/Contacts/Contacts.android.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Android.App; using Android.Content; using Android.Database; using Android.Provider; @@ -21,11 +22,11 @@ class ContactsImplementation : IContacts public async Task PickContactAsync() { var intent = new Intent(Intent.ActionPick, ContactsContract.Contacts.ContentUri); - var result = await IntermediateActivity.StartAsync(intent, Platform.requestCodePickContact).ConfigureAwait(false); + var result = await IntermediateActivity.StartAsync(intent, PlatformUtils.requestCodePickContact).ConfigureAwait(false); if (result?.Data == null) return null; - using var cursor = Platform.ContentResolver.Query(result?.Data, null, null, null, null); + using var cursor = Application.Context.ContentResolver.Query(result?.Data, null, null, null, null); if (cursor?.MoveToFirst() != true) return null; @@ -34,7 +35,7 @@ public async Task PickContactAsync() public Task> GetAllAsync(CancellationToken cancellationToken) { - var cursor = Platform.ContentResolver.Query(ContactsContract.Contacts.ContentUri, null, null, null, null); + var cursor = Application.Context.ContentResolver.Query(ContactsContract.Contacts.ContentUri, null, null, null, null); return Task.FromResult(GetEnumerable()); IEnumerable GetEnumerable() @@ -72,7 +73,7 @@ static IEnumerable GetNumbers(string id) .AppendQueryParameter(ContactsContract.RemoveDuplicateEntries, "1") .Build(); - var cursor = Platform.ContentResolver.Query(uri, null, $"{contactIdCol}=?", new[] { id }, null); + var cursor = Application.Context.ContentResolver.Query(uri, null, $"{contactIdCol}=?", new[] { id }, null); return ReadCursorItems(cursor, CommonDataKinds.Phone.Number); } @@ -84,7 +85,7 @@ static IEnumerable GetEmails(string id) .AppendQueryParameter(ContactsContract.RemoveDuplicateEntries, "1") .Build(); - var cursor = Platform.ContentResolver.Query(uri, null, $"{contactIdCol}=?", new[] { id }, null); + var cursor = Application.Context.ContentResolver.Query(uri, null, $"{contactIdCol}=?", new[] { id }, null); return ReadCursorItems(cursor, CommonDataKinds.Email.Address); } @@ -109,7 +110,7 @@ static IEnumerable ReadCursorItems(ICursor cursor, string dataKey) var selection = $"{mimetypeCol}=? AND {contactIdCol}=?"; var selectionArgs = new string[] { StructuredName.ContentItemType, id }; - using var cursor = Platform.ContentResolver.Query( + using var cursor = Application.Context.ContentResolver.Query( ContactsContract.Data.ContentUri, null, selection, diff --git a/src/Essentials/src/Contacts/Contacts.ios.macos.cs b/src/Essentials/src/Contacts/Contacts.ios.macos.cs index 85143b5f47f8..9211a6bd93ee 100644 --- a/src/Essentials/src/Contacts/Contacts.ios.macos.cs +++ b/src/Essentials/src/Contacts/Contacts.ios.macos.cs @@ -18,9 +18,7 @@ public Task PickContactAsync() => #elif __IOS__ public Task PickContactAsync() { - var uiView = Platform.GetCurrentViewController(); - if (uiView == null) - throw new ArgumentNullException($"The View Controller can't be null."); + var vc = WindowStateManager.Default.GetCurrentUIViewController(true); var source = new TaskCompletionSource(); @@ -42,10 +40,10 @@ public Task PickContactAsync() if (picker.PresentationController != null) { picker.PresentationController.Delegate = - new Platform.UIPresentationControllerDelegate(() => source?.TrySetResult(null)); + new UIPresentationControllerDelegate(() => source?.TrySetResult(null)); } - uiView.PresentViewController(picker, true, null); + vc.PresentViewController(picker, true, null); return source.Task; } diff --git a/src/Essentials/src/Contacts/Contacts.shared.cs b/src/Essentials/src/Contacts/Contacts.shared.cs index d16a84d95c4b..8c1fe146c9f7 100644 --- a/src/Essentials/src/Contacts/Contacts.shared.cs +++ b/src/Essentials/src/Contacts/Contacts.shared.cs @@ -12,7 +12,7 @@ public interface IContacts Task> GetAllAsync(CancellationToken cancellationToken = default); } - public static class Contacts + public static partial class Contacts { static IContacts? currentImplementation; diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs index 233d95a9881d..e04b482cf115 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.android.cs @@ -20,13 +20,13 @@ public bool KeepScreenOn { get { - var window = Platform.GetCurrentActivity(true)?.Window; + var window = ActivityStateManager.Default.GetCurrentActivity(true)?.Window; var flags = window?.Attributes?.Flags ?? 0; return flags.HasFlag(WindowManagerFlags.KeepScreenOn); } set { - var window = Platform.GetCurrentActivity(true)?.Window; + var window = ActivityStateManager.Default.GetCurrentActivity(true)?.Window; if (value) window?.AddFlags(WindowManagerFlags.KeepScreenOn); else diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs index 20bcd0952858..fb7d920dca88 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using Microsoft.Maui.ApplicationModel; namespace Microsoft.Maui.Devices { @@ -34,7 +35,7 @@ public static class DeviceDisplay static IDeviceDisplay? currentImplementation; public static IDeviceDisplay Current => - currentImplementation ?? new DeviceDisplayImplementation(); + currentImplementation ??= new DeviceDisplayImplementation(); /// internal static void SetCurrent(IDeviceDisplay? implementation) => diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs index 4c3901143b1c..54c949af97b8 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.uwp.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; using Microsoft.Maui.ApplicationModel; using Microsoft.UI.Windowing; +using Microsoft.UI.Xaml; using Windows.Graphics.Display; using Windows.System.Display; @@ -84,12 +85,11 @@ static DisplayRotation CalculateRotation(DisplayOrientations native, DisplayOrie DisplayInfo GetMainDisplayInfo() { - if (Platform.CurrentWindow == null) + if (WindowStateManager.Default.GetActiveAppWindow(false) is not AppWindow appWindow) return new DisplayInfo(); - var appWindow = Platform.CurrentAppWindow; - var windowHandler = Platform.CurrentWindowHandle; - var mi = GetDisplay(windowHandler); + var windowHandle = UI.Win32Interop.GetWindowFromWindowId(appWindow.Id); + var mi = GetDisplay(windowHandle); if (mi == null) return new DisplayInfo(); @@ -104,7 +104,7 @@ DisplayInfo GetMainDisplayInfo() var w = vDevMode.dmPelsWidth; var h = vDevMode.dmPelsHeight; - var dpi = GetDpiForWindow(windowHandler) / DeviceDisplay.BaseLogicalDpi; + var dpi = GetDpiForWindow(windowHandle) / DeviceDisplay.BaseLogicalDpi; return new DisplayInfo( width: perpendicular ? h : w, @@ -136,10 +136,10 @@ void StartScreenMetricsListeners() { MainThread.BeginInvokeOnMainThread(() => { - Platform.CurrentWindowDisplayChanged += OnWindowDisplayChanged; - Platform.CurrentWindowChanged += OnCurrentWindowChanged; + WindowStateManager.Default.ActiveWindowDisplayChanged += OnWindowDisplayChanged; + WindowStateManager.Default.ActiveWindowChanged += OnCurrentWindowChanged; - _currentAppWindowListeningTo = Platform.CurrentAppWindow; + _currentAppWindowListeningTo = WindowStateManager.Default.GetActiveAppWindow(true)!; _currentAppWindowListeningTo.Changed += OnAppWindowChanged; }); } @@ -148,8 +148,8 @@ void StopScreenMetricsListeners() { MainThread.BeginInvokeOnMainThread(() => { - Platform.CurrentWindowChanged -= OnCurrentWindowChanged; - Platform.CurrentWindowDisplayChanged -= OnWindowDisplayChanged; + WindowStateManager.Default.ActiveWindowChanged -= OnCurrentWindowChanged; + WindowStateManager.Default.ActiveWindowDisplayChanged -= OnWindowDisplayChanged; if (_currentAppWindowListeningTo != null) _currentAppWindowListeningTo.Changed -= OnAppWindowChanged; @@ -163,7 +163,7 @@ void OnCurrentWindowChanged(object? sender, EventArgs e) if (_currentAppWindowListeningTo != null) _currentAppWindowListeningTo.Changed -= OnAppWindowChanged; - _currentAppWindowListeningTo = Platform.CurrentAppWindow; + _currentAppWindowListeningTo = WindowStateManager.Default.GetActiveAppWindow(true)!; _currentAppWindowListeningTo.Changed += OnAppWindowChanged; } diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs index f3a175049e3f..69b653ee6bef 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.ios.tvos.watchos.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Microsoft.Maui.ApplicationModel; #if __WATCHOS__ using WatchKit; using UIDevice = WatchKit.WKInterfaceDevice; @@ -19,7 +20,7 @@ public string Model { try { - return Platform.GetSystemLibraryProperty("hw.machine"); + return PlatformUtils.GetSystemLibraryProperty("hw.machine"); } catch (Exception) { diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs index 205be16f478e..77b435aa8525 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs @@ -33,7 +33,7 @@ public interface IDeviceInfo DeviceType DeviceType { get; } } - public static class DeviceInfo + public static partial class DeviceInfo { static IDeviceInfo? currentImplementation; diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs index 956416f0ef9f..e326d25d2133 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.uwp.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using Microsoft.Maui.ApplicationModel; using Windows.Security.ExchangeActiveSyncProvisioning; using Windows.System.Profile; using Windows.UI.ViewManagement; @@ -70,7 +71,7 @@ public DeviceIdiom Idiom { try { - var currentHandle = ApplicationModel.Platform.CurrentWindowHandle; + var currentHandle = WindowStateManager.Default.GetActiveWindowHandle(true); var settings = UIViewSettingsInterop.GetForWindow(currentHandle); var uiMode = settings.UserInteractionMode; currentIdiom = uiMode == UserInteractionMode.Mouse ? DeviceIdiom.Desktop : DeviceIdiom.Tablet; diff --git a/src/Essentials/src/Email/Email.android.cs b/src/Essentials/src/Email/Email.android.cs index 4056f51c9999..7d1be6283d35 100644 --- a/src/Essentials/src/Email/Email.android.cs +++ b/src/Essentials/src/Email/Email.android.cs @@ -16,7 +16,7 @@ partial class EmailImplementation : IEmail new("Testing Microsoft.Maui.Essentials", "This is a test email.", "Microsoft.Maui.Essentials@example.org"); public bool IsComposeSupported - => Platform.IsIntentSupported(CreateIntent(testEmail)); + => PlatformUtils.IsIntentSupported(CreateIntent(testEmail)); Task PlatformComposeAsync(EmailMessage message) { @@ -86,7 +86,7 @@ static Intent CreateIntent(EmailMessage message) var uris = new List(); foreach (var attachment in message.Attachments) { - uris.Add(Platform.GetShareableFileUri(attachment)); + uris.Add(FileSystemUtils.GetShareableFileUri(attachment)); } if (uris.Count > 1) diff --git a/src/Essentials/src/Email/Email.ios.cs b/src/Essentials/src/Email/Email.ios.cs index 718159b8304c..0bf45338c2d7 100644 --- a/src/Essentials/src/Email/Email.ios.cs +++ b/src/Essentials/src/Email/Email.ios.cs @@ -34,7 +34,7 @@ Task ComposeWithMailCompose(EmailMessage message) { #if !(MACCATALYST || MACOS) // do this first so we can throw as early as possible - var parentController = Platform.GetCurrentViewController(); + var parentController = WindowStateManager.Default.GetCurrentUIViewController(true); // create the controller var controller = new MFMailComposeViewController(); @@ -72,7 +72,7 @@ Task ComposeWithMailCompose(EmailMessage message) if (controller.PresentationController != null) { controller.PresentationController.Delegate = - new Platform.UIPresentationControllerDelegate(() => tcs.TrySetResult(false)); + new UIPresentationControllerDelegate(() => tcs.TrySetResult(false)); } parentController.PresentViewController(controller, true, null); @@ -87,7 +87,7 @@ Task ComposeWithUrl(EmailMessage message) { var url = GetMailToUri(message); var nsurl = NSUrl.FromString(url); - return Launcher.OpenAsync(nsurl); + return Launcher.Default.OpenAsync(nsurl); } } } diff --git a/src/Essentials/src/Essentials.csproj b/src/Essentials/src/Essentials.csproj index d58d8fe8cf72..2eb0694777d9 100644 --- a/src/Essentials/src/Essentials.csproj +++ b/src/Essentials/src/Essentials.csproj @@ -7,7 +7,7 @@ BI1234 false true - --writer TypeList + true @@ -55,6 +55,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + None - IL2036;0618;0612 + IL2036;0618;0612;0619 - 0612 + 0612;0619 diff --git a/src/Controls/src/Core/Shapes/EllipseGeometry.cs b/src/Controls/src/Core/Shapes/EllipseGeometry.cs index 5c09c4ac9f58..7aac6a72cb24 100644 --- a/src/Controls/src/Core/Shapes/EllipseGeometry.cs +++ b/src/Controls/src/Core/Shapes/EllipseGeometry.cs @@ -58,7 +58,7 @@ public override void AppendPath(PathF path) { double density = 1.0d; #if ANDROID - density = DeviceDisplay.MainDisplayInfo.Density; + density = DeviceDisplay.Current.MainDisplayInfo.Density; #endif var centerX = (float)(density * RadiusX); diff --git a/src/Controls/src/Core/Shapes/LineGeometry.cs b/src/Controls/src/Core/Shapes/LineGeometry.cs index aff5b0d2112b..51c7458b9ed8 100644 --- a/src/Controls/src/Core/Shapes/LineGeometry.cs +++ b/src/Controls/src/Core/Shapes/LineGeometry.cs @@ -46,7 +46,7 @@ public override void AppendPath(PathF path) { double density = 1.0d; #if ANDROID - density = DeviceDisplay.MainDisplayInfo.Density; + density = DeviceDisplay.Current.MainDisplayInfo.Density; #endif float startPointX = (float)(density * StartPoint.X); diff --git a/src/Controls/src/Core/Shapes/PathGeometry.cs b/src/Controls/src/Core/Shapes/PathGeometry.cs index 059b81993ba8..c7bbfd5f2bf2 100644 --- a/src/Controls/src/Core/Shapes/PathGeometry.cs +++ b/src/Controls/src/Core/Shapes/PathGeometry.cs @@ -54,7 +54,7 @@ public override void AppendPath(PathF path) { double density = 1.0d; #if ANDROID - density = DeviceDisplay.MainDisplayInfo.Density; + density = DeviceDisplay.Current.MainDisplayInfo.Density; #endif foreach (var figure in Figures) diff --git a/src/Controls/src/Core/Shapes/RectangleGeometry.cs b/src/Controls/src/Core/Shapes/RectangleGeometry.cs index 12fb4cdd49c2..ff07c618c100 100644 --- a/src/Controls/src/Core/Shapes/RectangleGeometry.cs +++ b/src/Controls/src/Core/Shapes/RectangleGeometry.cs @@ -34,7 +34,7 @@ public override void AppendPath(Graphics.PathF path) { double density = 1.0d; #if ANDROID - density = DeviceDisplay.MainDisplayInfo.Density; + density = DeviceDisplay.Current.MainDisplayInfo.Density; #endif float x = (float)(density * Rect.X); float y = (float)(density * Rect.Y); diff --git a/src/Controls/tests/Core.UnitTests/ItemsViewTests.cs b/src/Controls/tests/Core.UnitTests/ItemsViewTests.cs index 70e1a50e41fd..c835fb9817dd 100644 --- a/src/Controls/tests/Core.UnitTests/ItemsViewTests.cs +++ b/src/Controls/tests/Core.UnitTests/ItemsViewTests.cs @@ -22,7 +22,7 @@ public void VerticalListMeasurement() var sizeRequest = itemsView.Measure(double.PositiveInfinity, double.PositiveInfinity); - var scaled = DeviceDisplay.MainDisplayInfo.GetScaledScreenSize(); + var scaled = DeviceDisplay.Current.MainDisplayInfo.GetScaledScreenSize(); Assert.That(sizeRequest.Request.Height, Is.EqualTo(scaled.Height)); Assert.That(sizeRequest.Request.Width, Is.EqualTo(scaled.Width)); } @@ -36,7 +36,7 @@ public void HorizontalListMeasurement() var sizeRequest = itemsView.Measure(double.PositiveInfinity, double.PositiveInfinity); - var scaled = DeviceDisplay.MainDisplayInfo.GetScaledScreenSize(); + var scaled = DeviceDisplay.Current.MainDisplayInfo.GetScaledScreenSize(); Assert.That(sizeRequest.Request.Height, Is.EqualTo(scaled.Height)); Assert.That(sizeRequest.Request.Width, Is.EqualTo(scaled.Width)); } diff --git a/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs b/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs index f1773ecbc126..e13a7e72caad 100644 --- a/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs +++ b/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs @@ -13,7 +13,7 @@ internal class MockDeviceDisplay : IDeviceDisplay public event EventHandler? MainDisplayInfoChanged; - public DisplayInfo GetMainDisplayInfo() => _mainDisplayInfo; + public DisplayInfo MainDisplayInfo => _mainDisplayInfo; public void UpdateMainDisplayInfo(DisplayInfo displayInfo) { diff --git a/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs b/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs index 94437a6eba11..4a7bad30d2e4 100644 --- a/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs +++ b/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs @@ -32,13 +32,13 @@ public override void OnAppearing() { base.OnAppearing(); - DeviceDisplay.MainDisplayInfoChanged += OnScreenMetricsChanged; - ScreenMetrics = DeviceDisplay.MainDisplayInfo; + DeviceDisplay.Current.MainDisplayInfoChanged += OnScreenMetricsChanged; + ScreenMetrics = DeviceDisplay.Current.MainDisplayInfo; } public override void OnDisappearing() { - DeviceDisplay.MainDisplayInfoChanged -= OnScreenMetricsChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnScreenMetricsChanged; base.OnDisappearing(); } diff --git a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs index 846366dde5af..2fef6c08500f 100644 --- a/src/Essentials/src/Accelerometer/Accelerometer.shared.cs +++ b/src/Essentials/src/Accelerometer/Accelerometer.shared.cs @@ -20,8 +20,30 @@ public interface IAccelerometer void Stop(); } - public static partial class Accelerometer + /// + public static class Accelerometer { + public static event EventHandler ReadingChanged + { + add => Default.ReadingChanged += value; + remove => Default.ReadingChanged -= value; + } + + public static event EventHandler ShakeDetected + { + add => Default.ShakeDetected += value; + remove => Default.ShakeDetected -= value; + } + + /// + public static bool IsMonitoring => Default.IsMonitoring; + + /// + public static void Start(SensorSpeed sensorSpeed) => Default.Start(sensorSpeed); + + /// + public static void Stop() => Default.Stop(); + static IAccelerometer? defaultImplementation; public static IAccelerometer Default => diff --git a/src/Essentials/src/AppActions/AppActions.shared.cs b/src/Essentials/src/AppActions/AppActions.shared.cs index f78b7803e110..5b1eb5b26c1e 100755 --- a/src/Essentials/src/AppActions/AppActions.shared.cs +++ b/src/Essentials/src/AppActions/AppActions.shared.cs @@ -28,8 +28,28 @@ public interface IPlatformAppActions #endif } - public static partial class AppActions + /// + public static class AppActions { + /// + public static Task> GetAsync() + => Current.GetAsync(); + + /// + public static Task SetAsync(params AppAction[] actions) + => Current.SetAsync(actions); + + /// + public static Task SetAsync(IEnumerable actions) + => Current.SetAsync(actions); + + /// + public static event EventHandler? OnAppAction + { + add => Current.AppActionActivated += value; + remove => Current.AppActionActivated -= value; + } + static IAppActions? currentImplementation; public static IAppActions Current => diff --git a/src/Essentials/src/AppInfo/AppInfo.shared.cs b/src/Essentials/src/AppInfo/AppInfo.shared.cs index 1e0770a5df94..89905c90ebda 100644 --- a/src/Essentials/src/AppInfo/AppInfo.shared.cs +++ b/src/Essentials/src/AppInfo/AppInfo.shared.cs @@ -24,8 +24,34 @@ public interface IAppInfo LayoutDirection RequestedLayoutDirection { get; } } - public static partial class AppInfo + /// + public static class AppInfo { + /// + public static string PackageName => Current.PackageName; + + /// + public static string Name => Current.Name; + + /// + public static string VersionString => Current.VersionString; + + /// + public static Version Version => Current.Version; + + /// + public static string BuildString => Current.BuildString; + + /// + public static void ShowSettingsUI() => Current.ShowSettingsUI(); + + /// + public static AppTheme RequestedTheme => Current.RequestedTheme; + + public static AppPackagingModel PackagingModel => Current.PackagingModel; + + public static LayoutDirection RequestedLayoutDirection => Current.RequestedLayoutDirection; + static IAppInfo? currentImplementation; public static IAppInfo Current => diff --git a/src/Essentials/src/Barometer/Barometer.shared.cs b/src/Essentials/src/Barometer/Barometer.shared.cs index 89a93720b47e..d2cb900160a2 100644 --- a/src/Essentials/src/Barometer/Barometer.shared.cs +++ b/src/Essentials/src/Barometer/Barometer.shared.cs @@ -17,8 +17,29 @@ public interface IBarometer void Stop(); } - public static partial class Barometer + /// + public static class Barometer { + public static event EventHandler ReadingChanged + { + add => Default.ReadingChanged += value; + remove => Default.ReadingChanged -= value; + } + + public static bool IsSupported => Default.IsSupported; + + /// + public static bool IsMonitoring + => Default.IsMonitoring; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Default.Start(sensorSpeed); + + /// + public static void Stop() + => Default.Stop(); + static IBarometer? defaultImplementation; public static IBarometer Default => diff --git a/src/Essentials/src/Battery/Battery.shared.cs b/src/Essentials/src/Battery/Battery.shared.cs index c93c64ebd6a5..d7b05409af76 100755 --- a/src/Essentials/src/Battery/Battery.shared.cs +++ b/src/Essentials/src/Battery/Battery.shared.cs @@ -18,8 +18,35 @@ public interface IBattery event EventHandler EnergySaverStatusChanged; } - public static partial class Battery + /// + public static class Battery { + /// + public static double ChargeLevel => Default.ChargeLevel; + + /// + public static BatteryState State => Default.State; + + /// + public static BatteryPowerSource PowerSource => Default.PowerSource; + + /// + public static EnergySaverStatus EnergySaverStatus => Default.EnergySaverStatus; + + /// + public static event EventHandler BatteryInfoChanged + { + add => Default.BatteryInfoChanged += value; + remove => Default.BatteryInfoChanged -= value; + } + + /// + public static event EventHandler EnergySaverStatusChanged + { + add => Default.EnergySaverStatusChanged += value; + remove => Default.EnergySaverStatusChanged -= value; + } + static IBattery? defaultImplementation; public static IBattery Default => diff --git a/src/Essentials/src/Browser/Browser.shared.cs b/src/Essentials/src/Browser/Browser.shared.cs index 0904189b74f7..067337f44fd4 100755 --- a/src/Essentials/src/Browser/Browser.shared.cs +++ b/src/Essentials/src/Browser/Browser.shared.cs @@ -9,8 +9,27 @@ public interface IBrowser Task OpenAsync(Uri uri, BrowserLaunchOptions options); } - public static partial class Browser + /// + public static class Browser { + /// + public static Task OpenAsync(string uri) => Default.OpenAsync(uri); + + /// + public static Task OpenAsync(string uri, BrowserLaunchMode launchMode) => Default.OpenAsync(uri, launchMode); + + /// + public static Task OpenAsync(string uri, BrowserLaunchOptions options) => Default.OpenAsync(uri, options); + + /// + public static Task OpenAsync(Uri uri) => Default.OpenAsync(uri); + + /// + public static Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) => Default.OpenAsync(uri, launchMode); + + /// + public static Task OpenAsync(Uri uri, BrowserLaunchOptions options) => Default.OpenAsync(uri, options); + static IBrowser? defaultImplementation; public static IBrowser Default => diff --git a/src/Essentials/src/Clipboard/Clipboard.shared.cs b/src/Essentials/src/Clipboard/Clipboard.shared.cs index ca6ba85af57c..492271fbb47e 100644 --- a/src/Essentials/src/Clipboard/Clipboard.shared.cs +++ b/src/Essentials/src/Clipboard/Clipboard.shared.cs @@ -15,8 +15,28 @@ public interface IClipboard event EventHandler ClipboardContentChanged; } - public static partial class Clipboard + /// + public static class Clipboard { + /// + public static Task SetTextAsync(string? text) + => Default.SetTextAsync(text ?? string.Empty); + + /// + public static bool HasText + => Default.HasText; + + /// + public static Task GetTextAsync() + => Default.GetTextAsync(); + + /// + public static event EventHandler ClipboardContentChanged + { + add => Default.ClipboardContentChanged += value; + remove => Default.ClipboardContentChanged -= value; + } + static IClipboard? defaultImplementation; public static IClipboard Default => diff --git a/src/Essentials/src/Compass/Compass.shared.cs b/src/Essentials/src/Compass/Compass.shared.cs index 653c25d3f3f2..7ccb90e0068a 100644 --- a/src/Essentials/src/Compass/Compass.shared.cs +++ b/src/Essentials/src/Compass/Compass.shared.cs @@ -26,8 +26,53 @@ public interface IPlatformCompass #endif } + /// public static class Compass { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + /// + public static bool IsSupported + => Current.IsSupported; + + public static bool IsMonitoring + => Current.IsMonitoring; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Start(sensorSpeed, true); + + /// + public static void Start(SensorSpeed sensorSpeed, bool applyLowPassFilter) + => Current.Start(sensorSpeed, applyLowPassFilter); + + /// + public static void Stop() + => Current.Stop(); + +#if IOS || MACCATALYST + public static bool ShouldDisplayHeadingCalibration + { + get + { + if (Current is IPlatformCompass c) + return c.ShouldDisplayHeadingCalibration; + return false; + } + set + { + if (Current is IPlatformCompass c) + c.ShouldDisplayHeadingCalibration = value; + } + } +#endif + + static ICompass Current => Devices.Sensors.Compass.Default; + static ICompass? defaultImplementation; public static ICompass Default => diff --git a/src/Essentials/src/Connectivity/Connectivity.shared.cs b/src/Essentials/src/Connectivity/Connectivity.shared.cs index 0604c7df409b..4bdc7661fd39 100644 --- a/src/Essentials/src/Connectivity/Connectivity.shared.cs +++ b/src/Essentials/src/Connectivity/Connectivity.shared.cs @@ -17,8 +17,22 @@ public interface IConnectivity } #nullable enable + /// public static class Connectivity { + /// + public static NetworkAccess NetworkAccess => Current.NetworkAccess; + + /// + public static IEnumerable ConnectionProfiles => Current.ConnectionProfiles.Distinct(); + + /// + public static event EventHandler ConnectivityChanged + { + add => Current.ConnectivityChanged += value; + remove => Current.ConnectivityChanged -= value; + } + static IConnectivity? currentImplementation; public static IConnectivity Current => diff --git a/src/Essentials/src/Contacts/Contacts.shared.cs b/src/Essentials/src/Contacts/Contacts.shared.cs index 8c1fe146c9f7..9a74056fa739 100644 --- a/src/Essentials/src/Contacts/Contacts.shared.cs +++ b/src/Essentials/src/Contacts/Contacts.shared.cs @@ -12,8 +12,17 @@ public interface IContacts Task> GetAllAsync(CancellationToken cancellationToken = default); } - public static partial class Contacts + /// + public static class Contacts { + /// + public static Task PickContactAsync() => + Current.PickContactAsync(); + + /// + public static Task> GetAllAsync(CancellationToken cancellationToken = default) => + Current.GetAllAsync(cancellationToken); + static IContacts? currentImplementation; public static IContacts Current => diff --git a/src/Essentials/src/Obsolete/Accelerometer.cs b/src/Essentials/src/Obsolete/Accelerometer.cs deleted file mode 100644 index a7111ab77e5c..000000000000 --- a/src/Essentials/src/Obsolete/Accelerometer.cs +++ /dev/null @@ -1,35 +0,0 @@ -#nullable enable -using System; - -namespace Microsoft.Maui.Devices.Sensors -{ - /// - public static partial class Accelerometer - { - [Obsolete($"Use {nameof(Accelerometer)}.{nameof(Default)} instead.", true)] - public static event EventHandler ReadingChanged - { - add => Default.ReadingChanged += value; - remove => Default.ReadingChanged -= value; - } - - [Obsolete($"Use {nameof(Accelerometer)}.{nameof(Default)} instead.", true)] - public static event EventHandler ShakeDetected - { - add => Default.ShakeDetected += value; - remove => Default.ShakeDetected -= value; - } - - /// - [Obsolete($"Use {nameof(Accelerometer)}.{nameof(Default)} instead.", true)] - public static bool IsMonitoring => Default.IsMonitoring; - - /// - [Obsolete($"Use {nameof(Accelerometer)}.{nameof(Default)} instead.", true)] - public static void Start(SensorSpeed sensorSpeed) => Default.Start(sensorSpeed); - - /// - [Obsolete($"Use {nameof(Accelerometer)}.{nameof(Default)} instead.", true)] - public static void Stop() => Default.Stop(); - } -} diff --git a/src/Essentials/src/Obsolete/AppActions.cs b/src/Essentials/src/Obsolete/AppActions.cs deleted file mode 100644 index 54ef1b1187ee..000000000000 --- a/src/Essentials/src/Obsolete/AppActions.cs +++ /dev/null @@ -1,34 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Threading.Tasks; - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public static partial class AppActions - { - /// - [Obsolete($"Use {nameof(AppActions)}.{nameof(Current)} instead.", true)] - public static Task> GetAsync() - => Current.GetAsync(); - - /// - [Obsolete($"Use {nameof(AppActions)}.{nameof(Current)} instead.", true)] - public static Task SetAsync(params AppAction[] actions) - => Current.SetAsync(actions); - - /// - [Obsolete($"Use {nameof(AppActions)}.{nameof(Current)} instead.", true)] - public static Task SetAsync(IEnumerable actions) - => Current.SetAsync(actions); - - /// - [Obsolete($"Use {nameof(AppActions)}.{nameof(Current)} instead.", true)] - public static event EventHandler? OnAppAction - { - add => Current.AppActionActivated += value; - remove => Current.AppActionActivated -= value; - } - } -} diff --git a/src/Essentials/src/Obsolete/AppInfo.cs b/src/Essentials/src/Obsolete/AppInfo.cs deleted file mode 100644 index 11c4bab03ad9..000000000000 --- a/src/Essentials/src/Obsolete/AppInfo.cs +++ /dev/null @@ -1,43 +0,0 @@ -#nullable enable -using System; - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public static partial class AppInfo - { - /// - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static string PackageName => Current.PackageName; - - /// - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static string Name => Current.Name; - - /// - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static string VersionString => Current.VersionString; - - /// - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static Version Version => Current.Version; - - /// - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static string BuildString => Current.BuildString; - - /// - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static void ShowSettingsUI() => Current.ShowSettingsUI(); - - /// - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static AppTheme RequestedTheme => Current.RequestedTheme; - - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static AppPackagingModel PackagingModel => Current.PackagingModel; - - [Obsolete($"Use {nameof(AppInfo)}.{nameof(Current)} instead.", true)] - public static LayoutDirection RequestedLayoutDirection => Current.RequestedLayoutDirection; - } -} \ No newline at end of file diff --git a/src/Essentials/src/Obsolete/AppleSignInAuthenticator.cs b/src/Essentials/src/Obsolete/AppleSignInAuthenticator.cs deleted file mode 100644 index c7ebb8b4e82b..000000000000 --- a/src/Essentials/src/Obsolete/AppleSignInAuthenticator.cs +++ /dev/null @@ -1,15 +0,0 @@ -#nullable enable -using System; -using System.Threading.Tasks; - -namespace Microsoft.Maui.Authentication -{ - /// - public static partial class AppleSignInAuthenticator - { - /// - [Obsolete($"Use {nameof(AppleSignInAuthenticator)}.{nameof(Default)} instead.", true)] - public static Task AuthenticateAsync(AppleSignInAuthenticatorOptions? options = null) - => Default.AuthenticateAsync(options ?? new AppleSignInAuthenticatorOptions()); - } -} diff --git a/src/Essentials/src/Obsolete/Barometer.cs b/src/Essentials/src/Obsolete/Barometer.cs deleted file mode 100644 index a1e96888b874..000000000000 --- a/src/Essentials/src/Obsolete/Barometer.cs +++ /dev/null @@ -1,34 +0,0 @@ -#nullable enable -using System; - -namespace Microsoft.Maui.Devices.Sensors -{ - /// - public static partial class Barometer - { - [Obsolete($"Use {nameof(Barometer)}.{nameof(Default)} instead.", true)] - public static event EventHandler ReadingChanged - { - add => Default.ReadingChanged += value; - remove => Default.ReadingChanged -= value; - } - - [Obsolete($"Use {nameof(Barometer)}.{nameof(Default)} instead.", true)] - public static bool IsSupported => Default.IsSupported; - - /// - [Obsolete($"Use {nameof(Barometer)}.{nameof(Default)} instead.", true)] - public static bool IsMonitoring - => Default.IsMonitoring; - - /// - [Obsolete($"Use {nameof(Barometer)}.{nameof(Default)} instead.", true)] - public static void Start(SensorSpeed sensorSpeed) - => Default.Start(sensorSpeed); - - /// - [Obsolete($"Use {nameof(Barometer)}.{nameof(Default)} instead.", true)] - public static void Stop() - => Default.Stop(); - } -} diff --git a/src/Essentials/src/Obsolete/Battery.cs b/src/Essentials/src/Obsolete/Battery.cs deleted file mode 100644 index ae5a6c780db8..000000000000 --- a/src/Essentials/src/Obsolete/Battery.cs +++ /dev/null @@ -1,41 +0,0 @@ -#nullable enable -using System; - -namespace Microsoft.Maui.Devices -{ - /// - public static partial class Battery - { - /// - [Obsolete($"Use {nameof(Battery)}.{nameof(Default)} instead.", true)] - public static double ChargeLevel => Default.ChargeLevel; - - /// - [Obsolete($"Use {nameof(Battery)}.{nameof(Default)} instead.", true)] - public static BatteryState State => Default.State; - - /// - [Obsolete($"Use {nameof(Battery)}.{nameof(Default)} instead.", true)] - public static BatteryPowerSource PowerSource => Default.PowerSource; - - /// - [Obsolete($"Use {nameof(Battery)}.{nameof(Default)} instead.", true)] - public static EnergySaverStatus EnergySaverStatus => Default.EnergySaverStatus; - - /// - [Obsolete($"Use {nameof(Battery)}.{nameof(Default)} instead.", true)] - public static event EventHandler BatteryInfoChanged - { - add => Default.BatteryInfoChanged += value; - remove => Default.BatteryInfoChanged -= value; - } - - /// - [Obsolete($"Use {nameof(Battery)}.{nameof(Default)} instead.", true)] - public static event EventHandler EnergySaverStatusChanged - { - add => Default.EnergySaverStatusChanged += value; - remove => Default.EnergySaverStatusChanged -= value; - } - } -} diff --git a/src/Essentials/src/Obsolete/Browser.cs b/src/Essentials/src/Obsolete/Browser.cs deleted file mode 100644 index d13e80124a20..000000000000 --- a/src/Essentials/src/Obsolete/Browser.cs +++ /dev/null @@ -1,34 +0,0 @@ -#nullable enable -using System; -using System.Threading.Tasks; - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public static partial class Browser - { - /// - [Obsolete($"Use {nameof(Browser)}.{nameof(Default)} instead.", true)] - public static Task OpenAsync(string uri) => Default.OpenAsync(uri); - - /// - [Obsolete($"Use {nameof(Browser)}.{nameof(Default)} instead.", true)] - public static Task OpenAsync(string uri, BrowserLaunchMode launchMode) => Default.OpenAsync(uri, launchMode); - - /// - [Obsolete($"Use {nameof(Browser)}.{nameof(Default)} instead.", true)] - public static Task OpenAsync(string uri, BrowserLaunchOptions options) => Default.OpenAsync(uri, options); - - /// - [Obsolete($"Use {nameof(Browser)}.{nameof(Default)} instead.", true)] - public static Task OpenAsync(Uri uri) => Default.OpenAsync(uri); - - /// - [Obsolete($"Use {nameof(Browser)}.{nameof(Default)} instead.", true)] - public static Task OpenAsync(Uri uri, BrowserLaunchMode launchMode) => Default.OpenAsync(uri, launchMode); - - /// - [Obsolete($"Use {nameof(Browser)}.{nameof(Default)} instead.", true)] - public static Task OpenAsync(Uri uri, BrowserLaunchOptions options) => Default.OpenAsync(uri, options); - } -} diff --git a/src/Essentials/src/Obsolete/Clipboard.cs b/src/Essentials/src/Obsolete/Clipboard.cs deleted file mode 100644 index 334663285c06..000000000000 --- a/src/Essentials/src/Obsolete/Clipboard.cs +++ /dev/null @@ -1,33 +0,0 @@ -#nullable enable -using System; -using System.Threading.Tasks; - -namespace Microsoft.Maui.ApplicationModel.DataTransfer -{ - /// - public static partial class Clipboard - { - /// - [Obsolete($"Use {nameof(Clipboard)}.{nameof(Default)} instead.", true)] - public static Task SetTextAsync(string? text) - => Default.SetTextAsync(text ?? string.Empty); - - /// - [Obsolete($"Use {nameof(Clipboard)}.{nameof(Default)} instead.", true)] - public static bool HasText - => Default.HasText; - - /// - [Obsolete($"Use {nameof(Clipboard)}.{nameof(Default)} instead.", true)] - public static Task GetTextAsync() - => Default.GetTextAsync(); - - /// - [Obsolete($"Use {nameof(Clipboard)}.{nameof(Default)} instead.", true)] - public static event EventHandler ClipboardContentChanged - { - add => Default.ClipboardContentChanged += value; - remove => Default.ClipboardContentChanged -= value; - } - } -} diff --git a/src/Essentials/src/Obsolete/Compass.cs b/src/Essentials/src/Obsolete/Compass.cs deleted file mode 100644 index 64abcfa43908..000000000000 --- a/src/Essentials/src/Obsolete/Compass.cs +++ /dev/null @@ -1,54 +0,0 @@ -#nullable enable -using System; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Compass - { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - /// - public static bool IsSupported - => Current.IsSupported; - - public static bool IsMonitoring - => Current.IsMonitoring; - - /// - public static void Start(SensorSpeed sensorSpeed) - => Start(sensorSpeed, true); - - /// - public static void Start(SensorSpeed sensorSpeed, bool applyLowPassFilter) - => Current.Start(sensorSpeed, applyLowPassFilter); - - /// - public static void Stop() - => Current.Stop(); - -#if IOS || MACCATALYST - public static bool ShouldDisplayHeadingCalibration - { - get - { - if (Current is IPlatformCompass c) - return c.ShouldDisplayHeadingCalibration; - return false; - } - set - { - if (Current is IPlatformCompass c) - c.ShouldDisplayHeadingCalibration = value; - } - } -#endif - - static ICompass Current => Devices.Sensors.Compass.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Connectivity.cs b/src/Essentials/src/Obsolete/Connectivity.cs deleted file mode 100644 index fd5249800037..000000000000 --- a/src/Essentials/src/Obsolete/Connectivity.cs +++ /dev/null @@ -1,27 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Maui.Networking; - -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Connectivity - { - /// - public static NetworkAccess NetworkAccess => Current.NetworkAccess; - - /// - public static IEnumerable ConnectionProfiles => Current.ConnectionProfiles.Distinct(); - - /// - public static event EventHandler ConnectivityChanged - { - add => Current.ConnectivityChanged += value; - remove => Current.ConnectivityChanged -= value; - } - - static IConnectivity Current => Networking.Connectivity.Current; - } -} diff --git a/src/Essentials/src/Obsolete/Contacts.cs b/src/Essentials/src/Obsolete/Contacts.cs deleted file mode 100644 index 694179e16b9e..000000000000 --- a/src/Essentials/src/Obsolete/Contacts.cs +++ /dev/null @@ -1,29 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Maui.Devices; - -namespace Microsoft.Maui.ApplicationModel.Communication -{ - /// - public static partial class Contacts - { - /// - [Obsolete($"Use {nameof(Contacts)}.{nameof(Current)} instead.", true)] - public static async Task PickContactAsync() - { - // iOS does not require permissions for the picker - if (DeviceInfo.Current.Platform != DevicePlatform.iOS) - await Permissions.EnsureGrantedAsync(); - - return await Current.PickContactAsync(); - } - - /// - [Obsolete($"Use {nameof(Contacts)}.{nameof(Current)} instead.", true)] - public static Task> GetAllAsync(CancellationToken cancellationToken = default) - => Current.GetAllAsync(cancellationToken); - } -} diff --git a/src/Essentials/src/Obsolete/Email.cs b/src/Essentials/src/Obsolete/Email.cs index f6eff1245dee..e6641ebc7e90 100644 --- a/src/Essentials/src/Obsolete/Email.cs +++ b/src/Essentials/src/Obsolete/Email.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Microsoft.Maui.ApplicationModel.Communication; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { /// public static class Email diff --git a/src/Essentials/src/Obsolete/FilePicker.cs b/src/Essentials/src/Obsolete/FilePicker.cs index 396fb8b6b649..f15706f8c3f3 100644 --- a/src/Essentials/src/Obsolete/FilePicker.cs +++ b/src/Essentials/src/Obsolete/FilePicker.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { /// public static partial class FilePicker diff --git a/src/Essentials/src/Obsolete/Flashlight.cs b/src/Essentials/src/Obsolete/Flashlight.cs index f74208195e76..98906fce592a 100644 --- a/src/Essentials/src/Obsolete/Flashlight.cs +++ b/src/Essentials/src/Obsolete/Flashlight.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public static partial class Flashlight diff --git a/src/Essentials/src/Obsolete/Geocoding.cs b/src/Essentials/src/Obsolete/Geocoding.cs index 026c5b60db26..d5d7ba136f21 100644 --- a/src/Essentials/src/Obsolete/Geocoding.cs +++ b/src/Essentials/src/Obsolete/Geocoding.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static class Geocoding diff --git a/src/Essentials/src/Obsolete/Geolocation.cs b/src/Essentials/src/Obsolete/Geolocation.cs index c3b6907988fe..5fbeeeb427b2 100644 --- a/src/Essentials/src/Obsolete/Geolocation.cs +++ b/src/Essentials/src/Obsolete/Geolocation.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static partial class Geolocation diff --git a/src/Essentials/src/Obsolete/Gyroscope.cs b/src/Essentials/src/Obsolete/Gyroscope.cs index be7fa44a2450..45ed13347b41 100644 --- a/src/Essentials/src/Obsolete/Gyroscope.cs +++ b/src/Essentials/src/Obsolete/Gyroscope.cs @@ -2,7 +2,7 @@ using System; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static partial class Gyroscope diff --git a/src/Essentials/src/Obsolete/HapticFeedback.cs b/src/Essentials/src/Obsolete/HapticFeedback.cs index a6e54d554d38..baa154904cf4 100644 --- a/src/Essentials/src/Obsolete/HapticFeedback.cs +++ b/src/Essentials/src/Obsolete/HapticFeedback.cs @@ -1,7 +1,7 @@ #nullable enable using Microsoft.Maui.Devices; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices { /// public static partial class HapticFeedback diff --git a/src/Essentials/src/Obsolete/Launcher.cs b/src/Essentials/src/Obsolete/Launcher.cs index aac36a2a410b..71c17ca4a964 100644 --- a/src/Essentials/src/Obsolete/Launcher.cs +++ b/src/Essentials/src/Obsolete/Launcher.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Microsoft.Maui.ApplicationModel; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public static partial class Launcher diff --git a/src/Essentials/src/Obsolete/LocationExtensions.cs b/src/Essentials/src/Obsolete/LocationExtensions.cs index 906217a8bd8c..d0a36e063fc2 100644 --- a/src/Essentials/src/Obsolete/LocationExtensions.cs +++ b/src/Essentials/src/Obsolete/LocationExtensions.cs @@ -2,7 +2,7 @@ using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static class LocationExtensions diff --git a/src/Essentials/src/Obsolete/Magnetometer.cs b/src/Essentials/src/Obsolete/Magnetometer.cs index bb88d06cb023..091b1a7b9967 100644 --- a/src/Essentials/src/Obsolete/Magnetometer.cs +++ b/src/Essentials/src/Obsolete/Magnetometer.cs @@ -2,7 +2,7 @@ using System; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static partial class Magnetometer diff --git a/src/Essentials/src/Obsolete/Map.cs b/src/Essentials/src/Obsolete/Map.cs index fe2a684ed25e..722e6d9e3ef6 100644 --- a/src/Essentials/src/Obsolete/Map.cs +++ b/src/Essentials/src/Obsolete/Map.cs @@ -3,7 +3,7 @@ using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public static class Map diff --git a/src/Essentials/src/Obsolete/OrientationSensor.cs b/src/Essentials/src/Obsolete/OrientationSensor.cs index 79e001a7819a..0bd0c8d9063f 100644 --- a/src/Essentials/src/Obsolete/OrientationSensor.cs +++ b/src/Essentials/src/Obsolete/OrientationSensor.cs @@ -2,7 +2,7 @@ using System; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Devices.Sensors { /// public static class OrientationSensor diff --git a/src/Essentials/src/Obsolete/PhoneDialer.cs b/src/Essentials/src/Obsolete/PhoneDialer.cs index f82b5b11a029..2a5f4f1693cf 100644 --- a/src/Essentials/src/Obsolete/PhoneDialer.cs +++ b/src/Essentials/src/Obsolete/PhoneDialer.cs @@ -1,7 +1,7 @@ #nullable enable using Microsoft.Maui.ApplicationModel.Communication; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel.Communication { /// public static class PhoneDialer diff --git a/src/Essentials/src/Obsolete/PlacemarkExtensions.cs b/src/Essentials/src/Obsolete/PlacemarkExtensions.cs index f1b3a4c0f4b2..492afd6d0775 100644 --- a/src/Essentials/src/Obsolete/PlacemarkExtensions.cs +++ b/src/Essentials/src/Obsolete/PlacemarkExtensions.cs @@ -3,7 +3,7 @@ using Microsoft.Maui.ApplicationModel; using Microsoft.Maui.Devices.Sensors; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.ApplicationModel { /// public static partial class PlacemarkExtensions diff --git a/src/Essentials/src/Obsolete/Preferences.cs b/src/Essentials/src/Obsolete/Preferences.cs index 1f14c258150a..affbaf69efd9 100644 --- a/src/Essentials/src/Obsolete/Preferences.cs +++ b/src/Essentials/src/Obsolete/Preferences.cs @@ -2,7 +2,7 @@ using System; using Microsoft.Maui.Storage; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Storage { /// public static class Preferences diff --git a/src/Essentials/src/Obsolete/Screenshot.cs b/src/Essentials/src/Obsolete/Screenshot.cs index eb93d032eb2f..01e15c60ed0f 100644 --- a/src/Essentials/src/Obsolete/Screenshot.cs +++ b/src/Essentials/src/Obsolete/Screenshot.cs @@ -2,7 +2,7 @@ using System.Threading.Tasks; using Microsoft.Maui.Media; -namespace Microsoft.Maui.Essentials +namespace Microsoft.Maui.Media { /// public static partial class Screenshot @@ -19,7 +19,5 @@ public static Task CaptureAsync() return Current.CaptureAsync(); } - - static IScreenshot Current => Media.Screenshot.Current; } } diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs index 4bce2049a79a..7766f7e71fac 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs @@ -15,8 +15,13 @@ public class AppleSignInAuthenticatorOptions public bool IncludeEmailScope { get; set; } = false; } - public static partial class AppleSignInAuthenticator + /// + public static class AppleSignInAuthenticator { + /// + public static Task AuthenticateAsync(AppleSignInAuthenticatorOptions? options = null) + => Default.AuthenticateAsync(options ?? new AppleSignInAuthenticatorOptions()); + static IAppleSignInAuthenticator? defaultImplementation; public static IAppleSignInAuthenticator Default => diff --git a/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs b/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs index 3ac788b499de..bdd4291d543c 100644 --- a/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs +++ b/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs @@ -140,7 +140,7 @@ public void MainDisplayInfo_Invokes_Correct_Members() DeviceDisplay.SetCurrent(display); display.ResetCounts(); - var main = DeviceDisplay.MainDisplayInfo; + var main = DeviceDisplay.Current.MainDisplayInfo; Assert.Equal(expected, main); Assert.Equal(0, display.StartedCount); @@ -163,7 +163,7 @@ public void Adding_MainDisplayInfoChanged_Invokes_Correct_Members() DeviceDisplay.SetCurrent(display); display.ResetCounts(); - DeviceDisplay.MainDisplayInfoChanged += OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged += OnChanged; Assert.Equal(1, display.StartedCount); Assert.Equal(0, display.StoppedCount); @@ -176,7 +176,7 @@ public void Adding_MainDisplayInfoChanged_Invokes_Correct_Members() Assert.False(display.KeepScreenOn); - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; void OnChanged(object sender, DisplayInfoChangedEventArgs e) { @@ -191,10 +191,10 @@ public void Adding_Second_MainDisplayInfoChanged_Invokes_Correct_Members() var display = new MyDisplay(); DeviceDisplay.SetCurrent(display); - DeviceDisplay.MainDisplayInfoChanged += OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged += OnChanged; display.ResetCounts(); - DeviceDisplay.MainDisplayInfoChanged += OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged += OnChanged; Assert.Equal(0, display.StartedCount); Assert.Equal(0, display.StoppedCount); @@ -207,8 +207,8 @@ public void Adding_Second_MainDisplayInfoChanged_Invokes_Correct_Members() Assert.False(display.KeepScreenOn); - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; void OnChanged(object sender, DisplayInfoChangedEventArgs e) { @@ -225,7 +225,7 @@ public void Removing_None_MainDisplayInfoChanged_Invokes_Correct_Members() DeviceDisplay.SetCurrent(display); display.ResetCounts(); - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; Assert.Equal(0, display.StartedCount); Assert.Equal(0, display.StoppedCount); @@ -251,10 +251,10 @@ public void Removing_First_MainDisplayInfoChanged_Invokes_Correct_Members() var display = new MyDisplay(); DeviceDisplay.SetCurrent(display); - DeviceDisplay.MainDisplayInfoChanged += OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged += OnChanged; display.ResetCounts(); - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; Assert.Equal(0, display.StartedCount); Assert.Equal(1, display.StoppedCount); @@ -280,11 +280,11 @@ public void Removing_Second_MainDisplayInfoChanged_Invokes_Correct_Members() var display = new MyDisplay(); DeviceDisplay.SetCurrent(display); - DeviceDisplay.MainDisplayInfoChanged += OnChanged; - DeviceDisplay.MainDisplayInfoChanged += OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged += OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged += OnChanged; display.ResetCounts(); - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; Assert.Equal(0, display.StartedCount); Assert.Equal(0, display.StoppedCount); @@ -297,8 +297,8 @@ public void Removing_Second_MainDisplayInfoChanged_Invokes_Correct_Members() Assert.False(display.KeepScreenOn); - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; - DeviceDisplay.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged -= OnChanged; void OnChanged(object sender, DisplayInfoChangedEventArgs e) { @@ -349,7 +349,7 @@ public void Swapping_With_MainDisplayInfoChanged_Invokes_Correct_Members() var display2 = new MyDisplay(); DeviceDisplay.SetCurrent(display1); - DeviceDisplay.MainDisplayInfoChanged += OnChanged; + DeviceDisplay.Current.MainDisplayInfoChanged += OnChanged; display1.ResetCounts(); DeviceDisplay.SetCurrent(display2); @@ -425,10 +425,13 @@ public event EventHandler MainDisplayInfoChanged remove => RemovedCount++; } - public DisplayInfo GetMainDisplayInfo() + public DisplayInfo MainDisplayInfo { - GetMainDisplayInfoCount++; - return _displayInfo; + get + { + GetMainDisplayInfoCount++; + return _displayInfo; + } } public void StartScreenMetricsListeners() diff --git a/src/TestUtils/src/DeviceTests.Runners/HeadlessRunner/TestDevice.cs b/src/TestUtils/src/DeviceTests.Runners/HeadlessRunner/TestDevice.cs index 1a2907acd305..67a5e679a202 100644 --- a/src/TestUtils/src/DeviceTests.Runners/HeadlessRunner/TestDevice.cs +++ b/src/TestUtils/src/DeviceTests.Runners/HeadlessRunner/TestDevice.cs @@ -13,13 +13,13 @@ class TestDevice : IDevice public string UniqueIdentifier => Guid.NewGuid().ToString("N"); - public string Name => DeviceInfo.Name; + public string Name => DeviceInfo.Current.Name; - public string Model => DeviceInfo.Model; + public string Model => DeviceInfo.Current.Model; - public string SystemName => DeviceInfo.Platform.ToString(); + public string SystemName => DeviceInfo.Current.Platform.ToString(); - public string SystemVersion => DeviceInfo.VersionString; + public string SystemVersion => DeviceInfo.Current.VersionString; public string Locale => CultureInfo.CurrentCulture.Name; } From b7abfed51f657f7ff15a8fd5e16e3ada80241634 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:22:30 +0200 Subject: [PATCH 27/45] merge files again --- .../src/DeviceDisplay/DeviceDisplay.shared.cs | 20 ++- .../src/DeviceInfo/DeviceInfo.shared.cs | 27 ++- src/Essentials/src/Email/Email.shared.cs | 15 ++ .../src/FilePicker/FilePicker.shared.cs | 12 +- .../src/FileSystem/FileSystem.shared.cs | 18 +- .../src/Flashlight/Flashlight.shared.cs | 10 ++ .../src/Geocoding/Geocoding.shared.cs | 15 ++ .../src/Geolocation/Geolocation.shared.cs | 21 ++- .../src/Gyroscope/Gyroscope.shared.cs | 26 ++- .../HapticFeedback/HapticFeedback.shared.cs | 9 +- .../src/Launcher/Launcher.shared.cs | 31 ++++ .../src/Magnetometer/Magnetometer.shared.cs | 24 +++ src/Essentials/src/Map/Map.shared.cs | 27 +++ .../src/MediaPicker/MediaPicker.shared.cs | 23 ++- src/Essentials/src/Obsolete/DeviceDisplay.cs | 29 ---- src/Essentials/src/Obsolete/DeviceInfo.cs | 41 ----- src/Essentials/src/Obsolete/Email.cs | 24 --- src/Essentials/src/Obsolete/FilePicker.cs | 21 --- src/Essentials/src/Obsolete/FileSystem.cs | 30 ---- src/Essentials/src/Obsolete/Flashlight.cs | 20 --- src/Essentials/src/Obsolete/Geocoding.cs | 26 --- src/Essentials/src/Obsolete/Geolocation.cs | 29 ---- src/Essentials/src/Obsolete/Gyroscope.cs | 33 ---- src/Essentials/src/Obsolete/HapticFeedback.cs | 15 -- src/Essentials/src/Obsolete/Launcher.cs | 41 ----- src/Essentials/src/Obsolete/Magnetometer.cs | 33 ---- src/Essentials/src/Obsolete/Map.cs | 37 ----- src/Essentials/src/Obsolete/MediaPicker.cs | 30 ---- .../src/Obsolete/OrientationSensor.cs | 32 ---- src/Essentials/src/Obsolete/PhoneDialer.cs | 18 -- .../src/Obsolete/PlacemarkExtensions.cs | 19 --- src/Essentials/src/Obsolete/Preferences.cs | 154 ------------------ src/Essentials/src/Obsolete/Screenshot.cs | 23 --- src/Essentials/src/Obsolete/SecureStorage.cs | 39 ----- .../src/Obsolete/SemanticScreenReader.cs | 15 -- src/Essentials/src/Obsolete/Share.cs | 32 ---- src/Essentials/src/Obsolete/Sms.cs | 20 --- src/Essentials/src/Obsolete/TextToSpeech.cs | 26 --- .../src/Obsolete/VersionTracking.cs | 80 --------- src/Essentials/src/Obsolete/Vibration.cs | 28 ---- .../src/Obsolete/WebAuthenticator.cs | 21 --- .../OrientationSensor.shared.cs | 25 ++- .../src/PhoneDialer/PhoneDialer.shared.cs | 10 ++ .../Platform.shared.cs} | 0 .../src/Preferences/Preferences.shared.cs | 145 +++++++++++++++++ .../src/Screenshot/Screenshot.shared.cs | 16 +- .../src/SecureStorage/SecureStorage.shared.cs | 30 ++++ .../SemanticScreenReader.shared.cs | 7 + src/Essentials/src/Share/Share.shared.cs | 25 ++- src/Essentials/src/Sms/Sms.shared.cs | 11 ++ .../src/TextToSpeech/TextToSpeech.shared.cs | 17 +- .../LocationExtensions.shared.cs} | 2 +- .../src/Types/PlacemarkExtensions.shared.cs | 11 +- .../VersionTracking/VersionTracking.shared.cs | 57 +++++++ .../src/Vibration/Vibration.shared.cs | 19 +++ .../WebAuthenticator.shared.cs | 11 ++ 56 files changed, 650 insertions(+), 930 deletions(-) delete mode 100644 src/Essentials/src/Obsolete/DeviceDisplay.cs delete mode 100644 src/Essentials/src/Obsolete/DeviceInfo.cs delete mode 100644 src/Essentials/src/Obsolete/Email.cs delete mode 100644 src/Essentials/src/Obsolete/FilePicker.cs delete mode 100644 src/Essentials/src/Obsolete/FileSystem.cs delete mode 100644 src/Essentials/src/Obsolete/Flashlight.cs delete mode 100644 src/Essentials/src/Obsolete/Geocoding.cs delete mode 100644 src/Essentials/src/Obsolete/Geolocation.cs delete mode 100644 src/Essentials/src/Obsolete/Gyroscope.cs delete mode 100644 src/Essentials/src/Obsolete/HapticFeedback.cs delete mode 100644 src/Essentials/src/Obsolete/Launcher.cs delete mode 100644 src/Essentials/src/Obsolete/Magnetometer.cs delete mode 100644 src/Essentials/src/Obsolete/Map.cs delete mode 100644 src/Essentials/src/Obsolete/MediaPicker.cs delete mode 100644 src/Essentials/src/Obsolete/OrientationSensor.cs delete mode 100644 src/Essentials/src/Obsolete/PhoneDialer.cs delete mode 100644 src/Essentials/src/Obsolete/PlacemarkExtensions.cs delete mode 100644 src/Essentials/src/Obsolete/Preferences.cs delete mode 100644 src/Essentials/src/Obsolete/Screenshot.cs delete mode 100644 src/Essentials/src/Obsolete/SecureStorage.cs delete mode 100644 src/Essentials/src/Obsolete/SemanticScreenReader.cs delete mode 100644 src/Essentials/src/Obsolete/Share.cs delete mode 100644 src/Essentials/src/Obsolete/Sms.cs delete mode 100644 src/Essentials/src/Obsolete/TextToSpeech.cs delete mode 100644 src/Essentials/src/Obsolete/VersionTracking.cs delete mode 100644 src/Essentials/src/Obsolete/Vibration.cs delete mode 100644 src/Essentials/src/Obsolete/WebAuthenticator.cs rename src/Essentials/src/{Obsolete/Platform.cs => Platform/Platform.shared.cs} (100%) rename src/Essentials/src/{Obsolete/LocationExtensions.cs => Types/LocationExtensions.shared.cs} (96%) diff --git a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs index 76aa6a370434..17a78d7a91a0 100644 --- a/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs +++ b/src/Essentials/src/DeviceDisplay/DeviceDisplay.shared.cs @@ -24,8 +24,26 @@ public DisplayInfoChangedEventArgs(DisplayInfo displayInfo) => public DisplayInfo DisplayInfo { get; } } - public static partial class DeviceDisplay + /// + public static class DeviceDisplay { + /// + public static bool KeepScreenOn + { + get => Current.KeepScreenOn; + set => Current.KeepScreenOn = value; + } + + /// + public static DisplayInfo MainDisplayInfo => Current.MainDisplayInfo; + + /// + public static event EventHandler MainDisplayInfoChanged + { + add => Current.MainDisplayInfoChanged += value; + remove => Current.MainDisplayInfoChanged -= value; + } + #if WINDOWS internal const float BaseLogicalDpi = 96.0f; #elif ANDROID diff --git a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs index 77b435aa8525..0784e7e2ef16 100644 --- a/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs +++ b/src/Essentials/src/DeviceInfo/DeviceInfo.shared.cs @@ -33,8 +33,33 @@ public interface IDeviceInfo DeviceType DeviceType { get; } } - public static partial class DeviceInfo + /// + public static class DeviceInfo { + /// + public static string Model => Current.Model; + + /// + public static string Manufacturer => Current.Manufacturer; + + /// + public static string Name => Current.Name; + + /// + public static string VersionString => Current.VersionString; + + /// + public static Version Version => Current.Version; + + /// + public static DevicePlatform Platform => Current.Platform; + + /// + public static DeviceIdiom Idiom => Current.Idiom; + + /// + public static DeviceType DeviceType => Current.DeviceType; + static IDeviceInfo? currentImplementation; public static IDeviceInfo Current => diff --git a/src/Essentials/src/Email/Email.shared.cs b/src/Essentials/src/Email/Email.shared.cs index a6db9778b8de..bf6ff893e49d 100644 --- a/src/Essentials/src/Email/Email.shared.cs +++ b/src/Essentials/src/Email/Email.shared.cs @@ -60,8 +60,23 @@ static string GetMailToUri(EmailMessage message) } } + /// public static class Email { + /// + public static Task ComposeAsync() => + Current.ComposeAsync(); + + /// + public static Task ComposeAsync(string subject, string body, params string[] to) => + Current.ComposeAsync(subject, body, to); + + /// + public static Task ComposeAsync(EmailMessage message) => + Current.ComposeAsync(message); + + static IEmail Current => ApplicationModel.Communication.Email.Default; + static IEmail? defaultImplementation; public static IEmail Default => diff --git a/src/Essentials/src/FilePicker/FilePicker.shared.cs b/src/Essentials/src/FilePicker/FilePicker.shared.cs index 11289c68d081..1a79a4a27ab6 100644 --- a/src/Essentials/src/FilePicker/FilePicker.shared.cs +++ b/src/Essentials/src/FilePicker/FilePicker.shared.cs @@ -17,8 +17,18 @@ public interface IFilePicker } /// - public static class FilePicker + public static partial class FilePicker { + /// + public static Task PickAsync(PickOptions? options = null) => + Current.PickAsync(options); + + /// + public static Task> PickMultipleAsync(PickOptions? options = null) => + Current.PickMultipleAsync(options); + + static IFilePicker Current => Storage.FilePicker.Default; + static IFilePicker? defaultImplementation; public static IFilePicker Default => diff --git a/src/Essentials/src/FileSystem/FileSystem.shared.cs b/src/Essentials/src/FileSystem/FileSystem.shared.cs index 2556be952acb..642b59d36286 100644 --- a/src/Essentials/src/FileSystem/FileSystem.shared.cs +++ b/src/Essentials/src/FileSystem/FileSystem.shared.cs @@ -16,8 +16,24 @@ public interface IFileSystem Task AppPackageFileExistsAsync(string filename); } - public static partial class FileSystem + /// + public static class FileSystem { + /// + public static string CacheDirectory + => Current.CacheDirectory; + + /// + public static string AppDataDirectory + => Current.AppDataDirectory; + + /// + public static Task OpenAppPackageFileAsync(string filename) + => Current.OpenAppPackageFileAsync(filename); + + public static Task AppPackageFileExistsAsync(string filename) + => Current.AppPackageFileExistsAsync(filename); + static IFileSystem? currentImplementation; public static IFileSystem Current => diff --git a/src/Essentials/src/Flashlight/Flashlight.shared.cs b/src/Essentials/src/Flashlight/Flashlight.shared.cs index a7c5d542287a..76cf93553829 100644 --- a/src/Essentials/src/Flashlight/Flashlight.shared.cs +++ b/src/Essentials/src/Flashlight/Flashlight.shared.cs @@ -13,6 +13,16 @@ public interface IFlashlight /// public static partial class Flashlight { + /// + public static Task TurnOnAsync() => + Current.TurnOnAsync(); + + /// + public static Task TurnOffAsync() => + Current.TurnOffAsync(); + + static IFlashlight Current => Devices.Flashlight.Current; + static IFlashlight? currentImplementation; public static IFlashlight Current => diff --git a/src/Essentials/src/Geocoding/Geocoding.shared.cs b/src/Essentials/src/Geocoding/Geocoding.shared.cs index f237b1e5a5b6..b8385b1b4a0a 100644 --- a/src/Essentials/src/Geocoding/Geocoding.shared.cs +++ b/src/Essentials/src/Geocoding/Geocoding.shared.cs @@ -19,8 +19,23 @@ public interface IPlatformGeocoding : IGeocoding #endif } + /// public static class Geocoding { + /// + public static Task> GetPlacemarksAsync(Location location) => + Current.GetPlacemarksAsync(location); + + /// + public static Task> GetPlacemarksAsync(double latitude, double longitude) => + Current.GetPlacemarksAsync(latitude, longitude); + + /// + public static Task> GetLocationsAsync(string address) => + Current.GetLocationsAsync(address); + + static IGeocoding Current => Devices.Sensors.Geocoding.Default; + static IGeocoding? defaultImplementation; public static IGeocoding Default => diff --git a/src/Essentials/src/Geolocation/Geolocation.shared.cs b/src/Essentials/src/Geolocation/Geolocation.shared.cs index 5b42f8ad4603..9d951c4921e0 100644 --- a/src/Essentials/src/Geolocation/Geolocation.shared.cs +++ b/src/Essentials/src/Geolocation/Geolocation.shared.cs @@ -11,8 +11,27 @@ public interface IGeolocation Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken); } - public static class Geolocation + /// + public static partial class Geolocation { + /// + public static Task GetLastKnownLocationAsync() => + Current.GetLastKnownLocationAsync(); + + /// + public static Task GetLocationAsync() => + Current.GetLocationAsync(); + + /// + public static Task GetLocationAsync(GeolocationRequest request) => + Current.GetLocationAsync(request); + + /// + public static Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken) => + Current.GetLocationAsync(request, cancelToken); + + static IGeolocation Current => Devices.Sensors.Geolocation.Default; + static IGeolocation? defaultImplementation; public static IGeolocation Default => diff --git a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs index 2ee2b32fe3e8..9c4ee3a2207e 100644 --- a/src/Essentials/src/Gyroscope/Gyroscope.shared.cs +++ b/src/Essentials/src/Gyroscope/Gyroscope.shared.cs @@ -18,8 +18,32 @@ public interface IGyroscope event EventHandler ReadingChanged; } - public static class Gyroscope + /// + public static partial class Gyroscope { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + /// + public static bool IsMonitoring + => Current.IsMonitoring; + + public static bool IsSupported + => Current.IsSupported; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Current.Start(sensorSpeed); + + /// + public static void Stop() + => Current.Stop(); + + static IGyroscope Current => Devices.Sensors.Gyroscope.Default; + static IGyroscope? defaultImplementation; public static IGyroscope Default => diff --git a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs index 724e39603966..22fbe5490249 100644 --- a/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs +++ b/src/Essentials/src/HapticFeedback/HapticFeedback.shared.cs @@ -9,8 +9,15 @@ public interface IHapticFeedback void Perform(HapticFeedbackType type); } - public static partial class HapticFeedback + /// + public static class HapticFeedback { + /// + public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click) => + Current.Perform(type); + + public static IHapticFeedback Current => Devices.HapticFeedback.Default; + static IHapticFeedback? defaultImplementation; public static IHapticFeedback Default => diff --git a/src/Essentials/src/Launcher/Launcher.shared.cs b/src/Essentials/src/Launcher/Launcher.shared.cs index 42aceed7f716..73c1085c686c 100644 --- a/src/Essentials/src/Launcher/Launcher.shared.cs +++ b/src/Essentials/src/Launcher/Launcher.shared.cs @@ -17,8 +17,39 @@ public interface ILauncher Task TryOpenAsync(Uri uri); } + /// public static partial class Launcher { + /// + public static Task CanOpenAsync(string uri) + => Current.CanOpenAsync(uri); + + /// + public static Task CanOpenAsync(Uri uri) + => Current.CanOpenAsync(uri); + + /// + public static Task OpenAsync(string uri) + => Current.OpenAsync(uri); + + /// + public static Task OpenAsync(Uri uri) + => Current.OpenAsync(uri); + + /// + public static Task OpenAsync(OpenFileRequest request) + => Current.OpenAsync(request); + + /// + public static Task TryOpenAsync(string uri) + => Current.TryOpenAsync(uri); + + /// + public static Task TryOpenAsync(Uri uri) + => Current.TryOpenAsync(uri); + + static ILauncher Current => ApplicationModel.Launcher.Default; + static ILauncher? defaultImplementation; public static ILauncher Default => diff --git a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs index 308aeb43f3bf..236f03f02d37 100644 --- a/src/Essentials/src/Magnetometer/Magnetometer.shared.cs +++ b/src/Essentials/src/Magnetometer/Magnetometer.shared.cs @@ -18,8 +18,32 @@ public interface IMagnetometer event EventHandler ReadingChanged; } + /// public static partial class Magnetometer { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + /// + public static bool IsMonitoring + => Current.IsMonitoring; + + public static bool IsSupported + => Current.IsSupported; + + /// + public static void Start(SensorSpeed sensorSpeed) + => Current.Start(sensorSpeed); + + /// + public static void Stop() + => Current.Stop(); + + static IMagnetometer Current => Devices.Sensors.Magnetometer.Default; + static IMagnetometer? defaultImplementation; public static IMagnetometer Default => diff --git a/src/Essentials/src/Map/Map.shared.cs b/src/Essentials/src/Map/Map.shared.cs index 10694a9e7746..1d0ef7ba528f 100644 --- a/src/Essentials/src/Map/Map.shared.cs +++ b/src/Essentials/src/Map/Map.shared.cs @@ -12,8 +12,35 @@ public interface IMap Task OpenAsync(Placemark placemark, MapLaunchOptions options); } + /// public static class Map { + /// + public static Task OpenAsync(Location location) => + Current.OpenAsync(location); + + /// + public static Task OpenAsync(Location location, MapLaunchOptions options) => + Current.OpenAsync(location, options); + + /// + public static Task OpenAsync(double latitude, double longitude) => + Current.OpenAsync(latitude, longitude); + + /// + public static Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) => + Current.OpenAsync(latitude, longitude, options); + + /// + public static Task OpenAsync(Placemark placemark) => + Current.OpenAsync(placemark); + + /// + public static Task OpenAsync(Placemark placemark, MapLaunchOptions options) => + Current.OpenAsync(placemark, options); + + static IMap Current => ApplicationModel.Map.Default; + static IMap? defaultImplementation; public static IMap Default => diff --git a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs index 1baea41a9c8f..9d0b775e1eac 100644 --- a/src/Essentials/src/MediaPicker/MediaPicker.shared.cs +++ b/src/Essentials/src/MediaPicker/MediaPicker.shared.cs @@ -18,8 +18,29 @@ public interface IMediaPicker Task CaptureVideoAsync(MediaPickerOptions? options = null); } - public static partial class MediaPicker + /// + public static class MediaPicker { + /// + public static bool IsCaptureSupported => + Default.IsCaptureSupported; + + /// + public static Task PickPhotoAsync(MediaPickerOptions? options = null) => + Default.PickPhotoAsync(options); + + /// + public static Task CapturePhotoAsync(MediaPickerOptions? options = null) => + Default.CapturePhotoAsync(options); + + /// + public static Task PickVideoAsync(MediaPickerOptions? options = null) => + Default.PickVideoAsync(options); + + /// + public static Task CaptureVideoAsync(MediaPickerOptions? options = null) => + Default.CaptureVideoAsync(options); + static IMediaPicker? defaultImplementation; public static IMediaPicker Default => diff --git a/src/Essentials/src/Obsolete/DeviceDisplay.cs b/src/Essentials/src/Obsolete/DeviceDisplay.cs deleted file mode 100644 index e0fdea954346..000000000000 --- a/src/Essentials/src/Obsolete/DeviceDisplay.cs +++ /dev/null @@ -1,29 +0,0 @@ -#nullable enable -using System; - -namespace Microsoft.Maui.Devices -{ - /// - public static partial class DeviceDisplay - { - /// - [Obsolete($"Use {nameof(DeviceDisplay)}.{nameof(Current)} instead.", true)] - public static bool KeepScreenOn - { - get => Current.KeepScreenOn; - set => Current.KeepScreenOn = value; - } - - /// - [Obsolete($"Use {nameof(DeviceDisplay)}.{nameof(Current)} instead.", true)] - public static DisplayInfo MainDisplayInfo => Current.MainDisplayInfo; - - /// - [Obsolete($"Use {nameof(DeviceDisplay)}.{nameof(Current)} instead.", true)] - public static event EventHandler MainDisplayInfoChanged - { - add => Current.MainDisplayInfoChanged += value; - remove => Current.MainDisplayInfoChanged -= value; - } - } -} diff --git a/src/Essentials/src/Obsolete/DeviceInfo.cs b/src/Essentials/src/Obsolete/DeviceInfo.cs deleted file mode 100644 index d896f1ff7b24..000000000000 --- a/src/Essentials/src/Obsolete/DeviceInfo.cs +++ /dev/null @@ -1,41 +0,0 @@ -#nullable enable -using System; - -namespace Microsoft.Maui.Devices -{ - /// - public static partial class DeviceInfo - { - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static string Model => Current.Model; - - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static string Manufacturer => Current.Manufacturer; - - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static string Name => Current.Name; - - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static string VersionString => Current.VersionString; - - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static Version Version => Current.Version; - - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static DevicePlatform Platform => Current.Platform; - - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static DeviceIdiom Idiom => Current.Idiom; - - /// - [Obsolete($"Use {nameof(DeviceInfo)}.{nameof(Current)} instead.", true)] - public static DeviceType DeviceType => Current.DeviceType; - } -} diff --git a/src/Essentials/src/Obsolete/Email.cs b/src/Essentials/src/Obsolete/Email.cs deleted file mode 100644 index e6641ebc7e90..000000000000 --- a/src/Essentials/src/Obsolete/Email.cs +++ /dev/null @@ -1,24 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.Communication; - -namespace Microsoft.Maui.ApplicationModel.Communication -{ - /// - public static class Email - { - /// - public static Task ComposeAsync() => - Current.ComposeAsync(); - - /// - public static Task ComposeAsync(string subject, string body, params string[] to) => - Current.ComposeAsync(subject, body, to); - - /// - public static Task ComposeAsync(EmailMessage message) => - Current.ComposeAsync(message); - - static IEmail Current => ApplicationModel.Communication.Email.Default; - } -} diff --git a/src/Essentials/src/Obsolete/FilePicker.cs b/src/Essentials/src/Obsolete/FilePicker.cs deleted file mode 100644 index f15706f8c3f3..000000000000 --- a/src/Essentials/src/Obsolete/FilePicker.cs +++ /dev/null @@ -1,21 +0,0 @@ -#nullable enable -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.Maui.Storage; - -namespace Microsoft.Maui.Storage -{ - /// - public static partial class FilePicker - { - /// - public static Task PickAsync(PickOptions? options = null) => - Current.PickAsync(options); - - /// - public static Task> PickMultipleAsync(PickOptions? options = null) => - Current.PickMultipleAsync(options); - - static IFilePicker Current => Storage.FilePicker.Default; - } -} diff --git a/src/Essentials/src/Obsolete/FileSystem.cs b/src/Essentials/src/Obsolete/FileSystem.cs deleted file mode 100644 index d5bb197f05d5..000000000000 --- a/src/Essentials/src/Obsolete/FileSystem.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable -using System; -using System.IO; -using System.Threading.Tasks; - -namespace Microsoft.Maui.Storage -{ - /// - public static partial class FileSystem - { - /// - [Obsolete($"Use {nameof(FileSystem)}.{nameof(Current)} instead.", true)] - public static string CacheDirectory - => Current.CacheDirectory; - - /// - [Obsolete($"Use {nameof(FileSystem)}.{nameof(Current)} instead.", true)] - public static string AppDataDirectory - => Current.AppDataDirectory; - - /// - [Obsolete($"Use {nameof(FileSystem)}.{nameof(Current)} instead.", true)] - public static Task OpenAppPackageFileAsync(string filename) - => Current.OpenAppPackageFileAsync(filename); - - [Obsolete($"Use {nameof(FileSystem)}.{nameof(Current)} instead.", true)] - public static Task AppPackageFileExistsAsync(string filename) - => Current.AppPackageFileExistsAsync(filename); - } -} diff --git a/src/Essentials/src/Obsolete/Flashlight.cs b/src/Essentials/src/Obsolete/Flashlight.cs deleted file mode 100644 index 98906fce592a..000000000000 --- a/src/Essentials/src/Obsolete/Flashlight.cs +++ /dev/null @@ -1,20 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.Devices; - -namespace Microsoft.Maui.Devices -{ - /// - public static partial class Flashlight - { - /// - public static Task TurnOnAsync() => - Current.TurnOnAsync(); - - /// - public static Task TurnOffAsync() => - Current.TurnOffAsync(); - - static IFlashlight Current => Devices.Flashlight.Current; - } -} diff --git a/src/Essentials/src/Obsolete/Geocoding.cs b/src/Essentials/src/Obsolete/Geocoding.cs deleted file mode 100644 index d5d7ba136f21..000000000000 --- a/src/Essentials/src/Obsolete/Geocoding.cs +++ /dev/null @@ -1,26 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.Devices.Sensors -{ - /// - public static class Geocoding - { - /// - public static Task> GetPlacemarksAsync(Location location) => - Current.GetPlacemarksAsync(location); - - /// - public static Task> GetPlacemarksAsync(double latitude, double longitude) => - Current.GetPlacemarksAsync(latitude, longitude); - - /// - public static Task> GetLocationsAsync(string address) => - Current.GetLocationsAsync(address); - - static IGeocoding Current => Devices.Sensors.Geocoding.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Geolocation.cs b/src/Essentials/src/Obsolete/Geolocation.cs deleted file mode 100644 index 5fbeeeb427b2..000000000000 --- a/src/Essentials/src/Obsolete/Geolocation.cs +++ /dev/null @@ -1,29 +0,0 @@ -#nullable enable -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.Devices.Sensors -{ - /// - public static partial class Geolocation - { - /// - public static Task GetLastKnownLocationAsync() => - Current.GetLastKnownLocationAsync(); - - /// - public static Task GetLocationAsync() => - Current.GetLocationAsync(); - - /// - public static Task GetLocationAsync(GeolocationRequest request) => - Current.GetLocationAsync(request); - - /// - public static Task GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken) => - Current.GetLocationAsync(request, cancelToken); - - static IGeolocation Current => Devices.Sensors.Geolocation.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Gyroscope.cs b/src/Essentials/src/Obsolete/Gyroscope.cs deleted file mode 100644 index 45ed13347b41..000000000000 --- a/src/Essentials/src/Obsolete/Gyroscope.cs +++ /dev/null @@ -1,33 +0,0 @@ -#nullable enable -using System; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.Devices.Sensors -{ - /// - public static partial class Gyroscope - { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - /// - public static bool IsMonitoring - => Current.IsMonitoring; - - public static bool IsSupported - => Current.IsSupported; - - /// - public static void Start(SensorSpeed sensorSpeed) - => Current.Start(sensorSpeed); - - /// - public static void Stop() - => Current.Stop(); - - static IGyroscope Current => Devices.Sensors.Gyroscope.Default; - } -} diff --git a/src/Essentials/src/Obsolete/HapticFeedback.cs b/src/Essentials/src/Obsolete/HapticFeedback.cs deleted file mode 100644 index baa154904cf4..000000000000 --- a/src/Essentials/src/Obsolete/HapticFeedback.cs +++ /dev/null @@ -1,15 +0,0 @@ -#nullable enable -using Microsoft.Maui.Devices; - -namespace Microsoft.Maui.Devices -{ - /// - public static partial class HapticFeedback - { - /// - public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click) => - Current.Perform(type); - - public static IHapticFeedback Current => Devices.HapticFeedback.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Launcher.cs b/src/Essentials/src/Obsolete/Launcher.cs deleted file mode 100644 index 71c17ca4a964..000000000000 --- a/src/Essentials/src/Obsolete/Launcher.cs +++ /dev/null @@ -1,41 +0,0 @@ -#nullable enable -using System; -using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel; - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public static partial class Launcher - { - /// - public static Task CanOpenAsync(string uri) - => Current.CanOpenAsync(uri); - - /// - public static Task CanOpenAsync(Uri uri) - => Current.CanOpenAsync(uri); - - /// - public static Task OpenAsync(string uri) - => Current.OpenAsync(uri); - - /// - public static Task OpenAsync(Uri uri) - => Current.OpenAsync(uri); - - /// - public static Task OpenAsync(OpenFileRequest request) - => Current.OpenAsync(request); - - /// - public static Task TryOpenAsync(string uri) - => Current.TryOpenAsync(uri); - - /// - public static Task TryOpenAsync(Uri uri) - => Current.TryOpenAsync(uri); - - static ILauncher Current => ApplicationModel.Launcher.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Magnetometer.cs b/src/Essentials/src/Obsolete/Magnetometer.cs deleted file mode 100644 index 091b1a7b9967..000000000000 --- a/src/Essentials/src/Obsolete/Magnetometer.cs +++ /dev/null @@ -1,33 +0,0 @@ -#nullable enable -using System; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.Devices.Sensors -{ - /// - public static partial class Magnetometer - { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - /// - public static bool IsMonitoring - => Current.IsMonitoring; - - public static bool IsSupported - => Current.IsSupported; - - /// - public static void Start(SensorSpeed sensorSpeed) - => Current.Start(sensorSpeed); - - /// - public static void Stop() - => Current.Stop(); - - static IMagnetometer Current => Devices.Sensors.Magnetometer.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Map.cs b/src/Essentials/src/Obsolete/Map.cs deleted file mode 100644 index 722e6d9e3ef6..000000000000 --- a/src/Essentials/src/Obsolete/Map.cs +++ /dev/null @@ -1,37 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public static class Map - { - /// - public static Task OpenAsync(Location location) => - Current.OpenAsync(location); - - /// - public static Task OpenAsync(Location location, MapLaunchOptions options) => - Current.OpenAsync(location, options); - - /// - public static Task OpenAsync(double latitude, double longitude) => - Current.OpenAsync(latitude, longitude); - - /// - public static Task OpenAsync(double latitude, double longitude, MapLaunchOptions options) => - Current.OpenAsync(latitude, longitude, options); - - /// - public static Task OpenAsync(Placemark placemark) => - Current.OpenAsync(placemark); - - /// - public static Task OpenAsync(Placemark placemark, MapLaunchOptions options) => - Current.OpenAsync(placemark, options); - - static IMap Current => ApplicationModel.Map.Default; - } -} diff --git a/src/Essentials/src/Obsolete/MediaPicker.cs b/src/Essentials/src/Obsolete/MediaPicker.cs deleted file mode 100644 index 14ac20b6a564..000000000000 --- a/src/Essentials/src/Obsolete/MediaPicker.cs +++ /dev/null @@ -1,30 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.Storage; - -namespace Microsoft.Maui.Media -{ - /// - public static partial class MediaPicker - { - /// - public static bool IsCaptureSupported => - Default.IsCaptureSupported; - - /// - public static Task PickPhotoAsync(MediaPickerOptions? options = null) => - Default.PickPhotoAsync(options); - - /// - public static Task CapturePhotoAsync(MediaPickerOptions? options = null) => - Default.CapturePhotoAsync(options); - - /// - public static Task PickVideoAsync(MediaPickerOptions? options = null) => - Default.PickVideoAsync(options); - - /// - public static Task CaptureVideoAsync(MediaPickerOptions? options = null) => - Default.CaptureVideoAsync(options); - } -} diff --git a/src/Essentials/src/Obsolete/OrientationSensor.cs b/src/Essentials/src/Obsolete/OrientationSensor.cs deleted file mode 100644 index 0bd0c8d9063f..000000000000 --- a/src/Essentials/src/Obsolete/OrientationSensor.cs +++ /dev/null @@ -1,32 +0,0 @@ -#nullable enable -using System; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.Devices.Sensors -{ - /// - public static class OrientationSensor - { - public static event EventHandler ReadingChanged - { - add => Current.ReadingChanged += value; - remove => Current.ReadingChanged -= value; - } - - public static bool IsSupported - => Current.IsSupported; - - /// - public static bool IsMonitoring { get; private set; } - - /// - public static void Start(SensorSpeed sensorSpeed) - => Current.Start(sensorSpeed); - - /// - public static void Stop() - => Current.Stop(); - - static IOrientationSensor Current => Devices.Sensors.OrientationSensor.Default; - } -} diff --git a/src/Essentials/src/Obsolete/PhoneDialer.cs b/src/Essentials/src/Obsolete/PhoneDialer.cs deleted file mode 100644 index 2a5f4f1693cf..000000000000 --- a/src/Essentials/src/Obsolete/PhoneDialer.cs +++ /dev/null @@ -1,18 +0,0 @@ -#nullable enable -using Microsoft.Maui.ApplicationModel.Communication; - -namespace Microsoft.Maui.ApplicationModel.Communication -{ - /// - public static class PhoneDialer - { - public static bool IsSupported => - Current.IsSupported; - - /// - public static void Open(string number) - => Current.Open(number); - - public static IPhoneDialer Current => ApplicationModel.Communication.PhoneDialer.Default; - } -} diff --git a/src/Essentials/src/Obsolete/PlacemarkExtensions.cs b/src/Essentials/src/Obsolete/PlacemarkExtensions.cs deleted file mode 100644 index 492afd6d0775..000000000000 --- a/src/Essentials/src/Obsolete/PlacemarkExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel; -using Microsoft.Maui.Devices.Sensors; - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public static partial class PlacemarkExtensions - { - /// - public static Task OpenMapsAsync(this Placemark placemark, MapLaunchOptions options) => - Map.OpenAsync(placemark, options); - - /// - public static Task OpenMapsAsync(this Placemark placemark) => - Map.OpenAsync(placemark); - } -} diff --git a/src/Essentials/src/Obsolete/Preferences.cs b/src/Essentials/src/Obsolete/Preferences.cs deleted file mode 100644 index affbaf69efd9..000000000000 --- a/src/Essentials/src/Obsolete/Preferences.cs +++ /dev/null @@ -1,154 +0,0 @@ -#nullable enable -using System; -using Microsoft.Maui.Storage; - -namespace Microsoft.Maui.Storage -{ - /// - public static class Preferences - { - // overloads - - /// - public static bool ContainsKey(string key) => - ContainsKey(key, null); - - /// - public static void Remove(string key) => - Remove(key, null); - - /// - public static void Clear() => - Clear(null); - - /// - public static string Get(string key, string defaultValue) => - Get(key, defaultValue, null); - - /// - public static bool Get(string key, bool defaultValue) => - Get(key, defaultValue, null); - - /// - public static int Get(string key, int defaultValue) => - Get(key, defaultValue, null); - - /// - public static double Get(string key, double defaultValue) => - Get(key, defaultValue, null); - - /// - public static float Get(string key, float defaultValue) => - Get(key, defaultValue, null); - - /// - public static long Get(string key, long defaultValue) => - Get(key, defaultValue, null); - - /// - public static void Set(string key, string value) => - Set(key, value, null); - - /// - public static void Set(string key, bool value) => - Set(key, value, null); - - /// - public static void Set(string key, int value) => - Set(key, value, null); - - /// - public static void Set(string key, double value) => - Set(key, value, null); - - /// - public static void Set(string key, float value) => - Set(key, value, null); - - /// - public static void Set(string key, long value) => - Set(key, value, null); - - // shared -> platform - - /// - public static bool ContainsKey(string key, string? sharedName) => - Current.ContainsKey(key, sharedName); - - /// - public static void Remove(string key, string? sharedName) => - Current.Remove(key, sharedName); - - /// - public static void Clear(string? sharedName) => - Current.Clear(sharedName); - - /// - public static string Get(string key, string defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static bool Get(string key, bool defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static int Get(string key, int defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static double Get(string key, double defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static float Get(string key, float defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static long Get(string key, long defaultValue, string? sharedName) => - Current.Get(key, defaultValue, sharedName); - - /// - public static void Set(string key, string value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, bool value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, int value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, double value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, float value, string? sharedName) => - Current.Set(key, value, sharedName); - - /// - public static void Set(string key, long value, string? sharedName) => - Current.Set(key, value, sharedName); - - // DateTime - - /// - public static DateTime Get(string key, DateTime defaultValue) => - Get(key, defaultValue, null); - - /// - public static void Set(string key, DateTime value) => - Set(key, value, null); - - /// - public static DateTime Get(string key, DateTime defaultValue, string? sharedName) => - DateTime.FromBinary(Current.Get(key, defaultValue.ToBinary(), sharedName)); - - /// - public static void Set(string key, DateTime value, string? sharedName) => - Current.Set(key, value.ToBinary(), sharedName); - - static IPreferences Current => Storage.Preferences.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Screenshot.cs b/src/Essentials/src/Obsolete/Screenshot.cs deleted file mode 100644 index 01e15c60ed0f..000000000000 --- a/src/Essentials/src/Obsolete/Screenshot.cs +++ /dev/null @@ -1,23 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.Media; - -namespace Microsoft.Maui.Media -{ - /// - public static partial class Screenshot - { - /// - public static bool IsCaptureSupported - => Current.IsCaptureSupported; - - /// - public static Task CaptureAsync() - { - if (!IsCaptureSupported) - throw new FeatureNotSupportedException(); - - return Current.CaptureAsync(); - } - } -} diff --git a/src/Essentials/src/Obsolete/SecureStorage.cs b/src/Essentials/src/Obsolete/SecureStorage.cs deleted file mode 100644 index 7f2886dbebcb..000000000000 --- a/src/Essentials/src/Obsolete/SecureStorage.cs +++ /dev/null @@ -1,39 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.Storage; - -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class SecureStorage - { - /// - public static Task GetAsync(string key) => - Current.GetAsync(key); - - /// - public static Task SetAsync(string key, string value) => - Current.SetAsync(key, value); - - /// - public static bool Remove(string key) => - Current.Remove(key); - - /// - public static void RemoveAll() => - Current.RemoveAll(); - -#if IOS || MACCATALYST || MACOS || TVOS || WATCHOS - public static Security.SecAccessible DefaultAccessible - { - get => Current.GetDefaultAccessible(); - set => Current.SetDefaultAccessible(value); - } - - public static Task SetAsync(string key, string value, Security.SecAccessible accessible) => - Current.SetAsync(key, value, accessible); -#endif - - static ISecureStorage Current => Storage.SecureStorage.Default; - } -} diff --git a/src/Essentials/src/Obsolete/SemanticScreenReader.cs b/src/Essentials/src/Obsolete/SemanticScreenReader.cs deleted file mode 100644 index d5e0298e423a..000000000000 --- a/src/Essentials/src/Obsolete/SemanticScreenReader.cs +++ /dev/null @@ -1,15 +0,0 @@ -#nullable enable -using Microsoft.Maui.Accessibility; - -namespace Microsoft.Maui.Essentials -{ - public static partial class SemanticScreenReader - { - public static void Announce(string text) - { - Current.Announce(text); - } - - static ISemanticScreenReader Current => Accessibility.SemanticScreenReader.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Share.cs b/src/Essentials/src/Obsolete/Share.cs deleted file mode 100644 index 224b6e93e46f..000000000000 --- a/src/Essentials/src/Obsolete/Share.cs +++ /dev/null @@ -1,32 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.DataTransfer; - -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class Share - { - /// - public static Task RequestAsync(string text) => - Current.RequestAsync(text); - - /// - public static Task RequestAsync(string text, string title) => - Current.RequestAsync(text, title); - - /// - public static Task RequestAsync(ShareTextRequest request) => - Current.RequestAsync(request); - - /// - public static Task RequestAsync(ShareFileRequest request) => - Current.RequestAsync(request); - - /// - public static Task RequestAsync(ShareMultipleFilesRequest request) => - Current.RequestAsync(request); - - static IShare Current => ApplicationModel.DataTransfer.Share.Default; - } -} diff --git a/src/Essentials/src/Obsolete/Sms.cs b/src/Essentials/src/Obsolete/Sms.cs deleted file mode 100644 index 3cd31b897e0a..000000000000 --- a/src/Essentials/src/Obsolete/Sms.cs +++ /dev/null @@ -1,20 +0,0 @@ -#nullable enable -using System.Threading.Tasks; -using Microsoft.Maui.ApplicationModel.Communication; - -namespace Microsoft.Maui.Essentials -{ - /// - public static class Sms - { - /// - public static Task ComposeAsync() - => Current.ComposeAsync(null); - - /// - public static Task ComposeAsync(SmsMessage? message) - => Current.ComposeAsync(message); - - static ISms Current => ApplicationModel.Communication.Sms.Default; - } -} diff --git a/src/Essentials/src/Obsolete/TextToSpeech.cs b/src/Essentials/src/Obsolete/TextToSpeech.cs deleted file mode 100644 index 738f68785e5d..000000000000 --- a/src/Essentials/src/Obsolete/TextToSpeech.cs +++ /dev/null @@ -1,26 +0,0 @@ -#nullable enable -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Maui.Media; - -namespace Microsoft.Maui.Essentials -{ - /// - public static partial class TextToSpeech - { - /// - public static Task> GetLocalesAsync() => - Current.GetLocalesAsync(); - - /// - public static Task SpeakAsync(string text, CancellationToken cancelToken = default) => - Current.SpeakAsync(text, default, cancelToken); - - /// - public static Task SpeakAsync(string text, SpeechOptions? options, CancellationToken cancelToken = default) => - Current.SpeakAsync(text, options, cancelToken); - - static ITextToSpeech Current => Media.TextToSpeech.Current; - } -} diff --git a/src/Essentials/src/Obsolete/VersionTracking.cs b/src/Essentials/src/Obsolete/VersionTracking.cs deleted file mode 100644 index 9cd77118c583..000000000000 --- a/src/Essentials/src/Obsolete/VersionTracking.cs +++ /dev/null @@ -1,80 +0,0 @@ -#nullable enable -using System; -using System.Collections.Generic; - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public static partial class VersionTracking - { - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static void Track() - => Default.Track(); - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static bool IsFirstLaunchEver - => Default.IsFirstLaunchEver; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static bool IsFirstLaunchForCurrentVersion - => Default.IsFirstLaunchForCurrentVersion; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static bool IsFirstLaunchForCurrentBuild - => Default.IsFirstLaunchForCurrentBuild; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static string CurrentVersion - => Default.CurrentVersion; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static string CurrentBuild - => Default.CurrentBuild; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static string? PreviousVersion - => Default.PreviousVersion; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static string? PreviousBuild - => Default.PreviousBuild; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static string? FirstInstalledVersion - => Default.FirstInstalledVersion; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static string? FirstInstalledBuild - => Default.FirstInstalledBuild; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static IEnumerable VersionHistory - => Default.VersionHistory; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static IEnumerable BuildHistory - => Default.BuildHistory; - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static bool IsFirstLaunchForVersion(string version) - => Default.IsFirstLaunchForVersion(version); - - /// - [Obsolete($"Use {nameof(VersionTracking)}.{nameof(Default)} instead.", true)] - public static bool IsFirstLaunchForBuild(string build) - => Default.IsFirstLaunchForBuild(build); - } -} diff --git a/src/Essentials/src/Obsolete/Vibration.cs b/src/Essentials/src/Obsolete/Vibration.cs deleted file mode 100644 index eab539b0776a..000000000000 --- a/src/Essentials/src/Obsolete/Vibration.cs +++ /dev/null @@ -1,28 +0,0 @@ -#nullable enable -using System; -using Microsoft.Maui.Devices; - -namespace Microsoft.Maui.Essentials -{ - /// - public static class Vibration - { - /// - public static void Vibrate() => - Current.Vibrate(); - - /// - public static void Vibrate(double duration) => - Current.Vibrate(duration); - - /// - public static void Vibrate(TimeSpan duration) => - Current.Vibrate(duration); - - /// - public static void Cancel() => - Current.Cancel(); - - static IVibration Current => Devices.Vibration.Default; - } -} diff --git a/src/Essentials/src/Obsolete/WebAuthenticator.cs b/src/Essentials/src/Obsolete/WebAuthenticator.cs deleted file mode 100644 index 1b927cfe6c90..000000000000 --- a/src/Essentials/src/Obsolete/WebAuthenticator.cs +++ /dev/null @@ -1,21 +0,0 @@ -#nullable enable -using System; -using System.Threading.Tasks; -using Microsoft.Maui.Authentication; - -namespace Microsoft.Maui.Essentials -{ - /// - public static class WebAuthenticator - { - /// - public static Task AuthenticateAsync(Uri url, Uri callbackUrl) - => Current.AuthenticateAsync(url, callbackUrl); - - /// - public static Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) - => Current.AuthenticateAsync(webAuthenticatorOptions); - - static IWebAuthenticator Current => Authentication.WebAuthenticator.Default; - } -} diff --git a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs index 0779724c3848..fded6970f733 100644 --- a/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs +++ b/src/Essentials/src/OrientationSensor/OrientationSensor.shared.cs @@ -18,8 +18,31 @@ public interface IOrientationSensor event EventHandler ReadingChanged; } - public static partial class OrientationSensor + /// + public static class OrientationSensor { + public static event EventHandler ReadingChanged + { + add => Current.ReadingChanged += value; + remove => Current.ReadingChanged -= value; + } + + public static bool IsSupported + => Current.IsSupported; + + /// + public static bool IsMonitoring { get; private set; } + + /// + public static void Start(SensorSpeed sensorSpeed) + => Current.Start(sensorSpeed); + + /// + public static void Stop() + => Current.Stop(); + + static IOrientationSensor Current => Devices.Sensors.OrientationSensor.Default; + static IOrientationSensor? defaultImplementation; public static IOrientationSensor Default => diff --git a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs index c1f96b0cfbd5..6321045a1655 100644 --- a/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs +++ b/src/Essentials/src/PhoneDialer/PhoneDialer.shared.cs @@ -10,8 +10,18 @@ public interface IPhoneDialer void Open(string number); } + /// public static class PhoneDialer { + public static bool IsSupported => + Current.IsSupported; + + /// + public static void Open(string number) + => Current.Open(number); + + public static IPhoneDialer Current => ApplicationModel.Communication.PhoneDialer.Default; + static IPhoneDialer? defaultImplementation; public static IPhoneDialer Default => diff --git a/src/Essentials/src/Obsolete/Platform.cs b/src/Essentials/src/Platform/Platform.shared.cs similarity index 100% rename from src/Essentials/src/Obsolete/Platform.cs rename to src/Essentials/src/Platform/Platform.shared.cs diff --git a/src/Essentials/src/Preferences/Preferences.shared.cs b/src/Essentials/src/Preferences/Preferences.shared.cs index bddf0526c4fb..e698ebfadb08 100644 --- a/src/Essentials/src/Preferences/Preferences.shared.cs +++ b/src/Essentials/src/Preferences/Preferences.shared.cs @@ -15,8 +15,153 @@ public interface IPreferences T Get(string key, T defaultValue, string? sharedName = null); } +/// public static class Preferences { + // overloads + + /// + public static bool ContainsKey(string key) => + ContainsKey(key, null); + + /// + public static void Remove(string key) => + Remove(key, null); + + /// + public static void Clear() => + Clear(null); + + /// + public static string Get(string key, string defaultValue) => + Get(key, defaultValue, null); + + /// + public static bool Get(string key, bool defaultValue) => + Get(key, defaultValue, null); + + /// + public static int Get(string key, int defaultValue) => + Get(key, defaultValue, null); + + /// + public static double Get(string key, double defaultValue) => + Get(key, defaultValue, null); + + /// + public static float Get(string key, float defaultValue) => + Get(key, defaultValue, null); + + /// + public static long Get(string key, long defaultValue) => + Get(key, defaultValue, null); + + /// + public static void Set(string key, string value) => + Set(key, value, null); + + /// + public static void Set(string key, bool value) => + Set(key, value, null); + + /// + public static void Set(string key, int value) => + Set(key, value, null); + + /// + public static void Set(string key, double value) => + Set(key, value, null); + + /// + public static void Set(string key, float value) => + Set(key, value, null); + + /// + public static void Set(string key, long value) => + Set(key, value, null); + + // shared -> platform + + /// + public static bool ContainsKey(string key, string? sharedName) => + Current.ContainsKey(key, sharedName); + + /// + public static void Remove(string key, string? sharedName) => + Current.Remove(key, sharedName); + + /// + public static void Clear(string? sharedName) => + Current.Clear(sharedName); + + /// + public static string Get(string key, string defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static bool Get(string key, bool defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static int Get(string key, int defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static double Get(string key, double defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static float Get(string key, float defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static long Get(string key, long defaultValue, string? sharedName) => + Current.Get(key, defaultValue, sharedName); + + /// + public static void Set(string key, string value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, bool value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, int value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, double value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, float value, string? sharedName) => + Current.Set(key, value, sharedName); + + /// + public static void Set(string key, long value, string? sharedName) => + Current.Set(key, value, sharedName); + + // DateTime + + /// + public static DateTime Get(string key, DateTime defaultValue) => + Get(key, defaultValue, null); + + /// + public static void Set(string key, DateTime value) => + Set(key, value, null); + + /// + public static DateTime Get(string key, DateTime defaultValue, string? sharedName) => + DateTime.FromBinary(Current.Get(key, defaultValue.ToBinary(), sharedName)); + + /// + public static void Set(string key, DateTime value, string? sharedName) => + Current.Set(key, value.ToBinary(), sharedName); + + static IPreferences Current => Storage.Preferences.Default; + internal static string GetPrivatePreferencesSharedName(string feature) => $"{ApplicationModel.AppInfo.Current.PackageName}.microsoft.maui.essentials.{feature}"; diff --git a/src/Essentials/src/Screenshot/Screenshot.shared.cs b/src/Essentials/src/Screenshot/Screenshot.shared.cs index f8fe6a9a1ae2..98cf13e7408b 100644 --- a/src/Essentials/src/Screenshot/Screenshot.shared.cs +++ b/src/Essentials/src/Screenshot/Screenshot.shared.cs @@ -46,8 +46,22 @@ public interface IScreenshotResult Task ToPixelBufferAsync(); } - public static class Screenshot + /// + public static partial class Screenshot { + /// + public static bool IsCaptureSupported + => Current.IsCaptureSupported; + + /// + public static Task CaptureAsync() + { + if (!IsCaptureSupported) + throw new FeatureNotSupportedException(); + + return Current.CaptureAsync(); + } + static IScreenshot? currentImplementation; public static IScreenshot Current => diff --git a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs index e3b95b1aeeb3..8b08e2aaaab9 100644 --- a/src/Essentials/src/SecureStorage/SecureStorage.shared.cs +++ b/src/Essentials/src/SecureStorage/SecureStorage.shared.cs @@ -24,8 +24,38 @@ public interface IPlatformSecureStorage #endif } + /// public static partial class SecureStorage { + /// + public static Task GetAsync(string key) => + Current.GetAsync(key); + + /// + public static Task SetAsync(string key, string value) => + Current.SetAsync(key, value); + + /// + public static bool Remove(string key) => + Current.Remove(key); + + /// + public static void RemoveAll() => + Current.RemoveAll(); + +#if IOS || MACCATALYST || MACOS || TVOS || WATCHOS + public static Security.SecAccessible DefaultAccessible + { + get => Current.GetDefaultAccessible(); + set => Current.SetDefaultAccessible(value); + } + + public static Task SetAsync(string key, string value, Security.SecAccessible accessible) => + Current.SetAsync(key, value, accessible); +#endif + + static ISecureStorage Current => Storage.SecureStorage.Default; + static ISecureStorage? defaultImplementation; public static ISecureStorage Default => diff --git a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs index a9afe5e9fc61..209dee361763 100644 --- a/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs +++ b/src/Essentials/src/SemanticScreenReader/SemanticScreenReader.shared.cs @@ -9,6 +9,13 @@ public interface ISemanticScreenReader public static partial class SemanticScreenReader { + public static void Announce(string text) + { + Current.Announce(text); + } + + static ISemanticScreenReader Current => Accessibility.SemanticScreenReader.Default; + static ISemanticScreenReader? defaultImplementation; public static ISemanticScreenReader Default => diff --git a/src/Essentials/src/Share/Share.shared.cs b/src/Essentials/src/Share/Share.shared.cs index 03d52e9e5ca2..627efd7dfc07 100644 --- a/src/Essentials/src/Share/Share.shared.cs +++ b/src/Essentials/src/Share/Share.shared.cs @@ -17,8 +17,31 @@ public interface IShare Task RequestAsync(ShareMultipleFilesRequest request); } - public static class Share + /// + public static partial class Share { + /// + public static Task RequestAsync(string text) => + Current.RequestAsync(text); + + /// + public static Task RequestAsync(string text, string title) => + Current.RequestAsync(text, title); + + /// + public static Task RequestAsync(ShareTextRequest request) => + Current.RequestAsync(request); + + /// + public static Task RequestAsync(ShareFileRequest request) => + Current.RequestAsync(request); + + /// + public static Task RequestAsync(ShareMultipleFilesRequest request) => + Current.RequestAsync(request); + + static IShare Current => ApplicationModel.DataTransfer.Share.Default; + static IShare? defaultImplementation; public static IShare Default => diff --git a/src/Essentials/src/Sms/Sms.shared.cs b/src/Essentials/src/Sms/Sms.shared.cs index 4a92561b2224..388dffef7b86 100644 --- a/src/Essentials/src/Sms/Sms.shared.cs +++ b/src/Essentials/src/Sms/Sms.shared.cs @@ -12,8 +12,19 @@ public interface ISms Task ComposeAsync(SmsMessage? message); } + /// public static class Sms { + /// + public static Task ComposeAsync() + => Current.ComposeAsync(null); + + /// + public static Task ComposeAsync(SmsMessage? message) + => Current.ComposeAsync(message); + + static ISms Current => ApplicationModel.Communication.Sms.Default; + static ISms? defaultImplementation; public static ISms Default => diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs index fc14744ca43f..ef85f5369411 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs @@ -13,8 +13,23 @@ public interface ITextToSpeech Task SpeakAsync(string text, SpeechOptions? options = default, CancellationToken cancelToken = default); } - public static class TextToSpeech + /// + public static partial class TextToSpeech { + /// + public static Task> GetLocalesAsync() => + Current.GetLocalesAsync(); + + /// + public static Task SpeakAsync(string text, CancellationToken cancelToken = default) => + Current.SpeakAsync(text, default, cancelToken); + + /// + public static Task SpeakAsync(string text, SpeechOptions? options, CancellationToken cancelToken = default) => + Current.SpeakAsync(text, options, cancelToken); + + static ITextToSpeech Current => Media.TextToSpeech.Current; + static ITextToSpeech? currentImplementation; public static ITextToSpeech Current => diff --git a/src/Essentials/src/Obsolete/LocationExtensions.cs b/src/Essentials/src/Types/LocationExtensions.shared.cs similarity index 96% rename from src/Essentials/src/Obsolete/LocationExtensions.cs rename to src/Essentials/src/Types/LocationExtensions.shared.cs index d0a36e063fc2..53485aba6b04 100644 --- a/src/Essentials/src/Obsolete/LocationExtensions.cs +++ b/src/Essentials/src/Types/LocationExtensions.shared.cs @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Devices.Sensors { /// - public static class LocationExtensions + public static partial class LocationExtensions { /// public static double CalculateDistance(this Location locationStart, double latitudeEnd, double longitudeEnd, DistanceUnits units) => diff --git a/src/Essentials/src/Types/PlacemarkExtensions.shared.cs b/src/Essentials/src/Types/PlacemarkExtensions.shared.cs index 31de4b32b1d3..148230e7ad7d 100644 --- a/src/Essentials/src/Types/PlacemarkExtensions.shared.cs +++ b/src/Essentials/src/Types/PlacemarkExtensions.shared.cs @@ -4,8 +4,17 @@ namespace Microsoft.Maui.Devices.Sensors { - static partial class PlacemarkExtensions + /// + public static partial class PlacemarkExtensions { + /// + public static Task OpenMapsAsync(this Placemark placemark, MapLaunchOptions options) => + Map.OpenAsync(placemark, options); + + /// + public static Task OpenMapsAsync(this Placemark placemark) => + Map.OpenAsync(placemark); + internal static string GetEscapedAddress(this Placemark placemark) { if (placemark == null) diff --git a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs index 1bb3f4ca2ccf..ceaedc77e5e6 100644 --- a/src/Essentials/src/VersionTracking/VersionTracking.shared.cs +++ b/src/Essentials/src/VersionTracking/VersionTracking.shared.cs @@ -38,8 +38,65 @@ public interface IVersionTracking bool IsFirstLaunchForBuild(string build); } + /// public static partial class VersionTracking { + /// + public static void Track() + => Default.Track(); + + /// + public static bool IsFirstLaunchEver + => Default.IsFirstLaunchEver; + + /// + public static bool IsFirstLaunchForCurrentVersion + => Default.IsFirstLaunchForCurrentVersion; + + /// + public static bool IsFirstLaunchForCurrentBuild + => Default.IsFirstLaunchForCurrentBuild; + + /// + public static string CurrentVersion + => Default.CurrentVersion; + + /// + public static string CurrentBuild + => Default.CurrentBuild; + + /// + public static string? PreviousVersion + => Default.PreviousVersion; + + /// + public static string? PreviousBuild + => Default.PreviousBuild; + + /// + public static string? FirstInstalledVersion + => Default.FirstInstalledVersion; + + /// + public static string? FirstInstalledBuild + => Default.FirstInstalledBuild; + + /// + public static IEnumerable VersionHistory + => Default.VersionHistory; + + /// + public static IEnumerable BuildHistory + => Default.BuildHistory; + + /// + public static bool IsFirstLaunchForVersion(string version) + => Default.IsFirstLaunchForVersion(version); + + /// + public static bool IsFirstLaunchForBuild(string build) + => Default.IsFirstLaunchForBuild(build); + static IVersionTracking? defaultImplementation; public static IVersionTracking Default => diff --git a/src/Essentials/src/Vibration/Vibration.shared.cs b/src/Essentials/src/Vibration/Vibration.shared.cs index 5948534ae785..0d7e03a73e76 100644 --- a/src/Essentials/src/Vibration/Vibration.shared.cs +++ b/src/Essentials/src/Vibration/Vibration.shared.cs @@ -14,8 +14,27 @@ public interface IVibration void Cancel(); } + /// public static class Vibration { + /// + public static void Vibrate() => + Current.Vibrate(); + + /// + public static void Vibrate(double duration) => + Current.Vibrate(duration); + + /// + public static void Vibrate(TimeSpan duration) => + Current.Vibrate(duration); + + /// + public static void Cancel() => + Current.Cancel(); + + static IVibration Current => Devices.Vibration.Default; + static IVibration? defaultImplementation; public static IVibration Default => diff --git a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs index d76f5e912766..6f780dab1e5c 100644 --- a/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs @@ -18,8 +18,19 @@ public interface IPlatformWebAuthenticatorCallback #endif } + /// public static class WebAuthenticator { + /// + public static Task AuthenticateAsync(Uri url, Uri callbackUrl) + => Current.AuthenticateAsync(url, callbackUrl); + + /// + public static Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) + => Current.AuthenticateAsync(webAuthenticatorOptions); + + static IWebAuthenticator Current => Authentication.WebAuthenticator.Default; + static IWebAuthenticator? defaultImplementation; public static IWebAuthenticator Default => From e8751f00b1505f0d58c7191b725796246c16ef24 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:23:33 +0200 Subject: [PATCH 28/45] revert --- .../src/Android/Compatibility.ControlGallery.Android.csproj | 2 +- .../src/Core/Compatibility.ControlGallery.Core.csproj | 4 ++-- .../src/WinUI/Compatibility.ControlGallery.WinUI.csproj | 2 +- .../src/iOS/Compatibility.ControlGallery.iOS.csproj | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compatibility/ControlGallery/src/Android/Compatibility.ControlGallery.Android.csproj b/src/Compatibility/ControlGallery/src/Android/Compatibility.ControlGallery.Android.csproj index 28294267c73e..a8cee2857d32 100644 --- a/src/Compatibility/ControlGallery/src/Android/Compatibility.ControlGallery.Android.csproj +++ b/src/Compatibility/ControlGallery/src/Android/Compatibility.ControlGallery.Android.csproj @@ -9,7 +9,7 @@ disable None - IL2036;0618;0612;0619 + IL2036;0618;0612 - 0612;0619 + 0612 From f26fafc373b873c0e40e8b40ebd45a95c2b36c6d Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:24:49 +0200 Subject: [PATCH 29/45] no need to fix here --- src/Core/src/Platform/Android/ViewExtensions.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Core/src/Platform/Android/ViewExtensions.cs b/src/Core/src/Platform/Android/ViewExtensions.cs index da0d1f64817d..e91ed9f7b7bc 100644 --- a/src/Core/src/Platform/Android/ViewExtensions.cs +++ b/src/Core/src/Platform/Android/ViewExtensions.cs @@ -77,13 +77,20 @@ public static void Focus(this AView platformView, FocusRequest request) // So in case we're setting the focus in response to another control's un-focusing, // we need to post the handling of it to the main looper so that it happens _after_ all the other focus // work is done; otherwise, a call to ClearFocus on another control will kill the focus we set - platformView.Post(() => + + var q = Looper.MyLooper(); + if (q != null) + new Handler(q).Post(RequestFocus); + else + MainThread.InvokeOnMainThreadAsync(RequestFocus); + + void RequestFocus() { if (platformView == null || platformView.IsDisposed()) return; platformView?.RequestFocus(); - }); + } } public static void Unfocus(this AView platformView, IView view) From a4987d8b35030449dc6cd679404c43031fe16e06 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:26:07 +0200 Subject: [PATCH 30/45] revert --- .../samples/Samples/ViewModel/DeviceInfoViewModel.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs b/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs index 4a7bad30d2e4..f0f4fd65ff81 100644 --- a/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs +++ b/src/Essentials/samples/Samples/ViewModel/DeviceInfoViewModel.cs @@ -16,7 +16,7 @@ public class DeviceInfoViewModel : BaseViewModel public string Version => DeviceInfo.Version.ToString(); - public DevicePlatform Platform => DeviceInfo.Current.Platform; + public DevicePlatform Platform => DeviceInfo.Platform; public DeviceIdiom Idiom => DeviceInfo.Idiom; @@ -32,13 +32,13 @@ public override void OnAppearing() { base.OnAppearing(); - DeviceDisplay.Current.MainDisplayInfoChanged += OnScreenMetricsChanged; - ScreenMetrics = DeviceDisplay.Current.MainDisplayInfo; + DeviceDisplay.MainDisplayInfoChanged += OnScreenMetricsChanged; + ScreenMetrics = DeviceDisplay.MainDisplayInfo; } public override void OnDisappearing() { - DeviceDisplay.Current.MainDisplayInfoChanged -= OnScreenMetricsChanged; + DeviceDisplay.MainDisplayInfoChanged -= OnScreenMetricsChanged; base.OnDisappearing(); } From ddc15d52db719134053de18f3ab34cc17a0999db Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:27:53 +0200 Subject: [PATCH 31/45] filenames --- .../Platform/{Platform.android.cs => PlatformUtils.android.cs} | 0 ...form.ios.tvos.watchos.cs => PlatformUtils.ios.tvos.watchos.cs} | 0 .../src/Platform/{Platform.macos.cs => PlatformUtils.macos.cs} | 0 .../src/Platform/{Platform.tizen.cs => PlatformUtils.tizen.cs} | 0 .../src/Platform/{Platform.uwp.cs => PlatformUtils.uwp.cs} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename src/Essentials/src/Platform/{Platform.android.cs => PlatformUtils.android.cs} (100%) rename src/Essentials/src/Platform/{Platform.ios.tvos.watchos.cs => PlatformUtils.ios.tvos.watchos.cs} (100%) rename src/Essentials/src/Platform/{Platform.macos.cs => PlatformUtils.macos.cs} (100%) rename src/Essentials/src/Platform/{Platform.tizen.cs => PlatformUtils.tizen.cs} (100%) rename src/Essentials/src/Platform/{Platform.uwp.cs => PlatformUtils.uwp.cs} (100%) diff --git a/src/Essentials/src/Platform/Platform.android.cs b/src/Essentials/src/Platform/PlatformUtils.android.cs similarity index 100% rename from src/Essentials/src/Platform/Platform.android.cs rename to src/Essentials/src/Platform/PlatformUtils.android.cs diff --git a/src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs b/src/Essentials/src/Platform/PlatformUtils.ios.tvos.watchos.cs similarity index 100% rename from src/Essentials/src/Platform/Platform.ios.tvos.watchos.cs rename to src/Essentials/src/Platform/PlatformUtils.ios.tvos.watchos.cs diff --git a/src/Essentials/src/Platform/Platform.macos.cs b/src/Essentials/src/Platform/PlatformUtils.macos.cs similarity index 100% rename from src/Essentials/src/Platform/Platform.macos.cs rename to src/Essentials/src/Platform/PlatformUtils.macos.cs diff --git a/src/Essentials/src/Platform/Platform.tizen.cs b/src/Essentials/src/Platform/PlatformUtils.tizen.cs similarity index 100% rename from src/Essentials/src/Platform/Platform.tizen.cs rename to src/Essentials/src/Platform/PlatformUtils.tizen.cs diff --git a/src/Essentials/src/Platform/Platform.uwp.cs b/src/Essentials/src/Platform/PlatformUtils.uwp.cs similarity index 100% rename from src/Essentials/src/Platform/Platform.uwp.cs rename to src/Essentials/src/Platform/PlatformUtils.uwp.cs From 54e609049e9e199972738a60cf4ae131a8072211 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:33:02 +0200 Subject: [PATCH 32/45] this --- .../Microsoft.Maui.Sdk/Sdk/AutoImport.props | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.props b/src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.props index e8035d7c7353..b19d4cb94260 100644 --- a/src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.props +++ b/src/Workload/Microsoft.Maui.Sdk/Sdk/AutoImport.props @@ -14,9 +14,18 @@ - - + + + + + + + + + + + From 53221473b12b6bf509712f0065cfb10f632a53fa Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:50:05 +0200 Subject: [PATCH 33/45] fix --- src/Core/src/ViewExtensions.cs | 4 ++-- src/Core/src/WindowExtensions.cs | 4 ++-- src/Essentials/src/Contacts/Contacts.shared.cs | 14 +++++++------- src/Essentials/src/Email/Email.shared.cs | 10 ++++------ .../src/FilePicker/FilePicker.shared.cs | 6 ++---- .../src/Flashlight/Flashlight.shared.cs | 16 +++++++--------- .../src/Preferences/Preferences.shared.cs | 1 + .../src/Screenshot/Screenshot.shared.cs | 14 +++++++------- .../src/TextToSpeech/TextToSpeech.shared.cs | 18 ++++++++---------- 9 files changed, 40 insertions(+), 47 deletions(-) diff --git a/src/Core/src/ViewExtensions.cs b/src/Core/src/ViewExtensions.cs index 907f3913824b..e2d59a29d96d 100644 --- a/src/Core/src/ViewExtensions.cs +++ b/src/Core/src/ViewExtensions.cs @@ -29,7 +29,7 @@ public static partial class ViewExtensions if (view?.ToPlatform() is not PlatformView platformView) return Task.FromResult(null); - if (!Screenshot.Current.IsCaptureSupported) + if (!Screenshot.Default.IsCaptureSupported) return Task.FromResult(null); return CaptureAsync(platformView, format, quality); @@ -41,7 +41,7 @@ public static partial class ViewExtensions #if PLATFORM static async Task CaptureAsync(PlatformView window, ScreenshotFormat format, int quality) { - var result = await Screenshot.Current.CaptureAsync(window); + var result = await Screenshot.Default.CaptureAsync(window); return await result.OpenReadAsync(format, quality); } diff --git a/src/Core/src/WindowExtensions.cs b/src/Core/src/WindowExtensions.cs index 2870c0933e82..341bcd6352c1 100644 --- a/src/Core/src/WindowExtensions.cs +++ b/src/Core/src/WindowExtensions.cs @@ -19,7 +19,7 @@ public static partial class WindowExtensions if (window?.Handler?.PlatformView is not PlatformView platformWindow) return Task.FromResult(null); - if (!Screenshot.Current.IsCaptureSupported) + if (!Screenshot.Default.IsCaptureSupported) return Task.FromResult(null); return CaptureAsync(platformWindow, format, quality); @@ -31,7 +31,7 @@ public static partial class WindowExtensions #if PLATFORM static async Task CaptureAsync(PlatformView window, ScreenshotFormat format, int quality) { - var result = await Screenshot.Current.CaptureAsync(window); + var result = await Screenshot.Default.CaptureAsync(window); return await result.OpenReadAsync(format, quality); } diff --git a/src/Essentials/src/Contacts/Contacts.shared.cs b/src/Essentials/src/Contacts/Contacts.shared.cs index 9a74056fa739..0c9062944819 100644 --- a/src/Essentials/src/Contacts/Contacts.shared.cs +++ b/src/Essentials/src/Contacts/Contacts.shared.cs @@ -17,18 +17,18 @@ public static class Contacts { /// public static Task PickContactAsync() => - Current.PickContactAsync(); + Default.PickContactAsync(); /// public static Task> GetAllAsync(CancellationToken cancellationToken = default) => - Current.GetAllAsync(cancellationToken); + Default.GetAllAsync(cancellationToken); - static IContacts? currentImplementation; + static IContacts? defaultImplementation; - public static IContacts Current => - currentImplementation ??= new ContactsImplementation(); + public static IContacts Default => + defaultImplementation ??= new ContactsImplementation(); - internal static void SetCurrent(IContacts? implementation) => - currentImplementation = implementation; + internal static void SetDefault(IContacts? implementation) => + defaultImplementation = implementation; } } diff --git a/src/Essentials/src/Email/Email.shared.cs b/src/Essentials/src/Email/Email.shared.cs index bf6ff893e49d..e22454a24621 100644 --- a/src/Essentials/src/Email/Email.shared.cs +++ b/src/Essentials/src/Email/Email.shared.cs @@ -65,24 +65,22 @@ public static class Email { /// public static Task ComposeAsync() => - Current.ComposeAsync(); + Default.ComposeAsync(); /// public static Task ComposeAsync(string subject, string body, params string[] to) => - Current.ComposeAsync(subject, body, to); + Default.ComposeAsync(subject, body, to); /// public static Task ComposeAsync(EmailMessage message) => - Current.ComposeAsync(message); - - static IEmail Current => ApplicationModel.Communication.Email.Default; + Default.ComposeAsync(message); static IEmail? defaultImplementation; public static IEmail Default => defaultImplementation ??= new EmailImplementation(); - internal static void SetCurrent(IEmail? implementation) => + internal static void SetDefault(IEmail? implementation) => defaultImplementation = implementation; } diff --git a/src/Essentials/src/FilePicker/FilePicker.shared.cs b/src/Essentials/src/FilePicker/FilePicker.shared.cs index 1a79a4a27ab6..57cd7222757e 100644 --- a/src/Essentials/src/FilePicker/FilePicker.shared.cs +++ b/src/Essentials/src/FilePicker/FilePicker.shared.cs @@ -21,14 +21,12 @@ public static partial class FilePicker { /// public static Task PickAsync(PickOptions? options = null) => - Current.PickAsync(options); + Default.PickAsync(options); /// public static Task> PickMultipleAsync(PickOptions? options = null) => - Current.PickMultipleAsync(options); + Default.PickMultipleAsync(options); - static IFilePicker Current => Storage.FilePicker.Default; - static IFilePicker? defaultImplementation; public static IFilePicker Default => diff --git a/src/Essentials/src/Flashlight/Flashlight.shared.cs b/src/Essentials/src/Flashlight/Flashlight.shared.cs index 76cf93553829..9aa659a7f7ae 100644 --- a/src/Essentials/src/Flashlight/Flashlight.shared.cs +++ b/src/Essentials/src/Flashlight/Flashlight.shared.cs @@ -15,20 +15,18 @@ public static partial class Flashlight { /// public static Task TurnOnAsync() => - Current.TurnOnAsync(); + Default.TurnOnAsync(); /// public static Task TurnOffAsync() => - Current.TurnOffAsync(); + Default.TurnOffAsync(); - static IFlashlight Current => Devices.Flashlight.Current; + static IFlashlight? defaultImplementation; - static IFlashlight? currentImplementation; + public static IFlashlight Default => + defaultImplementation ??= new FlashlightImplementation(); - public static IFlashlight Current => - currentImplementation ??= new FlashlightImplementation(); - - internal static void SetCurrent(IFlashlight? implementation) => - currentImplementation = implementation; + internal static void SetDefault(IFlashlight? implementation) => + defaultImplementation = implementation; } } diff --git a/src/Essentials/src/Preferences/Preferences.shared.cs b/src/Essentials/src/Preferences/Preferences.shared.cs index e698ebfadb08..734e8c37f454 100644 --- a/src/Essentials/src/Preferences/Preferences.shared.cs +++ b/src/Essentials/src/Preferences/Preferences.shared.cs @@ -1,4 +1,5 @@ #nullable enable +using System; namespace Microsoft.Maui.Storage { diff --git a/src/Essentials/src/Screenshot/Screenshot.shared.cs b/src/Essentials/src/Screenshot/Screenshot.shared.cs index 98cf13e7408b..e5842730f843 100644 --- a/src/Essentials/src/Screenshot/Screenshot.shared.cs +++ b/src/Essentials/src/Screenshot/Screenshot.shared.cs @@ -51,7 +51,7 @@ public static partial class Screenshot { /// public static bool IsCaptureSupported - => Current.IsCaptureSupported; + => Default.IsCaptureSupported; /// public static Task CaptureAsync() @@ -59,16 +59,16 @@ public static Task CaptureAsync() if (!IsCaptureSupported) throw new FeatureNotSupportedException(); - return Current.CaptureAsync(); + return Default.CaptureAsync(); } - static IScreenshot? currentImplementation; + static IScreenshot? defaultImplementation; - public static IScreenshot Current => - currentImplementation ??= new ScreenshotImplementation(); + public static IScreenshot Default => + defaultImplementation ??= new ScreenshotImplementation(); - internal static void SetCurrent(IScreenshot? implementation) => - currentImplementation = implementation; + internal static void SetDefault(IScreenshot? implementation) => + defaultImplementation = implementation; } public static class ScreenshotExtensions diff --git a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs index ef85f5369411..4a650e7c412b 100644 --- a/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs +++ b/src/Essentials/src/TextToSpeech/TextToSpeech.shared.cs @@ -18,25 +18,23 @@ public static partial class TextToSpeech { /// public static Task> GetLocalesAsync() => - Current.GetLocalesAsync(); + Default.GetLocalesAsync(); /// public static Task SpeakAsync(string text, CancellationToken cancelToken = default) => - Current.SpeakAsync(text, default, cancelToken); + Default.SpeakAsync(text, default, cancelToken); /// public static Task SpeakAsync(string text, SpeechOptions? options, CancellationToken cancelToken = default) => - Current.SpeakAsync(text, options, cancelToken); + Default.SpeakAsync(text, options, cancelToken); - static ITextToSpeech Current => Media.TextToSpeech.Current; + static ITextToSpeech? defaultImplementation; - static ITextToSpeech? currentImplementation; + public static ITextToSpeech Default => + defaultImplementation ??= new TextToSpeechImplementation(); - public static ITextToSpeech Current => - currentImplementation ??= new TextToSpeechImplementation(); - - internal static void SetCurrent(ITextToSpeech? implementation) => - currentImplementation = implementation; + internal static void SetDefault(ITextToSpeech? implementation) => + defaultImplementation = implementation; } partial class TextToSpeechImplementation : ITextToSpeech From 9e155faad1e9b5606dec3b72e4cdc5a484f3fddc Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 03:50:39 +0200 Subject: [PATCH 34/45] message --- src/Core/src/Hosting/EssentialsMauiAppBuilderExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/src/Hosting/EssentialsMauiAppBuilderExtensions.cs b/src/Core/src/Hosting/EssentialsMauiAppBuilderExtensions.cs index 0acc78d22e5a..f79dcec33bde 100644 --- a/src/Core/src/Hosting/EssentialsMauiAppBuilderExtensions.cs +++ b/src/Core/src/Hosting/EssentialsMauiAppBuilderExtensions.cs @@ -64,7 +64,7 @@ internal static MauiAppBuilder UseEssentials(this MauiAppBuilder builder) life.AddWindows(windows => windows .OnPlatformMessage((window, args) => { - ApplicationModel.Platform.NewWindowProc(args.Hwnd, args.MessageId, args.WParam, args.LParam); + ApplicationModel.Platform.OnWindowMessage(args.Hwnd, args.MessageId, args.WParam, args.LParam); }) .OnActivated((window, args) => { From 0b8ef87126b49b954aec75f27159c94f47565863 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 04:01:49 +0200 Subject: [PATCH 35/45] fix --- .../tests/Core.UnitTests/MockDeviceDisplay.cs | 2 +- .../src/AssemblyInfo/AssemblyInfo.shared.cs | 2 ++ .../src/Types/Shared/Exceptions.shared.cs | 29 +++++++++---------- .../src/Types/Shared/Utils.shared.cs | 2 +- .../src/Types/Shared/WebUtils.shared.cs | 26 ++++++++--------- .../AppleSignInAuthenticator.ios.cs | 2 +- ...rd.android.tvos.watchos.uwp.tizen.macos.cs | 2 +- .../AppleSignInAuthenticator.shared.cs | 20 ++++++------- .../test/UnitTests/DeviceDisplay_Tests.cs | 9 ++++-- 9 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs b/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs index f1773ecbc126..e13a7e72caad 100644 --- a/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs +++ b/src/Controls/tests/Core.UnitTests/MockDeviceDisplay.cs @@ -13,7 +13,7 @@ internal class MockDeviceDisplay : IDeviceDisplay public event EventHandler? MainDisplayInfoChanged; - public DisplayInfo GetMainDisplayInfo() => _mainDisplayInfo; + public DisplayInfo MainDisplayInfo => _mainDisplayInfo; public void UpdateMainDisplayInfo(DisplayInfo displayInfo) { diff --git a/src/Essentials/src/AssemblyInfo/AssemblyInfo.shared.cs b/src/Essentials/src/AssemblyInfo/AssemblyInfo.shared.cs index 6a926f0034cb..5420acffa342 100644 --- a/src/Essentials/src/AssemblyInfo/AssemblyInfo.shared.cs +++ b/src/Essentials/src/AssemblyInfo/AssemblyInfo.shared.cs @@ -12,3 +12,5 @@ [assembly: InternalsVisibleTo("CommunityToolkit.Maui.UnitTests")] [assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup")] [assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup.UnitTests")] +[assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Core.UnitTests")] +[assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Xaml.UnitTests")] diff --git a/src/Essentials/src/Types/Shared/Exceptions.shared.cs b/src/Essentials/src/Types/Shared/Exceptions.shared.cs index d71c592cdfac..bf67e1dd17d5 100644 --- a/src/Essentials/src/Types/Shared/Exceptions.shared.cs +++ b/src/Essentials/src/Types/Shared/Exceptions.shared.cs @@ -1,6 +1,6 @@ using System; -namespace Microsoft.Maui +namespace Microsoft.Maui.ApplicationModel { static class ExceptionUtils { @@ -9,13 +9,13 @@ static class ExceptionUtils new NotImplementedInReferenceAssemblyException(); #else internal static FeatureNotSupportedException NotSupportedOrImplementedException => - new FeatureNotSupportedException($"This API is not supported on {DeviceInfo.Current.Platform}"); + new FeatureNotSupportedException($"This API is not supported on {DeviceInfo.Platform}"); #endif } /// - public class NotImplementedInReferenceAssemblyException : NotImplementedException + class NotImplementedInReferenceAssemblyException : NotImplementedException { /// public NotImplementedInReferenceAssemblyException() @@ -24,6 +24,16 @@ public NotImplementedInReferenceAssemblyException() } } + /// + public class PermissionException : UnauthorizedAccessException + { + /// + public PermissionException(string message) + : base(message) + { + } + } + /// public class FeatureNotSupportedException : NotSupportedException { @@ -66,16 +76,3 @@ public FeatureNotEnabledException(string message, Exception innerException) } } } - -namespace Microsoft.Maui.ApplicationModel -{ - /// - public class PermissionException : UnauthorizedAccessException - { - /// - public PermissionException(string message) - : base(message) - { - } - } -} diff --git a/src/Essentials/src/Types/Shared/Utils.shared.cs b/src/Essentials/src/Types/Shared/Utils.shared.cs index b1f80d008677..0baac4b85d5d 100644 --- a/src/Essentials/src/Types/Shared/Utils.shared.cs +++ b/src/Essentials/src/Types/Shared/Utils.shared.cs @@ -3,7 +3,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Maui +namespace Microsoft.Maui.ApplicationModel { static class Utils { diff --git a/src/Essentials/src/Types/Shared/WebUtils.shared.cs b/src/Essentials/src/Types/Shared/WebUtils.shared.cs index 638e0e2d237e..00cee5050164 100644 --- a/src/Essentials/src/Types/Shared/WebUtils.shared.cs +++ b/src/Essentials/src/Types/Shared/WebUtils.shared.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; -namespace Microsoft.Maui +namespace Microsoft.Maui.ApplicationModel { static class WebUtils { @@ -57,18 +57,18 @@ internal static bool CanHandleCallback(Uri expectedUrl, Uri callbackUrl) } #if __IOS__ || __TVOS__ || __MACOS__ - internal static Foundation.NSUrl GetNativeUrl(Uri uri) - { - try - { - return new Foundation.NSUrl(uri.OriginalString); - } - catch (Exception ex) - { - Debug.WriteLine($"Unable to create NSUrl from Original string, trying Absolute URI: {ex.Message}"); - return new Foundation.NSUrl(uri.AbsoluteUri); - } - } + internal static Foundation.NSUrl GetNativeUrl(Uri uri) + { + try + { + return new Foundation.NSUrl(uri.OriginalString); + } + catch (Exception ex) + { + Debug.WriteLine($"Unable to create NSUrl from Original string, trying Absolute URI: {ex.Message}"); + return new Foundation.NSUrl(uri.AbsoluteUri); + } + } #endif } } diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs index 706d478faa6e..c474493c5317 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.ios.cs @@ -12,7 +12,7 @@ partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator { AuthManager authManager; - public async Task AuthenticateAsync(AppleSignInAuthenticatorOptions options) + public async Task AuthenticateAsync(AppleSignInAuthenticator.Options options) { if (!OperatingSystem.IsIOSVersionAtLeast(13)) throw new FeatureNotSupportedException(); diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs index 92e23e704f25..e54e10db5221 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs @@ -4,7 +4,7 @@ namespace Microsoft.Maui.Authentication { partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator { - public Task AuthenticateAsync(AppleSignInAuthenticatorOptions options) => + public Task AuthenticateAsync(AppleSignInAuthenticator.Options options) => throw ExceptionUtils.NotSupportedOrImplementedException; } } diff --git a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs index 7766f7e71fac..8d6bbe189202 100644 --- a/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs +++ b/src/Essentials/src/WebAuthenticator/AppleSignInAuthenticator.shared.cs @@ -5,22 +5,15 @@ namespace Microsoft.Maui.Authentication { public interface IAppleSignInAuthenticator { - Task AuthenticateAsync(AppleSignInAuthenticatorOptions? options = null); - } - - public class AppleSignInAuthenticatorOptions - { - public bool IncludeFullNameScope { get; set; } = false; - - public bool IncludeEmailScope { get; set; } = false; + Task AuthenticateAsync(AppleSignInAuthenticator.Options? options = null); } /// public static class AppleSignInAuthenticator { /// - public static Task AuthenticateAsync(AppleSignInAuthenticatorOptions? options = null) - => Default.AuthenticateAsync(options ?? new AppleSignInAuthenticatorOptions()); + public static Task AuthenticateAsync(AppleSignInAuthenticator.Options? options = null) + => Default.AuthenticateAsync(options ?? new AppleSignInAuthenticator.Options()); static IAppleSignInAuthenticator? defaultImplementation; @@ -29,5 +22,12 @@ public static Task AuthenticateAsync(AppleSignInAuthenti internal static void SetDefault(IAppleSignInAuthenticator? implementation) => defaultImplementation = implementation; + + public class Options + { + public bool IncludeFullNameScope { get; set; } = false; + + public bool IncludeEmailScope { get; set; } = false; + } } } diff --git a/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs b/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs index 3ac788b499de..1b47f4961547 100644 --- a/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs +++ b/src/Essentials/test/UnitTests/DeviceDisplay_Tests.cs @@ -425,10 +425,13 @@ public event EventHandler MainDisplayInfoChanged remove => RemovedCount++; } - public DisplayInfo GetMainDisplayInfo() + public DisplayInfo MainDisplayInfo { - GetMainDisplayInfoCount++; - return _displayInfo; + get + { + GetMainDisplayInfoCount++; + return _displayInfo; + } } public void StartScreenMetricsListeners() From 869ac8678fccd7f39a522b78d0e9aaa6b5f6f5d1 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 25 Mar 2022 05:01:47 +0200 Subject: [PATCH 36/45] more fixes --- .../src/Maui/Android/BlazorWebChromeClient.cs | 2 +- .../StreamImageSourceService.Windows.cs | 2 +- .../Handlers/HandlerTestBaseOfT.Tests.cs | 17 ++++++++--------- .../DeviceTests/Handlers/HandlerTestBaseOfT.cs | 9 +++++++++ .../samples/Samples/View/ScreenshotPage.xaml | 11 ++++------- .../Accelerometer.netstandard.tvos.macos.cs | 2 ++ .../src/Accelerometer/Accelerometer.shared.cs | 3 +++ .../src/AppActions/AppActions.shared.cs | 3 +++ .../src/Battery/Battery.netstandard.tvos.cs | 2 ++ .../Compass.netstandard.tvos.watchos.macos.cs | 2 ++ src/Essentials/src/Compass/Compass.shared.cs | 2 +- .../src/DeviceInfo/DeviceInfo.android.cs | 1 + .../src/FileSystem/FileSystem.netstandard.cs | 1 + .../Gyroscope.netstandard.tvos.macos.cs | 2 ++ .../HapticFeedback.netstandard.tvos.watchos.cs | 1 + .../Magnetometer.netstandard.tvos.macos.cs | 2 ++ .../MediaPicker.netstandard.watchos.tvos.cs | 1 + .../OrientationSensor.netstandard.tvos.macos.cs | 2 ++ .../src/Preferences/Preferences.netstandard.cs | 2 ++ .../src/Screenshot/Screenshot.shared.cs | 1 + 20 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/BlazorWebView/src/Maui/Android/BlazorWebChromeClient.cs b/src/BlazorWebView/src/Maui/Android/BlazorWebChromeClient.cs index b0f60b0a5686..8384723132d0 100644 --- a/src/BlazorWebView/src/Maui/Android/BlazorWebChromeClient.cs +++ b/src/BlazorWebView/src/Maui/Android/BlazorWebChromeClient.cs @@ -45,7 +45,7 @@ private static async Task CallFilePickerAsync(IValueCallback filePathCallback, F var pickOptions = GetPickOptions(fileChooserParams); var fileResults = fileChooserParams?.Mode == ChromeFileChooserMode.OpenMultiple ? await FilePicker.PickMultipleAsync(pickOptions) : - new[] { await FilePicker.PickAsync(pickOptions) }; + new[] { (await FilePicker.PickAsync(pickOptions))! }; if (fileResults?.All(f => f is null) ?? true) { diff --git a/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Windows.cs b/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Windows.cs index 6036773c2903..142211b7671b 100644 --- a/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Windows.cs +++ b/src/Core/src/ImageSources/StreamImageSourceService/StreamImageSourceService.Windows.cs @@ -28,7 +28,7 @@ public partial class StreamImageSourceService var image = new BitmapImage(); - using var ras = stream.AsRandomAccessStream(); + var ras = stream.AsRandomAccessStream(); await image.SetSourceAsync(ras); var result = new ImageSourceServiceResult(image); diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs b/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs index b63859cdd959..41684900643d 100644 --- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs +++ b/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs @@ -1,15 +1,14 @@ +using System.IO; using System.Threading.Tasks; using Microsoft.Maui.DeviceTests.Stubs; using Microsoft.Maui.Graphics; +using Microsoft.Maui.Media; using Xunit; namespace Microsoft.Maui.DeviceTests { public abstract partial class HandlerTestBase { - protected async Task GetRenderedView(IViewHandler viewHandler, RenderType type) => - await (viewHandler.VirtualView).RenderAsImage(type); - [Fact(DisplayName = "Automation Id is set correctly")] [InlineData()] public async Task SetAutomationId() @@ -220,10 +219,9 @@ public async Task ReturnsNonEmptyPlatformViewTransforms(int size) , Skip = "iOS and Windows can't render elements to images from test runner. It's missing the required root windows." #endif )] - [InlineData(RenderType.JPEG)] - [InlineData(RenderType.PNG)] - [InlineData(RenderType.BMP)] - public async Task RendersAsImage(RenderType type) + [InlineData(ScreenshotFormat.Jpeg)] + [InlineData(ScreenshotFormat.Png)] + public async Task RendersAsImage(ScreenshotFormat type) { var view = new TStub() { @@ -231,9 +229,10 @@ public async Task RendersAsImage(RenderType type) Width = 100, }; - var result = await (await GetValueAsync(view, handler => GetRenderedView(handler, type))); + var result = await GetValueAsync(view, handler => handler.VirtualView.CaptureAsync(type)); + Assert.NotNull(result); - Assert.NotNull(result?.Render); + Assert.True(result.Length > 0); } } } diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.cs b/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.cs index fa685c5ace26..110580abf59f 100644 --- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.cs +++ b/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.cs @@ -48,6 +48,15 @@ protected Task GetValueAsync(IView view, Func }); } + protected Task GetValueAsync(IView view, Func> func) + { + return InvokeOnMainThreadAsync(async () => + { + var handler = CreateHandler(view); + return await func(handler); + }); + } + protected Task SetValueAsync(IView view, TValue value, Action func) { return InvokeOnMainThreadAsync(() => diff --git a/src/Essentials/samples/Samples/View/ScreenshotPage.xaml b/src/Essentials/samples/Samples/View/ScreenshotPage.xaml index f06e3908979c..2d998fad675e 100644 --- a/src/Essentials/samples/Samples/View/ScreenshotPage.xaml +++ b/src/Essentials/samples/Samples/View/ScreenshotPage.xaml @@ -9,23 +9,20 @@ - +