I've set up the /android project of ZXing 1.7 as a library referenced by my main android app project. As a quick test / proof of concept, I have used the CaptureActivity, in the same manner as described here: http://damianflannery.wordpress.com/2011/06/13/integrate-zxing-barcod...
Mostly, things work well, I can launch the CaptureActivity and receive the scanned data in my activity that launched it. However, I get some really strange behaviour, which I think may be related to resource IDs conflicting between my project and the /android ZXing project. This will take some explaining so please bear with me...
I launch the CaptureActivity with this code:
Button scanBtn = (Button)findViewById(R.id.mainmenu_btn_scan);
scanBtn.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent("com.google.zxing.client.android.SCAN");
i.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(i, SCAN_CODE);
}
});
mainmenu_btn_scan
is defined in menu.xml:
<LinearLayout android:id="@+id/mainmenu_view" style="@style/MainMenu" xmlns:android="http://schemas.android.com/apk/res/android">
...
<Button android:id="@+id/mainmenu_btn_scan"
android:drawableTop="@drawable/btn_scan_drawable"
style="@style/MainMenuButton"
android:text="Scan"/>
...
</LinearLayout>
btn_scan_drawable.xml is in /drawable, and is a drawable selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/scan_btn_pressed" android:state_focused="true" android:state_pressed="true" />
...
</selector>
The stange problem is this: when I hold the phone in a lanscape orientation and launch the CaptureActivity, I see the scan_btn_pressed image stretched across the display, and another copy of it also stretched across the "Place a barcode inside the viewfinder rectangle text...". This only occurs when I launch the activity while holding the phone in landscape orientation.
I discovered that if I replace
android:drawableTop="@drawable/btn_scan_drawable"
with
android:drawableTop="@drawable/scan_btn_pressed"
The problem goes away and everything works perfectly, but I want to get it working with the selector (and understand why the problem occurs). How can a drawable from my activity's UI mysteriously show up in another activity? I'm new to Android development, but I've been googling and working at this issue all day and I can't seem to find out why this would be happening apart from some vague references to resource ID conflicts in the android docs.
Note: I am using CaptureActivity as a rapid prototype / proof of concept only. I will implement my own activity leveraging the ZXIng library for the final app.