Example usage for android.hardware Camera getCameraInfo

List of usage examples for android.hardware Camera getCameraInfo

Introduction

In this page you can find the example usage for android.hardware Camera getCameraInfo.

Prototype

public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) 

Source Link

Document

Returns the information about a particular camera.

Usage

From source file:com.czh.testmpeg.videorecord.CameraActivity.java

/**
 * ??,-1//  w  w  w .  j av a 2s . c o  m
 *
 * @return cameraId
 */
private int findBackFacingCamera() {
    int cameraId = -1;
    //??
    int numberOfCameras = Camera.getNumberOfCameras();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            cameraId = i;
            cameraFront = false;
            break;
        }
    }
    return cameraId;
}

From source file:com.TaxiDriver.jy.CameraPreview.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Hide the window title.
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.camera);//from   ww  w . j a  va2s.c o  m

    // Create a RelativeLayout container that will hold a SurfaceView,
    // and set it as the content of our activity.
    mPreview = new Preview(this);
    ((FrameLayout) findViewById(R.id.preview)).addView(mPreview);
    buttonRetry = (Button) findViewById(R.id.buttonRetry);
    buttonSend = (Button) findViewById(R.id.buttonSend);

    buttonClick = (Button) findViewById(R.id.buttonClick);
    buttonClick.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            mCamera.takePicture(null, null, jpegCallback);

        }
    });

    // Find the total number of cameras available
    numberOfCameras = Camera.getNumberOfCameras();

    // Find the ID of the default camera
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < numberOfCameras; i++) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
            defaultCameraId = i;
        }
    }
}

From source file:com.jasompeter.openalpr.CameraActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_camera);

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    mTorchButton = (ImageButton) findViewById(R.id.torch_button);
    mCapturingText = (TextView) findViewById(R.id.capturing_text);
    mTouchToCaptureText = (TextView) findViewById(R.id.touch_to_capture);
    mSurfaceHolder = surfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    // we should not open camera on UI thread
    mCameraOpenTask = new AsyncTask<Void, Void, Void>() {
        @Override/*from   w w w. ja  v  a  2s .co m*/
        protected Void doInBackground(Void[] params) {

            if (!mCameraIsOpen) {
                releaseCameraAndPreview();
                try {

                    int cameraCount = Camera.getNumberOfCameras();
                    Log.d(TAG, "We have " + cameraCount + " cameras.");
                    for (int i = 0; i < cameraCount; i++) {
                        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
                        Camera.getCameraInfo(i, cameraInfo);
                        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                            mCameraId = i;
                            break;
                        }
                    }

                    mCamera = Camera.open(mCameraId);
                    mCameraIsOpen = true;
                } catch (Exception e) {
                    mCameraIsOpen = false;
                    Log.d(TAG, "Failed to open camera. Camera is probably in use.");
                }
            }

            return null;
        }

        @Override
        protected void onPostExecute(Void o) {
            onCameraOpened(mCamera != null);
        }
    };

    // orientation manager handles orientation changes
    // because our activity is set to force landscape mode
    // and we may want rotate action buttons or do something with view
    mOrientationManager = new OrientationManager(this, SensorManager.SENSOR_DELAY_NORMAL, this);

    invalidateTorchButton();
    mTorchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            toggleTorch();
        }
    });

    initializeAlpr();

    surfaceView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mEnableRecognition = true;
                mCapturingText.setVisibility(View.VISIBLE);
                mTouchToCaptureText.setVisibility(View.GONE);
                return true; // if you want to handle the touch event
            case MotionEvent.ACTION_UP:
                mEnableRecognition = false;
                mCapturingText.setVisibility(View.GONE);
                mTouchToCaptureText.setVisibility(View.VISIBLE);
                return true; // if you want to handle the touch event
            }
            return false;
        }
    });

}

From source file:com.groundupworks.partyphotobooth.fragments.CaptureFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final KioskActivity activity = (KioskActivity) getActivity();
    final Context appContext = activity.getApplicationContext();
    final Bundle args = getArguments();
    final int totalFrames = args.getInt(FRAGMENT_BUNDLE_KEY_TOTAL_FRAMES);
    final int currentFrame = args.getInt(FRAGMENT_BUNDLE_KEY_CURRENT_FRAME);

    /*/*from  w  ww  . ja va  2s.com*/
     * Select camera from preference.
     */
    // Get from preference.
    PreferencesHelper preferencesHelper = new PreferencesHelper();
    PhotoBoothMode mode = preferencesHelper.getPhotoBoothMode(appContext);

    int cameraPreference = CameraInfo.CAMERA_FACING_FRONT;
    if (PhotoBoothMode.PHOTOGRAPHER.equals(mode)) {
        cameraPreference = CameraInfo.CAMERA_FACING_BACK;
    }

    // Default to first camera available.
    final int numCameras = Camera.getNumberOfCameras();
    if (numCameras > 0) {
        mCameraId = 0;
    }

    // Select preferred camera.
    CameraInfo cameraInfo = new CameraInfo();
    for (int cameraId = 0; cameraId < numCameras; cameraId++) {
        Camera.getCameraInfo(cameraId, cameraInfo);

        // Break on finding the preferred camera.
        if (cameraInfo.facing == cameraPreference) {
            mCameraId = cameraId;
            break;
        }
    }

    /*
    * Initialize and set key event handlers.
    */
    mKeyEventHandler = new KioskActivity.KeyEventHandler() {
        @Override
        public boolean onKeyEvent(KeyEvent event) {
            final int keyCode = event.getKeyCode();
            if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mStartButton.dispatchKeyEvent(event);
                return true;
            }
            return false;
        }
    };
    activity.setKeyEventHandler(mKeyEventHandler);

    /*
     * Functionalize views.
     */
    // Configure start button and trigger behaviour.
    switch (mode) {
    case PHOTOGRAPHER:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCapture();
                return true;
            }
        });
        linkStartButton();
        break;
    case AUTOMATIC:
        if (currentFrame > 1) {
            // Auto-trigger when camera is ready and preview has started.
            mPreview.setOnPreviewListener(new CenteredPreview.OnPreviewListener() {
                @Override
                public void onStarted() {
                    if (isActivityAlive()) {
                        mPreview.post(new Runnable() {
                            @Override
                            public void run() {
                                if (isActivityAlive()) {
                                    initiateCountdownCapture();
                                }
                            }
                        });
                    }
                }

                @Override
                public void onStopped() {
                    // Do nothing.
                }
            });
            break;
        } else {
            // Fall through to self-serve behaviour. Do not break.
        }
    case SELF_SERVE:
    default:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCountdownCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCountdownCapture();
                return true;
            }
        });
        linkStartButton();
    }

    // Show frame count only if more than one frame is to be captured.
    if (totalFrames > 1) {
        String frameCountText = getString(R.string.capture__frame_count, currentFrame, totalFrames);
        mFrameCount.setTypeface(
                Theme.from(appContext, preferencesHelper.getPhotoBoothTheme(appContext)).getFont());
        mFrameCount.setText(frameCountText);
        mFrameCount.setVisibility(View.VISIBLE);
    }
}

From source file:com.fatelon.partyphotobooth.fragments.CaptureFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    final KioskActivity activity = (KioskActivity) getActivity();
    final Context appContext = activity.getApplicationContext();
    final Bundle args = getArguments();
    final int totalFrames = args.getInt(FRAGMENT_BUNDLE_KEY_TOTAL_FRAMES);
    final int currentFrame = args.getInt(FRAGMENT_BUNDLE_KEY_CURRENT_FRAME);

    /*/*  ww  w  . ja  v a 2s  . c  o m*/
     * Select camera from preference.
     */
    // Get from preference.
    PreferencesHelper preferencesHelper = new PreferencesHelper();
    mPhotoBoothMode = preferencesHelper.getPhotoBoothMode(appContext);

    int cameraPreference = CameraInfo.CAMERA_FACING_FRONT;
    if (PreferencesHelper.PhotoBoothMode.PHOTOGRAPHER.equals(mPhotoBoothMode)) {
        cameraPreference = CameraInfo.CAMERA_FACING_BACK;
    }

    // Default to first camera available.
    final int numCameras = Camera.getNumberOfCameras();
    if (numCameras > 0) {
        mCameraId = 0;
    }

    // Select preferred camera.
    CameraInfo cameraInfo = new CameraInfo();
    for (int cameraId = 0; cameraId < numCameras; cameraId++) {
        Camera.getCameraInfo(cameraId, cameraInfo);

        // Break on finding the preferred camera.
        if (cameraInfo.facing == cameraPreference) {
            mCameraId = cameraId;
            break;
        }
    }

    /*
    * Initialize and set key event handlers.
    */
    mKeyEventHandler = new KioskActivity.KeyEventHandler() {
        @Override
        public boolean onKeyEvent(KeyEvent event) {
            final int keyCode = event.getKeyCode();
            if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mStartButton.dispatchKeyEvent(event);
                return true;
            }
            return false;
        }
    };
    activity.setKeyEventHandler(mKeyEventHandler);

    /*
     * Functionalize views.
     */
    // Configure start button and trigger behaviour.
    switch (mPhotoBoothMode) {
    case PHOTOGRAPHER:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCapture();
                return true;
            }
        });
        linkStartButton();
        break;
    case AUTOMATIC:
        mStartButtonLong.setVisibility(View.VISIBLE);
        mStartButton.setVisibility(View.GONE);
        mStartButton = mStartButtonLong;
        if (currentFrame > 1) {
            // Auto-trigger when camera is ready and preview has started.
            mPreview.setOnPreviewListener(new CenteredPreview.OnPreviewListener() {
                @Override
                public void onStarted() {
                    if (isActivityAlive()) {
                        mPreview.post(new Runnable() {
                            @Override
                            public void run() {
                                if (isActivityAlive()) {
                                    initiateCountdownCapture();
                                }
                            }
                        });
                    }
                }

                @Override
                public void onStopped() {
                    // Do nothing.
                }
            });
            break;
        } else {
            // Fall through to self-serve behaviour. Do not break.
        }
    case SELF_SERVE:
    default:
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initiateCountdownCapture();
            }
        });
        mStartButton.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                initiateCountdownCapture();
                return true;
            }
        });
        linkStartButton();
    }

    // Show frame count only if more than one frame is to be captured.
    if (totalFrames > 1) {
        String frameCountText = getString(R.string.capture__frame_count, currentFrame, totalFrames);
        mFrameCount.setTypeface(
                Theme.from(appContext, preferencesHelper.getPhotoBoothTheme(appContext)).getFont());
        mFrameCount.setText(frameCountText);
        mFrameCount.setVisibility(View.VISIBLE);
    }
}

From source file:com.grayraven.barcoder.CameraActivityFragement.java

private boolean safeCameraOpen() {
    boolean qOpened = false;

    try {/*w w  w .j  a va2  s  . co  m*/
        stopPreviewAndFreeCamera();

        //get index of front camera
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        int count = Camera.getNumberOfCameras();
        for (int i = 0; i < count; i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                mCamera = Camera.open(i);
                mCameraId = i;
                break;
            }
        }
        qOpened = (mCamera != null);
    } catch (Exception e) {
        Log.e(getString(R.string.app_name), "failed to open Camera");
        e.printStackTrace();
    }

    return qOpened;
}

From source file:com.microsoft.mimickeralarm.utilities.GeneralUtilities.java

@SuppressWarnings("deprecation")
private static boolean hasDeviceCameraWithDirection(int cameraDirection) {
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {

        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == cameraDirection) {
            return true;
        }//from w ww. j  a  v  a 2s .  c  o  m
    }
    return false;
}

From source file:ru.jango.j0widget.camera.fragment.AbstractCameraFragment.java

/**
 * Returns angle in degrees that taken picture should be rotated by.
 *///from  ww  w  . j  a  v a2  s. c om
protected int getRotation() {
    final Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, cameraInfo);

    int displayOrientation = (cameraInfo.orientation - RotationUtil.getDisplayRotation(getActivity()) + 360)
            % 360;

    return (displayOrientation + 360) % 360;
}

From source file:uk.ac.horizon.artcodes.camera.CameraView.java

private void createCamera() {
    if (ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
        for (int cameraId = 0; cameraId < Camera.getNumberOfCameras(); cameraId++) {
            try {
                Camera.CameraInfo info = new Camera.CameraInfo();
                Camera.getCameraInfo(cameraId, info);

                if (info.facing == facing) {
                    openCamera(cameraId);
                    return;
                }/*from  w  w w  .  j av a 2 s  . c om*/
            } catch (RuntimeException e) {
                Log.e("Scanner", "Failed to open scanner " + cameraId + ": " + e.getLocalizedMessage(), e);
            }
        }

        for (int cameraId = 0; cameraId < Camera.getNumberOfCameras(); cameraId++) {
            try {
                openCamera(cameraId);
                return;
            } catch (RuntimeException e) {
                Log.e("Scanner", "Failed to open scanner " + cameraId + ": " + e.getLocalizedMessage(), e);
            }
        }
    }
}

From source file:ru.jango.j0widget.camera.fragment.AbstractCameraFragment.java

private int getBackwardCameraId() {
    for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
        final Camera.CameraInfo info = new Camera.CameraInfo();
        Camera.getCameraInfo(i, info);
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK)
            return i;
    }//w ww  .  j  a v  a  2  s. c  o m

    return 0;
}