2011-03-08 13:49:58 +08:00
|
|
|
#include "CCApplication.h"
|
2011-07-22 18:14:29 +08:00
|
|
|
#include "jni/JniHelper.h"
|
2011-03-01 19:53:39 +08:00
|
|
|
#include "CCDirector.h"
|
2011-03-08 13:49:58 +08:00
|
|
|
#include "CCEGLView.h"
|
2011-03-01 19:53:39 +08:00
|
|
|
#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"
|
2011-03-01 19:53:39 +08:00
|
|
|
#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-01 19:53:39 +08:00
|
|
|
|
2011-03-08 13:49:58 +08:00
|
|
|
CCApplication::CCApplication()
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
2011-03-08 13:49:58 +08:00
|
|
|
CC_ASSERT(! sm_pSharedApplication);
|
2011-03-01 19:53:39 +08:00
|
|
|
sm_pSharedApplication = this;
|
|
|
|
}
|
|
|
|
|
2011-03-08 13:49:58 +08:00
|
|
|
CCApplication::~CCApplication()
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
2011-03-08 13:49:58 +08:00
|
|
|
CC_ASSERT(this == sm_pSharedApplication);
|
2011-03-01 19:53:39 +08:00
|
|
|
sm_pSharedApplication = NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-08 13:49:58 +08:00
|
|
|
int CCApplication::run()
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
|
|
|
// Initialize instance and cocos2d.
|
|
|
|
if (! initInstance() || ! applicationDidFinishLaunching())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-08 13:49:58 +08:00
|
|
|
void CCApplication::setAnimationInterval(double interval)
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
2011-07-22 18:14:29 +08:00
|
|
|
JniMethodInfo methodInfo;
|
|
|
|
if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxRenderer", "setAnimationInterval",
|
|
|
|
"(D)V"))
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
2011-07-22 18:14:29 +08:00
|
|
|
CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__);
|
2011-03-01 19:53:39 +08:00
|
|
|
}
|
2011-07-22 18:14:29 +08:00
|
|
|
else
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
2011-07-22 18:14:29 +08:00
|
|
|
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, interval);
|
2011-03-01 19:53:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-08 13:49:58 +08:00
|
|
|
CCApplication::Orientation CCApplication::setOrientation(Orientation orientation)
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
|
|
|
return orientation;
|
|
|
|
}
|
|
|
|
|
2011-03-08 13:49:58 +08:00
|
|
|
void CCApplication::statusBarFrame(CCRect * rect)
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
|
|
|
if (rect)
|
|
|
|
{
|
|
|
|
// android doesn't have status bar.
|
2011-03-08 13:49:58 +08:00
|
|
|
*rect = CCRectMake(0, 0, 0, 0);
|
2011-03-01 19:53:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// static member function
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2011-03-08 13:49:58 +08:00
|
|
|
CCApplication& CCApplication::sharedApplication()
|
2011-03-01 19:53:39 +08:00
|
|
|
{
|
2011-03-08 13:49:58 +08:00
|
|
|
CC_ASSERT(sm_pSharedApplication);
|
2011-03-01 19:53:39 +08:00
|
|
|
return *sm_pSharedApplication;
|
|
|
|
}
|
|
|
|
|
2011-06-17 10:49:02 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-01 19:53:39 +08:00
|
|
|
NS_CC_END;
|