package com.android.samples;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
import android.app.Activity;
-import android.content.res.Configuration;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Config;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-
-import java.lang.Runtime;
public class RsList extends Activity {
"Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
};
- int mWidth;
- int mHeight;
-
public RsListRS() {
}
- public void init(RenderScriptGL rs, Resources res, int width, int height) {
+ public void init(RenderScriptGL rs, Resources res) {
mRS = rs;
mRes = res;
- mWidth = width;
- mHeight = height;
initRS();
}
*/
package com.android.samples;
-
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
import android.renderscript.RenderScriptGL;
import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
import android.view.MotionEvent;
public class RsListView extends RSSurfaceView {
public RsListView(Context context) {
super(context);
- //setFocusable(true);
+ ensureRenderScript();
}
private RenderScriptGL mRS;
private RsListRS mRender;
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
+ private void ensureRenderScript() {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
- sc.setDepth(16, 24);
mRS = createRenderScriptGL(sc);
- mRS.setSurface(holder, w, h);
mRender = new RsListRS();
- mRender.init(mRS, getResources(), w, h);
+ mRender.init(mRS, getResources());
}
}
@Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ ensureRenderScript();
+ }
+
+ @Override
protected void onDetachedFromWindow() {
+ mRender = null;
if (mRS != null) {
mRS = null;
destroyRenderScriptGL();
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- // break point at here
- // this method doesn't work when 'extends View' include 'extends ScrollView'.
- return super.onKeyDown(keyCode, event);
- }
-
-
- @Override
public boolean onTouchEvent(MotionEvent ev)
{
boolean ret = false;
int act = ev.getAction();
- if (act == ev.ACTION_DOWN) {
+ if (act == MotionEvent.ACTION_DOWN) {
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
ret = true;
- } else if (act == ev.ACTION_MOVE) {
+ } else if (act == MotionEvent.ACTION_MOVE) {
mRender.onActionMove((int)ev.getX(), (int)ev.getY());
ret = true;
}
package com.android.samples;
-import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
-
import android.app.Activity;
-import android.content.res.Configuration;
import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.provider.Settings.System;
-import android.util.Config;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.Window;
-import android.widget.Button;
-import android.widget.ListView;
-
-import java.lang.Runtime;
public class RsRenderStates extends Activity {
package com.android.samples;
-import java.io.Writer;
-
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public RsRenderStatesRS() {
}
- public void init(RenderScriptGL rs, Resources res, int width, int height) {
+ public void init(RenderScriptGL rs, Resources res) {
mRS = rs;
+ mWidth = mRS.getWidth();
+ mHeight = mRS.getHeight();
mRes = res;
- mWidth = width;
- mHeight = height;
mOptionsARGB.inScaled = false;
mOptionsARGB.inPreferredConfig = Bitmap.Config.ARGB_8888;
mMode = 0;
initRS();
}
+ public void surfaceChanged() {
+ mWidth = mRS.getWidth();
+ mHeight = mRS.getHeight();
+
+ Matrix4f proj = new Matrix4f();
+ proj.loadOrthoWindow(mWidth, mHeight);
+ mPVA.setProjection(proj);
+ }
+
private Resources mRes;
private RenderScriptGL mRS;
package com.android.samples;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.Semaphore;
-
import android.renderscript.RSSurfaceView;
-import android.renderscript.RenderScript;
import android.renderscript.RenderScriptGL;
import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.os.Message;
-import android.util.AttributeSet;
-import android.util.Log;
-import android.view.Surface;
-import android.view.SurfaceHolder;
-import android.view.SurfaceView;
-import android.view.KeyEvent;
import android.view.MotionEvent;
+import android.view.SurfaceHolder;
public class RsRenderStatesView extends RSSurfaceView {
public RsRenderStatesView(Context context) {
super(context);
- //setFocusable(true);
+ ensureRenderScript();
}
private RenderScriptGL mRS;
private RsRenderStatesRS mRender;
-
- public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
- super.surfaceChanged(holder, format, w, h);
+ private void ensureRenderScript() {
if (mRS == null) {
RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
sc.setDepth(16, 24);
mRS = createRenderScriptGL(sc);
- mRS.setSurface(holder, w, h);
mRender = new RsRenderStatesRS();
- mRender.init(mRS, getResources(), w, h);
+ mRender.init(mRS, getResources());
}
}
@Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ ensureRenderScript();
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ super.surfaceChanged(holder, format, w, h);
+ mRender.surfaceChanged();
+ }
+
+ @Override
protected void onDetachedFromWindow() {
+ mRender = null;
if (mRS != null) {
mRS = null;
destroyRenderScriptGL();
}
@Override
- public boolean onKeyDown(int keyCode, KeyEvent event)
- {
- // break point at here
- // this method doesn't work when 'extends View' include 'extends ScrollView'.
- return super.onKeyDown(keyCode, event);
- }
-
-
- @Override
- public boolean onTouchEvent(MotionEvent ev)
- {
- boolean ret = false;
- int act = ev.getAction();
- if (act == ev.ACTION_DOWN) {
+ public boolean onTouchEvent(MotionEvent ev) {
+ if (ev.getAction() == MotionEvent.ACTION_DOWN) {
mRender.onActionDown((int)ev.getX(), (int)ev.getY());
- ret = true;
+ return true;
}
- return ret;
+ return false;
}
}
int root(int launchID) {
rsgClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- rsgClearDepth(1.0f);
textPos -= (int)gDY*2;
gDY *= 0.95;