1package com.android.galaxy4; 2 3import android.content.Context; 4import android.graphics.PixelFormat; 5import android.renderscript.RSSurfaceView; 6import android.renderscript.RenderScriptGL; 7import android.renderscript.RenderScriptGL.SurfaceConfig; 8import android.view.SurfaceHolder; 9 10public class GalaxyView extends RSSurfaceView { 11 12 private RenderScriptGL mRS; 13 private GalaxyRS mRender; 14 15 public GalaxyView(Context context) { 16 super(context); 17 setFocusable(true); 18 setFocusableInTouchMode(true); 19 // getHolder().setFormat(PixelFormat.TRANSPARENT); 20 } 21 22 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 23 super.surfaceChanged(holder, format, w, h); 24 25 if (mRS == null) { 26 RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig(); 27 mRS = createRenderScriptGL(sc); 28 mRS.setSurface(holder, w, h); 29 30 mRender = new GalaxyRS(); 31 mRender.init(mRS, getResources(), w, h); 32 } 33 34 } 35 36 @Override 37 protected void onDetachedFromWindow() { 38 if (mRS != null) { 39 mRS.setSurface(null, 0, 0); 40 mRS = null; 41 destroyRenderScriptGL(); 42 } 43 } 44 45} 46