翰林优商.apk(点击下载) / H5Activity.java


package com.tb.mob.saas;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.tb.mob.R;
import com.tencent.smtt.export.external.interfaces.JsPromptResult;
import com.tencent.smtt.export.external.interfaces.JsResult;
import com.tencent.smtt.export.external.interfaces.SslError;
import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
import com.tencent.smtt.export.external.interfaces.WebResourceError;
import com.tencent.smtt.export.external.interfaces.WebResourceRequest;
import com.tencent.smtt.sdk.ValueCallback;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import java.lang.ref.WeakReference;

public class H5Activity extends Activity {
    private WebView a;
    private boolean b = true;
    private String c = "";
    private String d = "";
    private ImageView e;
    private TextView f;
    private ValueCallback<Uri> g;
    private ValueCallback<Uri[]> h;

    /* access modifiers changed from: private */
    public static class MyWebViewClient extends WebViewClient {
        private final WeakReference<H5Activity> a;

        MyWebViewClient(H5Activity h5Activity) {
            this.a = new WeakReference<>(h5Activity);
        }

        @Override // com.tencent.smtt.sdk.WebViewClient
        public void onPageFinished(WebView webView, String str) {
            super.onPageFinished(webView, str);
            this.a.get();
        }

        @Override // com.tencent.smtt.sdk.WebViewClient
        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            super.onPageStarted(webView, str, bitmap);
            this.a.get();
        }

        @Override // com.tencent.smtt.sdk.WebViewClient
        public void onReceivedError(WebView webView, int i, String str, String str2) {
            super.onReceivedError(webView, i, str, str2);
            if (Build.VERSION.SDK_INT < 23) {
                this.a.get();
            }
        }

        @Override // com.tencent.smtt.sdk.WebViewClient
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            super.onReceivedError(webView, webResourceRequest, webResourceError);
            if (webResourceRequest.isForMainFrame()) {
                this.a.get();
            }
        }

        @Override // com.tencent.smtt.sdk.WebViewClient
        public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            sslErrorHandler.proceed();
        }

        @Override // com.tencent.smtt.sdk.WebViewClient
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            this.a.get().b = true;
            if (!str.startsWith("http:") && !str.startsWith("https:")) {
                return true;
            }
            webView.loadUrl(str);
            return false;
        }
    }

    private void a() {
        WebView webView = (WebView) findViewById(R.id.a_webView);
        this.a = webView;
        WebSettings settings = webView.getSettings();
        String userAgentString = settings.getUserAgentString();
        settings.setUserAgentString(userAgentString + "; qbmobSDK");
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        settings.setDisplayZoomControls(false);
        settings.setAllowFileAccess(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLoadsImagesAutomatically(true);
        settings.setCacheMode(-1);
        settings.setDomStorageEnabled(true);
        settings.setDatabaseEnabled(false);
        settings.setAppCacheEnabled(true);
        settings.setSaveFormData(false);
        if (Build.VERSION.SDK_INT >= 21) {
            settings.setMixedContentMode(0);
        }
        this.a.setWebViewClient(new MyWebViewClient(this));
        this.a.setWebChromeClient(new WebChromeClient() {
            /* class com.tb.mob.saas.H5Activity.AnonymousClass2 */

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public void onCloseWindow(WebView webView) {
                super.onCloseWindow(webView);
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public boolean onCreateWindow(WebView webView, boolean z, boolean z2, Message message) {
                return super.onCreateWindow(webView, z, z2, message);
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public boolean onJsAlert(WebView webView, String str, String str2, JsResult jsResult) {
                AlertDialog.Builder builder = new AlertDialog.Builder(webView.getContext());
                builder.setTitle(SaasConfigInfo.window_alert_title).setMessage(str2).setPositiveButton("确定", (DialogInterface.OnClickListener) null);
                builder.setOnKeyListener(new DialogInterface.OnKeyListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass1 */

                    public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                        Log.v("onJsAlert", "keyCode==" + i + "event=" + keyEvent);
                        return true;
                    }
                });
                builder.setCancelable(false);
                builder.create().show();
                jsResult.confirm();
                return true;
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public boolean onJsBeforeUnload(WebView webView, String str, String str2, JsResult jsResult) {
                return super.onJsBeforeUnload(webView, str, str2, jsResult);
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public boolean onJsConfirm(WebView webView, String str, String str2, final JsResult jsResult) {
                AlertDialog.Builder builder = new AlertDialog.Builder(webView.getContext());
                builder.setTitle(SaasConfigInfo.window_confirm_title).setMessage(str2).setPositiveButton("确定", new DialogInterface.OnClickListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass3 */

                    public void onClick(DialogInterface dialogInterface, int i) {
                        jsResult.confirm();
                    }
                }).setNeutralButton("取消", new DialogInterface.OnClickListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass2 */

                    public void onClick(DialogInterface dialogInterface, int i) {
                        jsResult.cancel();
                    }
                });
                builder.setOnCancelListener(new DialogInterface.OnCancelListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass4 */

                    public void onCancel(DialogInterface dialogInterface) {
                        jsResult.cancel();
                    }
                });
                builder.setOnKeyListener(new DialogInterface.OnKeyListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass5 */

                    public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                        Log.v("onJsConfirm", "keyCode==" + i + "event=" + keyEvent);
                        return true;
                    }
                });
                builder.create().show();
                return true;
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public boolean onJsPrompt(WebView webView, String str, String str2, String str3, final JsPromptResult jsPromptResult) {
                AlertDialog.Builder builder = new AlertDialog.Builder(webView.getContext());
                builder.setTitle(SaasConfigInfo.window_prompt_title).setMessage(str2);
                final EditText editText = new EditText(webView.getContext());
                editText.setSingleLine();
                editText.setText(str3);
                builder.setView(editText).setPositiveButton("确定", new DialogInterface.OnClickListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass7 */

                    public void onClick(DialogInterface dialogInterface, int i) {
                        jsPromptResult.confirm(editText.getText().toString());
                    }
                }).setNeutralButton("取消", new DialogInterface.OnClickListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass6 */

                    public void onClick(DialogInterface dialogInterface, int i) {
                        jsPromptResult.cancel();
                    }
                });
                builder.setOnKeyListener(new DialogInterface.OnKeyListener(this) {
                    /* class com.tb.mob.saas.H5Activity.AnonymousClass2.AnonymousClass8 */

                    public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                        Log.v("onJsPrompt", "keyCode==" + i + "event=" + keyEvent);
                        return true;
                    }
                });
                builder.create().show();
                return true;
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public void onProgressChanged(WebView webView, int i) {
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public void onReceivedIcon(WebView webView, Bitmap bitmap) {
                super.onReceivedIcon(webView, bitmap);
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public void onReceivedTitle(WebView webView, String str) {
                super.onReceivedTitle(webView, str);
                H5Activity.this.f.setText(str);
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public void onRequestFocus(WebView webView) {
                super.onRequestFocus(webView);
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
                H5Activity.this.h = valueCallback;
                H5Activity.this.b();
                return true;
            }

            public void openFileChooser(ValueCallback<Uri> valueCallback) {
                H5Activity.this.g = valueCallback;
                H5Activity.this.b();
            }

            public void openFileChooser(ValueCallback<Uri> valueCallback, String str) {
                H5Activity.this.g = valueCallback;
                H5Activity.this.b();
            }

            @Override // com.tencent.smtt.sdk.WebChromeClient
            public void openFileChooser(ValueCallback<Uri> valueCallback, String str, String str2) {
                H5Activity.this.g = valueCallback;
                H5Activity.this.b();
            }
        });
        this.a.loadUrl(this.d);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void b() {
        Intent intent = new Intent("android.intent.action.GET_CONTENT");
        intent.addCategory("android.intent.category.OPENABLE");
        intent.setType("*/*");
        startActivityForResult(Intent.createChooser(intent, "上传文件"), 0);
    }

    /* access modifiers changed from: protected */
    public void onActivityResult(int i, int i2, Intent intent) {
        ValueCallback<Uri> valueCallback;
        super.onActivityResult(i, i2, intent);
        if (i != 0) {
            return;
        }
        if (i2 == -1) {
            if (this.g != null) {
                this.g.onReceiveValue(intent == null ? null : intent.getData());
                this.g = null;
            }
            if (this.h != null) {
                this.h.onReceiveValue(new Uri[]{intent == null ? null : intent.getData()});
                this.h = null;
            }
        } else if (i2 == 0 && (valueCallback = this.g) != null) {
            valueCallback.onReceiveValue(null);
            this.g = null;
        }
    }

    public void onBackPressed() {
        if (!this.a.canGoBack() || !this.b) {
            super.onBackPressed();
        } else {
            this.a.goBack();
        }
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        this.c = getIntent().getStringExtra("callBack");
        this.d = getIntent().getStringExtra("url");
        setContentView(R.layout.saas_activity_h5);
        a();
        ImageView imageView = (ImageView) findViewById(R.id.a_h5_title_iv);
        this.e = imageView;
        imageView.setOnClickListener(new View.OnClickListener() {
            /* class com.tb.mob.saas.H5Activity.AnonymousClass1 */

            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("callBack", H5Activity.this.c);
                H5Activity.this.setResult(200, intent);
                H5Activity.this.finish();
            }
        });
        this.f = (TextView) findViewById(R.id.a_h5_title_tv);
    }

    /* access modifiers changed from: protected */
    public void onPause() {
        super.onPause();
        this.a.onPause();
    }

    /* access modifiers changed from: protected */
    public void onResume() {
        super.onResume();
        this.a.onResume();
    }
}