use of org.brickred.socialauth.util.Response in project android-app-common-tasks by multidots.
the class SocialAuthAdapter method uploadImage.
/**
* Synchronous Method to upload image on provider
*
* @param message message to be attached with image
* @param fileName image file name
* @param bitmap image bitmap to be uploaded
* @param quality image quality for jpeg , enter 0 for png
* <p/>
* Returns result in onReceive()
*/
public Integer uploadImage(String message, String fileName, Bitmap bitmap, int quality) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (fileName.endsWith("PNG") || fileName.endsWith("png")) {
bitmap.compress(CompressFormat.PNG, 0, bos);
} else if (fileName.endsWith("JPEG") || fileName.endsWith("JPG") || fileName.endsWith("jpg") || fileName.endsWith("jpeg")) {
bitmap.compress(CompressFormat.JPEG, quality, bos);
} else {
throw new SocialAuthException("Image Format not supported");
}
InputStream inputStream = new ByteArrayInputStream(bos.toByteArray());
Response res;
try {
//noinspection ConstantConditions
if (getCurrentProvider().getProviderId().equalsIgnoreCase("facebook") || getCurrentProvider().getProviderId().equalsIgnoreCase("twitter")) {
res = getCurrentProvider().uploadImage(message, fileName, inputStream);
Log.d("SocialAuthAdapter", "Image Uploaded");
return res.getStatus();
} else {
throw new SocialAuthException("Provider not Supported");
}
} catch (Exception e) {
throw new SocialAuthException("Image Upload Error");
}
}
use of org.brickred.socialauth.util.Response in project socialauth-android by 3pillarlabs.
the class SocialAuthAdapter method uploadImage.
/**
* Synchronous Method to upload image on provider
*
* @param message
* message to be attached with image
* @param fileName
* image file name
* @param bitmap
* image bitmap to be uploaded
* @param quality
* image quality for jpeg , enter 0 for png
*
* Returns result in onReceive()
*/
public Integer uploadImage(String message, String fileName, Bitmap bitmap, int quality) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
if (fileName.endsWith("PNG") || fileName.endsWith("png")) {
bitmap.compress(CompressFormat.PNG, 0, bos);
} else if (fileName.endsWith("JPEG") || fileName.endsWith("JPG") || fileName.endsWith("jpg") || fileName.endsWith("jpeg")) {
bitmap.compress(CompressFormat.JPEG, quality, bos);
} else {
throw new SocialAuthException("Image Format not supported");
}
InputStream inputStream = new ByteArrayInputStream(bos.toByteArray());
Response res = null;
try {
if (getCurrentProvider().getProviderId().equalsIgnoreCase("facebook") || getCurrentProvider().getProviderId().equalsIgnoreCase("twitter")) {
res = getCurrentProvider().uploadImage(message, fileName, inputStream);
Log.d("SocialAuthAdapter", "Image Uploaded");
return Integer.valueOf(res.getStatus());
} else {
throw new SocialAuthException("Provider not Supported");
}
} catch (Exception e) {
throw new SocialAuthException("Image Upload Error");
}
}
use of org.brickred.socialauth.util.Response in project socialauth-android by 3pillarlabs.
the class SocialAuthAdapter method updateStatus.
/**
* Method to update status of user
*
* @param message
* The message to be send.
* @param listener
* socialAuth listener to get status
* @param shareOption
* true - share on all providers false - share on current
* provider
*/
public void updateStatus(final String message, final SocialAuthListener<Integer> listener, final boolean shareOption) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
if (shareOption == true) {
final List<String> activeProviders = socialAuthManager.getConnectedProvidersIds();
for (int i = 0; i < activeProviders.size(); i++) {
final String provider = activeProviders.get(i);
final Response response = socialAuthManager.getProvider(provider).updateStatus(message);
handler.post(new Runnable() {
@Override
public void run() {
int status = response.getStatus();
listener.onExecute(provider, Integer.valueOf(status));
}
});
}
} else {
final Response response = getCurrentProvider().updateStatus(message);
handler.post(new Runnable() {
@Override
public void run() {
int status = response.getStatus();
listener.onExecute(getCurrentProvider().getProviderId(), Integer.valueOf(status));
}
});
}
} catch (Exception e) {
dialogListener.onError(new SocialAuthError("Message Not Posted", e));
}
}
};
new Thread(runnable).start();
}
use of org.brickred.socialauth.util.Response in project android-app-common-tasks by multidots.
the class SocialAuthAdapter method updateStatus.
/**
* Method to update status of user
*
* @param message The message to be send.
* @param listener socialAuth listener to get status
* @param shareOption true - share on all providers false - share on current
* provider
*/
public void updateStatus(final String message, final SocialAuthListener<Integer> listener, final boolean shareOption) {
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
if (shareOption) {
final List<String> activeProviders = socialAuthManager.getConnectedProvidersIds();
for (int i = 0; i < activeProviders.size(); i++) {
final String provider = activeProviders.get(i);
final Response response = socialAuthManager.getProvider(provider).updateStatus(message);
handler.post(new Runnable() {
@Override
public void run() {
int status = response.getStatus();
listener.onExecute(provider, status);
}
});
}
} else {
@SuppressWarnings("ConstantConditions") final Response response = getCurrentProvider().updateStatus(message);
handler.post(new Runnable() {
@Override
public void run() {
int status = response.getStatus();
listener.onExecute(getCurrentProvider().getProviderId(), status);
}
});
}
} catch (Exception e) {
dialogListener.onError(new SocialAuthError("Message Not Posted", e));
}
}
};
new Thread(runnable).start();
}
Aggregations