Created
July 25, 2019 18:20
-
-
Save rogergcc/eab1d178733c3ef1528ec9c3b56cab9c to your computer and use it in GitHub Desktop.
me.dm7.barcodescanner:zxing
nueva actividad libreria barcode scanner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.software3000.s3000.appludopataslinktek; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.FrameLayout; | |
import android.widget.LinearLayout; | |
import android.widget.Toast; | |
import android.widget.ToggleButton; | |
import com.google.zxing.Result; | |
import me.dm7.barcodescanner.zxing.ZXingScannerView; | |
public class SimpleScannerActivity extends AppCompatActivity | |
implements ZXingScannerView.ResultHandler{ | |
private ZXingScannerView mScannerView; | |
@Override | |
public void onCreate(Bundle state) { | |
super.onCreate(state); | |
// setContentView(R.layout.activity_simple_scanner); | |
// mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view | |
// setContentView(mScannerView); // Set the scanner view as the content view | |
FrameLayout frameLayout = new FrameLayout(this); | |
frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); | |
mScannerView = new ZXingScannerView(this); | |
final ToggleButton scanButton= new ToggleButton(this); | |
FrameLayout params = new FrameLayout(this); | |
// frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); | |
scanButton.setBackground(getResources().getDrawable(R.drawable.ic_flash_off_black_24dp)); | |
scanButton.setWidth('0'); | |
scanButton.setHeight(10); | |
scanButton.setTextOff(""); | |
scanButton.setTextOn(""); | |
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); | |
p.weight = 1; | |
scanButton.setLayoutParams(p); | |
frameLayout.addView(mScannerView ); | |
scanButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (scanButton.isChecked()){ | |
scanButton.setBackground(getResources().getDrawable(R.drawable.ic_flash_on_black_24dp)); | |
}else { | |
scanButton.setBackground(getResources().getDrawable(R.drawable.ic_flash_off_black_24dp)); | |
} | |
scanButton.setChecked(scanButton.isChecked()); | |
mScannerView.setFlash(scanButton.isChecked()); | |
} | |
}); | |
frameLayout.addView(scanButton); | |
setContentView(frameLayout ); | |
} | |
@Override | |
public void onResume() { | |
super.onResume(); | |
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. | |
mScannerView.startCamera(); // Start camera on resume | |
mScannerView.setAutoFocus(true); | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
mScannerView.stopCamera(); // Stop camera on pause | |
} | |
@Override | |
public void handleResult(Result rawResult) { | |
// Do something with the result here | |
Toast.makeText(this, rawResult.getText(), Toast.LENGTH_SHORT).show(); | |
// If you would like to resume scanning, call this method below: | |
mScannerView.resumeCameraPreview(this); | |
BusquerdaDniActivity.edtdni.setText(rawResult.getText()); | |
onBackPressed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment