User1204501
User1204501

Reputation: 831

How to exit SurfaceView?

I draw something on canvas using SurfaceView. How can I define a way to cancelling the surfaceView once the user is done? Below is my SurfaceView implementation. The DrawOnTop class has the onDraw() but I initialize all the variables in Preview class.

public class Preview extends SurfaceView implements SurfaceHolder.Callback {
    SurfaceHolder mHolder;

    DrawOnTop mDrawOnTop;
    boolean mFinished;

    Preview(Context context, DrawOnTop drawOnTop) {
        super(context);

        mDrawOnTop = drawOnTop;
        mFinished = false;

        // Install a SurfaceHolder.Callback so we get notified when the
        // underlying surface is created and destroyed.
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    public void surfaceCreated(SurfaceHolder holder) {

        //I set the bitmaps etc here
        mDrawOnTop.mBitmap = Bitmap.createBitmap(mDrawOnTop.mImageWidth,
                mDrawOnTop.mImageHeight, Bitmap.Config.ARGB_8888);

        mDrawOnTop.mBitmap.setPixels(mDrawOnTop.mRGBData, 0,
                mDrawOnTop.mImageWidth, 0, 0, mDrawOnTop.mImageWidth,
                mDrawOnTop.mImageHeight);
        Button x = new Button(getContext());
    x.setText("Hi");
    x.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {


        }

    });
        mDrawOnTop.invalidate();

    }

    public void surfaceDestroyed(SurfaceHolder holder) {

        mFinished = true;

    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

    }

}

EDIT:

Now after some research I was able to find out that I need to use setContentView and set it back to the Activity I want.

Upvotes: 0

Views: 961

Answers (1)

Nambi
Nambi

Reputation: 12042

setvisibility to invisible to hide the view

setVisibility(this.Invisible);

Upvotes: 1

Related Questions