use of com.facebook.Session in project phonegap-facebook-plugin by Wizcorp.
the class SessionTracker method setSession.
/**
* Set the Session object to track.
*
* @param newSession the new Session object to track
*/
public void setSession(Session newSession) {
if (newSession == null) {
if (session != null) {
// We're current tracking a Session. Remove the callback
// and start tracking the active Session.
session.removeCallback(callback);
session = null;
addBroadcastReceiver();
if (getSession() != null) {
getSession().addCallback(callback);
}
}
} else {
if (session == null) {
// We're currently tracking the active Session, but will be
// switching to tracking a different Session object.
Session activeSession = Session.getActiveSession();
if (activeSession != null) {
activeSession.removeCallback(callback);
}
broadcastManager.unregisterReceiver(receiver);
} else {
// We're currently tracking a Session, but are now switching
// to a new Session, so we remove the callback from the old
// Session, and add it to the new one.
session.removeCallback(callback);
}
session = newSession;
session.addCallback(callback);
}
}
use of com.facebook.Session in project phonegap-facebook-plugin by Wizcorp.
the class ConnectPlugin method initialize.
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
//Initialize UiLifecycleHelper
uiHelper = new UiLifecycleHelper(cordova.getActivity(), null);
// Init logger
logger = AppEventsLogger.newLogger(cordova.getActivity());
int appResId = cordova.getActivity().getResources().getIdentifier("fb_app_id", "string", cordova.getActivity().getPackageName());
applicationId = cordova.getActivity().getString(appResId);
// Set up the activity result callback to this class
cordova.setActivityResultCallback(this);
// Open a session if we have one cached
Session session = new Session.Builder(cordova.getActivity()).setApplicationId(applicationId).build();
if (session.getState() == SessionState.CREATED_TOKEN_LOADED) {
Session.setActiveSession(session);
// - Create the request
Session.OpenRequest openRequest = new Session.OpenRequest(cordova.getActivity());
// - Set the status change call back
openRequest.setCallback(new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(state, exception);
}
});
session.openForRead(openRequest);
}
// If we have a valid open session, get user's info
if (checkActiveSession(session)) {
// Call this method to initialize the session state info
onSessionStateChange(session.getState(), null);
}
super.initialize(cordova, webView);
}
use of com.facebook.Session in project phonegap-facebook-plugin by Wizcorp.
the class ConnectPlugin method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Log.d(TAG, "activity result in plugin: requestCode(" + requestCode + "), resultCode(" + resultCode + ")");
if (trackingPendingCall) {
uiHelper.onActivityResult(requestCode, resultCode, intent, new FacebookDialog.Callback() {
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.e("Activity", String.format("Error: %s", error.toString()));
handleError(error, showDialogContext);
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.i("Activity", "Success!");
handleSuccess(data);
}
});
} else {
Session session = Session.getActiveSession();
if (session != null && loginContext != null) {
session.onActivityResult(cordova.getActivity(), requestCode, resultCode, intent);
}
}
trackingPendingCall = false;
}
use of com.facebook.Session in project Klyph by jonathangerbaud.
the class StreamFragment method handleReplyAction.
private void handleReplyAction(final Comment comment) {
pendingReplyComment = false;
pendingCommentReply = comment;
Session session = Session.getActiveSession();
List<String> permissions = session.getPermissions();
if (!permissions.containsAll(PERMISSIONS)) {
pendingReplyComment = true;
requestPublishPermissions(session);
return;
}
replyToComment(comment);
}
use of com.facebook.Session in project Klyph by jonathangerbaud.
the class SessionTracker method setSession.
/**
* Set the Session object to track.
*
* @param newSession the new Session object to track
*/
public void setSession(Session newSession) {
if (newSession == null) {
if (session != null) {
// We're current tracking a Session. Remove the callback
// and start tracking the active Session.
session.removeCallback(callback);
session = null;
addBroadcastReceiver();
if (getSession() != null) {
getSession().addCallback(callback);
}
}
} else {
if (session == null) {
// We're currently tracking the active Session, but will be
// switching to tracking a different Session object.
Session activeSession = Session.getActiveSession();
if (activeSession != null) {
activeSession.removeCallback(callback);
}
broadcastManager.unregisterReceiver(receiver);
} else {
// We're currently tracking a Session, but are now switching
// to a new Session, so we remove the callback from the old
// Session, and add it to the new one.
session.removeCallback(callback);
}
session = newSession;
session.addCallback(callback);
}
}
Aggregations