CameraView
Custom Camera View (imitate wechat photo control, click to take photos, long press to record small video)
Sample screenshots
Git has a slight lag
Using the step
Android Studio
Add the following code to Project Gradle
allprojects {
repositories {
jcenter()
maven {
url 'https://dl.bintray.com/cjt/maven'
}
}
}
Copy the code
Add the following code to Module Gradle
The compile 'CJT. Library. Wheel: camera: 0.0.1'Copy the code
Add to the layout file
<com.cjt2325.cameralibrary.JCameraView
android:id="@+id/cameraview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Copy the code
Add permissions in androidmanifest.xml
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />Copy the code
Activity Sets the full screen
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Copy the code
Initialize the controller
private JCameraView mJCameraView; mJCameraView = (JCameraView) findViewById(R.id.cameraview); mJCameraView.setCameraViewListener(new JCameraView.CameraViewListener() { @Override public void quit() { MainActivity.this.finish(); } @Override public void captureSuccess(Bitmap bitmap) { Toast.makeText(MainActivity.this, + bitmap.getheight (), toast.length_short).show(); } @override public void recordSuccess(String url) {toast.maketext (MainActivity. Toast.LENGTH_SHORT).show(); }});Copy the code
The life cycle
@Override
protected void onResume() {
super.onResume();
mJCameraView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mJCameraView.onPause();
}
Copy the code