搜书大师 v23.2版本的 MD5 值为:5ee433f6456b6278bd6e80a5d44df55e

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


package com.flyersoft.seekbooks;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.format.Formatter;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.CookieManager;
import android.webkit.DownloadListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;
import com.flyersoft.WB.S;
import com.lygame.aaa.bf0;
import com.lygame.aaa.e50;
import com.lygame.aaa.o50;
import com.lygame.aaa.x1;
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class b extends Dialog implements View.OnClickListener {
    boolean A0;
    boolean B0;
    String a;
    String a0;
    String b;
    View b0;
    String c;
    Context c0;
    String d;
    h d0;
    String e;
    TextView e0;
    String f;
    View f0;
    String g;
    View g0;
    View h0;
    ImageView i0;
    ImageView j0;
    ImageView k0;
    ImageView l0;
    ImageView m0;
    TextView n0;
    String o0;
    String p0;
    String q0;
    b r0;
    WebView s0;
    boolean t0;
    int u0;
    String v0;
    String w0;
    String x0;
    String y0;
    String z0;

    public class a implements DownloadListener {
        a() {
        }

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
            e50.N5("*onDownloadStart : " + url);
            b bVar = b.this;
            if (bVar.u0 == 2) {
                bVar.f(url);
            }
        }
    }

    class HandlerC0934b extends Handler {
        HandlerC0934b(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message msg) {
            b.this.b0.findViewById(R.id.progressBar2).setVisibility(8);
            Drawable drawable = (Drawable) msg.obj;
            if (drawable != null) {
                b.this.i0.setImageDrawable(drawable);
                b.this.n0.setVisibility(8);
            }
        }
    }

    class c implements Runnable {
        final String a;
        final Handler b;

        c(final String val$url, final Handler val$fullHandler) {
            this.a = val$url;
            this.b = val$fullHandler;
        }

        @Override
        public void run() {
            this.b.sendMessage(this.b.obtainMessage(0, o50.b1(this.a)));
        }
    }

    public class d implements DialogInterface.OnClickListener {
        d() {
        }

        @Override
        public void onClick(DialogInterface dialog, int which) {
            b.this.A0 = true;
        }
    }

    public class e extends Handler {
        final ProgressDialog a;

        e(Looper looper, final ProgressDialog val$dlg) {
            super(looper);
            this.a = val$dlg;
        }

        @Override
        public void handleMessage(Message msg) {
            String h;
            ProgressDialog progressDialog;
            if (msg.what == 0) {
                b.this.B0 = false;
                ProgressDialog progressDialog2 = this.a;
                if (progressDialog2 != null) {
                    progressDialog2.cancel();
                }
                o50.o2(b.this.getContext(), b.this.getContext().getString(R.string.error), (String) msg.obj);
            }
            if (msg.what == 1 && (progressDialog = this.a) != null) {
                int i = msg.arg2;
                if (i == -1) {
                    i = msg.arg1 - 1;
                }
                progressDialog.setTitle(b.this.getContext().getString(R.string.download) + " " + o50.v0(b.this.w0) + " " + Formatter.formatFileSize(b.this.getContext(), i));
                this.a.setMax(i);
                this.a.setProgress(msg.arg1);
            }
            if (msg.what == 2) {
                b bVar = b.this;
                if (bVar.A0) {
                    return;
                }
                bVar.B0 = false;
                String str = bVar.v0;
                bVar.v0 = null;
                if (bVar.w0.endsWith(".zip") || b.this.w0.endsWith(".rar")) {
                    h = b.this.h();
                    b.this.e();
                } else {
                    String v0 = o50.v0(b.this.w0);
                    if (b.this.j(v0)) {
                        if (o50.P1(b.this.w0, e50.c3 + com.ksdk.ssds.manager.b.b + v0, true)) {
                            b.this.v0 = e50.c3 + com.ksdk.ssds.manager.b.b + v0;
                        } else {
                            if (o50.P1(b.this.w0, e50.d2() + com.ksdk.ssds.manager.b.b + v0, true)) {
                                b.this.v0 = e50.d2() + com.ksdk.ssds.manager.b.b + v0;
                            }
                        }
                    }
                    h = null;
                }
                if (b.this.v0 != null) {
                    File file = new File(b.this.v0);
                    if (!file.isFile()) {
                        b.this.v0 = null;
                    } else if (file.length() > 0) {
                        try {
                            b.this.n0.getPaint().setTypeface(Typeface.createFromFile(b.this.v0));
                            b.this.n0.setText(b.this.getContext().getString(R.string.ttf_downloaded) + ": " + o50.v0(b.this.v0));
                        } catch (Exception e) {
                            h = e50.U0(e).replace("Font not found", "Invalid font: ");
                            b.this.v0 = null;
                        }
                    } else {
                        o50.C(b.this.v0);
                        b.this.v0 = null;
                    }
                }
                ProgressDialog progressDialog3 = this.a;
                if (progressDialog3 != null) {
                    progressDialog3.cancel();
                }
                b bVar2 = b.this;
                if (bVar2.v0 == null) {
                    bVar2.v0 = str;
                    bVar2.e();
                    if (h == null) {
                        h = b.this.getContext().getString(R.string.invalid_file);
                    }
                    o50.o2(b.this.getContext(), b.this.getContext().getString(R.string.error), h);
                    return;
                }
                o50.p2(bVar2.getContext(), b.this.getContext().getString(R.string.ttf_downloaded) + ": " + o50.v0(b.this.v0));
            }
        }
    }

    public class f implements Runnable {
        final String a;
        final Handler b;

        f(final String val$url, final Handler val$fullHandler) {
            this.a = val$url;
            this.b = val$fullHandler;
        }

        private void a(URLConnection conn) {
            conn.setConnectTimeout(10000);
            conn.setRequestProperty("Referer", b.this.x0);
            conn.setRequestProperty("Cookie", b.this.y0);
            conn.setRequestProperty("User-Agent", b.this.z0);
        }

        @Override
        public void run() {
            b bVar = b.this;
            bVar.A0 = false;
            bVar.B0 = true;
            String str = this.a;
            bVar.w0 = Uri.decode(str.substring(str.lastIndexOf(com.ksdk.ssds.manager.b.b) + 1));
            OutputStream outputStream = null;
            try {
                try {
                    try {
                        URLConnection openConnection = new URL(this.a).openConnection();
                        a(openConnection);
                        String str2 = null;
                        String str3 = null;
                        for (Map.Entry<String, List<String>> entry : openConnection.getHeaderFields().entrySet()) {
                            e50.N5("header:" + entry.getKey() + " " + entry.getValue());
                            String valueOf = String.valueOf(entry.getValue());
                            if (valueOf.indexOf("filename=") != -1) {
                                str3 = valueOf.substring(valueOf.indexOf("filename=") + 9).trim();
                                if (str3.startsWith("\"")) {
                                    str3 = str3.substring(1, str3.length());
                                }
                                while (true) {
                                    if (!str3.endsWith(x1.b) && !str3.endsWith("\"") && !str3.endsWith("]")) {
                                        break;
                                    } else {
                                        str3 = str3.substring(0, str3.length() - 1);
                                    }
                                }
                            }
                            if (entry.getKey() != null && entry.getKey().equals("Location")) {
                                String trim = valueOf.trim();
                                while (trim.startsWith("[")) {
                                    trim = trim.substring(1);
                                }
                                while (trim.endsWith("]")) {
                                    trim = trim.substring(0, trim.length() - 1);
                                }
                                str2 = trim.trim();
                            }
                        }
                        if (str2 != null) {
                            e50.N5("----------redirection to: " + str2);
                            openConnection = new URL(str2).openConnection();
                            a(openConnection);
                        }
                        if (str3 != null && b.this.j(str3)) {
                            b.this.w0 = str3;
                        }
                        b bVar2 = b.this;
                        if (!bVar2.j(bVar2.w0)) {
                            Handler handler = this.b;
                            handler.sendMessage(handler.obtainMessage(0, b.this.getContext().getString(R.string.no_ttf_found) + ": " + b.this.w0));
                            return;
                        }
                        b.this.w0 = "/sdcard/" + o50.J(b.this.w0);
                        e50.N5("*save to:" + b.this.w0);
                        int contentLength = openConnection.getContentLength();
                        InputStream inputStream = openConnection.getInputStream();
                        byte[] bArr = new byte[8192];
                        OutputStream l0 = o50.l0(b.this.w0);
                        int i = 0;
                        while (true) {
                            int read = inputStream.read(bArr);
                            if (read != -1) {
                                if (b.this.A0) {
                                    e50.N5("--------download cancelled-------");
                                    b bVar3 = b.this;
                                    bVar3.B0 = false;
                                    bVar3.e();
                                    if (l0 != null) {
                                        try {
                                            l0.close();
                                            return;
                                        } catch (Exception e) {
                                            e50.S0(e);
                                            return;
                                        }
                                    }
                                    return;
                                }
                                l0.write(bArr, 0, read);
                                i += read;
                                e50.N5(i + com.ksdk.ssds.manager.b.b + contentLength);
                                Handler handler2 = this.b;
                                handler2.sendMessage(handler2.obtainMessage(1, i, contentLength));
                            } else {
                                this.b.sendEmptyMessage(2);
                                if (l0 != null) {
                                    l0.close();
                                    return;
                                }
                                return;
                            }
                        }
                    } catch (Exception e2) {
                        e50.S0(e2);
                        Handler handler3 = this.b;
                        handler3.sendMessage(handler3.obtainMessage(0, e50.U0(e2)));
                        if (0 != 0) {
                            outputStream.close();
                        }
                    }
                } catch (Throwable th) {
                    if (0 != 0) {
                        try {
                            outputStream.close();
                        } catch (Exception e3) {
                            e50.S0(e3);
                        }
                    }
                    throw th;
                }
            } catch (Exception e4) {
                e50.S0(e4);
            }
        }
    }

    public class g extends WebViewClient {
        g() {
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            e50.N5("#onPageFinished : " + url);
            super.onPageFinished(view, url);
            b.this.b0.findViewById(R.id.progressBar2).setVisibility(8);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            e50.N5("#onPageStarted : " + url);
            super.onPageStarted(view, url, favicon);
            b.this.b0.findViewById(R.id.progressBar2).setVisibility(0);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, final String url) {
            e50.N5("#url : " + url);
            b bVar = b.this;
            if (bVar.u0 == 2 && bVar.j(url)) {
                b.this.f(url);
                return true;
            }
            view.loadUrl(url);
            return true;
        }
    }

    public interface h {
        void onGetImageFile(String saveTo, Drawable d);
    }

    public b(Context context, h saveImage, String filename, String key, int downloadType, boolean resizeImage) {
        super(context, R.style.dialog_fullscreen);
        String g2;
        this.a = "https://www.google.com/search?tbm=isch&q=";
        this.b = "http://www.bing.com/images/search?q=";
        this.c = "https://images.search.yahoo.com/search/images?ei=UTF-8&p=";
        this.d = "http://pic.sogou.com/pics?ie=utf8&query=";
        this.e = "https://www.google.com/search?q=";
        this.f = "http://www.bing.com/search?q=";
        this.g = "https://search.yahoo.com/search?p=";
        this.a0 = "http://www.sogou.com/web?ie=utf8&query=";
        this.A0 = true;
        this.r0 = this;
        this.d0 = saveImage;
        this.p0 = filename;
        this.u0 = downloadType;
        this.q0 = key;
        this.t0 = resizeImage;
        if (downloadType == 1) {
            g2 = getContext().getString(R.string.background_image);
        } else if (downloadType == 2) {
            g2 = "下载字体";
        } else if (downloadType == 3) {
            g2 = getContext().getString(R.string.add_to_desktop);
        } else {
            g2 = g();
        }
        this.o0 = g2;
        if (this.u0 == 2) {
            this.q0 += " ttf";
        }
        Context context2 = getContext();
        this.c0 = context2;
        View inflate = LayoutInflater.from(context2).inflate(R.layout.download_cover, (ViewGroup) null);
        this.b0 = inflate;
        setContentView(inflate);
    }

    public void e() {
        o50.P1(this.w0, "/sdcard/errttf", true);
    }

    public void f(final String url) {
        if (this.B0) {
            return;
        }
        this.x0 = this.s0.getUrl();
        this.y0 = CookieManager.getInstance().getCookie(this.x0);
        this.z0 = this.s0.getSettings().getUserAgentString();
        ProgressDialog progressDialog = new ProgressDialog(getContext());
        progressDialog.setProgressStyle(1);
        progressDialog.setButton(getContext().getString(R.string.cancel), new d());
        progressDialog.setTitle(getContext().getString(R.string.download));
        progressDialog.setCancelable(false);
        progressDialog.show();
        new Thread(new f(url, new e(Looper.getMainLooper(), progressDialog))).start();
    }

    public static String g() {
        return e50.Z2().getLanguage().equals("ru") ? "Загрузить обложку книги" : o50.t(e50.S1().getString(R.string.download), e50.S1().getString(R.string.book_cover));
    }

    public String h() {
        String str = null;
        try {
            com.flyersoft.components.a c2 = com.flyersoft.components.a.c(this.w0);
            ArrayList<String> d2 = c2.d();
            ArrayList arrayList = new ArrayList();
            Iterator<String> it = d2.iterator();
            while (it.hasNext()) {
                String next = it.next();
                if (e50.U4(next)) {
                    arrayList.add(next);
                }
            }
            if (arrayList.size() == 0) {
                return getContext().getString(R.string.no_ttf_found);
            }
            int i = 0;
            int i2 = 0;
            while (true) {
                if (i >= arrayList.size()) {
                    i = i2;
                    break;
                }
                if (((String) arrayList.get(i)).toLowerCase().indexOf("-regular") != -1) {
                    break;
                }
                if (i2 != i && c2.g((String) arrayList.get(i2)).b < c2.g((String) arrayList.get(i)).b) {
                    i2 = i;
                }
                i++;
            }
            String J = o50.J(o50.v0((String) arrayList.get(i)));
            if (c2.k((String) arrayList.get(i), e50.c3 + com.ksdk.ssds.manager.b.b + J)) {
                this.v0 = e50.c3 + com.ksdk.ssds.manager.b.b + J;
            } else {
                if (c2.k((String) arrayList.get(i), e50.d2() + com.ksdk.ssds.manager.b.b + J)) {
                    this.v0 = e50.d2() + com.ksdk.ssds.manager.b.b + J;
                } else {
                    str = getContext().getString(R.string.invalid_file);
                }
            }
            if (str == null && arrayList.size() > 1) {
                for (int i3 = 0; i3 < arrayList.size(); i3++) {
                    if (i3 != i) {
                        String J2 = o50.J(o50.v0((String) arrayList.get(i3)));
                        c2.k((String) arrayList.get(i3), o50.n0(this.v0) + com.ksdk.ssds.manager.b.b + J2);
                    }
                }
            }
            return str;
        } catch (Exception e2) {
            e50.S0(e2);
            return e50.U0(e2);
        }
    }

    private void i() {
        this.e0 = (TextView) this.b0.findViewById(R.id.titleB);
        this.f0 = this.b0.findViewById(R.id.exitB);
        this.g0 = this.b0.findViewById(R.id.okB);
        this.h0 = this.b0.findViewById(R.id.cancelB);
        this.e0.setText(this.o0);
        this.f0.setVisibility(8);
        this.g0.setOnClickListener(this);
        this.h0.setOnClickListener(this);
        this.n0 = (TextView) this.b0.findViewById(R.id.tipTv);
        this.i0 = (ImageView) this.b0.findViewById(R.id.imageView1);
        this.j0 = (ImageView) this.b0.findViewById(R.id.google);
        this.k0 = (ImageView) this.b0.findViewById(R.id.bing);
        this.l0 = (ImageView) this.b0.findViewById(R.id.yahoo);
        ImageView imageView = (ImageView) this.b0.findViewById(R.id.baidu);
        this.m0 = imageView;
        imageView.setVisibility(e50.C8 ? 0 : 4);
        this.j0.setOnClickListener(this);
        this.k0.setOnClickListener(this);
        this.l0.setOnClickListener(this);
        this.m0.setOnClickListener(this);
        if (this.u0 == 2) {
            this.n0.setText(R.string.click_ttf_in_browser);
        }
        WebView webView = (WebView) findViewById(R.id.webView);
        this.s0 = webView;
        registerForContextMenu(webView);
        S.setWebViewSettings(this.s0);
        this.s0.setWebViewClient(new g());
        this.s0.setWebChromeClient(new S.NormalChromeClient());
        this.s0.setDownloadListener(new a());
        k();
    }

    public boolean j(String url) {
        String lowerCase = url.toLowerCase();
        return e50.U4(lowerCase) || lowerCase.endsWith(".zip") || lowerCase.endsWith(".rar");
    }

    private void k() {
        String str;
        int i = e50.Q4;
        if (i == 0) {
            str = this.u0 == 2 ? this.e : this.a;
        } else if (i == 1) {
            str = this.u0 == 2 ? this.f : this.b;
        } else if (i == 2) {
            str = this.u0 == 2 ? this.g : this.c;
        } else if (i != 3) {
            str = e50.F8 ? this.u0 == 2 ? this.f : this.b : this.u0 == 2 ? this.e : this.a;
        } else {
            str = this.u0 == 2 ? this.a0 : this.d;
        }
        String str2 = this.q0;
        if (this.u0 == 0 && str2.length() < 8) {
            StringBuilder sb = new StringBuilder();
            sb.append(str2);
            sb.append(e50.C8 ? " 封面" : e50.Q4 == 1 ? "" : " book cover");
            str2 = sb.toString();
        }
        if (this.u0 == 2) {
            CookieManager.getInstance().setAcceptCookie(true);
        }
        this.s0.loadUrl(str + Uri.encode(str2));
    }

    @Override
    public void onClick(View v) {
        String str;
        if (v == this.g0) {
            if (this.u0 == 2) {
                h hVar = this.d0;
                if (hVar != null && (str = this.v0) != null) {
                    hVar.onGetImageFile(str, null);
                }
            } else if (this.d0 != null && this.i0.getDrawable() != null) {
                Drawable drawable = this.i0.getDrawable();
                if (this.t0) {
                    int intrinsicWidth = drawable.getIntrinsicWidth();
                    int intrinsicHeight = drawable.getIntrinsicHeight();
                    if (intrinsicWidth > 540 && intrinsicHeight > 0) {
                        drawable = o50.K2(getContext().getResources(), drawable, 540, (intrinsicHeight * 540) / intrinsicWidth);
                    }
                }
                this.d0.onGetImageFile(this.p0, drawable);
            }
            cancel();
        }
        if (v == this.h0) {
            cancel();
        }
        if (v == this.j0) {
            e50.Q4 = 0;
            k();
        }
        if (v == this.k0) {
            e50.Q4 = 1;
            k();
        }
        if (v == this.l0) {
            e50.Q4 = 2;
            k();
        }
        if (v == this.m0) {
            e50.Q4 = 3;
            k();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(1024);
        e50.z6(getWindow(), 0.75f, true);
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.width = -1;
        attributes.height = -1;
        getWindow().setAttributes(attributes);
        i();
        e50.F6(this.b0);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        WebView.HitTestResult hitTestResult;
        if (!(v instanceof WebView) || (hitTestResult = ((WebView) v).getHitTestResult()) == null) {
            return;
        }
        if (this.u0 == 2) {
            String extra = hitTestResult.getExtra();
            if (extra == null) {
                return;
            }
            e50.N5("*********" + extra);
            if (j(extra)) {
                f(extra);
                return;
            } else {
                Context context = this.c0;
                o50.p2(context, context.getString(R.string.no_ttf_found));
                return;
            }
        }
        int type = hitTestResult.getType();
        if (type != 5 && type != 8) {
            Context context2 = this.c0;
            o50.p2(context2, context2.getString(R.string.not_image_anchor_in_browser));
            return;
        }
        String extra2 = hitTestResult.getExtra();
        e50.N5("*********" + extra2);
        int indexOf = extra2.indexOf("data:image");
        if (indexOf != -1) {
            byte[] a2 = com.flyersoft.components.l.a(extra2.substring(extra2.indexOf(bf0.COMMA, indexOf) + 1));
            this.i0.setImageDrawable(new BitmapDrawable(this.c0.getResources(), BitmapFactory.decodeByteArray(a2, 0, a2.length)));
            this.n0.setVisibility(8);
        } else {
            this.b0.findViewById(R.id.progressBar2).setVisibility(0);
            new Thread(new c(extra2, new HandlerC0934b(Looper.getMainLooper()))).start();
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (this.s0.canGoBack()) {
            this.s0.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}