use of com.facebook.FacebookException in project Klyph by jonathangerbaud.
the class PostActivity method publishPost.
private void publishPost() {
Log.d("PostActivity", "Publish post try " + numTry);
Log.d("PostActivity", "Publish post privacy " + privacy.toString());
if (photoUris.size() > 0) {
publishPhotos();
} else if (shareFragment.isVisible()) {
Bundle params = shareFragment.getParams();
setPrivacyParams(params);
if (shareFragment.isFriendShare()) {
WebDialog dialog = new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(), params).build();
dialog.setOnCompleteListener(new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, close activity
final String postId = values.getString("post_id");
if (postId != null) {
finish();
}
}
}
});
dialog.show();
} else {
params.putString("message", messageTextView.getText().toString());
sendRequest(Query.POST_STATUS, elementId, params);
}
} else if (linkFragment.isVisible()) {
Bundle params = linkFragment.getParams();
params.putString("message", messageTextView.getText().toString());
if (isGroupMessage == false)
setPrivacyParams(params);
// params.putString("privacy", "{'value':'" + privacy.toString() + "'}");
sendRequest(Query.POST_STATUS, elementId, params);
} else {
Bundle params = new Bundle();
params.putString("message", messageTextView.getText().toString());
if (placeId != null && placeId != "") {
params.putString("place", placeId);
if (friends != null && friends.size() > 0) {
StringBuilder ids = new StringBuilder();
for (String key : friends.keySet()) {
ids.append(key).append(",");
}
params.putString("tags", ids.substring(0, ids.length() - 1));
}
}
if (isEventMessage == false && isGroupMessage == false && isPageMessage == false) {
setPrivacyParams(params);
// params.putString("privacy", "{'value':'" + privacy.toString() + "'}");
}
sendRequest(Query.POST_STATUS, elementId, params);
}
}
use of com.facebook.FacebookException in project Klyph by jonathangerbaud.
the class KlyphPlacePickerFragment method onSearchTextTimerTriggered.
private void onSearchTextTimerTriggered() {
if (hasSearchTextChangedSinceLastQuery) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
FacebookException error = null;
try {
loadData(true);
} catch (FacebookException fe) {
error = fe;
} catch (Exception e) {
error = new FacebookException(e);
} finally {
if (error != null) {
OnErrorListener onErrorListener = getOnErrorListener();
if (onErrorListener != null) {
onErrorListener.onError(KlyphPlacePickerFragment.this, error);
} else {
Logger.log(LoggingBehavior.REQUESTS, TAG, "Error loading data : %s", error);
}
}
}
}
});
} else {
// Nothing has changed in 2 seconds. Invalidate and forget about this timer.
// Next time the user types, we will fire a query immediately again.
searchTextTimer.cancel();
searchTextTimer = null;
}
}
use of com.facebook.FacebookException in project openkit-android by OpenKit.
the class ImageDownloader method download.
private static void download(RequestKey key, Context context) {
HttpURLConnection connection = null;
InputStream stream = null;
Exception error = null;
Bitmap bitmap = null;
boolean issueResponse = true;
try {
URL url = new URL(key.uri.toString());
connection = (HttpURLConnection) url.openConnection();
connection.setInstanceFollowRedirects(false);
switch(connection.getResponseCode()) {
case HttpURLConnection.HTTP_MOVED_PERM:
case HttpURLConnection.HTTP_MOVED_TEMP:
// redirect. So we need to perform further requests
issueResponse = false;
String redirectLocation = connection.getHeaderField("location");
if (!Utility.isNullOrEmpty(redirectLocation)) {
URI redirectUri = new URI(redirectLocation);
UrlRedirectCache.cacheUriRedirect(context, key.uri, redirectUri);
// Once the old downloader context is removed, we are thread-safe since this is the
// only reference to it
DownloaderContext downloaderContext = removePendingRequest(key);
if (downloaderContext != null && !downloaderContext.isCancelled) {
enqueueCacheRead(downloaderContext.request, new RequestKey(redirectUri, key.tag), false);
}
}
break;
case HttpURLConnection.HTTP_OK:
// image should be available
stream = ImageResponseCache.interceptAndCacheImageStream(context, connection);
bitmap = BitmapFactory.decodeStream(stream);
break;
default:
stream = connection.getErrorStream();
InputStreamReader reader = new InputStreamReader(stream);
char[] buffer = new char[128];
int bufferLength;
StringBuilder errorMessageBuilder = new StringBuilder();
while ((bufferLength = reader.read(buffer, 0, buffer.length)) > 0) {
errorMessageBuilder.append(buffer, 0, bufferLength);
}
Utility.closeQuietly(reader);
error = new FacebookException(errorMessageBuilder.toString());
break;
}
} catch (IOException e) {
error = e;
} catch (URISyntaxException e) {
error = e;
} finally {
Utility.closeQuietly(stream);
Utility.disconnectQuietly(connection);
}
if (issueResponse) {
issueResponse(key, error, bitmap, false);
}
}
use of com.facebook.FacebookException in project Klyph by jonathangerbaud.
the class ProfilePictureView method processResponse.
private void processResponse(ImageResponse response) {
// 2. Detached this view, in which case the response should be discarded.
if (response.getRequest() == lastRequest) {
lastRequest = null;
Bitmap responseImage = response.getBitmap();
Exception error = response.getError();
if (error != null) {
OnErrorListener listener = onErrorListener;
if (listener != null) {
listener.onError(new FacebookException("Error in downloading profile picture for profileId: " + getProfileId(), error));
} else {
Logger.log(LoggingBehavior.REQUESTS, Log.ERROR, TAG, error.toString());
}
} else if (responseImage != null) {
setImageBitmap(responseImage);
if (response.isCachedRedirect()) {
sendImageRequest(false);
}
}
}
}
use of com.facebook.FacebookException in project Klyph by jonathangerbaud.
the class UserTimeline method publishFeedDialog.
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("from", KlyphSession.getSessionUserId());
params.putString("to", getElementId());
WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(getActivity(), Session.getActiveSession(), params)).setOnCompleteListener(new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
final String postId = values.getString("post_id");
if (postId != null) {
Toast.makeText(getActivity(), R.string.message_successfully_published, Toast.LENGTH_SHORT).show();
loadNewest();
} else {
// User clicked the Cancel button
Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
// Toast.makeText(getActivity().getApplicationContext(),
// "Publish cancelled",
// Toast.LENGTH_SHORT).show();
} else {
AlertUtil.showAlert(getActivity(), R.string.error, R.string.publish_message_unknown_error, R.string.ok);
}
}
}).build();
feedDialog.show();
}
Aggregations