Example usage for android.view SurfaceHolder addCallback

List of usage examples for android.view SurfaceHolder addCallback

Introduction

In this page you can find the example usage for android.view SurfaceHolder addCallback.

Prototype

public void addCallback(Callback callback);

Source Link

Document

Add a Callback interface for this holder.

Usage

From source file:com.pyamsoft.zaptorch.service.OriginalCamera.java

@SuppressWarnings("WeakerAccess")
SurfaceHolder getInitializedHolder() {//ww w .j  av  a 2  s. c om
    final SurfaceHolder holder = surfaceView.getHolder();
    holder.addCallback(this);
    return holder;
}

From source file:com.google.android.cameraview.SurfaceViewPreview.java

SurfaceViewPreview(Context context, ViewGroup parent) {
    final View view = View.inflate(context, R.layout.surface_view, parent);
    mSurfaceView = (SurfaceView) view.findViewById(R.id.surface_view);
    final SurfaceHolder holder = mSurfaceView.getHolder();
    //noinspection deprecation
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(new SurfaceHolder.Callback() {
        @Override/*  w  ww.ja va2s . c o m*/
        public void surfaceCreated(SurfaceHolder h) {
        }

        @Override
        public void surfaceChanged(SurfaceHolder h, int format, int width, int height) {
            setSize(width, height);
            if (!ViewCompat.isInLayout(mSurfaceView)) {
                dispatchSurfaceChanged();
            }
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder h) {
            setSize(0, 0);
        }
    });
}

From source file:com.octopepper.mediapickerinstagram.commons.cameraview.api9.SurfaceViewPreview.java

public SurfaceViewPreview(Context context, ViewGroup parent) {
    final View view = View.inflate(context, R.layout.surface_view, parent);
    mSurfaceView = (SurfaceView) view.findViewById(R.id.surface_view);
    final SurfaceHolder holder = mSurfaceView.getHolder();
    //noinspection deprecation
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(new SurfaceHolder.Callback() {
        @Override//  w ww.j  a v a  2s  . c o m
        public void surfaceCreated(SurfaceHolder h) {
        }

        @Override
        public void surfaceChanged(SurfaceHolder h, int format, int width, int height) {
            setSize(width, height);
            if (!ViewCompat.isInLayout(mSurfaceView)) {
                dispatchSurfaceChanged();
            }
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder h) {
            setSize(0, 0);
        }
    });
}

From source file:com.brotherpowers.cameraview.SurfaceViewPreview.java

SurfaceViewPreview(Context context, ViewGroup parent) {
    final View view = View.inflate(context, R.layout.surface_view, parent);
    mSurfaceView = (SurfaceView) view.findViewById(R.id.surface_view);

    final SurfaceHolder holder = mSurfaceView.getHolder();
    //noinspection deprecation
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(new SurfaceHolder.Callback() {
        @Override/* w ww . ja  va 2s . c om*/
        public void surfaceCreated(SurfaceHolder h) {

        }

        @Override
        public void surfaceChanged(SurfaceHolder h, int format, int width, int height) {
            setSize(width, height);
            if (!ViewCompat.isInLayout(mSurfaceView)) {
                dispatchSurfaceChanged();
            }
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder h) {

            setSize(0, 0);
        }
    });

}

From source file:io.mariachi.allianzvision.camera.api9.SurfaceViewPreview.java

public SurfaceViewPreview(Context context, ViewGroup parent) {
    final View view = View.inflate(context, R.layout.surface_view, parent);
    mSurfaceView = (SurfaceView) view.findViewById(R.id.surface_view);
    final SurfaceHolder holder = mSurfaceView.getHolder();
    //noinspection deprecation
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(new SurfaceHolder.Callback() {
        @Override/*from   www  .j  a v  a2 s .co  m*/
        public void surfaceCreated(SurfaceHolder h) {

        }

        @Override
        public void surfaceChanged(SurfaceHolder h, int format, int width, int height) {
            setSize(width, height);
            if (!ViewCompat.isInLayout(mSurfaceView)) {
                dispatchSurfaceChanged();
            }
        }

        @Override
        public void surfaceDestroyed(SurfaceHolder h) {
            setSize(0, 0);
        }
    });

}

From source file:org.artoolkit.ar.samples.nftBook.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*from w ww .j a v  a2s .  c  om*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        nftBookActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.samples.ARNativeES1.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {//from   ww  w  .jav  a2 s.  c  o m
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARNativeES1Activity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.samples.ARNativeOSG.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*  w ww . j  a  v a 2s.co  m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARNativeOSGActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:org.artoolkit.ar.samples.ARNative.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*from ww w.j ava 2s.  c o  m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARNativeActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}

From source file:com.mobiuso.argo.ARModule.CameraSurface.java

@SuppressWarnings("deprecation")
public CameraSurface(Context context) {
    super(context);

    Log.i(TAG, "CameraSurface(): ctor called");
    Activity activityRef = (Activity) context;

    try {/*w w w .  j  av a 2s  .co  m*/
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(activityRef,
                    Manifest.permission.CAMERA)) {
                mustAskPermissionFirst = true;
                if (activityRef.shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
                    // Will drop in here if user denied permissions access camera before.
                    // Or no uses-permission CAMERA element is in the
                    // manifest file. Must explain to the end user why the app wants
                    // permissions to the camera devices.
                    Toast.makeText(activityRef.getApplicationContext(),
                            "App requires access to camera to be granted", Toast.LENGTH_SHORT).show();
                }
                // Request permission from the user to access the camera.
                Log.i(TAG, "CameraSurface(): must ask user for camera access permission");
                activityRef.requestPermissions(new String[] { Manifest.permission.CAMERA },
                        ARMovieActivity.REQUEST_CAMERA_PERMISSION_RESULT);
                return;
            }
        }
    } catch (Exception ex) {
        Log.e(TAG, "CameraSurface(): exception caught, " + ex.getMessage());
        return;
    }

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Deprecated in API level 11. Still required for API levels <= 10.
}