Merge pull request #2113 from minggo/refactor-ccuserdefault

Refactor ccuserdefault
This commit is contained in:
minggo 2013-03-06 23:05:50 -08:00
commit dd8681b18b
18 changed files with 637 additions and 28 deletions

View File

@ -111,7 +111,7 @@ support/CCNotificationCenter.cpp \
support/CCProfiling.cpp \
support/CCPointExtension.cpp \
support/TransformUtils.cpp \
support/CCUserDefault.cpp \
support/user_default/CCUserDefault.cpp \
support/base64.cpp \
support/ccUtils.cpp \
support/CCVertex.cpp \

View File

@ -50,7 +50,7 @@ THE SOFTWARE.
#include "CCAccelerometer.h"
#include "sprite_nodes/CCAnimationCache.h"
#include "touch_dispatcher/CCTouch.h"
#include "support/CCUserDefault.h"
#include "support/user_default/CCUserDefault.h"
#include "shaders/ccGLStateCache.h"
#include "shaders/CCShaderCache.h"
#include "kazmath/kazmath.h"

View File

@ -221,7 +221,7 @@ THE SOFTWARE.
#include "support/CCNotificationCenter.h"
#include "support/CCPointExtension.h"
#include "support/CCProfiling.h"
#include "support/CCUserDefault.h"
#include "support/user_default/CCUserDefault.h"
#include "support/CCVertex.h"
#include "support/tinyxml2/tinyxml2.h"

View File

@ -1,5 +1,5 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2010-2013 cocos2d-x.org
http://www.cocos2d-x.org
@ -23,16 +23,15 @@ THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Locale;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.res.AssetManager;
import android.os.Build;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
@ -41,6 +40,7 @@ public class Cocos2dxHelper {
// ===========================================================
// Constants
// ===========================================================
private static final String PREFS_NAME = "Cocos2dxPrefsFile";
// ===========================================================
// Fields
@ -270,6 +270,67 @@ public class Cocos2dxHelper {
}
return -1;
}
// ===========================================================
// Functions for CCUserDefault
// ===========================================================
public static boolean getBoolForKey(String key) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
return settings.getBoolean(key, false);
}
public static int getIntegerForKey(String key) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
return settings.getInt(key, 0);
}
public static float getFloatForKey(String key) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
return settings.getFloat(key, 0);
}
public static double getDoubleForKey(String key) {
// SharedPreferences doesn't support saving float value
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
return settings.getFloat(key, 0);
}
public static String getStringForKey(String key) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
return settings.getString(key, "");
}
public static void setBoolForKey(String key, boolean value) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(key, value);
}
public static void setIntegerForKey(String key, int value) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt(key, value);
}
public static void setFloatForKey(String key, float value) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putFloat(key, value);
}
public static void setDoubleForKey(String key, double value) {
// SharedPreferences doesn't support recording double value
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putFloat(key, (float)value);
}
public static void setStringForKey(String key, String value) {
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString(key, value);
}
// ===========================================================
// Inner and Anonymous Classes

View File

@ -183,4 +183,160 @@ extern "C" {
t.env->DeleteLocalRef(t.classID);
}
}
// functions for CCUserDefault
bool getBoolForKeyJNI(const char* pKey)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getBoolForKey", "(Ljava/lang/String;)Z")) {
jstring stringArg = t.env->NewStringUTF(pKey);
jboolean ret = t.env->CallStaticBooleanMethod(t.classID, t.methodID, stringArg);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
return ret;
}
return false;
}
int getIntegerForKeyJNI(const char* pKey)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getIntegerForKey", "(Ljava/lang/String;)I")) {
jstring stringArg = t.env->NewStringUTF(pKey);
jint ret = t.env->CallStaticIntMethod(t.classID, t.methodID, stringArg);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
return ret;
}
return 0;
}
float getFloatForKeyJNI(const char* pKey)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getFloatForKey", "(Ljava/lang/String;)F")) {
jstring stringArg = t.env->NewStringUTF(pKey);
jfloat ret = t.env->CallStaticFloatMethod(t.classID, t.methodID, stringArg);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
return ret;
}
return 0;
}
double getDoubleForKeyJNI(const char* pKey)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getDoubleForKey", "(Ljava/lang/String;)D")) {
jstring stringArg = t.env->NewStringUTF(pKey);
jdouble ret = t.env->CallStaticDoubleMethod(t.classID, t.methodID, stringArg);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
return ret;
}
return 0;
}
const char* getStringForKeyJNI(const char* pKey)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "getStringForKey", "(Ljava/lang/String;)Ljava/lang/String;")) {
jstring stringArg = t.env->NewStringUTF(pKey);
jstring str = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, stringArg);
CCString *ret = new CCString(JniHelper::jstring2string(str).c_str());
ret->autorelease();
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
t.env->DeleteLocalRef(str);
return ret->getCString();
}
return 0;
}
void setBoolForKeyJNI(const char* pKey, bool value)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setBoolForKey", "(Ljava/lang/String;Z)V")) {
jstring stringArg = t.env->NewStringUTF(pKey);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
}
}
void setIntegerForKeyJNI(const char* pKey, int value)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setIntegerForKey", "(Ljava/lang/String;I)V")) {
jstring stringArg = t.env->NewStringUTF(pKey);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
}
}
void setFloatForKeyJNI(const char* pKey, float value)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setFloatForKey", "(Ljava/lang/String;F)V")) {
jstring stringArg = t.env->NewStringUTF(pKey);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
}
}
void setDoubleForKeyJNI(const char* pKey, double value)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setDoubleForKey", "(Ljava/lang/String;D)V")) {
jstring stringArg = t.env->NewStringUTF(pKey);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg, value);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg);
}
}
void setStringForKeyJNI(const char* pKey, const char* value)
{
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setStringForKeyKey", "(Ljava/lang/String;Ljava/lang/String;)V")) {
jstring stringArg1 = t.env->NewStringUTF(pKey);
jstring stringArg2 = t.env->NewStringUTF(value);
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1, stringArg2);
t.env->DeleteLocalRef(t.classID);
t.env->DeleteLocalRef(stringArg1);
t.env->DeleteLocalRef(stringArg2);
}
}
}

View File

@ -39,6 +39,17 @@ extern "C" {
extern void enableAccelerometerJNI();
extern void disableAccelerometerJNI();
extern void setAccelerometerIntervalJNI(float interval);
// functions for CCUserDefault
extern bool getBoolForKeyJNI(const char* pKey);
extern int getIntegerForKeyJNI(const char* pKey);
extern float getFloatForKeyJNI(const char* pKey);
extern double getDoubleForKeyJNI(const char* pKey);
extern const char* getStringForKeyJNI(const char* pKey);
extern void setBoolForKeyJNI(const char* pKey, bool value);
extern void setIntegerForKeyJNI(const char* pKey, int value);
extern void setFloatForKeyJNI(const char* pKey, float value);
extern void setDoubleForKeyJNI(const char* pKey, double value);
extern void setStringForKeyJNI(const char* pKey, const char* value);
}
#endif

View File

@ -1 +1 @@
502d05073a521dc7f534fb881b225d1ad5c8fde6
c7e210f8b33a816358feec83a71bfe927820a395

View File

@ -46,7 +46,8 @@ includepaths
"../script_support"
"../sprite_nodes"
"../support"
"../support/tinyxml2"
"../support/tinyxml2"
"../support/user_default/"
"../text_input_node"
"../textures"
"../tileMap_parallax_nodes"
@ -175,6 +176,11 @@ files
("../support/tinyxml2")
[support/tinyxml2]
"*.h"
"*.cpp"
("../support/user_default")
[support/user_default]
"*.h"
"*.cpp"
("../support/zip_support")

View File

@ -81,7 +81,7 @@ SOURCES = ../actions/CCAction.cpp \
../support/tinyxml2/tinyxml2.cpp \
../support/CCPointExtension.cpp \
../support/CCProfiling.cpp \
../support/CCUserDefault.cpp \
../support/user_default/CCUserDefault.cpp \
../support/TransformUtils.cpp \
../support/base64.cpp \
../support/ccUtils.cpp \

View File

@ -214,7 +214,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
<ClCompile Include="..\support\CCNotificationCenter.cpp" />
<ClCompile Include="..\support\CCPointExtension.cpp" />
<ClCompile Include="..\support\CCProfiling.cpp" />
<ClCompile Include="..\support\CCUserDefault.cpp" />
<ClCompile Include="..\support\ccUTF8.cpp" />
<ClCompile Include="..\support\ccUtils.cpp" />
<ClCompile Include="..\support\CCVertex.cpp" />
@ -222,6 +221,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
<ClCompile Include="..\support\TransformUtils.cpp" />
<ClCompile Include="..\support\data_support\ccCArray.cpp" />
<ClCompile Include="..\support\image_support\TGAlib.cpp" />
<ClCompile Include="..\support\user_default\CCUserDefault.cpp" />
<ClCompile Include="..\support\zip_support\ioapi.cpp" />
<ClCompile Include="..\support\zip_support\unzip.cpp" />
<ClCompile Include="..\support\zip_support\ZipUtils.cpp" />
@ -366,7 +366,6 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
<ClInclude Include="..\support\CCNotificationCenter.h" />
<ClInclude Include="..\support\CCPointExtension.h" />
<ClInclude Include="..\support\CCProfiling.h" />
<ClInclude Include="..\support\CCUserDefault.h" />
<ClInclude Include="..\support\ccUTF8.h" />
<ClInclude Include="..\support\ccUtils.h" />
<ClInclude Include="..\support\CCVertex.h" />
@ -376,6 +375,7 @@ xcopy /Y /Q "$(ProjectDir)..\platform\third_party\win32\libraries\*.*" "$(OutDir
<ClInclude Include="..\support\data_support\uthash.h" />
<ClInclude Include="..\support\data_support\utlist.h" />
<ClInclude Include="..\support\image_support\TGAlib.h" />
<ClInclude Include="..\support\user_default\CCUserDefault.h" />
<ClInclude Include="..\support\zip_support\ioapi.h" />
<ClInclude Include="..\support\zip_support\unzip.h" />
<ClInclude Include="..\support\zip_support\ZipUtils.h" />

View File

@ -97,6 +97,9 @@
<Filter Include="support\tinyxml2">
<UniqueIdentifier>{cc25bb83-527d-4218-8d68-ebf963ce7698}</UniqueIdentifier>
</Filter>
<Filter Include="support\user_default">
<UniqueIdentifier>{c45b97e8-fa1f-4e58-8ec5-d46371c2dd26}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\base_nodes\CCAtlasNode.cpp">
@ -291,9 +294,6 @@
<ClCompile Include="..\support\CCProfiling.cpp">
<Filter>support</Filter>
</ClCompile>
<ClCompile Include="..\support\CCUserDefault.cpp">
<Filter>support</Filter>
</ClCompile>
<ClCompile Include="..\support\ccUtils.cpp">
<Filter>support</Filter>
</ClCompile>
@ -446,13 +446,18 @@
<ClCompile Include="..\platform\CCImageCommonWebp.cpp">
<Filter>platform</Filter>
</ClCompile>
<ClCompile Include="..\support\tinyxml2\tinyxml2.cpp" />
<ClCompile Include="..\platform\win32\CCDevice.cpp">
<Filter>platform\win32</Filter>
</ClCompile>
<ClCompile Include="..\support\ccUTF8.cpp">
<Filter>support</Filter>
</ClCompile>
<ClCompile Include="..\support\user_default\CCUserDefault.cpp">
<Filter>support\user_default</Filter>
</ClCompile>
<ClCompile Include="..\support\tinyxml2\tinyxml2.cpp">
<Filter>support\tinyxml2</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\base_nodes\CCAtlasNode.h">
@ -692,9 +697,6 @@
<ClInclude Include="..\support\CCProfiling.h">
<Filter>support</Filter>
</ClInclude>
<ClInclude Include="..\support\CCUserDefault.h">
<Filter>support</Filter>
</ClInclude>
<ClInclude Include="..\support\ccUtils.h">
<Filter>support</Filter>
</ClInclude>
@ -903,9 +905,14 @@
<ClInclude Include="..\platform\win32\CCFileUtilsWin32.h">
<Filter>platform\win32</Filter>
</ClInclude>
<ClInclude Include="..\support\tinyxml2\tinyxml2.h" />
<ClInclude Include="..\support\ccUTF8.h">
<Filter>support</Filter>
</ClInclude>
<ClInclude Include="..\support\user_default\CCUserDefault.h">
<Filter>support\user_default</Filter>
</ClInclude>
<ClInclude Include="..\support\tinyxml2\tinyxml2.h">
<Filter>support\tinyxml2</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -24,7 +24,9 @@ THE SOFTWARE.
#include "CCUserDefault.h"
#include "platform/CCCommon.h"
#include "platform/CCFileUtils.h"
#include "tinyxml2/tinyxml2.h"
#include "../tinyxml2/tinyxml2.h"
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_PLATFORM != CC_PLATFORM_ANDROID)
// root name of xml
#define USERDEFAULT_ROOT_NAME "userDefaultRoot"
@ -441,3 +443,5 @@ void CCUserDefault::flush()
}
NS_CC_END
#endif // (CC_TARGET_PLATFORM != CC_PLATFORM_IOS && CC_PLATFORM != CC_PLATFORM_ANDROID)

View File

@ -0,0 +1,185 @@
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#import "CCUserDefault.h"
#import <string>
#import <UIKit/UIKit.h>
#import "platform/CCPlatformConfig.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
NS_CC_BEGIN
using namespace std;
/**
* implements of CCUserDefault
*/
CCUserDefault* CCUserDefault::m_spUserDefault = 0;
string CCUserDefault::m_sFilePath = string("");
bool CCUserDefault::m_sbIsFilePathInitialized = false;
/**
* If the user invoke delete CCUserDefault::sharedUserDefault(), should set m_spUserDefault
* to null to avoid error when he invoke CCUserDefault::sharedUserDefault() later.
*/
CCUserDefault::~CCUserDefault()
{
CC_SAFE_DELETE(m_spUserDefault);
m_spUserDefault = NULL;
}
CCUserDefault::CCUserDefault()
{
m_spUserDefault = NULL;
}
void CCUserDefault::purgeSharedUserDefault()
{
m_spUserDefault = NULL;
}
bool CCUserDefault::getBoolForKey(const char* pKey)
{
return getBoolForKey(pKey, false);
}
bool CCUserDefault::getBoolForKey(const char* pKey, bool defaultValue)
{
return[[NSUserDefaults standardUserDefaults] boolForKey:[NSString stringWithUTF8String:pKey]];
}
int CCUserDefault::getIntegerForKey(const char* pKey)
{
return getIntegerForKey(pKey, 0);
}
int CCUserDefault::getIntegerForKey(const char* pKey, int defaultValue)
{
return [[NSUserDefaults standardUserDefaults] integerForKey: [NSString stringWithUTF8String:pKey]];
}
float CCUserDefault::getFloatForKey(const char* pKey)
{
return getFloatForKey(pKey, 0);
}
float CCUserDefault::getFloatForKey(const char* pKey, float defaultValue)
{
return [[NSUserDefaults standardUserDefaults] floatForKey: [NSString stringWithUTF8String:pKey]];
}
double CCUserDefault::getDoubleForKey(const char* pKey)
{
return [[NSUserDefaults standardUserDefaults] doubleForKey: [NSString stringWithUTF8String:pKey]];
}
double CCUserDefault::getDoubleForKey(const char* pKey, double defaultValue)
{
return getDoubleForKey(pKey, 0);
}
std::string CCUserDefault::getStringForKey(const char* pKey)
{
return getStringForKey(pKey, "");
}
string CCUserDefault::getStringForKey(const char* pKey, const std::string & defaultValue)
{
NSString *str = [[NSUserDefaults standardUserDefaults] stringForKey:[NSString stringWithUTF8String:pKey]];
if (! str)
{
return defaultValue;
}
else
{
return [str UTF8String];
}
}
void CCUserDefault::setBoolForKey(const char* pKey, bool value)
{
[[NSUserDefaults standardUserDefaults] setBool:value forKey:[NSString stringWithUTF8String:pKey]];
}
void CCUserDefault::setIntegerForKey(const char* pKey, int value)
{
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:[NSString stringWithUTF8String:pKey]];
}
void CCUserDefault::setFloatForKey(const char* pKey, float value)
{
[[NSUserDefaults standardUserDefaults] setFloat:value forKey:[NSString stringWithUTF8String:pKey]];
}
void CCUserDefault::setDoubleForKey(const char* pKey, double value)
{
[[NSUserDefaults standardUserDefaults] setDouble:value forKey:[NSString stringWithUTF8String:pKey]];
}
void CCUserDefault::setStringForKey(const char* pKey, const std::string & value)
{
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithUTF8String:value.c_str()] forKey:[NSString stringWithUTF8String:pKey]];
}
CCUserDefault* CCUserDefault::sharedUserDefault()
{
if (! m_spUserDefault)
{
m_spUserDefault = new CCUserDefault();
}
return m_spUserDefault;
}
bool CCUserDefault::isXMLFileExist()
{
return false;
}
void CCUserDefault::initXMLFilePath()
{
}
// create new xml file
bool CCUserDefault::createXMLFile()
{
return false;
}
const string& CCUserDefault::getXMLFilePath()
{
return m_sFilePath;
}
void CCUserDefault::flush()
{
}
NS_CC_END
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

View File

@ -0,0 +1,179 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCUserDefault.h"
#include "platform/CCPlatformConfig.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include "platform/android/jni/JniHelper.h"
// root name of xml
#define USERDEFAULT_ROOT_NAME "userDefaultRoot"
#define XML_FILE_NAME "UserDefault.xml"
using namespace std;
NS_CC_BEGIN
/**
* implements of CCUserDefault
*/
CCUserDefault* CCUserDefault::m_spUserDefault = 0;
string CCUserDefault::m_sFilePath = string("");
bool CCUserDefault::m_sbIsFilePathInitialized = false;
/**
* If the user invoke delete CCUserDefault::sharedUserDefault(), should set m_spUserDefault
* to null to avoid error when he invoke CCUserDefault::sharedUserDefault() later.
*/
CCUserDefault::~CCUserDefault()
{
CC_SAFE_DELETE(m_spUserDefault);
m_spUserDefault = NULL;
}
CCUserDefault::CCUserDefault()
{
m_spUserDefault = NULL;
}
void CCUserDefault::purgeSharedUserDefault()
{
m_spUserDefault = NULL;
}
bool CCUserDefault::getBoolForKey(const char* pKey)
{
return getBoolForKey(pKey, false);
}
bool CCUserDefault::getBoolForKey(const char* pKey, bool defaultValue)
{
}
int CCUserDefault::getIntegerForKey(const char* pKey)
{
return getIntegerForKey(pKey, 0);
}
int CCUserDefault::getIntegerForKey(const char* pKey, int defaultValue)
{
}
float CCUserDefault::getFloatForKey(const char* pKey)
{
return getFloatForKey(pKey, 0.0f);
}
float CCUserDefault::getFloatForKey(const char* pKey, float defaultValue)
{
float ret = (float)getDoubleForKey(pKey, (double)defaultValue);
return ret;
}
double CCUserDefault::getDoubleForKey(const char* pKey)
{
return getDoubleForKey(pKey, 0.0);
}
double CCUserDefault::getDoubleForKey(const char* pKey, double defaultValue)
{
}
std::string CCUserDefault::getStringForKey(const char* pKey)
{
return getStringForKey(pKey, "");
}
string CCUserDefault::getStringForKey(const char* pKey, const std::string & defaultValue)
{
}
void CCUserDefault::setBoolForKey(const char* pKey, bool value)
{
}
void CCUserDefault::setIntegerForKey(const char* pKey, int value)
{
}
void CCUserDefault::setFloatForKey(const char* pKey, float value)
{
}
void CCUserDefault::setDoubleForKey(const char* pKey, double value)
{
}
void CCUserDefault::setStringForKey(const char* pKey, const std::string & value)
{
}
CCUserDefault* CCUserDefault::sharedUserDefault()
{
if (! m_spUserDefault)
{
m_spUserDefault = new CCUserDefault();
}
return m_spUserDefault;
}
bool CCUserDefault::isXMLFileExist()
{
return false;
}
void CCUserDefault::initXMLFilePath()
{
}
// create new xml file
bool CCUserDefault::createXMLFile()
{
return false;
}
const string& CCUserDefault::getXMLFilePath()
{
return m_sFilePath;
}
void CCUserDefault::flush()
{
}
NS_CC_END
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

View File

@ -1,6 +1,6 @@
#include "CCConfiguration.h"
#include "RenderTextureTest.h"
#include "testBasic.h"
#include "../testBasic.h"
// Test #1 by Jason Booth (slipster216)
// Test #3 by David Deaco (ddeaco)

View File

@ -1 +1 @@
102d501a7f1d29f475195b763dba313301ecdf00
86979b53e58b440028511140775967bd9e65d985

View File

@ -2,28 +2,28 @@ pushd ../../
echo "generating libcocos2dx"
mkdir -p template/xcode4/lib_cocos2dx.xctemplate
python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 blackberry linux marmalade CCImage.cpp CCThread.cpp proj.ios CCImageCommon_cpp.h Android.mk mac" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist
python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 nacl blackberry linux marmalade CCImage.cpp CCThread.cpp proj.ios CCImageCommon_cpp.h Android.mk mac CCUserDefault.cpp CCUserDefaultAndroid.cpp" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist
echo "generating libcocosdenshion"
mkdir -p template/xcode4/lib_cocosdenshion.xctemplate
python ./tools/xcode4_template_generator/template_generator.py --directory CocosDenshion --identifier libcocosdenshion --prefix libs --exclude "android win32 blackberry linux marmalade proj.android proj.win32 proj.blackberry proj.linux proj.marmalade third_party Android.mk mac" > ./template/xcode4/lib_cocosdenshion.xctemplate/TemplateInfo.plist
python ./tools/xcode4_template_generator/template_generator.py --directory CocosDenshion --identifier libcocosdenshion --prefix libs --exclude "android win32 blackberry linux marmalade proj.android proj.win32 proj.nacl proj.blackberry proj.linux proj.marmalade third_party Android.mk mac" > ./template/xcode4/lib_cocosdenshion.xctemplate/TemplateInfo.plist
echo "generating libbox2d"
mkdir -p template/xcode4/lib_box2d.xctemplate
pushd external
python ../tools/xcode4_template_generator/template_generator.py --directory Box2D --identifier libbox2d --prefix libs --exclude "proj.android proj.win32 proj.blackberry proj.linux proj.marmalade Android.mk" > ../template/xcode4/lib_box2d.xctemplate/TemplateInfo.plist
python ../tools/xcode4_template_generator/template_generator.py --directory Box2D --identifier libbox2d --prefix libs --exclude "proj.android proj.win32 proj.nacl proj.blackberry proj.linux proj.marmalade Android.mk" > ../template/xcode4/lib_box2d.xctemplate/TemplateInfo.plist
popd
echo "generating libchipmunk"
mkdir -p template/xcode4/lib_chipmunk.xctemplate
pushd external
python ../tools/xcode4_template_generator/template_generator.py --directory chipmunk --identifier libchipmunk --prefix libs --exclude "proj.android proj.win32 proj.blackberry proj.linux proj.marmalade Android.mk CMakeFiles Makefile" > ../template/xcode4/lib_chipmunk.xctemplate/TemplateInfo.plist
python ../tools/xcode4_template_generator/template_generator.py --directory chipmunk --identifier libchipmunk --prefix libs --exclude "proj.android proj.nacl proj.win32 proj.blackberry proj.linux proj.marmalade Android.mk CMakeFiles Makefile" > ../template/xcode4/lib_chipmunk.xctemplate/TemplateInfo.plist
popd
echo "generating liblua"
mkdir -p template/xcode4/lib_lua.xctemplate
pushd scripting
python ../tools/xcode4_template_generator/template_generator.py --directory lua --identifier liblua --prefix libs --append ../tools/xcode4_template_generator/template_lua_patch.txt --exclude "proj.android proj.win32 proj.blackberry proj.linux proj.marmalade Makefile CMakeFiles" > ../template/xcode4/lib_lua.xctemplate/TemplateInfo.plist
python ../tools/xcode4_template_generator/template_generator.py --directory lua --identifier liblua --prefix libs --append ../tools/xcode4_template_generator/template_lua_patch.txt --exclude "proj.android proj.win32 proj.blackberry proj.linux proj.nacl proj.marmalade Makefile CMakeFiles" > ../template/xcode4/lib_lua.xctemplate/TemplateInfo.plist
popd
@ -41,7 +41,7 @@ popd
echo "generating libextensions"
python ./tools/xcode4_template_generator/template_generator.py --directory extensions --identifier libextensions --prefix libs --exclude "proj.win32 proj.blackberry proj.linux Android.mk CCEditBoxImplAndroid.cpp CCEditBoxImplAndroid.h" > ./template/xcode4/lib_extensions.xctemplate/TemplateInfo.plist
python ./tools/xcode4_template_generator/template_generator.py --directory extensions --identifier libextensions --prefix libs --exclude "proj.win32 proj.nacl proj.blackberry proj.linux Android.mk CCEditBoxImplAndroid.cpp CCEditBoxImplAndroid.h" > ./template/xcode4/lib_extensions.xctemplate/TemplateInfo.plist
echo "done"