Zxings barscanner app, I have implemented it, as a library project, and it works.
Now I am to change the size of the field(Target Field) which is scanned (done as well). (though the scanning area remains the same, this didn't matter since focus was still in center.)
But then I needed to insert a menu in the left side. This forces me to change the Target Field, and this is were it starts crashing, if I change the size of the surfaceview or viewFinderView and if I wrap it in a relative view, it still decodes only the center(of cause). I just can't figure out a solution :-/
Short: I am able to change the area where the scan should be happening but this is only visible. The actual scanned area is still the center of the complete screen and not the center of the moved visible scan area.
Can anyone help me?
layout XML (with the menu inserted, and unnecessary removed):
<SurfaceView
android:id="@+id/preview_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.google.zxing.client.android.ViewfinderView
android:layout_marginLeft="120dip"
android:id="@+id/viewfinder_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/transparent" />
<LinearLayout
android:id="@+id/buttonPanel"
android:layout_width="120dip"
android:layout_height="fill_parent"
android:background="#000"
android:orientation="vertical"
android:paddingBottom="15dip"
android:paddingTop="15dip" >
<TextView
android:id="@+id/menuText"
android:layout_weight="1"
android:layout_width="90dip"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:text="@string/menu_title"/>
<ImageView
android:id="@+id/d1Button"
android:layout_width="90dip"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_weight="2"
android:onClick="scanner1d"
android:src="@drawable/d1image" />
<ImageView
android:id="@+id/d2Button"
android:layout_width="90dip"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_weight="2"
android:onClick="scanner2d"
android:src="@drawable/d2image" />
</LinearLayout>
<LinearLayout
android:id="@+id/result_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/result_view"
android:orientation="vertical"
android:padding="4dip"
android:visibility="gone" >
**removed**
</LinearLayout>
**removed**
Left picture: Is how the view is now and item placed where it is not being recognized.
Right picture: Item placed where it is recognized (How I check that target area is not changed):
Changes to CameraManager (squeezing of the viewfinder):
public Rect getFramingRect() {
// added
int menuSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 120, context.getResources().getDisplayMetrics());
// end of added
Point screenResolution = configManager.getScreenResolution();
if (framingRect == null) {
if (camera == null) {
return null;
}
int width = screenResolution.x * 3 / 4;
if (width < MIN_FRAME_WIDTH) {
width = MIN_FRAME_WIDTH;
} else if (width > MAX_FRAME_WIDTH) {
width = MAX_FRAME_WIDTH;
}
int height = screenResolution.y * 3 / 4;
if (height < MIN_FRAME_HEIGHT) {
height = MIN_FRAME_HEIGHT;
} else if (height > MAX_FRAME_HEIGHT) {
height = MAX_FRAME_HEIGHT;
}
// added menu size for calculation
int leftOffset = ((screenResolution.x -menuSize - width) / 2);
int topOffset = (screenResolution.y - height) / 2;
framingRect = new Rect(leftOffset, topOffset, leftOffset + width,
topOffset + height);
Log.d(TAG, "Calculated framing rect: " + framingRect);
}
return framingRect;
}
Now I have taken it all out into a small project which can be found here (problem fixed, were missing a lib) oct 18 10:14 CET
If you squeeze both the surfaceview together with the viewfinderview, it will actually work.
Though you have to take into consideration that the image is squeezed, so the target rectangle has to be that much smaller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With