Пример #1
0
        public void OnConnected(Bundle p0)
        {
            Alert("Google", "Connected", false, (res) => {});
            var request = new RestRequest();
            var gName   = plusClient.CurrentPerson.Name;
            var gImage  = plusClient.CurrentPerson.Image;

            request.RequestFinished += (object sender, RequestEndedArgs e) => {
                RunOnUiThread(delegate {
                    Globals.DeleteProfileId();
                    var id = (string)JsonConvert.DeserializeObject(e.Result, typeof(string));
                    Globals.SaveProfileId(id);
                    StartActivity(main);
                });
            };
            request.Send(RequestConfig.Google, "POST", new GoogleClient {
                name        = plusClient.CurrentPerson.DisplayName,
                family_name = gName.FamilyName,
                given_name  = gName.GivenName,
                id          = plusClient.CurrentPerson.Id,
                picture     = gImage.Url,
                email       = plusClient.AccountName
            });
        }
Пример #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Login);
            Console.WriteLine("LoginActivity");

            ImageView logo = FindViewById <ImageView> (Resource.Id.ActionBarLogo);

            logo.Visibility = ViewStates.Invisible;

            ImageView menu = FindViewById <ImageView> (Resource.Id.ActionBarMenu);

            menu.Visibility = ViewStates.Invisible;

            TextView title = FindViewById <TextView> (Resource.Id.ActionBarTitle);

            title.Text = "Login";

            Button back = FindViewById <Button> (Resource.Id.ActionBarBack);

            back.Click += delegate {
                Finish();
            };

            EditText email    = FindViewById <EditText> (Resource.Id.Email);
            EditText password = FindViewById <EditText> (Resource.Id.Password);

            email.TextChanged    += (object sender, Android.Text.TextChangedEventArgs e) => {
            };
            password.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
            };

            ImageButton facebook = FindViewById <ImageButton> (Resource.Id.loginViaFacebook);

            facebook.Click += delegate {
                var webAuth = new Intent(this, typeof(FBWebViewAuthActivity));
                webAuth.PutExtra("AppId", AppId);
                webAuth.PutExtra("ExtendedPermissions", ExtendedPermissions);
                StartActivityForResult(webAuth, 0);
            };

            ImageButton googlePlus = FindViewById <ImageButton> (Resource.Id.loginViaGoogle);

            plusClient = new PlusClient.Builder(this, this, this).Build();
            plusClient.RegisterConnectionCallbacks(this);
            plusClient.IsConnectionFailedListenerRegistered(this);

            googlePlus.Click += (object sender, EventArgs e) => {
                if (plusClient.IsConnected || plusClient.IsConnecting)
                {
                    return;
                }

                if (connectionResult == null)
                {
                    plusClient.Connect();
                }
                else
                {
                    resolveGoogleLogin(connectionResult);
                }
            };

            main = new Intent(this, typeof(MainTabActivity));
            Button login = FindViewById <Button> (Resource.Id.loginButton);

            login.Click += delegate {
                Globals.DeleteProfileId();
                var request = new RestRequest();
                request.RequestFinished += (object sender, RequestEndedArgs e) => {
                    RunOnUiThread(delegate {
                        var id = (string)JsonConvert.DeserializeObject(e.Result, typeof(string));
                        Globals.SaveProfileId(id);
                        StartActivity(main);
                    });
                };
                request.Send(RequestConfig.Login, "POST", new LoginModel {
                    Email = email.Text.Trim(), Password = password.Text.Trim(), RememberMe = true
                });
            };

            Button forgotPass         = FindViewById <Button> (Resource.Id.forgotPassButton);
            var    forgotPassActivity = new Intent(this, typeof(ForgotPassActivity));

            forgotPass.Click += delegate {
                StartActivity(forgotPassActivity);
            };
        }
Пример #3
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            // google
            if (requestCode == 9000)
            {
                if (resultCode == Result.Ok)
                {
                    plusClient.Connect();
                }
                return;
            }

            // facebook
            switch (resultCode)
            {
            case Result.Ok:
                accessToken = data.GetStringExtra("AccessToken");
                string userId = data.GetStringExtra("UserId");
                string error  = data.GetStringExtra("Exception");

                fb = new FacebookClient(accessToken);
                fb.GetTaskAsync("me").ContinueWith(t => {
                    if (!t.IsFaulted)
                    {
                        var result  = (IDictionary <string, object>)t.Result;
                        var request = new RestRequest();

                        RunOnUiThread(delegate {
                            request.RequestFinished += (object sender, RequestEndedArgs e) => {
                                RunOnUiThread(delegate {
                                    Globals.DeleteProfileId();
                                    var id = (string)JsonConvert.DeserializeObject(e.Result, typeof(string));
                                    Globals.SaveProfileId(id);
                                    StartActivity(main);
                                });
                            };
                            request.Send(RequestConfig.Facebook, "POST", new FacebookProfile {
                                Id         = long.Parse(result["id"].ToString()),
                                Name       = (string)result["name"],
                                first_name = (string)result["first_name"],
                                last_name  = (string)result["last_name"],
                                Birthday   = (string)result["birthday"],
                                Email      = (string)result["email"],
                                UserName   = (string)result["username"]
                            });
                        });
                    }
                    else
                    {
                        Alert("Failed to log in", "Reason: " + error, false, (res) => {});
                    }
                });

                /*
                 * var request = new RestRequest ();
                 * request.RequestFinished += (object sender, RequestEndedArgs e) => {
                 *      Globals.DeleteProfileId();
                 *      RunOnUiThread(delegate {
                 *              var id = (string)JsonConvert.DeserializeObject(e.Result, typeof(string));
                 *              Globals.SaveProfileId(id);
                 *              StartActivity (main);
                 *      });
                 * };
                 * request.Send(RequestConfig.Facebook*/

                break;

            case Result.Canceled:
                Alert("Failed to log in.", "User Cancelled", false, (res) => {});
                break;

            default:
                Alert("Something went wrong, please try again in a few minutes.", "Oops!", false, (res) => {});
                break;
            }
            ;
        }
Пример #4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.SignUp);
            Console.WriteLine("SignUpActivity");

            ImageView logo = FindViewById <ImageView> (Resource.Id.ActionBarLogo);

            logo.Visibility = ViewStates.Invisible;

            ImageView menu = FindViewById <ImageView> (Resource.Id.ActionBarMenu);

            menu.Visibility = ViewStates.Invisible;

            TextView title = FindViewById <TextView> (Resource.Id.ActionBarTitle);

            title.Text = "Sign Up";

            Button back = FindViewById <Button> (Resource.Id.ActionBarBack);

            back.Click += delegate {
                Finish();
            };
            // Create your application here

            Button      createAcc  = FindViewById <Button> (Resource.Id.createAccButton);
            Button      choseImage = FindViewById <Button> (Resource.Id.Chose);
            ImageButton facebook   = FindViewById <ImageButton> (Resource.Id.signUpViaFacebook);
            ImageButton twitter    = FindViewById <ImageButton> (Resource.Id.signUpViaTwitter);
            ImageButton googlePlus = FindViewById <ImageButton> (Resource.Id.signUpViaGoogle);
            EditText    firstName  = FindViewById <EditText> (Resource.Id.FirstName);
            EditText    lastName   = FindViewById <EditText> (Resource.Id.LastName);
            EditText    email      = FindViewById <EditText> (Resource.Id.Email);
            EditText    password   = FindViewById <EditText> (Resource.Id.Password);
            var         customize  = new Intent(this, typeof(CustomizingSelectionActivity));

            // Create your application here

            choseImage.Click += delegate {
                var imageIntent = new Intent();
                imageIntent.SetType("image/*");
                imageIntent.SetAction(Intent.ActionGetContent);
                StartActivityForResult(
                    Intent.CreateChooser(imageIntent, "Select photo"), 0);
            };


            /*firstName.KeyPress += (object sender, View.KeyEventArgs e) => {
             *      e.Handled = false;
             *      if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) {
             *              Globals.firstName = firstName.Text;
             *
             *              var inputManager = GetSystemService(InputMethodService) as InputMethodManager;
             *              inputManager.HideSoftInputFromWindow(firstName.WindowToken, 0);
             *      }
             * };
             *
             * lastName.KeyPress += (object sender, View.KeyEventArgs e) => {
             *      e.Handled = false;
             *      if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) {
             *              Globals.lastName = lastName.Text;
             *
             *              var inputManager = GetSystemService(InputMethodService) as InputMethodManager;
             *              inputManager.HideSoftInputFromWindow(firstName.WindowToken, 0);
             *      }
             * };
             *
             * email.KeyPress += (object sender, View.KeyEventArgs e) => {
             *      e.Handled = false;
             *      if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) {
             *              Globals.email = email.Text;
             *              var inputManager = GetSystemService(InputMethodService) as InputMethodManager;
             *              inputManager.HideSoftInputFromWindow(email.WindowToken, 0);
             *      }
             * };
             *
             * password.KeyPress += (object sender, View.KeyEventArgs e) => {
             *      e.Handled = false;
             *      if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter) {
             *
             *              var inputManager = GetSystemService(InputMethodService) as InputMethodManager;
             *              inputManager.HideSoftInputFromWindow(password.WindowToken, 0);
             *      }
             * };*/
            firstName.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
            };
            lastName.TextChanged  += (object sender, Android.Text.TextChangedEventArgs e) => {
            };
            email.TextChanged     += (object sender, Android.Text.TextChangedEventArgs e) => {
            };
            password.TextChanged  += (object sender, Android.Text.TextChangedEventArgs e) => {
            };

            this.fName = Globals.firstName;
            this.lName = Globals.lastName;


            createAcc.Click += delegate {
                var model = new RegisterModel {
                    Email = email.Text, FirstName = firstName.Text, LastName = lastName.Text, Password = password.Text.Trim()
                };
                var request = new RestRequest();
                request.RequestFinished += (object sender, RequestEndedArgs e) => {
                    var id = (string)JsonConvert.DeserializeObject(e.Result, typeof(string));
                    Globals.SaveProfileId(id);
                    StartActivity(customize);
                };
                request.Send(RequestConfig.Register, "POST", model);
            };

            facebook.Click += delegate {
                Console.WriteLine("Just clicked signup via Facebook");
            };

            twitter.Click += delegate {
                Console.WriteLine("Just clicked signup via Twitter");
            };

            googlePlus.Click += delegate {
                Console.WriteLine("Just clicked login via Google Plus");
            };
        }