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

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


package com.tencent.mtt.external.explorerone.camera.base.ui.panel.share;

import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextUtils;
import com.tencent.common.http.Apn;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.common.utils.FileUtils;
import com.tencent.common.utils.Md5Utils;
import com.tencent.common.utils.StringUtils;
import com.tencent.common.utils.ZipUtils;
import com.tencent.mtt.ContextHolder;
import com.tencent.mtt.browser.download.core.impl.DownloadServiceManager;
import com.tencent.mtt.browser.download.engine.BaseDownloadTaskListener;
import com.tencent.mtt.browser.download.engine.DownloadInfo;
import com.tencent.mtt.browser.download.engine.DownloadTask;
import com.tencent.mtt.setting.PublicSettingManager;
import com.tencent.mtt.view.common.QBTextView;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class CameraFontManager extends BaseDownloadTaskListener {

    private static final List<String> f51352a = Arrays.asList("camera_font_kai.ttf", "camera_font_song.ttf");

    private boolean f51353b;

    private HashMap<String, Typeface> f51354c;

    public static final class CameraFontManagerHolder {

        private static final CameraFontManager f51357a = new CameraFontManager();

        private CameraFontManagerHolder() {
        }
    }

    private CameraFontManager() {
        this.f51353b = false;
        this.f51354c = new HashMap<>();
    }

    private Typeface a(File file) {
        if (file == null || !file.exists()) {
            return null;
        }
        Typeface typeface = null;
        boolean z = false;
        for (int i = 0; !z && i < 3; i++) {
            try {
                Typeface createFromFile = Typeface.createFromFile(file);
                typeface = createFromFile;
                z = createFromFile != null;
            } catch (Throwable unused) {
            }
        }
        return typeface;
    }

    public static CameraFontManager a() {
        return CameraFontManagerHolder.f51357a;
    }

    public void a(String str, File file) {
        DownloadInfo downloadInfo = new DownloadInfo();
        downloadInfo.f37604a = str;
        downloadInfo.f37606c = file.getName();
        downloadInfo.f = file.getParent();
        downloadInfo.H |= 32;
        downloadInfo.j = false;
        DownloadServiceManager.a().addTaskListener(str, a());
        DownloadServiceManager.a().startDownloadTask(downloadInfo, null, null);
    }

    static File c() {
        return f();
    }

    static File d() {
        return e();
    }

    private static File e() {
        File file = new File(FileUtils.d(ContextHolder.getAppContext()), "camera_fonts");
        if (!file.exists() || file.isFile()) {
            file.mkdir();
        }
        return file;
    }

    private static File f() {
        return new File(FileUtils.d(ContextHolder.getAppContext()), "camera_fonts_dl_temp.zip");
    }

    public String[] g() {
        String[] split;
        String string = PublicSettingManager.a().getString("PREFERENCE_TYPE_CAMERA_FONT_CONFIG", "https://res.imtt.qq.com/life/explore/tbs_res_imtt_tbs_test_camera_font.zip|cb8eef67d4ffa0bb18bc0ff56c3d1413");
        if (TextUtils.isEmpty(string) || (split = string.split("\\|")) == null || split.length != 2 || TextUtils.isEmpty(split[0]) || TextUtils.isEmpty(split[1])) {
            return null;
        }
        return split;
    }

    public boolean h() {
        Typeface a2;
        File e = e();
        HashMap hashMap = new HashMap();
        for (String str : f51352a) {
            File file = new File(e, str);
            if (!file.exists() || (a2 = a(file)) == null) {
                return false;
            }
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setTypeface(a2);
            paint.measureText("正");
            hashMap.put(str, a2);
        }
        this.f51354c.putAll(hashMap);
        return true;
    }

    public boolean i() {
        Iterator<String> it = f51352a.iterator();
        boolean z = true;
        while (it.hasNext()) {
            z &= ZipUtils.a(f(), e(), it.next());
            if (!z) {
                break;
            }
        }
        return z;
    }

    public Typeface a(String str) {
        if (!this.f51353b) {
            b();
        }
        return this.f51354c.get(str);
    }

    public void a(QBTextView qBTextView, String str) {
        Typeface a2;
        if (qBTextView == null || TextUtils.isEmpty(str) || (a2 = a(str)) == null) {
            return;
        }
        qBTextView.setTypeface(a2);
    }

    public void b() {
        if (this.f51353b) {
            return;
        }
        this.f51353b = true;
        BrowserExecutorSupplier.forIoTasks().execute(new Runnable() {
            @Override
            public void run() {
                boolean z;
                boolean z2;
                String[] g = CameraFontManager.this.g();
                if (g == null) {
                    return;
                }
                File c2 = CameraFontManager.c();
                if (c2.exists()) {
                    String a2 = Md5Utils.a(c2);
                    if (!TextUtils.isEmpty(a2) && StringUtils.b(a2, g[1])) {
                        z = false;
                        z2 = true;
                        if (!z && !CameraFontManager.this.h()) {
                            z = true;
                        }
                        if (z && z2 && CameraFontManager.this.i() && CameraFontManager.this.h()) {
                            z = false;
                        }
                        if (z) {
                            return;
                        }
                        FileUtils.b(CameraFontManager.d());
                        FileUtils.b(c2);
                        if (Apn.isWifiMode()) {
                            CameraFontManager.this.a(g[0], c2);
                            return;
                        }
                        return;
                    }
                    z = false;
                } else {
                    z = true;
                }
                z2 = false;
                if (!z) {
                    z = true;
                }
                if (z) {
                    z = false;
                }
                if (z) {
                }
            }
        });
    }

    @Override
    public void onTaskCompleted(DownloadTask downloadTask) {
        BrowserExecutorSupplier.forIoTasks().execute(new Runnable() {
            @Override
            public void run() {
                DownloadServiceManager.a().removeTaskListener(CameraFontManager.a());
                File c2 = CameraFontManager.c();
                String[] g = CameraFontManager.this.g();
                boolean z = true;
                if (g != null && g.length == 2) {
                    String a2 = Md5Utils.a(c2);
                    if (TextUtils.isEmpty(a2) || !StringUtils.b(a2, g[1])) {
                        z = false;
                    }
                }
                if (z) {
                    z = CameraFontManager.this.i();
                }
                if (z) {
                    CameraFontManager.this.h();
                } else {
                    FileUtils.b(CameraFontManager.d());
                    FileUtils.b(c2);
                }
            }
        });
    }
}