package com.secondworld.univeralsdk; 
 | 
  
 | 
import android.app.Activity; 
 | 
  
 | 
import com.allugame.freesdk.callback.FreeCallback; 
 | 
import com.allugame.freesdk.callback.FreeCallbackCode; 
 | 
import com.allugame.freesdk.callback.FreeRegisterCallback; 
 | 
import com.allugame.freesdk.entities.FreeOrder; 
 | 
import com.allugame.freesdk.port.FreePlatform; 
 | 
  
 | 
import org.json.JSONException; 
 | 
import org.json.JSONObject; 
 | 
  
 | 
import java.util.HashMap; 
 | 
import java.util.Map; 
 | 
  
 | 
/** 
 | 
 * Created by Administrator on 2018/7/18 0018. 
 | 
 */ 
 | 
  
 | 
public class FreePlatformUtil 
 | 
{ 
 | 
    private static FreePlatformUtil s_Instance; 
 | 
  
 | 
    private boolean m_Init = false; 
 | 
    public boolean payProcessing = false; 
 | 
  
 | 
    public static FreePlatformUtil getInstace() 
 | 
    { 
 | 
        if (s_Instance == null) 
 | 
        { 
 | 
            s_Instance = new FreePlatformUtil(); 
 | 
        } 
 | 
        return s_Instance; 
 | 
    } 
 | 
  
 | 
    private Map<String, Object> m_Message = new HashMap<>(); 
 | 
  
 | 
    public void login(final Activity activity) 
 | 
    { 
 | 
        FreePlatform.getInstance().login(activity); 
 | 
    } 
 | 
  
 | 
    public void logout() 
 | 
    { 
 | 
        FreePlatform.getInstance().logout(); 
 | 
    } 
 | 
  
 | 
    public void switchAccount(final Activity activity) 
 | 
    { 
 | 
        FreePlatform.getInstance().switchAccount(activity); 
 | 
    } 
 | 
  
 | 
    public void pay(Activity activity, String title, String orderId, float mount, String cpInfo) 
 | 
    { 
 | 
        FreeOrder _order = new FreeOrder(title, orderId, mount, cpInfo); 
 | 
        FreePlatform.getInstance().pay(activity, _order); 
 | 
    } 
 | 
  
 | 
    public void init(final Activity activity) 
 | 
    { 
 | 
        if (m_Init) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        FreePlatform.getInstance().init(activity, new FreeCallback() 
 | 
        { 
 | 
            @Override 
 | 
            public void onResult(int i, String s) 
 | 
            { 
 | 
                m_Message.clear(); 
 | 
                switch (i) 
 | 
                { 
 | 
                    case FreeCallbackCode.INIT_SUCCESS: 
 | 
                        m_Init = true; 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformInitOk); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        break; 
 | 
                    case FreeCallbackCode.INIT_FAILURE: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformInitFail); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        break; 
 | 
                    case FreeCallbackCode.LOGIN_SUCCESS: 
 | 
                        FreePlatform.getInstance().auth(); 
 | 
                        try 
 | 
                        { 
 | 
                            JSONObject _info = new JSONObject(s); 
 | 
                            m_Message.put("code", CodeA2U.FreePlatformLoginOk); 
 | 
                            m_Message.put("info", _info); 
 | 
                            UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        } catch (JSONException e) 
 | 
                        { 
 | 
                            e.printStackTrace(); 
 | 
                        } 
 | 
                        break; 
 | 
                    case FreeCallbackCode.LOGIN_FAILURE: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformLoginFail); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        break; 
 | 
                    case FreeCallbackCode.LOGOUT_SUCCESS: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformLogoutOk); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        break; 
 | 
                    case FreeCallbackCode.LOGOUT_FAILURE: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformLogoutFail); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        break; 
 | 
                    case FreeCallbackCode.SWITCH_SUCCESS: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformSwitchAccountOk); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        break; 
 | 
                    case FreeCallbackCode.LOGIN_CANCEL: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformLoginCancel); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        break; 
 | 
                    case FreeCallbackCode.PAY_SUCCESS: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformPayOk); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        payProcessing = false; 
 | 
                        break; 
 | 
                    case FreeCallbackCode.PAY_FAIL: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformPayFail); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        payProcessing = false; 
 | 
                        break; 
 | 
                    case FreeCallbackCode.PAY_CANCEL: 
 | 
                        m_Message.put("code", CodeA2U.FreePlatformPayCancel); 
 | 
                        UniversalUtil.sendMessageToUnity(m_Message); 
 | 
                        payProcessing = false; 
 | 
                        break; 
 | 
                } 
 | 
            } 
 | 
        }); 
 | 
  
 | 
        FreePlatform.getInstance().setRegisterCallback(new FreeRegisterCallback() 
 | 
        { 
 | 
            @Override 
 | 
            public void onResult(boolean b, String account) 
 | 
            { 
 | 
                Map<String, Object> _registerMsg = new HashMap<>(); 
 | 
                _registerMsg.put("code", CodeA2U.FreePlatformRegisterOk); 
 | 
                _registerMsg.put("account", account); 
 | 
                UniversalUtil.sendMessageToUnity(_registerMsg); 
 | 
            } 
 | 
        }); 
 | 
    } 
 | 
  
 | 
    public void SendRegisterEvent() 
 | 
    { 
 | 
        Tracking.setRegisterWithAccountID(account); 
 | 
        EventUtils.setRegister("mobile",true); 
 | 
    } 
 | 
} 
 |