Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Forked from JonDouglas/Activity1.cs
Created March 17, 2018 01:21
Show Gist options
  • Select an option

  • Save codenamejason/54b70b9409e6cfe768b72573567b19a6 to your computer and use it in GitHub Desktop.

Select an option

Save codenamejason/54b70b9409e6cfe768b72573567b19a6 to your computer and use it in GitHub Desktop.

Revisions

  1. @JonDouglas JonDouglas revised this gist Jul 5, 2016. 1 changed file with 57 additions and 34 deletions.
    91 changes: 57 additions & 34 deletions TestCredentialsProvider.cs
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,62 @@
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Timers;

    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using LoginScreen;

    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);
    }
    }
    }
    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;
    }
    }
    }

  2. @JonDouglas JonDouglas created this gist Jul 5, 2016.
    28 changes: 28 additions & 0 deletions Activity1.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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);
    }
    }
    }


    29 changes: 29 additions & 0 deletions Activity2.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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";
    }
    }
    }


    39 changes: 39 additions & 0 deletions CustomApplication.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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);
    }
    }
    }
    13 changes: 13 additions & 0 deletions Main.axml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <?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>
    39 changes: 39 additions & 0 deletions TestCredentialsProvider.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    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);
    }
    }
    }