Wednesday, July 28, 2010

[android-developers] subclassing SurfaceView and overriding onDraw() to change SurfaceView parameters to generate preview of desired size

I have subclassed the SurfaceView and instantiating it in onCreate of
the Activity. The preview is generated but the control never enters
onDraw() which is overriden in the subclass of SurfaceView. Why is
that?

class ActivityClass extends Activity{

onCreate(){

mPreview = new Preview(this);
setContentView(mPreview);

}

public void startPreview(){

rec = new MediaRecorder();
rec.setVideoSource();.......
rec.setPreviewDisplay(mPreview.getSurfaceHolder.getSurface());
}

}

class Preview extends SurfaceView implements
SurfaceHolder.Callback{

SurfaceHolder mHolder;

public Preview(Context context){
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
bringToFront();//this is not
invalidate();//making a difference

}

SurfaceHolder getSurfaceHolder(){

return mHolder;
}

//Surface callback methods implemented here
}

Before drawing the preview on the Surface, shouldn't the control be
given to the onDraw callback if it is implemented?

Because onDraw callback says to the Android framework 'you don't draw
the view. I will draw it since I have been implemented'. Am I right?

Why then, is the control failing to enter onDraw()? Please help.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment