Search in sources :

Example 11 with LocalDataService

use of com.aviary.android.feather.library.services.LocalDataService in project mobile-android by photo.

the class FeatherActivity method doSave.

/**
	 * Do save.
	 * 
	 * @param bitmap
	 *           the bitmap
	 */
protected void doSave(Bitmap bitmap) {
    // result extras
    Bundle extras = new Bundle();
    LocalDataService service = mFilterManager.getService(LocalDataService.class);
    Uri saveUri = service.getDestImageUri();
    // then save the image into the output uri and return it
    if (saveUri != null) {
        OutputStream outputStream = null;
        String scheme = saveUri.getScheme();
        try {
            if (scheme == null) {
                outputStream = new FileOutputStream(saveUri.getPath());
            } else {
                outputStream = getContentResolver().openOutputStream(saveUri);
            }
            if (outputStream != null) {
                int quality = Constants.getValueFromIntent(Constants.EXTRA_OUTPUT_QUALITY, 80);
                bitmap.compress(service.getOutputFormat(), quality, outputStream);
            }
        } catch (IOException ex) {
            logger.error("Cannot open file", saveUri, ex);
        } finally {
            IOUtils.closeSilently(outputStream);
        }
        onSetResult(RESULT_OK, new Intent().setData(saveUri).putExtras(extras));
    } else {
        // no output uri declared, save the image in a new path
        // and return it
        String url = Media.insertImage(getContentResolver(), bitmap, "title", "modified with Aviary Feather");
        if (url != null) {
            saveUri = Uri.parse(url);
            getContentResolver().notifyChange(saveUri, null);
        }
        onSetResult(RESULT_OK, new Intent().setData(saveUri).putExtras(extras));
    }
    final Bitmap b = bitmap;
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            mImageView.clear();
            b.recycle();
        }
    });
    if (null != saveUri) {
        saveExif(saveUri);
    }
    mSaving = false;
    finish();
}
Also used : LocalDataService(com.aviary.android.feather.library.services.LocalDataService) Bitmap(android.graphics.Bitmap) Bundle(android.os.Bundle) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FeatherIntent(com.aviary.android.feather.library.content.FeatherIntent) Intent(android.content.Intent) IOException(java.io.IOException) Uri(android.net.Uri)

Aggregations

LocalDataService (com.aviary.android.feather.library.services.LocalDataService)11 Bundle (android.os.Bundle)5 Uri (android.net.Uri)4 Intent (android.content.Intent)2 FeatherIntent (com.aviary.android.feather.library.content.FeatherIntent)2 HiResService (com.aviary.android.feather.library.services.HiResService)2 IOException (java.io.IOException)2 Bitmap (android.graphics.Bitmap)1 CompressFormat (android.graphics.Bitmap.CompressFormat)1 ExifTask (com.aviary.android.feather.async_tasks.ExifTask)1 ExifInterfaceWrapper (com.aviary.android.feather.library.media.ExifInterfaceWrapper)1 FutureListener (com.aviary.android.feather.library.services.FutureListener)1 ThreadPoolService (com.aviary.android.feather.library.services.ThreadPoolService)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Future (java.util.concurrent.Future)1