List of usage examples for android.content Context CAMERA_SERVICE
String CAMERA_SERVICE
To view the source code for android.content Context CAMERA_SERVICE.
Click Source Link
From source file:Main.java
/** * Returns {@code true} if this device only supports {@code LEGACY} mode operation in the * Camera2 API for the given camera ID./*from w w w. j a v a 2 s.c o m*/ * * @param context {@link Context} to access the {@link CameraManager} in. * @param cameraId the ID of the camera device to check. * @return {@code true} if this device only supports {@code LEGACY} mode. */ public static boolean isLegacyHAL(Context context, int cameraId) throws Exception { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); CameraCharacteristics characteristics = manager.getCameraCharacteristics(Integer.toString(cameraId)); return characteristics.get( CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY; }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButtonLights = (ToggleButton) findViewById(R.id.buttonLights); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { mCameraManager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE); mCameraId = getCameraId();/*from ww w. j a v a 2s. c o m*/ if (mCameraId == null) { mButtonLights.setEnabled(false); } else { mButtonLights.setEnabled(true); } } else { mButtonLights.setEnabled(false); } }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButtonLight = (ToggleButton) findViewById(R.id.buttonLight); mCameraManager = (CameraManager) this.getSystemService(Context.CAMERA_SERVICE); mCameraId = getCameraId();//from w w w . ja va2 s . c o m if (mCameraId == null) { mButtonLight.setEnabled(false); } else { mButtonLight.setEnabled(true); } }
From source file:com.elkriefy.android.apps.torchi.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); torchMode = false;//from w ww . j a v a2s .c om manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); mTorchiCallback = new torchiCallback(); FloatingActionButton button = (FloatingActionButton) findViewById(R.id.fab); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleTorchMode(); } }); }
From source file:com.pyamsoft.zaptorch.service.LollipopCamera.java
@CheckResult @NonNull//w w w. j a v a2s.c o m static CameraManager setupCameraManager(final @NonNull Context context) { return (CameraManager) context.getApplicationContext().getSystemService(Context.CAMERA_SERVICE); }
From source file:jp.co.fake.TryCatchRoman.presentation.view.camera2lib.Camera2StateMachine.java
public void open(Context activity, AutoFitTextureView textureView) { if (mState != null) { Log.d(TAG, "\"Alrady started state=\" : " + mState); return;//ww w. j av a 2 s . c o m } else { mContext = activity; mTextureView = textureView; mCameraManager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); nextState(mInitSurfaceState); } }
From source file:jp.co.fake.TryCatchRoman.domain.usecase.camera.Camera2StateMachine.java
public void open(AutoFitTextureView textureView, Context context) { if (mState != null) throw new IllegalStateException("Alrady started state=" + mState); mContext = context;/*from w ww .j a v a2s . com*/ mTextureView = textureView; mCameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE); nextState(mInitSurfaceState); }
From source file:com.example.lenny.barcodevison.ScanBarcodeActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scan_barcode); buttonFlash = (Button) findViewById(R.id.btnFlash); cameraPreview = (SurfaceView) findViewById(R.id.camera_preview); camManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); hasFlash = getApplicationContext().getPackageManager() .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); if (!hasFlash) { buttonFlash.setVisibility(View.INVISIBLE); } else {/*from w w w . ja va 2 s.c om*/ } buttonFlash.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isFlashOn) { flashLightOn(); buttonFlash.setText("FLASH\nOFF"); } else { flashLightOff(); buttonFlash.setText("FLASH\nON"); } } }); createCameraSource(); }
From source file:MainActivity.java
protected void takePicture(View view) { if (null == mCameraDevice) { return;//from w w w. java 2 s. c o m } CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraDevice.getId()); StreamConfigurationMap configurationMap = characteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (configurationMap == null) return; Size largest = Collections.max(Arrays.asList(configurationMap.getOutputSizes(ImageFormat.JPEG)), new CompareSizesByArea()); ImageReader reader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(), ImageFormat.JPEG, 1); List<Surface> outputSurfaces = new ArrayList<Surface>(2); outputSurfaces.add(reader.getSurface()); outputSurfaces.add(new Surface(mTextureView.getSurfaceTexture())); final CaptureRequest.Builder captureBuilder = mCameraDevice .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureBuilder.addTarget(reader.getSurface()); captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO); ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { Image image = null; try { image = reader.acquireLatestImage(); ByteBuffer buffer = image.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.capacity()]; buffer.get(bytes); OutputStream output = new FileOutputStream(getPictureFile()); output.write(bytes); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (image != null) { image.close(); } } } }; HandlerThread thread = new HandlerThread("CameraPicture"); thread.start(); final Handler backgroudHandler = new Handler(thread.getLooper()); reader.setOnImageAvailableListener(readerListener, backgroudHandler); final CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() { @Override public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { super.onCaptureCompleted(session, request, result); Toast.makeText(MainActivity.this, "Picture Saved", Toast.LENGTH_SHORT).show(); startPreview(session); } }; mCameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession session) { try { session.capture(captureBuilder.build(), captureCallback, backgroudHandler); } catch (CameraAccessException e) { e.printStackTrace(); } } @Override public void onConfigureFailed(CameraCaptureSession session) { } }, backgroudHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.google.android.apps.watchme.StreamerActivity.java
private void setupCamera(int width, int height) { CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try {/*ww w . j a va 2 s .c o m*/ for (String cameraIDs : cameraManager.getCameraIdList()) { CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraIDs); if (cameraCharacteristics .get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) { continue; } StreamConfigurationMap map = cameraCharacteristics .get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); //@edsonAndrade // Alike the camera api version of the app, I am forcing the app into the landscape mode int deviceOrientation = getWindowManager().getDefaultDisplay().getRotation(); int totalRotation = sensorToDeeviceRotation(cameraCharacteristics, deviceOrientation); boolean swapRotation = totalRotation == 90 || totalRotation == 270; int rotatedWidth = width; int rotatedHeight = height; if (swapRotation) { rotatedHeight = width; rotatedWidth = height; } previewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class), rotatedWidth, rotatedHeight); cameraId = cameraIDs; return; } } catch (CameraAccessException e) { e.printStackTrace(); } }