Search in sources :

Example 1 with SocialAuthException

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");
    }
}
Also used : Response(org.brickred.socialauth.util.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SocialAuthException(org.brickred.socialauth.exception.SocialAuthException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SocialAuthException(org.brickred.socialauth.exception.SocialAuthException)

Example 2 with SocialAuthException

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");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SocialAuthException(org.brickred.socialauth.exception.SocialAuthException)

Example 3 with SocialAuthException

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");
    }
}
Also used : Response(org.brickred.socialauth.util.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SocialAuthException(org.brickred.socialauth.exception.SocialAuthException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SocialAuthException(org.brickred.socialauth.exception.SocialAuthException)

Example 4 with SocialAuthException

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");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SocialAuthException(org.brickred.socialauth.exception.SocialAuthException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 SocialAuthException (org.brickred.socialauth.exception.SocialAuthException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Response (org.brickred.socialauth.util.Response)2