Helper lib for Android camera2
Camera2HelperLib is a simple and lightweight library created to facilitate the use of Android’s Camera2 API.
Add jitpack.io to your project’s repositories:
allProjects {
repositories {
google()
// required to find the project's artifacts
// place last
maven { url "https://www.jitpack.io" }
}
}
Add this to your app’s build.gradle dependencies
gradle implementation 'com.danielebachicchi:camera2helperlib:0.0.4'
Camera Helper is an helper class that handle all the process of the open, close and processing image of the camera. In order to initialize it you have to pass to the constructor:
Usually you create the instance of the CameraHelper during onCreate of your Activity / Fragment.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Do your work
//retrieve the autofitTextureView inside the layout
AutoFitTextureView autoFitTextureView = findViewById(R.id.textureView);
_cameraHelper = new CameraHelper(autoFitTextureView,this,this);
}
In order for the class to function properly you have to call inside the onPause and onResume the respective methods of the CameraHelper:
@Override
protected void onResume() {
super.onResume();
_cameraHelper.onResume();
}
@Override
protected void onPause() {
super.onPause();
_cameraHelper.onPause();
}
With Live Mode active, you don’t have to manually request to take a picture. CameraHelper will capture a picture in background (outside the main thread) and it communicates it to your delegate.
This mode is helpfull especially for processing in real-time what the camera is seeing, like, for example, barcode or qrcode detect feature.
To enable the liveMode:
//enable the liveMode.
_cameraHelper.set_liveData(true);
//set the interval from one picture to another (in milliseconds).
_cameraHelper.set_liveDataMillisecondDelay(2000);
The delegate has the following method that need to implements:
void onAsyncImageDetected(Image image, CameraHelper.ImageSaver saver);
void onCameraPermissionNotAccepted(CameraHelper helper);
@Override
public void onCameraPermissionNotAccepted(CameraHelper helper) {
//you can call this helper method or handle yourself. As you wish :)
helper.requestCameraPermission(getSupportFragmentManager());
}
This project is created and mantained by:
Copyright 2019 Daniele Bachicchi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.