Преглед изворни кода

上传图片前,给png图片添加IENDData

zengjiebin пре 7 година
родитељ
комит
8ba9a18392

+ 13 - 8
app/src/main/java/com/kfzs/duanduan/react/upfile/UpFileUtils.java

@@ -4,7 +4,9 @@ package com.kfzs.duanduan.react.upfile;
 import android.graphics.Bitmap;
 
 import com.nanchen.compresshelper.CompressHelper;
+import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.util.ExceptionHandle;
+import com.sheep.gamegroup.util.PngUtil;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.zhy.http.okhttp.OkHttpUtils;
 import com.zhy.http.okhttp.callback.Callback;
@@ -15,6 +17,7 @@ import java.util.ArrayList;
 import okhttp3.Call;
 import okhttp3.Response;
 import okhttp3.ResponseBody;
+import rx.functions.Action1;
 
 /**
  * Created by howie on 2017/5/11.
@@ -56,21 +59,23 @@ public class UpFileUtils {
 
     }
 
-    public static void upImages(ArrayList<String> photos, final UpFileListener upFileListener) {
-        upImages(photos, upFileListener, 0);
+    public static void upImages(ArrayList<String> photos, final UpFileListener upFileListener, ICallBack<String> action1) {
+        upImages(photos, upFileListener, action1, 0);
     }
-
-    public static void upImages(final ArrayList<String> photos, final UpFileListener upFileListener, final int index) {
-        if (index < photos.size()) {
+    public static void upImages(final ArrayList<String> photos, final UpFileListener upFileListener, final ICallBack<String> action1, final int index) {
+        int size = photos.size();
+        if (index < size) {
             File file;
             if ((file = new File(photos.get(index))).exists()) {
                 File newFile = new CompressHelper.Builder(SheepApp.getInstance())
                         .setMaxWidth(2000)  // 默认最大宽度为720
                         .setMaxHeight(2000) // 默认最大高度为960
                         .setQuality(80)    // 默认压缩质量为80
-                        .setCompressFormat(Bitmap.CompressFormat.JPEG) // 设置默认压缩为jpg格式
+                        .setCompressFormat(Bitmap.CompressFormat.PNG) // 设置默认压缩为png格式
                         .build().compressToFile(file);
 //                org.xutils.common.util.FileUtil.copy(newFile.getAbsolutePath(), ClassFileHelper.DIR+"/1.png");
+                if(action1 != null)
+                    action1.call(newFile.getAbsolutePath(), size, index);
                 OkHttpUtils.post()
                         .addFile("uploadfile", "1.png", newFile)//
                         .url(URL_RN_UP_IMAGE)
@@ -98,11 +103,11 @@ public class UpFileUtils {
                             @Override
                             public void onResponse(Object response, int id) {
                                 upFileListener.Success(response.toString(), index);
-                                upImages(photos, upFileListener, index + 1);
+                                upImages(photos, upFileListener, action1,index + 1);
                             }
                         });
             }else {//文件不存在就不用上传
-                upImages(photos, upFileListener, index + 1);
+                upImages(photos, upFileListener, action1,index + 1);
             }
         } else
             upFileListener.Success("全部上传完成", -1);

+ 10 - 1
app/src/main/java/com/sheep/gamegroup/absBase/AbsChooseImageActivity.java

@@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSON;
 import com.kfzs.duanduan.react.upfile.UpFileListener;
 import com.kfzs.duanduan.react.upfile.UpFileUtils;
 import com.sheep.gamegroup.model.api.BaseMessageConverter;
+import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.entity.UploadResult;
 import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.view.dialog.DialogProgress;
@@ -144,13 +145,21 @@ public abstract class AbsChooseImageActivity extends BaseActivity implements UpF
             onGetImage(path);
             if (isUpload) {
                 AbsChooseImageActivity.this.dialogShowLoading = DialogProgress.showDialog(AbsChooseImageActivity.this);
-                UpFileUtils.upImages(photos, AbsChooseImageActivity.this);
+                UpFileUtils.upImages(photos, AbsChooseImageActivity.this, getCallBack());
             }
         } else {
             onNotGetImage("没有数据");
         }
     }
 
+    /**
+     * 上传图片前的回调
+     * @return
+     */
+    protected ICallBack<String> getCallBack(){
+        return null;
+    }
+
     @Override
     public void Success(String msg, int index) {
         if(index == -1 && !urls.isEmpty()) {//多图

+ 9 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ICallBack.java

@@ -0,0 +1,9 @@
+package com.sheep.gamegroup.model.api;
+
+/**
+ * Created by realicing on 2018/8/28.
+ * realicing@sina.com
+ */
+public interface ICallBack<T> {
+    T call(Object...args);
+}

+ 1 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActSheepPngList.java

@@ -118,6 +118,7 @@ public class ActSheepPngList extends BaseActivity {
     }
 
     private void onClickItem(final File file) throws Exception {
+        //加密文本内容:包名;签名md5;试玩应用包名;试玩应用签名md5;任务id;图片总数;图片位置
         String iEndData = PngUtil.decodePng(file.getAbsolutePath(), "com.realicing.android.upgrade.sheep", "280;7;0");
         if(iEndData == null){
             G.showToast("失败");

+ 24 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/TaskDetailAct.java

@@ -28,6 +28,7 @@ import com.sheep.gamegroup.absBase.AbsChooseImageActivity;
 import com.sheep.gamegroup.di.components.DaggerTaskDetailComponent;
 import com.sheep.gamegroup.di.modules.TaskDetailModule;
 import com.sheep.gamegroup.helper.TaskHelper;
+import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.api.IDownload;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.DialogEntity;
@@ -53,6 +54,7 @@ import com.sheep.gamegroup.util.ListUtil;
 import com.sheep.gamegroup.util.LocationUtils;
 import com.sheep.gamegroup.util.MyDbManager;
 import com.sheep.gamegroup.util.MyListview;
+import com.sheep.gamegroup.util.PngUtil;
 import com.sheep.gamegroup.util.SelfCountDownTimer;
 import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.TimeUtil;
@@ -989,7 +991,28 @@ public class TaskDetailAct extends AbsChooseImageActivity implements TaskDetailC
     protected void onGetImage(String path) {
 
     }
-
+    private ICallBack<String> callBack = new ICallBack<String>() {
+        @Override
+        public String call(Object... args) {
+            String pngFilePath = (String) args[0];
+            int size = (int) args[1];
+            int index = (int) args[2];
+            try {
+                //加密文本内容:包名;签名md5;试玩应用包名;试玩应用签名md5;任务id;图片总数;图片位置
+                return PngUtil.decodePng(pngFilePath, taskEty.getPackage_names(), String.format(Locale.CHINA, "%d;%d;%d", commitScreenShotTaskId, size, index));
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            return null;
+        }
+    };
+    /**
+     * 上传图片前的回调
+     * @return
+     */
+    protected ICallBack<String> getCallBack(){
+        return callBack;
+    }
     private int commitScreenShotTaskId;
 
     @Override