Wallkin v1.86859532693版本的 MD5 值为:c3099a56aae2c3706b2239994117cc3a

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


package net.dinglisch.android.taskerm;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import com.google.android.gms.maps.g;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.danlew.android.joda.R;
import net.dinglisch.android.taskerm.HTMLView;
import net.dinglisch.android.taskerm.fc;
public class HTMLView extends MyActivity implements com.joaomgcd.taskerm.helper.b {
    private static String f11131a = "<(?:TITLE|H\\d)>(?:Tasker:\\s*)?(.*)</(?:TITLE|H\\d)>";
    private c f11132b;
    private WebView f11134d;
    private String f11136f;
    private String g;
    private BroadcastReceiver f11133c = null;
    private com.joaomgcd.taskerm.helper.actions.j f11135e = new com.joaomgcd.taskerm.helper.actions.j(this);
    private ProgressDialog h = null;

    public enum c {
        Confirm,
        Inform,
        InformWithAccept
    }

    @Override
    public void a(com.joaomgcd.taskerm.util.bw bwVar, com.joaomgcd.taskerm.util.cs csVar) {
    }

    public static boolean a(Activity activity, String str) {
        File a2 = a(str);
        if (a2 == null) {
            gs.d(activity, (int) R.string.err_nosd, a2);
        } else if (gs.e(a2)) {
            String str2 = str + "." + a(activity.getResources(), str) + ".zip";
            gs.a(activity, ct.a(activity, (int) R.string.dt_download_language, new Object[0]), Uri.parse("https://tasker.joaoapps.com/userguide/" + str + "/zip/" + str2), new File(a2, str2), "application/zip", null);
            return true;
        } else {
            gs.d(activity, (int) R.string.f_mkdir_failed, a2);
        }
        return false;
    }

    public static File a(String str) {
        if (gs.h() == null) {
            bo.b("HV", "no SD card");
            return null;
        }
        return new File(new File(gs.k(), "userguide"), str);
    }

    public static String a(Resources resources, String str) {
        return ct.a(resources, (int) R.array.language_versions)[b(resources, str)];
    }

    public static String a(Resources resources, int i) {
        return ct.a(resources, (int) R.array.languages_short)[i];
    }

    public static int b(Resources resources, String str) {
        return gs.b(str, ct.a(resources, (int) R.array.languages_short));
    }

    public static synchronized boolean a(Context context) {
        boolean z;
        synchronized (HTMLView.class) {
            String a2 = bj.a(gs.g(context));
            File a3 = a(a2);
            z = true;
            if (a3 != null) {
                String a4 = a(context.getResources(), a2);
                if (a4.startsWith("XXX")) {
                }
            }
            z = false;
        }
        return z;
    }

    public static ProgressDialog a(Activity activity) {
        ProgressDialog show = ProgressDialog.show(activity, ct.a(activity, (int) R.string.dt_download_language, new Object[0]), ct.a(activity, (int) R.string.dc_please_wait, new Object[0]), true);
        show.setCancelable(true);
        return show;
    }

    public static void b(Activity activity, String str) {
        a(activity, str, -1, c.Inform);
    }

    public static void a(Activity activity, String str, int i, c cVar) {
        activity.startActivityForResult(a(activity, str, cVar), i);
    }

    public static Intent a(Activity activity, String str, c cVar) {
        return new Intent(activity, HTMLView.class).putExtra("url", str).putExtra("sty", cVar.ordinal());
    }

    public static void a(Context context, fb fbVar, String str, fc.a aVar, List<fc> list) {
        String str2;
        BufferedReader bufferedReader;
        Pattern pattern;
        BufferedReader bufferedReader2;
        fc fcVar;
        boolean z;
        String str3;
        fc fcVar2;
        String str4 = str;
        Pattern compile = Pattern.compile(f11131a, 2);
        String a2 = ct.a(context, (int) R.string.pl_line, new Object[0]);
        File a3 = a(bj.a(gs.g(context)));
        if (str4 != null) {
            a3 = new File(a3, str4);
        }
        if (a3 == null) {
            bo.d("HV", "search: no lang dir");
            return;
        }
        File[] listFiles = a3.listFiles(new FileFilter() {
            @Override
            public boolean accept(File file) {
                String name = file.getName();
                return name.endsWith(".html") && !name.endsWith("index.html");
            }
        });
        if (gs.a((Object[]) listFiles)) {
            bo.d("HV", "search: no files found in " + a3);
            return;
        }
        int length = listFiles.length;
        int i = 0;
        while (i < length) {
            File file = listFiles[i];
            String name = file.getName();
            if (str4 == null) {
                str2 = name;
            } else {
                str2 = str4 + File.separator + name;
            }
            try {
                bufferedReader = new BufferedReader(new FileReader(file));
                String str5 = name;
                boolean z2 = false;
                String str6 = null;
                StringBuilder sb = null;
                fcVar = null;
                int i2 = 1;
                while (true) {
                    try {
                        try {
                            String readLine = bufferedReader.readLine();
                            if (readLine != null && !z2) {
                                try {
                                    Matcher matcher = compile.matcher(readLine);
                                    if (matcher.find()) {
                                        str3 = matcher.group(1);
                                        z = true;
                                        if (readLine != null && fbVar.a(readLine)) {
                                            if (sb == null) {
                                                sb = new StringBuilder();
                                                if (str6 != null) {
                                                    sb.append(str6);
                                                    sb.append('\n');
                                                }
                                            }
                                            sb.append(readLine);
                                            pattern = compile;
                                            i2++;
                                            if (readLine != null) {
                                                break;
                                            }
                                            str6 = readLine;
                                            str5 = str3;
                                            z2 = z;
                                            compile = pattern;
                                        }
                                        pattern = compile;
                                        i2++;
                                        if (readLine != null) {
                                        }
                                    }
                                } catch (FileNotFoundException e2) {
                                    e = e2;
                                    pattern = compile;
                                    bufferedReader2 = bufferedReader;
                                    bo.a("HV", "search: " + file, (Throwable) e);
                                } catch (IOException e3) {
                                    e = e3;
                                    pattern = compile;
                                    bufferedReader2 = bufferedReader;
                                    try {
                                        bo.a("HV", "search: " + file, (Exception) e);
                                    } catch (Throwable th) {
                                        th = th;
                                        bufferedReader = bufferedReader2;
                                        if (bufferedReader != null) {
                                        }
                                        throw th;
                                    }
                                }
                            }
                            z = z2;
                            str3 = str5;
                            if (readLine != null) {
                                if (sb == null) {
                                }
                                sb.append(readLine);
                                pattern = compile;
                                i2++;
                                if (readLine != null) {
                                }
                            }
                            pattern = compile;
                            i2++;
                            if (readLine != null) {
                            }
                        } catch (Throwable th2) {
                            th = th2;
                            if (bufferedReader != null) {
                                gs.a((Reader) bufferedReader);
                            }
                            throw th;
                        }
                    } catch (FileNotFoundException e4) {
                        e = e4;
                        pattern = compile;
                    } catch (IOException e5) {
                        e = e5;
                        pattern = compile;
                    }
                }
                if (sb != null) {
                    if (fcVar == null) {
                        try {
                        } catch (FileNotFoundException e6) {
                            e = e6;
                            bufferedReader2 = bufferedReader;
                            bo.a("HV", "search: " + file, (Throwable) e);
                        } catch (IOException e7) {
                            e = e7;
                            bufferedReader2 = bufferedReader;
                            bo.a("HV", "search: " + file, (Exception) e);
                        }
                        try {
                            fcVar2 = new fc(aVar, str3, false, str2);
                        } catch (FileNotFoundException e8) {
                            e = e8;
                            bufferedReader2 = bufferedReader;
                            bo.a("HV", "search: " + file, (Throwable) e);
                        } catch (IOException e9) {
                            e = e9;
                            bufferedReader2 = bufferedReader;
                            bo.a("HV", "search: " + file, (Exception) e);
                        }
                    } else {
                        fcVar2 = fcVar;
                    }
                    try {
                        fc fcVar3 = new fc(fc.a.FileExcerpt, a2 + ' ' + String.valueOf(i2), false, str2);
                        fcVar3.f13240f = sb.toString();
                        fcVar2.b(fcVar3);
                    } catch (FileNotFoundException e10) {
                        e = e10;
                        fcVar = fcVar2;
                        bufferedReader2 = bufferedReader;
                        bo.a("HV", "search: " + file, (Throwable) e);
                    } catch (IOException e11) {
                        e = e11;
                        fcVar = fcVar2;
                        bufferedReader2 = bufferedReader;
                        bo.a("HV", "search: " + file, (Exception) e);
                    }
                } else {
                    fcVar2 = fcVar;
                }
                gs.a((Reader) bufferedReader);
                fcVar = fcVar2;
            } catch (FileNotFoundException e12) {
                e = e12;
                pattern = compile;
                bufferedReader2 = null;
                fcVar = null;
            } catch (IOException e13) {
                e = e13;
                pattern = compile;
                bufferedReader2 = null;
                fcVar = null;
            } catch (Throwable th3) {
                th = th3;
                bufferedReader = null;
            }
            if (fcVar != null) {
                list.add(fcVar);
            }
            i++;
            compile = pattern;
            str4 = str;
        }
    }

    @Override
    @TargetApi(g.a.MapAttrs_latLngBoundsNorthEastLongitude)
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setResult(0, null);
        Intent intent = getIntent();
        this.f11132b = c.values()[intent.getIntExtra("sty", c.Inform.ordinal())];
        try {
            this.f11134d = new WebView(this);
            this.f11134d.getSettings().setAllowFileAccess(true);
            this.f11134d.getSettings().setBuiltInZoomControls(true);
            this.f11134d.setWebViewClient(com.joaomgcd.taskerm.util.g.a() ? new a(this) : new b(this));
        } catch (Throwable th) {
            bo.b("HV", "onCreate", th);
            gs.a(this, "Android internal error, try updating Android WebView", new Object[0]);
            this.f11134d = null;
        }
        if (this.f11134d == null) {
            finish();
        } else {
            LinearLayout linearLayout = new LinearLayout(this);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
            linearLayout.setPadding(go.e(this, R.dimen.content_side_margin_left), 0, 0, 0);
            linearLayout.setLayoutParams(layoutParams);
            linearLayout.addView(this.f11134d);
            this.f11134d.setScrollBarStyle(16777216);
            setContentView(linearLayout);
            if (this.f11132b == c.InformWithAccept) {
                ActionBar actionBar = getActionBar();
                actionBar.setHomeButtonEnabled(false);
                if (go.a()) {
                    actionBar.setDisplayOptions(8);
                } else {
                    actionBar.setDisplayOptions(10);
                }
            } else {
                net.dinglisch.android.taskerm.a.a((Activity) this, false);
            }
            this.f11134d.setBackgroundColor(0);
            String stringExtra = intent.getStringExtra("url");
            if (bundle != null) {
                this.f11136f = bundle.getString("url");
            } else {
                this.f11136f = d(stringExtra);
            }
            b(this.f11136f);
        }
        this.f11135e.n();
    }

    public void b(String str) {
        if (str != null) {
            WebSettings settings = this.f11134d.getSettings();
            settings.setDefaultTextEncodingName("utf-8");
            if (!go.b(this)) {
                settings.setJavaScriptEnabled(true);
            }
            this.f11134d.loadUrl(str);
        }
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        menu.clear();
        if (this.f11132b != c.Inform) {
            net.dinglisch.android.taskerm.a.a(this, 3, (int) R.string.button_label_ok, menu);
        }
        if (this.f11132b == c.Confirm) {
            net.dinglisch.android.taskerm.a.b(this, 0, menu);
        } else {
            WebView webView = this.f11134d;
            if (webView == null) {
                return true;
            }
            if (webView.canGoBack()) {
                net.dinglisch.android.taskerm.a.d(this, 1, menu);
            }
            if (webView.canGoForward()) {
                net.dinglisch.android.taskerm.a.u(this, 2, menu);
            }
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId != 16908332) {
            switch (itemId) {
                case 0:
                    finish();
                    return true;
                case 1:
                    this.f11134d.goBack();
                    return true;
                case 2:
                    this.f11134d.goForward();
                    return true;
                case 3:
                    break;
                default:
                    return true;
            }
        }
        setResult(-1);
        finish();
        return true;
    }

    @Override
    public void onPause() {
        super.onPause();
        a();
    }

    public void c(String str) {
        gs.a((Context) this, new Intent("android.intent.action.VIEW", Uri.parse(str)));
    }

    @Override
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putString("url", this.f11136f);
    }

    public String a(String str, String str2) {
        return "https://tasker.joaoapps.com/userguide/" + str + "/" + str2;
    }

    private String d(String str) {
        SharedPreferences sharedPreferences = getSharedPreferences(bh.g, 0);
        String a2 = bj.a(sharedPreferences);
        this.f11136f = c(a2, str);
        if (this.f11136f == null) {
            File a3 = a(a2);
            if (a3 == null) {
                this.f11136f = a(a2, str);
            } else {
                gs.e(a3);
                File file = new File(a3, str);
                File file2 = new File(a3, a(getResources(), a2));
                bo.b("HV", "docfile: " + file.toString());
                bo.b("HV", "versionfile: " + file2.toString());
                if (sharedPreferences.getBoolean("avo", false)) {
                    this.f11136f = a(a2, str);
                } else if ((file2.exists() || gs.m()) && file.exists()) {
                    this.f11136f = "file:///" + file.toString();
                } else {
                    this.g = str;
                    e();
                }
            }
        }
        return this.f11136f;
    }

    private void b(String str, String str2) {
        this.f11136f = a(str, str2);
        b(this.f11136f);
    }

    private String c(String str, String str2) {
        String str3;
        AssetManager assets = getResources().getAssets();
        try {
            if (gs.b(str2, assets.list(str)) != -1) {
                str3 = "file:///android_asset/" + str + "/" + str2;
            } else if (gs.b(str2, assets.list("")) == -1) {
                return null;
            } else {
                str3 = "file:///android_asset/" + str2;
            }
            return str3;
        } catch (IOException e2) {
            bo.b("HV", "checkShowDoc", e2);
            return null;
        }
    }

    public void a() {
        if (this.f11133c != null) {
            unregisterReceiver(this.f11133c);
            this.f11133c = null;
        }
        if (this.h != null) {
            this.h.dismiss();
            this.h = null;
        }
    }

    private void e() {
        dp.a(this, new Handler() {
            @Override
            public void handleMessage(Message message) {
                if (message.what == 1) {
                    HTMLView.this.a(message.getData().getInt("index"));
                    return;
                }
                HTMLView.this.finish();
            }
        }, (int) R.string.dt_docsource_select).a(ct.a(this, (int) R.array.docsource_entries)).a(this);
    }

    public void a(int i) {
        SharedPreferences sharedPreferences = getSharedPreferences(bh.g, 0);
        final String a2 = bj.a(sharedPreferences);
        if (i == 2) {
            final File a3 = a(a2);
            a();
            this.f11133c = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    com.joaomgcd.taskerm.util.aa.b(intent);
                    HTMLView.this.a();
                    if (intent.getBooleanExtra("success", false)) {
                        File file = new File(a3, HTMLView.this.g);
                        HTMLView hTMLView = HTMLView.this;
                        hTMLView.f11136f = "file:///" + file.toString();
                    } else {
                        HTMLView.this.f11136f = HTMLView.this.a(a2, HTMLView.this.g);
                    }
                    HTMLView.this.b(HTMLView.this.f11136f);
                }
            };
            registerReceiver(this.f11133c, TaskerIntent.a(ct.a(this, (int) R.string.dt_download_language, new Object[0])));
            if (a((Activity) this, a2)) {
                if (this.h == null) {
                    this.h = a((Activity) this);
                    this.h.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialogInterface) {
                            HTMLView.this.finish();
                        }
                    });
                    return;
                }
                return;
            }
            b(a2, this.g);
            return;
        }
        if (i == 1) {
            sharedPreferences.edit().putBoolean("avo", true).commit();
        }
        b(a2, this.g);
    }

    @Override
    public void onDetachedFromWindow() {
        if (this.f11134d != null) {
            MyActivity.unbindAllReferences(this.f11134d);
            this.f11134d = null;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.h = null;
        this.f11133c = null;
        System.gc();
        this.f11135e.b();
    }

    public class b extends a {
        public b(HTMLView hTMLView) {
            super(hTMLView);
        }

        @Override
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            super.onReceivedHttpError(webView, webResourceRequest, webResourceResponse);
            HTMLView.this.f11135e.a(HTMLView.this.f11134d, webResourceRequest, (WebResourceRequest) webResourceResponse, (c.f.a.b<? super WebResourceRequest, Boolean>) new c.f.a.b() {
                @Override
                public final Object invoke(Object obj) {
                    Boolean b2;
                    b2 = HTMLView.b.b((WebResourceResponse) obj);
                    return b2;
                }
            }, (c.f.a.b<? super WebResourceRequest, Boolean>) new c.f.a.b() {
                @Override
                public final Object invoke(Object obj) {
                    Boolean a2;
                    a2 = HTMLView.b.a((WebResourceResponse) obj);
                    return a2;
                }
            });
        }

        public static Boolean a(WebResourceResponse webResourceResponse) {
            return Boolean.valueOf(webResourceResponse.getStatusCode() == 404);
        }

        public static Boolean b(WebResourceResponse webResourceResponse) {
            return Boolean.valueOf(webResourceResponse.getStatusCode() == 404);
        }

        @Override
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            super.onReceivedError(webView, webResourceRequest, webResourceError);
            HTMLView.this.f11135e.a(HTMLView.this.f11134d, webResourceRequest, (WebResourceRequest) webResourceError, (c.f.a.b<? super WebResourceRequest, Boolean>) new c.f.a.b() {
                @Override
                public final Object invoke(Object obj) {
                    Boolean b2;
                    b2 = HTMLView.b.this.b((WebResourceError) obj);
                    return b2;
                }
            }, (c.f.a.b<? super WebResourceRequest, Boolean>) new c.f.a.b() {
                @Override
                public final Object invoke(Object obj) {
                    Boolean a2;
                    a2 = HTMLView.b.this.a((WebResourceError) obj);
                    return a2;
                }
            });
        }

        public Boolean a(WebResourceError webResourceError) {
            return Boolean.valueOf(!HTMLView.this.f11135e.b(webResourceError));
        }

        public Boolean b(WebResourceError webResourceError) {
            return Boolean.valueOf(HTMLView.this.f11135e.a(webResourceError));
        }
    }

    private class a extends WebViewClient {
        HTMLView f11142a;

        public a(HTMLView hTMLView) {
            this.f11142a = hTMLView;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            if (str.startsWith("file://") || str.startsWith("https://tasker.joaoapps.com/userguide")) {
                return false;
            }
            this.f11142a.c(str);
            return true;
        }

        @Override
        public void onPageFinished(WebView webView, String str) {
            if (!go.b(HTMLView.this)) {
                String substring = cd.a(go.g(HTMLView.this), false).substring(2);
                String a2 = cd.a(gp.l(HTMLView.this), false);
                if (a2.length() > 6) {
                    a2 = a2.substring(a2.length() - 6);
                }
                webView.evaluateJavascript("document.body.style.setProperty(\"color\", \"#" + substring + "\");\nvar links = document.getElementsByTagName(\"a\");\nfor(var i=0;i<links.length;i++)\n{\n        if(links[i].href)\n        {\n            links[i].style.color = \"#" + a2 + "\";  \n        }\n}  ", null);
            }
            HTMLView.this.invalidateOptionsMenu();
        }
    }
}