public void OnClick(View arg0) { if (parent.mFb.IsSessionValid) { SessionEvents.OnLogoutBegin(); AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(parent.mFb); asyncRunner.Logout(parent.Context, new LogoutRequestListener(parent)); } else { parent.mFb.Authorize(parent.mActivity, parent.mPermissions, new LoginDialogListener()); } }
/** 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; }
public void OnClick (View arg0) { if (parent.mFb.IsSessionValid) { SessionEvents.OnLogoutBegin (); AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner (parent.mFb); asyncRunner.Logout (parent.Context, new LogoutRequestListener (parent)); } else { parent.mFb.Authorize (parent.mActivity, parent.mPermissions, new LoginDialogListener ()); } }
/** 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; }