Search in sources :

Example 1 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class SandBoxServicePresenterImpl method makePhoto.

/**
 * 做图
 *
 * @param sandPhoto
 */
private void makePhoto(SandPhoto sandPhoto) {
    byte[] rowData = getDataFromFile(sandPhoto.getFileName(), sandPhoto.getSize());
    if (rowData == null) {
        return;
    }
    byte[] data;
    if (sandPhoto.getImageFormat() == ImageFormat.JPEG) {
        data = rowData;
    } else {
        data = decodeNV21(rowData, sandPhoto.getSandExif().getImageWidth(), sandPhoto.getSandExif().getImageLength());
    }
    if (data == null) {
        return;
    }
    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
    } catch (OutOfMemoryError e) {
        YLog.e(e);
    }
    String fileName = sandPhoto.getTime() + ".jpg";
    if (FilePathUtils.savePhoto(fileName, bitmap)) {
        FilePathUtils.saveSmallPhoto(fileName, bitmap);
    }
    PhotoNote photoNote = new PhotoNote(fileName, sandPhoto.getTime(), sandPhoto.getTime(), "", "", sandPhoto.getTime(), sandPhoto.getTime(), sandPhoto.getCategoryId());
    photoNote.setPaletteColor(Utils.getPaletteColor(bitmap));
    mRxPhotoNote.savePhotoNote(photoNote).subscribe(photoNote1 -> {
    }, (throwable -> YLog.e(throwable)));
    try {
        setExif(photoNote, sandPhoto.getSandExif(), sandPhoto.getCameraId(), sandPhoto.isMirror());
    } catch (IOException e) {
        YLog.e(e);
    }
    deleteFromDBAndSDCard(sandPhoto);
    // bitmap.recycle();
    System.gc();
}
Also used : RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) Rect(android.graphics.Rect) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SandPhoto(com.yydcdut.note.entity.SandPhoto) BitmapFactory(android.graphics.BitmapFactory) ExifInterface(android.media.ExifInterface) Observable(rx.Observable) Inject(javax.inject.Inject) Const(com.yydcdut.note.utils.Const) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Utils(com.yydcdut.note.utils.Utils) ImageFormat(android.graphics.ImageFormat) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SandExif(com.yydcdut.note.entity.SandExif) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Message(android.os.Message) Bitmap(android.graphics.Bitmap) YuvImage(android.graphics.YuvImage) ISandBoxServiceView(com.yydcdut.note.views.service.ISandBoxServiceView) PhotoNote(com.yydcdut.note.entity.PhotoNote) ISandBoxServicePresenter(com.yydcdut.note.presenters.service.ISandBoxServicePresenter) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) InputStream(java.io.InputStream) Bitmap(android.graphics.Bitmap) IOException(java.io.IOException)

Example 2 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class SandBoxServicePresenterImpl method attachView.

@Override
public void attachView(IView iView) {
    mSandBoxServiceView = (ISandBoxServiceView) iView;
    mSandBoxServiceView.notification();
    mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            finishSandBoxService();
        }
    };
    mRxSandBox.findAll().flatMap(sandPhotos -> Observable.from(sandPhotos)).subscribe((sandPhoto -> makePhoto(sandPhoto)), (throwable -> YLog.e(throwable)), (() -> mHandler.sendEmptyMessageDelayed(0, 4000)));
}
Also used : Rect(android.graphics.Rect) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SandPhoto(com.yydcdut.note.entity.SandPhoto) BitmapFactory(android.graphics.BitmapFactory) ExifInterface(android.media.ExifInterface) Observable(rx.Observable) Inject(javax.inject.Inject) Const(com.yydcdut.note.utils.Const) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) Utils(com.yydcdut.note.utils.Utils) ImageFormat(android.graphics.ImageFormat) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SandExif(com.yydcdut.note.entity.SandExif) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Message(android.os.Message) Bitmap(android.graphics.Bitmap) YuvImage(android.graphics.YuvImage) ISandBoxServiceView(com.yydcdut.note.views.service.ISandBoxServiceView) PhotoNote(com.yydcdut.note.entity.PhotoNote) ISandBoxServicePresenter(com.yydcdut.note.presenters.service.ISandBoxServicePresenter) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) InputStream(java.io.InputStream) Message(android.os.Message) Handler(android.os.Handler)

Example 3 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class SandBoxDB method findById.

public synchronized SandPhoto findById(long _id) {
    SandPhoto sandPhoto = null;
    SQLiteDatabase db = mSandSQLite.getReadableDatabase();
    Cursor cursor = db.query(SandSQLite.TABLE, null, "_id = ?", new String[] { _id + "" }, null, null, null, null);
    while (cursor.moveToNext()) {
        long id = cursor.getLong(cursor.getColumnIndex("_id"));
        long time = cursor.getLong(cursor.getColumnIndex("time"));
        String cameraId = cursor.getString(cursor.getColumnIndex("cameraId"));
        String categoryIdString = cursor.getString(cursor.getColumnIndex("category"));
        int categoryId;
        try {
            categoryId = Integer.parseInt(categoryIdString);
        } catch (Exception e) {
            YLog.e(e);
            categoryId = -1;
        }
        String isMirrorString = cursor.getString(cursor.getColumnIndex("mirror"));
        boolean isMirror = isMirrorString.equals("0") ? false : true;
        int ratio = cursor.getInt(cursor.getColumnIndex("ratio"));
        String fileName = cursor.getString(cursor.getColumnIndex("fileName"));
        int size = cursor.getInt(cursor.getColumnIndex("size"));
        int orientation1 = cursor.getInt(cursor.getColumnIndex("orientation_"));
        String latitude = cursor.getString(cursor.getColumnIndex("latitude_"));
        String lontitude = cursor.getString(cursor.getColumnIndex("lontitude_"));
        int whiteBalance = cursor.getInt(cursor.getColumnIndex("whiteBalance_"));
        int flash = cursor.getInt(cursor.getColumnIndex("flash_"));
        int imageLength = cursor.getInt(cursor.getColumnIndex("imageLength_"));
        int imageWidth = cursor.getInt(cursor.getColumnIndex("imageWidth_"));
        String make = cursor.getString(cursor.getColumnIndex("make_"));
        String model = cursor.getString(cursor.getColumnIndex("model_"));
        int imageFormat = cursor.getInt(cursor.getColumnIndex("imageFormat_"));
        SandExif sandExif = new SandExif(orientation1, latitude, lontitude, whiteBalance, flash, imageLength, imageWidth, make, model);
        sandPhoto = new SandPhoto(id, time, cameraId, categoryId, isMirror, ratio, fileName, size, imageFormat, sandExif);
    }
    cursor.close();
    db.close();
    return sandPhoto;
}
Also used : SandExif(com.yydcdut.note.entity.SandExif) SandPhoto(com.yydcdut.note.entity.SandPhoto) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 4 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class SandBoxDB method finaAll.

public synchronized List<SandPhoto> finaAll() {
    List<SandPhoto> sandPhotoList = new ArrayList<>();
    SQLiteDatabase db = mSandSQLite.getReadableDatabase();
    Cursor cursor = db.query(SandSQLite.TABLE, null, null, null, null, null, null, null);
    while (cursor.moveToNext()) {
        long id = cursor.getLong(cursor.getColumnIndex("_id"));
        long time = cursor.getLong(cursor.getColumnIndex("time"));
        String cameraId = cursor.getString(cursor.getColumnIndex("cameraId"));
        String categoryIdString = cursor.getString(cursor.getColumnIndex("category"));
        int categoryId;
        try {
            categoryId = Integer.parseInt(categoryIdString);
        } catch (Exception e) {
            YLog.e(e);
            categoryId = -1;
        }
        String isMirrorString = cursor.getString(cursor.getColumnIndex("mirror"));
        boolean isMirror = isMirrorString.equals("0") ? false : true;
        int ratio = cursor.getInt(cursor.getColumnIndex("ratio"));
        String fileName = cursor.getString(cursor.getColumnIndex("fileName"));
        int size = cursor.getInt(cursor.getColumnIndex("size"));
        int orientation1 = cursor.getInt(cursor.getColumnIndex("orientation_"));
        String latitude = cursor.getString(cursor.getColumnIndex("latitude_"));
        String lontitude = cursor.getString(cursor.getColumnIndex("lontitude_"));
        int whiteBalance = cursor.getInt(cursor.getColumnIndex("whiteBalance_"));
        int flash = cursor.getInt(cursor.getColumnIndex("flash_"));
        int imageLength = cursor.getInt(cursor.getColumnIndex("imageLength_"));
        int imageWidth = cursor.getInt(cursor.getColumnIndex("imageWidth_"));
        String make = cursor.getString(cursor.getColumnIndex("make_"));
        String model = cursor.getString(cursor.getColumnIndex("model_"));
        int imageFormat = cursor.getInt(cursor.getColumnIndex("imageFormat_"));
        SandExif sandExif = new SandExif(orientation1, latitude, lontitude, whiteBalance, flash, imageLength, imageWidth, make, model);
        SandPhoto sandPhoto = new SandPhoto(id, time, cameraId, categoryId, isMirror, ratio, fileName, size, imageFormat, sandExif);
        sandPhotoList.add(sandPhoto);
    }
    cursor.close();
    db.close();
    return sandPhotoList;
}
Also used : SandExif(com.yydcdut.note.entity.SandExif) SandPhoto(com.yydcdut.note.entity.SandPhoto) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 5 with SandPhoto

use of com.yydcdut.note.entity.SandPhoto in project PhotoNoter by yydcdut.

the class SandBoxDB method findFirstOne.

public synchronized SandPhoto findFirstOne() {
    SandPhoto sandPhoto = null;
    SQLiteDatabase db = mSandSQLite.getReadableDatabase();
    Cursor cursor = db.query(SandSQLite.TABLE, null, null, null, null, null, null, "0,1");
    while (cursor.moveToNext()) {
        long id = cursor.getLong(cursor.getColumnIndex("_id"));
        long time = cursor.getLong(cursor.getColumnIndex("time"));
        String cameraId = cursor.getString(cursor.getColumnIndex("cameraId"));
        String categoryIdString = cursor.getString(cursor.getColumnIndex("category"));
        int categoryId;
        try {
            categoryId = Integer.parseInt(categoryIdString);
        } catch (Exception e) {
            YLog.e(e);
            categoryId = -1;
        }
        String isMirrorString = cursor.getString(cursor.getColumnIndex("mirror"));
        boolean isMirror = isMirrorString.equals("0") ? false : true;
        int ratio = cursor.getInt(cursor.getColumnIndex("ratio"));
        String fileName = cursor.getString(cursor.getColumnIndex("fileName"));
        int size = cursor.getInt(cursor.getColumnIndex("size"));
        int orientation1 = cursor.getInt(cursor.getColumnIndex("orientation_"));
        String latitude = cursor.getString(cursor.getColumnIndex("latitude_"));
        String lontitude = cursor.getString(cursor.getColumnIndex("lontitude_"));
        int whiteBalance = cursor.getInt(cursor.getColumnIndex("whiteBalance_"));
        int flash = cursor.getInt(cursor.getColumnIndex("flash_"));
        int imageLength = cursor.getInt(cursor.getColumnIndex("imageLength_"));
        int imageWidth = cursor.getInt(cursor.getColumnIndex("imageWidth_"));
        String make = cursor.getString(cursor.getColumnIndex("make_"));
        String model = cursor.getString(cursor.getColumnIndex("model_"));
        int imageFormat = cursor.getInt(cursor.getColumnIndex("imageFormat_"));
        SandExif sandExif = new SandExif(orientation1, latitude, lontitude, whiteBalance, flash, imageLength, imageWidth, make, model);
        sandPhoto = new SandPhoto(id, time, cameraId, categoryId, isMirror, ratio, fileName, size, imageFormat, sandExif);
    }
    cursor.close();
    db.close();
    return sandPhoto;
}
Also used : SandExif(com.yydcdut.note.entity.SandExif) SandPhoto(com.yydcdut.note.entity.SandPhoto) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Aggregations

SandExif (com.yydcdut.note.entity.SandExif)8 SandPhoto (com.yydcdut.note.entity.SandPhoto)8 Bitmap (android.graphics.Bitmap)4 BitmapFactory (android.graphics.BitmapFactory)4 ImageFormat (android.graphics.ImageFormat)4 Rect (android.graphics.Rect)4 YuvImage (android.graphics.YuvImage)4 ExifInterface (android.media.ExifInterface)4 PhotoNote (com.yydcdut.note.entity.PhotoNote)4 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)4 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)4 Const (com.yydcdut.note.utils.Const)4 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)4 Utils (com.yydcdut.note.utils.Utils)4 YLog (com.yydcdut.note.utils.YLog)4 IView (com.yydcdut.note.views.IView)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4