Merge branch 'java-style' of https://github.com/minggo/cocos2d-x into v3-game

This commit is contained in:
Wenhai Lin 2014-12-11 10:05:33 +08:00
commit 6bb91c35f6
13 changed files with 201 additions and 191 deletions

View File

@ -55,8 +55,8 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
// Constructors // Constructors
// =========================================================== // ===========================================================
public Cocos2dxAccelerometer(final Context pContext) { public Cocos2dxAccelerometer(final Context context) {
this.mContext = pContext; this.mContext = context;
this.mSensorManager = (SensorManager) this.mContext.getSystemService(Context.SENSOR_SERVICE); this.mSensorManager = (SensorManager) this.mContext.getSystemService(Context.SENSOR_SERVICE);
this.mAccelerometer = this.mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); this.mAccelerometer = this.mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
@ -92,14 +92,14 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
// =========================================================== // ===========================================================
@Override @Override
public void onSensorChanged(final SensorEvent pSensorEvent) { public void onSensorChanged(final SensorEvent sensorEvent) {
if (pSensorEvent.sensor.getType() != Sensor.TYPE_ACCELEROMETER) { if (sensorEvent.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
return; return;
} }
float x = pSensorEvent.values[0]; float x = sensorEvent.values[0];
float y = pSensorEvent.values[1]; float y = sensorEvent.values[1];
final float z = pSensorEvent.values[2]; final float z = sensorEvent.values[2];
/* /*
* Because the axes are not swapped when the device's screen orientation * Because the axes are not swapped when the device's screen orientation
@ -118,17 +118,17 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
y = -tmp; y = -tmp;
} }
Cocos2dxGLSurfaceView.queueAccelerometer(x,y,z,pSensorEvent.timestamp); Cocos2dxGLSurfaceView.queueAccelerometer(x,y,z,sensorEvent.timestamp);
/* /*
if(BuildConfig.DEBUG) { if(BuildConfig.DEBUG) {
Log.d(TAG, "x = " + pSensorEvent.values[0] + " y = " + pSensorEvent.values[1] + " z = " + pSensorEvent.values[2]); Log.d(TAG, "x = " + sensorEvent.values[0] + " y = " + sensorEvent.values[1] + " z = " + pSensorEvent.values[2]);
} }
*/ */
} }
@Override @Override
public void onAccuracyChanged(final Sensor pSensor, final int pAccuracy) { public void onAccuracyChanged(final Sensor sensor, final int accuracy) {
} }
// =========================================================== // ===========================================================
@ -136,7 +136,7 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
// Native method called from Cocos2dxGLSurfaceView (To be in the same thread) // Native method called from Cocos2dxGLSurfaceView (To be in the same thread)
// =========================================================== // ===========================================================
public static native void onSensorChanged(final float pX, final float pY, final float pZ, final long pTimestamp); public static native void onSensorChanged(final float x, final float y, final float z, final long timestamp);
// =========================================================== // ===========================================================
// Inner and Anonymous Classes // Inner and Anonymous Classes

View File

@ -56,9 +56,9 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
// Fields // Fields
// =========================================================== // ===========================================================
private Cocos2dxGLSurfaceView mGLSurfaceView; private Cocos2dxGLSurfaceView mGLSurfaceView = null;
private int[] glContextAttrs; private int[] mGLContextAttrs = null;
private Cocos2dxHandler mHandler; private Cocos2dxHandler mHandler = null;
private static Cocos2dxActivity sContext = null; private static Cocos2dxActivity sContext = null;
private Cocos2dxVideoHelper mVideoHelper = null; private Cocos2dxVideoHelper mVideoHelper = null;
private Cocos2dxWebViewHelper mWebViewHelper = null; private Cocos2dxWebViewHelper mWebViewHelper = null;
@ -103,7 +103,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
Cocos2dxHelper.init(this); Cocos2dxHelper.init(this);
this.glContextAttrs = getGLContextAttrs(); this.mGLContextAttrs = getGLContextAttrs();
this.init(); this.init();
if (mVideoHelper == null) { if (mVideoHelper == null) {
@ -222,7 +222,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
public Cocos2dxGLSurfaceView onCreateView() { public Cocos2dxGLSurfaceView onCreateView() {
Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
//this line is need on some device if we specify an alpha bits //this line is need on some device if we specify an alpha bits
if(this.glContextAttrs[3] > 0) glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT); if(this.mGLContextAttrs[3] > 0) glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
class cocos2dEGLConfigChooser implements GLSurfaceView.EGLConfigChooser class cocos2dEGLConfigChooser implements GLSurfaceView.EGLConfigChooser
{ {
@ -344,7 +344,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
} }
} }
cocos2dEGLConfigChooser chooser = new cocos2dEGLConfigChooser(this.glContextAttrs); cocos2dEGLConfigChooser chooser = new cocos2dEGLConfigChooser(this.mGLContextAttrs);
glSurfaceView.setEGLConfigChooser(chooser); glSurfaceView.setEGLConfigChooser(chooser);
return glSurfaceView; return glSurfaceView;

View File

@ -58,7 +58,7 @@ public class Cocos2dxBitmap {
// Fields // Fields
// =========================================================== // ===========================================================
private static Context _context; private static Context sContext;
// =========================================================== // ===========================================================
// Constructors // Constructors
@ -69,7 +69,7 @@ public class Cocos2dxBitmap {
// =========================================================== // ===========================================================
public static void setContext(final Context context) { public static void setContext(final Context context) {
Cocos2dxBitmap._context = context; Cocos2dxBitmap.sContext = context;
} }
// =========================================================== // ===========================================================
@ -84,20 +84,19 @@ public class Cocos2dxBitmap {
final int height, final byte[] pixels); final int height, final byte[] pixels);
/** /**
* @param pWidth * @param width
* the width to draw, it can be 0 * the width to draw, it can be 0
* @param pHeight * @param height
* the height to draw, it can be 0 * the height to draw, it can be 0
*/ */
public static void createTextBitmap(String string, final String fontName, public static void createTextBitmap(String string, final String fontName,
final int fontSize, final int alignment, final int width, final int fontSize, final int alignment, final int width,
final int height) { final int height) {
//
createTextBitmapShadowStroke( string, fontName, fontSize, 1.0f, 1.0f, 1.0f, // text font and color createTextBitmapShadowStroke( string, fontName, fontSize, 1.0f, 1.0f, 1.0f, // text font and color
alignment, width, height, // alignment and size alignment, width, height, // alignment and size
false, 0.0f, 0.0f, 0.0f, 0.0f, // no shadow false, 0.0f, 0.0f, 0.0f, 0.0f, // no shadow
false, 1.0f, 1.0f, 1.0f, 1.0f); // no stroke false, 1.0f, 1.0f, 1.0f, 1.0f); // no stroke
} }
@ -113,13 +112,12 @@ public class Cocos2dxBitmap {
string = Cocos2dxBitmap.refactorString(string); string = Cocos2dxBitmap.refactorString(string);
final Paint paint = Cocos2dxBitmap.newPaint(fontName, fontSize, horizontalAlignment); final Paint paint = Cocos2dxBitmap.newPaint(fontName, fontSize, horizontalAlignment);
/**
* if the first word width less than designed width,It means no words to show // if the first word width less than designed width, it means no words to show
*/
if(0 != width) if(0 != width)
{ {
final int firstWordWidth = (int) Math.ceil(paint.measureText(string, 0,1)); final int firstWordWidth = (int) Math.ceil(paint.measureText(string, 0,1));
if ( firstWordWidth > width) if (firstWordWidth > width)
{ {
Log.w("createTextBitmapShadowStroke warning:","the input width is less than the width of the pString's first word\n"); Log.w("createTextBitmapShadowStroke warning:","the input width is less than the width of the pString's first word\n");
return false; return false;
@ -151,7 +149,7 @@ public class Cocos2dxBitmap {
final Canvas canvas = new Canvas(bitmap); final Canvas canvas = new Canvas(bitmap);
/* Draw string. */ // Draw string.
final FontMetricsInt fontMetricsInt = paint.getFontMetricsInt(); final FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
// draw again with stroke on if needed // draw again with stroke on if needed
@ -204,17 +202,17 @@ public class Cocos2dxBitmap {
paint.setTextSize(fontSize); paint.setTextSize(fontSize);
paint.setAntiAlias(true); paint.setAntiAlias(true);
/* Set type face for paint, now it support .ttf file. */ // Set type face for paint, now it support .ttf file.
if (fontName.endsWith(".ttf")) { if (fontName.endsWith(".ttf")) {
try { try {
final Typeface typeFace = Cocos2dxTypefaces.get( final Typeface typeFace = Cocos2dxTypefaces.get(
Cocos2dxBitmap._context, fontName); Cocos2dxBitmap.sContext, fontName);
paint.setTypeface(typeFace); paint.setTypeface(typeFace);
} catch (final Exception e) { } catch (final Exception e) {
Log.e("Cocos2dxBitmap", "error to create ttf type face: " Log.e("Cocos2dxBitmap", "error to create ttf type face: "
+ fontName); + fontName);
/* The file may not find, use system font. */ // The file may not find, use system font.
paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL)); paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL));
} }
} else { } else {
@ -249,7 +247,7 @@ public class Cocos2dxBitmap {
if (width != 0) { if (width != 0) {
maxContentWidth = width; maxContentWidth = width;
} else { } else {
/* Compute the max width. */ // Compute the max width.
int temp = 0; int temp = 0;
for (final String line : lines) { for (final String line : lines) {
temp = (int) Math.ceil(paint.measureText(line, 0, temp = (int) Math.ceil(paint.measureText(line, 0,
@ -335,13 +333,13 @@ public class Cocos2dxBitmap {
strList.add(line); strList.add(line);
} }
/* Should not exceed the max height. */ // Should not exceed the max height.
if (maxLines > 0 && strList.size() >= maxLines) { if (maxLines > 0 && strList.size() >= maxLines) {
break; break;
} }
} }
/* Remove exceeding lines. */ // Remove exceeding lines.
if (maxLines > 0 && strList.size() > maxLines) { if (maxLines > 0 && strList.size() > maxLines) {
while (strList.size() > maxLines) { while (strList.size() > maxLines) {
strList.removeLast(); strList.removeLast();
@ -366,13 +364,13 @@ public class Cocos2dxBitmap {
} }
private static LinkedList<String> divideStringWithMaxWidth( private static LinkedList<String> divideStringWithMaxWidth(
final String string, final int maxWidth, final Paint paint) { final String string, final int maxWidth, final Paint paint) {
final int charLength = string.length(); final int charLength = string.length();
int start = 0; int start = 0;
int tempWidth = 0; int tempWidth = 0;
final LinkedList<String> strList = new LinkedList<String>(); final LinkedList<String> strList = new LinkedList<String>();
/* Break a String into String[] by the width & should wrap the word. */ // Break a String into String[] by the width & should wrap the word.
for (int i = 1; i <= charLength; ++i) { for (int i = 1; i <= charLength; ++i) {
tempWidth = (int) Math.ceil(paint.measureText(string, start, tempWidth = (int) Math.ceil(paint.measureText(string, start,
i)); i));
@ -381,21 +379,21 @@ public class Cocos2dxBitmap {
.lastIndexOf(" "); .lastIndexOf(" ");
if (lastIndexOfSpace != -1 && lastIndexOfSpace > start) { if (lastIndexOfSpace != -1 && lastIndexOfSpace > start) {
/* Should wrap the word. */ // Should wrap the word.
strList.add(string.substring(start, lastIndexOfSpace)); strList.add(string.substring(start, lastIndexOfSpace));
i = lastIndexOfSpace + 1; // skip space i = lastIndexOfSpace + 1; // skip space
} else { } else {
/* Should not exceed the width. */ // Should not exceed the width.
if (tempWidth > maxWidth) { if (tempWidth > maxWidth) {
strList.add(string.substring(start, i - 1)); strList.add(string.substring(start, i - 1));
/* Compute from previous char. */ // Compute from previous char.
--i; --i;
} else { } else {
strList.add(string.substring(start, i)); strList.add(string.substring(start, i));
} }
} }
/* Remove spaces at the beginning of a new line. */ // Remove spaces at the beginning of a new line.
while (i < charLength && string.charAt(i) == ' ') { while (i < charLength && string.charAt(i) == ' ') {
++i; ++i;
} }
@ -404,7 +402,7 @@ public class Cocos2dxBitmap {
} }
} }
/* Add the last chars. */ // Add the last chars.
if (start < charLength) { if (start < charLength) {
strList.add(string.substring(start)); strList.add(string.substring(start));
} }
@ -413,7 +411,7 @@ public class Cocos2dxBitmap {
} }
private static String refactorString(final String string) { private static String refactorString(final String string) {
/* Avoid error when content is "". */ // Avoid error when content is "".
if (string.compareTo("") == 0) { if (string.compareTo("") == 0) {
return " "; return " ";
} }

View File

@ -275,7 +275,7 @@ public class Cocos2dxEditBoxDialog extends Dialog {
this.mInputEditText.setOnEditorActionListener(new OnEditorActionListener() { this.mInputEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override @Override
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) { public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
/* If user didn't set keyboard type, this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP'. */ // If user didn't set keyboard type, this callback will be invoked twice with 'KeyEvent.ACTION_DOWN' and 'KeyEvent.ACTION_UP'.
if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null && event.getAction() == KeyEvent.ACTION_DOWN)) { if (actionId != EditorInfo.IME_NULL || (actionId == EditorInfo.IME_NULL && event != null && event.getAction() == KeyEvent.ACTION_DOWN)) {
Cocos2dxHelper.setEditTextDialogResult(Cocos2dxEditBoxDialog.this.mInputEditText.getText().toString()); Cocos2dxHelper.setEditTextDialogResult(Cocos2dxEditBoxDialog.this.mInputEditText.getText().toString());
Cocos2dxEditBoxDialog.this.closeKeyboard(); Cocos2dxEditBoxDialog.this.closeKeyboard();

View File

@ -72,7 +72,7 @@ public class Cocos2dxEditText extends EditText {
public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) { public boolean onKeyDown(final int pKeyCode, final KeyEvent pKeyEvent) {
super.onKeyDown(pKeyCode, pKeyEvent); super.onKeyDown(pKeyCode, pKeyEvent);
/* Let GlSurfaceView get focus if back key is input. */ // Let GlSurfaceView get focus if back key is input.
if (pKeyCode == KeyEvent.KEYCODE_BACK) { if (pKeyCode == KeyEvent.KEYCODE_BACK) {
this.mCocos2dxGLSurfaceView.requestFocus(); this.mCocos2dxGLSurfaceView.requestFocus();
} }

View File

@ -47,17 +47,17 @@ public class Cocos2dxMusic {
private MediaPlayer mBackgroundMediaPlayer; private MediaPlayer mBackgroundMediaPlayer;
private float mLeftVolume; private float mLeftVolume;
private float mRightVolume; private float mRightVolume;
private boolean mPaused;// whether music is paused state. private boolean mPaused; // whether music is paused state.
private boolean mIsLoop = false; private boolean mIsLoop = false;
private boolean mManualPaused = false;// whether music is paused manually before the program is switched to the background. private boolean mManualPaused = false; // whether music is paused manually before the program is switched to the background.
private String mCurrentPath; private String mCurrentPath;
// =========================================================== // ===========================================================
// Constructors // Constructors
// =========================================================== // ===========================================================
public Cocos2dxMusic(final Context pContext) { public Cocos2dxMusic(final Context context) {
this.mContext = pContext; this.mContext = context;
this.initData(); this.initData();
} }
@ -74,8 +74,8 @@ public class Cocos2dxMusic {
// Methods // Methods
// =========================================================== // ===========================================================
public void preloadBackgroundMusic(final String pPath) { public void preloadBackgroundMusic(final String path) {
if ((this.mCurrentPath == null) || (!this.mCurrentPath.equals(pPath))) { if ((this.mCurrentPath == null) || (!this.mCurrentPath.equals(path))) {
// preload new background music // preload new background music
// release old resource and create a new one // release old resource and create a new one
@ -83,10 +83,10 @@ public class Cocos2dxMusic {
this.mBackgroundMediaPlayer.release(); this.mBackgroundMediaPlayer.release();
} }
this.mBackgroundMediaPlayer = this.createMediaplayer(pPath); this.mBackgroundMediaPlayer = this.createMediaplayer(path);
// record the path // record the path
this.mCurrentPath = pPath; this.mCurrentPath = path;
} }
} }
@ -136,8 +136,11 @@ public class Cocos2dxMusic {
if (this.mBackgroundMediaPlayer != null) { if (this.mBackgroundMediaPlayer != null) {
mBackgroundMediaPlayer.release(); mBackgroundMediaPlayer.release();
mBackgroundMediaPlayer = createMediaplayer(mCurrentPath); mBackgroundMediaPlayer = createMediaplayer(mCurrentPath);
// should set the state, if not, the following sequence will be error
// play -> pause -> stop -> resume /**
* should set the state, if not, the following sequence will be error
* play -> pause -> stop -> resume
*/
this.mPaused = false; this.mPaused = false;
} }
} }
@ -192,16 +195,16 @@ public class Cocos2dxMusic {
} }
} }
public void setBackgroundVolume(float pVolume) { public void setBackgroundVolume(float volume) {
if (pVolume < 0.0f) { if (volume < 0.0f) {
pVolume = 0.0f; volume = 0.0f;
} }
if (pVolume > 1.0f) { if (volume > 1.0f) {
pVolume = 1.0f; volume = 1.0f;
} }
this.mLeftVolume = this.mRightVolume = pVolume; this.mLeftVolume = this.mRightVolume = volume;
if (this.mBackgroundMediaPlayer != null) { if (this.mBackgroundMediaPlayer != null) {
this.mBackgroundMediaPlayer.setVolume(this.mLeftVolume, this.mRightVolume); this.mBackgroundMediaPlayer.setVolume(this.mLeftVolume, this.mRightVolume);
} }
@ -238,16 +241,16 @@ public class Cocos2dxMusic {
* the pPath relative to assets * the pPath relative to assets
* @return * @return
*/ */
private MediaPlayer createMediaplayer(final String pPath) { private MediaPlayer createMediaplayer(final String path) {
MediaPlayer mediaPlayer = new MediaPlayer(); MediaPlayer mediaPlayer = new MediaPlayer();
try { try {
if (pPath.startsWith("/")) { if (path.startsWith("/")) {
final FileInputStream fis = new FileInputStream(pPath); final FileInputStream fis = new FileInputStream(path);
mediaPlayer.setDataSource(fis.getFD()); mediaPlayer.setDataSource(fis.getFD());
fis.close(); fis.close();
} else { } else {
final AssetFileDescriptor assetFileDescritor = this.mContext.getAssets().openFd(pPath); final AssetFileDescriptor assetFileDescritor = this.mContext.getAssets().openFd(path);
mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(), assetFileDescritor.getStartOffset(), assetFileDescritor.getLength()); mediaPlayer.setDataSource(assetFileDescritor.getFileDescriptor(), assetFileDescritor.getStartOffset(), assetFileDescritor.getLength());
} }

View File

@ -56,13 +56,13 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
// Getter & Setter // Getter & Setter
// =========================================================== // ===========================================================
public static void setAnimationInterval(final double pAnimationInterval) { public static void setAnimationInterval(final double animationInterval) {
Cocos2dxRenderer.sAnimationInterval = (long) (pAnimationInterval * Cocos2dxRenderer.NANOSECONDSPERSECOND); Cocos2dxRenderer.sAnimationInterval = (long) (animationInterval * Cocos2dxRenderer.NANOSECONDSPERSECOND);
} }
public void setScreenWidthAndHeight(final int pSurfaceWidth, final int pSurfaceHeight) { public void setScreenWidthAndHeight(final int surfaceWidth, final int surfaceHeight) {
this.mScreenWidth = pSurfaceWidth; this.mScreenWidth = surfaceWidth;
this.mScreenHeight = pSurfaceHeight; this.mScreenHeight = surfaceHeight;
} }
// =========================================================== // ===========================================================
@ -70,15 +70,15 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
// =========================================================== // ===========================================================
@Override @Override
public void onSurfaceCreated(final GL10 pGL10, final EGLConfig pEGLConfig) { public void onSurfaceCreated(final GL10 GL10, final EGLConfig EGLConfig) {
Cocos2dxRenderer.nativeInit(this.mScreenWidth, this.mScreenHeight); Cocos2dxRenderer.nativeInit(this.mScreenWidth, this.mScreenHeight);
this.mLastTickInNanoSeconds = System.nanoTime(); this.mLastTickInNanoSeconds = System.nanoTime();
mNativeInitCompleted = true; mNativeInitCompleted = true;
} }
@Override @Override
public void onSurfaceChanged(final GL10 pGL10, final int pWidth, final int pHeight) { public void onSurfaceChanged(final GL10 GL10, final int width, final int height) {
Cocos2dxRenderer.nativeOnSurfaceChanged(pWidth, pHeight); Cocos2dxRenderer.nativeOnSurfaceChanged(width, height);
} }
@Override @Override
@ -111,42 +111,44 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
// Methods // Methods
// =========================================================== // ===========================================================
private static native void nativeTouchesBegin(final int pID, final float pX, final float pY); private static native void nativeTouchesBegin(final int id, final float x, final float y);
private static native void nativeTouchesEnd(final int pID, final float pX, final float pY); private static native void nativeTouchesEnd(final int id, final float x, final float y);
private static native void nativeTouchesMove(final int[] pIDs, final float[] pXs, final float[] pYs); private static native void nativeTouchesMove(final int[] ids, final float[] xs, final float[] ys);
private static native void nativeTouchesCancel(final int[] pIDs, final float[] pXs, final float[] pYs); private static native void nativeTouchesCancel(final int[] ids, final float[] xs, final float[] ys);
private static native boolean nativeKeyDown(final int pKeyCode); private static native boolean nativeKeyDown(final int keyCode);
private static native void nativeRender(); private static native void nativeRender();
private static native void nativeInit(final int pWidth, final int pHeight); private static native void nativeInit(final int width, final int height);
private static native void nativeOnSurfaceChanged(final int pWidth, final int pHeight); private static native void nativeOnSurfaceChanged(final int width, final int height);
private static native void nativeOnPause(); private static native void nativeOnPause();
private static native void nativeOnResume(); private static native void nativeOnResume();
public void handleActionDown(final int pID, final float pX, final float pY) { public void handleActionDown(final int id, final float x, final float y) {
Cocos2dxRenderer.nativeTouchesBegin(pID, pX, pY); Cocos2dxRenderer.nativeTouchesBegin(id, x, y);
} }
public void handleActionUp(final int pID, final float pX, final float pY) { public void handleActionUp(final int id, final float x, final float y) {
Cocos2dxRenderer.nativeTouchesEnd(pID, pX, pY); Cocos2dxRenderer.nativeTouchesEnd(id, x, y);
} }
public void handleActionCancel(final int[] pIDs, final float[] pXs, final float[] pYs) { public void handleActionCancel(final int[] ids, final float[] xs, final float[] ys) {
Cocos2dxRenderer.nativeTouchesCancel(pIDs, pXs, pYs); Cocos2dxRenderer.nativeTouchesCancel(ids, xs, ys);
} }
public void handleActionMove(final int[] pIDs, final float[] pXs, final float[] pYs) { public void handleActionMove(final int[] ids, final float[] xs, final float[] ys) {
Cocos2dxRenderer.nativeTouchesMove(pIDs, pXs, pYs); Cocos2dxRenderer.nativeTouchesMove(ids, xs, ys);
} }
public void handleKeyDown(final int pKeyCode) { public void handleKeyDown(final int keyCode) {
Cocos2dxRenderer.nativeKeyDown(pKeyCode); Cocos2dxRenderer.nativeKeyDown(keyCode);
} }
public void handleOnPause() { public void handleOnPause() {
// onPause may be invoked before onSurfaceCreated /**
// and engine will be initialized correctly after * onPause may be invoked before onSurfaceCreated,
// onSurfaceCreated is invoked, can not invoke any * and engine will be initialized correctly after
// native methed before onSurfaceCreated is invoked * onSurfaceCreated is invoked. Can not invoke any
* native method before onSurfaceCreated is invoked
*/
if (! mNativeInitCompleted) if (! mNativeInitCompleted)
return; return;
@ -159,12 +161,12 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
Cocos2dxRenderer.nativeOnResume(); Cocos2dxRenderer.nativeOnResume();
} }
private static native void nativeInsertText(final String pText); private static native void nativeInsertText(final String text);
private static native void nativeDeleteBackward(); private static native void nativeDeleteBackward();
private static native String nativeGetContentText(); private static native String nativeGetContentText();
public void handleInsertText(final String pText) { public void handleInsertText(final String text) {
Cocos2dxRenderer.nativeInsertText(pText); Cocos2dxRenderer.nativeInsertText(text);
} }
public void handleDeleteBackward() { public void handleDeleteBackward() {

View File

@ -77,8 +77,8 @@ public class Cocos2dxSound {
// Constructors // Constructors
// =========================================================== // ===========================================================
public Cocos2dxSound(final Context pContext) { public Cocos2dxSound(final Context context) {
this.mContext = pContext; this.mContext = context;
this.initData(); this.initData();
} }
@ -111,50 +111,50 @@ public class Cocos2dxSound {
// Methods // Methods
// =========================================================== // ===========================================================
public int preloadEffect(final String pPath) { public int preloadEffect(final String path) {
Integer soundID = this.mPathSoundIDMap.get(pPath); Integer soundID = this.mPathSoundIDMap.get(path);
if (soundID == null) { if (soundID == null) {
soundID = this.createSoundIDFromAsset(pPath); soundID = this.createSoundIDFromAsset(path);
// save value just in case if file is really loaded // save value just in case if file is really loaded
if (soundID != Cocos2dxSound.INVALID_SOUND_ID) { if (soundID != Cocos2dxSound.INVALID_SOUND_ID) {
this.mPathSoundIDMap.put(pPath, soundID); this.mPathSoundIDMap.put(path, soundID);
} }
} }
return soundID; return soundID;
} }
public void unloadEffect(final String pPath) { public void unloadEffect(final String path) {
// stop effects // stop effects
final ArrayList<Integer> streamIDs = this.mPathStreamIDsMap.get(pPath); final ArrayList<Integer> streamIDs = this.mPathStreamIDsMap.get(path);
if (streamIDs != null) { if (streamIDs != null) {
for (final Integer steamID : streamIDs) { for (final Integer steamID : streamIDs) {
this.mSoundPool.stop(steamID); this.mSoundPool.stop(steamID);
} }
} }
this.mPathStreamIDsMap.remove(pPath); this.mPathStreamIDsMap.remove(path);
// unload effect // unload effect
final Integer soundID = this.mPathSoundIDMap.get(pPath); final Integer soundID = this.mPathSoundIDMap.get(path);
if(soundID != null){ if(soundID != null){
this.mSoundPool.unload(soundID); this.mSoundPool.unload(soundID);
this.mPathSoundIDMap.remove(pPath); this.mPathSoundIDMap.remove(path);
} }
} }
public int playEffect(final String pPath, final boolean pLoop, float pitch, float pan, float gain){ public int playEffect(final String path, final boolean loop, float pitch, float pan, float gain){
Integer soundID = this.mPathSoundIDMap.get(pPath); Integer soundID = this.mPathSoundIDMap.get(path);
int streamID = Cocos2dxSound.INVALID_STREAM_ID; int streamID = Cocos2dxSound.INVALID_STREAM_ID;
if (soundID != null) { if (soundID != null) {
// parameters; pan = -1 for left channel, 1 for right channel, 0 for both channels // parameters; pan = -1 for left channel, 1 for right channel, 0 for both channels
// play sound // play sound
streamID = this.doPlayEffect(pPath, soundID.intValue(), pLoop, pitch, pan, gain); streamID = this.doPlayEffect(path, soundID.intValue(), loop, pitch, pan, gain);
} else { } else {
// the effect is not prepared // the effect is not prepared
soundID = this.preloadEffect(pPath); soundID = this.preloadEffect(path);
if (soundID == Cocos2dxSound.INVALID_SOUND_ID) { if (soundID == Cocos2dxSound.INVALID_SOUND_ID) {
// can not preload effect // can not preload effect
return Cocos2dxSound.INVALID_SOUND_ID; return Cocos2dxSound.INVALID_SOUND_ID;
@ -163,7 +163,7 @@ public class Cocos2dxSound {
// only allow one playEffect at a time, or the semaphore will not work correctly // only allow one playEffect at a time, or the semaphore will not work correctly
synchronized(this.mSoundPool) { synchronized(this.mSoundPool) {
// add this effect into mEffecToPlayWhenLoadedArray, and it will be played when loaded completely // add this effect into mEffecToPlayWhenLoadedArray, and it will be played when loaded completely
mEffecToPlayWhenLoadedArray.add(new SoundInfoForLoadedCompleted(pPath, soundID.intValue(), pLoop, mEffecToPlayWhenLoadedArray.add(new SoundInfoForLoadedCompleted(path, soundID.intValue(), loop,
pitch, pan, gain)); pitch, pan, gain));
try { try {
@ -247,16 +247,16 @@ public class Cocos2dxSound {
return (this.mLeftVolume + this.mRightVolume) / 2; return (this.mLeftVolume + this.mRightVolume) / 2;
} }
public void setEffectsVolume(float pVolume) { public void setEffectsVolume(float volume) {
// pVolume should be in [0, 1.0] // volume should be in [0, 1.0]
if (pVolume < 0) { if (volume < 0) {
pVolume = 0; volume = 0;
} }
if (pVolume > 1) { if (volume > 1) {
pVolume = 1; volume = 1;
} }
this.mLeftVolume = this.mRightVolume = pVolume; this.mLeftVolume = this.mRightVolume = volume;
// change the volume of playing sounds // change the volume of playing sounds
if (!this.mPathStreamIDsMap.isEmpty()) { if (!this.mPathStreamIDsMap.isEmpty()) {
@ -282,14 +282,14 @@ public class Cocos2dxSound {
this.initData(); this.initData();
} }
public int createSoundIDFromAsset(final String pPath) { public int createSoundIDFromAsset(final String path) {
int soundID = Cocos2dxSound.INVALID_SOUND_ID; int soundID = Cocos2dxSound.INVALID_SOUND_ID;
try { try {
if (pPath.startsWith("/")) { if (path.startsWith("/")) {
soundID = this.mSoundPool.load(pPath, 0); soundID = this.mSoundPool.load(path, 0);
} else { } else {
soundID = this.mSoundPool.load(this.mContext.getAssets().openFd(pPath), 0); soundID = this.mSoundPool.load(this.mContext.getAssets().openFd(path), 0);
} }
} catch (final Exception e) { } catch (final Exception e) {
soundID = Cocos2dxSound.INVALID_SOUND_ID; soundID = Cocos2dxSound.INVALID_SOUND_ID;
@ -308,19 +308,19 @@ public class Cocos2dxSound {
return Math.max(min, (Math.min(value, max))); return Math.max(min, (Math.min(value, max)));
} }
private int doPlayEffect(final String pPath, final int soundId, final boolean pLoop, float pitch, float pan, float gain) { private int doPlayEffect(final String path, final int soundId, final boolean loop, float pitch, float pan, float gain) {
float leftVolume = this.mLeftVolume * gain * (1.0f - this.clamp(pan, 0.0f, 1.0f)); float leftVolume = this.mLeftVolume * gain * (1.0f - this.clamp(pan, 0.0f, 1.0f));
float rightVolume = this.mRightVolume * gain * (1.0f - this.clamp(-pan, 0.0f, 1.0f)); float rightVolume = this.mRightVolume * gain * (1.0f - this.clamp(-pan, 0.0f, 1.0f));
float soundRate = this.clamp(SOUND_RATE * pitch, 0.5f, 2.0f); float soundRate = this.clamp(SOUND_RATE * pitch, 0.5f, 2.0f);
// play sound // play sound
int streamID = this.mSoundPool.play(soundId, this.clamp(leftVolume, 0.0f, 1.0f), this.clamp(rightVolume, 0.0f, 1.0f), Cocos2dxSound.SOUND_PRIORITY, pLoop ? -1 : 0, soundRate); int streamID = this.mSoundPool.play(soundId, this.clamp(leftVolume, 0.0f, 1.0f), this.clamp(rightVolume, 0.0f, 1.0f), Cocos2dxSound.SOUND_PRIORITY, loop ? -1 : 0, soundRate);
// record stream id // record stream id
ArrayList<Integer> streamIDs = this.mPathStreamIDsMap.get(pPath); ArrayList<Integer> streamIDs = this.mPathStreamIDsMap.get(path);
if (streamIDs == null) { if (streamIDs == null) {
streamIDs = new ArrayList<Integer>(); streamIDs = new ArrayList<Integer>();
this.mPathStreamIDsMap.put(pPath, streamIDs); this.mPathStreamIDsMap.put(path, streamIDs);
} }
streamIDs.add(streamID); streamIDs.add(streamID);
@ -370,8 +370,10 @@ public class Cocos2dxSound {
// set the stream id which will be returned by playEffect() // set the stream id which will be returned by playEffect()
mStreamIdSyn = doPlayEffect(info.path, info.soundID, info.isLoop, info.pitch, info.pan, info.gain); mStreamIdSyn = doPlayEffect(info.path, info.soundID, info.isLoop, info.pitch, info.pan, info.gain);
// remove it from array, because we will break here /*
// so it is safe to do * Remove it from array, because we will break here.
* So it is safe to do.
*/
mEffecToPlayWhenLoadedArray.remove(info); mEffecToPlayWhenLoadedArray.remove(info);
break; break;

View File

@ -56,21 +56,21 @@ public class Cocos2dxTypefaces {
// Methods // Methods
// =========================================================== // ===========================================================
public static synchronized Typeface get(final Context pContext, final String pAssetName) { public static synchronized Typeface get(final Context context, final String assetName) {
if (!Cocos2dxTypefaces.sTypefaceCache.containsKey(pAssetName)) { if (!Cocos2dxTypefaces.sTypefaceCache.containsKey(assetName)) {
Typeface typeface = null; Typeface typeface = null;
if (pAssetName.startsWith("/")) if (assetName.startsWith("/"))
{ {
typeface = Typeface.createFromFile(pAssetName); typeface = Typeface.createFromFile(assetName);
} }
else else
{ {
typeface = Typeface.createFromAsset(pContext.getAssets(), pAssetName); typeface = Typeface.createFromAsset(context.getAssets(), assetName);
} }
Cocos2dxTypefaces.sTypefaceCache.put(pAssetName, typeface); Cocos2dxTypefaces.sTypefaceCache.put(assetName, typeface);
} }
return Cocos2dxTypefaces.sTypefaceCache.get(pAssetName); return Cocos2dxTypefaces.sTypefaceCache.get(assetName);
} }
// =========================================================== // ===========================================================

View File

@ -232,7 +232,7 @@ public class Cocos2dxVideoHelper {
} }
} }
public static void setVideoUrl(int index,int videoSource,String videoUrl) { public static void setVideoUrl(int index, int videoSource, String videoUrl) {
Message msg = new Message(); Message msg = new Message();
msg.what = VideoTaskSetSource; msg.what = VideoTaskSetSource;
msg.arg1 = index; msg.arg1 = index;
@ -241,7 +241,7 @@ public class Cocos2dxVideoHelper {
mVideoHandler.sendMessage(msg); mVideoHandler.sendMessage(msg);
} }
private void _setVideoURL(int index,int videoSource,String videoUrl) { private void _setVideoURL(int index, int videoSource, String videoUrl) {
Cocos2dxVideoView videoView = sVideoViews.get(index); Cocos2dxVideoView videoView = sVideoViews.get(index);
if (videoView != null) { if (videoView != null) {
switch (videoSource) { switch (videoSource) {
@ -257,7 +257,7 @@ public class Cocos2dxVideoHelper {
} }
} }
public static void setVideoRect(int index,int left,int top,int maxWidth,int maxHeight) { public static void setVideoRect(int index, int left, int top, int maxWidth, int maxHeight) {
Message msg = new Message(); Message msg = new Message();
msg.what = VideoTaskSetRect; msg.what = VideoTaskSetRect;
msg.arg1 = index; msg.arg1 = index;
@ -265,14 +265,14 @@ public class Cocos2dxVideoHelper {
mVideoHandler.sendMessage(msg); mVideoHandler.sendMessage(msg);
} }
private void _setVideoRect(int index,int left,int top,int maxWidth,int maxHeight) { private void _setVideoRect(int index, int left, int top, int maxWidth, int maxHeight) {
Cocos2dxVideoView videoView = sVideoViews.get(index); Cocos2dxVideoView videoView = sVideoViews.get(index);
if (videoView != null) { if (videoView != null) {
videoView.setVideoRect(left,top,maxWidth,maxHeight); videoView.setVideoRect(left,top,maxWidth,maxHeight);
} }
} }
public static void setFullScreenEnabled(int index,boolean enabled, int width,int height) { public static void setFullScreenEnabled(int index, boolean enabled, int width, int height) {
Message msg = new Message(); Message msg = new Message();
msg.what = VideoTaskFullScreen; msg.what = VideoTaskFullScreen;
msg.arg1 = index; msg.arg1 = index;

View File

@ -52,11 +52,13 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
private static final int STATE_PAUSED = 4; private static final int STATE_PAUSED = 4;
private static final int STATE_PLAYBACK_COMPLETED = 5; private static final int STATE_PLAYBACK_COMPLETED = 5;
// mCurrentState is a VideoView object's current state. /**
// mTargetState is the state that a method caller intends to reach. * mCurrentState is a VideoView object's current state.
// For instance, regardless the VideoView object's current state, * mTargetState is the state that a method caller intends to reach.
// calling pause() intends to bring the object to a target state * For instance, regardless the VideoView object's current state,
// of STATE_PAUSED. * calling pause() intends to bring the object to a target state
* of STATE_PAUSED.
*/
private int mCurrentState = STATE_IDLE; private int mCurrentState = STATE_IDLE;
private int mTargetState = STATE_IDLE; private int mTargetState = STATE_IDLE;
@ -113,7 +115,7 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
} }
public void setVideoRect(int left,int top,int maxWidth,int maxHeight) { public void setVideoRect(int left, int top, int maxWidth, int maxHeight) {
mViewLeft = left; mViewLeft = left;
mViewTop = top; mViewTop = top;
mViewWidth = maxWidth; mViewWidth = maxWidth;
@ -296,8 +298,10 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
} }
mMediaPlayer.prepareAsync(); mMediaPlayer.prepareAsync();
// we don't set the target state here either, but preserve the
// target state that was there before. /**
* Don't set the target state here either, but preserve the target state that was there before.
*/
mCurrentState = STATE_PREPARING; mCurrentState = STATE_PREPARING;
} catch (IOException ex) { } catch (IOException ex) {
Log.w(TAG, "Unable to open content: " + mUri, ex); Log.w(TAG, "Unable to open content: " + mUri, ex);
@ -329,7 +333,7 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
} }
} }
public void fixSize(int left,int top,int width,int height) { public void fixSize(int left, int top, int width, int height) {
if (width != 0 && height != 0) { if (width != 0 && height != 0) {
if (mKeepRatio) { if (mKeepRatio) {
if ( mVideoWidth * height > width * mVideoHeight ) { if ( mVideoWidth * height > width * mVideoHeight ) {
@ -389,7 +393,8 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
mVideoWidth = mp.getVideoWidth(); mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight(); mVideoHeight = mp.getVideoHeight();
int seekToPosition = mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call // mSeekWhenPrepared may be changed after seekTo() call
int seekToPosition = mSeekWhenPrepared;
if (seekToPosition != 0) { if (seekToPosition != 0) {
seekTo(seekToPosition); seekTo(seekToPosition);
} }
@ -451,10 +456,10 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
int messageId; int messageId;
if (framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) { if (framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
//messageId = com.android.internal.R.string.VideoView_error_text_invalid_progressive_playback; // messageId = com.android.internal.R.string.VideoView_error_text_invalid_progressive_playback;
messageId = r.getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", "android"); messageId = r.getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", "android");
} else { } else {
//messageId = com.android.internal.R.string.VideoView_error_text_unknown; // messageId = com.android.internal.R.string.VideoView_error_text_unknown;
messageId = r.getIdentifier("VideoView_error_text_unknown", "string", "android"); messageId = r.getIdentifier("VideoView_error_text_unknown", "string", "android");
} }
@ -502,7 +507,7 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
/** /**
* Register a callback to be invoked when the end of a media file * Register a callback to be invoked when the end of a media file
* has been reached during playback. * has been reached during play back.
* *
* @param l The callback that will be run * @param l The callback that will be run
*/ */
@ -513,7 +518,7 @@ public class Cocos2dxVideoView extends SurfaceView implements MediaPlayerControl
/** /**
* Register a callback to be invoked when an error occurs * Register a callback to be invoked when an error occurs
* during playback or setup. If no listener is specified, * during play back or setup. If no listener is specified,
* or if the listener returned false, VideoView will inform * or if the listener returned false, VideoView will inform
* the user of any errors. * the user of any errors.
* *

View File

@ -15,8 +15,8 @@ import android.widget.FrameLayout;
public class Cocos2dxWebView extends WebView { public class Cocos2dxWebView extends WebView {
private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName(); private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName();
private int viewTag; private int mViewTag;
private String jsScheme; private String mJSScheme;
public Cocos2dxWebView(Context context) { public Cocos2dxWebView(Context context) {
this(context, -1); this(context, -1);
@ -25,8 +25,8 @@ public class Cocos2dxWebView extends WebView {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
public Cocos2dxWebView(Context context, int viewTag) { public Cocos2dxWebView(Context context, int viewTag) {
super(context); super(context);
this.viewTag = viewTag; this.mViewTag = viewTag;
this.jsScheme = ""; this.mJSScheme = "";
this.setFocusable(true); this.setFocusable(true);
this.setFocusableInTouchMode(true); this.setFocusableInTouchMode(true);
@ -48,7 +48,7 @@ public class Cocos2dxWebView extends WebView {
} }
public void setJavascriptInterfaceScheme(String scheme) { public void setJavascriptInterfaceScheme(String scheme) {
this.jsScheme = scheme != null ? scheme : ""; this.mJSScheme = scheme != null ? scheme : "";
} }
public void setScalesPageToFit(boolean scalesPageToFit) { public void setScalesPageToFit(boolean scalesPageToFit) {
@ -59,23 +59,23 @@ public class Cocos2dxWebView extends WebView {
@Override @Override
public boolean shouldOverrideUrlLoading(WebView view, String urlString) { public boolean shouldOverrideUrlLoading(WebView view, String urlString) {
URI uri = URI.create(urlString); URI uri = URI.create(urlString);
if (uri != null && uri.getScheme().equals(jsScheme)) { if (uri != null && uri.getScheme().equals(mJSScheme)) {
Cocos2dxWebViewHelper._onJsCallback(viewTag, urlString); Cocos2dxWebViewHelper._onJsCallback(mViewTag, urlString);
return true; return true;
} }
return Cocos2dxWebViewHelper._shouldStartLoading(viewTag, urlString); return Cocos2dxWebViewHelper._shouldStartLoading(mViewTag, urlString);
} }
@Override @Override
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url); super.onPageFinished(view, url);
Cocos2dxWebViewHelper._didFinishLoading(viewTag, url); Cocos2dxWebViewHelper._didFinishLoading(mViewTag, url);
} }
@Override @Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl); super.onReceivedError(view, errorCode, description, failingUrl);
Cocos2dxWebViewHelper._didFailLoading(viewTag, failingUrl); Cocos2dxWebViewHelper._didFailLoading(mViewTag, failingUrl);
} }
} }

View File

@ -13,18 +13,18 @@ import java.util.concurrent.FutureTask;
public class Cocos2dxWebViewHelper { public class Cocos2dxWebViewHelper {
private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName(); private static final String TAG = Cocos2dxWebViewHelper.class.getSimpleName();
private static Handler handler; private static Handler sHandler;
private static Cocos2dxActivity cocos2dxActivity; private static Cocos2dxActivity sCocos2dxActivity;
private static FrameLayout layout; private static FrameLayout sLayout;
private static SparseArray<Cocos2dxWebView> webViews; private static SparseArray<Cocos2dxWebView> webViews;
private static int viewTag = 0; private static int viewTag = 0;
public Cocos2dxWebViewHelper(FrameLayout layout) { public Cocos2dxWebViewHelper(FrameLayout layout) {
Cocos2dxWebViewHelper.layout = layout; Cocos2dxWebViewHelper.sLayout = layout;
Cocos2dxWebViewHelper.handler = new Handler(Looper.myLooper()); Cocos2dxWebViewHelper.sHandler = new Handler(Looper.myLooper());
Cocos2dxWebViewHelper.cocos2dxActivity = (Cocos2dxActivity) Cocos2dxActivity.getContext(); Cocos2dxWebViewHelper.sCocos2dxActivity = (Cocos2dxActivity) Cocos2dxActivity.getContext();
Cocos2dxWebViewHelper.webViews = new SparseArray<Cocos2dxWebView>(); Cocos2dxWebViewHelper.webViews = new SparseArray<Cocos2dxWebView>();
} }
@ -55,14 +55,14 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static int createWebView() { public static int createWebView() {
final int index = viewTag; final int index = viewTag;
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = new Cocos2dxWebView(cocos2dxActivity, index); Cocos2dxWebView webView = new Cocos2dxWebView(sCocos2dxActivity, index);
FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams lParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT); FrameLayout.LayoutParams.WRAP_CONTENT);
layout.addView(webView, lParams); sLayout.addView(webView, lParams);
webViews.put(index, webView); webViews.put(index, webView);
} }
@ -72,13 +72,13 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void removeWebView(final int index) { public static void removeWebView(final int index) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
if (webView != null) { if (webView != null) {
webViews.remove(index); webViews.remove(index);
layout.removeView(webView); sLayout.removeView(webView);
} }
} }
}); });
@ -86,7 +86,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void setVisible(final int index, final boolean visible) { public static void setVisible(final int index, final boolean visible) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -99,7 +99,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void setWebViewRect(final int index, final int left, final int top, final int maxWidth, final int maxHeight) { public static void setWebViewRect(final int index, final int left, final int top, final int maxWidth, final int maxHeight) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -112,7 +112,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void setJavascriptInterfaceScheme(final int index, final String scheme) { public static void setJavascriptInterfaceScheme(final int index, final String scheme) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -125,7 +125,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void loadData(final int index, final String data, final String mimeType, final String encoding, final String baseURL) { public static void loadData(final int index, final String data, final String mimeType, final String encoding, final String baseURL) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -138,7 +138,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void loadHTMLString(final int index, final String htmlString, final String mimeType, final String encoding) { public static void loadHTMLString(final int index, final String htmlString, final String mimeType, final String encoding) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -151,7 +151,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void loadUrl(final int index, final String url) { public static void loadUrl(final int index, final String url) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -164,7 +164,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void loadFile(final int index, final String filePath) { public static void loadFile(final int index, final String filePath) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -176,7 +176,7 @@ public class Cocos2dxWebViewHelper {
} }
public static void stopLoading(final int index) { public static void stopLoading(final int index) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -189,7 +189,7 @@ public class Cocos2dxWebViewHelper {
} }
public static void reload(final int index) { public static void reload(final int index) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -202,7 +202,7 @@ public class Cocos2dxWebViewHelper {
public static <T> T callInMainThread(Callable<T> call) throws ExecutionException, InterruptedException { public static <T> T callInMainThread(Callable<T> call) throws ExecutionException, InterruptedException {
FutureTask<T> task = new FutureTask<T>(call); FutureTask<T> task = new FutureTask<T>(call);
handler.post(task); sHandler.post(task);
return task.get(); return task.get();
} }
@ -244,7 +244,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void goBack(final int index) { public static void goBack(final int index) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -257,7 +257,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void goForward(final int index) { public static void goForward(final int index) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -270,7 +270,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void evaluateJS(final int index, final String js) { public static void evaluateJS(final int index, final String js) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);
@ -283,7 +283,7 @@ public class Cocos2dxWebViewHelper {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void setScalesPageToFit(final int index, final boolean scalesPageToFit) { public static void setScalesPageToFit(final int index, final boolean scalesPageToFit) {
cocos2dxActivity.runOnUiThread(new Runnable() { sCocos2dxActivity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
Cocos2dxWebView webView = webViews.get(index); Cocos2dxWebView webView = webViews.get(index);