导航菜单

页面标题

页面副标题

夜猫麻将 v24.1.1 - MainActivity.java 源代码

正在查看: 夜猫麻将 v24.1.1 应用的 MainActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.yemao.yemao2024;

import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Process;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.content.PermissionChecker;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.View;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.mostone.open.sdk.MConfigure;
import com.mostone.open.sdk.ShareAction;
import com.mostone.open.sdk.listener.MShareListener;
import com.mostone.open.sdk.media.MImageData;
import com.mostone.open.sdk.media.MWebData;
import com.mostone.open.sdk.model.BeanMResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXImageObject;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXTextObject;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;
import org.xianliao.im.sdk.api.ISGAPI;
import org.xianliao.im.sdk.modelmsg.SGImageObject;
import org.xianliao.im.sdk.modelmsg.SGLinkObject;
import org.xianliao.im.sdk.modelmsg.SGMediaMessage;
import org.xianliao.im.sdk.modelmsg.SGTextObject;
import org.xianliao.im.sdk.modelmsg.SendMessageToSG;

public class MainActivity extends UnityPlayerActivity {
    private static final int PERMISSION_REQUEST_CODE = 1;
    private IWXAPI api;
    public static String rObj = null;
    public static String rFun = null;
    private LocationClient mLocationClient = null;
    private ISGAPI mXlApi = null;
    private MShareListener mShareListener = new MShareListener() {
        public void onResult(BeanMResp beanMResp) {
            String resultResp;
            int errCode = 9999;
            if (beanMResp.resCode == 0) {
                errCode = 0;
                resultResp = "分享成功!";
            } else if (beanMResp.resCode == -2) {
                resultResp = "分享取消!";
            } else {
                resultResp = "分享取消!";
            }
            MainActivity.CallBackUnity("MOWANG", "SHARE", errCode, resultResp);
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("开始创建初始化中");
        this.api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
        if (Build.VERSION.SDK_INT >= 23) {
            String[] permissions = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION", "android.permission.RECORD_AUDIO"};
            ArrayList<String> needPermissions = new ArrayList<>();
            for (String permission : permissions) {
                if (checkSelfPermission(permission) != 0) {
                    needPermissions.add(permission);
                }
            }
            if (!needPermissions.isEmpty()) {
                ActivityCompat.requestPermissions(this, (String[]) needPermissions.toArray(new String[0]), 1);
            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == 1) {
            return;
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    public String GetUrl() {
        Intent intent = getIntent();
        Uri uri = intent.getData();
        if (uri != null) {
            return uri.toString();
        }
        return "";
    }

    public void BindPlatform(String objectName, String callBackName) {
        rObj = objectName;
        rFun = callBackName;
    }

    public boolean IsInstallWX() {
        IWXAPI iwxapi = this.api;
        if (iwxapi != null && iwxapi.isWXAppInstalled()) {
            return true;
        }
        return false;
    }

    public void LoginWx() {
        this.api.registerApp(Constants.APP_ID);
        SendAuth.Req req = new SendAuth.Req();
        req.scope = "snsapi_userinfo";
        req.state = "wechat_sdk_demo_test";
        this.api.sendReq(req);
    }

    public static void CallBackUnity(String rName, String rType, int r_errCode, String r_msg) {
        JSONObject prame = new JSONObject();
        try {
            prame.put("rName", rName);
            prame.put("rType", rType);
            prame.put("r_errCode", Integer.toString(r_errCode));
            prame.put("r_msg", r_msg);
            if (rObj != null && rFun != null) {
                UnityPlayer.UnitySendMessage(rObj, rFun, prame.toString());
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    private String buildTransaction(String type) {
        if (type == null) {
            return String.valueOf(System.currentTimeMillis());
        }
        return type + System.currentTimeMillis();
    }

    public void ShareTextToWx(String str, String str2, String str3, boolean z) {
        Bitmap bitmap = ((BitmapDrawable) getPackageManager().getApplicationIcon(getApplicationInfo())).getBitmap();
        if (str3 != null && str3.length() > 0) {
            WXWebpageObject wXWebpageObject = new WXWebpageObject();
            wXWebpageObject.webpageUrl = str3;
            WXMediaMessage wXMediaMessage = new WXMediaMessage(wXWebpageObject);
            wXMediaMessage.title = str;
            wXMediaMessage.description = str2;
            wXMediaMessage.setThumbImage(bitmap);
            SendMessageToWX.Req req = new SendMessageToWX.Req();
            req.transaction = "transaction" + System.currentTimeMillis();
            req.message = wXMediaMessage;
            req.scene = !z ? 1 : 0;
            this.api.sendReq(req);
            return;
        }
        WXTextObject wXTextObject = new WXTextObject();
        wXTextObject.text = str2;
        WXMediaMessage wXMediaMessage2 = new WXMediaMessage(wXTextObject);
        wXMediaMessage2.title = str;
        wXMediaMessage2.description = str2;
        wXMediaMessage2.setThumbImage(bitmap);
        SendMessageToWX.Req req2 = new SendMessageToWX.Req();
        req2.transaction = "transaction" + System.currentTimeMillis();
        req2.message = wXMediaMessage2;
        req2.scene = !z ? 1 : 0;
        this.api.sendReq(req2);
    }

    public void ShareImageToWx(byte[] bArr, int i, int i2, boolean z) {
        Bitmap decodeByteArray = BitmapFactory.decodeByteArray(bArr, 0, bArr.length);
        WXImageObject wXImageObject = new WXImageObject(decodeByteArray);
        WXMediaMessage wXMediaMessage = new WXMediaMessage();
        wXMediaMessage.mediaObject = wXImageObject;
        Bitmap createScaledBitmap = Bitmap.createScaledBitmap(decodeByteArray, i, i2, true);
        decodeByteArray.recycle();
        wXMediaMessage.thumbData = Util.bmpToByteArray(createScaledBitmap, true);
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("img");
        req.message = wXMediaMessage;
        req.scene = !z ? 1 : 0;
        this.api.sendReq(req);
    }

    private Bitmap LoadBitmap(String uri) {
        URL imgUrl = null;
        try {
            imgUrl = new URL(uri);
        } catch (MalformedURLException e1) {
            e1.printStackTrace();
        }
        try {
            Bitmap bmp = BitmapFactory.decodeStream(imgUrl.openStream());
            return bmp;
        } catch (Exception e) {
            return null;
        }
    }

    public String CreateMD5(byte[] byteArray) {
        return MD5.getMessageDigest(byteArray);
    }

    public boolean CopyToClipboard(String inputText) {
        ClipboardManager clipboardManager = (ClipboardManager) getSystemService("clipboard");
        ClipData clipData = ClipData.newPlainText("playerId", inputText);
        clipboardManager.setPrimaryClip(clipData);
        return true;
    }

    public String GetTextFromClipboard() {
        ClipboardManager clipboardManager = (ClipboardManager) getSystemService("clipboard");
        if (clipboardManager != null && clipboardManager.hasPrimaryClip()) {
            ClipData cdText = clipboardManager.getPrimaryClip();
            ClipData.Item item = cdText.getItemAt(0);
            return item.getText().toString();
        }
        return "";
    }

    public void ToSetLocation() {
        if (!IsLocationEnabled()) {
            Intent intent = new Intent();
            intent.setAction("android.settings.LOCATION_SOURCE_SETTINGS");
            intent.setFlags(268435456);
            try {
                startActivity(intent);
                return;
            } catch (ActivityNotFoundException e) {
                intent.setAction("android.settings.SETTINGS");
                try {
                    startActivity(intent);
                    return;
                } catch (Exception e2) {
                    e2.printStackTrace();
                    return;
                }
            }
        }
        ToOpenAppInfo();
    }

    public void ToOpenAppInfo() {
        Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setData(Uri.parse("package:" + getPackageName()));
        try {
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            intent.setAction("android.settings.SETTINGS");
            try {
                startActivity(intent);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }

    public boolean IsLocationEnabled() {
        LocationManager locationManager = (LocationManager) getSystemService("location");
        boolean gps = locationManager.isProviderEnabled("gps");
        boolean network = locationManager.isProviderEnabled("network");
        if (gps || network) {
            return true;
        }
        return false;
    }

    public boolean CheckLocationPermission() {
        boolean location1 = CheckProvider("android.permission.ACCESS_FINE_LOCATION");
        boolean location2 = CheckProvider("android.permission.ACCESS_COARSE_LOCATION");
        if (!location1 && !location2) {
            return false;
        }
        return true;
    }

    private boolean CheckProvider(String permission) {
        return Build.VERSION.SDK_INT >= 23 ? ActivityCompat.checkSelfPermission(getApplicationContext(), permission) == 0 : PermissionChecker.checkPermission(getApplicationContext(), permission, Process.myPid(), Process.myUid(), getPackageName()) == 0;
    }

    public boolean IsAudioEnabled() {
        return CheckProvider("android.permission.RECORD_AUDIO");
    }

    public void OpenUrl(String url) {
        Intent intent = new Intent();
        intent.setAction("android.intent.action.VIEW");
        Uri content_url = Uri.parse(url);
        intent.setData(content_url);
        startActivity(intent);
        finish();
    }

    public void ListenerLocation() {
        try {
            LocationClient.setAgreePrivacy(true);
            this.mLocationClient = new LocationClient(getApplicationContext());
            BDAbstractLocationListener listener = new BDAbstractLocationListener() {
                public void onReceiveLocation(BDLocation location) {
                    MainActivity.this.SetLocationData(0, location, "定位返回!");
                    MainActivity.this.CheckLocationPermission();
                }
            };
            this.mLocationClient.registerLocationListener(listener);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void SetLocationData(int errCode, BDLocation location, String errStr) {
        if (errCode != 0) {
            CallBackUnity("LOCATION", "LOCATION", errCode, errStr);
            return;
        }
        JSONObject json = new JSONObject();
        try {
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();
            if (latitude == 0.0d) {
                json.put("success", false);
            } else {
                json.put("success", true);
            }
            json.put("errCode", errCode);
            json.put("latitude", latitude);
            json.put("longitude", longitude);
            if (location.getCountry() != null) {
                json.put("country", location.getCountry());
            }
            if (location.getProvince() != null) {
                json.put("province", location.getProvince());
            }
            if (location.getCity() != null) {
                json.put("city", location.getCity());
            }
            if (location.getDistrict() != null) {
                json.put("district", location.getDistrict());
            }
            if (location.getTown() != null) {
                json.put("town", location.getTown());
            }
            if (location.getStreet() != null) {
                json.put("street", location.getStreet());
            }
            if (location.getAddrStr() != null) {
                json.put("address", location.getAddrStr());
            }
            CallBackUnity("LOCATION", "LOCATION", 0, json.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    public void StartLocation(int updateTime) {
        LocationClientOption option = new LocationClientOption();
        option.setIsNeedAddress(true);
        option.setNeedNewVersionRgc(true);
        option.setLocationMode(LocationClientOption.LocationMode.Battery_Saving);
        option.setCoorType("bd09ll");
        option.setScanSpan(updateTime);
        option.setOpenGps(true);
        option.SetIgnoreCacheException(false);
        option.setWifiCacheTimeOut(300000);
        option.setNeedNewVersionRgc(true);
        this.mLocationClient.setLocOption(option);
        this.mLocationClient.start();
    }

    public void StopLocation() {
        this.mLocationClient.stop();
    }

    public void Vibrator(long r_time) {
        Vibrator vibrator = (Vibrator) getApplication().getSystemService("vibrator");
        if (Build.VERSION.SDK_INT >= 26) {
            vibrator.vibrate(VibrationEffect.createOneShot(r_time, -1));
        } else {
            vibrator.vibrate(r_time);
        }
    }

    public boolean CheckIsInstalledXL() {
        ISGAPI isgapi = this.mXlApi;
        if (isgapi != null && isgapi.isSGAppInstalled()) {
            return true;
        }
        return false;
    }

    public void ShareTextToXianLiao(String textTitle, String textMsg, String webpageUrl) {
        if (!CheckIsInstalledXL()) {
            return;
        }
        PackageManager pm = getPackageManager();
        Drawable icon = pm.getApplicationIcon(getApplicationInfo());
        BitmapDrawable bd = (BitmapDrawable) icon;
        Bitmap thumb = bd.getBitmap();
        if (webpageUrl != null && webpageUrl.length() > 0) {
            SGLinkObject linkObject = new SGLinkObject(thumb);
            linkObject.shareUrl = webpageUrl;
            SGMediaMessage msg = new SGMediaMessage();
            msg.mediaObject = linkObject;
            msg.title = textTitle;
            msg.description = textMsg;
            SendMessageToSG.Req req = new SendMessageToSG.Req();
            req.transaction = "t_link";
            req.mediaMessage = msg;
            req.scene = 0;
            this.mXlApi.sendReq(req);
            return;
        }
        SGTextObject textObject = new SGTextObject();
        textObject.text = textMsg;
        SGMediaMessage msg2 = new SGMediaMessage();
        msg2.mediaObject = textObject;
        SendMessageToSG.Req req2 = new SendMessageToSG.Req();
        req2.transaction = "t_link";
        req2.mediaMessage = msg2;
        req2.scene = 0;
        this.mXlApi.sendReq(req2);
    }

    public void ShareImgToXianLiao(byte[] imgBytes, int width, int height) {
        if (!CheckIsInstalledXL()) {
            return;
        }
        Bitmap bmp = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
        SGImageObject imageObject = new SGImageObject(bmp);
        SGMediaMessage msg = new SGMediaMessage();
        msg.mediaObject = imageObject;
        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, width, height, true);
        bmp.recycle();
        msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
        SendMessageToSG.Req req = new SendMessageToSG.Req();
        req.transaction = "t_image";
        req.mediaMessage = msg;
        req.scene = 0;
        this.mXlApi.sendReq(req);
    }

    public boolean CheckIsInstallMW() {
        return MConfigure.isMOAppInstalled();
    }

    public void ShareTextToMowang(String textTitle, String textMsg, String webpageUrl) {
        if (!CheckIsInstallMW()) {
            return;
        }
        PackageManager pm = getPackageManager();
        Drawable icon = pm.getApplicationIcon(getApplicationInfo());
        BitmapDrawable bd = (BitmapDrawable) icon;
        Bitmap thumb = bd.getBitmap();
        MWebData mWebData = new MWebData();
        mWebData.title = textTitle;
        mWebData.content = textMsg;
        mWebData.thumbData = new MImageData(this, thumb);
        mWebData.webLink = webpageUrl;
        new ShareAction(this).withMedia(mWebData).setCallBack(this.mShareListener).share();
    }

    public void ShareImgToToMowang(byte[] imgBytes, int width, int height) {
        if (!CheckIsInstallMW()) {
            return;
        }
        Bitmap bmp = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
        MImageData mImageData = new MImageData(this, bmp);
        new ShareAction(this).withMedia(mImageData).setCallBack(this.mShareListener).share();
    }

    public void ListenerNetWorkInfo() {
        TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService("phone");
        PhoneStateListener mylistener = new PhoneStateListener() {
            @Override
            public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                super.onSignalStrengthsChanged(signalStrength);
                int level = -1;
                if (Build.VERSION.SDK_INT >= 23) {
                    level = signalStrength.getLevel();
                } else {
                    Method method2 = null;
                    try {
                        method2 = signalStrength.getClass().getMethod("getLteLevel", new Class[0]);
                    } catch (NoSuchMethodException e) {
                        e.printStackTrace();
                    }
                    if (method2 != null) {
                        try {
                            level = ((Integer) method2.invoke(signalStrength, new Object[0])).intValue();
                        } catch (IllegalAccessException e2) {
                            e2.printStackTrace();
                        } catch (InvocationTargetException e3) {
                            e3.printStackTrace();
                        }
                    }
                }
                if (level >= 0) {
                    MainActivity.CallBackUnity("NETWORK", "NETWORK", 0, level + "");
                }
            }
        };
        tm.listen(mylistener, 256);
    }

    public int GetWifiInfo() {
        WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService("wifi");
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        if (wifiInfo.getBSSID() == null) {
            return 0;
        }
        wifiInfo.getSSID();
        int signalLevel = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 6);
        return signalLevel;
    }

    public void ListenerBattery() {
        BroadcastReceiver mBatInfoReveiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                int intLevel = intent.getIntExtra("level", 0);
                int intScale = intent.getIntExtra("scale", 100);
                MainActivity.CallBackUnity("BATTERY", "BATTERY", 0, ((intLevel * 100.0f) / intScale) + "");
            }
        };
        IntentFilter filter = new IntentFilter("android.intent.action.BATTERY_CHANGED");
        registerReceiver(mBatInfoReveiver, filter);
    }

    public void GetPhoneNotchHeight() {
        if (Build.VERSION.SDK_INT < 28) {
            return;
        }
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        Log.i("Unity", "**getStatusBarHeight**" + result);
        final View decorView = getWindow().getDecorView();
        decorView.post(new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= 28) {
                    Log.i("Unity", "获取刘海");
                    DisplayCutout displayCutout = decorView.getRootWindowInsets().getDisplayCutout();
                    if (displayCutout != null) {
                        Log.e("Unity", "安全区域距离屏幕左边的距离 SafeInsetLeft:" + displayCutout.getSafeInsetLeft());
                        Log.e("Unity", "安全区域距离屏幕右部的距离 SafeInsetRight:" + displayCutout.getSafeInsetRight());
                        Log.e("Unity", "安全区域距离屏幕顶部的距离 SafeInsetTop:" + displayCutout.getSafeInsetTop());
                        Log.e("Unity", "安全区域距离屏幕底部的距离 SafeInsetBottom:" + displayCutout.getSafeInsetBottom());
                    }
                }
            }
        });
    }

    public void InitYunCeng() {
        Log.i("Unity", "yunceng sdk init failed");
    }

    public String BindYunCeng(String pid, String dip, String dPort) {
        Log.i("Unity", "yunceng sdk bind failed");
        return null;
    }

    public boolean GetInstallAPKPermission() {
        if (Build.VERSION.SDK_INT >= 26) {
            return getApplicationContext().getPackageManager().canRequestPackageInstalls();
        }
        return true;
    }

    public void OpenInstallAPKPermission() {
        Uri packageURI = Uri.parse("package:" + getPackageName());
        Intent intent = new Intent("android.settings.MANAGE_UNKNOWN_APP_SOURCES", packageURI);
        startActivityForResult(intent, 10086);
    }

    public void InstallApk(String apkFullPath) {
        Uri uri;
        try {
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.setFlags(268435456);
            File apkFile = new File(apkFullPath);
            if (Build.VERSION.SDK_INT >= 24) {
                String path = getApplicationContext().getPackageName() + ".fileProvider";
                Log.i("Unity", path);
                uri = FileProvider.getUriForFile(this, path, apkFile);
                intent.addFlags(1);
            } else {
                uri = Uri.fromFile(apkFile);
                Log.i("Unity", apkFile.getAbsolutePath());
            }
            intent.setDataAndType(uri, "application/vnd.android.package-archive");
            startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}