I am developing an app to query qr in a database but I am having problems with the camera I am using the ZXING library to capture the QR data and generate the query
But fragment is only adapting a part of the camera, I share the XML and the class of the camera to see if they help me.
Class
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class Camera extends Fragment implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
public static boolean mAutoFocus = false;
public static int mCameraId = -1;
class C03012 implements Runnable {
C03012() {
}
public void run() {
mScannerView.startCamera();
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mScannerView = new ZXingScannerView(getActivity());
mScannerView.setResultHandler(this);
mScannerView.startCamera();
mScannerView.setAutoFocus(true);
return mScannerView;
}
@Override
public void handleResult(Result rawResult) {
mScannerView.resumeCameraPreview(this);
String sendTxt;
sendTxt = rawResult.toString();
Search search = new Search();
search.setConsult(sendTxt);
((MainActivity)getActivity()).recibirTexto(sendTxt);
mScannerView.postDelayed(new C03012(),20000000);
}
@Override
public void onPause() {
super.onPause();
mScannerView.setResultHandler(this);
mScannerView.startCamera();
mScannerView.setAutoFocus(true);
}
@Override
public void onResume()
{
super.onResume();
try {
this.mScannerView.setAutoFocus(mAutoFocus);
mScannerView.startCamera();
} catch (Exception e) {
e.printStackTrace();
try {
mAutoFocus = false;
this.mScannerView.setAutoFocus(mAutoFocus);
mScannerView.startCamera();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
@Override
public void onDestroy()
{
super.onDestroy();
mScannerView.stopCamera();
}
**XML**
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/scanner_fragment"
android:name="com.example.eslopezem.myapplication.Camera"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="@dimen/camera_layout_margin_bottom"
android:layout_marginTop="@dimen/camera_layout_margin_top"
android:layout_weight="1"
android:layout_x="0dp"
android:layout_y="0dp"
android:maxHeight="@dimen/scannner_view_height"
android:orientation="vertical"
android:layout_centerInParent="true"></fragment>