コード例 #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <FacebookLoginButton> ec)
        {
            base.OnElementChanged(ec);

            var element = ec.NewElement;
            {
                var session = Xamarin.Facebook.AccessToken.CurrentAccessToken;
                element.LoggedIn = session != null;
            }

            var control = new LoginButton(base.Context);

            control.RegisterCallback(MainActivity.CallbackManager, this);
            LoginManager.Instance.RegisterCallback(MainActivity.CallbackManager, this);

            fbTracker = new CustomAccessTokenTracker(base.Element)
            {
            };
            fbTracker.StartTracking();

            if (element.ReadPermissions != null)
            {
                control.SetReadPermissions(element.ReadPermissions);
            }
            else
            {
                if (element.PublishPermissions != null)
                {
                    control.SetPublishPermissions(element.PublishPermissions);
                }
            }

            MessagingCenter.Subscribe(this, "Login", (s) =>
            {
                Login();
            }, element);

            MessagingCenter.Subscribe(this, "Logout", (s) =>
            {
                Logout();
            }, element);

            bool sentInitialEvent = false;

            control.ViewAttachedToWindow += (s, e) =>
            {
                if (!sentInitialEvent && Element != null)
                {
                    sentInitialEvent = true;
                    var session = Xamarin.Facebook.AccessToken.CurrentAccessToken;
                    if (session != null)
                    {
                        LogIn();
                    }
                    else
                    {
                        Element.SendShowingLoggedOutUser();
                    }
                }
            };

            var oldControl = Control;

            SetNativeControl(control);
            if (oldControl != null)
            {
                oldControl.Dispose(); // collect Java Objects on Android
            }
        }
コード例 #2
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            /* Load the view and display it */
            ContentView = R.layout.activity_main;

            /* *************************************
            *              FACEBOOK               *
            ***************************************/
            /* Load the Facebook login button and set up the tracker to monitor access token changes */
            mFacebookCallbackManager    = CallbackManager.Factory.create();
            mFacebookLoginButton        = (LoginButton)findViewById(R.id.login_with_facebook);
            mFacebookAccessTokenTracker = new AccessTokenTrackerAnonymousInnerClassHelper(this);

            /* *************************************
            *               GOOGLE                *
            ***************************************/
            /* Load the Google login button */
            mGoogleLoginButton = (SignInButton)findViewById(R.id.login_with_google);
            mGoogleLoginButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper(this);
            /* Setup the Google API object to allow Google+ logins */
            mGoogleApiClient = (new GoogleApiClient.Builder(this)).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();

            /* *************************************
            *                TWITTER              *
            ***************************************/
            mTwitterLoginButton = (Button)findViewById(R.id.login_with_twitter);
            mTwitterLoginButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper2(this);

            /* *************************************
            *               PASSWORD              *
            ***************************************/
            mPasswordLoginButton = (Button)findViewById(R.id.login_with_password);
            mPasswordLoginButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper3(this);

            /* *************************************
            *              ANONYMOUSLY            *
            ***************************************/
            /* Load and setup the anonymous login button */
            mAnonymousLoginButton = (Button)findViewById(R.id.login_anonymously);
            mAnonymousLoginButton.OnClickListener = new OnClickListenerAnonymousInnerClassHelper4(this);

            /* *************************************
            *               GENERAL               *
            ***************************************/
            mLoggedInStatusTextView = (TextView)findViewById(R.id.login_status);

            /* Create the Firebase ref that is used for all authentication with Firebase */
            mFirebaseRef = new Firebase(Resources.getString([email protected]_url));

            /* Setup the progress dialog that is displayed later when authenticating with Firebase */
            mAuthProgressDialog            = new ProgressDialog(this);
            mAuthProgressDialog.Title      = "Loading";
            mAuthProgressDialog.Message    = "Authenticating with Firebase...";
            mAuthProgressDialog.Cancelable = false;
            mAuthProgressDialog.show();

            mAuthStateListener = new AuthStateListenerAnonymousInnerClassHelper(this);

            /* Check if the user is authenticated with Firebase already. If this is the case we can set the authenticated
             * user and hide hide any login buttons */
            mFirebaseRef.addAuthStateListener(mAuthStateListener);
        }