mirror of https://github.com/axmolengine/axmol.git
Helper and LocalStorage now use NativeActivity directly
This commit is contained in:
parent
9cefb85bea
commit
4567ab96b8
|
@ -51,11 +51,10 @@ public class Cocos2dxHelper {
|
||||||
private static Cocos2dxMusic sCocos2dMusic;
|
private static Cocos2dxMusic sCocos2dMusic;
|
||||||
private static Cocos2dxSound sCocos2dSound;
|
private static Cocos2dxSound sCocos2dSound;
|
||||||
private static AssetManager sAssetManager;
|
private static AssetManager sAssetManager;
|
||||||
private static Cocos2dxAccelerometer sCocos2dxAccelerometer;
|
|
||||||
private static boolean sAccelerometerEnabled;
|
private static boolean sAccelerometerEnabled;
|
||||||
private static String sPackageName;
|
private static String sPackageName;
|
||||||
private static String sFileDirectory;
|
private static String sFileDirectory;
|
||||||
private static Context sContext = null;
|
private static Activity sActivity = null;
|
||||||
private static Cocos2dxHelperListener sCocos2dxHelperListener;
|
private static Cocos2dxHelperListener sCocos2dxHelperListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +72,7 @@ public class Cocos2dxHelper {
|
||||||
public static void init(final Activity activity) {
|
public static void init(final Activity activity) {
|
||||||
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
final ApplicationInfo applicationInfo = activity.getApplicationInfo();
|
||||||
|
|
||||||
Cocos2dxHelper.sContext = activity;
|
Cocos2dxHelper.sActivity = activity;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get the lib_name from AndroidManifest.xml metadata
|
// Get the lib_name from AndroidManifest.xml metadata
|
||||||
|
@ -95,7 +94,6 @@ public class Cocos2dxHelper {
|
||||||
Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath();
|
Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath();
|
||||||
//Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);
|
//Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir);
|
||||||
|
|
||||||
Cocos2dxHelper.sCocos2dxAccelerometer = new Cocos2dxAccelerometer(activity);
|
|
||||||
Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity);
|
Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity);
|
||||||
Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity);
|
Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity);
|
||||||
Cocos2dxHelper.sAssetManager = activity.getAssets();
|
Cocos2dxHelper.sAssetManager = activity.getAssets();
|
||||||
|
@ -105,6 +103,10 @@ public class Cocos2dxHelper {
|
||||||
Cocos2dxETCLoader.setContext(activity);
|
Cocos2dxETCLoader.setContext(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Activity getActivity() {
|
||||||
|
return sActivity;
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Getter & Setter
|
// Getter & Setter
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
@ -139,21 +141,6 @@ public class Cocos2dxHelper {
|
||||||
return Cocos2dxHelper.sAssetManager;
|
return Cocos2dxHelper.sAssetManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enableAccelerometer() {
|
|
||||||
Cocos2dxHelper.sAccelerometerEnabled = true;
|
|
||||||
Cocos2dxHelper.sCocos2dxAccelerometer.enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void setAccelerometerInterval(float interval) {
|
|
||||||
Cocos2dxHelper.sCocos2dxAccelerometer.setInterval(interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void disableAccelerometer() {
|
|
||||||
Cocos2dxHelper.sAccelerometerEnabled = false;
|
|
||||||
Cocos2dxHelper.sCocos2dxAccelerometer.disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void preloadBackgroundMusic(final String pPath) {
|
public static void preloadBackgroundMusic(final String pPath) {
|
||||||
Cocos2dxHelper.sCocos2dMusic.preloadBackgroundMusic(pPath);
|
Cocos2dxHelper.sCocos2dMusic.preloadBackgroundMusic(pPath);
|
||||||
}
|
}
|
||||||
|
@ -239,18 +226,6 @@ public class Cocos2dxHelper {
|
||||||
Cocos2dxHelper.sCocos2dSound.end();
|
Cocos2dxHelper.sCocos2dSound.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onResume() {
|
|
||||||
if (Cocos2dxHelper.sAccelerometerEnabled) {
|
|
||||||
Cocos2dxHelper.sCocos2dxAccelerometer.enable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void onPause() {
|
|
||||||
if (Cocos2dxHelper.sAccelerometerEnabled) {
|
|
||||||
Cocos2dxHelper.sCocos2dxAccelerometer.disable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void terminateProcess() {
|
public static void terminateProcess() {
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
}
|
}
|
||||||
|
@ -280,10 +255,10 @@ public class Cocos2dxHelper {
|
||||||
|
|
||||||
public static int getDPI()
|
public static int getDPI()
|
||||||
{
|
{
|
||||||
if (sContext != null)
|
if (sActivity != null)
|
||||||
{
|
{
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
DisplayMetrics metrics = new DisplayMetrics();
|
||||||
WindowManager wm = ((Activity)sContext).getWindowManager();
|
WindowManager wm = sActivity.getWindowManager();
|
||||||
if (wm != null)
|
if (wm != null)
|
||||||
{
|
{
|
||||||
Display d = wm.getDefaultDisplay();
|
Display d = wm.getDefaultDisplay();
|
||||||
|
@ -302,47 +277,47 @@ public class Cocos2dxHelper {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
public static boolean getBoolForKey(String key, boolean defaultValue) {
|
public static boolean getBoolForKey(String key, boolean defaultValue) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
return settings.getBoolean(key, defaultValue);
|
return settings.getBoolean(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getIntegerForKey(String key, int defaultValue) {
|
public static int getIntegerForKey(String key, int defaultValue) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
return settings.getInt(key, defaultValue);
|
return settings.getInt(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getFloatForKey(String key, float defaultValue) {
|
public static float getFloatForKey(String key, float defaultValue) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
return settings.getFloat(key, defaultValue);
|
return settings.getFloat(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getDoubleForKey(String key, double defaultValue) {
|
public static double getDoubleForKey(String key, double defaultValue) {
|
||||||
// SharedPreferences doesn't support saving double value
|
// SharedPreferences doesn't support saving double value
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
return settings.getFloat(key, (float)defaultValue);
|
return settings.getFloat(key, (float)defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getStringForKey(String key, String defaultValue) {
|
public static String getStringForKey(String key, String defaultValue) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
return settings.getString(key, defaultValue);
|
return settings.getString(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBoolForKey(String key, boolean value) {
|
public static void setBoolForKey(String key, boolean value) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putBoolean(key, value);
|
editor.putBoolean(key, value);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setIntegerForKey(String key, int value) {
|
public static void setIntegerForKey(String key, int value) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putInt(key, value);
|
editor.putInt(key, value);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFloatForKey(String key, float value) {
|
public static void setFloatForKey(String key, float value) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putFloat(key, value);
|
editor.putFloat(key, value);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
@ -350,14 +325,14 @@ public class Cocos2dxHelper {
|
||||||
|
|
||||||
public static void setDoubleForKey(String key, double value) {
|
public static void setDoubleForKey(String key, double value) {
|
||||||
// SharedPreferences doesn't support recording double value
|
// SharedPreferences doesn't support recording double value
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putFloat(key, (float)value);
|
editor.putFloat(key, (float)value);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setStringForKey(String key, String value) {
|
public static void setStringForKey(String key, String value) {
|
||||||
SharedPreferences settings = ((Activity)sContext).getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
SharedPreferences settings = sActivity.getSharedPreferences(Cocos2dxHelper.PREFS_NAME, 0);
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
editor.putString(key, value);
|
editor.putString(key, value);
|
||||||
editor.commit();
|
editor.commit();
|
||||||
|
|
|
@ -46,10 +46,10 @@ public class Cocos2dxLocalStorage {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean init(String dbName, String tableName) {
|
public static boolean init(String dbName, String tableName) {
|
||||||
if (Cocos2dxActivity.getContext() != null) {
|
if (Cocos2dxHelper.getActivity() != null) {
|
||||||
DATABASE_NAME = dbName;
|
DATABASE_NAME = dbName;
|
||||||
TABLE_NAME = tableName;
|
TABLE_NAME = tableName;
|
||||||
mDatabaseOpenHelper = new DBOpenHelper(Cocos2dxActivity.getContext());
|
mDatabaseOpenHelper = new DBOpenHelper(Cocos2dxHelper.getActivity());
|
||||||
mDatabase = mDatabaseOpenHelper.getWritableDatabase();
|
mDatabase = mDatabaseOpenHelper.getWritableDatabase();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue