use of com.tbruyelle.rxpermissions.Permission in project RxPermissions by tbruyelle.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RxPermissions rxPermissions = new RxPermissions(this);
rxPermissions.setLogging(true);
setContentView(R.layout.act_main);
surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
RxView.clicks(findViewById(R.id.enableCamera)).compose(rxPermissions.ensureEach(Manifest.permission.CAMERA)).subscribe(new Action1<Permission>() {
@Override
public void call(Permission permission) {
Log.i(TAG, "Permission result " + permission);
if (permission.granted) {
releaseCamera();
camera = Camera.open(0);
try {
camera.setPreviewDisplay(surfaceView.getHolder());
camera.startPreview();
} catch (IOException e) {
Log.e(TAG, "Error while trying to display the camera preview", e);
}
} else if (permission.shouldShowRequestPermissionRationale) {
// Denied permission without ask never again
Toast.makeText(MainActivity.this, "Denied permission without ask never again", Toast.LENGTH_SHORT).show();
} else {
// Denied permission with ask never again
// Need to go to the settings
Toast.makeText(MainActivity.this, "Permission denied, can't enable the camera", Toast.LENGTH_SHORT).show();
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable t) {
Log.e(TAG, "onError", t);
}
}, new Action0() {
@Override
public void call() {
Log.i(TAG, "OnComplete");
}
});
}
Aggregations