Instantly share code, notes, and snippets.

Embed
What would you like to do?
Interfaces for Xamarin.Essentials 0.6.0-preview (generated off commit 480cac0)
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Essentials.Interfaces;
namespace Xamarin.Essentials.Interfaces
{
public interface IAccelerometer
{
void Start(SensorSpeed sensorSpeed);
void Stop();
bool IsMonitoring { get; }
}
public interface IAppInfo
{
string PackageName { get; }
string Name { get; }
string VersionString { get; }
Version Version { get; }
string BuildString { get; }
}
public interface IBattery
{
double ChargeLevel { get; }
BatteryState State { get; }
BatteryPowerSource PowerSource { get; }
event BatteryChangedEventHandler BatteryChanged;
}
public interface IBrowser
{
Task OpenAsync(string uri);
Task OpenAsync(string uri, BrowserLaunchType launchType);
Task OpenAsync(Uri uri);
Task OpenAsync(Uri uri, BrowserLaunchType launchType);
}
public interface IClipboard
{
void SetText(string text);
Task<string> GetTextAsync();
bool HasText { get; }
}
public interface ICompass
{
void Start(SensorSpeed sensorSpeed);
void Stop();
bool IsMonitoring { get; }
}
public interface IConnectivity
{
NetworkAccess NetworkAccess { get; }
IEnumerable<ConnectionProfile> Profiles { get; }
event ConnectivityChangedEventHandler ConnectivityChanged;
}
public interface IDataTransfer
{
Task RequestAsync(string text);
Task RequestAsync(string text, string title);
Task RequestAsync(ShareTextRequest request);
}
public interface IDeviceDisplay
{
ScreenMetrics ScreenMetrics { get; }
event ScreenMetricsChanagedEventHandler ScreenMetricsChanaged;
}
public interface IDeviceInfo
{
string Model { get; }
string Manufacturer { get; }
string Name { get; }
string VersionString { get; }
Version Version { get; }
string Platform { get; }
string Idiom { get; }
DeviceType DeviceType { get; }
}
public interface IEmail
{
Task ComposeAsync();
Task ComposeAsync(string subject, string body, params string[] to);
Task ComposeAsync(EmailMessage message);
}
public interface IFileSystem
{
Task<Stream> OpenAppPackageFileAsync(string filename);
string CacheDirectory { get; }
string AppDataDirectory { get; }
}
public interface IFlashlight
{
Task TurnOnAsync();
Task TurnOffAsync();
}
public interface IGeocoding
{
Task<IEnumerable<Placemark>> GetPlacemarksAsync(Location location);
Task<IEnumerable<Placemark>> GetPlacemarksAsync(double latitude, double longitude);
Task<IEnumerable<Location>> GetLocationsAsync(string address);
string MapKey { get; set; }
}
public interface IGeolocation
{
Task<Location> GetLastKnownLocationAsync();
Task<Location> GetLocationAsync();
Task<Location> GetLocationAsync(GeolocationRequest request);
Task<Location> GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken);
}
public interface IGyroscope
{
void Start(SensorSpeed sensorSpeed);
void Stop();
bool IsMonitoring { get; }
}
public interface IMagnetometer
{
void Start(SensorSpeed sensorSpeed);
void Stop();
bool IsMonitoring { get; }
}
public interface IPhoneDialer
{
void Open(string number);
}
public interface IPlatform
{
void BeginInvokeOnMainThread(Action action);
}
public interface IPreferences
{
bool ContainsKey(string key);
bool ContainsKey(string key, string sharedName);
void Remove(string key);
void Remove(string key, string sharedName);
void Clear();
void Clear(string sharedName);
string Get(string key, string defaultValue);
bool Get(string key, bool defaultValue);
int Get(string key, int defaultValue);
double Get(string key, double defaultValue);
float Get(string key, float defaultValue);
long Get(string key, long defaultValue);
void Set(string key, string value);
void Set(string key, bool value);
void Set(string key, int value);
void Set(string key, double value);
void Set(string key, float value);
void Set(string key, long value);
string Get(string key, string defaultValue, string sharedName);
bool Get(string key, bool defaultValue, string sharedName);
int Get(string key, int defaultValue, string sharedName);
double Get(string key, double defaultValue, string sharedName);
float Get(string key, float defaultValue, string sharedName);
long Get(string key, long defaultValue, string sharedName);
void Set(string key, string value, string sharedName);
void Set(string key, bool value, string sharedName);
void Set(string key, int value, string sharedName);
void Set(string key, double value, string sharedName);
void Set(string key, float value, string sharedName);
void Set(string key, long value, string sharedName);
}
public interface IScreenLock
{
void RequestActive();
void RequestRelease();
bool IsActive { get; }
}
public interface ISecureStorage
{
Task<string> GetAsync(string key);
Task SetAsync(string key, string value);
}
public interface ISms
{
Task ComposeAsync();
Task ComposeAsync(SmsMessage message);
}
public interface ITextToSpeech
{
Task<IEnumerable<Locale>> GetLocalesAsync();
Task SpeakAsync(string text, CancellationToken cancelToken = default);
Task SpeakAsync(string text, SpeakSettings settings, CancellationToken cancelToken = default);
}
public interface IVersionTracking
{
void Track();
bool IsFirstLaunchForVersion(string version);
bool IsFirstLaunchForBuild(string build);
bool IsFirstLaunchEver { get; }
bool IsFirstLaunchForCurrentVersion { get; }
bool IsFirstLaunchForCurrentBuild { get; }
string CurrentVersion { get; }
string CurrentBuild { get; }
string PreviousVersion { get; }
string PreviousBuild { get; }
string FirstInstalledVersion { get; }
string FirstInstalledBuild { get; }
IEnumerable<string> VersionHistory { get; }
IEnumerable<string> BuildHistory { get; }
}
public interface IVibration
{
void Vibrate();
void Vibrate(double duration);
void Vibrate(TimeSpan duration);
void Cancel();
}
}
namespace Xamarin.Essentials.Implementation
{
public class EssentialsImplementation : IAccelerometer, IAppInfo, IBattery, IBrowser, IClipboard, ICompass, IConnectivity, IDataTransfer, IDeviceDisplay, IDeviceInfo, IEmail, IFileSystem, IFlashlight, IGeocoding, IGeolocation, IGyroscope, IMagnetometer, IPhoneDialer, IPlatform, IPreferences, IScreenLock, ISecureStorage, ISms, ITextToSpeech, IVersionTracking, IVibration
{
void IAccelerometer.Start(SensorSpeed sensorSpeed)
=> Xamarin.Essentials.Accelerometer.Start(sensorSpeed);
void IAccelerometer.Stop()
=> Xamarin.Essentials.Accelerometer.Stop();
bool IAccelerometer.IsMonitoring
=> Xamarin.Essentials.Accelerometer.IsMonitoring;
string IAppInfo.PackageName
=> Xamarin.Essentials.AppInfo.PackageName;
string IAppInfo.Name
=> Xamarin.Essentials.AppInfo.Name;
string IAppInfo.VersionString
=> Xamarin.Essentials.AppInfo.VersionString;
Version IAppInfo.Version
=> Xamarin.Essentials.AppInfo.Version;
string IAppInfo.BuildString
=> Xamarin.Essentials.AppInfo.BuildString;
double IBattery.ChargeLevel
=> Xamarin.Essentials.Battery.ChargeLevel;
BatteryState IBattery.State
=> Xamarin.Essentials.Battery.State;
BatteryPowerSource IBattery.PowerSource
=> Xamarin.Essentials.Battery.PowerSource;
event BatteryChangedEventHandler IBattery.BatteryChanged
{
add => Xamarin.Essentials.Battery.BatteryChanged += value;
remove => Xamarin.Essentials.Battery.BatteryChanged -= value;
}
Task IBrowser.OpenAsync(string uri)
=> Xamarin.Essentials.Browser.OpenAsync(uri);
Task IBrowser.OpenAsync(string uri, BrowserLaunchType launchType)
=> Xamarin.Essentials.Browser.OpenAsync(uri, launchType);
Task IBrowser.OpenAsync(Uri uri)
=> Xamarin.Essentials.Browser.OpenAsync(uri);
Task IBrowser.OpenAsync(Uri uri, BrowserLaunchType launchType)
=> Xamarin.Essentials.Browser.OpenAsync(uri, launchType);
void IClipboard.SetText(string text)
=> Xamarin.Essentials.Clipboard.SetText(text);
Task<string> IClipboard.GetTextAsync()
=> Xamarin.Essentials.Clipboard.GetTextAsync();
bool IClipboard.HasText
=> Xamarin.Essentials.Clipboard.HasText;
void ICompass.Start(SensorSpeed sensorSpeed)
=> Xamarin.Essentials.Compass.Start(sensorSpeed);
void ICompass.Stop()
=> Xamarin.Essentials.Compass.Stop();
bool ICompass.IsMonitoring
=> Xamarin.Essentials.Compass.IsMonitoring;
NetworkAccess IConnectivity.NetworkAccess
=> Xamarin.Essentials.Connectivity.NetworkAccess;
IEnumerable<ConnectionProfile> IConnectivity.Profiles
=> Xamarin.Essentials.Connectivity.Profiles;
event ConnectivityChangedEventHandler IConnectivity.ConnectivityChanged
{
add => Xamarin.Essentials.Connectivity.ConnectivityChanged += value;
remove => Xamarin.Essentials.Connectivity.ConnectivityChanged -= value;
}
Task IDataTransfer.RequestAsync(string text)
=> Xamarin.Essentials.DataTransfer.RequestAsync(text);
Task IDataTransfer.RequestAsync(string text, string title)
=> Xamarin.Essentials.DataTransfer.RequestAsync(text, title);
Task IDataTransfer.RequestAsync(ShareTextRequest request)
=> Xamarin.Essentials.DataTransfer.RequestAsync(request);
ScreenMetrics IDeviceDisplay.ScreenMetrics
=> Xamarin.Essentials.DeviceDisplay.ScreenMetrics;
event ScreenMetricsChanagedEventHandler IDeviceDisplay.ScreenMetricsChanaged
{
add => Xamarin.Essentials.DeviceDisplay.ScreenMetricsChanaged += value;
remove => Xamarin.Essentials.DeviceDisplay.ScreenMetricsChanaged -= value;
}
string IDeviceInfo.Model
=> Xamarin.Essentials.DeviceInfo.Model;
string IDeviceInfo.Manufacturer
=> Xamarin.Essentials.DeviceInfo.Manufacturer;
string IDeviceInfo.Name
=> Xamarin.Essentials.DeviceInfo.Name;
string IDeviceInfo.VersionString
=> Xamarin.Essentials.DeviceInfo.VersionString;
Version IDeviceInfo.Version
=> Xamarin.Essentials.DeviceInfo.Version;
string IDeviceInfo.Platform
=> Xamarin.Essentials.DeviceInfo.Platform;
string IDeviceInfo.Idiom
=> Xamarin.Essentials.DeviceInfo.Idiom;
DeviceType IDeviceInfo.DeviceType
=> Xamarin.Essentials.DeviceInfo.DeviceType;
Task IEmail.ComposeAsync()
=> Xamarin.Essentials.Email.ComposeAsync();
Task IEmail.ComposeAsync(string subject, string body, params string[] to)
=> Xamarin.Essentials.Email.ComposeAsync(subject, body, to);
Task IEmail.ComposeAsync(EmailMessage message)
=> Xamarin.Essentials.Email.ComposeAsync(message);
Task<Stream> IFileSystem.OpenAppPackageFileAsync(string filename)
=> Xamarin.Essentials.FileSystem.OpenAppPackageFileAsync(filename);
string IFileSystem.CacheDirectory
=> Xamarin.Essentials.FileSystem.CacheDirectory;
string IFileSystem.AppDataDirectory
=> Xamarin.Essentials.FileSystem.AppDataDirectory;
Task IFlashlight.TurnOnAsync()
=> Xamarin.Essentials.Flashlight.TurnOnAsync();
Task IFlashlight.TurnOffAsync()
=> Xamarin.Essentials.Flashlight.TurnOffAsync();
Task<IEnumerable<Placemark>> IGeocoding.GetPlacemarksAsync(Location location)
=> Xamarin.Essentials.Geocoding.GetPlacemarksAsync(location);
Task<IEnumerable<Placemark>> IGeocoding.GetPlacemarksAsync(double latitude, double longitude)
=> Xamarin.Essentials.Geocoding.GetPlacemarksAsync(latitude, longitude);
Task<IEnumerable<Location>> IGeocoding.GetLocationsAsync(string address)
=> Xamarin.Essentials.Geocoding.GetLocationsAsync(address);
string IGeocoding.MapKey
{
get { return Xamarin.Essentials.Geocoding.MapKey; }
set { Xamarin.Essentials.Geocoding.MapKey = value; }
}
Task<Location> IGeolocation.GetLastKnownLocationAsync()
=> Xamarin.Essentials.Geolocation.GetLastKnownLocationAsync();
Task<Location> IGeolocation.GetLocationAsync()
=> Xamarin.Essentials.Geolocation.GetLocationAsync();
Task<Location> IGeolocation.GetLocationAsync(GeolocationRequest request)
=> Xamarin.Essentials.Geolocation.GetLocationAsync(request);
Task<Location> IGeolocation.GetLocationAsync(GeolocationRequest request, CancellationToken cancelToken)
=> Xamarin.Essentials.Geolocation.GetLocationAsync(request, cancelToken);
void IGyroscope.Start(SensorSpeed sensorSpeed)
=> Xamarin.Essentials.Gyroscope.Start(sensorSpeed);
void IGyroscope.Stop()
=> Xamarin.Essentials.Gyroscope.Stop();
bool IGyroscope.IsMonitoring
=> Xamarin.Essentials.Gyroscope.IsMonitoring;
void IMagnetometer.Start(SensorSpeed sensorSpeed)
=> Xamarin.Essentials.Magnetometer.Start(sensorSpeed);
void IMagnetometer.Stop()
=> Xamarin.Essentials.Magnetometer.Stop();
bool IMagnetometer.IsMonitoring
=> Xamarin.Essentials.Magnetometer.IsMonitoring;
void IPhoneDialer.Open(string number)
=> Xamarin.Essentials.PhoneDialer.Open(number);
void IPlatform.BeginInvokeOnMainThread(Action action)
=> Xamarin.Essentials.Platform.BeginInvokeOnMainThread(action);
bool IPreferences.ContainsKey(string key)
=> Xamarin.Essentials.Preferences.ContainsKey(key);
bool IPreferences.ContainsKey(string key, string sharedName)
=> Xamarin.Essentials.Preferences.ContainsKey(key, sharedName);
void IPreferences.Remove(string key)
=> Xamarin.Essentials.Preferences.Remove(key);
void IPreferences.Remove(string key, string sharedName)
=> Xamarin.Essentials.Preferences.Remove(key, sharedName);
void IPreferences.Clear()
=> Xamarin.Essentials.Preferences.Clear();
void IPreferences.Clear(string sharedName)
=> Xamarin.Essentials.Preferences.Clear(sharedName);
string IPreferences.Get(string key, string defaultValue)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue);
bool IPreferences.Get(string key, bool defaultValue)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue);
int IPreferences.Get(string key, int defaultValue)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue);
double IPreferences.Get(string key, double defaultValue)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue);
float IPreferences.Get(string key, float defaultValue)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue);
long IPreferences.Get(string key, long defaultValue)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue);
void IPreferences.Set(string key, string value)
=> Xamarin.Essentials.Preferences.Set(key, value);
void IPreferences.Set(string key, bool value)
=> Xamarin.Essentials.Preferences.Set(key, value);
void IPreferences.Set(string key, int value)
=> Xamarin.Essentials.Preferences.Set(key, value);
void IPreferences.Set(string key, double value)
=> Xamarin.Essentials.Preferences.Set(key, value);
void IPreferences.Set(string key, float value)
=> Xamarin.Essentials.Preferences.Set(key, value);
void IPreferences.Set(string key, long value)
=> Xamarin.Essentials.Preferences.Set(key, value);
string IPreferences.Get(string key, string defaultValue, string sharedName)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue, sharedName);
bool IPreferences.Get(string key, bool defaultValue, string sharedName)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue, sharedName);
int IPreferences.Get(string key, int defaultValue, string sharedName)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue, sharedName);
double IPreferences.Get(string key, double defaultValue, string sharedName)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue, sharedName);
float IPreferences.Get(string key, float defaultValue, string sharedName)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue, sharedName);
long IPreferences.Get(string key, long defaultValue, string sharedName)
=> Xamarin.Essentials.Preferences.Get(key, defaultValue, sharedName);
void IPreferences.Set(string key, string value, string sharedName)
=> Xamarin.Essentials.Preferences.Set(key, value, sharedName);
void IPreferences.Set(string key, bool value, string sharedName)
=> Xamarin.Essentials.Preferences.Set(key, value, sharedName);
void IPreferences.Set(string key, int value, string sharedName)
=> Xamarin.Essentials.Preferences.Set(key, value, sharedName);
void IPreferences.Set(string key, double value, string sharedName)
=> Xamarin.Essentials.Preferences.Set(key, value, sharedName);
void IPreferences.Set(string key, float value, string sharedName)
=> Xamarin.Essentials.Preferences.Set(key, value, sharedName);
void IPreferences.Set(string key, long value, string sharedName)
=> Xamarin.Essentials.Preferences.Set(key, value, sharedName);
void IScreenLock.RequestActive()
=> Xamarin.Essentials.ScreenLock.RequestActive();
void IScreenLock.RequestRelease()
=> Xamarin.Essentials.ScreenLock.RequestRelease();
bool IScreenLock.IsActive
=> Xamarin.Essentials.ScreenLock.IsActive;
Task<string> ISecureStorage.GetAsync(string key)
=> Xamarin.Essentials.SecureStorage.GetAsync(key);
Task ISecureStorage.SetAsync(string key, string value)
=> Xamarin.Essentials.SecureStorage.SetAsync(key, value);
Task ISms.ComposeAsync()
=> Xamarin.Essentials.Sms.ComposeAsync();
Task ISms.ComposeAsync(SmsMessage message)
=> Xamarin.Essentials.Sms.ComposeAsync(message);
Task<IEnumerable<Locale>> ITextToSpeech.GetLocalesAsync()
=> Xamarin.Essentials.TextToSpeech.GetLocalesAsync();
Task ITextToSpeech.SpeakAsync(string text, CancellationToken cancelToken = default)
=> Xamarin.Essentials.TextToSpeech.SpeakAsync(text, cancelToken);
Task ITextToSpeech.SpeakAsync(string text, SpeakSettings settings, CancellationToken cancelToken = default)
=> Xamarin.Essentials.TextToSpeech.SpeakAsync(text, settings, cancelToken);
void IVersionTracking.Track()
=> Xamarin.Essentials.VersionTracking.Track();
bool IVersionTracking.IsFirstLaunchForVersion(string version)
=> Xamarin.Essentials.VersionTracking.IsFirstLaunchForVersion(version);
bool IVersionTracking.IsFirstLaunchForBuild(string build)
=> Xamarin.Essentials.VersionTracking.IsFirstLaunchForBuild(build);
bool IVersionTracking.IsFirstLaunchEver
=> Xamarin.Essentials.VersionTracking.IsFirstLaunchEver;
bool IVersionTracking.IsFirstLaunchForCurrentVersion
=> Xamarin.Essentials.VersionTracking.IsFirstLaunchForCurrentVersion;
bool IVersionTracking.IsFirstLaunchForCurrentBuild
=> Xamarin.Essentials.VersionTracking.IsFirstLaunchForCurrentBuild;
string IVersionTracking.CurrentVersion
=> Xamarin.Essentials.VersionTracking.CurrentVersion;
string IVersionTracking.CurrentBuild
=> Xamarin.Essentials.VersionTracking.CurrentBuild;
string IVersionTracking.PreviousVersion
=> Xamarin.Essentials.VersionTracking.PreviousVersion;
string IVersionTracking.PreviousBuild
=> Xamarin.Essentials.VersionTracking.PreviousBuild;
string IVersionTracking.FirstInstalledVersion
=> Xamarin.Essentials.VersionTracking.FirstInstalledVersion;
string IVersionTracking.FirstInstalledBuild
=> Xamarin.Essentials.VersionTracking.FirstInstalledBuild;
IEnumerable<string> IVersionTracking.VersionHistory
=> Xamarin.Essentials.VersionTracking.VersionHistory;
IEnumerable<string> IVersionTracking.BuildHistory
=> Xamarin.Essentials.VersionTracking.BuildHistory;
void IVibration.Vibrate()
=> Xamarin.Essentials.Vibration.Vibrate();
void IVibration.Vibrate(double duration)
=> Xamarin.Essentials.Vibration.Vibrate(duration);
void IVibration.Vibrate(TimeSpan duration)
=> Xamarin.Essentials.Vibration.Vibrate(duration);
void IVibration.Cancel()
=> Xamarin.Essentials.Vibration.Cancel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment