@Override protected void onStart() { super.onStart(); fotoapparat.start(); }
@Override protected void onStop() { fotoapparat.stop(); super.onStop(); }
private void takePhoto() { fab.setEnabled(false); PhotoResult result=fotoapparat.takePicture(); result.toBitmap().whenAvailable(new PendingResult.Callback<BitmapPhoto>() { @Override public void onResult(BitmapPhoto bitmapPhoto) { // TODO: do something with picture setResult(RESULT_OK); finish(); } }); } }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera); camera=findViewById(R.id.camera); fab=findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { takePhoto(); } }); fotoapparat=Fotoapparat .with(this) .into(camera) .previewScaleType(ScaleType.CENTER_CROP) .photoSize(biggestSize()) .lensPosition(back()) .focusMode(firstAvailable(continuousFocus(), autoFocus(), fixed())) .flash(firstAvailable(autoRedEye(), autoFlash())) .build(); }
fotoapparat = Fotoapparat.with(this).into(mCamera) .previewScaleType(ScaleType.CenterCrop) // we want the preview to fill the view .lensPosition(LensPositionSelectorsKt.back()) // we want back camera .focusMode(SelectorsKt.firstAvailable( // (optional) use the first focus mode which is supported by device FocusModeSelectorsKt.continuousFocusPicture(), FocusModeSelectorsKt.autoFocus(), // in case if continuous focus is not available on device, auto focus will be used FocusModeSelectorsKt.fixed() // if even auto focus is not available - fixed focus mode will be used )) .build(); mCamera.setOnTouchListener(onCameraTouchListner); fotoapparat.start(); fotoapparat.updateConfiguration(CameraConfiguration.builder().flash(FlashSelectorsKt.autoRedEye()).build()); recyclerView.addItemDecoration(new HeaderItemDecoration(this, mainImageAdapter)); mHandleView.setOnTouchListener(this); final CameraConfiguration cameraConfiguration = new CameraConfiguration(); if (options.isFrontfacing()) { fotoapparat.switchTo(LensPositionSelectorsKt.front(), cameraConfiguration); } else { fotoapparat.switchTo(LensPositionSelectorsKt.back(), cameraConfiguration);
private Fotoapparat createFotoapparat(LensPosition position) { return Fotoapparat .with(this) .into(cameraView) .lensPosition(lensPosition(position)) .frameProcessor( FaceDetectorProcessor.with(this) .listener(new FaceDetectorProcessor.OnFacesDetectedListener() { @Override public void onFacesDetected(List<Rectangle> faces) { Log.d("&&&", "Detected faces: " + faces.size()); rectanglesView.setRectangles(faces); } }) .build() ) .logger(loggers( logcat(), fileLogger(this) )) .build(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); cameraView = (CameraView) findViewById(R.id.camera_view); rectanglesView = (RectanglesView) findViewById(R.id.rectanglesView); hasCameraPermission = permissionsDelegate.hasCameraPermission(); if (hasCameraPermission) { cameraView.setVisibility(View.VISIBLE); } else { permissionsDelegate.requestCameraPermission(); } frontFotoapparat = createFotoapparat(LensPosition.FRONT); backFotoapparat = createFotoapparat(LensPosition.BACK); fotoapparatSwitcher = FotoapparatSwitcher.withDefault(backFotoapparat); View switchCameraButton = findViewById(R.id.switchCamera); switchCameraButton.setVisibility( canSwitchCameras() ? View.VISIBLE : View.GONE ); switchCameraButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switchCamera(); } }); }
@Override public void onClick(View view) { fotoapparat.takePicture().toBitmap().transform(new Function1<BitmapPhoto, Bitmap>() { @Override public Bitmap invoke(BitmapPhoto bitmapPhoto) { Log.e("my pick transform", bitmapPhoto.toString()); fotoapparat.stop(); return Utility.rotate(bitmapPhoto.bitmap, -bitmapPhoto.rotationDegrees); } }).whenAvailable(new Function1<Bitmap, Unit>() { @Override public Unit invoke(Bitmap bitmap) { if (bitmap != null) { Log.e("my pick", bitmap.toString()); synchronized (bitmap) { File photo = Utility.writeImage(bitmap, options.getPath(), options.getImageQuality(), options.getWidth(), options.getHeight()); Log.e("my pick saved", bitmap.toString() + " -> " + photo.length() / 1024); selectionList.clear(); selectionList.add(new Img("", "", photo.getAbsolutePath(), "")); returnObjects(); } } return null; } }); } });
@Override public void onClick(View view) { final ObjectAnimator oa1 = ObjectAnimator.ofFloat(front, "scaleX", 1f, 0f).setDuration(150); final ObjectAnimator oa2 = ObjectAnimator.ofFloat(front, "scaleX", 0f, 1f).setDuration(150); oa1.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); front.setImageResource(R.drawable.ic_photo_camera); oa2.start(); } }); oa1.start(); Log.e("isFrontfacing", "-> " + options.isFrontfacing()); if (options.isFrontfacing()) { options.setFrontfacing(false); final CameraConfiguration cameraConfiguration = new CameraConfiguration(); fotoapparat.switchTo(LensPositionSelectorsKt.back(), cameraConfiguration); } else { final CameraConfiguration cameraConfiguration = new CameraConfiguration(); options.setFrontfacing(true); fotoapparat.switchTo(LensPositionSelectorsKt.front(), cameraConfiguration); } } });
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (permissionsDelegate.resultGranted(requestCode, permissions, grantResults)) { fotoapparatSwitcher.start(); cameraView.setVisibility(View.VISIBLE); } }
private void switchCamera() { if (fotoapparatSwitcher.getCurrentFotoapparat() == frontFotoapparat) { fotoapparatSwitcher.switchTo(backFotoapparat); } else { fotoapparatSwitcher.switchTo(frontFotoapparat); } }
private boolean canSwitchCameras() { return frontFotoapparat.isAvailable() == backFotoapparat.isAvailable(); }
@Override protected void onStart() { super.onStart(); if (hasCameraPermission) { fotoapparatSwitcher.start(); } }
@Override protected void onStop() { super.onStop(); if (hasCameraPermission) { fotoapparatSwitcher.stop(); } }
@Override public boolean onTouch(View v, MotionEvent event) { if (event.getPointerCount() > 1) { switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: dist = Utility.getFingerSpacing(event); break; case MotionEvent.ACTION_MOVE: float maxZoom = 1f; float newDist = Utility.getFingerSpacing(event); if (newDist > dist) { //zoom in if (zoom < maxZoom) zoom = zoom + 0.01f; } else if ((newDist < dist) && (zoom > 0)) { //zoom out zoom = zoom - 0.01f; } dist = newDist; fotoapparat.setZoom(zoom); break; default: break; } } return true; } };
@Override protected void onResume() { super.onResume(); fotoapparat.start(); }
@Override protected void onPause() { fotoapparat.stop(); super.onPause(); }
@Override protected void onRestart() { super.onRestart(); initialize(); fotoapparat.start(); }
@Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { Utility.manipulateVisibility(Pix.this, slideOffset, instantRecyclerView, recyclerView, status_bar_bg, topbar, bottomButtons, sendButton, LongSelection); if (slideOffset == 1) { Utility.showScrollbar(mScrollbar, Pix.this); mainImageAdapter.notifyDataSetChanged(); mViewHeight = mScrollbar.getMeasuredHeight(); handler.post(new Runnable() { @Override public void run() { setViewPositions(getScrollProportion(recyclerView)); } }); sendButton.setVisibility(View.GONE); // fotoapparat.stop(); } else if (slideOffset == 0) { initaliseadapter.notifyDataSetChanged(); hideScrollbar(); img_count.setText(String.valueOf(selectionList.size())); fotoapparat.start(); } } });