use of org.brickred.socialauth.exception.SocialAuthException 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.exception.SocialAuthException in project android-app-common-tasks by multidots.
the class SocialAuthAdapter method uploadImageAsync.
/**
* Asynchronous Method to upload image on provider.Returns result in
* onExecute() of AsyncTaskListener.Currently supports Facebook and Twitter
*
* @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
*/
public void uploadImageAsync(String message, String fileName, Bitmap bitmap, int quality, SocialAuthListener<Integer> listener) 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());
try {
//noinspection ConstantConditions
if (getCurrentProvider().getProviderId().equalsIgnoreCase("facebook") || getCurrentProvider().getProviderId().equalsIgnoreCase("twitter")) {
new UploadImageTask(listener).execute(message, fileName, inputStream);
} else {
throw new SocialAuthException("Provider not Supported");
}
} catch (NullPointerException e) {
e.printStackTrace();
throw new SocialAuthException("Provider not Supported");
}
}
use of org.brickred.socialauth.exception.SocialAuthException 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.exception.SocialAuthException in project socialauth-android by 3pillarlabs.
the class SocialAuthAdapter method uploadImageAsync.
/**
* Asynchronous Method to upload image on provider.Returns result in
* onExecute() of AsyncTaskListener.Currently supports Facebook and Twitter
*
* @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
*/
public void uploadImageAsync(String message, String fileName, Bitmap bitmap, int quality, SocialAuthListener<Integer> listener) 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());
if (getCurrentProvider().getProviderId().equalsIgnoreCase("facebook") || getCurrentProvider().getProviderId().equalsIgnoreCase("twitter")) {
new UploadImageTask(listener).execute(message, fileName, inputStream);
} else {
throw new SocialAuthException("Provider not Supported");
}
}
Aggregations