Added theme
This commit is contained in:
parent
4f21ecb859
commit
dceb5b49d8
@ -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();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using QRCoder; // QRCoder-ImageSharp else it crashes
|
||||
|
||||
namespace DemoAndroid;
|
||||
|
||||
[Activity(Label = "@string/app_name", MainLauncher = true)]
|
||||
[Activity(Label = "@string/app_name", MainLauncher = false)]
|
||||
public class MainActivity : Activity
|
||||
{
|
||||
private string _text = "";
|
||||
|
@ -2,18 +2,19 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="5pt">
|
||||
|
||||
<TextView android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Start PC by tapping button below" />
|
||||
android:text="Start de computer met Wake-On-Lan door op de knop hieronder te klikken" />
|
||||
|
||||
<Button android:id="@+id/btnWakeOnLan"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Start PC"
|
||||
android:text="Start de computer"
|
||||
android:textColor="@color/white"
|
||||
android:background="@color/blue"
|
||||
android:height="15pt"
|
||||
android:background="@color/green"
|
||||
android:height="20pt"
|
||||
android:layout_margin="10pt"/>
|
||||
</LinearLayout>
|
@ -2,4 +2,5 @@
|
||||
<resources>
|
||||
<color name="blue">#4287f5</color>
|
||||
<color name="white">#FFFFFF</color>
|
||||
<color name="green">#2abf39</color>
|
||||
</resources>
|
@ -1,4 +1,4 @@
|
||||
<resources>
|
||||
<string name="app_name">DemoAndroid</string>
|
||||
<string name="app_name">Start computer</string>
|
||||
<string name="app_text">Hello, Android!</string>
|
||||
</resources>
|
||||
|
8
DemoAndroid/Resources/values/style.xml
Normal file
8
DemoAndroid/Resources/values/style.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="NoActionBar" parent="@android:style/Theme.Material.Light.DarkActionBar">
|
||||
<item name="android:windowActionBar">false</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowFullscreen">true</item>
|
||||
</style>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user