This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for device settings (Screen brightness, wake lock and a…
…uto connect)
- Loading branch information
Manuel Mayer
committed
Jan 22, 2022
1 parent
f25be74
commit 06a2e9b
Showing
13 changed files
with
254 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Android.App; | ||
using Android.Content; | ||
using Android.OS; | ||
using Android.Runtime; | ||
using Android.Util; | ||
using Android.Views; | ||
using Android.Widget; | ||
using SuchByte.MacroDeck; | ||
using SuchByte.MacroDeck.Droid; | ||
using SuchByte.MacroDeck.Settings; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Xamarin.Forms; | ||
|
||
[assembly: Dependency(typeof(AndroidWakeLockService))] | ||
public class AndroidWakeLockService : IWakeLockService | ||
{ | ||
public string WakeLockMethod { get; set; } = "Connected"; | ||
|
||
public void SetWakeLock(bool state) | ||
{ | ||
switch (WakeLockMethod) | ||
{ | ||
case "Always": | ||
state = true; | ||
break; | ||
case "Connected": | ||
break; | ||
case "Never": | ||
state = false; | ||
break; | ||
} | ||
AppInstance.MainActivity.WakeLockActive = state; | ||
Log.Info("Wakelock", $"Set wakelock: { state }"); | ||
try | ||
{ | ||
if (AppInstance.MainActivity.WakeLock == null) return; Device.BeginInvokeOnMainThread(() => | ||
{ | ||
|
||
if (state) | ||
{ | ||
AppInstance.MainActivity.WakeLock.Acquire(); | ||
} | ||
else | ||
{ | ||
if (!AppInstance.MainActivity.WakeLock.IsHeld) return; | ||
AppInstance.MainActivity.WakeLock.Release(); | ||
} | ||
}); | ||
} | ||
catch { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using SuchByte.MacroDeck.Settings; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace SuchByte.MacroDeck | ||
{ | ||
public interface IWakeLockService | ||
{ | ||
string WakeLockMethod { get; set; } | ||
void SetWakeLock(bool state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.