Exemplo n.º 1
0
        public void Init(Activity activity, Facebook fb, String[] permissions)
        {
            mActivity    = activity;
            mFb          = fb;
            mPermissions = permissions;
            mHandler     = new Handler();

            SetBackgroundColor(Color.Transparent);
            SetAdjustViewBounds(true);
            SetImageResource(fb.IsSessionValid ?
                             Resource.Drawable.logout_button :
                             Resource.Drawable.login_button);
            DrawableStateChanged();

            SessionEvents.AddAuthListener(mSessionListener);
            SessionEvents.AddLogoutListener(mSessionListener);
            SetOnClickListener(new ButtonOnClickListener(this));
        }
Exemplo n.º 2
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;
        }