| | |
| | | import me.yokeyword.fragmentation.SupportFragment; |
| | | import safeluck.drive.evaluation.R; |
| | | import safeluck.drive.evaluation.customview.AutoFitTextureView; |
| | | import safeluck.drive.evaluation.util.MyLog; |
| | | |
| | | /** |
| | | * MyApplication2 |
| | |
| | | @Override |
| | | public void onOpened(@NonNull CameraDevice cameraDevice) { |
| | | // This method is called when the camera is opened. We start camera preview here. |
| | | MyLog.i(TAG,"Camera Device onOpened"); |
| | | mCameraOpenCloseLock.release(); |
| | | mCameraDevice = cameraDevice; |
| | | createCameraPreviewSession(); |
| | |
| | | |
| | | @Override |
| | | public void onDisconnected(@NonNull CameraDevice cameraDevice) { |
| | | MyLog.i(TAG,"Camera Device onDisconnected"); |
| | | mCameraOpenCloseLock.release(); |
| | | cameraDevice.close(); |
| | | mCameraDevice = null; |
| | |
| | | |
| | | @Override |
| | | public void onError(@NonNull CameraDevice cameraDevice, int error) { |
| | | MyLog.i(TAG,"Camera Device onError"); |
| | | mCameraOpenCloseLock.release(); |
| | | cameraDevice.close(); |
| | | mCameraDevice = null; |
| | |
| | | // Find out if we need to swap dimension to get the preview size relative to sensor |
| | | // coordinate. |
| | | int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); |
| | | MyLog.i(TAG,"displayRotation="+displayRotation); |
| | | //noinspection ConstantConditions |
| | | mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); |
| | | boolean swappedDimensions = false; |
| | |
| | | int rotatedPreviewHeight = height; |
| | | int maxPreviewWidth = displaySize.x; |
| | | int maxPreviewHeight = displaySize.y; |
| | | |
| | | MyLog.i(TAG,"swappedDimensions="+swappedDimensions); |
| | | if (swappedDimensions) { |
| | | rotatedPreviewWidth = height; |
| | | rotatedPreviewHeight = width; |
| | |
| | | mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), |
| | | rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, |
| | | maxPreviewHeight, largest); |
| | | |
| | | MyLog.i(TAG,"chooseOptimalSize="+mPreviewSize.getWidth()+":"+mPreviewSize.getHeight()); |
| | | // We fit the aspect ratio of TextureView to the size of preview we picked. |
| | | int orientation = getResources().getConfiguration().orientation; |
| | | MyLog.i(TAG,"getResources().getConfiguration().orientation="+orientation); |
| | | if (orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| | | mTextureView.setAspectRatio( |
| | | mPreviewSize.getWidth(), mPreviewSize.getHeight()); |
| | |
| | | mFlashSupported = available == null ? false : available; |
| | | |
| | | mCameraId = cameraId; |
| | | MyLog.i(TAG,"CameraID="+mCameraId+ " FlashSupported="+mFlashSupported); |
| | | return; |
| | | } |
| | | } catch (CameraAccessException e) { |
| | |
| | | RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth()); |
| | | float centerX = viewRect.centerX(); |
| | | float centerY = viewRect.centerY(); |
| | | MyLog.i(TAG,"configureTransform centerX="+centerX+" CenterY="+centerY+" getDefaultDisplay().getRotation()="+rotation); |
| | | if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) { |
| | | bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); |
| | | matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); |