ResistorScanner icon indicating copy to clipboard operation
ResistorScanner copied to clipboard

Enable macro mode

Open ghost opened this issue 10 years ago • 3 comments

Hello

on the S3 jellybean detection does not work because camera can not focus close enough.

Here I added a checkbox in the main view after Seekbar

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Macro"
        android:id="@+id/btnMacro"
        android:layout_above="@+id/CameraZoomControls"
        android:layout_centerHorizontal="true" />

Then I added code in CameraView to handle the checkbox

    public void setMacroControl(CheckBox macroControl)
    {
        _macroControl = macroControl;
        _macroControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Camera.Parameters params = mCamera.getParameters();
                List<String> FocusModes = params.getSupportedFocusModes();
                if (isChecked) {
                    if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_MACRO)) {
                        params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
                    }
                } else {
                    if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
                        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
                    } else if (FocusModes != null && FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
                        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                    }

                }
                mCamera.setParameters(params);
            }
        });
    }

it is enabled in main activity with:

_resistorCameraView.setMacroControl((CheckBox) findViewById(R.id.btnMacro));

It will be very useful.

ghost avatar Sep 15 '15 08:09 ghost

Nice! If you make a pull request, I can merge these changes in.

thegouger avatar Sep 15 '15 13:09 thegouger

you can also use some old fashioned copy-paste! I dont want to fork and all for 10 code lines :)

This code just has to be added, there is nothing to remove.

f4grx avatar Sep 15 '15 14:09 f4grx

Heh, touché

thegouger avatar Sep 15 '15 14:09 thegouger