Added theme
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user