|
|
@@ -8,8 +8,12 @@ import android.content.ContentValues;
|
|
|
import android.content.Context;
|
|
|
import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.SharedPreferences;
|
|
|
import android.database.Cursor;
|
|
|
+import android.graphics.Bitmap;
|
|
|
+import android.graphics.BitmapFactory;
|
|
|
import android.location.Location;
|
|
|
+import android.media.Image;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Environment;
|
|
|
import android.os.Handler;
|
|
|
@@ -53,6 +57,9 @@ import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.ref.WeakReference;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@@ -289,17 +296,20 @@ public class UpdateActivity extends BasicActivity implements UpdateAdapter.Updat
|
|
|
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
|
-// File scaleFile = compressImageFile(photoFile);
|
|
|
-// if (scaleFile != null) {
|
|
|
-// photoFile = scaleFile;
|
|
|
-// }
|
|
|
+ File scaleFile = compressImageFile(photoFile);
|
|
|
+// File scaleFile = photoFile;
|
|
|
+ if (scaleFile != null) {
|
|
|
|
|
|
- ImageUtil.updateGallery(mCtx,photoFile.getAbsolutePath());
|
|
|
- if (mPhotoModel != null) {
|
|
|
- mPhotoModel.setPhotoPath(photoFile.getAbsolutePath());
|
|
|
+ ImageUtil.updateGallery(mCtx,scaleFile.getAbsolutePath());
|
|
|
+
|
|
|
+ if (mPhotoModel != null) {
|
|
|
+ mPhotoModel.setPhotoPath(scaleFile.getAbsolutePath());
|
|
|
+ }
|
|
|
+
|
|
|
+ mPhotoArray.add(scaleFile);
|
|
|
}
|
|
|
|
|
|
- mPhotoArray.add(photoFile);
|
|
|
+
|
|
|
|
|
|
} else {
|
|
|
if (photoFile.exists()) {
|
|
|
@@ -345,6 +355,79 @@ public class UpdateActivity extends BasicActivity implements UpdateAdapter.Updat
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private File compressImageFile(File imgFile) {
|
|
|
+
|
|
|
+
|
|
|
+ String imageFileName = imgFile.getName();
|
|
|
+
|
|
|
+ File routedFile = ImageUtil.routeBitmap(mCtx,imgFile,null);
|
|
|
+
|
|
|
+ Bitmap source = null;
|
|
|
+ try {
|
|
|
+ FileInputStream stream = new FileInputStream(routedFile);
|
|
|
+ source = BitmapFactory.decodeStream(stream);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ return routedFile;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (source == null) {
|
|
|
+ return routedFile;
|
|
|
+ }
|
|
|
+
|
|
|
+ int originWidth = source.getWidth();
|
|
|
+ int originHeight = source.getHeight();
|
|
|
+
|
|
|
+ int width = originWidth, height = originHeight;
|
|
|
+
|
|
|
+ if (originHeight > 1024 || originWidth > 1024)
|
|
|
+ {
|
|
|
+ if (originWidth > originHeight)
|
|
|
+ {
|
|
|
+ width = 1024;
|
|
|
+ height = originHeight * 1024 / originWidth;
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ height = 1024;
|
|
|
+ width = originWidth * 1024 / originHeight;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Bitmap scaled = Bitmap.createScaledBitmap(source, width, height, true);
|
|
|
+
|
|
|
+ String scalePath = FileManager.internalStorageFileDir(mCtx) + File.separator + "Photo" + File.separator +imageFileName;
|
|
|
+ File scaleFile = new File(scalePath);
|
|
|
+ if (!scaleFile.getParentFile().exists()) {
|
|
|
+ scaleFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(scaleFile);
|
|
|
+ scaled.compress(Bitmap.CompressFormat.JPEG, 95, outputStream);
|
|
|
+
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+
|
|
|
+ String rotedpath = routedFile.getAbsolutePath();
|
|
|
+ routedFile.delete();
|
|
|
+
|
|
|
+ ImageUtil.updateGallery(mCtx,rotedpath);
|
|
|
+
|
|
|
+ return scaleFile;
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return routedFile;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Camera Permission
|
|
|
* */
|