├── .editorconfig
├── .gitattributes
├── .gitconfig
├── .gitignore
├── .gitmodules
├── Avalonia.Essentials.sln
├── CODE_OF_CONDUCT.md
├── Directory.Build.props
├── LICENSE.txt
├── README.md
├── THIRD-PARTY-NOTICES.TXT
├── global.json
├── samples
├── Directory.Build.props
├── Directory.Build.targets
├── Essentials.Sample.Android
│ ├── Essentials.Sample.Android.csproj
│ ├── Icon.png
│ ├── MainActivity.cs
│ ├── Properties
│ │ └── AndroidManifest.xml
│ ├── Resources
│ │ ├── drawable
│ │ │ └── splash_screen.xml
│ │ ├── values-night
│ │ │ └── colors.xml
│ │ └── values
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ └── SplashActivity.cs
├── Essentials.Sample.Desktop
│ ├── Essentials.Sample.Desktop.csproj
│ ├── Program.cs
│ └── app.manifest
├── Essentials.Sample.iOS
│ ├── AppDelegate.cs
│ ├── Entitlements.plist
│ ├── Essentials.Sample.iOS.csproj
│ ├── Info.plist
│ ├── Main.cs
│ └── Resources
│ │ └── LaunchScreen.xib
├── Essentials.Sample
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Converters
│ │ └── NegativeConverter.cs
│ ├── Essentials.Sample.csproj
│ ├── Helpers
│ │ ├── CommonConstants.cs
│ │ └── ViewHelpers.cs
│ ├── Model
│ │ ├── PermissionItem.cs
│ │ └── SampleItem.cs
│ ├── Resources
│ │ ├── AppIcons
│ │ │ ├── appicon.svg
│ │ │ └── appiconfg.svg
│ │ ├── Images
│ │ │ ├── app_info_action_icon.png
│ │ │ └── battery_action_icon.png
│ │ └── Raw
│ │ │ └── FileSystemTemplate.txt
│ ├── View
│ │ ├── AccelerometerPage.xaml
│ │ ├── AccelerometerPage.xaml.cs
│ │ ├── AllSensorsPage.xaml
│ │ ├── AllSensorsPage.xaml.cs
│ │ ├── AppInfoPage.xaml
│ │ ├── AppInfoPage.xaml.cs
│ │ ├── BarometerPage.xaml
│ │ ├── BarometerPage.xaml.cs
│ │ ├── BasePage.cs
│ │ ├── BatteryPage.xaml
│ │ ├── BatteryPage.xaml.cs
│ │ ├── BrowserPage.xaml
│ │ ├── BrowserPage.xaml.cs
│ │ ├── ClipboardPage.xaml
│ │ ├── ClipboardPage.xaml.cs
│ │ ├── ColorConvertersPage.xaml
│ │ ├── ColorConvertersPage.xaml.cs
│ │ ├── CompassPage.xaml
│ │ ├── CompassPage.xaml.cs
│ │ ├── ConnectivityPage.xaml
│ │ ├── ConnectivityPage.xaml.cs
│ │ ├── ContactDetailsPage.xaml
│ │ ├── ContactDetailsPage.xaml.cs
│ │ ├── ContactsPage.xaml
│ │ ├── ContactsPage.xaml.cs
│ │ ├── DeviceInfoPage.xaml
│ │ ├── DeviceInfoPage.xaml.cs
│ │ ├── EmailPage.xaml
│ │ ├── EmailPage.xaml.cs
│ │ ├── FilePickerPage.xaml
│ │ ├── FilePickerPage.xaml.cs
│ │ ├── FileSystemPage.xaml
│ │ ├── FileSystemPage.xaml.cs
│ │ ├── FlashlightPage.xaml
│ │ ├── FlashlightPage.xaml.cs
│ │ ├── GeocodingPage.xaml
│ │ ├── GeocodingPage.xaml.cs
│ │ ├── GeolocationPage.xaml
│ │ ├── GeolocationPage.xaml.cs
│ │ ├── GyroscopePage.xaml
│ │ ├── GyroscopePage.xaml.cs
│ │ ├── HapticFeedbackPage.xaml
│ │ ├── HapticFeedbackPage.xaml.cs
│ │ ├── HomePage.xaml
│ │ ├── HomePage.xaml.cs
│ │ ├── KeepScreenOnPage.xaml
│ │ ├── KeepScreenOnPage.xaml.cs
│ │ ├── LauncherPage.xaml
│ │ ├── LauncherPage.xaml.cs
│ │ ├── MagnetometerPage.xaml
│ │ ├── MagnetometerPage.xaml.cs
│ │ ├── MainWindow.xaml
│ │ ├── MainWindow.xaml.cs
│ │ ├── MapsPage.xaml
│ │ ├── MapsPage.xaml.cs
│ │ ├── MediaPickerPage.xaml
│ │ ├── MediaPickerPage.xaml.cs
│ │ ├── OrientationSensorPage.xaml
│ │ ├── OrientationSensorPage.xaml.cs
│ │ ├── PermissionsPage.xaml
│ │ ├── PermissionsPage.xaml.cs
│ │ ├── PhoneDialerPage.xaml
│ │ ├── PhoneDialerPage.xaml.cs
│ │ ├── PreferencesPage.xaml
│ │ ├── PreferencesPage.xaml.cs
│ │ ├── SMSPage.xaml
│ │ ├── SMSPage.xaml.cs
│ │ ├── ScreenshotPage.xaml
│ │ ├── ScreenshotPage.xaml.cs
│ │ ├── SecureStoragePage.xaml
│ │ ├── SecureStoragePage.xaml.cs
│ │ ├── SemanticScreenReaderPage.xaml
│ │ ├── SemanticScreenReaderPage.xaml.cs
│ │ ├── SharePage.xaml
│ │ ├── SharePage.xaml.cs
│ │ ├── TextToSpeechPage.xaml
│ │ ├── TextToSpeechPage.xaml.cs
│ │ ├── UnitConvertersPage.xaml
│ │ ├── UnitConvertersPage.xaml.cs
│ │ ├── VibrationPage.xaml
│ │ ├── VibrationPage.xaml.cs
│ │ ├── WebAuthenticatorPage.xaml
│ │ └── WebAuthenticatorPage.xaml.cs
│ └── ViewModel
│ │ ├── AccelerometerViewModel.cs
│ │ ├── AppInfoViewModel.cs
│ │ ├── BarometerViewModel.cs
│ │ ├── BaseViewModel.cs
│ │ ├── BatteryViewModel.cs
│ │ ├── BrowserViewModel.cs
│ │ ├── ClipboardViewModel.cs
│ │ ├── ColorConvertersViewModel.cs
│ │ ├── CompassViewModel.cs
│ │ ├── ConnectivityViewModel.cs
│ │ ├── ContactDetailsViewModel.cs
│ │ ├── ContactsViewModel.cs
│ │ ├── DeviceInfoViewModel.cs
│ │ ├── EmailViewModel.cs
│ │ ├── FilePickerViewModel.cs
│ │ ├── FileSystemViewModel.cs
│ │ ├── FlashlightViewModel.cs
│ │ ├── GeocodingViewModel.cs
│ │ ├── GeolocationViewModel.cs
│ │ ├── GyroscopeViewModel.cs
│ │ ├── HapticFeedbackViewModel.cs
│ │ ├── HomeViewModel.cs
│ │ ├── KeepScreenOnViewModel.cs
│ │ ├── LauncherViewModel.cs
│ │ ├── MagnetometerViewModel.cs
│ │ ├── MapsViewModel.cs
│ │ ├── MediaPickerViewModel.cs
│ │ ├── ObservableObject.cs
│ │ ├── OrientationSensorViewModel.cs
│ │ ├── PermissionsViewModel.cs
│ │ ├── PhoneDialerViewModel.cs
│ │ ├── PreferencesViewModel.cs
│ │ ├── ScreenshotViewModel.cs
│ │ ├── SecureStorageViewModel.cs
│ │ ├── ShareViewModel.cs
│ │ ├── SmsViewModel.cs
│ │ ├── TextToSpeechViewModel.cs
│ │ ├── UnitConvertersViewModel.cs
│ │ ├── VibrationViewModel.cs
│ │ └── WebAuthenticatorViewModel.cs
└── Sample.Server.WebAuthenticator
│ ├── Controllers
│ └── MobileAuthController.cs
│ ├── Essentials.Sample.Server.WebAuthenticator.csproj
│ ├── Program.cs
│ ├── Properties
│ └── launchSettings.json
│ ├── Startup.cs
│ └── appsettings.json
├── src
├── Accelerometer
│ ├── Accelerometer.android.cs
│ ├── Accelerometer.ios.watchos.cs
│ ├── Accelerometer.netstandard.tvos.macos.cs
│ ├── Accelerometer.shared.cs
│ ├── Accelerometer.tizen.cs
│ ├── Accelerometer.uwp.cs
│ └── AccelerometerQueue.shared.cs
├── AppActions
│ ├── AppActions.android.cs
│ ├── AppActions.ios.cs
│ ├── AppActions.netstandard.tvos.watchos.macos.tizen.cs
│ ├── AppActions.shared.cs
│ └── AppActions.uwp.cs
├── AppInfo
│ ├── AppInfo.android.cs
│ ├── AppInfo.ios.tvos.watchos.macos.cs
│ ├── AppInfo.netstandard.cs
│ ├── AppInfo.shared.cs
│ ├── AppInfo.tizen.cs
│ ├── AppInfo.uwp.cs
│ ├── AppTheme.shared.cs
│ └── LayoutDirection.shared.cs
├── AssemblyInfo
│ └── AssemblyInfo.shared.cs
├── Barometer
│ ├── Barometer.android.cs
│ ├── Barometer.ios.watchos.cs
│ ├── Barometer.netstandard.tvos.macos.cs
│ ├── Barometer.shared.cs
│ ├── Barometer.tizen.cs
│ └── Barometer.uwp.cs
├── Battery
│ ├── Battery.android.cs
│ ├── Battery.ios.watchos.cs
│ ├── Battery.macos.cs
│ ├── Battery.netstandard.tvos.cs
│ ├── Battery.shared.cs
│ ├── Battery.tizen.cs
│ └── Battery.uwp.cs
├── Browser
│ ├── Browser.android.cs
│ ├── Browser.ios.cs
│ ├── Browser.macos.cs
│ ├── Browser.netstandard.tvos.watchos.cs
│ ├── Browser.shared.cs
│ ├── Browser.tizen.cs
│ ├── Browser.uwp.cs
│ ├── BrowserLaunchMode.shared.cs
│ ├── BrowserLaunchOptions.shared.cs
│ └── BrowserTitleMode.shared.cs
├── Clipboard
│ ├── Clipboard.android.cs
│ ├── Clipboard.ios.cs
│ ├── Clipboard.macos.cs
│ ├── Clipboard.netstandard.tvos.watchos.tizen.cs
│ ├── Clipboard.shared.cs
│ └── Clipboard.uwp.cs
├── Compass
│ ├── Compass.android.cs
│ ├── Compass.ios.cs
│ ├── Compass.netstandard.tvos.watchos.macos.cs
│ ├── Compass.shared.cs
│ ├── Compass.tizen.cs
│ ├── Compass.uwp.cs
│ └── LowPassFilter.shared.cs
├── Connectivity
│ ├── Connectivity.android.cs
│ ├── Connectivity.ios.tvos.macos.cs
│ ├── Connectivity.ios.tvos.macos.reachability.cs
│ ├── Connectivity.netstandard.watchos.cs
│ ├── Connectivity.shared.cs
│ ├── Connectivity.shared.enums.cs
│ ├── Connectivity.tizen.cs
│ └── Connectivity.uwp.cs
├── Contacts
│ ├── Contacts.android.cs
│ ├── Contacts.ios.macos.cs
│ ├── Contacts.netstandard.tvos.watchos.cs
│ ├── Contacts.shared.cs
│ ├── Contacts.tizen.cs
│ └── Contacts.uwp.cs
├── DeviceDisplay
│ ├── DeviceDisplay.android.cs
│ ├── DeviceDisplay.ios.cs
│ ├── DeviceDisplay.macos.cs
│ ├── DeviceDisplay.netstandard.tvos.watchos.cs
│ ├── DeviceDisplay.shared.cs
│ ├── DeviceDisplay.tizen.cs
│ └── DeviceDisplay.uwp.cs
├── DeviceInfo
│ ├── DeviceInfo.android.cs
│ ├── DeviceInfo.ios.tvos.watchos.cs
│ ├── DeviceInfo.macos.cs
│ ├── DeviceInfo.netstandard.cs
│ ├── DeviceInfo.shared.cs
│ ├── DeviceInfo.tizen.cs
│ └── DeviceInfo.uwp.cs
├── Email
│ ├── Email.android.cs
│ ├── Email.ios.cs
│ ├── Email.macos.cs
│ ├── Email.netstandard.tvos.watchos.cs
│ ├── Email.shared.cs
│ ├── Email.tizen.cs
│ ├── Email.uwp.cs
│ └── EmailHelper.uwp.cs
├── Essentials.csproj
├── FilePicker
│ ├── FilePicker.android.cs
│ ├── FilePicker.ios.cs
│ ├── FilePicker.macos.cs
│ ├── FilePicker.netstandard.watchos.tvos.cs
│ ├── FilePicker.shared.cs
│ ├── FilePicker.tizen.cs
│ └── FilePicker.uwp.cs
├── FileSystem
│ ├── FileSystem.android.cs
│ ├── FileSystem.ios.cs
│ ├── FileSystem.ios.tvos.watchos.macos.cs
│ ├── FileSystem.netstandard.cs
│ ├── FileSystem.shared.cs
│ ├── FileSystem.tizen.cs
│ ├── FileSystem.uwp.cs
│ ├── FileSystemUtils.android.cs
│ ├── FileSystemUtils.shared.cs
│ └── FileSystemUtils.uwp.cs
├── Flashlight
│ ├── Flashlight.android.cs
│ ├── Flashlight.ios.cs
│ ├── Flashlight.netstandard.tvos.watchos.macos.cs
│ ├── Flashlight.shared.cs
│ ├── Flashlight.tizen.cs
│ └── Flashlight.uwp.cs
├── Geocoding
│ ├── Geocoding.android.cs
│ ├── Geocoding.ios.tvos.watchos.macos.cs
│ ├── Geocoding.netstandard.cs
│ ├── Geocoding.shared.cs
│ ├── Geocoding.tizen.cs
│ └── Geocoding.uwp.cs
├── Geolocation
│ ├── Geolocation.android.cs
│ ├── Geolocation.ios.macos.cs
│ ├── Geolocation.netstandard.tvos.watchos.cs
│ ├── Geolocation.shared.cs
│ ├── Geolocation.tizen.cs
│ ├── Geolocation.uwp.cs
│ ├── GeolocationAccuracyExtensionMethods.ios.macos.cs
│ ├── GeolocationAccuracyExtensionMethods.uwp.cs
│ ├── GeolocationError.shared.cs
│ ├── GeolocationListeningFailedEventArgs.shared.cs
│ ├── GeolocationListeningRequest.ios.macos.cs
│ ├── GeolocationListeningRequest.shared.cs
│ ├── GeolocationListeningRequest.uwp.cs
│ ├── GeolocationLocationChangedEventArgs.shared.cs
│ ├── GeolocationRequest.ios.macos.cs
│ ├── GeolocationRequest.shared.cs
│ └── GeolocationRequest.uwp.cs
├── GlobalSuppressions.shared.cs
├── Graphics
│ ├── Color.cs
│ └── Rect.cs
├── Gyroscope
│ ├── Gyroscope.android.cs
│ ├── Gyroscope.ios.watchos.cs
│ ├── Gyroscope.netstandard.tvos.macos.cs
│ ├── Gyroscope.shared.cs
│ ├── Gyroscope.tizen.cs
│ └── Gyroscope.uwp.cs
├── HapticFeedback
│ ├── HapticFeedback.android.cs
│ ├── HapticFeedback.ios.cs
│ ├── HapticFeedback.macos.cs
│ ├── HapticFeedback.netstandard.tvos.watchos.cs
│ ├── HapticFeedback.shared.cs
│ ├── HapticFeedback.tizen.cs
│ ├── HapticFeedback.uwp.cs
│ └── HapticFeedbackType.shared.cs
├── Launcher
│ ├── Launcher.android.cs
│ ├── Launcher.ios.tvos.cs
│ ├── Launcher.macos.cs
│ ├── Launcher.netstandard.watchos.cs
│ ├── Launcher.shared.cs
│ ├── Launcher.tizen.cs
│ └── Launcher.uwp.cs
├── Magnetometer
│ ├── Magnetometer.android.cs
│ ├── Magnetometer.ios.watchos.cs
│ ├── Magnetometer.netstandard.tvos.macos.cs
│ ├── Magnetometer.shared.cs
│ ├── Magnetometer.tizen.cs
│ └── Magnetometer.uwp.cs
├── MainThread
│ ├── MainThread.android.cs
│ ├── MainThread.ios.tvos.watchos.macos.cs
│ ├── MainThread.netstandard.cs
│ ├── MainThread.shared.cs
│ ├── MainThread.tizen.cs
│ └── MainThread.uwp.cs
├── Map
│ ├── Map.android.cs
│ ├── Map.ios.watchos.macos.cs
│ ├── Map.netstandard.tvos.cs
│ ├── Map.shared.cs
│ ├── Map.tizen.cs
│ ├── Map.uwp.cs
│ ├── MapLaunchOptions.shared.cs
│ └── NavigationMode.shared.cs
├── MediaPicker
│ ├── MediaPicker.android.cs
│ ├── MediaPicker.ios.cs
│ ├── MediaPicker.macos.cs
│ ├── MediaPicker.netstandard.watchos.tvos.cs
│ ├── MediaPicker.shared.cs
│ ├── MediaPicker.tizen.cs
│ └── MediaPicker.uwp.cs
├── OperatingSystemEx.cs
├── OrientationSensor
│ ├── OrientationSensor.android.cs
│ ├── OrientationSensor.ios.watchos.cs
│ ├── OrientationSensor.netstandard.tvos.macos.cs
│ ├── OrientationSensor.shared.cs
│ ├── OrientationSensor.tizen.cs
│ └── OrientationSensor.uwp.cs
├── Permissions
│ ├── Permissions.android.cs
│ ├── Permissions.ios.cs
│ ├── Permissions.ios.tvos.macos.cs
│ ├── Permissions.ios.tvos.watchos.cs
│ ├── Permissions.ios.watchos.cs
│ ├── Permissions.macos.cs
│ ├── Permissions.netstandard.cs
│ ├── Permissions.shared.cs
│ ├── Permissions.shared.enums.cs
│ ├── Permissions.tizen.cs
│ └── Permissions.uwp.cs
├── PhoneDialer
│ ├── PhoneDialer.android.cs
│ ├── PhoneDialer.ios.cs
│ ├── PhoneDialer.macos.cs
│ ├── PhoneDialer.netstandard.tvos.watchos.cs
│ ├── PhoneDialer.shared.cs
│ ├── PhoneDialer.tizen.cs
│ └── PhoneDialer.uwp.cs
├── Platform
│ ├── ActiveWindowTracker.uwp.cs
│ ├── ActivityStateManager.android.cs
│ ├── IntermediateActivity.android.cs
│ ├── Platform.shared.cs
│ ├── PlatformMethods.uwp.cs
│ ├── PlatformUtils.android.cs
│ ├── PlatformUtils.ios.tvos.watchos.cs
│ ├── PlatformUtils.macos.cs
│ ├── PlatformUtils.tizen.cs
│ ├── PlatformUtils.uwp.cs
│ ├── UIPresentationControllerDelegate.ios.cs
│ ├── WindowMessageEventArgs.uwp.cs
│ ├── WindowMessageManager.uwp.cs
│ ├── WindowStateManager.ios.cs
│ └── WindowStateManager.uwp.cs
├── Preferences
│ ├── Preferences.android.cs
│ ├── Preferences.ios.tvos.watchos.macos.cs
│ ├── Preferences.netstandard.cs
│ ├── Preferences.shared.cs
│ ├── Preferences.tizen.cs
│ └── Preferences.uwp.cs
├── Properties
│ └── AssemblyInfo.shared.cs
├── PublicAPI
│ ├── net-android
│ │ ├── PublicAPI.Shipped.txt
│ │ └── PublicAPI.Unshipped.txt
│ ├── net-ios
│ │ ├── PublicAPI.Shipped.txt
│ │ └── PublicAPI.Unshipped.txt
│ ├── net-maccatalyst
│ │ ├── PublicAPI.Shipped.txt
│ │ └── PublicAPI.Unshipped.txt
│ ├── net-tizen
│ │ ├── PublicAPI.Shipped.txt
│ │ └── PublicAPI.Unshipped.txt
│ ├── net-windows
│ │ ├── PublicAPI.Shipped.txt
│ │ └── PublicAPI.Unshipped.txt
│ ├── net
│ │ ├── PublicAPI.Shipped.txt
│ │ └── PublicAPI.Unshipped.txt
│ └── netstandard
│ │ ├── PublicAPI.Shipped.txt
│ │ └── PublicAPI.Unshipped.txt
├── Resources
│ └── xml
│ │ └── microsoft_maui_essentials_fileprovider_file_paths.xml
├── Screenshot
│ ├── Screenshot.android.cs
│ ├── Screenshot.ios.cs
│ ├── Screenshot.netstandard.watchos.macos.cs
│ ├── Screenshot.shared.cs
│ ├── Screenshot.tizen.cs
│ ├── Screenshot.tvos.cs
│ └── Screenshot.uwp.cs
├── SecureStorage
│ ├── SecureStorage.android.cs
│ ├── SecureStorage.ios.tvos.watchos.macos.cs
│ ├── SecureStorage.netstandard.cs
│ ├── SecureStorage.shared.cs
│ ├── SecureStorage.tizen.cs
│ └── SecureStorage.uwp.cs
├── SemanticScreenReader
│ ├── SemanticScreenReader.android.cs
│ ├── SemanticScreenReader.ios.cs
│ ├── SemanticScreenReader.netstandard.tvos.watchos.macos.cs
│ ├── SemanticScreenReader.shared.cs
│ ├── SemanticScreenReader.tizen.cs
│ └── SemanticScreenReader.uwp.cs
├── Share
│ ├── Share.android.cs
│ ├── Share.ios.cs
│ ├── Share.macos.cs
│ ├── Share.netstandard.tvos.watchos.cs
│ ├── Share.shared.cs
│ ├── Share.tizen.cs
│ └── Share.uwp.cs
├── Sms
│ ├── Sms.android.cs
│ ├── Sms.ios.cs
│ ├── Sms.macos.cs
│ ├── Sms.netstandard.tvos.watchos.cs
│ ├── Sms.shared.cs
│ ├── Sms.tizen.cs
│ └── Sms.uwp.cs
├── TextToSpeech
│ ├── TextToSpeech.android.cs
│ ├── TextToSpeech.ios.tvos.watchos.cs
│ ├── TextToSpeech.macos.cs
│ ├── TextToSpeech.netstandard.cs
│ ├── TextToSpeech.shared.cs
│ ├── TextToSpeech.tizen.cs
│ └── TextToSpeech.uwp.cs
├── Types
│ ├── Contact.shared.cs
│ ├── DeviceIdiom.shared.cs
│ ├── DevicePlatform.shared.cs
│ ├── DisplayInfo.shared.cs
│ ├── DisplayOrientation.shared.cs
│ ├── DisplayRotation.shared.cs
│ ├── FileProvider.android.cs
│ ├── Location.shared.cs
│ ├── LocationExtensions.android.cs
│ ├── LocationExtensions.ios.tvos.watchos.macos.cs
│ ├── LocationExtensions.shared.cs
│ ├── LocationExtensions.uwp.cs
│ ├── Placemark.shared.cs
│ ├── PlacemarkExtensions.android.cs
│ ├── PlacemarkExtensions.ios.tvos.watchos.macos.cs
│ ├── PlacemarkExtensions.shared.cs
│ ├── PlacemarkExtensions.uwp.cs
│ ├── SensorSpeed.android.cs
│ ├── SensorSpeed.ios.tvos.watchos.cs
│ ├── SensorSpeed.shared.cs
│ ├── SensorSpeed.tizen.cs
│ ├── SensorSpeed.uwp.cs
│ └── Shared
│ │ ├── Exceptions.shared.cs
│ │ ├── Utils.shared.cs
│ │ └── WebUtils.shared.cs
├── UnitConverters
│ └── UnitConverters.shared.cs
├── VersionTracking
│ └── VersionTracking.shared.cs
├── Vibration
│ ├── Vibration.android.cs
│ ├── Vibration.ios.cs
│ ├── Vibration.netstandard.tvos.watchos.macos.cs
│ ├── Vibration.shared.cs
│ ├── Vibration.tizen.cs
│ └── Vibration.uwp.cs
├── WebAuthenticator
│ ├── AppleSignInAuthenticator.ios.cs
│ ├── AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs
│ ├── AppleSignInAuthenticator.shared.cs
│ ├── WebAuthenticator.android.cs
│ ├── WebAuthenticator.ios.tvos.cs
│ ├── WebAuthenticator.macos.cs
│ ├── WebAuthenticator.netstandard.watchos.tizen.cs
│ ├── WebAuthenticator.shared.cs
│ ├── WebAuthenticator.uwp.cs
│ ├── WebAuthenticatorCallbackActivity.android.cs
│ ├── WebAuthenticatorIntermediateActivity.android.cs
│ └── WebAuthenticatorResult.shared.cs
└── WinRTEmbed.props
└── test
├── DeviceTests
├── Directory.Build.targets
├── Essentials.DeviceTests.csproj
├── Platforms
│ ├── Android
│ │ ├── AndroidManifest.xml
│ │ └── environment.txt
│ ├── MacCatalyst
│ │ └── Info.plist
│ ├── Windows
│ │ ├── App.xaml
│ │ ├── App.xaml.cs
│ │ ├── Package.appxmanifest
│ │ └── app.manifest
│ └── iOS
│ │ ├── Entitlements.plist
│ │ └── Info.plist
├── Properties
│ └── launchSettings.json
├── Resources
│ ├── Raw
│ │ ├── AppBundleFile.txt
│ │ ├── AppBundleFile_NoExtension
│ │ └── Folder
│ │ │ └── AppBundleFile_Nested.txt
│ ├── appicon.svg
│ └── appiconfg.svg
├── Startup.cs
├── Tests
│ ├── Accelerometer_Tests.cs
│ ├── Android
│ │ └── FileProvider_Tests.cs
│ ├── AppActions_Tests.cs
│ ├── AppInfo_Tests.cs
│ ├── Barometer_Shared.cs
│ ├── Battery_Tests.cs
│ ├── Clipboard_Tests.cs
│ ├── Compass_Tests.cs
│ ├── Connectivity_Tests.cs
│ ├── Contacts_Tests.cs
│ ├── DeviceDisplay_Tests.cs
│ ├── DeviceInfo_Tests.cs
│ ├── Email_Tests.cs
│ ├── FileSystem_Tests.cs
│ ├── Flashlight_Tests.cs
│ ├── Geocoding_Tests.cs
│ ├── Geolocation_Tests.cs
│ ├── Gyroscope_Tests.cs
│ ├── HapticFeedback_Tests.cs
│ ├── HardwareSupport.cs
│ ├── Launcher_Tests.cs
│ ├── Magnetometer_Tests.cs
│ ├── MainThread_Tests.cs
│ ├── Maps_Tests.cs
│ ├── Permissions_Tests.cs
│ ├── PhoneDialer_Tests.cs
│ ├── Preferences_Tests.cs
│ ├── Screenshot_Tests.cs
│ ├── SecureStorage_Tests.cs
│ ├── Share_Tests.cs
│ ├── VersionTracking_Tests.cs
│ ├── Vibration_Tests.cs
│ ├── WebAuthenticator_Tests.cs
│ ├── WindowStateManager_Tests.cs
│ └── Windows
│ │ ├── ActiveWindowTracker_Tests.cs
│ │ ├── BaseWindowMessageManager_Tests.cs
│ │ ├── DeviceDisplay_Windows_Tests.cs
│ │ └── WindowMessageManager_Tests.cs
├── Traits.cs
└── Utils.cs
└── UnitTests
├── Accelerometer_Tests.cs
├── AppActions_Tests.cs
├── Barometer_Tests.cs
├── Battery_Tests.cs
├── Browser_Tests.cs
├── Clipboard_Tests.cs
├── Compass_Tests.cs
├── Connectivity_Tests.cs
├── Contacts_Tests.cs
├── DeviceDisplay_Tests.cs
├── Email_Tests.cs
├── Essentials.UnitTests.csproj
├── FilePicker_Tests.cs
├── FileSystem_Tests.cs
├── Geocoding_Tests.cs
├── Gyroscope_Tests.cs
├── Launcher_Tests.cs
├── Magnetometer_Tests.cs
├── Maps_Tests.cs
├── OrientationSensor_Tests.cs
├── PhoneDialer_Tests.cs
├── Preferences_Tests.cs
├── SecureStorage_Tests.cs
├── Share_Tests.cs
├── Sms_Tests.cs
├── TextToSpeech_Tests.cs
├── UnitConverters_Tests.cs
├── Utils.cs
└── Utils_Tests.cs
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set default behaviour, in case users don't have core.autocrlf set.
2 | * text=auto
3 |
4 | # Explicitly declare text files we want to always be normalized and converted
5 | # to native line endings on checkout.
6 | *.cs text
7 |
8 | # Declare files that will always have CRLF line endings on checkout.
9 | *.sln text eol=crlf
10 |
11 | # Denote all files that are truly binary and should not be modified.
12 | *.png binary
13 | *.jpg binary
14 | *.jpeg binary
15 |
16 | # Always checkout docs using unix line endings because mdoc uses unix line endings even on windows
17 | /docs/**/*.xml text eol=lf
18 |
19 | # avoid overriding GitInfo.txt on merge
20 | GitInfo.txt merge=ours
21 |
--------------------------------------------------------------------------------
/.gitconfig:
--------------------------------------------------------------------------------
1 | [merge "ours"]
2 | driver = true
3 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "submodules/Avalonia.Labs"]
2 | path = submodules/Avalonia.Labs
3 | url = https://github.com/AvaloniaUI/Avalonia.Labs.git
4 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | <_MauiDotNetTfm>net6.0
4 | 11
5 |
6 |
7 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) .NET Foundation and Contributors
4 |
5 | All rights reserved.
6 |
7 | Permission is hereby granted, free of charge, to any person obtaining a copy
8 | of this software and associated documentation files (the "Software"), to deal
9 | in the Software without restriction, including without limitation the rights
10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | copies of the Software, and to permit persons to whom the Software is
12 | furnished to do so, subject to the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be included in all
15 | copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | SOFTWARE.
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This repository is archived.
2 | The only reason for Avalonia.Essentials was to enable Maui.Essential working with any non-MAUI project.
3 | But starting with .NET 8 Maui.Essentials can be used detached from the Maui, which is handy with Avalonia.
4 |
5 | Alternatively, you can still integrate full Maui, if you wish, with [Avalonia.Maui](https://github.com/AvaloniaUI/AvaloniaMauiHybrid)https://github.com/AvaloniaUI/AvaloniaMauiHybrid hybrid project.
6 |
7 | Keep in mind, Maui.Essentials still has a limited set of supported platforms. For example, it doesn't support Browser, Linux, macOS (only macCatalyst). But it still is really useful with mobile.
8 |
9 | If you just need to call platform APIs, but don't want to use Essentials, please visit our documentation:
10 | https://docs.avaloniaui.net/docs/guides/platforms/platform-specific-code/dotnet
11 |
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "sdk": {
3 | "version": "6.0.0",
4 | "rollForward": "latestMajor",
5 | "allowPrerelease": true
6 | }
7 | }
--------------------------------------------------------------------------------
/samples/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 | true
5 | 11.0.0-preview8
6 |
7 |
8 |
--------------------------------------------------------------------------------
/samples/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Android/Essentials.Sample.Android.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | net7.0-android
5 | 21
6 | enable
7 | com.CompanyName.Essentials.Sample
8 | 1
9 | 1.0
10 | apk
11 | False
12 |
13 |
14 |
15 |
16 | Resources\drawable\Icon.png
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Android/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AvaloniaUI/Avalonia.Essentials/3cf7aa3445725c84a70a3e7c8c5f0ee2d0292922/samples/Essentials.Sample.Android/Icon.png
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Android/Resources/drawable/splash_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Android/Resources/values-night/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #212121
4 |
5 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Android/Resources/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 |
5 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Android/Resources/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Android/SplashActivity.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Content;
3 | using Android.OS;
4 | using Application = Android.App.Application;
5 | using Avalonia;
6 | using Avalonia.Android;
7 | using Samples;
8 |
9 | namespace Essentials.Sample.Android;
10 |
11 | [Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
12 | public class SplashActivity : AvaloniaSplashActivity
13 | {
14 | protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
15 | {
16 | return base.CustomizeAppBuilder(builder)
17 | .WithInterFont();
18 | }
19 |
20 | protected override void OnCreate(Bundle? savedInstanceState)
21 | {
22 | base.OnCreate(savedInstanceState);
23 | }
24 |
25 | protected override void OnResume()
26 | {
27 | base.OnResume();
28 |
29 | StartActivity(new Intent(Application.Context, typeof(MainActivity)));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Desktop/Essentials.Sample.Desktop.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | WinExe
4 | net6.0
5 | enable
6 |
7 |
8 |
9 | app.manifest
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Desktop/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia;
3 | using Samples;
4 |
5 | namespace HotReloadTest.Desktop;
6 |
7 | class Program
8 | {
9 | // Initialization code. Don't use any Avalonia, third-party APIs or any
10 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
11 | // yet and stuff might break.
12 | [STAThread]
13 | public static void Main(string[] args) => BuildAvaloniaApp()
14 | .StartWithClassicDesktopLifetime(args);
15 |
16 | // Avalonia configuration, don't remove; also used by visual designer.
17 | public static AppBuilder BuildAvaloniaApp()
18 | => AppBuilder.Configure()
19 | .UsePlatformDetect()
20 | .WithInterFont()
21 | .LogToTrace();
22 | }
23 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.Desktop/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.iOS/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 | using Avalonia;
3 | using Avalonia.iOS;
4 | using Microsoft.Maui.ApplicationModel;
5 | using Samples;
6 |
7 | namespace Essentials.Sample.iOS;
8 |
9 | // The UIApplicationDelegate for the application. This class is responsible for launching the
10 | // User Interface of the application, as well as listening (and optionally responding) to
11 | // application events from iOS.
12 | [Register("AppDelegate")]
13 | public partial class AppDelegate : AvaloniaAppDelegate
14 | {
15 | protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
16 | {
17 | return base.CustomizeAppBuilder(builder)
18 | .AfterSetup(_ => Platform.Init(() => Window.RootViewController!))
19 | .WithInterFont();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.iOS/Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | keychain-access-groups
6 |
7 | $(AppIdentifierPrefix)$(CFBundleIdentifier)
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.iOS/Essentials.Sample.iOS.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | net7.0-ios
5 | 10.0
6 | manual
7 | enable
8 | iossimulator-x64
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample.iOS/Main.cs:
--------------------------------------------------------------------------------
1 | using UIKit;
2 |
3 | namespace Essentials.Sample.iOS;
4 |
5 | public class Application
6 | {
7 | // This is the main entry point of the application.
8 | static void Main(string[] args)
9 | {
10 | // if you want to use a different Application Delegate class from "AppDelegate"
11 | // you can specify it here.
12 | UIApplication.Main(args, null, typeof(AppDelegate));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia;
2 | using Avalonia.Controls.ApplicationLifetimes;
3 | using Avalonia.Markup.Xaml;
4 | using Avalonia.Threading;
5 | using Microsoft.Maui.ApplicationModel;
6 | using Samples.View;
7 |
8 | namespace Samples
9 | {
10 | public partial class App : Application
11 | {
12 | private static HomePage _host;
13 |
14 | public App()
15 | {
16 | AvaloniaXamlLoader.Load(this);
17 | }
18 |
19 | public override void OnFrameworkInitializationCompleted()
20 | {
21 | _host = new HomePage();
22 |
23 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
24 | {
25 | desktop.MainWindow = new MainWindow
26 | {
27 | Content = _host
28 | };
29 | }
30 | else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
31 | {
32 | singleView.MainView = _host;
33 | }
34 |
35 | base.OnFrameworkInitializationCompleted();
36 | }
37 |
38 | public static void HandleAppActions(AppAction appAction)
39 | {
40 | Dispatcher.UIThread.Invoke(() =>
41 | {
42 | var page = appAction.Id switch
43 | {
44 | "battery_info" => typeof(BatteryPage),
45 | "app_info" => typeof(AppInfoPage),
46 | _ => null
47 | };
48 |
49 | if (page != null)
50 | {
51 | _host?.Navigate(page);
52 | }
53 | });
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Converters/NegativeConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Avalonia.Data.Converters;
4 |
5 | namespace Samples.Converters
6 | {
7 | public class NegativeConverter : IValueConverter
8 | {
9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
10 | {
11 | if (value is bool v)
12 | return !v;
13 | else
14 | return false;
15 | }
16 |
17 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18 | {
19 | if (value is bool v)
20 | return !v;
21 | else
22 | return true;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Essentials.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 | false
6 | $(NoWarn),CA1416
7 | true
8 | Essentials.Sample
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Helpers/CommonConstants.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.Helpers
2 | {
3 | public static class CommonConstants
4 | {
5 | internal const string AppCenterAndroid = "AC_ANDROID";
6 | internal const string AppCenteriOS = "AC_IOS";
7 | internal const string AppCenterUWP = "AC_UWP";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Helpers/ViewHelpers.cs:
--------------------------------------------------------------------------------
1 |
2 | using Avalonia;
3 | using Avalonia.VisualTree;
4 |
5 | namespace Samples.Helpers
6 | {
7 | public static class ViewHelpers
8 | {
9 | public static Microsoft.Maui.Essentials.Rect GetAbsoluteBounds(this Visual element)
10 | {
11 | var bounds = element.GetTransformedBounds().Value;
12 | var avRect = new Rect(bounds.Transform.Transform(bounds.Bounds.Position), bounds.Bounds.Size);
13 | return new Microsoft.Maui.Essentials.Rect(avRect.X, avRect.Y, avRect.Width, avRect.Height);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Model/SampleItem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Samples.Model
4 | {
5 | public class SampleItem
6 | {
7 | public SampleItem(string icon, string name, Type pageType, string description, params string[] tags)
8 | {
9 | Icon = icon;
10 | Name = name;
11 | Description = description;
12 | PageType = pageType;
13 | Tags = tags ?? new string[0];
14 | }
15 |
16 | public string Icon { get; }
17 |
18 | public string Name { get; }
19 |
20 | public string Description { get; }
21 |
22 | public Type PageType { get; }
23 |
24 | public string[] Tags { get; }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Resources/AppIcons/appicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Resources/Images/app_info_action_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AvaloniaUI/Avalonia.Essentials/3cf7aa3445725c84a70a3e7c8c5f0ee2d0292922/samples/Essentials.Sample/Resources/Images/app_info_action_icon.png
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Resources/Images/battery_action_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AvaloniaUI/Avalonia.Essentials/3cf7aa3445725c84a70a3e7c8c5f0ee2d0292922/samples/Essentials.Sample/Resources/Images/battery_action_icon.png
--------------------------------------------------------------------------------
/samples/Essentials.Sample/Resources/Raw/FileSystemTemplate.txt:
--------------------------------------------------------------------------------
1 | This file was loaded from the app package.
2 |
3 | You can use this as a starting point for your comments...
4 |
5 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/AccelerometerPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class AccelerometerPage : BasePage
4 | {
5 | public AccelerometerPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/AllSensorsPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class AllSensorsPage : BasePage
4 | {
5 | public AllSensorsPage()
6 | {
7 | InitializeComponent();
8 | }
9 |
10 | protected override void OnLoaded()
11 | {
12 | base.OnLoaded();
13 |
14 | SetupBinding(GridAccelerometer.DataContext);
15 | SetupBinding(GridCompass.DataContext);
16 | SetupBinding(GridGyro.DataContext);
17 | SetupBinding(GridMagnetometer.DataContext);
18 | SetupBinding(GridOrientation.DataContext);
19 | SetupBinding(GridBarometer.DataContext);
20 | }
21 |
22 | protected override void OnUnloaded()
23 | {
24 | TearDownBinding(GridAccelerometer.DataContext);
25 | TearDownBinding(GridCompass.DataContext);
26 | TearDownBinding(GridGyro.DataContext);
27 | TearDownBinding(GridMagnetometer.DataContext);
28 | TearDownBinding(GridOrientation.DataContext);
29 | TearDownBinding(GridBarometer.DataContext);
30 |
31 | base.OnUnloaded();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/AppInfoPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class AppInfoPage : BasePage
4 | {
5 | public AppInfoPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/BarometerPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class BarometerPage : BasePage
4 | {
5 | public BarometerPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/BatteryPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/BatteryPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class BatteryPage : BasePage
4 | {
5 | public BatteryPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/BrowserPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class BrowserPage : BasePage
4 | {
5 | public BrowserPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ClipboardPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ClipboardPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class ClipboardPage : BasePage
4 | {
5 | public ClipboardPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ColorConvertersPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class ColorConvertersPage : BasePage
4 | {
5 | public ColorConvertersPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/CompassPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class CompassPage : BasePage
4 | {
5 | public CompassPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ConnectivityPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ConnectivityPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class ConnectivityPage : BasePage
4 | {
5 | public ConnectivityPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ContactDetailsPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class ContactDetailsPage : BasePage
4 | {
5 | public ContactDetailsPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ContactsPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class ContactsPage : BasePage
4 | {
5 | public ContactsPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/DeviceInfoPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class DeviceInfoPage : BasePage
4 | {
5 | public DeviceInfoPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/EmailPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class EmailPage : BasePage
4 | {
5 | public EmailPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/FilePickerPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class FilePickerPage : BasePage
4 | {
5 | public FilePickerPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/FileSystemPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class FileSystemPage : BasePage
4 | {
5 | public FileSystemPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/FlashlightPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class FlashlightPage : BasePage
4 | {
5 | public FlashlightPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/GeocodingPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class GeocodingPage : BasePage
4 | {
5 | public GeocodingPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/GeolocationPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class GeolocationPage : BasePage
4 | {
5 | public GeolocationPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/GyroscopePage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class GyroscopePage : BasePage
4 | {
5 | public GyroscopePage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/HapticFeedbackPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/HapticFeedbackPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class HapticFeedbackPage : BasePage
4 | {
5 | public HapticFeedbackPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/KeepScreenOnPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class KeepScreenOnPage : BasePage
4 | {
5 | public KeepScreenOnPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/LauncherPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class LauncherPage : BasePage
4 | {
5 | public LauncherPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/MagnetometerPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class MagnetometerPage : BasePage
4 | {
5 | public MagnetometerPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia.Controls;
2 |
3 | namespace Samples.View;
4 |
5 | public partial class MainWindow : Window
6 | {
7 | public MainWindow()
8 | {
9 | InitializeComponent();
10 | }
11 | }
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/MapsPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class MapsPage : BasePage
4 | {
5 | public MapsPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/MediaPickerPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class MediaPickerPage : BasePage
4 | {
5 | public MediaPickerPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/OrientationSensorPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class OrientationSensorPage : BasePage
4 | {
5 | public OrientationSensorPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/PermissionsPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using CommunityToolkit.Mvvm.Messaging;
3 | using Microsoft.Maui.ApplicationModel;
4 | using Samples.ViewModel;
5 |
6 | namespace Samples.View
7 | {
8 | public partial class PermissionsPage : BasePage
9 | {
10 | public PermissionsPage()
11 | {
12 | InitializeComponent();
13 | }
14 |
15 | protected override void OnLoaded()
16 | {
17 | base.OnLoaded();
18 |
19 | WeakReferenceMessenger.Default.Register(
20 | this,
21 | nameof(PermissionException),
22 | async (p, ex) => await ((PermissionsViewModel)DataContext!).DisplayAlertAsync(ex.Message));
23 | }
24 |
25 | protected override void OnUnloaded()
26 | {
27 | base.OnUnloaded();
28 |
29 | WeakReferenceMessenger.Default.Unregister(this, nameof(PermissionException));
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/PhoneDialerPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/PhoneDialerPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class PhoneDialerPage : BasePage
4 | {
5 | public PhoneDialerPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/PreferencesPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/PreferencesPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class PreferencesPage : BasePage
4 | {
5 | public PreferencesPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/SMSPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/SMSPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class SMSPage : BasePage
4 | {
5 | public SMSPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ScreenshotPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/ScreenshotPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class ScreenshotPage : BasePage
4 | {
5 | public ScreenshotPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/SecureStoragePage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class SecureStoragePage : BasePage
4 | {
5 | public SecureStoragePage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/SemanticScreenReaderPage.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
18 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/SemanticScreenReaderPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia.Interactivity;
3 | using Microsoft.Maui.Accessibility;
4 |
5 | namespace Samples.View
6 | {
7 | public partial class SemanticScreenReaderPage : BasePage
8 | {
9 | public SemanticScreenReaderPage()
10 | {
11 | InitializeComponent();
12 | }
13 |
14 | void Announce_Clicked(object sender, RoutedEventArgs e)
15 | {
16 | SemanticScreenReader.Announce("This is the announcement text");
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/SharePage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class SharePage : BasePage
4 | {
5 | public SharePage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/TextToSpeechPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class TextToSpeechPage : BasePage
4 | {
5 | public TextToSpeechPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/UnitConvertersPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class UnitConvertersPage : BasePage
4 | {
5 | public UnitConvertersPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/VibrationPage.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/VibrationPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class VibrationPage : BasePage
4 | {
5 | public VibrationPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/View/WebAuthenticatorPage.xaml.cs:
--------------------------------------------------------------------------------
1 | namespace Samples.View
2 | {
3 | public partial class WebAuthenticatorPage : BasePage
4 | {
5 | public WebAuthenticatorPage()
6 | {
7 | InitializeComponent();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/AppInfoViewModel.cs:
--------------------------------------------------------------------------------
1 | using CommunityToolkit.Mvvm.Input;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Samples.ViewModel
5 | {
6 | public class AppInfoViewModel : BaseViewModel
7 | {
8 | public string AppPackageName => AppInfo.PackageName;
9 |
10 | public string AppName => AppInfo.Name;
11 |
12 | public string AppVersion => AppInfo.VersionString;
13 |
14 | public string AppBuild => AppInfo.BuildString;
15 |
16 | public string AppTheme => AppInfo.RequestedTheme.ToString();
17 |
18 | public RelayCommand ShowSettingsUICommand { get; }
19 |
20 | public AppInfoViewModel()
21 | {
22 | ShowSettingsUICommand = new RelayCommand(() => AppInfo.ShowSettingsUI());
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/BaseViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace Samples.ViewModel
5 | {
6 | public class BaseViewModel : ObservableObject
7 | {
8 | bool isBusy;
9 |
10 | public bool IsBusy
11 | {
12 | get => isBusy;
13 | set => SetProperty(ref isBusy, value, onChanged: () => OnPropertyChanged(nameof(IsNotBusy)));
14 | }
15 |
16 | public bool IsNotBusy => !IsBusy;
17 |
18 | public virtual void OnAppearing()
19 | {
20 | }
21 |
22 | public virtual void OnDisappearing()
23 | {
24 | }
25 |
26 | internal event Func DoDisplayAlert;
27 |
28 | internal event Func DoNavigate;
29 |
30 | public Task DisplayAlertAsync(string message)
31 | {
32 | return DoDisplayAlert?.Invoke(message) ?? Task.CompletedTask;
33 | }
34 |
35 | public Task NavigateAsync(BaseViewModel vm, bool showModal = false)
36 | {
37 | return DoNavigate?.Invoke(vm, showModal) ?? Task.CompletedTask;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/BatteryViewModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.Devices;
2 |
3 | namespace Samples.ViewModel
4 | {
5 | public class BatteryViewModel : BaseViewModel
6 | {
7 | public BatteryViewModel()
8 | {
9 | }
10 |
11 | public double Level => Battery.ChargeLevel;
12 |
13 | public BatteryState State => Battery.State;
14 |
15 | public BatteryPowerSource PowerSource => Battery.PowerSource;
16 |
17 | public EnergySaverStatus EnergySaverStatus => Battery.EnergySaverStatus;
18 |
19 | public override void OnAppearing()
20 | {
21 | base.OnAppearing();
22 |
23 | Battery.BatteryInfoChanged += OnBatteryInfoChanged;
24 | Battery.EnergySaverStatusChanged += OnEnergySaverStatusChanged;
25 | }
26 |
27 | public override void OnDisappearing()
28 | {
29 | Battery.BatteryInfoChanged -= OnBatteryInfoChanged;
30 | Battery.EnergySaverStatusChanged -= OnEnergySaverStatusChanged;
31 |
32 | base.OnDisappearing();
33 | }
34 |
35 | void OnEnergySaverStatusChanged(object sender, EnergySaverStatusChangedEventArgs e)
36 | {
37 | OnPropertyChanged(nameof(EnergySaverStatus));
38 | }
39 |
40 | void OnBatteryInfoChanged(object sender, BatteryInfoChangedEventArgs e)
41 | {
42 | OnPropertyChanged(nameof(Level));
43 | OnPropertyChanged(nameof(State));
44 | OnPropertyChanged(nameof(PowerSource));
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/ConnectivityViewModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.Networking;
2 |
3 | namespace Samples.ViewModel
4 | {
5 | public class ConnectivityViewModel : BaseViewModel
6 | {
7 | public ConnectivityViewModel()
8 | {
9 | }
10 |
11 | public string NetworkAccess =>
12 | Connectivity.NetworkAccess.ToString();
13 |
14 | public string ConnectionProfiles
15 | {
16 | get
17 | {
18 | var profiles = string.Empty;
19 | foreach (var p in Connectivity.ConnectionProfiles)
20 | profiles += "\n" + p.ToString();
21 | return profiles;
22 | }
23 | }
24 |
25 | public override void OnAppearing()
26 | {
27 | base.OnAppearing();
28 |
29 | Connectivity.ConnectivityChanged += OnConnectivityChanged;
30 | }
31 |
32 | public override void OnDisappearing()
33 | {
34 | Connectivity.ConnectivityChanged -= OnConnectivityChanged;
35 |
36 | base.OnDisappearing();
37 | }
38 |
39 | void OnConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
40 | {
41 | OnPropertyChanged(nameof(ConnectionProfiles));
42 | OnPropertyChanged(nameof(NetworkAccess));
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/ContactDetailsViewModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel.Communication;
2 |
3 | namespace Samples.ViewModel
4 | {
5 | class ContactDetailsViewModel : BaseViewModel
6 | {
7 | public ContactDetailsViewModel(Contact contact)
8 | {
9 | Contact = contact;
10 | }
11 |
12 | public Contact Contact { get; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/KeepScreenOnViewModel.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Input;
2 | using CommunityToolkit.Mvvm.Input;
3 | using Microsoft.Maui.Devices;
4 |
5 | namespace Samples.ViewModel
6 | {
7 | public class KeepScreenOnViewModel : BaseViewModel
8 | {
9 | public KeepScreenOnViewModel()
10 | {
11 | RequestActiveCommand = new RelayCommand(OnRequestActive);
12 | RequestReleaseCommand = new RelayCommand(OnRequestRelease);
13 | }
14 |
15 | public bool IsActive => DeviceDisplay.KeepScreenOn;
16 |
17 | public ICommand RequestActiveCommand { get; }
18 |
19 | public ICommand RequestReleaseCommand { get; }
20 |
21 | public override void OnDisappearing()
22 | {
23 | OnRequestRelease();
24 |
25 | base.OnDisappearing();
26 | }
27 |
28 | void OnRequestActive()
29 | {
30 | DeviceDisplay.KeepScreenOn = true;
31 |
32 | OnPropertyChanged(nameof(IsActive));
33 | }
34 |
35 | void OnRequestRelease()
36 | {
37 | DeviceDisplay.KeepScreenOn = false;
38 |
39 | OnPropertyChanged(nameof(IsActive));
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/PhoneDialerViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 | using CommunityToolkit.Mvvm.Input;
4 | using Microsoft.Maui.ApplicationModel.Communication;
5 |
6 | namespace Samples.ViewModel
7 | {
8 | public class PhoneDialerViewModel : BaseViewModel
9 | {
10 | string phoneNumber;
11 |
12 | public PhoneDialerViewModel()
13 | {
14 | OpenPhoneDialerCommand = new RelayCommand(OnOpenPhoneDialer);
15 | }
16 |
17 | public ICommand OpenPhoneDialerCommand { get; }
18 |
19 | public string PhoneNumber
20 | {
21 | get => phoneNumber;
22 | set => SetProperty(ref phoneNumber, value);
23 | }
24 |
25 | async void OnOpenPhoneDialer()
26 | {
27 | try
28 | {
29 | PhoneDialer.Open(PhoneNumber);
30 | }
31 | catch (Exception ex)
32 | {
33 | await DisplayAlertAsync($"Dialer is not supported: {ex.Message}");
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/PreferencesViewModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.Storage;
2 |
3 | namespace Samples.ViewModel
4 | {
5 | public class PreferencesViewModel : BaseViewModel
6 | {
7 | const string preferenceKey = "PreferenceKey";
8 |
9 | string preferenceValue;
10 |
11 | public PreferencesViewModel()
12 | {
13 | preferenceValue = Preferences.Get(preferenceKey, string.Empty);
14 | }
15 |
16 | public string PreferenceValue
17 | {
18 | get => preferenceValue;
19 | set
20 | {
21 | preferenceValue = value;
22 | Preferences.Set(preferenceKey, value);
23 |
24 | OnPropertyChanged();
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/SmsViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 | using CommunityToolkit.Mvvm.Input;
4 | using Microsoft.Maui.ApplicationModel;
5 | using Microsoft.Maui.ApplicationModel.Communication;
6 |
7 | namespace Samples.ViewModel
8 | {
9 | public class SmsViewModel : BaseViewModel
10 | {
11 | string recipient;
12 | string messageText;
13 |
14 | public SmsViewModel()
15 | {
16 | SendSmsCommand = new RelayCommand(OnSendSms);
17 | }
18 |
19 | public string Recipient
20 | {
21 | get => recipient;
22 | set => SetProperty(ref recipient, value);
23 | }
24 |
25 | public string MessageText
26 | {
27 | get => messageText;
28 | set => SetProperty(ref messageText, value);
29 | }
30 |
31 | public ICommand SendSmsCommand { get; }
32 |
33 | async void OnSendSms()
34 | {
35 | if (IsBusy)
36 | return;
37 | IsBusy = true;
38 |
39 | try
40 | {
41 | var message = new SmsMessage(MessageText, Recipient.Split(',', '*'));
42 | await Sms.ComposeAsync(message);
43 | }
44 | catch (FeatureNotSupportedException)
45 | {
46 | await DisplayAlertAsync("Sending an SMS is not supported on this device.");
47 | }
48 | catch (Exception ex)
49 | {
50 | await DisplayAlertAsync($"Unable to send Sms: {ex.Message}");
51 | }
52 |
53 | IsBusy = false;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/samples/Essentials.Sample/ViewModel/UnitConvertersViewModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.Media;
2 |
3 | namespace Samples.ViewModel
4 | {
5 | public class UnitConvertersViewModel : BaseViewModel
6 | {
7 | double fahrenheit;
8 | double celsius;
9 | double miles;
10 | double kilometers;
11 |
12 | public UnitConvertersViewModel()
13 | {
14 | }
15 |
16 | public double Fahrenheit
17 | {
18 | get => fahrenheit;
19 | set => SetProperty(ref fahrenheit, value, onChanged: () => Celsius = UnitConverters.FahrenheitToCelsius(fahrenheit));
20 | }
21 |
22 | public double Celsius
23 | {
24 | get => celsius;
25 | set => SetProperty(ref celsius, value);
26 | }
27 |
28 | public double Miles
29 | {
30 | get => miles;
31 | set => SetProperty(ref miles, value, onChanged: () => Kilometers = UnitConverters.MilesToKilometers(miles));
32 | }
33 |
34 | public double Kilometers
35 | {
36 | get => kilometers;
37 | set => SetProperty(ref kilometers, value);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/Sample.Server.WebAuthenticator/Essentials.Sample.Server.WebAuthenticator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(_MauiDotNetTfm)
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/samples/Sample.Server.WebAuthenticator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.AspNetCore.Hosting;
6 | using Microsoft.Extensions.Configuration;
7 | using Microsoft.Extensions.Hosting;
8 | using Microsoft.Extensions.Logging;
9 |
10 | namespace Sample.Server.WebAuthenticator
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | CreateHostBuilder(args).Build().Run();
17 | }
18 |
19 | public static IHostBuilder CreateHostBuilder(string[] args) =>
20 | Host.CreateDefaultBuilder(args)
21 | .ConfigureWebHostDefaults(webBuilder =>
22 | {
23 | webBuilder.UseStartup();
24 | });
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/samples/Sample.Server.WebAuthenticator/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:58823/",
7 | "sslPort": 44373
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Sample.Server.WebAuthenticator": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
22 | "environmentVariables": {
23 | "ASPNETCORE_ENVIRONMENT": "Development"
24 | }
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/samples/Sample.Server.WebAuthenticator/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*"
10 | }
11 |
--------------------------------------------------------------------------------
/src/Accelerometer/Accelerometer.ios.watchos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using CoreMotion;
3 | using Foundation;
4 | using Microsoft.Maui.ApplicationModel;
5 |
6 | namespace Microsoft.Maui.Devices.Sensors
7 | {
8 | partial class AccelerometerImplementation : AccelerometerImplementationBase
9 | {
10 | static CMMotionManager? motionManager;
11 |
12 | static CMMotionManager MotionManager =>
13 | motionManager ??= new CMMotionManager();
14 |
15 | public override bool IsSupported =>
16 | MotionManager.AccelerometerAvailable;
17 |
18 | protected override void PlatformStart(SensorSpeed sensorSpeed)
19 | {
20 | MotionManager.AccelerometerUpdateInterval = sensorSpeed.ToPlatform();
21 | MotionManager.StartAccelerometerUpdates(NSOperationQueue.CurrentQueue ?? new NSOperationQueue(), DataUpdated);
22 | }
23 |
24 | void DataUpdated(CMAccelerometerData data, NSError error)
25 | {
26 | if (data == null)
27 | return;
28 |
29 | #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-macios/issues/14619
30 | var field = data.Acceleration;
31 | #pragma warning restore CA1416
32 | var accelData = new AccelerometerData(field.X * -1, field.Y * -1, field.Z * -1);
33 | OnChanged(accelData);
34 | }
35 |
36 | protected override void PlatformStop() =>
37 | MotionManager.StopAccelerometerUpdates();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Accelerometer/Accelerometer.netstandard.tvos.macos.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | class NotImplementedAccelerometerImplementation : AccelerometerImplementationBase
6 | {
7 | public override bool IsSupported =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | protected override void PlatformStart(SensorSpeed sensorSpeed) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | protected override void PlatformStop() =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Accelerometer/Accelerometer.tizen.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Tizen.Sensor;
3 | using TizenAccelerometer = Tizen.Sensor.Accelerometer;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | partial class AccelerometerImplementation
8 | {
9 | internal static TizenAccelerometer DefaultSensor =>
10 | (TizenAccelerometer)PlatformUtils.GetDefaultSensor(SensorType.Accelerometer);
11 |
12 | public bool IsSupported =>
13 | TizenAccelerometer.IsSupported;
14 |
15 | void PlatformStart(SensorSpeed sensorSpeed)
16 | {
17 | DefaultSensor.Interval = sensorSpeed.ToPlatform();
18 | DefaultSensor.DataUpdated += DataUpdated;
19 | DefaultSensor.Start();
20 | }
21 |
22 | void PlatformStop()
23 | {
24 | DefaultSensor.DataUpdated -= DataUpdated;
25 | DefaultSensor.Stop();
26 | }
27 |
28 | void DataUpdated(object sender, AccelerometerDataUpdatedEventArgs e)
29 | {
30 | OnChanged(new AccelerometerData(e.X, e.Y, e.Z));
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Accelerometer/Accelerometer.uwp.cs:
--------------------------------------------------------------------------------
1 | using Windows.Devices.Sensors;
2 | using WindowsAccelerometer = Windows.Devices.Sensors.Accelerometer;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | partial class WinAccelerometerImplementation : AccelerometerImplementationBase
7 | {
8 | // keep around a reference so we can stop this same instance
9 | WindowsAccelerometer sensor;
10 |
11 | internal static WindowsAccelerometer DefaultSensor =>
12 | WindowsAccelerometer.GetDefault();
13 |
14 | public override bool IsSupported =>
15 | DefaultSensor != null;
16 |
17 | protected override void PlatformStart(SensorSpeed sensorSpeed)
18 | {
19 | sensor = DefaultSensor;
20 |
21 | var interval = sensorSpeed.ToPlatform();
22 | sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval;
23 |
24 | sensor.ReadingChanged += DataUpdated;
25 | }
26 |
27 | void DataUpdated(object sender, AccelerometerReadingChangedEventArgs e)
28 | {
29 | var reading = e.Reading;
30 | var data = new AccelerometerData(reading.AccelerationX * -1, reading.AccelerationY * -1, reading.AccelerationZ * -1);
31 | OnChanged(data);
32 | }
33 |
34 | protected override void PlatformStop()
35 | {
36 | sensor.ReadingChanged -= DataUpdated;
37 | sensor.ReportInterval = 0;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/AppActions/AppActions.netstandard.tvos.watchos.macos.tizen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 |
5 | namespace Microsoft.Maui.ApplicationModel
6 | {
7 | partial class AppActionsImplementation : IAppActions
8 | {
9 | public bool IsSupported =>
10 | throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | public Task> GetAsync() =>
13 | throw ExceptionUtils.NotSupportedOrImplementedException;
14 |
15 | public Task SetAsync(IEnumerable actions) =>
16 | throw ExceptionUtils.NotSupportedOrImplementedException;
17 |
18 | #pragma warning disable CS0067 // The event is never used
19 | public event EventHandler AppActionActivated;
20 | #pragma warning restore CS0067 // The event is never used
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/AppInfo/AppInfo.netstandard.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.ApplicationModel
2 | {
3 | class AppInfoImplementation : IAppInfo
4 | {
5 | public string PackageName => throw ExceptionUtils.NotSupportedOrImplementedException;
6 |
7 | public string Name => throw ExceptionUtils.NotSupportedOrImplementedException;
8 |
9 | public System.Version Version => Utils.ParseVersion(VersionString);
10 |
11 | public string VersionString => throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | public string BuildString => throw ExceptionUtils.NotSupportedOrImplementedException;
14 |
15 | public void ShowSettingsUI() => throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | public AppTheme RequestedTheme => AppTheme.Unspecified;
18 |
19 | public AppPackagingModel PackagingModel => throw ExceptionUtils.NotSupportedOrImplementedException;
20 |
21 | // Returning the Unknown value for LayoutDirection so that unit tests can work
22 | public LayoutDirection RequestedLayoutDirection => LayoutDirection.Unknown;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/AppInfo/AppInfo.tizen.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using Tizen.Applications;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | class AppInfoImplementation : IAppInfo
7 | {
8 | public string PackageName
9 | => Application.Current.ApplicationInfo.PackageId;
10 |
11 | public string Name
12 | => Application.Current.ApplicationInfo.Label;
13 |
14 | public System.Version Version => Utils.ParseVersion(VersionString);
15 |
16 | public string VersionString
17 | => Platform.CurrentPackage.Version;
18 |
19 | public string BuildString
20 | => Version.Build.ToString(CultureInfo.InvariantCulture);
21 |
22 | public void ShowSettingsUI()
23 | {
24 | Permissions.EnsureDeclared();
25 | AppControl.SendLaunchRequest(new AppControl() { Operation = AppControlOperations.Setting });
26 | }
27 |
28 | public AppTheme RequestedTheme
29 | => AppTheme.Unspecified;
30 |
31 | public AppPackagingModel PackagingModel => AppPackagingModel.Packaged;
32 |
33 | public LayoutDirection RequestedLayoutDirection
34 | => LayoutDirection.LeftToRight;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/AppInfo/AppTheme.shared.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.ApplicationModel
2 | {
3 | ///
4 | /// Enumerates different themes an operating system or application can show.
5 | ///
6 | public enum AppTheme
7 | {
8 | /// Default, unknown or unspecified theme.
9 | Unspecified,
10 |
11 | /// Light theme.
12 | Light,
13 |
14 | /// Dark theme.
15 | Dark
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/AppInfo/LayoutDirection.shared.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Microsoft.Maui.ApplicationModel
6 | {
7 | ///
8 | /// Enumerates possible layout directions.
9 | ///
10 | public enum LayoutDirection
11 | {
12 | /// The requested layout direction is unknown.
13 | Unknown,
14 |
15 | /// The requested layout direction is left-to-right.
16 | LeftToRight,
17 |
18 | /// The requested layout direction is right-to-left.
19 | RightToLeft
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/AssemblyInfo/AssemblyInfo.shared.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Microsoft.Maui.Essentials.DeviceTests")]
4 | [assembly: InternalsVisibleTo("Microsoft.Maui.Essentials.UnitTests")]
5 | [assembly: InternalsVisibleTo("EssentialsTests")]
6 | [assembly: InternalsVisibleTo("EssentialsDeviceTestsAndroid")]
7 | [assembly: InternalsVisibleTo("EssentialsDeviceTestsUWP")]
8 | [assembly: InternalsVisibleTo("EssentialsDeviceTestsShared")]
9 | [assembly: InternalsVisibleTo("EssentialsDeviceTestsiOS")]
10 | [assembly: InternalsVisibleTo("CommunityToolkit.Maui")]
11 | [assembly: InternalsVisibleTo("CommunityToolkit.Maui.Core")]
12 | [assembly: InternalsVisibleTo("CommunityToolkit.Maui.UnitTests")]
13 | [assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup")]
14 | [assembly: InternalsVisibleTo("CommunityToolkit.Maui.Markup.UnitTests")]
15 | [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Core.UnitTests")]
16 | [assembly: InternalsVisibleTo("Microsoft.Maui.Controls.Xaml.UnitTests")]
17 | [assembly: InternalsVisibleTo("Microsoft.Maui.TestUtils")]
18 | [assembly: InternalsVisibleTo("Microsoft.Maui.TestUtils.DeviceTests")]
19 | [assembly: InternalsVisibleTo("Microsoft.Maui.TestUtils.DeviceTests.Runners")]
20 |
--------------------------------------------------------------------------------
/src/Barometer/Barometer.ios.watchos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using CoreMotion;
3 | using Foundation;
4 | using Microsoft.Maui.Media;
5 |
6 | namespace Microsoft.Maui.Devices.Sensors
7 | {
8 | partial class BarometerImplementation : IBarometer
9 | {
10 | CMAltimeter altitudeManager;
11 |
12 | public bool IsSupported
13 | => CMAltimeter.IsRelativeAltitudeAvailable;
14 |
15 | void PlatformStart(SensorSpeed sensorSpeed)
16 | {
17 | altitudeManager = new CMAltimeter();
18 | altitudeManager.StartRelativeAltitudeUpdates(NSOperationQueue.CurrentQueue ?? new NSOperationQueue(), LocationManagerUpdatedHeading);
19 |
20 | void LocationManagerUpdatedHeading(CMAltitudeData e, NSError error)
21 | {
22 | var reading = new BarometerData(UnitConverters.KilopascalsToHectopascals(e.Pressure.DoubleValue));
23 |
24 | RaiseReadingChanged(reading);
25 | }
26 | }
27 |
28 | void PlatformStop()
29 | {
30 | if (altitudeManager == null)
31 | return;
32 |
33 | altitudeManager.StopRelativeAltitudeUpdates();
34 | altitudeManager.Dispose();
35 | altitudeManager = null;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Barometer/Barometer.netstandard.tvos.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | partial class BarometerImplementation : IBarometer
7 | {
8 | void PlatformStart(SensorSpeed sensorSpeed)
9 | => throw ExceptionUtils.NotSupportedOrImplementedException;
10 |
11 | void PlatformStop()
12 | => throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | public bool IsSupported
15 | => throw ExceptionUtils.NotSupportedOrImplementedException;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Barometer/Barometer.tizen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Tizen.Sensor;
4 | using TizenBarometerSensor = Tizen.Sensor.PressureSensor;
5 |
6 | namespace Microsoft.Maui.Devices.Sensors
7 | {
8 | partial class BarometerImplementation : IBarometer
9 | {
10 | public bool IsSupported
11 | => TizenBarometerSensor.IsSupported;
12 |
13 | TizenBarometerSensor DefaultSensor
14 | => (TizenBarometerSensor)PlatformUtils.GetDefaultSensor(SensorType.Barometer);
15 |
16 | TizenBarometerSensor sensor = null;
17 |
18 | void PlatformStart(SensorSpeed sensorSpeed)
19 | {
20 | sensor = DefaultSensor;
21 | sensor.Interval = sensorSpeed.ToPlatform();
22 | sensor.DataUpdated += DataUpdated;
23 | sensor.Start();
24 | }
25 |
26 | void DataUpdated(object sender, PressureSensorDataUpdatedEventArgs e)
27 | => RaiseReadingChanged(new BarometerData(e.Pressure));
28 |
29 | void PlatformStop()
30 | {
31 | sensor.DataUpdated -= DataUpdated;
32 | sensor.Stop();
33 | sensor = null;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Barometer/Barometer.uwp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Windows.Devices.Sensors;
3 | using WinBarometer = Windows.Devices.Sensors.Barometer;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | partial class BarometerImplementation : IBarometer
8 | {
9 | WinBarometer sensor;
10 |
11 | WinBarometer DefaultBarometer => WinBarometer.GetDefault();
12 |
13 | public bool IsSupported =>
14 | DefaultBarometer != null;
15 |
16 | void PlatformStart(SensorSpeed sensorSpeed)
17 | {
18 | sensor = DefaultBarometer;
19 |
20 | var interval = sensorSpeed.ToPlatform();
21 | sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval;
22 |
23 | sensor.ReadingChanged += BarometerReportedInterval;
24 | }
25 |
26 | internal void BarometerReportedInterval(object sender, BarometerReadingChangedEventArgs e)
27 | => RaiseReadingChanged(new BarometerData(e.Reading.StationPressureInHectopascals));
28 |
29 | void PlatformStop()
30 | {
31 | if (sensor == null)
32 | return;
33 |
34 | sensor.ReadingChanged -= BarometerReportedInterval;
35 | sensor.ReportInterval = 0;
36 | sensor = null;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Battery/Battery.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using CoreFoundation;
3 |
4 | namespace Microsoft.Maui.Devices
5 | {
6 | partial class BatteryImplementation : IBattery
7 | {
8 | CFRunLoopSource powerSourceNotification;
9 |
10 | void StartBatteryListeners()
11 | {
12 | powerSourceNotification = IOKit.CreatePowerSourceNotification(PowerSourceNotification);
13 | CFRunLoop.Current.AddSource(powerSourceNotification, CFRunLoop.ModeDefault);
14 | }
15 |
16 | void StopBatteryListeners()
17 | {
18 | if (powerSourceNotification != null)
19 | {
20 | CFRunLoop.Current.RemoveSource(powerSourceNotification, CFRunLoop.ModeDefault);
21 | powerSourceNotification = null;
22 | }
23 | }
24 |
25 | void PowerSourceNotification()
26 | => MainThread.BeginInvokeOnMainThread(OnBatteryInfoChanged);
27 |
28 | public double ChargeLevel => IOKit.GetInternalBatteryChargeLevel();
29 |
30 | public BatteryState State => IOKit.GetInternalBatteryState();
31 |
32 | public BatteryPowerSource PowerSource => IOKit.GetProvidingPowerSource();
33 |
34 | void StartEnergySaverListeners()
35 | {
36 | }
37 |
38 | void StopEnergySaverListeners()
39 | {
40 | }
41 |
42 | public EnergySaverStatus EnergySaverStatus => EnergySaverStatus.Off;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Battery/Battery.netstandard.tvos.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 |
3 | namespace Microsoft.Maui.Devices
4 | {
5 | partial class BatteryImplementation : IBattery
6 | {
7 | void StartBatteryListeners() =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | void StopBatteryListeners() =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | public double ChargeLevel =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 |
16 | public BatteryState State =>
17 | throw ExceptionUtils.NotSupportedOrImplementedException;
18 |
19 | public BatteryPowerSource PowerSource =>
20 | throw ExceptionUtils.NotSupportedOrImplementedException;
21 |
22 | void StartEnergySaverListeners() =>
23 | throw ExceptionUtils.NotSupportedOrImplementedException;
24 |
25 | void StopEnergySaverListeners() =>
26 | throw ExceptionUtils.NotSupportedOrImplementedException;
27 |
28 | public EnergySaverStatus EnergySaverStatus =>
29 | throw ExceptionUtils.NotSupportedOrImplementedException;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Browser/Browser.macos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Threading.Tasks;
4 | using AppKit;
5 | using Foundation;
6 |
7 | namespace Microsoft.Maui.ApplicationModel
8 | {
9 | partial class BrowserImplementation : IBrowser
10 | {
11 | static Task OpenAsync(Uri uri, BrowserLaunchOptions options) =>
12 | Task.FromResult(NSWorkspace.SharedWorkspace.OpenUrl(new NSUrl(uri.AbsoluteUri)));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Browser/Browser.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Threading.Tasks;
4 |
5 | namespace Microsoft.Maui.ApplicationModel
6 | {
7 | partial class BrowserImplementation : IBrowser
8 | {
9 | public Task OpenAsync(Uri uri, BrowserLaunchOptions options) =>
10 | throw ExceptionUtils.NotSupportedOrImplementedException;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Browser/Browser.tizen.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Tizen.Applications;
6 |
7 | namespace Microsoft.Maui.ApplicationModel
8 | {
9 | partial class BrowserImplementation : IBrowser
10 | {
11 | public Task OpenAsync(Uri uri, BrowserLaunchOptions launchMode)
12 | {
13 | if (uri == null)
14 | throw new ArgumentNullException(nameof(uri));
15 |
16 | Permissions.EnsureDeclared();
17 |
18 | var appControl = new AppControl
19 | {
20 | Operation = AppControlOperations.View,
21 | Uri = uri.AbsoluteUri
22 | };
23 |
24 | var hasMatches = AppControl.GetMatchedApplicationIds(appControl).Any();
25 |
26 | if (hasMatches)
27 | AppControl.SendLaunchRequest(appControl);
28 |
29 | return Task.FromResult(hasMatches);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Browser/Browser.uwp.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Threading.Tasks;
4 |
5 | namespace Microsoft.Maui.ApplicationModel
6 | {
7 | partial class BrowserImplementation : IBrowser
8 | {
9 | public Task OpenAsync(Uri uri, BrowserLaunchOptions options) =>
10 | global::Windows.System.Launcher.LaunchUriAsync(uri).AsTask();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Browser/BrowserLaunchMode.shared.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | namespace Microsoft.Maui.ApplicationModel
3 | {
4 | ///
5 | /// Launch type of the browser.
6 | ///
7 | /// It's recommended to use the as it is the default and gracefully falls back if needed.
8 | public enum BrowserLaunchMode
9 | {
10 | /// Launch the optimized system browser and stay inside of your application. Chrome Custom Tabs on Android and SFSafariViewController on iOS.
11 | SystemPreferred = 0,
12 |
13 | /// Use the default external launcher to open the browser outside of the app.
14 | External = 1
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Browser/BrowserTitleMode.shared.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | namespace Microsoft.Maui.ApplicationModel
3 | {
4 | ///
5 | /// Mode for the in-app browser title.
6 | ///
7 | /// These values only apply to Android.
8 | public enum BrowserTitleMode
9 | {
10 | /// Uses the system default.
11 | Default = 0,
12 |
13 | /// Show the title.
14 | Show = 1,
15 |
16 | /// Hide the title.
17 | Hide = 2
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Clipboard/Clipboard.ios.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Threading.Tasks;
4 | using Foundation;
5 | using ObjCRuntime;
6 | using UIKit;
7 |
8 | namespace Microsoft.Maui.ApplicationModel.DataTransfer
9 | {
10 | partial class ClipboardImplementation : IClipboard
11 | {
12 | NSObject? observer;
13 |
14 | public Task SetTextAsync(string? text)
15 | {
16 | UIPasteboard.General.String = text;
17 | return Task.CompletedTask;
18 | }
19 |
20 | public bool HasText
21 | => UIPasteboard.General.HasStrings;
22 |
23 | public Task GetTextAsync()
24 | => Task.FromResult(UIPasteboard.General.String);
25 |
26 | void StartClipboardListeners()
27 | {
28 | observer = NSNotificationCenter.DefaultCenter.AddObserver(
29 | UIPasteboard.ChangedNotification,
30 | ClipboardChangedObserver);
31 | }
32 |
33 | void StopClipboardListeners()
34 | {
35 | if (observer is not null)
36 | NSNotificationCenter.DefaultCenter.RemoveObserver(observer);
37 | }
38 |
39 | ///
40 | /// The observer for triggering the event.
41 | ///
42 | /// The notification that triggered this event.
43 | public void ClipboardChangedObserver(NSNotification notification)
44 | => OnClipboardContentChanged();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Clipboard/Clipboard.macos.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using AppKit;
4 | using Foundation;
5 |
6 | namespace Microsoft.Maui.ApplicationModel.DataTransfer
7 | {
8 | partial class ClipboardImplementation : IClipboard
9 | {
10 | readonly string pasteboardType = NSPasteboard.NSPasteboardTypeString;
11 | readonly string[] pasteboardTypes = { pasteboardType };
12 |
13 | NSPasteboard Pasteboard => NSPasteboard.GeneralPasteboard;
14 |
15 | public Task SetTextAsync(string text)
16 | {
17 | Pasteboard.DeclareTypes(pasteboardTypes, null);
18 | Pasteboard.ClearContents();
19 | Pasteboard.SetStringForType(text, pasteboardType);
20 |
21 | return Task.CompletedTask;
22 | }
23 |
24 | public bool HasText =>
25 | !string.IsNullOrEmpty(GetPasteboardText());
26 |
27 | public Task GetTextAsync()
28 | => Task.FromResult(GetPasteboardText());
29 |
30 | string GetPasteboardText()
31 | => Pasteboard.ReadObjectsForClasses(
32 | new ObjCRuntime.Class[] { new ObjCRuntime.Class(typeof(NSString)) },
33 | null)?[0]?.ToString();
34 |
35 | void StartClipboardListeners()
36 | => throw ExceptionUtils.NotSupportedOrImplementedException;
37 |
38 | void StopClipboardListeners()
39 | => throw ExceptionUtils.NotSupportedOrImplementedException;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Clipboard/Clipboard.netstandard.tvos.watchos.tizen.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System.Threading.Tasks;
3 |
4 | namespace Microsoft.Maui.ApplicationModel.DataTransfer
5 | {
6 | partial class ClipboardImplementation : IClipboard
7 | {
8 | public Task SetTextAsync(string? text)
9 | => throw ExceptionUtils.NotSupportedOrImplementedException;
10 |
11 | public bool HasText
12 | => throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | public Task GetTextAsync()
15 | => throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | void StartClipboardListeners()
18 | => throw ExceptionUtils.NotSupportedOrImplementedException;
19 |
20 | void StopClipboardListeners()
21 | => throw ExceptionUtils.NotSupportedOrImplementedException;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Compass/Compass.netstandard.tvos.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | partial class CompassImplementation : ICompass
6 | {
7 | bool PlatformIsSupported => throw ExceptionUtils.NotSupportedOrImplementedException;
8 |
9 | void PlatformStart(SensorSpeed sensorSpeed, bool applyLowPassFilter) =>
10 | throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | void PlatformStop() =>
13 | throw ExceptionUtils.NotSupportedOrImplementedException;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Compass/Compass.tizen.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Tizen.Sensor;
3 | using TizenCompass = Tizen.Sensor.OrientationSensor;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | partial class CompassImplementation : ICompass
8 | {
9 | static TizenCompass DefaultSensor =>
10 | (TizenCompass)PlatformUtils.GetDefaultSensor(SensorType.Compass);
11 |
12 | bool PlatformIsSupported =>
13 | TizenCompass.IsSupported;
14 |
15 | TizenCompass sensor;
16 |
17 | void PlatformStart(SensorSpeed sensorSpeed, bool applyLowPassFilter)
18 | {
19 | sensor = DefaultSensor;
20 |
21 | sensor.Interval = sensorSpeed.ToPlatform();
22 | sensor.DataUpdated += DataUpdated;
23 | sensor.Start();
24 | }
25 |
26 | void PlatformStop()
27 | {
28 | sensor.DataUpdated -= DataUpdated;
29 | sensor.Stop();
30 | sensor = null;
31 | }
32 |
33 | void DataUpdated(object sender, OrientationSensorDataUpdatedEventArgs e)
34 | {
35 | RaiseReadingChanged(new CompassData(e.Azimuth));
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Compass/LowPassFilter.shared.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | class LowPassFilter
7 | {
8 | const int length = 10;
9 |
10 | readonly Queue history = new Queue(length);
11 | float sin;
12 | float cos;
13 |
14 | internal void Add(float radians)
15 | {
16 | sin += (float)Math.Sin(radians);
17 |
18 | cos += (float)Math.Cos(radians);
19 |
20 | history.Enqueue(radians);
21 |
22 | if (history.Count > length)
23 | {
24 | var old = history.Dequeue();
25 |
26 | sin -= (float)Math.Sin(old);
27 |
28 | cos -= (float)Math.Cos(old);
29 | }
30 | }
31 |
32 | internal float Average()
33 | {
34 | var size = history.Count;
35 |
36 | return (float)Math.Atan2(sin / size, cos / size);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Connectivity/Connectivity.netstandard.watchos.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Microsoft.Maui.Networking
5 | {
6 | partial class ConnectivityImplementation : IConnectivity
7 | {
8 | public NetworkAccess NetworkAccess =>
9 | throw ExceptionUtils.NotSupportedOrImplementedException;
10 |
11 | public IEnumerable ConnectionProfiles =>
12 | throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | void StartListeners() =>
15 | throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | void StopListeners() =>
18 | throw ExceptionUtils.NotSupportedOrImplementedException;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Connectivity/Connectivity.shared.enums.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Networking
2 | {
3 | ///
4 | /// Describes the type of connection the device is using.
5 | ///
6 | public enum ConnectionProfile
7 | {
8 | /// Other unknown type of connection.
9 | Unknown = 0,
10 |
11 | /// The bluetooth data connection.
12 | Bluetooth = 1,
13 |
14 | /// The mobile/cellular data connection.
15 | Cellular = 2,
16 |
17 | /// The ethernet data connection.
18 | Ethernet = 3,
19 |
20 | /// The Wi-Fi data connection.
21 | WiFi = 4
22 | }
23 |
24 | ///
25 | /// Various states of the connection to the internet.
26 | ///
27 | public enum NetworkAccess
28 | {
29 | /// The state of the connectivity is not known.
30 | Unknown = 0,
31 |
32 | /// No connectivity.
33 | None = 1,
34 |
35 | /// Local network access only.
36 | Local = 2,
37 |
38 | /// Limited internet access.
39 | ConstrainedInternet = 3,
40 |
41 | /// Local and Internet access.
42 | Internet = 4
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Contacts/Contacts.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 |
5 | namespace Microsoft.Maui.ApplicationModel.Communication
6 | {
7 | class ContactsImplementation : IContacts
8 | {
9 | public Task PickContactAsync() =>
10 | throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | public Task> GetAllAsync(CancellationToken cancellationToken) =>
13 | throw ExceptionUtils.NotSupportedOrImplementedException;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/DeviceDisplay/DeviceDisplay.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | namespace Microsoft.Maui.Devices
4 | {
5 | partial class DeviceDisplayImplementation
6 | {
7 | protected override bool GetKeepScreenOn() => false;
8 |
9 | protected override void SetKeepScreenOn(bool keepScreenOn) { }
10 |
11 | protected override DisplayInfo GetMainDisplayInfo() => default;
12 |
13 | protected override void StartScreenMetricsListeners() { }
14 |
15 | protected override void StopScreenMetricsListeners() { }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/DeviceInfo/DeviceInfo.netstandard.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Microsoft.Maui.Devices
5 | {
6 | class DeviceInfoImplementation : IDeviceInfo
7 | {
8 | public string Model => throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | public string Manufacturer => throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | public string Name => throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | public string VersionString => throw ExceptionUtils.NotSupportedOrImplementedException;
15 |
16 | public Version Version => throw ExceptionUtils.NotSupportedOrImplementedException;
17 |
18 | public DevicePlatform Platform => DevicePlatform.Unknown;
19 |
20 | public DeviceIdiom Idiom => DeviceIdiom.Unknown;
21 |
22 | public DeviceType DeviceType => DeviceType.Unknown;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Email/Email.macos.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using AppKit;
3 | using Foundation;
4 |
5 | namespace Microsoft.Maui.ApplicationModel.Communication
6 | {
7 | partial class EmailImplementation : IEmail
8 | {
9 | public bool IsComposeSupported =>
10 | MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString("mailto:")) != null);
11 |
12 | Task PlatformComposeAsync(EmailMessage message)
13 | {
14 | var url = GetMailToUri(message);
15 |
16 | using var nsurl = NSUrl.FromString(url);
17 | NSWorkspace.SharedWorkspace.OpenUrl(nsurl);
18 | return Task.CompletedTask;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Email/Email.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Microsoft.Maui.ApplicationModel.Communication
4 | {
5 | partial class EmailImplementation : IEmail
6 | {
7 | public bool IsComposeSupported =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | Task PlatformComposeAsync(EmailMessage message) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/FilePicker/FilePicker.netstandard.watchos.tvos.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 |
5 | namespace Microsoft.Maui.Storage
6 | {
7 | partial class FilePickerImplementation : IFilePicker
8 | {
9 | Task> PlatformPickAsync(PickOptions options, bool allowMultiple = false)
10 | => throw new NotImplementedInReferenceAssemblyException();
11 | }
12 |
13 | public partial class FilePickerFileType
14 | {
15 | static FilePickerFileType PlatformImageFileType()
16 | => throw new NotImplementedInReferenceAssemblyException();
17 |
18 | static FilePickerFileType PlatformPngFileType()
19 | => throw new NotImplementedInReferenceAssemblyException();
20 |
21 | static FilePickerFileType PlatformJpegFileType()
22 | => throw new NotImplementedInReferenceAssemblyException();
23 |
24 | static FilePickerFileType PlatformVideoFileType()
25 | => throw new NotImplementedInReferenceAssemblyException();
26 |
27 | static FilePickerFileType PlatformPdfFileType()
28 | => throw new NotImplementedInReferenceAssemblyException();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/FileSystem/FileSystem.netstandard.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 |
5 | namespace Microsoft.Maui.Storage
6 | {
7 | partial class FileSystemImplementation : IFileSystem
8 | {
9 | string PlatformCacheDirectory
10 | => throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | string PlatformAppDataDirectory
13 | => throw ExceptionUtils.NotSupportedOrImplementedException;
14 |
15 | Task PlatformOpenAppPackageFileAsync(string filename)
16 | => throw ExceptionUtils.NotSupportedOrImplementedException;
17 |
18 | Task PlatformAppPackageFileExistsAsync(string filename)
19 | => throw ExceptionUtils.NotSupportedOrImplementedException;
20 | }
21 |
22 | public partial class FileBase
23 | {
24 | static string PlatformGetContentType(string extension) =>
25 | throw ExceptionUtils.NotSupportedOrImplementedException;
26 |
27 | internal void Init(FileBase file) =>
28 | throw ExceptionUtils.NotSupportedOrImplementedException;
29 |
30 | internal virtual Task PlatformOpenReadAsync()
31 | => throw ExceptionUtils.NotSupportedOrImplementedException;
32 |
33 | void PlatformInit(FileBase file)
34 | => throw ExceptionUtils.NotSupportedOrImplementedException;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/FileSystem/FileSystemUtils.shared.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System.IO;
3 |
4 | namespace Microsoft.Maui.Storage
5 | {
6 | static partial class FileSystemUtils
7 | {
8 | ///
9 | /// Normalizes the given file path for the current platform.
10 | ///
11 | /// The file path to normalize.
12 | ///
13 | /// The normalized version of the file path provided in .
14 | /// Forward and backward slashes will be replaced by
15 | /// so that it is correct for the current platform.
16 | ///
17 | public static string NormalizePath(string filename) =>
18 | filename
19 | .Replace('\\', Path.DirectorySeparatorChar)
20 | .Replace('/', Path.DirectorySeparatorChar);
21 | }
22 | }
--------------------------------------------------------------------------------
/src/FileSystem/FileSystemUtils.uwp.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Diagnostics.CodeAnalysis;
4 | using System.IO;
5 | using Microsoft.Maui.ApplicationModel;
6 | using Package = Windows.ApplicationModel.Package;
7 |
8 | namespace Microsoft.Maui.Storage
9 | {
10 | static partial class FileSystemUtils
11 | {
12 | public static bool AppPackageFileExists(string filename)
13 | {
14 | var file = PlatformGetFullAppPackageFilePath(filename);
15 | return File.Exists(file);
16 | }
17 |
18 | public static string PlatformGetFullAppPackageFilePath(string filename)
19 | {
20 | if (filename is null)
21 | throw new ArgumentNullException(nameof(filename));
22 |
23 | filename = NormalizePath(filename);
24 |
25 | string root;
26 | if (AppInfoUtils.IsPackagedApp)
27 | root = Package.Current.InstalledLocation.Path;
28 | else
29 | root = AppContext.BaseDirectory;
30 |
31 | return Path.Combine(root, filename);
32 | }
33 |
34 | public static bool TryGetAppPackageFileUri(string filename, [NotNullWhen(true)] out string? uri)
35 | {
36 | var path = PlatformGetFullAppPackageFilePath(filename);
37 |
38 | if (File.Exists(path))
39 | {
40 | if (AppInfoUtils.IsPackagedApp)
41 | uri = $"ms-appx:///{filename.Replace('\\', '/')}";
42 | else
43 | uri = $"file:///{path.Replace('\\', '/')}";
44 |
45 | return true;
46 | }
47 |
48 | uri = null;
49 | return false;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Flashlight/Flashlight.netstandard.tvos.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Microsoft.Maui.Devices
5 | {
6 | class FlashlightImplementation : IFlashlight
7 | {
8 | ///
9 | /// Checks if the flashlight is available and can be turned on or off.
10 | ///
11 | /// when the flashlight is available, or when not
12 | public Task IsSupportedAsync() => Task.FromResult(false);
13 |
14 | public Task TurnOnAsync() =>
15 | throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | public Task TurnOffAsync() =>
18 | throw ExceptionUtils.NotSupportedOrImplementedException;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Flashlight/Flashlight.tizen.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Tizen.System;
4 |
5 | namespace Microsoft.Maui.Devices
6 | {
7 | class FlashlightImplementation : IFlashlight
8 | {
9 | internal static bool IsSupported
10 | => PlatformUtils.GetFeatureInfo("camera.back.flash");
11 |
12 | ///
13 | /// Checks if the flashlight is available and can be turned on or off.
14 | ///
15 | /// when the flashlight is available, or when not
16 | public Task IsSupportedAsync() => Task.FromResult(IsSupported);
17 |
18 | public Task TurnOnAsync()
19 | {
20 | return SwitchFlashlight(true);
21 | }
22 |
23 | public Task TurnOffAsync()
24 | {
25 | return SwitchFlashlight(false);
26 | }
27 |
28 | Task SwitchFlashlight(bool switchOn)
29 | {
30 | Permissions.EnsureDeclared();
31 | return Task.Run(() =>
32 | {
33 | if (!IsSupported)
34 | throw new FeatureNotSupportedException();
35 |
36 | if (switchOn)
37 | Led.Brightness = Led.MaxBrightness;
38 | else
39 | Led.Brightness = 0;
40 | });
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/Geocoding/Geocoding.android.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Threading.Tasks;
5 | using Android.App;
6 | using Android.Locations;
7 | using Microsoft.Maui.ApplicationModel;
8 |
9 | namespace Microsoft.Maui.Devices.Sensors
10 | {
11 | class GeocodingImplementation : IGeocoding
12 | {
13 | public async Task> GetPlacemarksAsync(double latitude, double longitude)
14 | {
15 | using (var geocoder = new Geocoder(Application.Context))
16 | {
17 | var addressList = await geocoder.GetFromLocationAsync(latitude, longitude, 10);
18 | return addressList?.ToPlacemarks() ?? Array.Empty();
19 | }
20 | }
21 |
22 | public async Task> GetLocationsAsync(string address)
23 | {
24 | if (address == null)
25 | throw new ArgumentNullException(nameof(address));
26 |
27 | using (var geocoder = new Geocoder(Application.Context))
28 | {
29 | var addressList = await geocoder.GetFromLocationNameAsync(address, 10);
30 |
31 | return addressList?.ToLocations() ?? Array.Empty();
32 | }
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Geocoding/Geocoding.ios.tvos.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Threading.Tasks;
5 | using CoreLocation;
6 |
7 | namespace Microsoft.Maui.Devices.Sensors
8 | {
9 | class GeocodingImplementation : IGeocoding
10 | {
11 | public async Task> GetPlacemarksAsync(double latitude, double longitude)
12 | {
13 | using (var geocoder = new CLGeocoder())
14 | {
15 | var addressList = await geocoder.ReverseGeocodeLocationAsync(new CLLocation(latitude, longitude));
16 |
17 | return addressList?.ToPlacemarks() ?? Array.Empty();
18 | }
19 | }
20 |
21 | public async Task> GetLocationsAsync(string address)
22 | {
23 | using (var geocoder = new CLGeocoder())
24 | {
25 | var positionList = await geocoder.GeocodeAddressAsync(address);
26 |
27 | return positionList?.ToLocations() ?? Array.Empty();
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Geocoding/Geocoding.netstandard.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | class GeocodingImplementation : IGeocoding
8 | {
9 | public Task> GetPlacemarksAsync(double latitude, double longitude) =>
10 | throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | public Task> GetLocationsAsync(string address) =>
13 | throw ExceptionUtils.NotSupportedOrImplementedException;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Geolocation/Geolocation.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using Microsoft.Maui.ApplicationModel;
6 |
7 | namespace Microsoft.Maui.Devices.Sensors
8 | {
9 | partial class GeolocationImplementation : IGeolocation
10 | {
11 | public Task GetLastKnownLocationAsync() =>
12 | throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | public Task GetLocationAsync(GeolocationRequest request, CancellationToken cancellationToken) =>
15 | throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | public bool IsListeningForeground { get => false; }
18 |
19 | public Task StartListeningForegroundAsync(GeolocationListeningRequest request) =>
20 | throw ExceptionUtils.NotSupportedOrImplementedException;
21 |
22 | public void StopListeningForeground() =>
23 | throw ExceptionUtils.NotSupportedOrImplementedException;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationAccuracyExtensionMethods.ios.macos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using CoreLocation;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | static class GeolocationAccuracyExtensionMethods
7 | {
8 | internal static double PlatformDesiredAccuracy(this GeolocationAccuracy desiredAccuracy)
9 | {
10 | switch (desiredAccuracy)
11 | {
12 | case GeolocationAccuracy.Lowest:
13 | return CLLocation.AccuracyThreeKilometers;
14 | case GeolocationAccuracy.Low:
15 | return CLLocation.AccuracyKilometer;
16 | case GeolocationAccuracy.Default:
17 | case GeolocationAccuracy.Medium:
18 | return CLLocation.AccuracyHundredMeters;
19 | case GeolocationAccuracy.High:
20 | return CLLocation.AccuracyNearestTenMeters;
21 | case GeolocationAccuracy.Best:
22 | return CLLocation.AccurracyBestForNavigation;
23 | default:
24 | return CLLocation.AccuracyHundredMeters;
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationAccuracyExtensionMethods.uwp.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | static class GeolocationAccuracyExtensionMethods
6 | {
7 | internal static uint PlatformGetDesiredAccuracy(this GeolocationAccuracy desiredAccuracy)
8 | {
9 | switch (desiredAccuracy)
10 | {
11 | case GeolocationAccuracy.Lowest:
12 | return 3000;
13 | case GeolocationAccuracy.Low:
14 | return 1000;
15 | case GeolocationAccuracy.Default:
16 | case GeolocationAccuracy.Medium:
17 | return 100;
18 | case GeolocationAccuracy.High:
19 | return 10; // Equivalent to PositionAccuracy.High
20 | case GeolocationAccuracy.Best:
21 | return 1;
22 | default:
23 | return 500; // Equivalent to PositionAccuracy.Default
24 | }
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationError.shared.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | ///
6 | /// Error values for listening for geolocation changes
7 | ///
8 | public enum GeolocationError
9 | {
10 | ///
11 | /// The provider was unable to retrieve any position data.
12 | ///
13 | ///
14 | /// Android: Sent when no location provider is available that satisfies the requested geolocation accuracy.
15 | /// iOS: Getting location data has failed.
16 | /// Windows: No location data is available from any source.
17 | ///
18 | PositionUnavailable,
19 |
20 | ///
21 | /// The app is not, or no longer, authorized to receive location data.
22 | ///
23 | ///
24 | /// Android: Not used.
25 | /// iOS: Authorization for getting locations has changed.
26 | /// Windows: Location sources are turned off.
27 | ///
28 | Unauthorized,
29 | }
30 | }
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationListeningFailedEventArgs.shared.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | ///
7 | /// Event args for the geolocation listening error event.
8 | ///
9 | public class GeolocationListeningFailedEventArgs : EventArgs
10 | {
11 | ///
12 | /// The geolocation error that describes the error that occurred.
13 | ///
14 | public GeolocationError Error { get; }
15 |
16 | ///
17 | /// Creates a new geolocation error event args object
18 | ///
19 | /// gelocation error to use for this object
20 | public GeolocationListeningFailedEventArgs(GeolocationError geolocationError)
21 | {
22 | Error = geolocationError;
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationListeningRequest.ios.macos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | public partial class GeolocationListeningRequest
6 | {
7 | internal double PlatformDesiredAccuracy
8 | {
9 | get
10 | {
11 | return DesiredAccuracy.PlatformDesiredAccuracy();
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationListeningRequest.uwp.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | public partial class GeolocationListeningRequest
6 | {
7 | internal uint PlatformDesiredAccuracy
8 | {
9 | get
10 | {
11 | return DesiredAccuracy.PlatformGetDesiredAccuracy();
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationLocationChangedEventArgs.shared.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | ///
7 | /// Event arguments containing the current reading of .
8 | ///
9 | public class GeolocationLocationChangedEventArgs : EventArgs
10 | {
11 | ///
12 | /// The current reading's location data.
13 | ///
14 | public Location Location { get; }
15 |
16 | ///
17 | /// Public constructor that takes in a reading for event arguments.
18 | ///
19 | /// The location data reading.
20 | /// Thrown when is .
21 | public GeolocationLocationChangedEventArgs(Location location)
22 | {
23 | if (location == null)
24 | throw new ArgumentNullException(nameof(location));
25 |
26 | Location = location;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationRequest.ios.macos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | public partial class GeolocationRequest
6 | {
7 | internal double PlatformDesiredAccuracy
8 | {
9 | get
10 | {
11 | return DesiredAccuracy.PlatformDesiredAccuracy();
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Geolocation/GeolocationRequest.uwp.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | public partial class GeolocationRequest
6 | {
7 | internal uint PlatformDesiredAccuracy
8 | {
9 | get
10 | {
11 | return DesiredAccuracy.PlatformGetDesiredAccuracy();
12 | }
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Graphics/Color.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui;
2 |
3 | ///
4 | /// Color struct.
5 | ///
6 | public record struct Color(float A, float R, float G, float B);
7 |
8 | ///
9 | /// Helpers.
10 | ///
11 | public static class ColorEx
12 | {
13 | #if IOS
14 | ///
15 | /// Convert to UIColor.
16 | ///
17 | public static UIKit.UIColor? AsUIColor(this Color? color) => color is { } c
18 | ? new(c.R, c.G, c.B, c.A)
19 | : null;
20 | #endif
21 |
22 | ///
23 | /// Convert to int.
24 | ///
25 | public static int ToInt(this Color? color) => color is { } c
26 | ? ((byte)c.A * 255) << 24 | ((byte)c.R * 255) << 16 | ((byte)c.G * 255) << 8 | ((byte)c.B * 255)
27 | : 0;
28 | }
--------------------------------------------------------------------------------
/src/Graphics/Rect.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Essentials;
2 |
3 | ///
4 | /// Rect struct.
5 | ///
6 | public record struct Rect(double X, double Y, double Width, double Height)
7 | {
8 | ///
9 | /// Empty rect.
10 | ///
11 | public static Rect Zero => default;
12 |
13 | #if IOS
14 | ///
15 | /// Convert to CGRect.
16 | ///
17 | public CoreGraphics.CGRect AsCGRect() => new(X, Y, Width, Height);
18 | #endif
19 | }
--------------------------------------------------------------------------------
/src/Gyroscope/Gyroscope.ios.watchos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using CoreMotion;
3 | using Foundation;
4 | using Microsoft.Maui.ApplicationModel;
5 |
6 | namespace Microsoft.Maui.Devices.Sensors
7 | {
8 | partial class GyroscopeImplementation : IGyroscope
9 | {
10 | static CMMotionManager? motionManager;
11 |
12 | static CMMotionManager MotionManager =>
13 | motionManager ??= new CMMotionManager();
14 |
15 | bool PlatformIsSupported =>
16 | MotionManager.GyroAvailable;
17 |
18 | void PlatformStart(SensorSpeed sensorSpeed)
19 | {
20 | MotionManager.GyroUpdateInterval = sensorSpeed.ToPlatform();
21 | MotionManager.StartGyroUpdates(NSOperationQueue.CurrentQueue ?? new NSOperationQueue(), DataUpdated);
22 | }
23 |
24 | void DataUpdated(CMGyroData data, NSError error)
25 | {
26 | if (data == null)
27 | return;
28 |
29 | #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-macios/issues/14619
30 | var field = data.RotationRate;
31 | #pragma warning restore CA1416
32 | var gyroData = new GyroscopeData(field.x, field.y, field.z);
33 | RaiseReadingChanged(gyroData);
34 | }
35 |
36 | void PlatformStop() =>
37 | MotionManager.StopGyroUpdates();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Gyroscope/Gyroscope.netstandard.tvos.macos.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | partial class GyroscopeImplementation : IGyroscope
6 | {
7 | bool PlatformIsSupported =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | void PlatformStart(SensorSpeed sensorSpeed) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | void PlatformStop() =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Gyroscope/Gyroscope.tizen.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Tizen.Sensor;
3 | using TizenGyroscope = Tizen.Sensor.Gyroscope;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | partial class GyroscopeImplementation : IGyroscope
8 | {
9 | static TizenGyroscope DefaultSensor =>
10 | (TizenGyroscope)PlatformUtils.GetDefaultSensor(SensorType.Gyroscope);
11 |
12 | bool PlatformIsSupported =>
13 | TizenGyroscope.IsSupported;
14 |
15 | TizenGyroscope sensor;
16 |
17 | void PlatformStart(SensorSpeed sensorSpeed)
18 | {
19 | sensor = DefaultSensor;
20 | sensor.Interval = sensorSpeed.ToPlatform();
21 | sensor.DataUpdated += DataUpdated;
22 | sensor.Start();
23 | }
24 |
25 | void PlatformStop()
26 | {
27 | sensor.DataUpdated -= DataUpdated;
28 | sensor.Stop();
29 | sensor = null;
30 | }
31 |
32 | void DataUpdated(object sender, GyroscopeDataUpdatedEventArgs e)
33 | {
34 | RaiseReadingChanged(new GyroscopeData(e.X, e.Y, e.Z));
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Gyroscope/Gyroscope.uwp.cs:
--------------------------------------------------------------------------------
1 | using Windows.Devices.Sensors;
2 | using WindowsGyro = Windows.Devices.Sensors.Gyrometer;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | partial class GyroscopeImplementation : IGyroscope
7 | {
8 | // keep around a reference so we can stop this same instance
9 | WindowsGyro sensor;
10 |
11 | static WindowsGyro DefaultSensor =>
12 | WindowsGyro.GetDefault();
13 |
14 | bool PlatformIsSupported =>
15 | DefaultSensor != null;
16 |
17 | void PlatformStart(SensorSpeed sensorSpeed)
18 | {
19 | sensor = DefaultSensor;
20 |
21 | var interval = sensorSpeed.ToPlatform();
22 | sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval;
23 |
24 | sensor.ReadingChanged += DataUpdated;
25 | }
26 |
27 | void DataUpdated(object sender, GyrometerReadingChangedEventArgs e)
28 | {
29 | var reading = e.Reading;
30 | var data = new GyroscopeData(reading.AngularVelocityX, reading.AngularVelocityY, reading.AngularVelocityZ);
31 | RaiseReadingChanged(data);
32 | }
33 |
34 | void PlatformStop()
35 | {
36 | sensor.ReadingChanged -= DataUpdated;
37 | sensor.ReportInterval = 0;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/HapticFeedback/HapticFeedback.android.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Threading.Tasks;
4 | using Android.Views;
5 | using Microsoft.Maui.ApplicationModel;
6 |
7 | namespace Microsoft.Maui.Devices
8 | {
9 | partial class HapticFeedbackImplementation : IHapticFeedback
10 | {
11 | public bool IsSupported => true;
12 |
13 | public void Perform(HapticFeedbackType type)
14 | {
15 | Permissions.EnsureDeclared();
16 |
17 | try
18 | {
19 | ActivityStateManager.Default.GetCurrentActivity()?.Window?.DecorView?.PerformHapticFeedback(ConvertType(type));
20 | }
21 | catch (Exception ex)
22 | {
23 | Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
24 | }
25 | }
26 |
27 | static FeedbackConstants ConvertType(HapticFeedbackType type) =>
28 | type switch
29 | {
30 | HapticFeedbackType.LongPress => FeedbackConstants.LongPress,
31 | #pragma warning disable CA1416 // Introduced in API 23: https://developer.android.com/reference/android/view/HapticFeedbackConstants#CONTEXT_CLICK
32 | _ => FeedbackConstants.ContextClick
33 | #pragma warning restore CA1416
34 | };
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/HapticFeedback/HapticFeedback.ios.cs:
--------------------------------------------------------------------------------
1 | using UIKit;
2 |
3 | namespace Microsoft.Maui.Devices
4 | {
5 | partial class HapticFeedbackImplementation : IHapticFeedback
6 | {
7 | public bool IsSupported => true;
8 |
9 | public void Perform(HapticFeedbackType type)
10 | {
11 | switch (type)
12 | {
13 | case HapticFeedbackType.LongPress:
14 | LongPress();
15 | break;
16 | default:
17 | Click();
18 | break;
19 | }
20 | }
21 |
22 | void Click()
23 | {
24 | var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Light);
25 | impact.Prepare();
26 | impact.ImpactOccurred();
27 | impact.Dispose();
28 | }
29 |
30 | void LongPress()
31 | {
32 | var impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium);
33 | impact.Prepare();
34 | impact.ImpactOccurred();
35 | impact.Dispose();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/HapticFeedback/HapticFeedback.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using AppKit;
4 |
5 | namespace Microsoft.Maui.Devices
6 | {
7 | partial class HapticFeedbackImplementation : IHapticFeedback
8 | {
9 | public bool IsSupported => true;
10 |
11 | public void Perform(HapticFeedbackType type)
12 | {
13 | if (type == HapticFeedbackType.LongPress)
14 | NSHapticFeedbackManager.DefaultPerformer.PerformFeedback(NSHapticFeedbackPattern.Generic, NSHapticFeedbackPerformanceTime.Default);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/HapticFeedback/HapticFeedback.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 |
5 | namespace Microsoft.Maui.Devices
6 | {
7 | partial class HapticFeedbackImplementation : IHapticFeedback
8 | {
9 | public bool IsSupported
10 | => throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | public void Perform(HapticFeedbackType type)
13 | => throw ExceptionUtils.NotSupportedOrImplementedException;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/HapticFeedback/HapticFeedback.tizen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using Microsoft.Maui.ApplicationModel;
4 | using Tizen.System;
5 |
6 | namespace Microsoft.Maui.Devices
7 | {
8 | partial class HapticFeedbackImplementation : IHapticFeedback
9 | {
10 | public bool IsSupported => true;
11 |
12 | public void Perform(HapticFeedbackType type)
13 | {
14 | Permissions.EnsureDeclared();
15 | try
16 | {
17 | var feedback = new Feedback();
18 | var pattern = ConvertType(type);
19 | if (feedback.IsSupportedPattern(FeedbackType.Vibration, pattern))
20 | feedback.Play(FeedbackType.Vibration, pattern);
21 | }
22 | catch (Exception ex)
23 | {
24 | Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
25 | }
26 | }
27 |
28 | static string ConvertType(HapticFeedbackType type) =>
29 | type switch
30 | {
31 | HapticFeedbackType.LongPress => "Hold",
32 | _ => "Tap"
33 | };
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/HapticFeedback/HapticFeedbackType.shared.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Devices
2 | {
3 | ///
4 | /// Enumerates the possible types of response.
5 | ///
6 | public enum HapticFeedbackType
7 | {
8 | /// The haptic feedback that belongs to a click/tap action.
9 | Click,
10 |
11 | /// The haptic feedback that belongs to a long press action.
12 | LongPress
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Launcher/Launcher.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Diagnostics;
3 | using System.Threading.Tasks;
4 | using AppKit;
5 | using Foundation;
6 |
7 | namespace Microsoft.Maui.ApplicationModel
8 | {
9 | partial class LauncherImplementation
10 | {
11 | Task PlatformCanOpenAsync(Uri uri) =>
12 | Task.FromResult(NSWorkspace.SharedWorkspace.UrlForApplication(WebUtils.GetNativeUrl(uri)) != null);
13 |
14 | Task PlatformOpenAsync(Uri uri) =>
15 | Task.FromResult(NSWorkspace.SharedWorkspace.OpenUrl(WebUtils.GetNativeUrl(uri)));
16 |
17 | Task PlatformTryOpenAsync(Uri uri)
18 | {
19 | var nativeUrl = WebUtils.GetNativeUrl(uri);
20 | var canOpen = NSWorkspace.SharedWorkspace.UrlForApplication(nativeUrl) != null;
21 |
22 | if (canOpen)
23 | return Task.FromResult(NSWorkspace.SharedWorkspace.OpenUrl(nativeUrl));
24 |
25 | return Task.FromResult(canOpen);
26 | }
27 |
28 | Task PlatformOpenAsync(OpenFileRequest request) =>
29 | Task.FromResult(NSWorkspace.SharedWorkspace.OpenFile(request.File.FullPath));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Launcher/Launcher.netstandard.watchos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | partial class LauncherImplementation
7 | {
8 | Task PlatformCanOpenAsync(Uri uri) =>
9 | throw ExceptionUtils.NotSupportedOrImplementedException;
10 |
11 | Task PlatformOpenAsync(Uri uri) =>
12 | throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | Task PlatformOpenAsync(OpenFileRequest request) =>
15 | throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | Task PlatformTryOpenAsync(Uri uri) =>
18 | throw ExceptionUtils.NotSupportedOrImplementedException;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Launcher/Launcher.uwp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Windows.Storage;
4 | using Windows.System;
5 | using WinLauncher = Windows.System.Launcher;
6 |
7 | namespace Microsoft.Maui.ApplicationModel
8 | {
9 | partial class LauncherImplementation
10 | {
11 | async Task PlatformCanOpenAsync(Uri uri)
12 | {
13 | var supported = await WinLauncher.QueryUriSupportAsync(uri, LaunchQuerySupportType.Uri);
14 | return supported == LaunchQuerySupportStatus.Available;
15 | }
16 |
17 | Task PlatformOpenAsync(Uri uri) =>
18 | WinLauncher.LaunchUriAsync(uri).AsTask();
19 |
20 | async Task PlatformOpenAsync(OpenFileRequest request)
21 | {
22 | var storageFile = request.File.File ?? await StorageFile.GetFileFromPathAsync(request.File.FullPath);
23 |
24 | return await WinLauncher.LaunchFileAsync(storageFile).AsTask();
25 | }
26 |
27 | async Task PlatformTryOpenAsync(Uri uri)
28 | {
29 | var canOpen = await PlatformCanOpenAsync(uri);
30 |
31 | if (canOpen)
32 | return await WinLauncher.LaunchUriAsync(uri).AsTask();
33 |
34 | return canOpen;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Magnetometer/Magnetometer.ios.watchos.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using CoreMotion;
3 | using Foundation;
4 | using Microsoft.Maui.ApplicationModel;
5 |
6 | namespace Microsoft.Maui.Devices.Sensors
7 | {
8 | partial class MagnetometerImplementation : IMagnetometer
9 | {
10 | static CMMotionManager? motionManager;
11 |
12 | static CMMotionManager MotionManager =>
13 | motionManager ??= new CMMotionManager();
14 |
15 | bool PlatformIsSupported =>
16 | MotionManager.MagnetometerAvailable;
17 |
18 | void PlatformStart(SensorSpeed sensorSpeed)
19 | {
20 | MotionManager.MagnetometerUpdateInterval = sensorSpeed.ToPlatform();
21 | MotionManager.StartMagnetometerUpdates(NSOperationQueue.CurrentQueue ?? new NSOperationQueue(), DataUpdated);
22 | }
23 |
24 | void DataUpdated(CMMagnetometerData data, NSError error)
25 | {
26 | if (data == null)
27 | return;
28 | #pragma warning disable CA1416 // https://github.com/xamarin/xamarin-macios/issues/14619
29 | var field = data.MagneticField;
30 | var magnetometerData = new MagnetometerData(field.X, field.Y, field.Z);
31 | #pragma warning restore CA1416
32 | RaiseReadingChanged(magnetometerData);
33 | }
34 |
35 | void PlatformStop() =>
36 | MotionManager.StopMagnetometerUpdates();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Magnetometer/Magnetometer.netstandard.tvos.macos.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | partial class MagnetometerImplementation
6 | {
7 | bool PlatformIsSupported =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | void PlatformStart(SensorSpeed sensorSpeed) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | void PlatformStop() =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Magnetometer/Magnetometer.shared.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AvaloniaUI/Avalonia.Essentials/3cf7aa3445725c84a70a3e7c8c5f0ee2d0292922/src/Magnetometer/Magnetometer.shared.cs
--------------------------------------------------------------------------------
/src/Magnetometer/Magnetometer.tizen.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Tizen.Sensor;
3 | using TizenMagnetometer = Tizen.Sensor.Magnetometer;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | partial class MagnetometerImplementation : IMagnetometer
8 | {
9 | static TizenMagnetometer DefaultSensor =>
10 | (TizenMagnetometer)PlatformUtils.GetDefaultSensor(SensorType.Magnetometer);
11 |
12 | bool PlatformIsSupported =>
13 | TizenMagnetometer.IsSupported;
14 |
15 | TizenMagnetometer sensor;
16 |
17 | void PlatformStart(SensorSpeed sensorSpeed)
18 | {
19 | sensor = DefaultSensor;
20 | sensor.Interval = sensorSpeed.ToPlatform();
21 | sensor.DataUpdated += DataUpdated;
22 | sensor.Start();
23 | }
24 |
25 | void PlatformStop()
26 | {
27 | sensor.DataUpdated -= DataUpdated;
28 | sensor.Stop();
29 | sensor = null;
30 | }
31 |
32 | void DataUpdated(object sender, MagnetometerDataUpdatedEventArgs e)
33 | {
34 | RaiseReadingChanged(new MagnetometerData(e.X, e.Y, e.Z));
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Magnetometer/Magnetometer.uwp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Windows.Devices.Sensors;
3 | using WindowsMagnetometer = Windows.Devices.Sensors.Magnetometer;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | partial class MagnetometerImplementation : IMagnetometer
8 | {
9 | // keep around a reference so we can stop this same instance
10 | WindowsMagnetometer sensor;
11 |
12 | static WindowsMagnetometer DefaultSensor =>
13 | WindowsMagnetometer.GetDefault();
14 |
15 | bool PlatformIsSupported =>
16 | DefaultSensor != null;
17 |
18 | void PlatformStart(SensorSpeed sensorSpeed)
19 | {
20 | sensor = DefaultSensor;
21 |
22 | var interval = sensorSpeed.ToPlatform();
23 | sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval;
24 |
25 | sensor.ReadingChanged += DataUpdated;
26 | }
27 |
28 | void DataUpdated(object sender, MagnetometerReadingChangedEventArgs e)
29 | {
30 | var reading = e.Reading;
31 | var data = new MagnetometerData(reading.MagneticFieldX, reading.MagneticFieldY, reading.MagneticFieldZ);
32 | RaiseReadingChanged(data);
33 | }
34 |
35 | void PlatformStop()
36 | {
37 | sensor.ReadingChanged -= DataUpdated;
38 | sensor.ReportInterval = 0;
39 | sensor = null;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/MainThread/MainThread.android.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Android.OS;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | public static partial class MainThread
7 | {
8 | static volatile Handler handler;
9 |
10 | static bool PlatformIsMainThread
11 | {
12 | get
13 | {
14 | if (OperatingSystem.IsAndroidVersionAtLeast(23))
15 | return Looper.MainLooper.IsCurrentThread;
16 |
17 | return Looper.MyLooper() == Looper.MainLooper;
18 | }
19 | }
20 |
21 | static void PlatformBeginInvokeOnMainThread(Action action)
22 | {
23 | if (handler?.Looper != Looper.MainLooper)
24 | handler = new Handler(Looper.MainLooper);
25 |
26 | handler.Post(action);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/MainThread/MainThread.ios.tvos.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Foundation;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | public static partial class MainThread
7 | {
8 | static bool PlatformIsMainThread =>
9 | NSThread.Current.IsMainThread;
10 |
11 | static void PlatformBeginInvokeOnMainThread(Action action)
12 | {
13 | NSRunLoop.Main.BeginInvokeOnMainThread(action.Invoke);
14 | }
15 |
16 | internal static T InvokeOnMainThread(Func factory)
17 | {
18 | T value = default;
19 | NSRunLoop.Main.InvokeOnMainThread(() => value = factory());
20 | return value;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/MainThread/MainThread.netstandard.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Microsoft.Maui.ApplicationModel
4 | {
5 | public static partial class MainThread
6 | {
7 | static void PlatformBeginInvokeOnMainThread(Action action) =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | static bool PlatformIsMainThread =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/MainThread/MainThread.tizen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using ElmSharp;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | public static partial class MainThread
7 | {
8 | static void PlatformBeginInvokeOnMainThread(Action action)
9 | {
10 | if (PlatformIsMainThread)
11 | action();
12 | else
13 | EcoreMainloop.PostAndWakeUp(action);
14 | }
15 |
16 | static bool PlatformIsMainThread
17 | => EcoreMainloop.IsMainThread;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/MainThread/MainThread.uwp.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using Microsoft.UI.Dispatching;
4 |
5 | namespace Microsoft.Maui.ApplicationModel
6 | {
7 | public static partial class MainThread
8 | {
9 | static bool PlatformIsMainThread =>
10 | TryGetDispatcherQueue()?.HasThreadAccess ?? false;
11 |
12 | static void PlatformBeginInvokeOnMainThread(Action action)
13 | {
14 | var dispatcher = TryGetDispatcherQueue();
15 |
16 | if (dispatcher == null)
17 | throw new InvalidOperationException("Unable to find main thread.");
18 |
19 | if (!dispatcher.TryEnqueue(DispatcherQueuePriority.Normal, () => action()))
20 | throw new InvalidOperationException("Unable to queue on the main thread.");
21 | }
22 |
23 | static DispatcherQueue? TryGetDispatcherQueue() =>
24 | DispatcherQueue.GetForCurrentThread() ??
25 | WindowStateManager.Default.GetActiveWindow(false)?.DispatcherQueue;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Map/Map.netstandard.tvos.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.Devices.Sensors;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | class MapImplementation : IMap
7 | {
8 | public Task OpenAsync(double latitude, double longitude, MapLaunchOptions options)
9 | => throw ExceptionUtils.NotSupportedOrImplementedException;
10 |
11 | public Task OpenAsync(Placemark placemark, MapLaunchOptions options)
12 | => throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | public Task TryOpenAsync(double latitude, double longitude, MapLaunchOptions options)
15 | => throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | public Task TryOpenAsync(Placemark placemark, MapLaunchOptions options)
18 | => throw ExceptionUtils.NotSupportedOrImplementedException;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Map/MapLaunchOptions.shared.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.ApplicationModel
2 | {
3 | ///
4 | /// Launch options for opening the installed map application.
5 | ///
6 | public class MapLaunchOptions
7 | {
8 | ///
9 | /// Gets or sets the navigation mode to use in the map application.
10 | ///
11 | public NavigationMode NavigationMode { get; set; } = NavigationMode.None;
12 |
13 | ///
14 | /// Gets or sets the name of destination to display to user.
15 | ///
16 | public string Name { get; set; } = string.Empty;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Map/NavigationMode.shared.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.ApplicationModel
2 | {
3 | ///
4 | /// Represents various modes of navigation that can be passed to the operating system's Maps app.
5 | ///
6 | public enum NavigationMode
7 | {
8 | /// No navigation mode.
9 | None = 0,
10 |
11 | /// The default navigation mode on the platform.
12 | Default = 1,
13 |
14 | /// Bicycle route mode.
15 | Bicycling = 2,
16 |
17 | /// Car route mode.
18 | Driving = 3,
19 |
20 | /// Transit route mode.
21 | Transit = 4,
22 |
23 | /// Walking route mode.
24 | Walking = 5,
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/MediaPicker/MediaPicker.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.Maui.Media
7 | {
8 | partial class MediaPickerImplementation : IMediaPicker
9 | {
10 | public bool PlatformIsCaptureSupported
11 | => false;
12 |
13 | public async Task PlatformPickPhotoAsync(MediaPickerOptions options)
14 | => new FileResult(await FilePicker.PickAsync(new PickOptions
15 | {
16 | FileTypes = FilePickerFileType.Images
17 | }));
18 |
19 | public Task PlatformCapturePhotoAsync(MediaPickerOptions options)
20 | => PlatformPickPhotoAsync(options);
21 |
22 | public async Task PlatformPickVideoAsync(MediaPickerOptions options)
23 | => new FileResult(await FilePicker.PickAsync(new PickOptions
24 | {
25 | FileTypes = FilePickerFileType.Videos
26 | }));
27 |
28 | public Task PlatformCaptureVideoAsync(MediaPickerOptions options)
29 | => PlatformPickVideoAsync(options);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/MediaPicker/MediaPicker.netstandard.watchos.tvos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Threading.Tasks;
4 | using Microsoft.Maui.ApplicationModel;
5 | using Microsoft.Maui.Storage;
6 |
7 | namespace Microsoft.Maui.Media
8 | {
9 | partial class MediaPickerImplementation : IMediaPicker
10 | {
11 | public bool IsCaptureSupported =>
12 | throw new NotImplementedInReferenceAssemblyException();
13 |
14 | public Task PickPhotoAsync(MediaPickerOptions options) =>
15 | throw new NotImplementedInReferenceAssemblyException();
16 |
17 | public Task CapturePhotoAsync(MediaPickerOptions options) =>
18 | throw new NotImplementedInReferenceAssemblyException();
19 |
20 | public Task PickVideoAsync(MediaPickerOptions options) =>
21 | throw new NotImplementedInReferenceAssemblyException();
22 |
23 | public Task CaptureVideoAsync(MediaPickerOptions options) =>
24 | throw new NotImplementedInReferenceAssemblyException();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/OrientationSensor/OrientationSensor.netstandard.tvos.macos.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | partial class OrientationSensorImplementation : IOrientationSensor
6 | {
7 | bool PlatformIsSupported =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | void PlatformStart(SensorSpeed sensorSpeed) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | void PlatformStop() =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/OrientationSensor/OrientationSensor.tizen.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Tizen.Sensor;
3 | using TizenRotationVectorSensor = Tizen.Sensor.RotationVectorSensor;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | partial class OrientationSensorImplementation : IOrientationSensor
8 | {
9 | static TizenRotationVectorSensor DefaultSensor
10 | => (TizenRotationVectorSensor)PlatformUtils.GetDefaultSensor(SensorType.OrientationSensor);
11 |
12 | bool PlatformIsSupported
13 | => TizenRotationVectorSensor.IsSupported;
14 |
15 | TizenRotationVectorSensor sensor;
16 |
17 | void PlatformStart(SensorSpeed sensorSpeed)
18 | {
19 | sensor = DefaultSensor;
20 |
21 | sensor.Interval = sensorSpeed.ToPlatform();
22 | sensor.DataUpdated += DataUpdated;
23 | sensor.Start();
24 | }
25 |
26 | void PlatformStop()
27 | {
28 | sensor.DataUpdated -= DataUpdated;
29 | sensor.Stop();
30 | sensor = null;
31 | }
32 |
33 | void DataUpdated(object sender, RotationVectorSensorDataUpdatedEventArgs e)
34 | {
35 | RaiseReadingChanged(new OrientationSensorData(e.X, e.Y, e.Z, e.W));
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/OrientationSensor/OrientationSensor.uwp.cs:
--------------------------------------------------------------------------------
1 | using Windows.Devices.Sensors;
2 | using WindowsOrientationSensor = Windows.Devices.Sensors.OrientationSensor;
3 |
4 | namespace Microsoft.Maui.Devices.Sensors
5 | {
6 | partial class OrientationSensorImplementation : IOrientationSensor
7 | {
8 | // keep around a reference so we can stop this same instance
9 | WindowsOrientationSensor sensor;
10 |
11 | static WindowsOrientationSensor DefaultSensor =>
12 | WindowsOrientationSensor.GetDefault();
13 |
14 | bool PlatformIsSupported =>
15 | DefaultSensor != null;
16 |
17 | void PlatformStart(SensorSpeed sensorSpeed)
18 | {
19 | sensor = DefaultSensor;
20 |
21 | var interval = sensorSpeed.ToPlatform();
22 |
23 | sensor.ReportInterval = sensor.MinimumReportInterval >= interval ? sensor.MinimumReportInterval : interval;
24 | sensor.ReadingChanged += DataUpdated;
25 | }
26 |
27 | void DataUpdated(object sender, OrientationSensorReadingChangedEventArgs e)
28 | {
29 | var reading = e.Reading;
30 | var data = new OrientationSensorData(reading.Quaternion.X, reading.Quaternion.Y, reading.Quaternion.Z, reading.Quaternion.W);
31 | RaiseReadingChanged(data);
32 | }
33 |
34 | void PlatformStop()
35 | {
36 | sensor.ReadingChanged -= DataUpdated;
37 | sensor.ReportInterval = 0;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Permissions/Permissions.shared.enums.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.ApplicationModel
2 | {
3 | ///
4 | /// Possible statuses of a permission.
5 | ///
6 | public enum PermissionStatus
7 | {
8 | /// The permission is in an unknown state.
9 | Unknown = 0,
10 |
11 | /// The user denied the permission request
12 | Denied = 1,
13 |
14 | /// The feature is disabled on the device.
15 | Disabled = 2,
16 |
17 | /// The user granted permission or is automatically granted.
18 | Granted = 3,
19 |
20 | /// In a restricted state (only iOS).
21 | Restricted = 4,
22 |
23 | /// In a limited state (only iOS).
24 | Limited = 5
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/PhoneDialer/PhoneDialer.ios.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Foundation;
3 | using UIKit;
4 |
5 | namespace Microsoft.Maui.ApplicationModel.Communication
6 | {
7 | partial class PhoneDialerImplementation : IPhoneDialer
8 | {
9 | public bool IsSupported => UIApplication.SharedApplication.CanOpenUrl(CreateNsUrl(new string('0', 10)));
10 |
11 | public void Open(string number)
12 | {
13 | ValidateOpen(number);
14 |
15 | var nsUrl = CreateNsUrl(number);
16 | Launcher.Default.OpenAsync(nsUrl);
17 | }
18 |
19 | static NSUrl CreateNsUrl(string number) => new NSUrl(new Uri($"tel:{number}").AbsoluteUri);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/PhoneDialer/PhoneDialer.macos.cs:
--------------------------------------------------------------------------------
1 | using AppKit;
2 | using Foundation;
3 |
4 | namespace Microsoft.Maui.ApplicationModel.Communication
5 | {
6 | partial class PhoneDialerImplementation : IPhoneDialer
7 | {
8 | public bool IsSupported =>
9 | MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString($"tel:0000000000")) != null);
10 |
11 | public void Open(string number)
12 | {
13 | ValidateOpen(number);
14 |
15 | var nsurl = NSUrl.FromString($"tel:{number}");
16 | NSWorkspace.SharedWorkspace.OpenUrl(nsurl);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/PhoneDialer/PhoneDialer.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.ApplicationModel.Communication
2 | {
3 | partial class PhoneDialerImplementation : IPhoneDialer
4 | {
5 | public bool IsSupported =>
6 | throw ExceptionUtils.NotSupportedOrImplementedException;
7 |
8 | public void Open(string number) =>
9 | throw ExceptionUtils.NotSupportedOrImplementedException;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/PhoneDialer/PhoneDialer.tizen.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Tizen.Applications;
3 |
4 | namespace Microsoft.Maui.ApplicationModel.Communication
5 | {
6 | partial class PhoneDialerImplementation : IPhoneDialer
7 | {
8 | public bool IsSupported
9 | => PlatformUtils.GetFeatureInfo("contact");
10 |
11 | public void Open(string number)
12 | {
13 | ValidateOpen(number);
14 |
15 | Permissions.EnsureDeclared();
16 |
17 | var appControl = new AppControl
18 | {
19 | Operation = AppControlOperations.Dial,
20 | Uri = "tel:",
21 | };
22 |
23 | if (!string.IsNullOrEmpty(number))
24 | appControl.Uri += number;
25 |
26 | AppControl.SendLaunchRequest(appControl);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/PhoneDialer/PhoneDialer.uwp.cs:
--------------------------------------------------------------------------------
1 | using Windows.ApplicationModel.Calls;
2 | using Windows.Foundation.Metadata;
3 |
4 | namespace Microsoft.Maui.ApplicationModel.Communication
5 | {
6 | partial class PhoneDialerImplementation : IPhoneDialer
7 | {
8 | public bool IsSupported =>
9 | true;
10 |
11 | public async void Open(string number)
12 | {
13 | ValidateOpen(number);
14 |
15 | if (ApiInformation.IsTypePresent("Windows.ApplicationModel.Calls.PhoneCallManager"))
16 | PhoneCallManager.ShowPhoneCallUI(number, string.Empty);
17 | else
18 | await Launcher.OpenAsync($"tel:{number}");
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Platform/PlatformUtils.uwp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Windows.Foundation;
5 |
6 | namespace Microsoft.Maui.ApplicationModel
7 | {
8 | static class PlatformUtils
9 | {
10 | internal const string AppManifestFilename = "AppxManifest.xml";
11 | internal const string AppManifestXmlns = "http://schemas.microsoft.com/appx/manifest/foundation/windows10";
12 | internal const string AppManifestUapXmlns = "http://schemas.microsoft.com/appx/manifest/uap/windows10";
13 |
14 | internal static void WatchForError(this IAsyncAction self) =>
15 | self.AsTask().WatchForError();
16 |
17 | internal static void WatchForError(this IAsyncOperation self) =>
18 | self.AsTask().WatchForError();
19 |
20 | internal static void WatchForError(this Task self)
21 | {
22 | var context = SynchronizationContext.Current;
23 | if (context == null)
24 | return;
25 |
26 | self.ContinueWith(
27 | t =>
28 | {
29 | var exception = t.Exception.InnerExceptions.Count > 1 ? t.Exception : t.Exception.InnerException;
30 |
31 | context.Post(e => { throw (Exception)e; }, exception);
32 | }, CancellationToken.None,
33 | TaskContinuationOptions.OnlyOnFaulted,
34 | TaskScheduler.Default);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Platform/UIPresentationControllerDelegate.ios.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UIKit;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | class UIPresentationControllerDelegate : UIAdaptivePresentationControllerDelegate
7 | {
8 | Action dismissHandler;
9 |
10 | internal UIPresentationControllerDelegate(Action dismissHandler)
11 | => this.dismissHandler = dismissHandler;
12 |
13 | public override void DidDismiss(UIPresentationController presentationController)
14 | {
15 | dismissHandler?.Invoke();
16 | dismissHandler = null;
17 | }
18 |
19 | protected override void Dispose(bool disposing)
20 | {
21 | dismissHandler?.Invoke();
22 | base.Dispose(disposing);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Platform/WindowMessageEventArgs.uwp.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 |
4 | namespace Microsoft.Maui.ApplicationModel
5 | {
6 | class WindowMessageEventArgs : EventArgs
7 | {
8 | public WindowMessageEventArgs(IntPtr hwnd, uint messageId, IntPtr wParam, IntPtr lParam)
9 | {
10 | Hwnd = hwnd;
11 | MessageId = messageId;
12 | WParam = wParam;
13 | LParam = lParam;
14 | }
15 |
16 | public IntPtr Hwnd { get; }
17 |
18 | public uint MessageId { get; }
19 |
20 | public IntPtr WParam { get; }
21 |
22 | public IntPtr LParam { get; }
23 |
24 | public IntPtr Result { get; set; }
25 |
26 | public bool Handled { get; set; }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Preferences/Preferences.netstandard.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 |
3 | namespace Microsoft.Maui.Storage
4 | {
5 | class PreferencesImplementation : IPreferences
6 | {
7 | public bool ContainsKey(string key, string sharedName) =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | public void Remove(string key, string sharedName) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | public void Clear(string sharedName) =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 |
16 | public void Set(string key, T value, string sharedName) =>
17 | throw ExceptionUtils.NotSupportedOrImplementedException;
18 |
19 | public T Get(string key, T defaultValue, string sharedName) =>
20 | throw ExceptionUtils.NotSupportedOrImplementedException;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Properties/AssemblyInfo.shared.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 |
3 | [assembly: InternalsVisibleTo("Microsoft.Maui")]
4 |
--------------------------------------------------------------------------------
/src/Resources/xml/microsoft_maui_essentials_fileprovider_file_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/Screenshot/Screenshot.netstandard.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 |
5 | namespace Microsoft.Maui.Media
6 | {
7 | partial class ScreenshotImplementation : IScreenshot
8 | {
9 | public bool IsCaptureSupported =>
10 | throw ExceptionUtils.NotSupportedOrImplementedException;
11 |
12 | public Task CaptureAsync() =>
13 | throw ExceptionUtils.NotSupportedOrImplementedException;
14 | }
15 |
16 | partial class ScreenshotResult
17 | {
18 | ScreenshotResult()
19 | {
20 | }
21 |
22 | Task PlatformOpenReadAsync(ScreenshotFormat format, int quality) =>
23 | throw ExceptionUtils.NotSupportedOrImplementedException;
24 |
25 | Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) =>
26 | throw ExceptionUtils.NotSupportedOrImplementedException;
27 |
28 | Task PlatformToPixelBufferAsync() =>
29 | throw ExceptionUtils.NotSupportedOrImplementedException;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Screenshot/Screenshot.tizen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.Threading.Tasks;
4 | using Microsoft.Maui.ApplicationModel;
5 | using NView = Tizen.NUI.BaseComponents.View;
6 | using Window = Tizen.NUI.Window;
7 |
8 | namespace Microsoft.Maui.Media
9 | {
10 | // TODO: Need to impl
11 | partial class ScreenshotImplementation : IPlatformScreenshot, IScreenshot
12 | {
13 | public bool IsCaptureSupported =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 |
16 | public Task CaptureAsync() =>
17 | throw ExceptionUtils.NotSupportedOrImplementedException;
18 |
19 | public Task CaptureAsync(Window window) =>
20 | throw ExceptionUtils.NotSupportedOrImplementedException;
21 |
22 | public Task CaptureAsync(NView view) =>
23 | throw ExceptionUtils.NotSupportedOrImplementedException;
24 | }
25 |
26 | partial class ScreenshotResult
27 | {
28 | ScreenshotResult()
29 | {
30 | }
31 |
32 | Task PlatformOpenReadAsync(ScreenshotFormat format, int quality) =>
33 | throw ExceptionUtils.NotSupportedOrImplementedException;
34 |
35 | Task PlatformCopyToAsync(Stream destination, ScreenshotFormat format, int quality) =>
36 | throw ExceptionUtils.NotSupportedOrImplementedException;
37 |
38 | Task PlatformToPixelBufferAsync() =>
39 | throw ExceptionUtils.NotSupportedOrImplementedException;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Screenshot/Screenshot.tvos.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.Threading.Tasks;
3 | using ObjCRuntime;
4 | using UIKit;
5 |
6 | namespace Microsoft.Maui.Media
7 | {
8 | partial class ScreenshotImplementation : IScreenshot
9 | {
10 | public bool PlatformIsCaptureSupported =>
11 | UIScreen.MainScreen != null;
12 |
13 | public Task CaptureAsync()
14 | {
15 | var img = UIScreen.MainScreen.Capture();
16 | var result = new ScreenshotResult(img);
17 |
18 | return Task.FromResult(result);
19 | }
20 | }
21 |
22 | partial class ScreenshotResult
23 | {
24 | readonly UIImage uiImage;
25 |
26 | internal ScreenshotResult(UIImage image)
27 | {
28 | uiImage = image;
29 |
30 | Width = (int)(image.Size.Width * image.CurrentScale);
31 | Height = (int)(image.Size.Height * image.CurrentScale);
32 | }
33 |
34 | internal Task PlatformOpenReadAsync(ScreenshotFormat format)
35 | {
36 | var data = format switch
37 | {
38 | ScreenshotFormat.Jpeg => uiImage.AsJPEG(),
39 | _ => uiImage.AsPNG()
40 | };
41 |
42 | return Task.FromResult(data.AsStream());
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/SecureStorage/SecureStorage.netstandard.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Microsoft.Maui.Storage
5 | {
6 | partial class SecureStorageImplementation : ISecureStorage
7 | {
8 | Task PlatformGetAsync(string key) =>
9 | throw ExceptionUtils.NotSupportedOrImplementedException;
10 |
11 | Task PlatformSetAsync(string key, string data) =>
12 | throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | bool PlatformRemove(string key) =>
15 | throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | void PlatformRemoveAll() =>
18 | throw ExceptionUtils.NotSupportedOrImplementedException;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/SemanticScreenReader/SemanticScreenReader.android.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Android.Views.Accessibility;
3 |
4 | namespace Microsoft.Maui.Accessibility
5 | {
6 | partial class SemanticScreenReaderImplementation : ISemanticScreenReader
7 | {
8 | public void Announce(string text)
9 | {
10 | var manager = Android.App.Application.Context.GetSystemService(Android.Content.Context.AccessibilityService) as AccessibilityManager;
11 | var announcement = OperatingSystem.IsAndroidVersionAtLeast(33)
12 | ? new AccessibilityEvent()
13 | #pragma warning disable 618
14 | : AccessibilityEvent.Obtain();
15 | #pragma warning restore 618
16 |
17 | if (manager == null || announcement == null)
18 | return;
19 |
20 | if (!(manager.IsEnabled || manager.IsTouchExplorationEnabled))
21 | return;
22 |
23 | announcement.EventType = EventTypes.Announcement;
24 | announcement.Text?.Add(new Java.Lang.String(text));
25 | manager.SendAccessibilityEvent(announcement);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/SemanticScreenReader/SemanticScreenReader.ios.cs:
--------------------------------------------------------------------------------
1 | using Foundation;
2 | using ObjCRuntime;
3 | using UIKit;
4 |
5 | namespace Microsoft.Maui.Accessibility
6 | {
7 | partial class SemanticScreenReaderImplementation : ISemanticScreenReader
8 | {
9 | public void Announce(string text)
10 | {
11 | if (!UIAccessibility.IsVoiceOverRunning)
12 | return;
13 |
14 | UIAccessibility.PostNotification(UIAccessibilityPostNotification.Announcement, new NSString(text));
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/SemanticScreenReader/SemanticScreenReader.netstandard.tvos.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using Microsoft.Maui.ApplicationModel;
5 |
6 | namespace Microsoft.Maui.Accessibility
7 | {
8 | partial class SemanticScreenReaderImplementation : ISemanticScreenReader
9 | {
10 | public void Announce(string text) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/SemanticScreenReader/SemanticScreenReader.tizen.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Accessibility
2 | {
3 | partial class SemanticScreenReaderImplementation : ISemanticScreenReader
4 | {
5 | public void Announce(string text)
6 | {
7 | Tizen.NUI.Accessibility.Accessibility.Say(text, true);
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Share/Share.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Microsoft.Maui.ApplicationModel.DataTransfer
4 | {
5 | partial class ShareImplementation : IShare
6 | {
7 | Task PlatformRequestAsync(ShareTextRequest request) =>
8 | throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | Task PlatformRequestAsync(ShareFileRequest request) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | Task PlatformRequestAsync(ShareMultipleFilesRequest request) =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Sms/Sms.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using System.Threading.Tasks;
4 | using AppKit;
5 | using Foundation;
6 |
7 | namespace Microsoft.Maui.ApplicationModel.Communication
8 | {
9 | partial class SmsImplementation : ISms
10 | {
11 | public bool IsComposeSupported =>
12 | MainThread.InvokeOnMainThread(() => NSWorkspace.SharedWorkspace.UrlForApplication(NSUrl.FromString("sms:")) != null);
13 |
14 | Task PlatformComposeAsync(SmsMessage message)
15 | {
16 | var recipients = string.Join(",", message.Recipients.Select(r => Uri.EscapeDataString(r)));
17 |
18 | var uri = $"sms:/open?addresses={recipients}";
19 |
20 | if (!string.IsNullOrEmpty(message?.Body))
21 | uri += "&body=" + Uri.EscapeDataString(message.Body);
22 |
23 | var nsurl = NSUrl.FromString(uri);
24 | NSWorkspace.SharedWorkspace.OpenUrl(nsurl);
25 | return Task.CompletedTask;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Sms/Sms.netstandard.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Microsoft.Maui.ApplicationModel.Communication
4 | {
5 | partial class SmsImplementation : ISms
6 | {
7 | public bool IsComposeSupported
8 | => throw ExceptionUtils.NotSupportedOrImplementedException;
9 |
10 | Task PlatformComposeAsync(SmsMessage message)
11 | => throw ExceptionUtils.NotSupportedOrImplementedException;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Sms/Sms.tizen.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Tizen.Applications;
4 |
5 | namespace Microsoft.Maui.ApplicationModel.Communication
6 | {
7 | partial class SmsImplementation : ISms
8 | {
9 | public bool IsComposeSupported
10 | => PlatformUtils.GetFeatureInfo("network.telephony.sms");
11 |
12 | Task PlatformComposeAsync(SmsMessage message)
13 | {
14 | Permissions.EnsureDeclared();
15 |
16 | var appControl = new AppControl
17 | {
18 | Operation = AppControlOperations.Compose,
19 | Uri = "sms:",
20 | };
21 |
22 | if (!string.IsNullOrEmpty(message.Body))
23 | appControl.ExtraData.Add(AppControlData.Text, message.Body);
24 | if (message.Recipients.Count > 0)
25 | appControl.Uri += string.Join(" ", message.Recipients);
26 |
27 | AppControl.SendLaunchRequest(appControl);
28 |
29 | return Task.CompletedTask;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Sms/Sms.uwp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Windows.ApplicationModel.Chat;
4 | using Windows.Foundation.Metadata;
5 |
6 | namespace Microsoft.Maui.ApplicationModel.Communication
7 | {
8 | partial class SmsImplementation : ISms
9 | {
10 | public bool IsComposeSupported
11 | => ApiInformation.IsTypePresent("Windows.ApplicationModel.Chat.ChatMessageManager");
12 |
13 | Task PlatformComposeAsync(SmsMessage message)
14 | {
15 | var chat = new ChatMessage();
16 | if (!string.IsNullOrWhiteSpace(message?.Body))
17 | chat.Body = message.Body;
18 |
19 | foreach (var recipient in message?.Recipients)
20 | chat.Recipients.Add(recipient);
21 |
22 | return ChatMessageManager.ShowComposeSmsMessageAsync(chat).AsTask();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/TextToSpeech/TextToSpeech.netstandard.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Threading;
3 | using System.Threading.Tasks;
4 | using Microsoft.Maui.ApplicationModel;
5 |
6 | namespace Microsoft.Maui.Media
7 | {
8 | partial class TextToSpeechImplementation : ITextToSpeech
9 | {
10 | Task PlatformSpeakAsync(string text, SpeechOptions options, CancellationToken cancelToken) =>
11 | throw ExceptionUtils.NotSupportedOrImplementedException;
12 |
13 | Task> PlatformGetLocalesAsync() =>
14 | throw ExceptionUtils.NotSupportedOrImplementedException;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Types/DisplayOrientation.shared.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Devices
2 | {
3 | ///
4 | /// Represents the orientation a device display can have.
5 | ///
6 | public enum DisplayOrientation
7 | {
8 | /// Unknown display orientation.
9 | Unknown = 0,
10 |
11 | /// Device display is in portrait orientation.
12 | Portrait = 1,
13 |
14 | /// Device display is in landscape orientation.
15 | Landscape = 2
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Types/DisplayRotation.shared.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Devices
2 | {
3 | ///
4 | /// Represents the rotation a device display can have.
5 | ///
6 | public enum DisplayRotation
7 | {
8 | /// Unknown display rotation.
9 | Unknown = 0,
10 |
11 | /// The device display is rotated 0 degrees.
12 | Rotation0 = 1,
13 |
14 | /// The device display is rotated 90 degrees.
15 | Rotation90 = 2,
16 |
17 | /// The device display is rotated 180 degrees.
18 | Rotation180 = 3,
19 |
20 | /// The device display is rotated 270 degrees.
21 | Rotation270 = 4
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Types/LocationExtensions.shared.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.Devices.Sensors;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | ///
8 | /// This class contains static extension methods for use with objects.
9 | ///
10 | public static partial class LocationExtensions
11 | {
12 | ///
13 | public static double CalculateDistance(this Location locationStart, double latitudeEnd, double longitudeEnd, DistanceUnits units) =>
14 | Location.CalculateDistance(locationStart, latitudeEnd, longitudeEnd, units);
15 |
16 | ///
17 | public static double CalculateDistance(this Location locationStart, Location locationEnd, DistanceUnits units) =>
18 | Location.CalculateDistance(locationStart, locationEnd, units);
19 |
20 | ///
21 | public static Task OpenMapsAsync(this Location location, MapLaunchOptions options) =>
22 | Map.OpenAsync(location, options);
23 |
24 | ///
25 | public static Task OpenMapsAsync(this Location location) =>
26 | Map.OpenAsync(location);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Types/PlacemarkExtensions.android.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | using AndroidAddress = Android.Locations.Address;
5 |
6 | namespace Microsoft.Maui.Devices.Sensors
7 | {
8 | static partial class PlacemarkExtensions
9 | {
10 | internal static IEnumerable ToPlacemarks(this IEnumerable addresses)
11 | {
12 | return addresses.Select(address => new Placemark
13 | {
14 | Location = address.ToLocation(),
15 | FeatureName = address.FeatureName,
16 | PostalCode = address.PostalCode,
17 | SubLocality = address.SubLocality,
18 | CountryCode = address.CountryCode,
19 | CountryName = address.CountryName,
20 | Thoroughfare = address.Thoroughfare,
21 | SubThoroughfare = address.SubThoroughfare,
22 | Locality = address.Locality,
23 | AdminArea = address.AdminArea,
24 | SubAdminArea = address.SubAdminArea
25 | });
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Types/PlacemarkExtensions.ios.tvos.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using CoreLocation;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | static partial class PlacemarkExtensions
8 | {
9 | internal static IEnumerable ToPlacemarks(this IEnumerable addresses)
10 | {
11 | return addresses.Select(address => new Placemark
12 | {
13 | Location = address.ToLocation(),
14 | FeatureName = address.Name,
15 | PostalCode = address.PostalCode,
16 | SubLocality = address.SubLocality,
17 | CountryCode = address.IsoCountryCode,
18 | CountryName = address.Country,
19 | Thoroughfare = address.Thoroughfare,
20 | SubThoroughfare = address.SubThoroughfare,
21 | Locality = address.Locality,
22 | AdminArea = address.AdministrativeArea,
23 | SubAdminArea = address.SubAdministrativeArea
24 | });
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Types/PlacemarkExtensions.shared.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | ///
8 | /// This class contains static extension methods for use with objects.
9 | ///
10 | public static partial class PlacemarkExtensions
11 | {
12 | ///
13 | public static Task OpenMapsAsync(this Placemark placemark, MapLaunchOptions options) =>
14 | Map.OpenAsync(placemark, options);
15 |
16 | ///
17 | public static Task OpenMapsAsync(this Placemark placemark) =>
18 | Map.OpenAsync(placemark);
19 |
20 | internal static string GetEscapedAddress(this Placemark placemark)
21 | {
22 | if (placemark == null)
23 | throw new ArgumentNullException(nameof(placemark));
24 |
25 | var address = $"{placemark.Thoroughfare} {placemark.Locality} {placemark.AdminArea} {placemark.PostalCode} {placemark.CountryName}";
26 |
27 | return Uri.EscapeDataString(address);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Types/PlacemarkExtensions.uwp.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Windows.Services.Maps;
4 |
5 | namespace Microsoft.Maui.Devices.Sensors
6 | {
7 | static partial class LocationExtensions
8 | {
9 | internal static IEnumerable ToPlacemarks(this IEnumerable mapLocations)
10 | {
11 | return mapLocations.Select(address => new Placemark
12 | {
13 | Location = address.ToLocation(),
14 | FeatureName = address.DisplayName,
15 | PostalCode = address.Address.PostCode,
16 | CountryCode = address.Address.CountryCode,
17 | CountryName = address.Address.Country,
18 | Thoroughfare = address.Address.Street,
19 | SubThoroughfare = address.Address.StreetNumber,
20 | Locality = address.Address.Town,
21 | AdminArea = address.Address.Region,
22 | SubAdminArea = address.Address.District,
23 | SubLocality = address.Address.Neighborhood
24 | });
25 | }
26 |
27 | internal static IEnumerable ToPlacemarks(this MapLocationFinderResult result) =>
28 | result?.ToPlacemarks();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Types/SensorSpeed.android.cs:
--------------------------------------------------------------------------------
1 | using Android.Hardware;
2 |
3 | namespace Microsoft.Maui.Devices.Sensors
4 | {
5 | internal static partial class SensorSpeedExtensions
6 | {
7 | internal static SensorDelay ToPlatform(this SensorSpeed sensorSpeed)
8 | {
9 | switch (sensorSpeed)
10 | {
11 | case SensorSpeed.Fastest:
12 | return SensorDelay.Fastest;
13 | case SensorSpeed.Game:
14 | return SensorDelay.Game;
15 | case SensorSpeed.UI:
16 | return SensorDelay.Ui;
17 | }
18 |
19 | return SensorDelay.Normal;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Types/SensorSpeed.ios.tvos.watchos.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Devices.Sensors
2 | {
3 | internal static partial class SensorSpeedExtensions
4 | {
5 | internal static double ToPlatform(this SensorSpeed sensorSpeed)
6 | {
7 | switch (sensorSpeed)
8 | {
9 | case SensorSpeed.Fastest:
10 | return sensorIntervalFastest / 1000.0;
11 | case SensorSpeed.Game:
12 | return sensorIntervalGame / 1000.0;
13 | case SensorSpeed.UI:
14 | return sensorIntervalUI / 1000.0;
15 | }
16 |
17 | return sensorIntervalDefault / 1000.0;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Types/SensorSpeed.shared.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Devices.Sensors
2 | {
3 | ///
4 | /// Represents the sensor speed to monitor device sensors for changes.
5 | ///
6 | public enum SensorSpeed
7 | {
8 | /// The device default sensor speed.
9 | Default = 0,
10 |
11 | /// Rate suitable for general user interface.
12 | UI = 1,
13 |
14 | /// Rate suitable for games.
15 | Game = 2,
16 |
17 | /// Get the sensor data as fast as possible.
18 | Fastest = 3,
19 | }
20 |
21 | internal static partial class SensorSpeedExtensions
22 | {
23 | // Timing intervals to match Android sensor speeds in milliseconds
24 | // https://developer.android.com/guide/topics/sensors/sensors_overview
25 | internal const uint sensorIntervalDefault = 200;
26 | internal const uint sensorIntervalUI = 60;
27 | internal const uint sensorIntervalGame = 20;
28 | internal const uint sensorIntervalFastest = 5;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Types/SensorSpeed.tizen.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Devices.Sensors
2 | {
3 | internal static partial class SensorSpeedExtensions
4 | {
5 | internal static uint ToPlatform(this SensorSpeed sensorSpeed)
6 | {
7 | switch (sensorSpeed)
8 | {
9 | case SensorSpeed.Fastest:
10 | return sensorIntervalFastest;
11 | case SensorSpeed.Game:
12 | return sensorIntervalGame;
13 | case SensorSpeed.UI:
14 | return sensorIntervalUI;
15 | }
16 |
17 | return sensorIntervalDefault;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Types/SensorSpeed.uwp.cs:
--------------------------------------------------------------------------------
1 | namespace Microsoft.Maui.Devices.Sensors
2 | {
3 | internal static partial class SensorSpeedExtensions
4 | {
5 | internal static uint ToPlatform(this SensorSpeed sensorSpeed)
6 | {
7 | switch (sensorSpeed)
8 | {
9 | case SensorSpeed.Fastest:
10 | return sensorIntervalFastest;
11 | case SensorSpeed.Game:
12 | return sensorIntervalGame;
13 | case SensorSpeed.UI:
14 | return sensorIntervalUI;
15 | }
16 |
17 | return sensorIntervalDefault;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Types/Shared/Utils.shared.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 |
6 | namespace Microsoft.Maui.ApplicationModel
7 | {
8 | static class Utils
9 | {
10 | internal static Version ParseVersion(string version)
11 | {
12 | if (Version.TryParse(version, out var number))
13 | return number;
14 |
15 | if (int.TryParse(version, out var major))
16 | return new Version(major, 0);
17 |
18 | return new Version(0, 0);
19 | }
20 |
21 | internal static CancellationToken TimeoutToken(CancellationToken cancellationToken, TimeSpan timeout)
22 | {
23 | // create a new linked cancellation token source
24 | var cancelTokenSrc = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
25 |
26 | // if a timeout was given, make the token source cancel after it expires
27 | if (timeout > TimeSpan.Zero)
28 | cancelTokenSrc.CancelAfter(timeout);
29 |
30 | // our Cancel method will handle the actual cancellation logic
31 | return cancelTokenSrc.Token;
32 | }
33 |
34 | internal static async Task WithTimeout(Task task, TimeSpan timeSpan)
35 | {
36 | var retTask = await Task.WhenAny(task, Task.Delay(timeSpan))
37 | .ConfigureAwait(false);
38 |
39 | return retTask is Task ? task.Result : default(T);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Vibration/Vibration.ios.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using AudioToolbox;
3 |
4 | namespace Microsoft.Maui.Devices
5 | {
6 | partial class VibrationImplementation : IVibration
7 | {
8 | public bool IsSupported => true;
9 |
10 | void PlatformVibrate() =>
11 | SystemSound.Vibrate.PlaySystemSound();
12 |
13 | void PlatformVibrate(TimeSpan duration) =>
14 | SystemSound.Vibrate.PlaySystemSound();
15 |
16 | void PlatformCancel()
17 | {
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Vibration/Vibration.netstandard.tvos.watchos.macos.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Microsoft.Maui.Devices
5 | {
6 | partial class VibrationImplementation : IVibration
7 | {
8 | public bool IsSupported
9 | => throw ExceptionUtils.NotSupportedOrImplementedException;
10 |
11 | void PlatformVibrate()
12 | => throw ExceptionUtils.NotSupportedOrImplementedException;
13 |
14 | void PlatformVibrate(TimeSpan duration)
15 | => throw ExceptionUtils.NotSupportedOrImplementedException;
16 |
17 | void PlatformCancel()
18 | => throw ExceptionUtils.NotSupportedOrImplementedException;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Vibration/Vibration.tizen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 | using Microsoft.Maui.ApplicationModel;
4 | using Tizen.System;
5 |
6 | namespace Microsoft.Maui.Devices
7 | {
8 | partial class VibrationImplementation : IVibration
9 | {
10 | public bool IsSupported
11 | => Vibrator.NumberOfVibrators > 0;
12 |
13 | void PlatformVibrate()
14 | => Vibrate(TimeSpan.FromMilliseconds(500));
15 |
16 | void PlatformVibrate(TimeSpan duration)
17 | {
18 | Permissions.EnsureDeclared();
19 |
20 | Vibrator.Vibrators.FirstOrDefault()?.Vibrate((int)duration.TotalMilliseconds, 100);
21 | }
22 |
23 | void PlatformCancel()
24 | {
25 | Permissions.EnsureDeclared();
26 |
27 | Vibrator.Vibrators.FirstOrDefault()?.Stop();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Vibration/Vibration.uwp.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Windows.Devices.Haptics;
3 | using Windows.Foundation.Metadata;
4 |
5 | namespace Microsoft.Maui.Devices
6 | {
7 | partial class VibrationImplementation : IVibration
8 | {
9 | public bool IsSupported
10 | => ApiInformation.IsTypePresent("Windows.Phone.Devices.Notification.VibrationDevice") && DefaultDevice != null;
11 |
12 | static VibrationDevice DefaultDevice =>
13 | throw new NotImplementedException("WINUI"); //VibrationDevice.GetDefault();
14 |
15 | void PlatformVibrate()
16 | => throw new NotImplementedException("WINUI");// DefaultDevice.Vibrate(duration);
17 |
18 | void PlatformVibrate(TimeSpan duration) =>
19 | throw new NotImplementedException("WINUI");// DefaultDevice.Vibrate(duration);
20 |
21 | void PlatformCancel() =>
22 | throw new NotImplementedException("WINUI");//DefaultDevice.Cancel();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/WebAuthenticator/AppleSignInAuthenticator.netstandard.android.tvos.watchos.uwp.tizen.macos.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 |
4 | namespace Microsoft.Maui.Authentication
5 | {
6 | partial class AppleSignInAuthenticatorImplementation : IAppleSignInAuthenticator
7 | {
8 | public Task AuthenticateAsync(AppleSignInAuthenticator.Options options) =>
9 | throw ExceptionUtils.NotSupportedOrImplementedException;
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/WebAuthenticator/WebAuthenticator.netstandard.watchos.tizen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using System.Threading.Tasks;
5 | using Microsoft.Maui.ApplicationModel;
6 |
7 | namespace Microsoft.Maui.Authentication
8 | {
9 | partial class WebAuthenticatorImplementation : IWebAuthenticator
10 | {
11 | public Task AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions)
12 | => throw ExceptionUtils.NotSupportedOrImplementedException;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/WebAuthenticator/WebAuthenticatorCallbackActivity.android.cs:
--------------------------------------------------------------------------------
1 | using Android.App;
2 | using Android.Content;
3 | using Android.OS;
4 |
5 | namespace Microsoft.Maui.Authentication
6 | {
7 | public abstract class WebAuthenticatorCallbackActivity : Activity
8 | {
9 | protected override void OnCreate(Bundle savedInstanceState)
10 | {
11 | base.OnCreate(savedInstanceState);
12 |
13 | // start the intermediate activity again with flags to close the custom tabs
14 | var intent = new Intent(this, typeof(WebAuthenticatorIntermediateActivity));
15 | intent.SetData(Intent.Data);
16 | intent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);
17 | StartActivity(intent);
18 |
19 | // finish this activity
20 | Finish();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/WinRTEmbed.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | true
14 | true
15 | 10.0.19041.0
16 |
17 | Windows.Foundation;
18 | Windows.Devices.Sensors.AccelerometerReadingChangedEventArgs;
19 | Windows.Devices.Sensors.Accelerometer;
20 | Windows.Devices.Sensors.IAccelerometerDataThreshold;
21 | Windows.Devices.Sensors.IAccelerometer;
22 | Windows.Devices.Sensors.IAccelerometerReading;
23 | Windows.Devices.Sensors.IAccelerometerReadingChangedEventArgs;
24 | Windows.Devices.Sensors.IAccelerometerShakenEventArgs;
25 | Windows.Graphics.Display.DisplayOrientations;
26 |
27 |
28 | Windows.Foundation.Diagnostics;
29 | Windows.Foundation.PropertyType;
30 | Windows.Storage.BulkAccess;
31 | Windows.Web.UI;
32 |
33 |
34 |
--------------------------------------------------------------------------------
/test/DeviceTests/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/test/DeviceTests/Platforms/Android/environment.txt:
--------------------------------------------------------------------------------
1 | MONO_THREADS_SUSPEND=preemptive
--------------------------------------------------------------------------------
/test/DeviceTests/Platforms/MacCatalyst/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UIDeviceFamily
6 |
7 | 1
8 | 2
9 |
10 | UIRequiredDeviceCapabilities
11 |
12 | arm64
13 |
14 | UISupportedInterfaceOrientations
15 |
16 | UIInterfaceOrientationPortrait
17 | UIInterfaceOrientationLandscapeLeft
18 | UIInterfaceOrientationLandscapeRight
19 |
20 | UISupportedInterfaceOrientations~ipad
21 |
22 | UIInterfaceOrientationPortrait
23 | UIInterfaceOrientationPortraitUpsideDown
24 | UIInterfaceOrientationLandscapeLeft
25 | UIInterfaceOrientationLandscapeRight
26 |
27 | XSAppIconAssets
28 | Assets.xcassets/appicon.appiconset
29 |
30 |
31 |
--------------------------------------------------------------------------------
/test/DeviceTests/Platforms/Windows/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/test/DeviceTests/Platforms/Windows/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui;
2 | using Microsoft.Maui.Hosting;
3 | using Microsoft.UI.Xaml;
4 | using Windows.ApplicationModel;
5 |
6 | // To learn more about WinUI, the WinUI project structure,
7 | // and more about our project templates, see: http://aka.ms/winui-project-info.
8 |
9 | namespace Microsoft.Maui.Essentials.DeviceTests.WinUI
10 | {
11 | ///
12 | /// Provides application-specific behavior to supplement the default Application class.
13 | ///
14 | public partial class App : MiddleApp
15 | {
16 | ///
17 | /// Initializes the singleton application object. This is the first line of authored code
18 | /// executed, and as such is the logical equivalent of main() or WinMain().
19 | ///
20 | public App()
21 | {
22 | this.InitializeComponent();
23 | }
24 | }
25 |
26 | public class MiddleApp : MauiWinUIApplication
27 | {
28 | protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/test/DeviceTests/Platforms/Windows/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 | true/PM
12 | PerMonitorV2, PerMonitor
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/test/DeviceTests/Platforms/iOS/Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | keychain-access-groups
6 |
7 | $(AppIdentifierPrefix)$(CFBundleIdentifier)
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/DeviceTests/Platforms/iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | LSRequiresIPhoneOS
6 |
7 | UIDeviceFamily
8 |
9 | 1
10 | 2
11 |
12 | UIRequiredDeviceCapabilities
13 |
14 | arm64
15 |
16 | UISupportedInterfaceOrientations
17 |
18 | UIInterfaceOrientationPortrait
19 | UIInterfaceOrientationLandscapeLeft
20 | UIInterfaceOrientationLandscapeRight
21 |
22 | UISupportedInterfaceOrientations~ipad
23 |
24 | UIInterfaceOrientationPortrait
25 | UIInterfaceOrientationPortraitUpsideDown
26 | UIInterfaceOrientationLandscapeLeft
27 | UIInterfaceOrientationLandscapeRight
28 |
29 | XSAppIconAssets
30 | Assets.xcassets/appicon.appiconset
31 | NSLocationWhenInUseUsageDescription
32 | Access to your location is required for cool things to happen!
33 | NSContactsUsageDescription
34 | Contacts
35 |
36 |
37 |
--------------------------------------------------------------------------------
/test/DeviceTests/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Windows Machine": {
4 | "commandName": "MsixPackage"
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/test/DeviceTests/Resources/Raw/AppBundleFile.txt:
--------------------------------------------------------------------------------
1 | This file was in the app bundle.
--------------------------------------------------------------------------------
/test/DeviceTests/Resources/Raw/AppBundleFile_NoExtension:
--------------------------------------------------------------------------------
1 | This file was in the app bundle.
--------------------------------------------------------------------------------
/test/DeviceTests/Resources/Raw/Folder/AppBundleFile_Nested.txt:
--------------------------------------------------------------------------------
1 | This file was in the app bundle.
--------------------------------------------------------------------------------
/test/DeviceTests/Resources/appicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/AppActions_Tests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Microsoft.Maui.ApplicationModel;
5 | using Xunit;
6 |
7 | namespace Microsoft.Maui.Essentials.DeviceTests
8 | {
9 | [Category("AppActions")]
10 | public class AppActions_Tests
11 | {
12 | [Fact]
13 | public void IsSupported()
14 | {
15 | var expectSupported = false;
16 |
17 | #if __ANDROID__
18 | expectSupported = OperatingSystem.IsAndroidVersionAtLeast(25);
19 | #elif __IOS__
20 | expectSupported = true;
21 | #endif
22 |
23 | Assert.Equal(expectSupported, AppActions.IsSupported);
24 | }
25 |
26 | [Fact]
27 | public async Task GetSetItems()
28 | {
29 | if (!AppActions.IsSupported)
30 | return;
31 |
32 | var actions = new List
33 | {
34 | new AppAction("TEST1", "Test 1", "This is a test", "myapp://test1"),
35 | new AppAction("TEST2", "Test 2", "This is a test 2", "myapp://test2"),
36 | };
37 |
38 | await AppActions.SetAsync(actions);
39 |
40 | var get = await AppActions.GetAsync();
41 |
42 | Assert.Contains(get, a => a.Id == "TEST1");
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/Clipboard_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel.DataTransfer;
3 | using Xunit;
4 |
5 | namespace Microsoft.Maui.Essentials.DeviceTests
6 | {
7 | [Category("Clipboard")]
8 | public class Clipboard_Tests
9 | {
10 | [Theory]
11 | [InlineData("text")]
12 | [InlineData("some really long test text")]
13 | [Trait(Traits.UI, Traits.FeatureSupport.Supported)]
14 | public Task Set_Clipboard_Values(string text)
15 | {
16 | return Utils.OnMainThread(async () =>
17 | {
18 | await Clipboard.SetTextAsync(text);
19 | Assert.True(Clipboard.HasText);
20 | });
21 | }
22 |
23 | [Theory]
24 | [InlineData("text")]
25 | [InlineData("some really long test text")]
26 | [Trait(Traits.UI, Traits.FeatureSupport.Supported)]
27 | public Task Get_Clipboard_Values(string text)
28 | {
29 | return Utils.OnMainThread(async () =>
30 | {
31 | await Clipboard.SetTextAsync(text);
32 | var clipText = await Clipboard.GetTextAsync();
33 |
34 | Assert.NotNull(clipText);
35 | Assert.Equal(text, clipText);
36 | });
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/Connectivity_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.Networking;
4 | using Xunit;
5 |
6 | namespace Microsoft.Maui.Essentials.DeviceTests
7 | {
8 | [Category("Connectivity")]
9 | public class Connectivity_Tests
10 | {
11 | [Fact]
12 | public void Network_Access() =>
13 | Assert.Equal(NetworkAccess.Internet, Connectivity.NetworkAccess);
14 |
15 | [Fact]
16 | public void Connection_Profiles() =>
17 | Assert.True(Connectivity.ConnectionProfiles.Count() > 0);
18 |
19 | [Fact]
20 | public void Distict_Connection_Profiles()
21 | {
22 | var profiles = Connectivity.ConnectionProfiles;
23 | Assert.Equal(profiles.Count(), profiles.Distinct().Count());
24 | }
25 |
26 | [Fact]
27 | public async Task Test()
28 | {
29 | var current = Connectivity.Current.NetworkAccess;
30 |
31 | var thread = await Task.Run(() => Connectivity.Current.NetworkAccess);
32 |
33 | Assert.Equal(current, thread);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/Contacts_Tests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading.Tasks;
5 | using Microsoft.Maui.ApplicationModel;
6 | using Microsoft.Maui.ApplicationModel.Communication;
7 | using Xunit;
8 |
9 | namespace Microsoft.Maui.Essentials.DeviceTests.Shared
10 | {
11 | using Contacts = ApplicationModel.Communication.Contacts;
12 |
13 | [Category("Contacts")]
14 | public class Contacts_Tests
15 | {
16 | [Fact]
17 | [Trait(Traits.InteractionType, Traits.InteractionTypes.Human)]
18 | public async Task GetAll()
19 | {
20 | await MainThread.InvokeOnMainThreadAsync(async () =>
21 | {
22 | await Permissions.RequestAsync();
23 | });
24 |
25 | var list = new List();
26 | var contacts = await Contacts.GetAllAsync();
27 |
28 | foreach (var contact in contacts.Take(10))
29 | list?.Add(contact);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/Flashlight_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.Devices;
3 | using Xunit;
4 |
5 | namespace Microsoft.Maui.Essentials.DeviceTests
6 | {
7 | // TEST NOTES:
8 | // - a human needs to accept permissions on Android
9 | // - the camera flash is not always available
10 | [Category("Flashlight")]
11 | public class Flashlight_Tests
12 | {
13 | [Theory]
14 | [InlineData(true)]
15 | [InlineData(false)]
16 | #if __ANDROID__
17 | [Trait(Traits.InteractionType, Traits.InteractionTypes.Human)]
18 | #endif
19 | [Trait(Traits.Hardware.Flash, Traits.FeatureSupport.Supported)]
20 | public Task Turn_On_Off(bool oldCameraApi)
21 | {
22 | // TODO: the test runner app (UI version) should do this, until then...
23 | if (!HardwareSupport.HasFlash)
24 | return Task.CompletedTask;
25 |
26 | #if __ANDROID__
27 | (Flashlight.Default as FlashlightImplementation).AlwaysUseCameraApi = oldCameraApi;
28 | #else
29 | Utils.Unused(oldCameraApi);
30 | #endif
31 |
32 | return Utils.OnMainThread(async () =>
33 | {
34 | await Flashlight.TurnOnAsync();
35 | await Flashlight.TurnOffAsync();
36 | });
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/HapticFeedback_Tests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Maui.Devices;
3 | using Xunit;
4 |
5 | namespace Microsoft.Maui.Essentials.DeviceTests
6 | {
7 | [Category("HapticFeedback")]
8 | public class HapticFeedback_Tests
9 | {
10 | [Fact]
11 | public void Click() => HapticFeedback.Perform(HapticFeedbackType.Click);
12 |
13 | [Fact]
14 | public void LongPress() => HapticFeedback.Perform(HapticFeedbackType.LongPress);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/MainThread_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Xunit;
4 |
5 | namespace Microsoft.Maui.Essentials.DeviceTests
6 | {
7 | [Category("MainThread")]
8 | public class MainThread_Tests
9 | {
10 | [Fact]
11 | public Task IsOnMainThread()
12 | {
13 | return Utils.OnMainThread(() =>
14 | {
15 | Assert.True(MainThread.IsMainThread);
16 | });
17 | }
18 |
19 | [Fact]
20 | public Task IsNotOnMainThread()
21 | {
22 | return Task.Run(() =>
23 | {
24 | Assert.False(MainThread.IsMainThread);
25 | });
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/PhoneDialer_Tests.cs:
--------------------------------------------------------------------------------
1 | using Xunit;
2 |
3 | namespace Microsoft.Maui.Essentials.DeviceTests
4 | {
5 | [Category("PhoneDialer")]
6 | public class PhoneDialer_Tests
7 | {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/WindowStateManager_Tests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.Maui.ApplicationModel;
7 | using Microsoft.Maui.Authentication;
8 | using Xunit;
9 |
10 | namespace Microsoft.Maui.Essentials.DeviceTests
11 | {
12 | [Category("WindowStateManager")]
13 | public class WindowStateManager_Tests
14 | {
15 | #if __IOS__
16 | [Fact]
17 | [Trait(Traits.InteractionType, Traits.InteractionTypes.Machine)]
18 | public void GetCurrentUIWindow()
19 | {
20 | var window = WindowStateManager.Default.GetCurrentUIWindow();
21 | Assert.NotNull(window);
22 | }
23 |
24 | [Fact]
25 | [Trait(Traits.InteractionType, Traits.InteractionTypes.Machine)]
26 | public void GetCurrentUIViewController()
27 | {
28 | var viewController = WindowStateManager.Default.GetCurrentUIViewController();
29 | Assert.NotNull(viewController);
30 | }
31 | #endif
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/test/DeviceTests/Tests/Windows/BaseWindowMessageManager_Tests.cs:
--------------------------------------------------------------------------------
1 | #nullable enable
2 | using System;
3 | using System.Runtime.InteropServices;
4 | using System.Threading.Tasks;
5 | using Microsoft.Maui.Platform;
6 |
7 | namespace Microsoft.Maui.Essentials.DeviceTests.Shared
8 | {
9 | public abstract class BaseWindowMessageManager_Tests
10 | {
11 | protected const uint WM_APP = 0x8000;
12 | protected const uint TEST_MESSAGE = WM_APP + 1;
13 |
14 | [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
15 | [return: MarshalAs(UnmanagedType.Bool)]
16 | protected static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
17 |
18 | protected async Task PostTestMessageAsync(UI.Xaml.Window window)
19 | {
20 | var handle = window.GetWindowHandle();
21 |
22 | PostMessage(handle, TEST_MESSAGE, IntPtr.Zero, IntPtr.Zero);
23 |
24 | await Task.Delay(100);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/test/DeviceTests/Utils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 |
5 | namespace Microsoft.Maui.Essentials.DeviceTests
6 | {
7 | public class Utils
8 | {
9 | public static void Unused(params object[] obj) { }
10 |
11 | public static Task OnMainThread(Action action) =>
12 | MainThread.InvokeOnMainThreadAsync(() => action());
13 |
14 | public static Task OnMainThread(Func action) =>
15 | MainThread.InvokeOnMainThreadAsync(() => action());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/test/UnitTests/AppActions_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Xunit;
4 |
5 | namespace Tests
6 | {
7 | public class AppActions_Tests
8 | {
9 | [Fact]
10 | public void AppActions_SetActions() =>
11 | Assert.ThrowsAsync(() => AppActions.SetAsync(new List()));
12 |
13 | [Fact]
14 | public void AppActions_GetActions() =>
15 | Assert.ThrowsAsync(() => AppActions.GetAsync());
16 |
17 | [Fact]
18 | public void AppActions_IsSupported() =>
19 | Assert.Throws(() => AppActions.IsSupported);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/test/UnitTests/Battery_Tests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Microsoft.Maui.Devices;
3 | using Xunit;
4 |
5 | namespace Tests
6 | {
7 | public class Battery_Tests
8 | {
9 | [Fact]
10 | public void Charge_Level_On_NetStandard() =>
11 | Assert.Throws(() => Battery.ChargeLevel);
12 |
13 | [Fact]
14 | public void Charge_State_On_NetStandard() =>
15 | Assert.Throws(() => Battery.State);
16 |
17 | [Fact]
18 | public void Charge_Power_Source_On_NetStandard() =>
19 | Assert.Throws(() => Battery.PowerSource);
20 |
21 | [Fact]
22 | public void Battery_Changed_Event_On_NetStandard() =>
23 | Assert.Throws(() => Battery.BatteryInfoChanged += Battery_BatteryInfoChanged);
24 |
25 | void Battery_BatteryInfoChanged(object sender, BatteryInfoChangedEventArgs e)
26 | {
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/test/UnitTests/Clipboard_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.ApplicationModel.DataTransfer;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class Clipboard_Tests
9 | {
10 | [Fact]
11 | public async Task Clipboard_SetText_Fail_On_NetStandard() =>
12 | await Assert.ThrowsAsync(() => Clipboard.SetTextAsync("Text"));
13 |
14 | [Fact]
15 | public void Clipboard_HasText_Fail_On_NetStandard() =>
16 | Assert.Throws(() => Clipboard.HasText);
17 |
18 | [Fact]
19 | public async Task Clipboard_GetText_Fail_On_NetStandard() =>
20 | await Assert.ThrowsAsync(() => Clipboard.GetTextAsync());
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test/UnitTests/Connectivity_Tests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Microsoft.Maui.Networking;
3 | using Xunit;
4 |
5 | namespace Tests
6 | {
7 | public class Connectivity_Tests
8 | {
9 | [Fact]
10 | public void Network_Access_On_NetStandard() =>
11 | Assert.Throws(() => Connectivity.NetworkAccess);
12 |
13 | [Fact]
14 | public void ConnectionProfiles_On_NetStandard() =>
15 | Assert.Throws(() => Connectivity.ConnectionProfiles);
16 |
17 | [Fact]
18 | public void Connectivity_Changed_Event_On_NetStandard() =>
19 | Assert.Throws(() => Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged);
20 |
21 | void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
22 | {
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/test/UnitTests/Contacts_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.ApplicationModel.Communication;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class Contacts_Tests
9 | {
10 | [Fact]
11 | public async Task Contacts_GetAll() =>
12 | await Assert.ThrowsAsync(() => Contacts.GetAllAsync());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/test/UnitTests/Essentials.UnitTests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(_MauiDotNetTfm)
5 | false
6 | Microsoft.Maui.Essentials.UnitTests
7 | portable
8 | Debug;Release
9 |
10 |
11 |
12 | true
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/test/UnitTests/FilePicker_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.Storage;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class FilePicker_Tests
9 | {
10 | [Fact]
11 | public async Task PickAsync_Fail_On_NetStandard()
12 | {
13 | await Assert.ThrowsAsync(() => FilePicker.PickAsync());
14 | }
15 |
16 | [Fact]
17 | public async Task PickMultipleAsync_Fail_On_NetStandard()
18 | {
19 | await Assert.ThrowsAsync(() => FilePicker.PickMultipleAsync());
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test/UnitTests/FileSystem_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.Storage;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class FileSystem_Tests
9 | {
10 | [Fact]
11 | public void FileSystem_Fail_On_NetStandard()
12 | {
13 | Assert.Throws(() => FileSystem.AppDataDirectory);
14 | }
15 |
16 | [Fact]
17 | public async Task OpenAppPackageFileAsync_Fail_On_NetStandard()
18 | {
19 | await Assert.ThrowsAsync(() => FileSystem.OpenAppPackageFileAsync("filename.txt"));
20 | }
21 |
22 | [Theory]
23 | [InlineData(null, "")]
24 | [InlineData("", "")]
25 | [InlineData(".", ".")]
26 | [InlineData(".txt", ".txt")]
27 | [InlineData("*.txt", ".txt")]
28 | [InlineData("*.*", ".*")]
29 | [InlineData("txt", ".txt")]
30 | [InlineData("test.txt", ".test.txt")]
31 | [InlineData("test.", ".test.")]
32 | [InlineData("....txt", ".txt")]
33 | [InlineData("******txt", ".txt")]
34 | [InlineData("******.txt", ".txt")]
35 | [InlineData("******.......txt", ".txt")]
36 | public void Extensions_Clean_Correctly_Cleans_Extensions(string input, string output)
37 | {
38 | var cleaned = FileExtensions.Clean(input);
39 |
40 | Assert.Equal(output, cleaned);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/test/UnitTests/Geocoding_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.Devices.Sensors;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class Geocoding_Tests
9 | {
10 | [Fact]
11 | public async Task Geocoding_Placemarks_Fail_On_NetStandard()
12 | {
13 | await Assert.ThrowsAsync(() => Geocoding.GetPlacemarksAsync(1, 1));
14 | }
15 |
16 | [Fact]
17 | public async Task Geocoding_Placemarks_Location_Fail_On_NetStandard()
18 | {
19 | await Assert.ThrowsAsync(() => Geocoding.GetPlacemarksAsync(new Location(1, 1)));
20 | }
21 |
22 | [Fact]
23 | public async Task Geocoding_Locations_On_NetStandard()
24 | {
25 | await Assert.ThrowsAsync(() => Geocoding.GetLocationsAsync("Microsoft Building 25"));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/test/UnitTests/Launcher_Tests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class Launcher_Tests
9 | {
10 | [Fact]
11 | public async Task CanOpen_String_NetStandard() =>
12 | await Assert.ThrowsAsync(() => Launcher.CanOpenAsync("http://www.xamarin.com"));
13 |
14 | [Fact]
15 | public async Task CanOpen_Uri_NetStandard() =>
16 | await Assert.ThrowsAsync(() => Launcher.CanOpenAsync(new Uri("http://www.xamarin.com")));
17 |
18 | [Fact]
19 | public async Task Open_String_NetStandard() =>
20 | await Assert.ThrowsAsync(() => Launcher.OpenAsync("http://www.xamarin.com"));
21 |
22 | [Fact]
23 | public async Task Open_Uri_NetStandard() =>
24 | await Assert.ThrowsAsync(() => Launcher.OpenAsync(new Uri("http://www.xamarin.com")));
25 |
26 | [Fact]
27 | public async Task Open_File_NetStandard() =>
28 | await Assert.ThrowsAsync(() => Launcher.OpenAsync(new OpenFileRequest()));
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/test/UnitTests/PhoneDialer_Tests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Microsoft.Maui.ApplicationModel.Communication;
3 | using Xunit;
4 |
5 | namespace Tests
6 | {
7 | public class PhoneDialer_Tests
8 | {
9 | [Fact]
10 | public void Dialer_Open_Fail_On_NetStandard() =>
11 | Assert.Throws(() => PhoneDialer.Open("1234567890"));
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test/UnitTests/SecureStorage_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.Storage;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class SecureStorage_Tests
9 | {
10 | [Fact]
11 | public async Task SecureStorage_LoadAsync_Fail_On_NetStandard()
12 | {
13 | await Assert.ThrowsAsync(() => SecureStorage.GetAsync("key"));
14 | }
15 |
16 | [Fact]
17 | public async Task SecureStorage_SaveAsync_Fail_On_NetStandard()
18 | {
19 | await Assert.ThrowsAsync(() => SecureStorage.SetAsync("key", "data"));
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/test/UnitTests/Share_Tests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 | using Microsoft.Maui.ApplicationModel;
4 | using Microsoft.Maui.ApplicationModel.DataTransfer;
5 | using Xunit;
6 |
7 | namespace Tests
8 | {
9 | public class Share_Tests
10 | {
11 | [Fact]
12 | public async Task Request_Text_NetStandard() =>
13 | await Assert.ThrowsAsync(() => Share.RequestAsync("Text"));
14 |
15 | [Fact]
16 | public async Task Request_Text_Title_NetStandard() =>
17 | await Assert.ThrowsAsync(() => Share.RequestAsync("Text", "Title"));
18 |
19 | [Fact]
20 | public async Task Request_Text_Request_NetStandard() =>
21 | await Assert.ThrowsAsync(() => Share.RequestAsync(new ShareTextRequest()));
22 |
23 | [Fact]
24 | public async Task Request_File_Request_NetStandard() =>
25 | await Assert.ThrowsAsync(() => Share.RequestAsync(new ShareFileRequest()));
26 |
27 | [Fact]
28 | public async Task Request_Multiple_Files_Request_NetStandard() =>
29 | await Assert.ThrowsAsync(() => Share.RequestAsync(new ShareMultipleFilesRequest()));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/test/UnitTests/Sms_Tests.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 | using Microsoft.Maui.ApplicationModel;
3 | using Microsoft.Maui.ApplicationModel.Communication;
4 | using Xunit;
5 |
6 | namespace Tests
7 | {
8 | public class Sms_Tests
9 | {
10 | [Fact]
11 | public Task Sms_Fail_On_NetStandard() =>
12 | Assert.ThrowsAsync(() => Sms.ComposeAsync());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/test/UnitTests/Utils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Tests
6 | {
7 | public static class TestUtils
8 | {
9 | public static void EnableExperimentalFeatures()
10 | {
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test/UnitTests/Utils_Tests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Maui.ApplicationModel;
2 | using Xunit;
3 |
4 | namespace Tests
5 | {
6 | public class Utils_Tests
7 | {
8 | [Theory]
9 | [InlineData("9", "9.0", 9, 0)]
10 | [InlineData("9.0", "9.0", 9, 0)]
11 | public void ParseVersion(string input, string expected, int major, int minor)
12 | {
13 | var version = Utils.ParseVersion(input);
14 | Assert.Equal(expected, version.ToString());
15 | Assert.Equal(major, version.Major);
16 | Assert.Equal(minor, version.Minor);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------