/*
ApicAday - Everyday.. is different, your mood, your life.
Copyright (c) 2010
Oliver Selinger <oliver.selinger@autburst.com>,
Michael Greifeneder <michael.greifeneder@autburst.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.autburst.picture;
import java.io.File;
import java.io.FileOutputStream;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.AsyncTask;
import android.os.Handler;
import android.util.Log;
public class SavePhotoAsyncTask extends AsyncTask<byte[], String, String> {
private String name;
private String albumName;
private boolean isPortrait;
private Handler handler;
public SavePhotoAsyncTask(String albumName, String name, boolean isPortrait, Handler handler) {
this.name = name;
this.albumName = albumName;
this.isPortrait = isPortrait;
this.handler = handler;
}
@Override
protected String doInBackground(byte[]... jpeg) {
File dir = Utilities.getAlbumDirectory(albumName);
File photo = new File(dir, name);
if (photo.exists()) {
photo.delete();
}
try {
FileOutputStream fos=new FileOutputStream(photo.getAbsolutePath());
fos.write(jpeg[0]);
fos.close();
if (isPortrait) {
Bitmap bmp = BitmapFactory.decodeFile(photo.getAbsolutePath());
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
fos = new FileOutputStream(photo.getAbsolutePath());
rotated.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
}
//Message msg = Message.obtain();
//msg.what = Utilities.MSG_FINISHED_PIC_SAVING;
//handler.sendMessage(msg);
}
catch (java.io.IOException e) {
Log.e("PictureDemo", "Exception in photoCallback", e);
}
return(null);
}
}