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();
}
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)));
}
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;
}
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;
}
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;
}
Aggregations