Android SurfaceHolder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SurfaceHolder class.

This code example shows how to use the following methods:addCallback, setType
    public ForegroundCameraPreview(Context context, Camera camera) {
        super(context);
        mCamera = camera;
 
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    } 
 
    public void surfaceCreated(SurfaceHolder holder) {
        try { 
            mCamera.setPreviewDisplay(holder);
            mCamera.startPreview();
        } catch (IOException e) {
            Log.d(TAG, "Error setting camera preview: " + e.getMessage());
        } 
    } 
 
    public void surfaceDestroyed(SurfaceHolder holder) {
    } 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addCallback, setType
        root.addView(stopButton);
         
        setContentView(root);
         
        mSurfaceHolder = mSurfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);                    
        mIntent = this.getIntent();
         
        quality = mIntent.getIntExtra("quality", 100);
         
         
        stopButton.setOnClickListener(mSnapListener);
    } 
     
    private OnClickListener mSnapListener = new OnClickListener() {
        public void onClick(View v) { 
        	mCamera.takePicture(null, null, mPictureCallback); 
        } 
    }; 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addCallback, setSizeFromLayout, setType
        mCamera = camera;
 
        // Install a SurfaceHolder.Callback so we get notified when the 
        // underlying surface is created and destroyed. 
        mHolder = mSurfaceView.getHolder();
        mHolder.addCallback(this);
        mHolder.setSizeFromLayout();
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    } 
     
    public void stopPreview() { 
        Logger.T(TAG, "stopPreview");
        if (mCamera != null) {
            mCamera.stopPreview();
            mCamera = null;
        } else { 
            Logger.T(TAG, "No camera to stop preview");
        } 
    } 
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addCallback, getSurfaceFrame, lockCanvas, unlockCanvasAndPost
    public  ViESurfaceRenderer(SurfaceView view) {
        surfaceHolder = view.getHolder();
        if(surfaceHolder == null)
            return; 
 
        Canvas canvas = surfaceHolder.lockCanvas();
        if(canvas != null) {
            Rect dst =surfaceHolder.getSurfaceFrame();
            if(dst != null) {
                dstRect = dst;
                dstHeight =dstRect.bottom-dstRect.top;
                dstWidth = dstRect.right-dstRect.left;
            } 
            surfaceHolder.unlockCanvasAndPost(canvas);
        } 
 
        surfaceHolder.addCallback(this);
    } 
 
    public void surfaceChanged(SurfaceHolder holder, int format,

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addCallback
        previewData = new byte[640*480 + 320*240*2];
 
        // Install a SurfaceHolder.Callback so we get notified when the 
        // underlying surface is created and destroyed. 
        mHolder = getHolder();
        mHolder.addCallback(this);
 
    } 
 
    public void onPreviewFrame(byte[] data, Camera camera) {
        if (mFiltered.getHolder().getSurface().isValid()) {
            processFrame(data, mFiltered.getHolder().getSurface());
            /* 
 
            Canvas canvas = mFiltered.getHolder().lockCanvas(); 
 
            if (canvas != null) { 
                //canvas.drawBitmap(filteredData, 0, 640, 0, 0, 640, 360, false, null); 
                //canvas.drawBitmap(data, 0, 640, 0, 0, 640, 360, false, null); 
                //mFiltered.getHolder().unlockCanvasAndPost(canvas); 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addCallback, setFormat, setType
	{ 
		super( context );
 
		m_eglState = new EGLState(glApi);
		m_holder = getHolder( );
		m_holder.addCallback( this );
		m_holder.setType( SurfaceHolder.SURFACE_TYPE_GPU );
		m_holder.setFormat( PixelFormat.RGBA_8888 );
	} 
 
	/** 
	 * Binds the context of this view to the thread calling 
	 * this function. 
	 */ 
	public void bind() 
	{ 
		m_eglState.bind( );
	} 
 
	/** 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addCallback, setType
     * @param attrs 
     */ 
    public CameraPreviewView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mHolder = getHolder();
        mHolder.addCallback(this);
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        // TODO Auto-generated constructor stub 
    } 
 
    /* (non-Javadoc) 
     * @see android.view.SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder, int, int, int) 
     */ 
    @Override 
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        // TODO Auto-generated method stub 
         
    } 
 
    /* (non-Javadoc) 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:lockCanvas, unlockCanvasAndPost
                } 
            } 
        } 
 
        private void drawWallpaperWithCanvas(SurfaceHolder sh, int w, int h, int x, int y) {
            Canvas c = sh.lockCanvas();
            if (c != null) {
                try { 
                    if (DEBUG) {
                        Log.d(TAG, "Redrawing: x=" + x + ", y=" + y);
                    } 
 
                    c.translate(x, y);
                    if (w < 0 || h < 0) {
                        c.save(Canvas.CLIP_SAVE_FLAG);
                        c.clipRect(0, 0, mBackground.getWidth(), mBackground.getHeight(),
                                Op.DIFFERENCE);
                        c.drawColor(0xff000000);
                        c.restore();
                    } 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addCallback, setType
        super(context);
 
        // 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);
        mActivity = (Activity)context;
    } 
 
 
    /** 
     * Activates everything when the surface is created 
     */ 
	 @Override 
	public void surfaceCreated(SurfaceHolder holder)
     { 
		 mHolder = holder;
		// if (mCamera != null) 
		// initiateCamera(); 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setFormat, setSizeFromLayout
 
        @Override 
        public void onCreate(SurfaceHolder surfaceHolder) {
            super.onCreate(surfaceHolder);
            setTouchEventsEnabled(true);
            surfaceHolder.setSizeFromLayout();
            surfaceHolder.setFormat(PixelFormat.RGB_888);
 
            DisplayMetrics metrics = new DisplayMetrics();
            ((WindowManager) getApplication().getSystemService(Service.WINDOW_SERVICE))
                    .getDefaultDisplay().getMetrics(metrics);
            mDensityDPI = metrics.densityDpi;
        } 
 
        @Override 
        public void onDestroy() { 
            super.onDestroy(); 
            destroyRenderer(); 
        } 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android SurfaceHolder Questions & Answers:

See Code Examples for Android SurfaceHolder Methods: