Search in sources :

Example 1 with Response

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");
    }
}
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 Response

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");
    }
}
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 3 with Response

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

Example 4 with Response

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

Aggregations

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