mirror of https://github.com/axmolengine/axmol.git
Use Java code instead of XML to define layout
* Android layout for cocos apps are very simple (full screen) * Avoids creation of R.java for loading the layout * Can package entire library in jar * Remove unused layout resource
This commit is contained in:
parent
4e5a64fd9e
commit
6fc2dc5ed9
|
@ -23,6 +23,7 @@ THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
package org.cocos2dx.hellolua;
|
package org.cocos2dx.hellolua;
|
||||||
import org.cocos2dx.lib.Cocos2dxActivity;
|
import org.cocos2dx.lib.Cocos2dxActivity;
|
||||||
|
import org.cocos2dx.lib.Cocos2dxEditText;
|
||||||
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
|
import org.cocos2dx.lib.Cocos2dxGLSurfaceView;
|
||||||
import org.cocos2dx.lib.Cocos2dxRenderer;
|
import org.cocos2dx.lib.Cocos2dxRenderer;
|
||||||
|
|
||||||
|
@ -33,6 +34,8 @@ import android.opengl.GLSurfaceView;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
public class HelloLua extends Cocos2dxActivity{
|
public class HelloLua extends Cocos2dxActivity{
|
||||||
protected void onCreate(Bundle savedInstanceState){
|
protected void onCreate(Bundle savedInstanceState){
|
||||||
|
@ -43,10 +46,35 @@ public class HelloLua extends Cocos2dxActivity{
|
||||||
String packageName = getApplication().getPackageName();
|
String packageName = getApplication().getPackageName();
|
||||||
super.setPackageName(packageName);
|
super.setPackageName(packageName);
|
||||||
|
|
||||||
|
// FrameLayout
|
||||||
|
ViewGroup.LayoutParams framelayout_params =
|
||||||
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
|
ViewGroup.LayoutParams.FILL_PARENT);
|
||||||
|
FrameLayout framelayout = new FrameLayout(this);
|
||||||
|
framelayout.setLayoutParams(framelayout_params);
|
||||||
|
|
||||||
|
// Cocos2dxEditText layout
|
||||||
|
ViewGroup.LayoutParams edittext_layout_params =
|
||||||
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
|
||||||
|
edittext.setLayoutParams(edittext_layout_params);
|
||||||
|
|
||||||
|
// ...add to FrameLayout
|
||||||
|
framelayout.addView(edittext);
|
||||||
|
|
||||||
|
// LuaGLSurfaceView
|
||||||
mGLView = new LuaGLSurfaceView(this);
|
mGLView = new LuaGLSurfaceView(this);
|
||||||
setContentView(mGLView);
|
|
||||||
|
// ...add to FrameLayout
|
||||||
|
framelayout.addView(mGLView);
|
||||||
|
|
||||||
mGLView.setEGLContextClientVersion(2);
|
mGLView.setEGLContextClientVersion(2);
|
||||||
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
||||||
|
mGLView.setTextField(edittext);
|
||||||
|
|
||||||
|
// Set framelayout as the content view
|
||||||
|
setContentView(framelayout);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.d("activity", "don't support gles2.0");
|
Log.d("activity", "don't support gles2.0");
|
||||||
|
|
|
@ -33,6 +33,8 @@ import android.content.Context;
|
||||||
import android.content.pm.ConfigurationInfo;
|
import android.content.pm.ConfigurationInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
public class ApplicationDemo extends Cocos2dxActivity{
|
public class ApplicationDemo extends Cocos2dxActivity{
|
||||||
private Cocos2dxGLSurfaceView mGLView;
|
private Cocos2dxGLSurfaceView mGLView;
|
||||||
|
@ -45,11 +47,35 @@ public class ApplicationDemo extends Cocos2dxActivity{
|
||||||
String packageName = getApplication().getPackageName();
|
String packageName = getApplication().getPackageName();
|
||||||
super.setPackageName(packageName);
|
super.setPackageName(packageName);
|
||||||
|
|
||||||
setContentView(R.layout.cocos2dx_default_screen_layout);
|
// FrameLayout
|
||||||
mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.cocos2dx_default_gl_surfaceview);
|
ViewGroup.LayoutParams framelayout_params =
|
||||||
mGLView.setTextField((Cocos2dxEditText)findViewById(R.id.cocos2dx_default_textField));
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
|
ViewGroup.LayoutParams.FILL_PARENT);
|
||||||
|
FrameLayout framelayout = new FrameLayout(this);
|
||||||
|
framelayout.setLayoutParams(framelayout_params);
|
||||||
|
|
||||||
|
// Cocos2dxEditText layout
|
||||||
|
ViewGroup.LayoutParams edittext_layout_params =
|
||||||
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
|
||||||
|
edittext.setLayoutParams(edittext_layout_params);
|
||||||
|
|
||||||
|
// ...add to FrameLayout
|
||||||
|
framelayout.addView(edittext);
|
||||||
|
|
||||||
|
// Cocos2dxGLSurfaceView
|
||||||
|
mGLView = new Cocos2dxGLSurfaceView(this);
|
||||||
|
|
||||||
|
// ...add to FrameLayout
|
||||||
|
framelayout.addView(mGLView);
|
||||||
|
|
||||||
mGLView.setEGLContextClientVersion(2);
|
mGLView.setEGLContextClientVersion(2);
|
||||||
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
||||||
|
mGLView.setTextField(edittext);
|
||||||
|
|
||||||
|
// Set framelayout as the content view
|
||||||
|
setContentView(framelayout);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.d("activity", "don't support gles2.0");
|
Log.d("activity", "don't support gles2.0");
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent">
|
|
||||||
|
|
||||||
<org.cocos2dx.lib.Cocos2dxEditText
|
|
||||||
android:id="@+id/cocos2dx_default_textField"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
<org.cocos2dx.lib.Cocos2dxGLSurfaceView
|
|
||||||
android:id="@+id/cocos2dx_default_gl_surfaceview"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
|
@ -6,6 +6,7 @@ APP_NAME=$2
|
||||||
COCOS2DX_ROOT=$1
|
COCOS2DX_ROOT=$1
|
||||||
APP_DIR=$COCOS2DX_ROOT/$APP_NAME
|
APP_DIR=$COCOS2DX_ROOT/$APP_NAME
|
||||||
HELLOWORLD_ROOT=$COCOS2DX_ROOT/HelloWorld
|
HELLOWORLD_ROOT=$COCOS2DX_ROOT/HelloWorld
|
||||||
|
COCOSJAVALIB_ROOT=$COCOS2DX_ROOT/cocos2dx/platform/android/java
|
||||||
NDK_ROOT=$3
|
NDK_ROOT=$3
|
||||||
PACKAGE_PATH=$4
|
PACKAGE_PATH=$4
|
||||||
NEED_BOX2D=$5
|
NEED_BOX2D=$5
|
||||||
|
|
|
@ -33,6 +33,8 @@ import android.content.Context;
|
||||||
import android.content.pm.ConfigurationInfo;
|
import android.content.pm.ConfigurationInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
public class TestsDemo extends Cocos2dxActivity{
|
public class TestsDemo extends Cocos2dxActivity{
|
||||||
private Cocos2dxGLSurfaceView mGLView;
|
private Cocos2dxGLSurfaceView mGLView;
|
||||||
|
@ -45,12 +47,35 @@ public class TestsDemo extends Cocos2dxActivity{
|
||||||
String packageName = getApplication().getPackageName();
|
String packageName = getApplication().getPackageName();
|
||||||
super.setPackageName(packageName);
|
super.setPackageName(packageName);
|
||||||
|
|
||||||
setContentView(R.layout.cocos2dx_default_screen_layout);
|
// FrameLayout
|
||||||
|
ViewGroup.LayoutParams framelayout_params =
|
||||||
mGLView = (Cocos2dxGLSurfaceView) findViewById(R.id.cocos2dx_default_gl_surfaceview);
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
mGLView.setTextField((Cocos2dxEditText)findViewById(R.id.cocos2dx_default_textField));
|
ViewGroup.LayoutParams.FILL_PARENT);
|
||||||
mGLView.setEGLContextClientVersion(2);
|
FrameLayout framelayout = new FrameLayout(this);
|
||||||
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
framelayout.setLayoutParams(framelayout_params);
|
||||||
|
|
||||||
|
// Cocos2dxEditText layout
|
||||||
|
ViewGroup.LayoutParams edittext_layout_params =
|
||||||
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
Cocos2dxEditText edittext = new Cocos2dxEditText(this);
|
||||||
|
edittext.setLayoutParams(edittext_layout_params);
|
||||||
|
|
||||||
|
// ...add to FrameLayout
|
||||||
|
framelayout.addView(edittext);
|
||||||
|
|
||||||
|
// Cocos2dxGLSurfaceView
|
||||||
|
mGLView = new Cocos2dxGLSurfaceView(this);
|
||||||
|
|
||||||
|
// ...add to FrameLayout
|
||||||
|
framelayout.addView(mGLView);
|
||||||
|
|
||||||
|
mGLView.setEGLContextClientVersion(2);
|
||||||
|
mGLView.setCocos2dxRenderer(new Cocos2dxRenderer());
|
||||||
|
mGLView.setTextField(edittext);
|
||||||
|
|
||||||
|
// Set framelayout as the content view
|
||||||
|
setContentView(framelayout);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.d("activity", "don't support gles2.0");
|
Log.d("activity", "don't support gles2.0");
|
||||||
|
|
Loading…
Reference in New Issue