package org.cocos2dx.javascript.thirdSdk;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

import org.cocos2dx.javascript.AppActivity;
import org.cocos2dx.javascript.util.DeviceUtil;
import org.cocos2dx.lib.Cocos2dxJavascriptJavaBridge;

import com.aries.qsllx.BuildConfig;
import com.aries.qsllx.R;
import com.aries.qsllx.wxapi.WXEntryActivity;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXImageObject;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;

public class ThirdSdkMgr {

    /** 日志标签 */
    private static String _Tag = "[ThirdMgr]-------:";

    /** 主活动进程 */
    public static AppActivity appActivity = null;
    /** 微信 */
    public static WXEntryActivity wxEntryActivity = null;
    private static DeviceUtil DevicesUtil;

    public static void regToWx()
    {

        WXEntryActivity.getInstance().regToWx(ThirdSdkMgr.appActivity);
    }

    //Cocos 对应与Java交互的脚本
    public static String cocosJsbMgrName = "window.JsbMgr.";

    //微信相关---------------------------------------------------------------------------------------
    /** 微信授权 */
    public static void WxAuth()
    {
        WXEntryActivity.getInstance().startWxAuth(ThirdSdkMgr.appActivity);
    }

    /** 分享图 */
    public static  void sharePic()
    {
        Log.d("=== Android","微信分享大图");
        WXEntryActivity.getInstance().sharePic(ThirdSdkMgr.appActivity);
    }

    /**
     * 微信授权code
     * @param code 微信授权返回的code
     */
    public static void wxAccessToken(final String code) {
        appActivity.runOnGLThread(new Runnable() {
            @Override
            public void run() {
                Cocos2dxJavascriptJavaBridge.evalString(cocosJsbMgrName + "onGetWxAccessCode('" + code + "');");
                Log.d("TTTTTTT", "callToJsCancel ");
            }
        });
    }

    //设备信息相关------------------------------------------------------------------------------------
    /** 获取设备信息 */
    public static void getDeviceInfo() {
        Log.d("[ThirdSdkMgr] ","getDeviceInfo");
        //获取安卓id
        String ANDROID_ID = DevicesUtil.getAndroidId(appActivity);
        //获取Oaid
        String mOAID = DevicesUtil.getOaid();
        //获取IMEI号
        String imei1 = DevicesUtil.getImei(appActivity);
        //获取mac
        String mac = DevicesUtil.getMac(appActivity);
        //获取版本名称
        String versionName = DevicesUtil.getVersionName(appActivity);
        //获取友盟的channel
        String umengChannel = BuildConfig.UM_CHANNEL;
        //获取设备类型
        String deviceType = DevicesUtil.getSystemVersion();
        //获取安卓版本
        String androidVersion = DevicesUtil.getSystemModel();

        updateDeviceInfo(ANDROID_ID, "", imei1, mac, mOAID, BuildConfig.UM_AID, versionName, umengChannel, deviceType, androidVersion);
    }

    /** 更新设备信息 */
    public static void updateDeviceInfo(final String android_id, final String idfa, final String imei, final String mac,
                                        final String oaid, final String umid, final String versionName,
                                        final String umengChannel, final String deviceType, final String androidVersion) {
//        android_id, idfa, imei, mac, oaid, umid
        appActivity.runOnGLThread(new Runnable() {
            @Override
            public void run() {
                String param =  android_id + "#" + idfa + "#" + imei + "#" + mac + "#" + oaid + "#" + umid + "#" + BuildConfig.TF_CHANNEL +
                        "#" + versionName + "#" + umengChannel + "#" + deviceType + "#" + androidVersion ;
                Cocos2dxJavascriptJavaBridge.evalString(cocosJsbMgrName + "updateDeviceInfo('" + param + "');");
            }
        });
    }

    /**获取广告配置*/
    public static String getAdvertisingChannel(){
        //Log.d("adadasdsad",BuildConfig.WX_APP_ID);
        //Log.d("adadasdsad",BuildConfig.TF_CHANNEL);
        //Log.d("adadasdsad","asdadsadsa"+BuildConfig.TOPON);
        String str = BuildConfig.TF_CHANNEL +","+BuildConfig.TOPON;
        return str;
    }

    /**获取微信appid*/
    public static String getWxAppId(){
//        Log.d(">>>>> ", "getWXAppId: " + BuildConfig.WX_APP_ID);
        return BuildConfig.WX_APP_ID;
    }
    public static void requestPermission() {

    }

    //埋点相关---------------------------------------------------------------------------------------
}
