Android Question Converting Android "Studio" syntax to "B4A"

Christopher Brown

Member
Licensed User
Longtime User
Bear with me via a brief intro ...

I'm trying to scan QR codes. I installed "ABCameraTest" which in turn loads "BarCodeScanner" (ZXing?)
But it has major drawbacks: The scanner will only work in landscape - even if activity set to portrait- it has a small viewfinder and needs a high contrast scan to work. (I understand the wording beneath can be changed with "intent.PutExtra" if such a command exists in B4A)

So I'm looking at Zbar, which -from past experience of the Windows version - appears to be very tolerant to errors. I gave it some deliberately Gaussian blurred JPG's, angled at 45 degrees, and it managed to decode them. I gave it four images on a jpeg ... and it found all four barcodes.

True, I'm now operating with an Android camera rather than images, but if it can cope with one ...

This has been "ported" to Android ... but the syntax is based on Studio / Eclipse methodology, and obviously they do not match the variables that B4A uses.

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:eek:rientation="vertical"
android:padding="5dp"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

< Button
android:id="@+id/qrscan_btn"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/scan_only_qr_codes" />

< EditText
android:id="@+id/edtTxt_Result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >

< requestFocus />
< /EditText>

< /LinearLayout>


This I can decode as simple buttons and TextEdit items, with the width set to full screen. However ...

main Activity:
private static final int ZBAR_QR_SCANNER_REQUEST = 1;

onCreate() method:
((Button) findViewById(R.id.qrscan_btn)).setOnClickListener(this);

public void launchQRScanner() {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES,
new int[] { Symbol.QRCODE });
startActivityForResult(intent, ZBAR_QR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public boolean isCameraAvailable() {
PackageManager pm = getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

---
@override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {

case ZBAR_QR_SCANNER_REQUEST:
if (resultCode == RESULT_OK) {
passCodeValue.setText(data
.getStringExtra(ZBarConstants.SCAN_RESULT));

} else if (resultCode == RESULT_CANCELED && data != null) {
String error = data.getStringExtra(ZBarConstants.ERROR_INFO);
if (!TextUtils.isEmpty(error)) {
}
}
break;
}
}
---

Manifest (know where this goes - I think!)
< uses-permission android:name="android.permission.CAMERA" />
< uses-feature
android:name="android.hardware.camera"
android:required="false" />
---
(???)
< activity
android:name="com.dm.zbar.android.scanner.ZBarScannerActivity"
android:label="@string/app_name"
android:screenOrientation="landscape" />


Can anyone help to 'decode' this into B4A parlance?
 

DonManfred

Expert
Licensed User
Longtime User
USE CODE TAGs when posting code or manifest-code here!

codetag001.png


codetag002.png


codetag003.png


AND you dont need to create a POLL just to ask something... Just use the FIRST CREATE THREAD button. Not the second one at the bottom... This is just needed if you want to create a poll. Usually it is NOT needed
 
Upvote 0

Christopher Brown

Member
Licensed User
Longtime User
Thanks for your advice on using the code option; I'll remember that for the next post.

As for the poll, I thought I'd add that to see how many other people might be interested in a Zbar to B4A port. If enough people responded, my theory was that perhaps some programmers with more knowledge than me might take up the gantlet and convert the code.
 
Upvote 0
Top