Added theme

This commit is contained in:
Maurice
2024-06-19 19:20:50 +02:00
parent 4f21ecb859
commit dceb5b49d8
6 changed files with 77 additions and 56 deletions

View File

@@ -7,37 +7,7 @@ using Java.Lang;
namespace DemoAndroid;
class BiometricCallback : BiometricPrompt.AuthenticationCallback, IDialogInterfaceOnClickListener
{
private Context _context;
public BiometricCallback(Context context)
{
_context = context;
}
public override void OnAuthenticationError(BiometricErrorCode errorCode, ICharSequence? errString)
{
Toast.MakeText(_context, $"Authentication error: {errorCode}, {errString?.ToString()}", ToastLength.Long).Show();
}
public override void OnAuthenticationSucceeded(BiometricPrompt.AuthenticationResult? result)
{
Toast.MakeText(_context, "Authentication succeeded!", ToastLength.Long).Show();
}
public override void OnAuthenticationFailed()
{
Toast.MakeText(_context, "Authentication failed!", ToastLength.Long).Show();
}
public void OnClick(IDialogInterface? dialog, int which)
{
Toast.MakeText(_context, "Cancel clicked!", ToastLength.Long).Show();
}
}
[Activity(Label = "WakeOnLanActivity")]
[Activity(Label = "WakeOnLanActivity", MainLauncher = true, Theme = "@style/NoActionBar")]
public class WakeOnLanActivity : Activity
{
private const int BiometricStrong = 0x0000000f;
@@ -56,30 +26,34 @@ public class WakeOnLanActivity : Activity
var button = FindViewById<Button>(Resource.Id.btnWakeOnLan);
button.Click += (sender, args) =>
{
if (!_authenticated)
{
Authenticate();
return;
}
WakePc();
OnlyAuthenticated(WakePc);
};
}
private void Authenticate()
private void OnlyAuthenticated(Action action)
{
var callback = new BiometricCallback(this);
if (!_authenticated)
{
var callback = new BiometricCallback(this, () =>
{
_authenticated = true;
action();
});
var prompt = new BiometricPrompt.Builder(this)
.SetNegativeButton("Negative", MainExecutor, callback)
.SetTitle("Bewijs jezelf met je vingerafdruk")
.SetSubtitle("We willen zeker weten dat je niet Colinde bent")
.SetAllowedAuthenticators(BiometricStrong)
.Build();
var prompt = new BiometricPrompt.Builder(this)
.SetNegativeButton("Annuleren", MainExecutor, callback)
.SetTitle("Bewijs jezelf met je vingerafdruk")
.SetSubtitle("We willen zeker weten dat je niet Colinde bent")
.SetAllowedAuthenticators(BiometricStrong)
.Build();
var cancellation = new CancellationSignal();
var cancellation = new CancellationSignal();
prompt.Authenticate(cancellation, MainExecutor, callback);
prompt.Authenticate(cancellation, MainExecutor, callback);
return;
}
action();
}
private void WakePc()
@@ -112,6 +86,43 @@ public class WakeOnLanActivity : Activity
client.Send(magicPacket, magicPacket.Length, endpoint);
}
Toast.MakeText(this, "Computer started!", ToastLength.Long).Show();
Toast.MakeText(this, "Computer started!", ToastLength.Long)!.Show();
}
}
/// <summary>
/// Biometric authentication callbacks
/// https://developer.android.com/identity/sign-in/biometric-auth#java
/// </summary>
class BiometricCallback : BiometricPrompt.AuthenticationCallback, IDialogInterfaceOnClickListener
{
private Context _context;
private readonly Action _onSuccess;
public BiometricCallback(Context context, Action onSuccess)
{
_context = context;
_onSuccess = onSuccess;
}
public override void OnAuthenticationError(BiometricErrorCode errorCode, ICharSequence? errString)
{
Toast.MakeText(_context, $"Authenticatie mislukt: {errorCode}, {errString?.ToString()}", ToastLength.Long)!.Show();
}
public override void OnAuthenticationSucceeded(BiometricPrompt.AuthenticationResult? result)
{
Toast.MakeText(_context, "Authentication succeeded!", ToastLength.Short)!.Show();
_onSuccess();
}
public override void OnAuthenticationFailed()
{
Toast.MakeText(_context, "Authenticatie mislukt!", ToastLength.Long)!.Show();
}
public void OnClick(IDialogInterface? dialog, int which)
{
Toast.MakeText(_context, "Geannuleerd!", ToastLength.Long)!.Show();
}
}