Пример #1
0
		/** Called when the activity is first created. */
		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);

			if (APP_ID == null) {
				Util.ShowAlert (this, "Warning", "Facebook Applicaton ID must be " +
					"specified before running this example: see Example.java");
			}

			SetContentView (Resource.Layout.main);
			mLoginButton = (LoginButton)FindViewById (Resource.Id.login);
			mText = (TextView)FindViewById (Resource.Id.txt);
			mRequestButton = (Button)FindViewById (Resource.Id.requestButton);
			mPostButton = (Button)FindViewById (Resource.Id.postButton);
			mDeleteButton = (Button)FindViewById (Resource.Id.deletePostButton);
			mUploadButton = (Button)FindViewById (Resource.Id.uploadButton);

			mFacebook = new Facebook (APP_ID);
			mAsyncRunner = new AsyncFacebookRunner (mFacebook);

			SessionStore.Restore (mFacebook, this);
			SessionEvents.AddAuthListener (new SampleAuthListener (this));
			SessionEvents.AddLogoutListener (new SampleLogoutListener (this));
			mLoginButton.Init (this, mFacebook);

			mRequestButton.Click += delegate {
				mAsyncRunner.Request ("me", new SampleRequestListener (this));
			};
			mRequestButton.Visibility = mFacebook.IsSessionValid ?
                ViewStates.Visible :
                ViewStates.Invisible;

			mUploadButton.Click += async delegate {
				Bundle parameters = new Bundle ();
				parameters.PutString ("method", "photos.upload");

				URL uploadFileUrl = null;
				try {
					uploadFileUrl = new URL (
						"http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
				} catch (MalformedURLException e) {
					e.PrintStackTrace ();
				}
				try {
					HttpURLConnection conn = (HttpURLConnection)uploadFileUrl.OpenConnection ();
					conn.DoInput = true;
					await conn.ConnectAsync ();
					int length = conn.ContentLength;

					byte[] imgData = new byte[length];
					var ins = conn.InputStream;
					await ins.ReadAsync (imgData, 0, imgData.Length);
					parameters.PutByteArray ("picture", imgData);

				} catch (IOException e) {
					e.PrintStackTrace ();
				}

				mAsyncRunner.Request (null, parameters, "POST",
				                      new SampleUploadListener (this), null);
			};
			mUploadButton.Visibility = mFacebook.IsSessionValid ?
                ViewStates.Visible :
                ViewStates.Invisible;

			mPostButton.Click += delegate {
				mFacebook.Dialog (this, "feed",
				                  new SampleDialogListener (this));
			};
			mPostButton.Visibility = mFacebook.IsSessionValid ?
                ViewStates.Visible :
                ViewStates.Invisible;
		}
Пример #2
0
			public LogoutRequestListener (LoginButton parent)
			{
				this.parent = parent;
			}
Пример #3
0
			public SessionListener (LoginButton parent)
			{
				this.parent = parent;
			}
Пример #4
0
			public ButtonOnClickListener (LoginButton parent)
			{
				this.parent = parent;
			}
Пример #5
0
        /** Called when the activity is first created. */
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (APP_ID == null)
            {
                Util.ShowAlert(this, "Warning", "Facebook Applicaton ID must be " +
                               "specified before running this example: see Example.java");
            }

            SetContentView(Resource.Layout.main);
            mLoginButton   = (LoginButton)FindViewById(Resource.Id.login);
            mText          = (TextView)FindViewById(Resource.Id.txt);
            mRequestButton = (Button)FindViewById(Resource.Id.requestButton);
            mPostButton    = (Button)FindViewById(Resource.Id.postButton);
            mDeleteButton  = (Button)FindViewById(Resource.Id.deletePostButton);
            mUploadButton  = (Button)FindViewById(Resource.Id.uploadButton);

            mFacebook    = new Facebook(APP_ID);
            mAsyncRunner = new AsyncFacebookRunner(mFacebook);

            SessionStore.Restore(mFacebook, this);
            SessionEvents.AddAuthListener(new SampleAuthListener(this));
            SessionEvents.AddLogoutListener(new SampleLogoutListener(this));
            mLoginButton.Init(this, mFacebook);

            mRequestButton.Click += delegate {
                mAsyncRunner.Request("me", new SampleRequestListener(this));
            };
            mRequestButton.Visibility = mFacebook.IsSessionValid ?
                                        ViewStates.Visible :
                                        ViewStates.Invisible;

            mUploadButton.Click += async delegate {
                Bundle parameters = new Bundle();
                parameters.PutString("method", "photos.upload");

                URL uploadFileUrl = null;
                try {
                    uploadFileUrl = new URL(
                        "http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
                } catch (MalformedURLException e) {
                    e.PrintStackTrace();
                }
                try {
                    HttpURLConnection conn = (HttpURLConnection)uploadFileUrl.OpenConnection();
                    conn.DoInput = true;
                    await conn.ConnectAsync();

                    int length = conn.ContentLength;

                    byte[] imgData = new byte[length];
                    var    ins     = conn.InputStream;
                    await ins.ReadAsync(imgData, 0, imgData.Length);

                    parameters.PutByteArray("picture", imgData);
                } catch (IOException e) {
                    e.PrintStackTrace();
                }

                mAsyncRunner.Request(null, parameters, "POST",
                                     new SampleUploadListener(this), null);
            };
            mUploadButton.Visibility = mFacebook.IsSessionValid ?
                                       ViewStates.Visible :
                                       ViewStates.Invisible;

            mPostButton.Click += delegate {
                mFacebook.Dialog(this, "feed",
                                 new SampleDialogListener(this));
            };
            mPostButton.Visibility = mFacebook.IsSessionValid ?
                                     ViewStates.Visible :
                                     ViewStates.Invisible;
        }
Пример #6
0
 public SessionListener(LoginButton parent)
 {
     this.parent = parent;
 }
Пример #7
0
 public LogoutRequestListener(LoginButton parent)
 {
     this.parent = parent;
 }
Пример #8
0
 public ButtonOnClickListener(LoginButton parent)
 {
     this.parent = parent;
 }