Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
support upload large photo and raw gif
Browse files Browse the repository at this point in the history
  • Loading branch information
mcxiaoke committed Mar 9, 2016
1 parent b61c64d commit 0761e33
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
23 changes: 17 additions & 6 deletions app/src/main/java/com/mcxiaoke/minicat/service/SyncService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.mcxiaoke.minicat.dao.model.UserColumns;
import com.mcxiaoke.minicat.dao.model.UserModel;
import com.mcxiaoke.minicat.util.Assert;
import com.mcxiaoke.minicat.util.IOHelper;
import com.mcxiaoke.minicat.util.ImageHelper;
import com.mcxiaoke.minicat.util.LogUtil;
import com.mcxiaoke.minicat.util.NetworkHelper;
Expand Down Expand Up @@ -799,6 +800,7 @@ private boolean doStatusUpdate(final StatusUpdateInfo info, boolean needDeleteDr

debug("doStatusUpdate() info=" + info);
boolean photoUpload = false;
File photo = null;
try {
StatusModel result = null;
if (StringHelper.isEmpty(info.fileName) || new File(info.fileName).length() == 0) {
Expand All @@ -809,14 +811,21 @@ private boolean doStatusUpdate(final StatusUpdateInfo info, boolean needDeleteDr
}
} else {
File file = new File(info.fileName);
int quality = NetworkHelper.isWifi(this) ? ImageHelper.IMAGE_QUALITY_HIGH : ImageHelper.IMAGE_QUALITY_MEDIUM;

File photo = ImageHelper.prepareUploadFile(this, file,
quality);
boolean isWifi = NetworkHelper.isWifi(this);
int quality = isWifi ? ImageHelper.IMAGE_QUALITY_HIGH :
ImageHelper.IMAGE_QUALITY_MEDIUM;
int maxWidth = isWifi ? ImageHelper.IMAGE_MAX_WIDTH : ImageHelper.IMAGE_MAX_WIDTH_2;
if (file.getName().toLowerCase().endsWith(".gif")) {
photo = new File(IOHelper.getImageCacheDir(this),
System.currentTimeMillis() + "_fanfouupload.gif");
IOHelper.copyFile(file, photo);
} else {
photo = ImageHelper.prepareUploadFile(this, file, quality, maxWidth);
}
if (photo != null && photo.length() > 0) {
if (DEBUG) {
debug("doStatusUpdate() photo file=" + file.getName() + " size="
+ photo.length() / 1024 + " quality=" + quality);
+ photo.length() / 1024 + "k quality=" + quality);
}
photoUpload = true;
result = mApi.uploadPhoto(photo, info.text, info.location);
Expand Down Expand Up @@ -857,7 +866,9 @@ private boolean doStatusUpdate(final StatusUpdateInfo info, boolean needDeleteDr
getString(R.string.msg_unkonow_error));
UmengHelper.onStatusUpdateError(this, AppContext.getAccount(), 0, e.getMessage(), e.getCause() + "");
} finally {
// mNotificationManager.cancel(NOTIFICATION_STATUS_UPDATE_ONGOING);
if (photo != null) {
photo.delete();
}
}
isSending = false;
return res;
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/mcxiaoke/minicat/util/ImageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
* @version 3.2 2011.12.26
*/
final public class ImageHelper {
public static final int IMAGE_QUALITY_HIGH = 90;
public static final int IMAGE_QUALITY_MEDIUM = 80;
public static final int IMAGE_QUALITY_HIGH = 95;
public static final int IMAGE_QUALITY_MEDIUM = 85;
public static final int IMAGE_QUALITY_LOW = 70;
public static final int IMAGE_MAX_WIDTH = 596;// 640 596
// public static final int IMAGE_MAX_HEIGHT = 1200;// 1320 1192
public static final int IMAGE_MAX_WIDTH = 1600;// 640 596
public static final int IMAGE_MAX_WIDTH_2 = 1000;// 640 596
public static final int OUTPUT_BUFFER_SIZE = 8196;
private static final String TAG = ImageHelper.class.getSimpleName();

Expand Down Expand Up @@ -420,11 +420,11 @@ public static boolean writeToFile(File file, Bitmap bitmap) {
return false;
}

public static File prepareUploadFile(Context context, File file, int quality) {
public static File prepareUploadFile(Context context, File file, int quality, int maxWidth) {
File destFile = new File(IOHelper.getImageCacheDir(context),
"fanfouupload.jpg");
System.currentTimeMillis() + "_fanfouupload.jpg");
return compressForUpload(file.getPath(), destFile.getPath(),
IMAGE_MAX_WIDTH, quality);
maxWidth, quality);
}

public static File prepareProfileImage(Context context, File file) {
Expand Down

0 comments on commit 0761e33

Please sign in to comment.