Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
14792 manas 1
/**
2
 * Copyright 2010-present Facebook
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *    http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
package com.facebook.android;
18
 
19
import android.content.Context;
20
import android.os.Bundle;
21
import com.facebook.FacebookDialogException;
22
import com.facebook.FacebookException;
23
import com.facebook.FacebookOperationCanceledException;
24
import com.facebook.android.Facebook.DialogListener;
25
import com.facebook.widget.WebDialog;
26
 
27
/**
28
 * This class is deprecated. See {@link com.facebook.widget.WebDialog}.
29
 */
30
@Deprecated
31
public class FbDialog extends WebDialog {
32
    private DialogListener mListener;
33
 
34
    public FbDialog(Context context, String url, DialogListener listener) {
35
        this(context, url, listener, DEFAULT_THEME);
36
    }
37
 
38
    public FbDialog(Context context, String url, DialogListener listener, int theme) {
39
        super(context, url, theme);
40
        setDialogListener(listener);
41
    }
42
 
43
    public FbDialog(Context context, String action, Bundle parameters, DialogListener listener) {
44
        super(context, action, parameters, DEFAULT_THEME, null);
45
        setDialogListener(listener);
46
    }
47
 
48
    public FbDialog(Context context, String action, Bundle parameters, DialogListener listener,
49
            int theme) {
50
        super(context, action, parameters, theme, null);
51
        setDialogListener(listener);
52
    }
53
 
54
    private void setDialogListener(DialogListener listener) {
55
        this.mListener = listener;
56
        setOnCompleteListener(new OnCompleteListener() {
57
            @Override
58
            public void onComplete(Bundle values, FacebookException error) {
59
                callDialogListener(values, error);
60
            }
61
        });
62
    }
63
 
64
    private void callDialogListener(Bundle values, FacebookException error) {
65
        if (mListener == null) {
66
            return;
67
        }
68
 
69
        if (values != null) {
70
            mListener.onComplete(values);
71
        } else {
72
            if (error instanceof FacebookDialogException) {
73
                FacebookDialogException facebookDialogException = (FacebookDialogException) error;
74
                DialogError dialogError = new DialogError(facebookDialogException.getMessage(),
75
                        facebookDialogException.getErrorCode(), facebookDialogException.getFailingUrl());
76
                mListener.onError(dialogError);
77
            } else if (error instanceof FacebookOperationCanceledException) {
78
                mListener.onCancel();
79
            } else {
80
                FacebookError facebookError = new FacebookError(error.getMessage());
81
                mListener.onFacebookError(facebookError);
82
            }
83
        }
84
    }
85
}