I have a facebook dialog in the screen in which I put a button on the top right of the page (next to the Facebook`s login page). What I want to do is, if the user hits that button, dismiss the Facebook Dialog and pass some values for the activity that started the Facebook dialog (that is, the activity who called:
mFacebook.authorize(this, Settings.FACEBOOK_PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
The problem is that I only know how to dismiss the Facebook dialog WITHOUT BEING ABLE TO PASS ANY PARAMETERS TO IT, because the callback function onCancel() of the DialogListener doesnt receive a Bundle. I cant pass parameters back to the original activity (I could if the signature was onCancel(Bundle bundle) ).
In other words, what I want is either something like a onCancel(Bundle bundle) (which, unfortunately, doesn`t exist) or a way to programatically return to the callback onComplete(Bundle values) because, that way, I could read the Bundle values that I had set while the Facebook dialog was on the screen).
Thank you in advance!
Update (Code)
private class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
Settings.setFBStats(Settings.getFBStats() + 1);
facebookPost();
Util.showThanks(PhotoActivity.this, galleryName);
}
public void onFacebookError(FacebookError error) {
}
public void onError(DialogError error) {
}
public void onCancel() {
System.out.println("Hi! =D");
}
}
public void facebook(View target) {
mFacebook = new Facebook( getString(R.string.facebookappid) );
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mAsyncRunner.logout(this, new LogoutRequestListener());
mFacebook.authorize(this, Settings.FACEBOOK_PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
And here is the code inside the FbDialog.java`s onCreate() method:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSpinner = new ProgressDialog(getContext());
mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE);
mSpinner.setMessage("Loading...");
requestWindowFeature(Window.FEATURE_NO_TITLE);
mContent = new FrameLayout(getContext());
/* Create the 'x' image, but don't add to the mContent layout yet
* at this point, we only need to know its drawable width and height
* to place the webview
*/
createCrossImage();
overlay = new ImageView(getContext());
overlay.setImageDrawable(getContext().getResources().getDrawable(R.drawable.overlay_horiz));
overlay.setTop(0);
overlay.setLeft(0);
overlay.setVisibility(View.INVISIBLE);
/* Now we know 'x' drawable width and height,
* layout the webivew and add it the mContent layout
*/
int crossWidth = mCrossImage.getDrawable().getIntrinsicWidth();
setUpWebView(crossWidth / 2);
/* Finally add the 'x' image to the mContent layout and
* add mContent to the Dialog view
*/
mContent.addView(mCrossImage, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
FrameLayout main = new FrameLayout(getContext());
main.addView(overlay, new LayoutParams(1280, 755));
RelativeLayout rel = new RelativeLayout(getContext());
mContent.setPadding(450, 60, 0, 0);
rel.addView(mContent, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
closeIt = new ImageButton(getContext());
closeIt.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.closefb));
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(282, 150);
lp.setMargins(980, 10, 0, 0);
closeIt.setVisibility(View.INVISIBLE);
closeIt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onCancel();
FbDialog.this.hide();//HERE!!! =D
}
});
rel.addView(closeIt,lp);
main.addView(rel, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
addContentView(main, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
The button that I am talking about is the closeIt button.
Do you see the setOnClickListener method of the closeIt button? So, I am only able to dismiss or hide the button. When I do any of that (dismiss or hide), the onCancel() method of the LoginDialogListener is called. The problem is that I cannot detect that it came from that button, because the flow also goes to that very same onCancel() method when the user presses de default X button next to the facebook dialog. If I am able to detect that it came from my button, then I can do some other things I want in the code.
Thank you once again.
Change
Facebook.DialogListenerclass and add a newonCancel(Bundle)function to it, (You may also change the existingonCancel()toonCancel(Bundle), but this should be avoided to maintain compatibility with the existing code.), then callonCancel(bundle)inonClick()ofcloseItbutton.OR
if
LoginDialogListeneris accessible inFbDialogthen define a new functiononCancel(Bundle)in it (You may use anyObjectinstead ofBundle). Then in youronClick()ofcloseItbutton, callOR
Define a new subclass of
Facebook.DialogListener, Lets say itclassA, having a newonCancel(Bundle)function. ThisclassAshould be visible toFbDialog. Now redefine yourLoginDialogListenerso that it is a subclass ofclassA. In youronClick()ofcloseItbutton, callHope it helps !!