Search in sources :

Example 1 with PhotoNote

use of com.yydcdut.note.entity.PhotoNote 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 PhotoNote

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

the class AlbumPresenterImpl method changePhotosCategory.

@Override
public void changePhotosCategory(int toCategoryId) {
    if (mCategoryId != toCategoryId) {
        mRxPhotoNote.findByCategoryId(mCategoryId, mAlbumSortKind).observeOn(AndroidSchedulers.mainThread()).map(photoNoteList -> {
            TreeMap<Integer, PhotoNote> map = getTreeMap();
            for (int i = 0; i < photoNoteList.size(); i++) {
                PhotoNote photoNote = photoNoteList.get(i);
                if (photoNote.isSelected()) {
                    photoNote.setSelected(false);
                    photoNote.setCategoryId(toCategoryId);
                    map.put(i, photoNote);
                }
            }
            int times = 0;
            for (Map.Entry<Integer, PhotoNote> entry : map.entrySet()) {
                photoNoteList.remove(entry.getValue());
                // todo 这个在这里合适吗?觉得严重的不合适
                mAlbumView.notifyItemRemoved(entry.getKey() - times);
                mRxPhotoNote.updatePhotoNote(entry.getValue()).subscribe((photoNotes -> {
                }), (throwable -> YLog.e(throwable)));
                times++;
            }
            return map.size();
        }).subscribe(integer -> {
            mRxCategory.updateChangeCategory(mCategoryId, toCategoryId, integer).subscribe(categories -> {
                mRxPhotoNote.refreshByCategoryId(mCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe((photoNoteList) -> mAlbumView.updateDataNoChange(photoNoteList), (throwable -> YLog.e(throwable)));
                mRxPhotoNote.refreshByCategoryId(toCategoryId, ComparatorFactory.FACTORY_NOT_SORT).subscribe(photoNotes -> {
                }, (throwable -> YLog.e(throwable)));
                EventBus.getDefault().post(new CategoryMoveEvent());
            }, (throwable -> YLog.e(throwable)));
        }, (throwable -> YLog.e(throwable)));
    }
}
Also used : Context(android.content.Context) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) Uri(android.net.Uri) PhotoNoteDeleteEvent(com.yydcdut.note.bus.PhotoNoteDeleteEvent) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Observable(rx.Observable) Inject(javax.inject.Inject) IAlbumView(com.yydcdut.note.views.home.IAlbumView) ContentResolver(android.content.ContentResolver) RxSandBox(com.yydcdut.note.model.rx.RxSandBox) Handler(android.os.Handler) ContextLife(com.yydcdut.note.injector.ContextLife) EventBus(org.greenrobot.eventbus.EventBus) Map(java.util.Map) Category(com.yydcdut.note.entity.Category) FilePathUtils(com.yydcdut.note.utils.FilePathUtils) R(com.yydcdut.note.R) Utils(com.yydcdut.note.utils.Utils) PermissionUtils(com.yydcdut.note.utils.PermissionUtils) RxCategory(com.yydcdut.note.model.rx.RxCategory) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent) Subscriber(rx.Subscriber) PhotoNoteCreateEvent(com.yydcdut.note.bus.PhotoNoteCreateEvent) LocalStorageUtils(com.yydcdut.note.utils.LocalStorageUtils) TextUtils(android.text.TextUtils) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IAlbumPresenter(com.yydcdut.note.presenters.home.IAlbumPresenter) List(java.util.List) Permission(com.yydcdut.note.utils.permission.Permission) TreeMap(java.util.TreeMap) ComparatorFactory(com.yydcdut.note.model.compare.ComparatorFactory) ImageLoaderManager(com.yydcdut.note.utils.ImageManager.ImageLoaderManager) CategoryCreateEvent(com.yydcdut.note.bus.CategoryCreateEvent) PhotoNote(com.yydcdut.note.entity.PhotoNote) AspectPermission(com.yydcdut.note.aspect.permission.AspectPermission) YLog(com.yydcdut.note.utils.YLog) IView(com.yydcdut.note.views.IView) RxPhotoNote(com.yydcdut.note.model.rx.RxPhotoNote) PhotoNote(com.yydcdut.note.entity.PhotoNote) TreeMap(java.util.TreeMap) CategoryMoveEvent(com.yydcdut.note.bus.CategoryMoveEvent)

Example 3 with PhotoNote

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

the class PhotoNoteDB method findByCategoryId.

public synchronized List<PhotoNote> findByCategoryId(int categoryId) {
    List<PhotoNote> list = new ArrayList<>();
    SQLiteDatabase db = mNotesSQLite.getReadableDatabase();
    Cursor cursor = db.query(NotesSQLite.TABLE_PHOTONOTE, null, "categoryId = ?", new String[] { categoryId + "" }, null, null, null);
    while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex("_id"));
        String photoName = cursor.getString(cursor.getColumnIndex("photoName"));
        long createdPhotoTime = cursor.getLong(cursor.getColumnIndex("createdPhotoTime"));
        long editedPhotoTime = cursor.getLong(cursor.getColumnIndex("editedPhotoTime"));
        String title = cursor.getString(cursor.getColumnIndex("title"));
        String content = cursor.getString(cursor.getColumnIndex("content"));
        long createdNoteTime = cursor.getLong(cursor.getColumnIndex("createdNoteTime"));
        long editedNoteTime = cursor.getLong(cursor.getColumnIndex("editedNoteTime"));
        int color = cursor.getInt(cursor.getColumnIndex("palette"));
        int tag = cursor.getInt(cursor.getColumnIndex("tag"));
        int categoryId_ = cursor.getInt(cursor.getColumnIndex("categoryId"));
        PhotoNote photoNote = new PhotoNote(id, photoName, createdPhotoTime, editedPhotoTime, title, content, createdNoteTime, editedNoteTime, categoryId_);
        photoNote.setPaletteColor(color);
        list.add(photoNote);
    }
    cursor.close();
    db.close();
    return list;
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 4 with PhotoNote

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

the class PhotoNoteDB method delete.

public synchronized int delete(PhotoNote... photoNotes) {
    SQLiteDatabase db = mNotesSQLite.getWritableDatabase();
    db.beginTransaction();
    int rows = 0;
    try {
        for (PhotoNote photoNote : photoNotes) {
            rows = db.delete(NotesSQLite.TABLE_PHOTONOTE, "_id = ?", new String[] { photoNote.getId() + "" });
        }
        db.setTransactionSuccessful();
    } catch (Exception e) {
        YLog.e(e);
        return -1;
    } finally {
        // 处理完成
        db.endTransaction();
        db.close();
    }
    return rows;
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 5 with PhotoNote

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

the class AlbumAdapter method cancelSelectPhotos.

/**
 * 取消选择所有照片
 */
public void cancelSelectPhotos() {
    for (PhotoNote photoNote : mPhotoNoteList) {
        photoNote.setSelected(false);
        int index = mPhotoNoteList.indexOf(photoNote);
        notifyItemChanged(index);
    }
}
Also used : PhotoNote(com.yydcdut.note.entity.PhotoNote)

Aggregations

PhotoNote (com.yydcdut.note.entity.PhotoNote)19 RxPhotoNote (com.yydcdut.note.model.rx.RxPhotoNote)11 FilePathUtils (com.yydcdut.note.utils.FilePathUtils)9 YLog (com.yydcdut.note.utils.YLog)9 IView (com.yydcdut.note.views.IView)9 ArrayList (java.util.ArrayList)9 Inject (javax.inject.Inject)9 Handler (android.os.Handler)8 List (java.util.List)8 Context (android.content.Context)7 R (com.yydcdut.note.R)7 Category (com.yydcdut.note.entity.Category)7 ContextLife (com.yydcdut.note.injector.ContextLife)7 ComparatorFactory (com.yydcdut.note.model.compare.ComparatorFactory)7 RxCategory (com.yydcdut.note.model.rx.RxCategory)7 RxSandBox (com.yydcdut.note.model.rx.RxSandBox)7 Utils (com.yydcdut.note.utils.Utils)7 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 Map (java.util.Map)7