setKeepScreenOn method

This commit is contained in:
Sergey 2014-08-18 16:41:12 +04:00
parent 18cc62d16d
commit bfe6513706
11 changed files with 56 additions and 0 deletions

View File

@ -65,6 +65,8 @@ public:
static void setAccelerometerInterval(float interval);
static Data getTextureDataForText(const char * text, const FontDefinition& textDefinition, TextAlign align, int &width, int &height, bool& hasPremultipliedAlpha);
static void setKeepScreenOn(bool value);
private:
CC_DISALLOW_IMPLICIT_CONSTRUCTORS(Device);

View File

@ -202,6 +202,12 @@ Data Device::getTextureDataForText(const char * text, const FontDefinition& text
return ret;
}
void Device::setKeepScreenOn(bool value)
{
setKeepScreenOnJni(value);
}
NS_CC_END
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID

View File

@ -34,6 +34,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.util.Log;
import android.widget.FrameLayout;
import android.preference.PreferenceManager.OnActivityResultListener;
@ -58,6 +59,16 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
return sContext;
}
public void setKeepScreenOn(boolean value) {
final boolean newValue = value;
runOnUiThread(new Runnable() {
@Override
public void run() {
mGLSurfaceView.setKeepScreenOn(newValue);
}
});
}
protected void onLoadNativeLibraries() {
try {
ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);

View File

@ -167,6 +167,10 @@ public class Cocos2dxHelper {
Cocos2dxHelper.sAccelerometerEnabled = false;
Cocos2dxHelper.sCocos2dxAccelerometer.disable();
}
public static void setKeepScreenOn(boolean value) {
((Cocos2dxActivity)sActivity).setKeepScreenOn(value);
}
public static void preloadBackgroundMusic(final String pPath) {
Cocos2dxHelper.sCocos2dMusic.preloadBackgroundMusic(pPath);

View File

@ -209,6 +209,16 @@ void disableAccelerometerJni() {
}
}
void setKeepScreenOnJni(bool value) {
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setKeepScreenOn", "(Z)V")) {
t.env->CallStaticVoidMethod(t.classID, t.methodID, value);
t.env->DeleteLocalRef(t.classID);
}
}
// functions for UserDefault
bool getBoolForKeyJNI(const char* key, bool defaultValue)
{

View File

@ -39,6 +39,7 @@ extern std::string getFileDirectoryJNI();
extern void enableAccelerometerJni();
extern void disableAccelerometerJni();
extern void setAccelerometerIntervalJni(float interval);
extern void setKeepScreenOnJni(bool value);
// functions for UserDefault
extern bool getBoolForKeyJNI(const char* key, bool defaultValue);
extern int getIntegerForKeyJNI(const char* key, int defaultValue);

View File

@ -477,6 +477,11 @@ Data Device::getTextureDataForText(const char * text, const FontDefinition& text
return ret;
}
void Device::setKeepScreenOn(bool value)
{
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
NS_CC_END
#endif // CC_PLATFORM_IOS

View File

@ -499,6 +499,10 @@ Data Device::getTextureDataForText(const char * text, const FontDefinition& text
return ret;
}
void Device::setKeepScreenOn(bool value)
{
}
NS_CC_END
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_LINUX

View File

@ -247,6 +247,11 @@ Data Device::getTextureDataForText(const char * text, const FontDefinition& text
return ret;
}
void Device::setKeepScreenOn(bool value)
{
}
NS_CC_END
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_MAC

View File

@ -451,6 +451,10 @@ Data Device::getTextureDataForText(const char * text, const FontDefinition& text
return ret;
}
void Device::setKeepScreenOn(bool value)
{
}
NS_CC_END
#endif // CC_TARGET_PLATFORM == CC_PLATFORM_WIN32

View File

@ -163,6 +163,10 @@ Data Device::getTextureDataForText(const char * text, const FontDefinition& text
return ret;
}
void Device::setKeepScreenOn(bool value)
{
}
NS_CC_END
#endif // (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)