axmol/cocos2dx/platform/android/CCApplication_android.cpp

97 lines
2.2 KiB
C++
Raw Normal View History

2011-03-08 13:49:58 +08:00
#include "CCApplication.h"
#include "jni/JniHelper.h"
#include "CCDirector.h"
2011-03-08 13:49:58 +08:00
#include "CCEGLView.h"
#include "Cocos2dJni.h"
#include <android/log.h>
#include <jni.h>
2011-07-19 16:54:42 +08:00
#include <cstring>
2011-03-08 13:49:58 +08:00
#define LOG_TAG "CCApplication_android Debug"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
NS_CC_BEGIN;
// sharedApplication pointer
2011-03-08 13:49:58 +08:00
CCApplication * CCApplication::sm_pSharedApplication = 0;
2011-03-08 13:49:58 +08:00
CCApplication::CCApplication()
{
2011-03-08 13:49:58 +08:00
CC_ASSERT(! sm_pSharedApplication);
sm_pSharedApplication = this;
}
2011-03-08 13:49:58 +08:00
CCApplication::~CCApplication()
{
2011-03-08 13:49:58 +08:00
CC_ASSERT(this == sm_pSharedApplication);
sm_pSharedApplication = NULL;
}
2011-03-08 13:49:58 +08:00
int CCApplication::run()
{
// Initialize instance and cocos2d.
if (! initInstance() || ! applicationDidFinishLaunching())
{
return 0;
}
return -1;
}
2011-03-08 13:49:58 +08:00
void CCApplication::setAnimationInterval(double interval)
{
JniMethodInfo methodInfo;
if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxRenderer", "setAnimationInterval",
"(D)V"))
{
CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__);
}
else
{
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, interval);
}
}
2011-03-08 13:49:58 +08:00
CCApplication::Orientation CCApplication::setOrientation(Orientation orientation)
{
return orientation;
}
2011-03-08 13:49:58 +08:00
void CCApplication::statusBarFrame(CCRect * rect)
{
if (rect)
{
// android doesn't have status bar.
2011-03-08 13:49:58 +08:00
*rect = CCRectMake(0, 0, 0, 0);
}
}
//////////////////////////////////////////////////////////////////////////
// static member function
//////////////////////////////////////////////////////////////////////////
2011-03-08 13:49:58 +08:00
CCApplication& CCApplication::sharedApplication()
{
2011-03-08 13:49:58 +08:00
CC_ASSERT(sm_pSharedApplication);
return *sm_pSharedApplication;
}
ccLanguageType CCApplication::getCurrentLanguage()
{
char* pLanguageName = getCurrentLanguageJNI();
ccLanguageType ret = kLanguageEnglish;
if (0 == strcmp("zh", pLanguageName))
{
ret = kLanguageChinese;
}
else if (0 == strcmp("en", pLanguageName))
{
ret = kLanguageEnglish;
}
return ret;
}
NS_CC_END;