use of com.facebook.FacebookCallback in project facebook-android-sdk by facebook.
the class ShareApi method sharePhotoContent.
private void sharePhotoContent(final SharePhotoContent photoContent, final FacebookCallback<Sharer.Result> callback) {
final Mutable<Integer> requestCount = new Mutable<Integer>(0);
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
final ArrayList<GraphRequest> requests = new ArrayList<GraphRequest>();
final ArrayList<JSONObject> results = new ArrayList<JSONObject>();
final ArrayList<GraphResponse> errorResponses = new ArrayList<GraphResponse>();
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject result = response.getJSONObject();
if (result != null) {
results.add(result);
}
if (response.getError() != null) {
errorResponses.add(response);
}
requestCount.value -= 1;
if (requestCount.value == 0) {
if (!errorResponses.isEmpty()) {
ShareInternalUtility.invokeCallbackWithResults(callback, null, errorResponses.get(0));
} else if (!results.isEmpty()) {
final String postId = results.get(0).optString("id");
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
}
}
};
try {
for (SharePhoto photo : photoContent.getPhotos()) {
Bundle params;
try {
params = getSharePhotoCommonParameters(photo, photoContent);
} catch (JSONException e) {
ShareInternalUtility.invokeCallbackWithException(callback, e);
return;
}
final Bitmap bitmap = photo.getBitmap();
final Uri photoUri = photo.getImageUrl();
String caption = photo.getCaption();
if (caption == null) {
caption = this.getMessage();
}
if (bitmap != null) {
requests.add(GraphRequest.newUploadPhotoRequest(accessToken, getGraphPath(PHOTOS_EDGE), bitmap, caption, params, requestCallback));
} else if (photoUri != null) {
requests.add(GraphRequest.newUploadPhotoRequest(accessToken, getGraphPath(PHOTOS_EDGE), photoUri, caption, params, requestCallback));
}
}
requestCount.value += requests.size();
for (GraphRequest request : requests) {
request.executeAsync();
}
} catch (final FileNotFoundException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}
use of com.facebook.FacebookCallback in project facebook-android-sdk by facebook.
the class CreateAppGroupDialog method registerCallbackImpl.
@Override
protected void registerCallbackImpl(final CallbackManagerImpl callbackManager, final FacebookCallback<Result> callback) {
final ResultProcessor resultProcessor = (callback == null) ? null : new ResultProcessor(callback) {
@Override
public void onSuccess(AppCall appCall, Bundle results) {
callback.onSuccess(new Result(results.getString("id")));
}
};
CallbackManagerImpl.Callback callbackManagerCallback = new CallbackManagerImpl.Callback() {
@Override
public boolean onActivityResult(int resultCode, Intent data) {
return ShareInternalUtility.handleActivityResult(getRequestCode(), resultCode, data, resultProcessor);
}
};
callbackManager.registerCallback(getRequestCode(), callbackManagerCallback);
}
use of com.facebook.FacebookCallback in project facebook-android-sdk by facebook.
the class ShareApi method shareLinkContent.
private void shareLinkContent(final ShareLinkContent linkContent, final FacebookCallback<Sharer.Result> callback) {
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject data = response.getJSONObject();
final String postId = (data == null ? null : data.optString("id"));
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
};
final Bundle parameters = new Bundle();
this.addCommonParameters(parameters, linkContent);
parameters.putString("message", this.getMessage());
parameters.putString("link", Utility.getUriString(linkContent.getContentUrl()));
parameters.putString("picture", Utility.getUriString(linkContent.getImageUrl()));
parameters.putString("name", linkContent.getContentTitle());
parameters.putString("description", linkContent.getContentDescription());
parameters.putString("ref", linkContent.getRef());
new GraphRequest(AccessToken.getCurrentAccessToken(), getGraphPath("feed"), parameters, HttpMethod.POST, requestCallback).executeAsync();
}
use of com.facebook.FacebookCallback in project facebook-android-sdk by facebook.
the class ShareApi method shareOpenGraphContent.
private void shareOpenGraphContent(final ShareOpenGraphContent openGraphContent, final FacebookCallback<Sharer.Result> callback) {
// In order to create a new Open Graph action using a custom object that does not already
// exist (objectID or URL), you must first send a request to post the object and then
// another to post the action. If a local image is supplied with the object or action, that
// must be staged first and then referenced by the staging URL that is returned by that
// request.
final GraphRequest.Callback requestCallback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
final JSONObject data = response.getJSONObject();
final String postId = (data == null ? null : data.optString("id"));
ShareInternalUtility.invokeCallbackWithResults(callback, postId, response);
}
};
final ShareOpenGraphAction action = openGraphContent.getAction();
final Bundle parameters = action.getBundle();
this.addCommonParameters(parameters, openGraphContent);
if (!Utility.isNullOrEmpty(this.getMessage())) {
parameters.putString("message", this.getMessage());
}
final CollectionMapper.OnMapperCompleteListener stageCallback = new CollectionMapper.OnMapperCompleteListener() {
@Override
public void onComplete() {
try {
handleImagesOnAction(parameters);
new GraphRequest(AccessToken.getCurrentAccessToken(), getGraphPath(URLEncoder.encode(action.getActionType(), DEFAULT_CHARSET)), parameters, HttpMethod.POST, requestCallback).executeAsync();
} catch (final UnsupportedEncodingException ex) {
ShareInternalUtility.invokeCallbackWithException(callback, ex);
}
}
@Override
public void onError(FacebookException exception) {
ShareInternalUtility.invokeCallbackWithException(callback, exception);
}
};
this.stageOpenGraphAction(parameters, stageCallback);
}
use of com.facebook.FacebookCallback in project facebook-android-sdk by facebook.
the class FacebookLoginActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook_login);
callbackManager = CallbackManager.Factory.create();
fbLoginButton = (LoginButton) findViewById(R.id._fb_login);
profilePictureView = (ProfilePictureView) findViewById(R.id.user_pic);
profilePictureView.setCropped(true);
userNameView = (TextView) findViewById(R.id.user_name);
final Button deAuthButton = (Button) findViewById(R.id.deauth);
deAuthButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!isLoggedIn()) {
Toast.makeText(FacebookLoginActivity.this, R.string.app_not_logged_in, Toast.LENGTH_LONG).show();
return;
}
GraphRequest.Callback callback = new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
try {
if (response.getError() != null) {
Toast.makeText(FacebookLoginActivity.this, getResources().getString(R.string.failed_to_deauth, response.toString()), Toast.LENGTH_LONG).show();
} else if (response.getJSONObject().getBoolean(SUCCESS)) {
LoginManager.getInstance().logOut();
// updateUI();?
}
} catch (JSONException ex) {
/* no op */
}
}
};
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), GRAPH_PATH, new Bundle(), HttpMethod.DELETE, callback);
request.executeAsync();
}
});
final Button permsButton = (Button) findViewById(R.id.perms);
permsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(final View v) {
Intent selectPermsIntent = new Intent(FacebookLoginActivity.this, PermissionSelectActivity.class);
startActivityForResult(selectPermsIntent, PICK_PERMS_REQUEST);
}
});
// Callback registration
fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(final LoginResult loginResult) {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.success, Toast.LENGTH_LONG).show();
updateUI();
}
@Override
public void onCancel() {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.cancel, Toast.LENGTH_LONG).show();
}
@Override
public void onError(final FacebookException exception) {
// App code
Toast.makeText(FacebookLoginActivity.this, R.string.error, Toast.LENGTH_LONG).show();
}
});
new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(final Profile oldProfile, final Profile currentProfile) {
updateUI();
}
};
}
Aggregations