QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

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


package com.tencent.mtt.external.qrcode;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.core.view.ViewCompat;
import com.facebook.common.util.UriUtil;
import com.tencent.common.http.NetUtils;
import com.tencent.common.utils.UrlUtils;
import com.tencent.mtt.base.functionwindow.ActivityHandler;
import com.tencent.mtt.base.utils.DeviceUtils;
import com.tencent.mtt.browser.window.UrlParams;
import com.tencent.mtt.businesscenter.facade.IFrameworkDelegate;
import com.tencent.mtt.compliance.MethodDelegate;
import com.tencent.mtt.external.qrcode.common.ActionConstants2;
import com.tencent.mtt.external.qrcode.common.AddressBookParsedResult;
import com.tencent.mtt.external.qrcode.common.AddressBookResultHandler;
import com.tencent.mtt.external.qrcode.common.BeepManager;
import com.tencent.mtt.external.qrcode.common.ParsedResult;
import com.tencent.mtt.external.qrcode.common.ResultHandler;
import com.tencent.mtt.external.qrcode.common.ResultHandlerFactory;
import com.tencent.mtt.external.qrcode.common.URIParsedResult;
import com.tencent.mtt.external.qrcode.common.URIResultHandler;
import com.tencent.mtt.external.qrcode.facade.IQRCodeExtension;
import com.tencent.mtt.external.qrcode.facade.IQrCodeProviderListener;
import com.tencent.mtt.external.qrcode.inhost.AddressResultActivity;
import com.tencent.mtt.external.qrcode.inhost.NormalResultActivity;
import com.tencent.mtt.external.qrcode.inhost.ParsedResultType;
import com.tencent.mtt.external.qrcode.result.ResultParser;
import com.tencent.mtt.qbcontext.core.QBContext;
import com.tencent.mtt.qbinfo.IQConfigure;
import com.tencent.qbar.QBarManager;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class ZxingUtils implements IQRCodeExtension {

    private static final String f56450a = System.getProperty("file.encoding");

    private static Bitmap a(Context context, Uri uri, BitmapFactory.Options options) {
        InputStream inputStream;
        InputStream inputStream2 = null;
        if (uri == null) {
            return null;
        }
        String scheme = uri.getScheme();
        if (!"content".equals(scheme) && !"file".equals(scheme)) {
            UriUtil.QUALIFIED_RESOURCE_SCHEME.equals(scheme);
            return null;
        }
        try {
            inputStream = context.getContentResolver().openInputStream(uri);
            try {
                Bitmap decodeStream = BitmapFactory.decodeStream(inputStream, null, options);
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException unused) {
                    }
                }
                return decodeStream;
            } catch (Exception unused2) {
                if (inputStream == null) {
                    return null;
                }
                try {
                    inputStream.close();
                    return null;
                } catch (IOException unused3) {
                    return null;
                }
            } catch (Throwable th) {
                th = th;
                inputStream2 = inputStream;
                if (inputStream2 != null) {
                    try {
                        inputStream2.close();
                    } catch (IOException unused4) {
                    }
                }
                throw th;
            }
        } catch (Exception unused5) {
            inputStream = null;
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static int calculateInSampleSize(Context context, Uri uri, int i) {
        InputStream openInputStream;
        BitmapFactory.Options options = new BitmapFactory.Options();
        int i2 = 1;
        options.inJustDecodeBounds = true;
        InputStream inputStream = null;
        try {
            openInputStream = context.getContentResolver().openInputStream(uri);
        } catch (FileNotFoundException unused) {
        } catch (Throwable th) {
            th = th;
        }
        try {
            BitmapFactory.decodeStream(openInputStream, null, options);
            closeQuietly(openInputStream);
        } catch (FileNotFoundException unused2) {
            inputStream = openInputStream;
            closeQuietly(inputStream);
            while (true) {
                if (options.outWidth / i2 > i) {
                }
                i2 *= 2;
            }
        } catch (Throwable th2) {
            th = th2;
            inputStream = openInputStream;
            closeQuietly(inputStream);
            throw th;
        }
        while (true) {
            if (options.outWidth / i2 > i && options.outHeight / i2 <= i) {
                return i2;
            }
            i2 *= 2;
        }
    }

    public static void changeZoom(Camera camera, int i) {
        if (camera != null) {
            try {
                Camera.Parameters parameters = camera.getParameters();
                if (parameters == null || !parameters.isZoomSupported()) {
                    return;
                }
                int maxZoom = parameters.getMaxZoom();
                int zoom = parameters.getZoom();
                int i2 = i + zoom;
                if (i2 >= maxZoom) {
                    i2 = zoom;
                }
                parameters.setZoom(i2);
                camera.setParameters(parameters);
            } catch (Exception unused) {
            }
        }
    }

    public static void closeQuietly(Closeable closeable) {
        if (closeable == null) {
            return;
        }
        try {
            closeable.close();
        } catch (Throwable unused) {
        }
    }

    public static void createQrBitmap(final String str, final int i, final int i2, final IQrCodeProviderListener iQrCodeProviderListener) {
        if (iQrCodeProviderListener == null) {
            return;
        }
        QBarManager.loadPlugin(new QBarManager.QbarPluginListener() {
            @Override
            public void qbarPluginFailed() {
                iQrCodeProviderListener.a();
            }

            @Override
            public void qbarPluginSuc() {
                Bitmap encode = QBarManager.getInstance().encode(str, "UTF-8");
                if (encode == null) {
                    iQrCodeProviderListener.a();
                    return;
                }
                int i3 = i;
                int i4 = i2;
                Bitmap createBitmap = Bitmap.createBitmap((i4 * 2) + i3, i3 + (i4 * 2), Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(createBitmap);
                canvas.drawColor(-1);
                Matrix matrix = new Matrix();
                matrix.postScale(i / encode.getWidth(), i / encode.getHeight());
                int i5 = i2;
                matrix.postTranslate(i5, i5);
                canvas.drawBitmap(encode, matrix, null);
                iQrCodeProviderListener.a(createBitmap, true, null);
            }
        });
    }

    public static void createQrBitmap(final String str, final int i, final IQrCodeProviderListener iQrCodeProviderListener) {
        QBarManager.loadPlugin(new QBarManager.QbarPluginListener() {
            @Override
            public void qbarPluginFailed() {
                iQrCodeProviderListener.a();
            }

            @Override
            public void qbarPluginSuc() {
                Bitmap encode = QBarManager.getInstance().encode(str, "UTF-8");
                if (encode == null) {
                    iQrCodeProviderListener.a();
                    return;
                }
                int i2 = i;
                int i3 = i2 / 12;
                Bitmap createBitmap = Bitmap.createBitmap(i2 + i3, i2 + i3, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(createBitmap);
                canvas.drawColor(-1);
                Matrix matrix = new Matrix();
                matrix.postScale(i / encode.getWidth(), i / encode.getHeight());
                float f = i3 / 2;
                matrix.postTranslate(f, f);
                canvas.drawBitmap(encode, matrix, null);
                iQrCodeProviderListener.a(createBitmap, true, null);
            }
        });
    }

    public static boolean decode(int[] iArr, int i, int i2, Context context) {
        return decodePicScan(iArr, i, i2, context);
    }

    public static boolean decodePicScan(int[] iArr, int i, int i2, Context context) {
        String[] decodePic;
        if (iArr == null || (decodePic = QBarManager.getInstance().decodePic(iArr, i, i2)) == null || decodePic.length != 2 || decodePic[0].length() <= 0) {
            return false;
        }
        try {
            return handleDecode(decodePic[0], decodePic[1], context);
        } catch (OutOfMemoryError unused) {
            return true;
        }
    }

    public static String decodePicScanResult(int[] iArr, int i, int i2) {
        String[] decodePic;
        if (iArr != null && (decodePic = QBarManager.getInstance().decodePic(iArr, i, i2)) != null && decodePic.length == 2 && decodePic[0].length() > 0) {
            return decodePic[0];
        }
        return null;
    }

    public static Bitmap decodeSampledBitmapFromUri(Context context, Uri uri, int i) {
        InputStream inputStream;
        Bitmap bitmap = null;
        try {
            inputStream = context.getContentResolver().openInputStream(uri);
        } catch (FileNotFoundException unused) {
            inputStream = null;
        } catch (Throwable th) {
            th = th;
            inputStream = null;
        }
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = i;
            options.inJustDecodeBounds = false;
            bitmap = a(context, uri, options);
        } catch (FileNotFoundException unused2) {
        } catch (Throwable th2) {
            th = th2;
            if (inputStream != null) {
                closeQuietly(inputStream);
            }
            throw th;
        }
    }

    public static boolean detect(int[] iArr, int i, int i2) {
        String[] decodePic;
        return iArr != null && (decodePic = QBarManager.getInstance().decodePic(iArr, i, i2)) != null && decodePic.length > 0 && decodePic[0].length() > 0;
    }

    public static Bitmap getAvaiableDimenBitmap(Bitmap bitmap) {
        if (bitmap == null) {
            return null;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
            return getAvaiableDimenBitmap(byteArrayOutputStream.toByteArray());
        } catch (Exception unused) {
            return null;
        }
    }

    public static Bitmap getAvaiableDimenBitmap(byte[] bArr) {
        BitmapFactory.Options options;
        int i;
        int i2;
        Bitmap bitmap = null;
        if (bArr == null) {
            return null;
        }
        try {
            options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
            i = options.outWidth;
            i2 = options.outHeight;
        } catch (OutOfMemoryError unused) {
            System.gc();
        }
        if (i != 0 && i2 != 0) {
            options.inSampleSize = 1;
            if (i > 400 || i2 > 400) {
                options.inJustDecodeBounds = false;
                bitmap = BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
            } else {
                if (i < i2) {
                    i = i2;
                }
                float f = 400.0f / i;
                options.inJustDecodeBounds = false;
                Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length, options);
                if (decodeByteArray == null) {
                    return null;
                }
                int width = (int) (decodeByteArray.getWidth() * f);
                int height = (int) (decodeByteArray.getHeight() * f);
                bitmap = Bitmap.createScaledBitmap(decodeByteArray, width, height, false);
                if (decodeByteArray != null && (decodeByteArray.getWidth() != width || decodeByteArray.getHeight() != height)) {
                    decodeByteArray.recycle();
                }
            }
            return bitmap;
        }
        return null;
    }

    public static byte[] getBitmapBytes(Bitmap bitmap) {
        if (bitmap == null) {
            return null;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        try {
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
            return byteArrayOutputStream.toByteArray();
        } catch (Exception unused) {
            return null;
        }
    }

    public static int getMaxScreenDimen() {
        return Math.max(DeviceUtils.af(), DeviceUtils.ac());
    }

    public static int getScreenWidth() {
        return Math.min(DeviceUtils.af(), DeviceUtils.ac());
    }

    public static boolean handleDecode(String str, String str2, Context context) {
        Activity activity = (Activity) context;
        ResultHandler a2 = new ResultHandlerFactory().a(activity, str);
        new BeepManager(activity, true).b();
        return handleDecodeInternally(str, str2, a2, null, context);
    }

    public static boolean handleDecodeInternally(String str, String str2, ResultHandler resultHandler, Bitmap bitmap, Context context) {
        IFrameworkDelegate iFrameworkDelegate;
        UrlParams c2;
        String str3 = null;
        if (resultHandler.g().equals(ParsedResultType.URI) && (resultHandler instanceof URIResultHandler)) {
            String a2 = ((URIParsedResult) resultHandler.d()).a();
            if (a2 != null && (a2.startsWith(NetUtils.SCHEME_HTTP) || a2.startsWith(NetUtils.SCHEME_HTTPS) || a2.startsWith("qb://"))) {
                ((IFrameworkDelegate) QBContext.getInstance().getService(IFrameworkDelegate.class)).doLoad(new UrlParams(a2).b(1).f(133).c(0).a((Bundle) null));
                return true;
            }
        } else {
            if (resultHandler.g().equals(ParsedResultType.ADDRESSBOOK) && (resultHandler instanceof AddressBookResultHandler)) {
                AddressBookParsedResult addressBookParsedResult = (AddressBookParsedResult) ((AddressBookResultHandler) resultHandler).d();
                String[] j = addressBookParsedResult.j();
                String str4 = (j == null || j.length < 1) ? null : j[0];
                String[] k = addressBookParsedResult.k();
                if (k != null && k.length >= 1) {
                    str3 = k[0];
                }
                Intent intent = new Intent(context, (Class<?>) AddressResultActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("qrtype", resultHandler.g());
                bundle.putStringArray("qrname", addressBookParsedResult.a());
                bundle.putString("qrpronunciation", addressBookParsedResult.b());
                bundle.putStringArray("qrphonenumbers", addressBookParsedResult.d());
                bundle.putStringArray("qrphonetypes", addressBookParsedResult.e());
                bundle.putStringArray("qremails", addressBookParsedResult.f());
                bundle.putStringArray("qrpemailtypes", addressBookParsedResult.g());
                bundle.putString("qrnotes", addressBookParsedResult.i());
                bundle.putString("qrinstantmess", addressBookParsedResult.h());
                bundle.putString("qraddress1", str4);
                bundle.putString("qraddress1type", str3);
                bundle.putString("qrorg", addressBookParsedResult.m());
                bundle.putString("qrtitle", addressBookParsedResult.l());
                bundle.putString("qrurl", addressBookParsedResult.n());
                bundle.putString("qrbirthday", addressBookParsedResult.o());
                bundle.putCharSequence("qrcontent", resultHandler.b());
                intent.putExtras(bundle);
                context.startActivity(intent);
                return true;
            }
            if (resultHandler.g().equals(ParsedResultType.EXPRESS)) {
                if (TextUtils.isEmpty(str2) || !str2.contains("CODE_")) {
                    iFrameworkDelegate = (IFrameworkDelegate) QBContext.getInstance().getService(IFrameworkDelegate.class);
                    c2 = new UrlParams("https://m.sogou.com/web/searchList.jsp?keyword=" + resultHandler.b().toString()).b(1).f(133).c(0);
                } else {
                    StringBuilder sb = new StringBuilder("qb://weapp/?package=kuaidi100");
                    sb.append("&title=%e5%bf%ab%e9%80%92100&entry=75052&appid=124&pagepath=pages%2fresult%2fresult.html%3fnu%3d" + resultHandler.b().toString());
                    iFrameworkDelegate = (IFrameworkDelegate) QBContext.getInstance().getService(IFrameworkDelegate.class);
                    c2 = new UrlParams(sb.toString()).b(1).f(133).c(4);
                }
                iFrameworkDelegate.doLoad(c2.a((Bundle) null));
                return true;
            }
            if (resultHandler.g().equals(ParsedResultType.ISBN) || resultHandler.g().equals(ParsedResultType.PRODUCT)) {
                Intent intent2 = new Intent(ActionConstants2.k, Uri.parse(CaptureActivityImpl.ONECODE_URL + ((Object) resultHandler.b())));
                intent2.setClass(context, ActivityHandler.f32417a);
                intent2.putExtra("internal_back", true);
                intent2.putExtra("fromWhere", 4);
                context.startActivity(intent2);
                return true;
            }
        }
        String trim = resultHandler.b().toString().trim();
        if (trim.toLowerCase().startsWith("kp_")) {
            context.startActivity(new Intent(ActionConstants2.e, Uri.parse(UrlUtils.escapeAllChineseChar(UrlUtils.prepareUrl(String.format("https://tencent.kuaipai.cn/routing.html?key=%s&phonemodel=%s&phoneosversion=%s&appversion=%s&source=QQbrowser", trim, MethodDelegate.getModel().replaceAll("[ |\\/|\\_|\\&|\\|]", ""), Build.VERSION.RELEASE, IQConfigure.f69589b))))));
            return true;
        }
        Intent intent3 = new Intent(context, (Class<?>) NormalResultActivity.class);
        Bundle bundle2 = new Bundle();
        bundle2.putSerializable("qrtype", resultHandler.g());
        bundle2.putCharSequence("qrcontent", resultHandler.b());
        intent3.putExtras(bundle2);
        context.startActivity(intent3);
        return true;
    }

    public static ParsedResult parseResult(String str) {
        return ResultParser.e(str);
    }

    public static byte[] rgb2YCbCr420(int[] iArr, int i, int i2) {
        byte[] bArr = new byte[i * i2];
        for (int i3 = 0; i3 < i2; i3++) {
            for (int i4 = 0; i4 < i; i4++) {
                int i5 = (i3 * i) + i4;
                try {
                    int i6 = iArr[i5] & ViewCompat.MEASURED_SIZE_MASK;
                    int i7 = ((((((i6 & 255) * 66) + (((i6 >> 8) & 255) * 129)) + (((i6 >> 16) & 255) * 25)) + 128) >> 8) + 16;
                    if (i7 < 16) {
                        i7 = 16;
                    } else if (i7 > 255) {
                        i7 = 255;
                    }
                    bArr[i5] = (byte) i7;
                } catch (Exception | OutOfMemoryError unused) {
                    return null;
                }
            }
        }
        return bArr;
    }

    public static void setZoom(Camera camera, float f) {
        if (camera != null) {
            try {
                Camera.Parameters parameters = camera.getParameters();
                if (parameters == null || !parameters.isZoomSupported()) {
                    return;
                }
                int maxZoom = parameters.getMaxZoom();
                int i = (int) ((maxZoom * 1) / f);
                if (i < maxZoom) {
                    i = maxZoom;
                }
                parameters.setZoom(i);
                camera.setParameters(parameters);
            } catch (Exception unused) {
            }
        }
    }

    @Override
    public void icreateQrBitmap(String str, int i, int i2, IQrCodeProviderListener iQrCodeProviderListener) {
        createQrBitmap(str, i, i2, iQrCodeProviderListener);
    }

    @Override
    public void icreateQrBitmap(String str, int i, IQrCodeProviderListener iQrCodeProviderListener) {
        createQrBitmap(str, i, iQrCodeProviderListener);
    }

    @Override
    public void idecode(final int[] iArr, final int i, final int i2, final Context context, final IQrCodeProviderListener iQrCodeProviderListener) {
        QBarManager.loadPlugin(new QBarManager.QbarPluginListener() {
            @Override
            public void qbarPluginFailed() {
                IQrCodeProviderListener iQrCodeProviderListener2 = iQrCodeProviderListener;
                if (iQrCodeProviderListener2 != null) {
                    iQrCodeProviderListener2.a();
                }
            }

            @Override
            public void qbarPluginSuc() {
                boolean decode = ZxingUtils.decode(iArr, i, i2, context);
                IQrCodeProviderListener iQrCodeProviderListener2 = iQrCodeProviderListener;
                if (iQrCodeProviderListener2 != null) {
                    iQrCodeProviderListener2.a(null, decode, null);
                }
            }
        });
    }

    @Override
    public void idecode(final int[] iArr, final int i, final int i2, final IQrCodeProviderListener iQrCodeProviderListener) {
        QBarManager.loadPlugin(new QBarManager.QbarPluginListener() {
            @Override
            public void qbarPluginFailed() {
                IQrCodeProviderListener iQrCodeProviderListener2 = iQrCodeProviderListener;
                if (iQrCodeProviderListener2 != null) {
                    iQrCodeProviderListener2.a();
                }
            }

            @Override
            public void qbarPluginSuc() {
                String decodePicScanResult = ZxingUtils.decodePicScanResult(iArr, i, i2);
                IQrCodeProviderListener iQrCodeProviderListener2 = iQrCodeProviderListener;
                if (iQrCodeProviderListener2 != null) {
                    iQrCodeProviderListener2.a(null, true, decodePicScanResult);
                }
            }
        });
    }

    @Override
    public void idetect(final int[] iArr, final int i, final int i2, final IQrCodeProviderListener iQrCodeProviderListener) {
        QBarManager.loadPlugin(new QBarManager.QbarPluginListener() {
            @Override
            public void qbarPluginFailed() {
                IQrCodeProviderListener iQrCodeProviderListener2 = iQrCodeProviderListener;
                if (iQrCodeProviderListener2 != null) {
                    iQrCodeProviderListener2.a();
                }
            }

            @Override
            public void qbarPluginSuc() {
                boolean detect = ZxingUtils.detect(iArr, i, i2);
                IQrCodeProviderListener iQrCodeProviderListener2 = iQrCodeProviderListener;
                if (iQrCodeProviderListener2 != null) {
                    iQrCodeProviderListener2.a(null, detect, null);
                }
            }
        });
    }

    @Override
    public Bitmap igetAvaiableDimenBitmap(Bitmap bitmap) {
        return getAvaiableDimenBitmap(bitmap);
    }

    @Override
    public Bitmap igetAvaiableDimenBitmap(byte[] bArr) {
        return getAvaiableDimenBitmap(bArr);
    }
}