Skip to main content
Version: 2.6.4

Examples

Set new Region of interest with new Camera orientation

This example can be used to scan BVR in a portrait application (the must be put in landscape).

Display display = getActivity().getWindowManager().getDefaultDisplay();
int stageWidth = display.getWidth();
int stageHeight = display.getHeight();
int width = stageWidth, height = stageHeight;
if(width > height)
// Set new ROI
mSmartScanner.setRegionOfInterest(new Rect(height / 100 * 15,width / 10 ,width / 100 * 95,height / 100 * 80));
else {
/**
* Set the new orientation decoding on the device. By activating this mode you must manage the ROI manually.
* @param forceOrientationEnabled true if the decoder should decode in manual orientation
* @param scanOrientation the orientation for decoding.The options are: LANDSCAPE_MODE, LANDSCAPE_REVERSE_MODE, PORTRAIT_MODE, PORTRAIT_REVERSE_MODE
*
*/
mSmartScanner.setOrientationDecoding(true, SmartScanner.LANDSCAPE_MODE);
mSmartScanner.setRegionOfInterest(new Rect(height / 100 * 10, width / 100 * 15, width / 100 * 85, height / 100 * 90));
}

Flash

Enable/disable the flash with a toggle button

...
someToggleButton.setOnCheckedChangeListener(flashModeLister);
...

private CompoundButton.OnCheckedChangeListener flashModeLister = new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
mSmartScanner.setFlashEnabled(true);
else
mSmartScanner.setFlashEnabled(false);
}
};

Enable/disable Auto-Focus

Enable/disable the Auto-Focus with a toggle button

...
someToggleButton.setOnCheckedChangeListener(focusModeLister);
...

private CompoundButton.OnCheckedChangeListener focusModeLister = new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
mSmartScanner.setAutoFocusEnabled(true);
else
mSmartScanner.setAutoFocusEnabled(false);
}
};


Manual focus

On main layout put the focus view

<View
android:id="@+id/focus"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
android:background="@drawable/rectangle" />

Add to drawable folder the new shape

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="#00000000" />

<stroke
android:width="1dp"
android:color="#8BC34A" />

<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />

</shape>
/**
* On double tap we switch to manual focus. We try focusing on the region were the double tap was done.
* @param x Position on x axis on the screen
* @param y Position on y axis on the screen
* @param view View where we will draw the focus rectangle
* @param isFocusRectangleVisible Option to draw the focus rectangle or not
*/

mSmartScanner.manualFocus(mPrimStartTouchEventX, mPrimStartTouchEventY, root.findViewById(R.id.focus), true);