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

Commit

Permalink
All platform code is now internal
Browse files Browse the repository at this point in the history
 - public APIs live in the *.shared.cs files
 - all platform code is internal or private
  • Loading branch information
mattleibow committed May 2, 2018
1 parent 4802423 commit 831c22d
Show file tree
Hide file tree
Showing 60 changed files with 192 additions and 128 deletions.
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Accelerometer/Accelerometer.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class AccelerometerListener : Java.Lang.Object, ISensorEventListener
// acceleration due to gravity
const double gravity = 9.81;

public AccelerometerListener()
internal AccelerometerListener()
{
}

public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
void ISensorEventListener.OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
{
}

public void OnSensorChanged(SensorEvent e)
void ISensorEventListener.OnSensorChanged(SensorEvent e)
{
var data = new AccelerometerData(e.Values[0] / gravity, e.Values[1] / gravity, e.Values[2] / gravity);
Accelerometer.OnChanged(data);
Expand Down
10 changes: 5 additions & 5 deletions Xamarin.Essentials/Battery/Battery.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void StopBatteryListeners()
batteryReceiver = null;
}

public static double ChargeLevel
static double PlatformChargeLevel
{
get
{
Expand All @@ -50,7 +50,7 @@ public static double ChargeLevel
}
}

public static BatteryState State
static BatteryState PlatformState
{
get
{
Expand All @@ -77,7 +77,7 @@ public static BatteryState State
}
}

public static BatteryPowerSource PowerSource
static BatteryPowerSource PlatformPowerSource
{
get
{
Expand Down Expand Up @@ -108,11 +108,11 @@ internal class BatteryBroadcastReceiver : BroadcastReceiver
{
Action onChanged;

public BatteryBroadcastReceiver()
internal BatteryBroadcastReceiver()
{
}

public BatteryBroadcastReceiver(Action onChanged) =>
internal BatteryBroadcastReceiver(Action onChanged) =>
this.onChanged = onChanged;

public override void OnReceive(Context context, Intent intent) =>
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Battery/Battery.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void StopBatteryListeners()
static void BatteryChangedNotification(object sender, NSNotificationEventArgs args)
=> Platform.BeginInvokeOnMainThread(OnBatteryChanged);

public static double ChargeLevel
static double PlatformChargeLevel
{
get
{
Expand All @@ -44,7 +44,7 @@ public static double ChargeLevel
}
}

public static BatteryState State
static BatteryState PlatformState
{
get
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public static BatteryState State
}
}

public static BatteryPowerSource PowerSource
static BatteryPowerSource PlatformPowerSource
{
get
{
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Battery/Battery.netstandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ static void StartBatteryListeners() =>
static void StopBatteryListeners() =>
throw new NotImplementedInReferenceAssemblyException();

public static double ChargeLevel =>
static double PlatformChargeLevel =>
throw new NotImplementedInReferenceAssemblyException();

public static BatteryState State =>
static BatteryState PlatformState =>
throw new NotImplementedInReferenceAssemblyException();

public static BatteryPowerSource PowerSource =>
static BatteryPowerSource PlatformPowerSource =>
throw new NotImplementedInReferenceAssemblyException();
}
}
6 changes: 6 additions & 0 deletions Xamarin.Essentials/Battery/Battery.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public static partial class Battery
static BatteryPowerSource currentSource;
static BatteryState currentState;

public static double ChargeLevel => PlatformChargeLevel;

public static BatteryState State => PlatformState;

public static BatteryPowerSource PowerSource => PlatformPowerSource;

public static event BatteryChangedEventHandler BatteryChanged
{
add
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Battery/Battery.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static void ReportUpdated(object sender, object e)
static Windows.Devices.Power.Battery DefaultBattery =>
Windows.Devices.Power.Battery.AggregateBattery;

public static double ChargeLevel
static double PlatformChargeLevel
{
get
{
Expand All @@ -31,7 +31,7 @@ public static double ChargeLevel
}
}

public static BatteryState State
static BatteryState PlatformState
{
get
{
Expand All @@ -58,7 +58,7 @@ public static BatteryState State
}
}

public static BatteryPowerSource PowerSource
static BatteryPowerSource PlatformPowerSource
{
get
{
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Browser/Browser.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Xamarin.Essentials
{
public static partial class Browser
{
public static Task OpenAsync(Uri uri, BrowserLaunchType launchType)
static Task PlatformOpenAsync(Uri uri, BrowserLaunchType launchType)
{
if (uri == null)
throw new ArgumentNullException(nameof(uri));
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Browser/Browser.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Xamarin.Essentials
{
public static partial class Browser
{
public static Task OpenAsync(Uri uri, BrowserLaunchType launchType)
static Task PlatformOpenAsync(Uri uri, BrowserLaunchType launchType)
{
if (uri == null)
throw new ArgumentNullException(nameof(uri));
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Browser/Browser.netstandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Xamarin.Essentials
{
public static partial class Browser
{
public static Task OpenAsync(Uri uri, BrowserLaunchType launchType) =>
static Task PlatformOpenAsync(Uri uri, BrowserLaunchType launchType) =>
throw new NotImplementedInReferenceAssemblyException();
}
}
3 changes: 3 additions & 0 deletions Xamarin.Essentials/Browser/Browser.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public static Task OpenAsync(string uri, BrowserLaunchType launchType)

public static Task OpenAsync(Uri uri) =>
OpenAsync(uri, BrowserLaunchType.SystemPreferred);

public static Task OpenAsync(Uri uri, BrowserLaunchType launchType) =>
PlatformOpenAsync(uri, launchType);
}

public enum BrowserLaunchType
Expand Down
2 changes: 1 addition & 1 deletion Xamarin.Essentials/Browser/Browser.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Xamarin.Essentials
{
public static partial class Browser
{
public static Task OpenAsync(Uri uri, BrowserLaunchType launchType)
static Task PlatformOpenAsync(Uri uri, BrowserLaunchType launchType)
{
if (uri == null)
throw new ArgumentNullException(nameof(uri));
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Clipboard/Clipboard.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Xamarin.Essentials
{
public static partial class Clipboard
{
public static void SetText(string text)
static void PlatformSetText(string text)
=> Platform.ClipboardManager.PrimaryClip = ClipData.NewPlainText("Text", text);

public static bool HasText
static bool PlatformHasText
=> Platform.ClipboardManager.HasPrimaryClip;

public static Task<string> GetTextAsync()
static Task<string> PlatformGetTextAsync()
=> Task.FromResult(Platform.ClipboardManager.PrimaryClip?.GetItemAt(0)?.Text);
}
}
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Clipboard/Clipboard.ios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Xamarin.Essentials
{
public static partial class Clipboard
{
public static void SetText(string text)
static void PlatformSetText(string text)
=> UIPasteboard.General.String = text;

public static bool HasText
static bool PlatformHasText
=> UIPasteboard.General.HasStrings;

public static Task<string> GetTextAsync()
static Task<string> PlatformGetTextAsync()
=> Task.FromResult(UIPasteboard.General.String);
}
}
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Clipboard/Clipboard.netstandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ namespace Xamarin.Essentials
{
public static partial class Clipboard
{
public static void SetText(string text)
static void PlatformSetText(string text)
=> throw new NotImplementedInReferenceAssemblyException();

public static bool HasText
static bool PlatformHasText
=> throw new NotImplementedInReferenceAssemblyException();

public static Task<string> GetTextAsync()
static Task<string> PlatformGetTextAsync()
=> throw new NotImplementedInReferenceAssemblyException();
}
}
17 changes: 17 additions & 0 deletions Xamarin.Essentials/Clipboard/Clipboard.shared.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;

namespace Xamarin.Essentials
{
public static partial class Clipboard
{
public static void SetText(string text)
=> PlatformSetText(text);

public static bool HasText
=> PlatformHasText;

public static Task<string> GetTextAsync()
=> PlatformGetTextAsync();
}
}
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Clipboard/Clipboard.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace Xamarin.Essentials
{
public static partial class Clipboard
{
public static void SetText(string text)
static void PlatformSetText(string text)
{
var dataPackage = new DataPackage();
dataPackage.SetText(text);
SetContent(dataPackage);
}

public static bool HasText
static bool PlatformHasText
=> GetContent().Contains(StandardDataFormats.Text);

public static Task<string> GetTextAsync()
static Task<string> PlatformGetTextAsync()
{
var clipboardContent = GetContent();
return clipboardContent.Contains(StandardDataFormats.Text)
Expand Down
6 changes: 3 additions & 3 deletions Xamarin.Essentials/Compass/Compass.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ class SensorListener : Java.Lang.Object, ISensorEventListener, IDisposable
string magnetometer;
string accelerometer;

public SensorListener(string accelerometer, string magnetometer, SensorDelay delay)
internal SensorListener(string accelerometer, string magnetometer, SensorDelay delay)
{
this.magnetometer = magnetometer;
this.accelerometer = accelerometer;
}

public void OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
void ISensorEventListener.OnAccuracyChanged(Sensor sensor, [GeneratedEnum] SensorStatus accuracy)
{
}

public void OnSensorChanged(SensorEvent e)
void ISensorEventListener.OnSensorChanged(SensorEvent e)
{
if (e.Sensor.Name == accelerometer && !lastAccelerometerSet)
{
Expand Down
8 changes: 4 additions & 4 deletions Xamarin.Essentials/Connectivity/Connectivity.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void StopListeners()
static NetworkAccess IsBetterAccess(NetworkAccess currentAccess, NetworkAccess newAccess) =>
newAccess > currentAccess ? newAccess : currentAccess;

public static NetworkAccess NetworkAccess
static NetworkAccess PlatformNetworkAccess
{
get
{
Expand Down Expand Up @@ -110,7 +110,7 @@ void ProcessNetworkInfo(NetworkInfo info)
}
}

public static IEnumerable<ConnectionProfile> Profiles
static IEnumerable<ConnectionProfile> PlatformProfiles
{
get
{
Expand Down Expand Up @@ -207,11 +207,11 @@ class ConnectivityBroadcastReceiver : BroadcastReceiver
{
Action onChanged;

public ConnectivityBroadcastReceiver()
internal ConnectivityBroadcastReceiver()
{
}

public ConnectivityBroadcastReceiver(Action onChanged) =>
internal ConnectivityBroadcastReceiver(Action onChanged) =>
this.onChanged = onChanged;

public override async void OnReceive(Context context, Intent intent)
Expand Down
7 changes: 4 additions & 3 deletions Xamarin.Essentials/Connectivity/Connectivity.ios.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace Xamarin.Essentials
{
Expand All @@ -22,7 +23,7 @@ static void StopListeners()
listener = null;
}

public static NetworkAccess NetworkAccess
static NetworkAccess PlatformNetworkAccess
{
get
{
Expand All @@ -38,7 +39,7 @@ public static NetworkAccess NetworkAccess
}
}

public static IEnumerable<ConnectionProfile> Profiles
static IEnumerable<ConnectionProfile> PlatformProfiles
{
get
{
Expand Down
10 changes: 6 additions & 4 deletions Xamarin.Essentials/Connectivity/Connectivity.ios.reachability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static NetworkStatus RemoteHostStatus()
}
}

public static NetworkStatus InternetConnectionStatus()
internal static NetworkStatus InternetConnectionStatus()
{
var status = NetworkStatus.NotReachable;

Expand Down Expand Up @@ -124,7 +124,7 @@ class ReachabilityListener : IDisposable
NetworkReachability defaultRouteReachability;
NetworkReachability remoteHostReachability;

public ReachabilityListener()
internal ReachabilityListener()
{
var ip = new IPAddress(0);
defaultRouteReachability = new NetworkReachability(ip);
Expand All @@ -141,9 +141,11 @@ public ReachabilityListener()
remoteHostReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);
}

public event Action ReachabilityChanged;
internal event Action ReachabilityChanged;

public void Dispose()
void IDisposable.Dispose() => Dispose();

internal void Dispose()
{
defaultRouteReachability?.Dispose();
defaultRouteReachability = null;
Expand Down
Loading

0 comments on commit 831c22d

Please sign in to comment.