调研通 v3.0.3版本的 MD5 值为:fe075d21227d488bdb9f6aa09d3b3f35

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


package com.yyt.common.custom;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.annotation.RequiresApi;
import c.o.a.a.b;
import com.baidu.tts.client.SpeechSynthesizer;
import com.stx.xhb.commontitlebar.CustomTitleBar;
import com.yyt.common.BaseActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.cordova.ConfigXmlParser;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaPreferences;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CordovaWebViewImpl;
import org.apache.cordova.ICordovaCookieManager;
import org.apache.cordova.PluginEntry;
import org.json.JSONException;
import org.json.JSONObject;

public class YCWebViewActivity extends BaseActivity implements CordovaInterface {
    public static String s = "YCWebViewActivity";
    private static final String t = "0";
    private static final String u = "1";
    private static final String v = "2";
    protected CordovaWebView g;
    protected CordovaPreferences h;
    protected ArrayList<PluginEntry> i;
    private Activity j;
    private String k;
    private boolean l;
    private boolean m;
    BroadcastReceiver n;
    BroadcastReceiver o;
    com.stx.xhb.commontitlebar.d.a p;
    private CustomTitleBar q;

    protected CordovaPlugin f10902f = null;
    private String r = "0";

    public class a extends BroadcastReceiver {
        a() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            String stringExtra = intent.getStringExtra("barcode_string");
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("success", true);
                jSONObject.put("scanType", "barcode");
                jSONObject.put("data", stringExtra);
            } catch (JSONException unused) {
            }
            YCWebViewActivity.this.g.sendJavascript("cordova.fireDocumentEvent('onScanComplete'," + jSONObject + ")");
        }
    }

    public class b extends BroadcastReceiver {
        b() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {
            YCWebViewActivity.this.g.loadUrl("javascript:YC.Navigation.setLeftCloseBtn()");
        }
    }

    private void O() {
        com.stx.xhb.commontitlebar.d.a b2 = this.q.b(b.h.icon_back, b.i.topbar_left_button);
        int parseColor = Color.parseColor(com.yyt.common.o.n.e(this));
        if (b2.getTag() != null) {
            getResources().getDrawable(((Integer) b2.getTag()).intValue()).setColorFilter(parseColor, PorterDuff.Mode.SRC_ATOP);
        }
        if (this.l) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public final void run() {
                    YCWebViewActivity.this.T();
                }
            }, 0L);
        }
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                YCWebViewActivity.this.V(view);
            }
        });
    }

    private void P() {
        com.stx.xhb.commontitlebar.d.a b2 = this.q.b(b.h.icon_close, b.i.topbar_left_button2);
        int parseColor = Color.parseColor(com.yyt.common.o.n.e(this));
        if (b2.getTag() != null) {
            getResources().getDrawable(((Integer) b2.getTag()).intValue()).setColorFilter(parseColor, PorterDuff.Mode.SRC_ATOP);
        }
        if (this.l) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public final void run() {
                    YCWebViewActivity.this.X();
                }
            }, 0L);
        }
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                YCWebViewActivity.this.Z(view);
            }
        });
    }

    public void T() {
        this.q.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
    }

    public void V(View view) {
        if (this.g.getEngine().canGoBack()) {
            this.g.getEngine().goBack();
        } else {
            finish();
        }
    }

    public void X() {
        this.q.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
    }

    public void Z(View view) {
        finish();
    }

    public void b0() {
        this.q.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
    }

    public void d0(View view) {
        this.g.loadUrl("javascript:YC.Navigation.popToRoot()");
    }

    public void g0(View view) {
        Boolean valueOf = Boolean.valueOf(getIntent().getBooleanExtra("directClose", false));
        if (this.g.getEngine().canGoBack() && !valueOf.booleanValue()) {
            this.g.getEngine().goBack();
        } else {
            F().d(1);
        }
    }

    public void i0(String str, String str2) {
        this.g.showWebPage(str + "?error=" + str2, false, true, null);
    }

    public void k0(DialogInterface dialogInterface, int i) {
        com.yyt.common.o.n.p(getActivity());
    }

    public void m0(int i, String str, DialogInterface dialogInterface) {
        onRequestPermissionsResult(i, new String[]{str}, new int[]{-1});
    }

    public void o0(List list) {
        for (int i = 0; i < list.size(); i++) {
            ((WindowManager) getActivity().getSystemService("window")).addView(G().get(list.get(i)), G().get(list.get(i)).getLayoutParams());
        }
    }

    private void p0() {
        ConfigXmlParser configXmlParser = new ConfigXmlParser();
        configXmlParser.parse(this);
        CordovaPreferences preferences = configXmlParser.getPreferences();
        this.h = preferences;
        preferences.setPreferencesBundle(getIntent().getExtras());
        this.i = configXmlParser.getPluginEntries();
    }

    private void q0() {
        if (this.g == null) {
            this.g = new CordovaWebViewImpl(CordovaWebViewImpl.createEngine(this, this.h));
            R();
            if (!this.g.isInitialized()) {
                this.i.remove(1);
                this.g.init(this, this.i, this.h);
            }
        }
        this.g.getCookieManager().setCookiesEnabled(true);
        if (this.g.getEngine().getView() != null) {
            ((WebView) this.g.getEngine().getView()).getSettings().setTextZoom((int) (getResources().getConfiguration().fontScale * 100.0f));
        }
        String stringExtra = getIntent().getStringExtra("url");
        if (stringExtra != null) {
            if (stringExtra.startsWith("http://") || stringExtra.startsWith("https://")) {
                this.m = true;
                String i = com.yyt.common.o.s.i(this, "yytmpToken");
                String i2 = com.yyt.common.o.s.i(getActivity(), "yth_sys_psnorg");
                if (i != null && !"".equals(i)) {
                    String host = Uri.parse(stringExtra).getHost();
                    ICordovaCookieManager cookieManager = this.g.getEngine().getCookieManager();
                    cookieManager.setCookiesEnabled(true);
                    cookieManager.setCookie(stringExtra, "yytmpToken=" + i + ";Domain=" + host + ";Path=/");
                    cookieManager.setCookie(stringExtra, "yth_sys_psnorg=" + i2 + ";Domain=" + host + ";Path=/");
                    cookieManager.flush();
                }
                String g = com.yyt.common.o.n.g(stringExtra, "leftBtnType");
                if (g != null) {
                    this.r = g;
                }
            }
            this.g.loadUrlIntoView(com.yyt.common.o.n.j(getApplicationContext(), stringExtra), true);
        }
    }

    private void r0() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.ACTION_CLOSE_YC_ACTIVITY");
        b bVar = new b();
        this.o = bVar;
        registerReceiver(bVar, intentFilter);
    }

    private void s0() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.ACTION_DECODE_DATA");
        a aVar = new a();
        this.n = aVar;
        registerReceiver(aVar, intentFilter);
    }

    private void t0() {
        this.j.sendBroadcast(new Intent("android.intent.ACTION_CLOSE_YC_ACTIVITY"));
    }

    @Override
    public void C(int i) {
        View view = this.g.getView();
        if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            layoutParams.topMargin += i;
            view.setLayoutParams(layoutParams);
        }
        if (view.getLayoutParams() instanceof FrameLayout.LayoutParams) {
            FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) view.getLayoutParams();
            layoutParams2.topMargin += i;
            view.setLayoutParams(layoutParams2);
        }
        if (com.yyt.common.o.s.h(this, com.yyt.common.d.H) == 0) {
            int c2 = com.yyt.common.o.j.c(this, i + com.stx.xhb.commontitlebar.c.d.c(this, b.d.titlebar_height));
            com.yyt.common.o.s.l(this, com.yyt.common.d.H, c2);
            WebSettings settings = ((WebView) this.g.getView()).getSettings();
            settings.setUserAgentString(settings.getUserAgentString() + " notchHeight/" + c2);
        }
    }

    @Override
    public void D() {
        this.j = this;
        if ("LANDSCAPE".equals(getIntent().getStringExtra("orientation"))) {
            setRequestedOrientation(0);
        }
        this.k = getIntent().getStringExtra("hideNav");
        this.l = getIntent().getBooleanExtra("isTranslucent", false);
        q0();
    }

    @Override
    public void H(final CustomTitleBar customTitleBar) {
        this.q = customTitleBar;
        customTitleBar.H(getIntent().getStringExtra("title"));
        customTitleBar.setmTitleTextColor(Color.parseColor(com.yyt.common.o.n.e(this)));
        com.stx.xhb.commontitlebar.d.a b2 = customTitleBar.b(b.h.icon_back, b.i.topbar_left_button);
        int parseColor = Color.parseColor(com.yyt.common.o.n.e(this));
        if (b2.getTag() != null) {
            getResources().getDrawable(((Integer) b2.getTag()).intValue()).setColorFilter(parseColor, PorterDuff.Mode.SRC_ATOP);
        }
        if (this.l) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public final void run() {
                    CustomTitleBar.this.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
                }
            }, 0L);
        }
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                YCWebViewActivity.this.g0(view);
            }
        });
    }

    public void Q() {
        if (this.p == null) {
            this.p = this.q.b(b.h.icon_close, b.i.topbar_left_button2);
            int parseColor = Color.parseColor(com.yyt.common.o.n.e(this));
            if (this.p.getTag() != null) {
                getResources().getDrawable(((Integer) this.p.getTag()).intValue()).setColorFilter(parseColor, PorterDuff.Mode.SRC_ATOP);
            }
            if (this.l) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public final void run() {
                        YCWebViewActivity.this.b0();
                    }
                }, 0L);
            }
            this.p.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    YCWebViewActivity.this.d0(view);
                }
            });
        }
    }

    public void R() {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
        String str = this.k;
        layoutParams.topMargin = ((str == null || !str.equals("true")) && !this.l) ? com.stx.xhb.commontitlebar.c.d.c(this, b.d.titlebar_height) : 0;
        setContentView(this.g.getView());
        this.g.getView().requestFocusFromTouch();
        this.g.getView().setLayoutParams(layoutParams);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent keyEvent) {
        if (keyEvent.getAction() == 2 && keyEvent.getKeyCode() == 0) {
            String characters = keyEvent.getCharacters();
            if (characters != null && characters != "") {
                this.g.loadUrl("javascript:component.afterScanQrcode('" + characters + "')");
            }
        } else if (keyEvent.getAction() == 0) {
            Intent intent = new Intent("com.scanphone.android.KEY_DOWN");
            intent.putExtra("keyCode", keyEvent.getKeyCode());
            sendBroadcast(intent);
        } else if (keyEvent.getAction() == 1) {
            Intent intent2 = new Intent("com.scanphone.android.KEY_UP");
            intent2.putExtra("keyCode", keyEvent.getKeyCode());
            sendBroadcast(intent2);
        }
        keyEvent.getCharacters();
        return super.dispatchKeyEvent(keyEvent);
    }

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public ExecutorService getThreadPool() {
        return Executors.newCachedThreadPool();
    }

    @Override
    @SuppressLint({"NewApi"})
    public boolean hasPermission(String str) {
        return Build.VERSION.SDK_INT < 23 || checkSelfPermission(str) == 0;
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        CordovaPlugin cordovaPlugin = this.f10902f;
        if (cordovaPlugin != null) {
            cordovaPlugin.onActivityResult(i, i2, intent);
        }
    }

    @Override
    @SuppressLint({"NewApi"})
    public void onCreate(Bundle bundle) {
        p0();
        int h = com.yyt.common.o.s.h(this, com.yyt.common.d.H);
        if (h != 0) {
            String string = this.h.getString("AppendUserAgent", "");
            this.h.set("AppendUserAgent", string + " notchHeight/" + h);
        }
        super.onCreate(bundle);
        String str = this.k;
        if (str != null && str.equals("true")) {
            E().setVisibility(8);
        } else {
            E().setVisibility(0);
        }
        if (getIntent().getBooleanExtra("showDireCloseBtn", false)) {
            Q();
        }
        s0();
        r0();
    }

    @Override
    public void onDestroy() {
        BroadcastReceiver broadcastReceiver = this.o;
        if (broadcastReceiver != null) {
            unregisterReceiver(broadcastReceiver);
        }
        t0();
        super.onDestroy();
        this.g.getEngine().destroy();
        this.g.getPluginManager().onDestroy();
        BroadcastReceiver broadcastReceiver2 = this.n;
        if (broadcastReceiver2 != null) {
            unregisterReceiver(broadcastReceiver2);
        }
        SpeechSynthesizer speechSynthesizer = SpeechSynthesizer.getInstance();
        speechSynthesizer.stop();
        speechSynthesizer.release();
    }

    @Override
    public Object onMessage(String str, Object obj) {
        if (str.equals("onPageStarted") && this.m && ("1".equals(this.r) || "2".equals(this.r))) {
            this.q.C();
            if ("1".equals(this.r)) {
                P();
            } else if ("2".equals(this.r)) {
                O();
                P();
            }
        }
        if (str.equals("onReceivedError")) {
            JSONObject jSONObject = (JSONObject) obj;
            try {
                String string = jSONObject.getString("url");
                final String string2 = jSONObject.getString("description");
                final String string3 = this.h.getString("errorUrl", null);
                if (string3 != null && !string.equals(string3) && this.g != null) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public final void run() {
                            YCWebViewActivity.this.i0(string3, string2);
                        }
                    });
                }
            } catch (JSONException unused) {
            }
        }
        return null;
    }

    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
    }

    @Override
    public void onPause() {
        super.onPause();
        CordovaWebView cordovaWebView = this.g;
        if (cordovaWebView != null) {
            cordovaWebView.handlePause(this.f10902f != null);
        }
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (G().size() > 0) {
            for (Map.Entry<String, View> entry : G().entrySet()) {
                String key = entry.getKey();
                if (key.equals("android.permission.READ_EXTERNAL_STORAGE")) {
                    key = "android.permission.WRITE_EXTERNAL_STORAGE";
                }
                com.yyt.common.o.s.m(this, key + "_isRequested", "true");
                try {
                    ((WindowManager) getSystemService("window")).removeView(entry.getValue());
                } catch (Exception e2) {
                    Log.e(s, e2.getMessage(), e2);
                }
            }
            G().clear();
        }
        try {
            CordovaPlugin cordovaPlugin = this.f10902f;
            if (cordovaPlugin != null) {
                cordovaPlugin.onRequestPermissionResult(i, strArr, iArr);
            }
        } catch (Exception unused) {
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (this.g == null) {
            return;
        }
        getWindow().getDecorView().requestFocus();
        this.g.handleResume(true);
    }

    @Override
    @RequiresApi(api = 23)
    public void requestPermission(CordovaPlugin cordovaPlugin, int i, String str) {
        requestPermissions(cordovaPlugin, i, new String[]{str});
    }

    @Override
    @RequiresApi(api = 23)
    public void requestPermissions(CordovaPlugin cordovaPlugin, final int i, String[] strArr) {
        this.f10902f = cordovaPlugin;
        final ArrayList arrayList = new ArrayList();
        for (int i2 = 0; i2 < strArr.length; i2++) {
            final String str = strArr[i2];
            if (str.equals("android.permission.READ_EXTERNAL_STORAGE")) {
                str = "android.permission.WRITE_EXTERNAL_STORAGE";
            }
            if (str.equals("android.permission.ACCESS_COARSE_LOCATION")) {
                str = "android.permission.ACCESS_FINE_LOCATION";
            }
            if (!G().containsKey(str)) {
                G().put(str, com.yyt.common.o.n.i(this, str));
                if ("true".equals(com.yyt.common.o.s.i(getActivity(), str + "_isRequested"))) {
                    if (!hasPermission(str)) {
                        new AlertDialog.Builder(getActivity()).setTitle("提示").setMessage(com.yyt.common.o.n.h(str)).setPositiveButton("去开启", new DialogInterface.OnClickListener() {
                            @Override
                            public final void onClick(DialogInterface dialogInterface, int i3) {
                                YCWebViewActivity.this.k0(dialogInterface, i3);
                            }
                        }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                            @Override
                            public final void onDismiss(DialogInterface dialogInterface) {
                                YCWebViewActivity.this.m0(i, str, dialogInterface);
                            }
                        }).show();
                    }
                } else {
                    arrayList.add(str);
                }
            }
        }
        if (arrayList.size() > 0) {
            runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    YCWebViewActivity.this.o0(arrayList);
                }
            });
            requestPermissions((String[]) arrayList.toArray(new String[arrayList.size()]), i);
        }
    }

    @Override
    public void setActivityResultCallback(CordovaPlugin cordovaPlugin) {
        this.f10902f = cordovaPlugin;
    }

    @Override
    public void startActivityForResult(CordovaPlugin cordovaPlugin, Intent intent, int i) {
        this.f10902f = cordovaPlugin;
        super.startActivityForResult(intent, i);
    }
}