コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Initialize the SDK before executing any other operations
            FacebookSdk.SdkInitialize(Application.Context);

            // create callback manager using CallbackManagerFactory
            callbackManager = CallbackManagerFactory.Create();

            LoginManager.Instance.RegisterCallback(callbackManager, new MyFacebookCallback <LoginResult>(this));

            shareDialog   = new ShareDialog(this);
            shareCallback = new MySharedDialogCallback <SharerResult>(this);
            shareDialog.RegisterCallback(callbackManager, shareCallback);

            if (savedInstanceState != null)
            {
                var name = savedInstanceState.GetString(PENDING_ACTION_BUNDLE_KEY);
                System.Enum.TryParse(name, true, out pendingAction);
            }

            SetContentView(Resource.Layout.main);

            profileTracker = new MyProfileTracker(this);

            profilePictureView = FindViewById <ProfilePictureView>(Resource.Id.profilePicture);
            greeting           = FindViewById <TextView>(Resource.Id.greeting);

            postStatusUpdateButton        = FindViewById <Button>(Resource.Id.postStatusUpdateButton);
            postStatusUpdateButton.Click += (sender, args) =>
            {
                OnClickPostStatusUpdate();
            };

            postPhotoButton        = FindViewById <Button>(Resource.Id.postPhotoButton);
            postPhotoButton.Click += (sender, args) =>
            {
                OnClickPostPhoto();
            };

            // Can we present the share dialog for regular links?
            canPresentShareDialog = ShareDialog.CanShow(Class.FromType(typeof(ShareLinkContent)));

            // Can we present the share dialog for photos?
            canPresentShareDialogWithPhotos = ShareDialog.CanShow(Class.FromType(typeof(SharePhotoContent)));
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            FacebookSdk.SdkInitialize(this.ApplicationContext);

            callbackManager = CallbackManagerFactory.Create();

            var loginCallback = new FacebookCallback <LoginResult> {
                HandleSuccess = loginResult => {
                    HandlePendingAction();
                    UpdateUI();
                },
                HandleCancel = () => {
                    if (pendingAction != PendingAction.NONE)
                    {
                        ShowAlert(
                            GetString(Resource.String.cancelled),
                            GetString(Resource.String.permission_not_granted));
                        pendingAction = PendingAction.NONE;
                    }
                    UpdateUI();
                },
                HandleError = loginError => {
                    if (pendingAction != PendingAction.NONE &&
                        loginError is FacebookAuthorizationException)
                    {
                        ShowAlert(
                            GetString(Resource.String.cancelled),
                            GetString(Resource.String.permission_not_granted));
                        pendingAction = PendingAction.NONE;
                    }
                    UpdateUI();
                }
            };

            LoginManager.Instance.RegisterCallback(callbackManager, loginCallback);

            shareCallback = new FacebookCallback <SharerResult> {
                HandleSuccess = shareResult => {
                    Console.WriteLine("HelloFacebook: Success!");

                    if (shareResult.PostId != null)
                    {
                        var title    = Parent.GetString(Resource.String.error);
                        var id       = shareResult.PostId;
                        var alertMsg = Parent.GetString(Resource.String.successfully_posted_post, id);

                        ShowAlert(title, alertMsg);
                    }
                },
                HandleCancel = () => {
                    Console.WriteLine("HelloFacebook: Canceled");
                },
                HandleError = shareError => {
                    Console.WriteLine("HelloFacebook: Error: {0}", shareError);

                    var title    = Parent.GetString(Resource.String.error);
                    var alertMsg = shareError.Message;

                    ShowAlert(title, alertMsg);
                }
            };

            shareDialog = new ShareDialog(this);
            shareDialog.RegisterCallback(callbackManager, shareCallback);

            if (savedInstanceState != null)
            {
                var name = savedInstanceState.GetString(PENDING_ACTION_BUNDLE_KEY);
                pendingAction = (PendingAction)Enum.Parse(typeof(PendingAction), name);
            }

            SetContentView(Resource.Layout.main);

            profileTracker = new CustomProfileTracker {
                HandleCurrentProfileChanged = (oldProfile, currentProfile) => {
                    UpdateUI();
                    HandlePendingAction();
                }
            };

            profilePictureView = FindViewById <ProfilePictureView> (Resource.Id.profilePicture);

            greeting = FindViewById <TextView> (Resource.Id.greeting);

            postStatusUpdateButton        = FindViewById <Button> (Resource.Id.postStatusUpdateButton);
            postStatusUpdateButton.Click += (sender, e) => {
                PerformPublish(PendingAction.POST_STATUS_UPDATE, canPresentShareDialog);
            };

            postPhotoButton        = FindViewById <Button> (Resource.Id.postPhotoButton);
            postPhotoButton.Click += (sender, e) => {
                PerformPublish(PendingAction.POST_PHOTO, canPresentShareDialogWithPhotos);
            };

            // Can we present the share dialog for regular links?
            canPresentShareDialog = ShareDialog.CanShow(Java.Lang.Class.FromType(typeof(ShareLinkContent)));

            // Can we present the share dialog for photos?
            canPresentShareDialogWithPhotos = ShareDialog.CanShow(Java.Lang.Class.FromType(typeof(SharePhotoContent)));
        }
コード例 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            try
            {
                FacebookSdk.SdkInitialize(this.ApplicationContext);

                callbackManager = CallbackManagerFactory.Create();
                LoginManager.Instance.RegisterCallback(callbackManager, this);

                LoginManager.Instance.LogInWithReadPermissions(this, LOGIN_PERMISSIONS);
            }
            catch (Exception e)
            {
                string failureInfo = e.ToString();
                Console.WriteLine("FacebookActivity::onCreate() EXCEPTION " + failureInfo);
            }

            SetContentView(Resource.Layout.facebookLoginPage);

            profileTracker = new CustomProfileTracker
            {
                HandleCurrentProfileChanged = (oldProfile, currentProfile) =>
                {
                    UpdateUI();
                }
            };

            // properties applied to all buttons on Facebook login page
            var      padding   = Awpbs.Mobile.Config.OkCancelButtonsPadding;
            var      minHeight = Awpbs.Mobile.Config.OkCancelButtonsHeight;
            Typeface typeface  = Typeface.CreateFromAsset(Resources.Assets, "fonts/Lato-Regular.ttf");

            // Profile Picture
            profilePictureView = FindViewById <ProfilePictureView>(Resource.Id.profilePicture);
            profilePictureView.SetMinimumHeight(minHeight);
            profilePictureView.SetPadding(padding, padding, padding, padding);

            // Greeting "Hello, Alex!", visible when connected to facebook account
            greeting = FindViewById <TextView>(Resource.Id.greeting);
            greeting.SetMinimumHeight(minHeight);
            greeting.SetPadding(padding, padding, padding, padding);
            greeting.SetTypeface(typeface, TypefaceStyle.Bold);
            greeting.SetTextSize(Android.Util.ComplexUnitType.Sp, Config.LargerFontSize);

            //
            // Cancel and Ok buttons at the bottom of the page
            //
            cancelButton = FindViewById <Button>(Resource.Id.CancelButtonFb);
            cancelButton.SetBackgroundColor(Config.ColorBackgroundLogo.ToAndroid());
            cancelButton.SetMinimumHeight(minHeight);
            cancelButton.SetPadding(padding, padding, padding, padding);
            cancelButton.SetTypeface(typeface, TypefaceStyle.Bold);
            cancelButton.SetTextSize(Android.Util.ComplexUnitType.Sp, Config.DefaultFontSize);
            cancelButton.Click += (sender, e) =>
            {
                this.Finish();
                App.FacebookService.OnLoginFailed();
            };

            thisIsMeButton = FindViewById <Button>(Resource.Id.thisIsMeButton);
            thisIsMeButton.SetBackgroundColor(Config.ColorRedBackground.ToAndroid());
            thisIsMeButton.SetMinimumHeight(minHeight);
            thisIsMeButton.SetPadding(padding, padding, padding, padding);
            thisIsMeButton.SetTypeface(typeface, TypefaceStyle.Bold);
            thisIsMeButton.SetTextSize(Android.Util.ComplexUnitType.Sp, Config.DefaultFontSize);
            thisIsMeButton.Click += (sender, e) =>
            {
                this.Finish();
                App.FacebookService.OnLoginSucessful();
            };
        }         // onCreate()