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