Skip to content

Commit

Permalink
Android Init requires Activity. (#286)
Browse files Browse the repository at this point in the history
* Android Init requires Activity.

* Cleaned up usings

Co-authored-by: Erling Moxnes Kristiansen <emk@dips.no>
  • Loading branch information
ErlingMK and Erling Moxnes Kristiansen authored Aug 17, 2021
1 parent 1e78c18 commit 3ab6872
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
7 changes: 4 additions & 3 deletions src/DIPS.Xamarin.UI.Android/Library.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DIPS.Xamarin.UI.Internal.Utilities;
using Android.App;
using DIPS.Xamarin.UI.Internal.Utilities;

namespace DIPS.Xamarin.UI.Android
{
Expand All @@ -12,7 +13,7 @@ public static class Library
/// <summary>
/// Method to call at startup of the app in order to keep assemblies and to run other initializing methods in the library
/// </summary>
public static void Initialize()
public static void Initialize(Activity activity)
{
if (s_isInitialized) return;
Inspector.Instance = new Util.Inspector();
Expand All @@ -21,7 +22,7 @@ public static void Initialize()

var vibrationService = new VibrationService();
Vibration.Vibration.Initialize(vibrationService);
VibrationService.Initialize();
VibrationService.Initialize(activity);
s_isInitialized = true;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/DIPS.Xamarin.UI.Android/VibrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Android.Content.PM;
using Android.OS;
using DIPS.Xamarin.UI.Vibration;
using Xamarin.Essentials;

namespace DIPS.Xamarin.UI.Android
{
Expand Down Expand Up @@ -115,15 +114,14 @@ public IPlatformFeedbackGenerator Generate()
return new PlatformFeedbackGenerator();
}

internal static void Initialize()
internal static void Initialize(Activity activity)
{
s_activity = Platform.CurrentActivity;
s_activity = activity;
s_hasPermission = s_activity.CheckSelfPermission(Manifest.Permission.Vibrate);
}

private static bool ShouldVibrate()
{

s_vibrator ??= Vibrator.FromContext(s_activity);
return true;
}
Expand Down
4 changes: 1 addition & 3 deletions src/DIPS.Xamarin.UI/Vibration/Vibration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;

namespace DIPS.Xamarin.UI.Vibration
namespace DIPS.Xamarin.UI.Vibration
{
/// <summary>
/// Vibration/haptic feedback.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void OnCreate(Bundle savedInstanceState)
Essentials.Platform.Init(this, savedInstanceState); //Xamarin essentials

global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
DIPS.Xamarin.UI.Android.Library.Initialize();
DIPS.Xamarin.UI.Android.Library.Initialize(this);

InternalShared.MobileSettings.Instance = new AndroidSettings(this);

Expand Down

0 comments on commit 3ab6872

Please sign in to comment.