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

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


package com.tencent.mtt.useraddress;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.webkit.ValueCallback;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.common.utils.FileUtils;
import com.tencent.common.utils.ZipUtils;
import com.tencent.mtt.ContextHolder;
import com.tencent.mtt.R;
import com.tencent.mtt.base.functionwindow.ActivityHandler;
import com.tencent.mtt.base.skin.MttResources;
import com.tencent.mtt.browser.account.js.IBaseJsApiCallBack;
import com.tencent.mtt.browser.account.js.ReginJsApiCallback;
import com.tencent.mtt.browser.download.core.impl.DownloadServiceManager;
import com.tencent.mtt.browser.download.engine.DownloadErrorDetail;
import com.tencent.mtt.browser.download.engine.DownloadInfo;
import com.tencent.mtt.browser.download.engine.DownloadTask;
import com.tencent.mtt.browser.download.engine.DownloadTaskListener;
import com.tencent.mtt.browser.download.engine.PauseReason;
import com.tencent.mtt.setting.PublicSettingManager;
import com.tencent.mtt.useraddress.AddressPicker;
import com.tencent.mtt.view.dialog.alert.MttLoadingDialog;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import qb.a.e;
import qb.a.f;

public class RegionUtil implements Handler.Callback, DownloadTaskListener {

    private String f72306a;

    private Handler f72307b;

    private Context f72308c;
    private ValueCallback<IBaseJsApiCallBack> e;

    private MttLoadingDialog f72309d = null;
    private String f = null;
    private String g = null;
    private String h = null;
    private boolean i = false;
    private boolean j = false;
    private IRegionLoadListener k = null;
    private boolean l = false;

    public interface IRegionLoadListener {
        void a(List<Province> list);
    }

    public RegionUtil(Context context, ValueCallback<IBaseJsApiCallBack> valueCallback) {
        this.f72306a = null;
        this.f72307b = null;
        this.f72308c = null;
        this.e = null;
        this.f72308c = context;
        this.e = valueCallback;
        this.f72307b = new Handler(Looper.getMainLooper(), this);
        this.f72306a = FileUtils.a(ContextHolder.getAppContext()).getAbsolutePath();
    }

    private void a(List<Province> list) {
        if (list == null || list.size() <= 0) {
            return;
        }
        AddressPicker addressPicker = new AddressPicker(ActivityHandler.b().a(), list);
        addressPicker.a(this.i);
        addressPicker.b(e.s);
        addressPicker.a(1.0f, 1.0f, 1.0f);
        addressPicker.c(false);
        addressPicker.e(MttResources.d(e.E));
        addressPicker.f(e.f85871a);
        addressPicker.a(MttResources.h(f.cR));
        addressPicker.h(MttResources.h(f.cR));
        a(list, addressPicker);
        addressPicker.b(e.f85873b, e.f85873b);
        addressPicker.a(MttResources.n(R.string.ud));
        addressPicker.b(MttResources.n(R.string.atp));
        addressPicker.j(MttResources.d(e.E));
        addressPicker.d(R.anim.w);
        addressPicker.i(MttResources.h(f.cR));
        addressPicker.g(e.f);
        addressPicker.a(new AddressPicker.OnAddressPickListener() {
            @Override
            public void a(Province province, City city, District district) {
                RegionUtil.this.e.onReceiveValue(new ReginJsApiCallback(province != null ? province.getName() : "", city != null ? city.getName() : "", district != null ? district.getName() : "", province != null ? province.getId() : "", city != null ? city.getId() : "", district != null ? district.getId() : ""));
            }
        });
        addressPicker.j();
    }

    private void a(List<Province> list, AddressPicker addressPicker) {
        Province province;
        int i;
        int i2;
        int i3;
        City city = null;
        if (!TextUtils.isEmpty(this.f)) {
            Iterator<Province> it = list.iterator();
            i = 0;
            while (it.hasNext()) {
                province = it.next();
                if (TextUtils.equals(province.getId(), this.f)) {
                    break;
                } else {
                    i++;
                }
            }
        }
        province = null;
        i = 0;
        if (province != null && !TextUtils.isEmpty(this.g)) {
            i2 = 0;
            for (City city2 : province.getCities()) {
                if (TextUtils.equals(city2.getId(), this.g)) {
                    city = city2;
                    break;
                }
                i2++;
            }
        }
        i2 = 0;
        if (city != null && !TextUtils.isEmpty(this.h)) {
            Iterator<District> it2 = city.getCounties().iterator();
            i3 = 0;
            while (it2.hasNext()) {
                if (TextUtils.equals(it2.next().getId(), this.h)) {
                    break;
                } else {
                    i3++;
                }
            }
        }
        i3 = 0;
        addressPicker.a(i, i2, i3);
    }

    private String e() {
        FileInputStream fileInputStream;
        File file = new File(this.f72306a + File.separator + "simplify_region.json");
        if (file.exists()) {
            try {
                fileInputStream = FileUtils.i(file);
                try {
                    String a2 = FileUtils.a(fileInputStream, "UTF-8");
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException unused) {
                        }
                    }
                    return a2;
                } catch (IOException unused2) {
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException unused3) {
                        }
                    }
                    return null;
                } catch (Throwable th) {
                    th = th;
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException unused4) {
                        }
                    }
                    throw th;
                }
            } catch (IOException unused5) {
                fileInputStream = null;
            } catch (Throwable th2) {
                th = th2;
                fileInputStream = null;
            }
        } else {
            DownloadInfo downloadInfo = new DownloadInfo();
            downloadInfo.f37604a = "https://res.imtt.qq.com/region/simplify_region.zip";
            downloadInfo.f = FileUtils.a(ContextHolder.getAppContext()).getAbsolutePath();
            downloadInfo.f37606c = "simplify_region.zip";
            downloadInfo.j = false;
            downloadInfo.h = false;
            downloadInfo.H |= 32;
            DownloadServiceManager.a().addTaskListener(downloadInfo.f37604a, this);
            DownloadServiceManager.a().startDownloadTask(downloadInfo, null, null);
            PublicSettingManager.a().setBoolean("regin_downloading", true);
            this.f72307b.sendEmptyMessage(100);
        }
        return null;
    }

    public RegionUtil a(IRegionLoadListener iRegionLoadListener) {
        this.j = true;
        this.k = iRegionLoadListener;
        return this;
    }

    public RegionUtil a(JSONObject jSONObject) {
        if (jSONObject == null) {
            return this;
        }
        this.f = jSONObject.optString("provinceId");
        this.g = jSONObject.optString("cityId");
        this.h = jSONObject.optString("districtId");
        return this;
    }

    public RegionUtil a(boolean z) {
        this.i = z;
        return this;
    }

    public void a() {
        if (this.f72309d == null) {
            this.f72309d = new MttLoadingDialog(this.f72308c);
        }
        this.f72309d.show();
        BrowserExecutorSupplier.postForBackgroundTasks(new BrowserExecutorSupplier.BackgroundRunable() {
            @Override
            public void doRun() {
                List<Province> c2 = RegionUtil.this.c();
                Message obtainMessage = RegionUtil.this.f72307b.obtainMessage(103);
                obtainMessage.obj = c2;
                obtainMessage.sendToTarget();
            }
        });
    }

    public RegionUtil b() {
        this.l = true;
        return this;
    }

    public List<Province> c() {
        ArrayList arrayList = new ArrayList();
        String e = e();
        if (TextUtils.isEmpty(e)) {
            return arrayList;
        }
        try {
            StringBuffer stringBuffer = new StringBuffer(e);
            if (this.l) {
                stringBuffer.insert(1, "{\"name\": \"保密\",\"id\": \"0\",\"data\": [{\"name\": \"保密\",\"id\": \"0\",\"data\": [{\"id\": \"0\",\"name\": \"保密\"}]}]},");
            }
            JSONArray jSONArray = new JSONArray(stringBuffer.toString());
            for (int i = 0; i < jSONArray.length(); i++) {
                JSONObject jSONObject = jSONArray.getJSONObject(i);
                String optString = jSONObject.optString("name");
                String optString2 = jSONObject.optString("id");
                String optString3 = jSONObject.optString("data");
                Province province = new Province(optString, optString2);
                province.parse(optString3);
                arrayList.add(province);
            }
        } catch (JSONException unused) {
        }
        return arrayList;
    }

    public boolean d() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.f72306a);
        sb.append(File.separator);
        sb.append("simplify_region.json");
        return new File(sb.toString()).exists();
    }

    @Override
    public boolean handleMessage(Message message) {
        MttLoadingDialog mttLoadingDialog;
        if (message.what == 100) {
            if (this.j) {
                return false;
            }
            if (this.f72309d == null) {
                this.f72309d = new MttLoadingDialog(this.f72308c);
            }
            this.f72309d.show();
            return false;
        }
        if (message.what == 101) {
            if (this.j) {
                return false;
            }
            MttLoadingDialog mttLoadingDialog2 = this.f72309d;
            if (mttLoadingDialog2 != null) {
                mttLoadingDialog2.dismiss();
            }
            a();
            return false;
        }
        if (message.what == 102) {
            mttLoadingDialog = this.f72309d;
            if (mttLoadingDialog == null) {
                return false;
            }
        } else {
            if (message.what != 103) {
                return false;
            }
            if (message.obj != null && (message.obj instanceof List)) {
                a((List<Province>) message.obj);
            }
            mttLoadingDialog = this.f72309d;
            if (mttLoadingDialog == null) {
                return false;
            }
        }
        mttLoadingDialog.dismiss();
        return false;
    }

    @Override
    public void onTaskCompleted(DownloadTask downloadTask) {
        PublicSettingManager.a().setBoolean("regin_downloading", false);
        if (TextUtils.equals(downloadTask.k(), "https://res.imtt.qq.com/region/simplify_region.zip")) {
            DownloadServiceManager.a().removeTaskListener(this);
            ZipUtils.a(new File(this.f72306a + File.separator + "simplify_region.zip"), new File(this.f72306a), "simplify_region.json");
            if (!this.j) {
                this.f72307b.sendEmptyMessage(101);
            } else if (this.k != null) {
                this.k.a(c());
            }
        }
    }

    @Override
    public void onTaskCreated(DownloadTask downloadTask) {
    }

    @Override
    public void onTaskFailed(DownloadTask downloadTask, DownloadErrorDetail downloadErrorDetail) {
        PublicSettingManager.a().setBoolean("regin_downloading", false);
        DownloadServiceManager.a().removeTaskListener(this);
        this.f72307b.sendEmptyMessage(102);
    }

    @Override
    public void onTaskPaused(DownloadTask downloadTask, PauseReason pauseReason) {
    }

    @Override
    public void onTaskProgress(DownloadTask downloadTask) {
    }

    @Override
    public void onTaskRemoved(DownloadTask downloadTask) {
    }

    @Override
    public void onTaskStarted(DownloadTask downloadTask) {
    }

    @Override
    public void onTaskWaiting(DownloadTask downloadTask) {
    }
}