果博东方.apk(点击下载) / H5Container.java


package com.ccc.ossweb;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.ccc.ossweb.ReWebChomeClient;
import com.daimajia.numberprogressbar.NumberProgressBar;
import com.imuxuan.floatingview.FloatingMagnetView;
import com.imuxuan.floatingview.FloatingView;
import com.imuxuan.floatingview.MagnetViewListener;
import com.tencent.ijk.media.player.IjkMediaPlayer;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import notchtools.geek.com.notchtools.NotchTools;

public class H5Container extends FrameLayout implements ReWebChomeClient.OpenFileChooserCallBack {
    private static final int P_CODE_PERMISSIONS = 101;
    private static final int REQUEST_CODE_IMAGE_CAPTURE = 1;
    private static final int REQUEST_CODE_PICK_IMAGE = 0;
    private static H5Container instance;
    public H5Game curH5Game = null;
    public Visitor function = null;
    public Map<String, H5Game> h5GameMap = new HashMap();
    private Intent mSourceIntent;
    private ValueCallback<Uri> mUploadMsg;
    public ValueCallback<Uri[]> mUploadMsgForAndroid5;
    private boolean withCloseBt = false;

    public interface Visitor {
        void scanQR();
    }

    public H5Container(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        initView();
    }

    public H5Container(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        initView();
    }

    public H5Container(Context context) {
        super(context);
        initView();
    }

    private void initView() {
        inflate(getContext(), R.layout.h5_container, this);
        NotchTools.getFullScreenTools().fullScreenDontUseStatusForPortrait((Activity) getContext());
        instance = this;
    }

    public void testGame(String str) {
        this.curH5Game = new H5Game(getContext(), "HALL");
        this.curH5Game.show(this, false);
        this.curH5Game.hideH5Loading(false);
        this.curH5Game.startGame(str);
    }

    public void startGame(String str) {
        this.curH5Game = new H5Game(getContext(), "HALL");
        this.curH5Game.show(this, true);
        this.curH5Game.hideH5Loading(true);
        this.curH5Game.setLoginInfo(str);
        this.curH5Game.setVersionUrl("http://g-oss.oss-accelerate.aliyuncs.com/new/v");
        this.curH5Game.setUpdateUrl("http://g-oss.oss-accelerate.aliyuncs.com/new/g.zip");
        this.curH5Game.checkVer();
        this.curH5Game.rotateScreen("portrait");
        if (!this.withCloseBt) {
            this.curH5Game.checkAppVer(2, "http://g-oss.oss-accelerate.aliyuncs.com/new/gb_android");
        }
        hideVirtualButton();
        showCloseBt();
    }

    public void callJs(String str) {
        Log.e("callJS", "callJS" + str);
        this.curH5Game.mWebView.loadUrl(str);
    }

    public void clearCache() {
        for (Map.Entry<String, H5Game> entry : this.h5GameMap.entrySet()) {
            entry.getValue().mWebView.clearCache(true);
            entry.getValue().mWebView.clearHistory();
        }
    }

    public boolean goBack() {
        for (Map.Entry<String, H5Game> entry : this.h5GameMap.entrySet()) {
            if (!entry.getKey().equals("HALL")) {
                entry.getValue().closeGame("");
                return true;
            }
        }
        return false;
    }

    public void setWithCloseBt(boolean z) {
        this.withCloseBt = z;
    }

    public boolean showCloseBt() {
        if (!this.withCloseBt) {
            return false;
        }
        FloatingView.get().add();
        FloatingView.get().setPos();
        FloatingView.get().icon(R.drawable.home);
        FloatingView.get().listener(new MagnetViewListener() {
            /* class com.ccc.ossweb.H5Container.AnonymousClass1 */

            @Override // com.imuxuan.floatingview.MagnetViewListener
            public void onRemove(FloatingMagnetView floatingMagnetView) {
            }

            @Override // com.imuxuan.floatingview.MagnetViewListener
            public void onClick(FloatingMagnetView floatingMagnetView) {
                for (Map.Entry<String, H5Game> entry : H5Container.this.h5GameMap.entrySet()) {
                    entry.getValue().hide();
                }
                H5Container.instance.setVisibility(4);
                H5Container.this.h5GameMap.clear();
            }
        });
        return true;
    }

    public void hideCloseBt() {
        FloatingView.get().remove();
    }

    public void updateProgressText(String str, int i) {
        ((TextView) findViewById(R.id.progressText)).setText(str);
        ((NumberProgressBar) findViewById(R.id.NumberProgressBar)).setProgress(i);
    }

    public void onResume() {
        for (Map.Entry<String, H5Game> entry : this.h5GameMap.entrySet()) {
            entry.getValue().onResume();
        }
    }

    public void onPause() {
        for (Map.Entry<String, H5Game> entry : this.h5GameMap.entrySet()) {
            entry.getValue().onPause();
        }
    }

    public void onDestroy() {
        for (Map.Entry<String, H5Game> entry : this.h5GameMap.entrySet()) {
            entry.getValue().onDestroy();
        }
    }

    public void onStart() {
        FloatingView.get().attach(this);
    }

    public void onStop() {
        FloatingView.get().detach(this);
    }

    public boolean onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i != 101) {
            return false;
        }
        requestResult(strArr, iArr);
        restoreUploadMsg();
        return true;
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        if (i2 != -1) {
            ValueCallback<Uri> valueCallback = this.mUploadMsg;
            if (valueCallback != null) {
                valueCallback.onReceiveValue(null);
            }
            ValueCallback<Uri[]> valueCallback2 = this.mUploadMsgForAndroid5;
            if (valueCallback2 != null) {
                valueCallback2.onReceiveValue(null);
            }
        } else if (i == 0 || i == 1) {
            try {
                if (Build.VERSION.SDK_INT < 21) {
                    if (this.mUploadMsg != null) {
                        String retrievePath = ImageUtil.retrievePath(getContext(), this.mSourceIntent, intent);
                        if (TextUtils.isEmpty(retrievePath)) {
                            return;
                        }
                        if (new File(retrievePath).exists()) {
                            this.mUploadMsg.onReceiveValue(Uri.fromFile(new File(retrievePath)));
                        }
                    }
                } else if (Build.VERSION.SDK_INT >= 21 && this.mUploadMsgForAndroid5 != null) {
                    String retrievePath2 = ImageUtil.retrievePath(getContext(), this.mSourceIntent, intent);
                    if (TextUtils.isEmpty(retrievePath2)) {
                        return;
                    }
                    if (new File(retrievePath2).exists()) {
                        Uri fromFile = Uri.fromFile(new File(retrievePath2));
                        this.mUploadMsgForAndroid5.onReceiveValue(new Uri[]{fromFile});
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void showOptions() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setOnCancelListener(new DialogOnCancelListener());
        builder.setTitle("请选择操作");
        builder.setItems(new String[]{"相册", "拍照"}, new DialogInterface.OnClickListener() {
            /* class com.ccc.ossweb.H5Container.AnonymousClass2 */

            public void onClick(DialogInterface dialogInterface, int i) {
                if (i != 0) {
                    if (PermissionUtil.isOverMarshmallow()) {
                        if (!PermissionUtil.isPermissionValid((Activity) H5Container.this.getContext(), "android.permission.WRITE_EXTERNAL_STORAGE")) {
                            Toast.makeText(H5Container.this.getContext(), "请去\"设置\"中开启本应用的图片媒体访问权限", 0).show();
                            H5Container.this.restoreUploadMsg();
                            H5Container.this.requestPermissionsAndroidM();
                            return;
                        } else if (!PermissionUtil.isPermissionValid((Activity) H5Container.this.getContext(), "android.permission.CAMERA")) {
                            Toast.makeText(H5Container.this.getContext(), "请去\"设置\"中开启本应用的相机权限", 0).show();
                            H5Container.this.restoreUploadMsg();
                            H5Container.this.requestPermissionsAndroidM();
                            return;
                        }
                    }
                    try {
                        H5Container.this.mSourceIntent = ImageUtil.takeBigPicture();
                        ((Activity) H5Container.this.getContext()).startActivityForResult(H5Container.this.mSourceIntent, 1);
                    } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(H5Container.this.getContext(), "请去\"设置\"中开启本应用的相机和图片媒体访问权限", 0).show();
                        H5Container.this.restoreUploadMsg();
                    }
                } else if (!PermissionUtil.isOverMarshmallow() || PermissionUtil.isPermissionValid((Activity) H5Container.this.getContext(), "android.permission.READ_EXTERNAL_STORAGE")) {
                    try {
                        H5Container.this.mSourceIntent = ImageUtil.choosePicture();
                        ((Activity) H5Container.this.getContext()).startActivityForResult(H5Container.this.mSourceIntent, 0);
                    } catch (Exception e2) {
                        e2.printStackTrace();
                        Toast.makeText(H5Container.this.getContext(), "请去\"设置\"中开启本应用的图片媒体访问权限", 0).show();
                        H5Container.this.restoreUploadMsg();
                    }
                } else {
                    Toast.makeText(H5Container.this.getContext(), "请去\"设置\"中开启本应用的图片媒体访问权限", 0).show();
                    H5Container.this.restoreUploadMsg();
                    H5Container.this.requestPermissionsAndroidM();
                }
            }
        }).show();
    }

    private void fixDirPath() {
        File file = new File(ImageUtil.getDirPath());
        if (!file.exists()) {
            file.mkdirs();
        }
    }

    @Override // com.ccc.ossweb.ReWebChomeClient.OpenFileChooserCallBack
    public void openFileChooserCallBack(ValueCallback<Uri> valueCallback, String str) {
        this.mUploadMsg = valueCallback;
        showOptions();
    }

    @Override // com.ccc.ossweb.ReWebChomeClient.OpenFileChooserCallBack
    public boolean openFileChooserCallBackAndroid5(WebView webView, ValueCallback<Uri[]> valueCallback, WebChromeClient.FileChooserParams fileChooserParams) {
        this.mUploadMsgForAndroid5 = valueCallback;
        showOptions();
        return true;
    }

    /* access modifiers changed from: private */
    public class DialogOnCancelListener implements DialogInterface.OnCancelListener {
        private DialogOnCancelListener() {
        }

        public void onCancel(DialogInterface dialogInterface) {
            H5Container.this.restoreUploadMsg();
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void restoreUploadMsg() {
        ValueCallback<Uri> valueCallback = this.mUploadMsg;
        if (valueCallback != null) {
            valueCallback.onReceiveValue(null);
            this.mUploadMsg = null;
            return;
        }
        ValueCallback<Uri[]> valueCallback2 = this.mUploadMsgForAndroid5;
        if (valueCallback2 != null) {
            valueCallback2.onReceiveValue(null);
            this.mUploadMsgForAndroid5 = null;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void requestPermissionsAndroidM() {
        if (Build.VERSION.SDK_INT >= 23) {
            ArrayList arrayList = new ArrayList();
            arrayList.add("android.permission.WRITE_EXTERNAL_STORAGE");
            arrayList.add("android.permission.READ_EXTERNAL_STORAGE");
            arrayList.add("android.permission.CAMERA");
            PermissionUtil.requestPermissions((Activity) getContext(), 101, arrayList);
        }
    }

    public void requestResult(String[] strArr, int[] iArr) {
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < iArr.length; i++) {
            if (iArr[i] != 0 && PermissionUtil.isOverMarshmallow()) {
                arrayList.add(strArr[i]);
            }
        }
        if (arrayList.size() > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i2 = 0; i2 < arrayList.size(); i2++) {
                String str = (String) arrayList.get(i2);
                if ("android.permission.WRITE_EXTERNAL_STORAGE".equals(str)) {
                    sb.append("," + getContext().getString(R.string.permission_storage));
                } else if ("android.permission.READ_EXTERNAL_STORAGE".equals(str)) {
                    sb.append("," + getContext().getString(R.string.permission_storage));
                } else if ("android.permission.CAMERA".equals(str)) {
                    sb.append("," + getContext().getString(R.string.permission_camera));
                }
            }
            Toast.makeText(getContext(), "请允许使用\"" + sb.substring(1).toString() + "\"权限, 以正常使用APP的所有功能.", 0).show();
        }
    }

    public static <T> T getConstantValue(Class cls, String str) {
        try {
            return (T) cls.getDeclaredField(str).get(null);
        } catch (NoSuchFieldException unused) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, "can not find " + str + " in " + cls.getName());
            return null;
        } catch (IllegalAccessException unused2) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, str + " is not accessable");
            return null;
        } catch (IllegalArgumentException unused3) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, "arguments error when get " + str);
            return null;
        } catch (Exception unused4) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, "can not get constant" + str);
            return null;
        }
    }

    public static <T> T invokeInstanceMethod(Object obj, String str, Class[] clsArr, Object[] objArr) {
        Class<?> cls = obj.getClass();
        try {
            return (T) cls.getMethod(str, clsArr).invoke(obj, objArr);
        } catch (NoSuchMethodException unused) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, "can not find " + str + " in " + cls.getName());
            return null;
        } catch (IllegalAccessException unused2) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, str + " is not accessible");
            return null;
        } catch (IllegalArgumentException unused3) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, "arguments are error when invoking " + str);
            return null;
        } catch (InvocationTargetException unused4) {
            Log.e(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, "an exception was thrown by the invoked method when invoking " + str);
            return null;
        }
    }

    public void hideVirtualButton() {
        if (Build.VERSION.SDK_INT >= 19) {
            int intValue = ((Integer) getConstantValue(View.class, "SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION")).intValue();
            int intValue2 = ((Integer) getConstantValue(View.class, "SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN")).intValue();
            int intValue3 = ((Integer) getConstantValue(View.class, "SYSTEM_UI_FLAG_HIDE_NAVIGATION")).intValue();
            int intValue4 = ((Integer) getConstantValue(View.class, "SYSTEM_UI_FLAG_FULLSCREEN")).intValue();
            Object[] objArr = {Integer.valueOf(((Integer) getConstantValue(View.class, "SYSTEM_UI_FLAG_LAYOUT_STABLE")).intValue() | intValue | intValue2 | intValue3 | intValue4 | ((Integer) getConstantValue(View.class, "SYSTEM_UI_FLAG_IMMERSIVE_STICKY")).intValue())};
            invokeInstanceMethod(((Activity) getContext()).getWindow().getDecorView(), "setSystemUiVisibility", new Class[]{Integer.TYPE}, objArr);
        }
    }
}