Example usage for org.opencv.android CameraBridgeViewBase CAMERA_ID_BACK

List of usage examples for org.opencv.android CameraBridgeViewBase CAMERA_ID_BACK

Introduction

In this page you can find the example usage for org.opencv.android CameraBridgeViewBase CAMERA_ID_BACK.

Prototype

int CAMERA_ID_BACK

To view the source code for org.opencv.android CameraBridgeViewBase CAMERA_ID_BACK.

Click Source Link

Usage

From source file:com.davidmiguel.gobees.monitoring.MonitoringFragment.java

License:Open Source License

@Nullable
@Override//from  w  w w  .  jav a2  s.c om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.monitoring_frag, container, false);

    // Configure OpenCV callback
    loaderCallback = new BaseLoaderCallback(getContext()) {
        @Override
        public void onManagerConnected(final int status) {
            if (status == LoaderCallbackInterface.SUCCESS) {
                presenter.onOpenCvConnected();
            } else {
                super.onManagerConnected(status);
            }
        }
    };

    // Don't switch off screen
    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Configure camera
    cameraView = (CameraView) root.findViewById(R.id.camera_view);
    cameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_BACK);
    cameraView.setMaxFrameSize(MAX_WIDTH, MAX_HEIGHT);
    // Configure view
    numBeesTV = (TextView) root.findViewById(R.id.num_bees);
    settingsLayout = (RelativeLayout) getActivity().findViewById(R.id.settings);
    chronometer = (Chronometer) root.findViewById(R.id.chronometer);

    // Configure icons
    settingsIcon = (ImageView) root.findViewById(R.id.settings_icon);
    settingsIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            presenter.openSettings();
        }
    });
    recordIcon = (ImageView) root.findViewById(R.id.record_icon);
    recordIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            presenter.startMonitoring();
        }
    });

    // Configure service connection
    mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder service) {
            MonitoringBinder binder = (MonitoringBinder) service;
            mService = binder.getService(new GoBeesDataSource.SaveRecordingCallback() {
                @Override
                public void onRecordingTooShort() {
                    // Finish activity with error
                    Intent intent = new Intent();
                    intent.putExtra(HiveRecordingsFragment.ARGUMENT_MONITORING_ERROR,
                            HiveRecordingsFragment.ERROR_RECORDING_TOO_SHORT);
                    getActivity().setResult(Activity.RESULT_CANCELED, intent);
                    getActivity().finish();

                }

                @Override
                public void onSuccess() {
                    // Finish activity with OK
                    getActivity().setResult(Activity.RESULT_OK);
                    getActivity().finish();
                }

                @Override
                public void onFailure() {
                    // Finish activity with error
                    Intent intent = new Intent();
                    intent.putExtra(HiveRecordingsFragment.ARGUMENT_MONITORING_ERROR,
                            HiveRecordingsFragment.ERROR_SAVING_RECORDING);
                    getActivity().setResult(Activity.RESULT_CANCELED, intent);
                    getActivity().finish();
                }
            });
            // Set chronometer
            chronometer.setBase(mService.getStartTime());
            chronometer.setVisibility(View.VISIBLE);
            chronometer.start();
        }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            mService = null;
        }
    };
    return root;
}