中华民生 v1.1.2版本的 MD5 值为:045ab4f32e7f11cf35faae8fa3db528a

以下内容为反编译后的 a.java 源代码,内容仅作参考


package io.dcloud.feature.pdr;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.text.TextUtils;
import com.taobao.weex.common.Constants;
import io.dcloud.base.R;
import io.dcloud.common.DHInterface.IWebview;
import io.dcloud.common.adapter.util.Logger;
import io.dcloud.common.constant.DOMException;
import io.dcloud.common.util.Deprecated_JSUtil;
import io.dcloud.common.util.FileUtil;
import io.dcloud.common.util.JSUtil;
import io.dcloud.common.util.PdrUtil;
import io.dcloud.common.util.ThreadPool;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Locale;
import org.json.JSONException;
import org.json.JSONObject;
public class a {

    class RunnableC0057a implements Runnable {
        final IWebview a;
        final String[] b;

        RunnableC0057a(IWebview iWebview, String[] strArr) {
            this.a = iWebview;
            this.b = strArr;
        }

        @Override
        public void run() {
            a.a(this.a, this.b);
        }
    }

    public static class b {
        float a;
        float b;
        float c;
        float d;
        float e;
        float f;

        public b(String str, String str2, String str3, String str4, float f, float f2) {
            this.e = f;
            this.f = f2;
            this.a = a.a(str, f2, 0.0f);
            float a = a.a(str2, this.e, 0.0f);
            this.b = a;
            float f3 = this.e;
            this.c = a.a(str3, f3, f3 - a);
            float f4 = this.f;
            float a2 = a.a(str4, f4, f4 - this.a);
            this.d = a2;
            float f5 = this.c;
            float f6 = this.b;
            float f7 = this.e;
            if (f5 + f6 > f7) {
                this.c = f7 - f6;
            }
            float f8 = this.a;
            float f9 = this.f;
            if (a2 + f8 > f9) {
                this.d = f9 - f8;
            }
        }

        public boolean a() {
            return this.a <= this.f && this.b <= this.e;
        }
    }

    public static synchronized void a(IWebview iWebview, String[] strArr) {
        Bitmap a;
        Bitmap bitmap;
        Bitmap createBitmap;
        long a2;
        synchronized (a.class) {
            String str = strArr[0];
            String str2 = strArr[1];
            try {
                JSONObject jSONObject = new JSONObject(str);
                c cVar = new c();
                if (cVar.a(jSONObject, iWebview, str2)) {
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inJustDecodeBounds = false;
                    if (cVar.e < 0) {
                        cVar.e = 50;
                    }
                    if (cVar.m > 1500000) {
                        options.inSampleSize = 2;
                    } else {
                        options.inSampleSize = 1;
                    }
                    Logger.d("CompressImage", "文件获取完毕 初始化bitmap 获取文件大小" + cVar.m);
                    Matrix matrix = null;
                    try {
                        try {
                            a = a(iWebview.getContext(), cVar.a, options);
                        } catch (IOException unused) {
                            a = null;
                        }
                    } catch (OutOfMemoryError unused2) {
                        Logger.d("CompressImage", "获取bitmap 内存溢出第一次  bitmap路径" + cVar.a);
                        options.inSampleSize = options.inSampleSize * 2;
                        Logger.d("CompressImage", "获取bitmap 内存溢出第一次 第二次获取bitmmap  bitmap路径" + cVar.a);
                        a = a(iWebview.getContext(), cVar.a, options);
                    }
                    if (a == null) {
                        a(iWebview, str2, DOMException.MSG_PARAMETER_ERROR, -1);
                        return;
                    }
                    if (!cVar.l || cVar.f <= 0.0f || cVar.g <= 0.0f) {
                        bitmap = a;
                    } else {
                        Matrix matrix2 = new Matrix();
                        matrix2.setScale(cVar.f / a.getWidth(), cVar.g / a.getHeight());
                        bitmap = Bitmap.createBitmap(a, 0, 0, a.getWidth(), a.getHeight(), matrix2, false);
                    }
                    Logger.d("CompressImage", "缩放完毕" + cVar.a);
                    if (cVar.h > 0) {
                        matrix = new Matrix();
                        matrix.postRotate(cVar.h);
                    }
                    Matrix matrix3 = matrix;
                    Logger.d("CompressImage", "旋转完毕" + cVar.a);
                    b bVar = cVar.k;
                    if (bVar != null) {
                        float f = bVar.a;
                        float f2 = options.inSampleSize;
                        createBitmap = Bitmap.createBitmap(bitmap, (int) (bVar.b / f2), (int) (f / f2), (int) (bVar.c / f2), (int) (bVar.d / f2), matrix3, false);
                        if (createBitmap != bitmap) {
                            bitmap.recycle();
                        }
                    } else {
                        if (matrix3 != null) {
                            createBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix3, false);
                            if (createBitmap != bitmap) {
                                bitmap.recycle();
                            }
                        }
                        Logger.d("CompressImage", "裁剪完毕" + cVar.a);
                        int width = bitmap.getWidth();
                        int height = bitmap.getHeight();
                        a2 = a(cVar.b, bitmap, cVar.d, cVar.e);
                        if (a2 <= 0) {
                            a(cVar.a, cVar.b);
                            Logger.d("CompressImage", "开始保存图片" + cVar.a);
                            a(iWebview, str2, String.format(Locale.ENGLISH, "{path:'file://%s', w:%d, h:%d, size:%d}", cVar.b, Integer.valueOf(width), Integer.valueOf(height), Long.valueOf(a2)));
                        } else {
                            if (!bitmap.isRecycled()) {
                                bitmap.recycle();
                            }
                            a(iWebview, str2, iWebview.getContext().getString(R.string.dcloud_common_zip_image_output_failed), -5);
                        }
                        if (!a.isRecycled()) {
                            a.recycle();
                        }
                    }
                    bitmap = createBitmap;
                    Logger.d("CompressImage", "裁剪完毕" + cVar.a);
                    int width2 = bitmap.getWidth();
                    int height2 = bitmap.getHeight();
                    a2 = a(cVar.b, bitmap, cVar.d, cVar.e);
                    if (a2 <= 0) {
                    }
                    if (!a.isRecycled()) {
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
                a(iWebview, str2, DOMException.MSG_PARAMETER_ERROR, -1);
            }
        }
    }

    public static void b(IWebview iWebview, String[] strArr) {
        ThreadPool.self().addThreadTask(new RunnableC0057a(iWebview, strArr));
    }

    public static Bitmap.CompressFormat c(String str) {
        if (!str.contains(".jpg") && !str.contains(".jpeg")) {
            return Bitmap.CompressFormat.PNG;
        }
        return Bitmap.CompressFormat.JPEG;
    }

    public static boolean b(String str) {
        try {
            File file = new File(str);
            if (file.exists()) {
                if (file.length() >= 5) {
                    return true;
                }
            }
        } catch (Exception unused) {
        }
        return false;
    }

    public static class c {
        String a;
        String b;
        String c;
        boolean d;
        int e;
        float f;
        float g;
        int h;
        int i;
        int j;
        b k;
        boolean l = false;
        long m;

        c() {
        }

        public boolean a(JSONObject jSONObject, IWebview iWebview, String str) {
            this.a = jSONObject.optString("src");
            this.b = jSONObject.optString("dst");
            if (a(iWebview, str)) {
                this.d = jSONObject.optBoolean("overwrite", false);
                this.c = jSONObject.optString("format");
                this.e = jSONObject.optInt(Constants.Name.QUALITY, -1);
                a(iWebview.getContext(), jSONObject.optString("width", "auto"), jSONObject.optString("height", "auto"));
                this.h = jSONObject.optInt("rotate", -1);
                JSONObject optJSONObject = jSONObject.optJSONObject("clip");
                if (optJSONObject != null) {
                    b bVar = new b(optJSONObject.optString("top"), optJSONObject.optString("left"), optJSONObject.optString("width"), optJSONObject.optString("height"), this.f, this.g);
                    this.k = bVar;
                    if (bVar.a()) {
                        return true;
                    }
                    a.a(iWebview, str, DOMException.MSG_PARAMETER_ERROR, -1);
                    return false;
                }
                return true;
            }
            return false;
        }

        public boolean a(IWebview iWebview, String str) {
            if (!TextUtils.isEmpty(this.a) && !TextUtils.isEmpty(this.b)) {
                String convert2AbsFullPath = iWebview.obtainFrameView().obtainApp().convert2AbsFullPath(iWebview.obtainFullUrl(), this.a);
                this.a = convert2AbsFullPath;
                if (!a.b(convert2AbsFullPath)) {
                    a.a(iWebview, str, DOMException.MSG_FILE_NOT_EXIST, -4);
                    return false;
                }
                this.b = iWebview.obtainFrameView().obtainApp().convert2AbsFullPath(iWebview.obtainFullUrl(), this.b);
                return true;
            }
            a.a(iWebview, str, DOMException.MSG_PARAMETER_ERROR, -1);
            return false;
        }

        public void a(Context context, String str, String str2) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            try {
                a.a(context, this.a, options);
            } catch (IOException e) {
                e.printStackTrace();
            }
            int i = options.outWidth;
            this.i = i;
            int i2 = options.outHeight;
            this.j = i2;
            if (i2 <= 0 || i <= 0) {
                return;
            }
            this.m = new File(this.a).length();
            if (str.equals("auto") && str2.endsWith("auto")) {
                this.l = false;
                this.f = this.i;
                this.g = this.j;
            } else if (str.equals("auto")) {
                this.l = true;
                float f = this.j;
                float parseFloat = PdrUtil.parseFloat(str2, f, f);
                this.g = parseFloat;
                this.f = (this.i * parseFloat) / this.j;
            } else if (str2.equals("auto")) {
                this.l = true;
                float f2 = this.i;
                float parseFloat2 = PdrUtil.parseFloat(str, f2, f2);
                this.f = parseFloat2;
                this.g = (this.j * parseFloat2) / this.i;
            } else {
                this.l = true;
                float f3 = this.i;
                this.f = PdrUtil.parseFloat(str, f3, f3);
                float f4 = this.j;
                this.g = PdrUtil.parseFloat(str2, f4, f4);
            }
        }
    }

    private static void a(String str, String str2) {
        Field[] fields;
        Object obj;
        String obj2;
        String attribute;
        try {
            ExifInterface exifInterface = new ExifInterface(str);
            ExifInterface exifInterface2 = new ExifInterface(str2);
            for (Field field : ExifInterface.class.getFields()) {
                String name = field.getName();
                if (!TextUtils.isEmpty(name) && name.startsWith("TAG") && (obj = field.get(ExifInterface.class)) != null && (attribute = exifInterface.getAttribute((obj2 = obj.toString()))) != null) {
                    exifInterface2.setAttribute(obj2, attribute);
                }
            }
            exifInterface2.saveAttributes();
        } catch (Throwable unused) {
        }
    }

    public static Bitmap a(Context context, String str, BitmapFactory.Options options) throws IOException {
        if (!FileUtil.checkPrivatePath(context, str)) {
            InputStream fileInputStream = FileUtil.getFileInputStream(context, str);
            if (fileInputStream != null) {
                Bitmap decodeStream = BitmapFactory.decodeStream(fileInputStream, null, options);
                fileInputStream.close();
                return decodeStream;
            }
            return null;
        }
        return BitmapFactory.decodeFile(str, options);
    }

    public static void a(IWebview iWebview, String str, String str2, int i) {
        Deprecated_JSUtil.execCallback(iWebview, str, DOMException.toJSON(i, str2), JSUtil.ERROR, true, false);
    }

    public static void a(IWebview iWebview, String str, String str2) {
        Deprecated_JSUtil.execCallback(iWebview, str, str2, JSUtil.OK, true, false);
    }

    public static long a(String str, Bitmap bitmap, boolean z, int i) {
        File file = new File(str);
        if (file.exists()) {
            if (file.length() < 1) {
                file.delete();
            } else if (!z) {
                return -1L;
            } else {
                file.delete();
            }
        } else if (a(str)) {
            file = new File(str);
        }
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            bitmap.compress(c(str), i, fileOutputStream);
            fileOutputStream.flush();
            fileOutputStream.close();
            if (!bitmap.isRecycled()) {
                bitmap.recycle();
            }
            return file.length();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return -1L;
        } catch (IOException e2) {
            e2.printStackTrace();
            return -1L;
        }
    }

    public static boolean a(String str) {
        int lastIndexOf;
        if (!TextUtils.isEmpty(str) && (lastIndexOf = str.lastIndexOf("/")) != -1 && lastIndexOf != 0) {
            try {
                File file = new File(str.substring(0, lastIndexOf));
                if (file.exists()) {
                    return true;
                }
                file.mkdirs();
                return true;
            } catch (Exception unused) {
            }
        }
        return false;
    }

    public static float a(String str, float f, float f2) {
        return str.equals("auto") ? f2 : PdrUtil.parseFloat(str, f, f2);
    }
}