|
@@ -5,6 +5,7 @@ import android.content.Intent;
|
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Bitmap;
|
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.BitmapFactory;
|
|
|
import android.media.ThumbnailUtils;
|
|
import android.media.ThumbnailUtils;
|
|
|
|
|
+import android.os.Environment;
|
|
|
import android.support.v7.app.ActionBar;
|
|
import android.support.v7.app.ActionBar;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
@@ -20,7 +21,11 @@ import android.widget.GridView;
|
|
|
import android.widget.ImageButton;
|
|
import android.widget.ImageButton;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import com.usai.redant.raimage.R;
|
|
import com.usai.redant.raimage.R;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -219,7 +224,7 @@ public class PhotoGridActivity extends AppCompatActivity implements RAGridView.G
|
|
|
|
|
|
|
|
if (measuring == true) {
|
|
if (measuring == true) {
|
|
|
measuring = false;
|
|
measuring = false;
|
|
|
- return cell;
|
|
|
|
|
|
|
+// return cell;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -237,23 +242,34 @@ public class PhotoGridActivity extends AppCompatActivity implements RAGridView.G
|
|
|
//
|
|
//
|
|
|
// holder.photoView.setImageBitmap(scale);
|
|
// holder.photoView.setImageBitmap(scale);
|
|
|
|
|
|
|
|
- final String filePath = path;
|
|
|
|
|
- final PhotoViewHolder photoHolder = holder;
|
|
|
|
|
- new Thread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- Bitmap bitmap = BitmapFactory.decodeFile(filePath);
|
|
|
|
|
|
|
+ if (thumbPhotoIsExists(path)) {
|
|
|
|
|
+ Bitmap bitmap = BitmapFactory.decodeFile(path);
|
|
|
|
|
+ holder.photoView.setImageBitmap(bitmap);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ final String filePath = path;
|
|
|
|
|
+ final PhotoViewHolder photoHolder = holder;
|
|
|
|
|
+ new Thread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ Bitmap bitmap = BitmapFactory.decodeFile(filePath);
|
|
|
|
|
+
|
|
|
|
|
+ final Bitmap scale = ThumbnailUtils.extractThumbnail(bitmap, 300, 300);
|
|
|
|
|
+
|
|
|
|
|
+ File thumbFile = thumbFile(filePath);
|
|
|
|
|
+ savePhotoToFile(scale,thumbFile);
|
|
|
|
|
+
|
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ photoHolder.photoView.setImageBitmap(scale);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }).start();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- final Bitmap scale = ThumbnailUtils.extractThumbnail(bitmap, 300, 300);
|
|
|
|
|
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- photoHolder.photoView.setImageBitmap(scale);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }).start();
|
|
|
|
|
|
|
|
|
|
holder.checkBtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.check_none));
|
|
holder.checkBtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.check_none));
|
|
|
|
|
|
|
@@ -310,4 +326,56 @@ public class PhotoGridActivity extends AppCompatActivity implements RAGridView.G
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void savePhotoToFile(Bitmap bitmap, File photoFile) {
|
|
|
|
|
+ if (photoFile == null || bitmap == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(photoFile));
|
|
|
|
|
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
|
|
|
|
|
+ bos.flush();
|
|
|
|
|
+ bos.close();
|
|
|
|
|
+
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String photoDirectory() {
|
|
|
|
|
+
|
|
|
|
|
+ String dir = Environment.getExternalStorageDirectory().getPath() + "/redant/.thumb/";
|
|
|
|
|
+ File file = new File(dir);
|
|
|
|
|
+ if (!file.exists()) {
|
|
|
|
|
+ if (file.mkdirs()) {
|
|
|
|
|
+ return dir;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return dir;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private File thumbFile(String path) {
|
|
|
|
|
+ File file = new File(path);
|
|
|
|
|
+ String name = file.getName();
|
|
|
|
|
+ String thumbDir = photoDirectory();
|
|
|
|
|
+ if (thumbDir != null) {
|
|
|
|
|
+ String thumbPath = thumbDir + name;
|
|
|
|
|
+ return new File(thumbPath);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean thumbPhotoIsExists(String path) {
|
|
|
|
|
+
|
|
|
|
|
+ File thumbFile = thumbFile(path);
|
|
|
|
|
+ if (thumbFile != null && thumbFile.exists()) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|