package com.caimai.platform.demo.activity;

import org.json.JSONObject;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.caimai.platform.demo.utils.Constant;
import com.duoku.platform.DkPlatform;
import com.duoku.platform.DkPlatformSettings;
import com.duoku.platform.DkPlatformSettings.GameCategory;
import com.duoku.platform.DkProtocolKeys;
import com.duoku.platform.IDKSDKCallBack;

/**
 * 启动页面
 * 
 */
public class WelcomeActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 1、初始化sdk
        initSDK();
    }

    /*
     * 初始化SDK
     */
    private void initSDK() {
        IDKSDKCallBack initcompletelistener = new IDKSDKCallBack() {
            @Override
            public void onResponse(String paramString) {
                int _stateCode = 0;
                try {
                    JSONObject _jsonObj = new JSONObject(paramString);
                    _stateCode = _jsonObj
                            .getInt(DkProtocolKeys.FUNCTION_INIT_STATE_CODE);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                switch (_stateCode) {
                    case DkProtocolKeys.FUNCTION_FLAG_NORMAL: {
                        // 正常启动初始化自己的游戏,CP处理
                        Intent intent = new Intent(WelcomeActivity.this,
                                UserLoginActivity.class);
                        startActivity(intent);
                        finish();
                    }
                        break;
                    case DkProtocolKeys.FUNCTION_FLAG_FORCE_CLOSE: {

                        // 异常则退出
                        finish();
                    }
                        break;
                    default: {
                        // 如果还有别的Activity或资源要关闭的在这里处理
                        // 彻底关闭游戏的处理
                    }
                        break;
                }
            }
        };

        DkPlatformSettings appInfo = new DkPlatformSettings();
        appInfo.setGameCategory(GameCategory.ONLINE_Game);
        appInfo.setAppid(Constant.appId_DkDemo);// 应用ID，由百度移动游戏分配
        appInfo.setAppkey(Constant.appKey_DkDemo);// 应用Key，由百度移动游戏分配
        // appInfo.setOrient(DkPlatformSettings.SCREEN_ORIENTATION_PORTRAIT); //
        // 竖屏
        appInfo.setOrient(DkPlatformSettings.SCREEN_ORIENTATION_LANDSCAPE);//
        // 横屏
        DkPlatform.init(this, appInfo, initcompletelistener);
    }

}
