Skip to content

Instantly share code, notes, and snippets.

@JonDouglas
Last active March 17, 2018 01:21
Show Gist options
  • Save JonDouglas/655cd55dab1124bd71c6ad72ffb864a5 to your computer and use it in GitHub Desktop.
Save JonDouglas/655cd55dab1124bd71c6ad72ffb864a5 to your computer and use it in GitHub Desktop.
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using LoginScreen;
namespace LoginScreen.Android.Sample
{
[Activity (Label = "LoginScreen.Android.Sample", MainLauncher = true)]
public class Activity1 : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
FindViewById<Button>(Resource.Id.loginButton).Click += (sender, e) => LoginScreenControl<TestCredentialsProvider>.Activate(this);
}
}
}
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using LoginScreen;
namespace LoginScreen.Android.Sample
{
[Activity (Label = "Activity2")]
public class Activity2 : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button b = FindViewById<Button>(Resource.Id.loginButton);
b.Text = "Activity 2 Button";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace LoginScreen.Android.Sample
{
[Application]
public class CustomApplication : Application
{
public CustomApplication(IntPtr handle, JniHandleOwnership ownerShip)
: base(handle, ownerShip)
{
}
public override void OnCreate()
{
base.OnCreate();
}
public static Context GetAppContext()
{
return CustomApplication.Context;
}
public static void ChangeActivity()
{
Intent i = new Intent(Context, typeof(Activity2));
i.AddFlags(ActivityFlags.NewTask);
Context.StartActivity(i);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#000000"
android:text="Login" />
</RelativeLayout>
using System;
using System.Timers;
using LoginScreen;
namespace LoginScreen.Android.Sample
{
public class TestCredentialsProvider : ICredentialsProvider
{
readonly Random rnd = new Random ();
public bool NeedLoginAfterRegistration {
get { return false; }
}
public bool ShowPasswordResetLink {
get { return true; }
}
public bool ShowRegistration {
get { return true; }
}
public void Login (string userName, string password, Action successCallback, Action<LoginScreenFaultDetails> failCallback)
{
DelayInvoke (EquiprobableSelect (successCallback, () => failCallback (new LoginScreenFaultDetails { CommonErrorMessage = "Something wrong happened." })));
CustomApplication.ChangeActivity();
}
public void Register (string email, string userName, string password, Action successCallback, Action<LoginScreenFaultDetails> failCallback)
{
DelayInvoke (() => {
if (password.Length < 4) {
failCallback (new LoginScreenFaultDetails { PasswordErrorMessage = "Password must be at least 4 chars." });
} else {
successCallback ();
}
});
}
public void ResetPassword (string email, Action successCallback, Action<LoginScreenFaultDetails> failCallback)
{
DelayInvoke (EquiprobableSelect (successCallback, () => failCallback (new LoginScreenFaultDetails { CommonErrorMessage = "Something wrong happened." })));
}
private void DelayInvoke (Action operation)
{
Timer timer = new Timer ();
timer.AutoReset = false;
timer.Interval = 3000;
timer.Elapsed += (object sender, ElapsedEventArgs e) => operation.Invoke ();
timer.Start ();
}
private T EquiprobableSelect<T> (T first, T second)
{
return rnd.Next (100) < 50 ? first : second;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment