大漢易經書院.apk(点击下载) / RichWebActivity.java


package com.baidu.techain;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.baidu.techain.i.c;
import java.util.List;
import java.util.Stack;

public class RichWebActivity extends Activity implements View.OnClickListener {
    public RelativeLayout a;
    private WebView b;
    private ImageView c;
    private TextView d;
    private int e = 0;
    private String f = null;
    private Stack<String> g = new Stack<>();

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        setContentView(R.layout.wb_notify);
        String stringExtra = getIntent().getStringExtra("url");
        this.f = stringExtra;
        if (TextUtils.isEmpty(stringExtra) || (!this.f.startsWith("http") && !this.f.startsWith("https"))) {
            finish();
            return;
        }
        this.e = getIntent().getIntExtra("back_type", 0);
        this.b = (WebView) findViewById(R.id.webview);
        this.c = (ImageView) findViewById(R.id.act_go_back);
        this.d = (TextView) findViewById(R.id.title_text);
        this.a = (RelativeLayout) findViewById(R.id.title_bar);
        this.c.setOnClickListener(this);
        this.a.setBackgroundColor(a()[0]);
        if (a(a()[0])) {
            this.c.setImageResource(R.drawable.backwh);
        } else {
            this.c.setImageResource(R.drawable.back);
        }
        WebSettings settings = this.b.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setSavePassword(false);
        settings.setAllowFileAccess(false);
        if (Build.VERSION.SDK_INT >= 16) {
            settings.setAllowFileAccessFromFileURLs(false);
            settings.setAllowUniversalAccessFromFileURLs(false);
        }
        if (Build.VERSION.SDK_INT >= 11) {
            this.b.removeJavascriptInterface("searchBoxJavaBridge_");
            this.b.removeJavascriptInterface("accessibility");
            this.b.removeJavascriptInterface("accessibilityTraversal");
        }
        this.b.loadUrl(this.f);
        this.b.setWebViewClient(new WebViewClient() {
            /* class com.baidu.techain.RichWebActivity.AnonymousClass1 */

            @Override // android.webkit.WebViewClient
            public final boolean shouldOverrideUrlLoading(WebView webView, String str) {
                if (TextUtils.isEmpty(str)) {
                    return true;
                }
                if (!str.startsWith("https") && !str.startsWith("http")) {
                    return true;
                }
                webView.loadUrl(str);
                if (RichWebActivity.this.g.contains(str)) {
                    return true;
                }
                RichWebActivity.this.g.push(str);
                return true;
            }

            public final void onPageFinished(WebView webView, String str) {
                super.onPageFinished(webView, str);
                String title = webView.getTitle();
                if (!TextUtils.isEmpty(title) && RichWebActivity.this.d != null) {
                    RichWebActivity.this.d.setTextColor(RichWebActivity.this.a()[1]);
                    RichWebActivity.this.d.setText(title);
                }
            }
        });
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (i != 4 || this.b == null || this.g.empty()) {
            return super.onKeyDown(i, keyEvent);
        }
        this.b.loadUrl(this.g.pop());
        return true;
    }

    public void onBackPressed() {
        b();
    }

    public void onClick(View view) {
        if (view.getId() == R.id.act_go_back) {
            b();
        }
    }

    private void b() {
        boolean z;
        try {
            boolean z2 = true;
            if (this.e == 1) {
                boolean z3 = false;
                try {
                    Intent intent = new Intent();
                    intent.setPackage(getPackageName());
                    intent.setAction("android.intent.action.MAIN");
                    intent.addCategory("android.intent.category.LAUNCHER");
                    intent.addFlags(268435456);
                    startActivity(intent);
                    z = true;
                } catch (Throwable unused) {
                    c.a();
                    z = false;
                }
                if (!z) {
                    try {
                        Intent intent2 = new Intent("android.intent.action.MAIN");
                        intent2.setPackage(getPackageName());
                        List<ResolveInfo> queryIntentActivities = getPackageManager().queryIntentActivities(intent2, 131072);
                        if (queryIntentActivities != null && !queryIntentActivities.isEmpty()) {
                            String str = queryIntentActivities.get(0).activityInfo.name;
                            if (!TextUtils.isEmpty(str)) {
                                Intent intent3 = new Intent("android.intent.action.MAIN");
                                intent3.addCategory("android.intent.category.LAUNCHER");
                                intent3.setComponent(new ComponentName(getPackageName(), str));
                                startActivity(intent3);
                                z3 = z2;
                            }
                        }
                        z2 = z;
                        z3 = z2;
                    } catch (Throwable unused2) {
                        c.a();
                    }
                } else {
                    z3 = z;
                }
                if (!z3) {
                    try {
                        startActivity(getPackageManager().getLaunchIntentForPackage(getPackageName()));
                    } catch (Throwable unused3) {
                        c.a();
                    }
                }
            }
            finish();
        } catch (Throwable unused4) {
            c.a();
        }
    }

    /* access modifiers changed from: protected */
    public void onDestroy() {
        Stack<String> stack = this.g;
        if (stack != null) {
            stack.clear();
        }
        super.onDestroy();
    }

    private static boolean a(int i) {
        int i2 = i | -16777216;
        try {
            int red = Color.red(-16777216) - Color.red(i2);
            int green = Color.green(-16777216) - Color.green(i2);
            int blue = Color.blue(-16777216) - Color.blue(i2);
            if (Math.sqrt((double) ((red * red) + (green * green) + (blue * blue))) < 180.0d) {
                return true;
            }
            return false;
        } catch (Throwable th) {
            th.printStackTrace();
            return false;
        }
    }

    public final int[] a() {
        TypedArray typedArray = null;
        try {
            typedArray = getTheme().obtainStyledAttributes(new int[]{16842801, 16842806});
            int[] iArr = {typedArray.getColor(0, 16777215), typedArray.getColor(1, 0)};
            if (typedArray != null) {
                typedArray.recycle();
            }
            return iArr;
        } catch (Throwable th) {
            if (typedArray != null) {
                typedArray.recycle();
            }
            throw th;
        }
    }
}