use of com.budiyev.android.codescanner.CodeScanner in project ScanEco by Pepapipi.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Création et initialisation du scanner
CodeScannerView mCodeScannerView = findViewById(R.id.scanner_view);
mCodeScanner = new CodeScanner(this, mCodeScannerView);
// Initialisation des variables qui nous permettront d'affocher les
// caracteristiques du produit
mEcranBlanc = findViewById(R.id.view_ecranBlanc);
mNomProduit = findViewById(R.id.textView_nomProduit);
mImageEmballage = findViewById(R.id.imageView_EmballageScan);
mMarqueProduit = findViewById(R.id.textView_marqueProduit);
mImageViewPoubelle1 = findViewById(R.id.imageView_poubelle1);
mImageViewPoubelle2 = findViewById(R.id.imageView_poubelle2);
mImageViewPoubelle3 = findViewById(R.id.imageView_poubelle3);
mTraitView = findViewById(R.id.traitView);
// Initialisation des listes
mDonneesDuProduit = new DoneesProduit();
mDonneesDuProduit.initialisationDesListes();
// Initialisation du swipe de l'utilisateur
this.mGestureUtilisateur = new GestureDetector(MainActivity.this, this);
// Initialisation de la barre de menu
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnItemSelectedListener(item -> {
int itemId = item.getItemId();
if (itemId == R.id.accueilHorRamPoubelles) {
ouvrirHorRamPoubelles();
} else if (itemId == R.id.accueilAnimations) {
ouvrirAnimations();
} else if (itemId == R.id.accueilPointDeCollecte) {
ouvrirRecherchePointDeCollecte();
}
return true;
});
// Initialisation du bouton qui ouvre la page recherche sans scan
ImageButton mBoutonRechercheSansScan = findViewById(R.id.bouton1);
// Quand le bouton est cliqué alors il sera redirigé vers la page recherche sans scan
mBoutonRechercheSansScan.setOnClickListener(v -> ouvrirRechercheSansScan());
// S'il a refusé on redemande si on peut l'utilser, mais on ne peut pas se servir du scan
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) {
mPermissionResult.launch(Manifest.permission.CAMERA);
} else // S'il accepte, on lance le scan
{
startScanning();
}
}
use of com.budiyev.android.codescanner.CodeScanner in project EasyPlayer-RTMP-Android by EasyDSS.
the class ScanQRActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan_qr);
CodeScannerView scannerView = findViewById(R.id.scanner_view);
mCodeScanner = new CodeScanner(this, scannerView);
mCodeScanner.setScanMode(ScanMode.SINGLE);
mCodeScanner.setAutoFocusEnabled(true);
mCodeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull final Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!TextUtils.isEmpty(result.getText())) {
final String text = result.getText().trim();
if (text.toLowerCase().startsWith("rtmp://")) {
Intent intent = new Intent();
intent.putExtra("text", text);
setResult(RESULT_OK, intent);
finish();
}
}
}
});
}
});
scannerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCodeScanner.startPreview();
}
});
}
use of com.budiyev.android.codescanner.CodeScanner in project QR-Game by CMPUT301W22T15.
the class ScannerView method onCreate.
/**
* This method creates the inital interface and obtains the necessary permissions.
* @param savedInstanceState
* Expects object of type Bundle.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner_view);
// Access a Cloud FireStore instance from Activity
db = FirebaseFirestore.getInstance();
final CollectionReference collectionReference = db.collection("Players");
// Set variable data
scannerView = findViewById(R.id.scanner_view);
codeScanner = new CodeScanner(this, scannerView);
// resultData = findViewById(R.id.code_result);
// Decode data from QR code
codeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// resultData.setText(result.getText());
Toast.makeText(ScannerView.this, "Scanned Successfully", Toast.LENGTH_SHORT).show();
// TODO create the location string
QRCode qrcode = new QRCode(result.getText(), "");
qrcode.setKey("classified information");
if (isUnique(qrcode.getId())) {
singletonPlayer.player.addQrcode(qrcode);
String TAG = "working";
collectionReference.document(singletonPlayer.player.getUsername()).set(singletonPlayer.player).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Log.d(TAG, "message");
Intent intent = new Intent(ScannerView.this, QRCodeEditor.class);
intent.putExtra("QRCodeValue", (Parcelable) qrcode);
startActivity(intent);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("MYAPP", "exception: " + e.getMessage());
Log.e("MYAPP", "exception: " + e.toString());
}
});
} else {
// not unique. close activity
Toast.makeText(ScannerView.this, "you already scanned this one", Toast.LENGTH_SHORT).show();
finish();
}
}
});
}
});
// Restart scan if UI is clicked
scannerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
codeScanner.startPreview();
}
});
}
use of com.budiyev.android.codescanner.CodeScanner in project QRHunt by CMPUT301W22T00.
the class FragmentScanner method onCreateView.
/**
* Sets up fragment to be loaded in, finds all views, sets onClickListener for buttons
*
* @param inflater Inflater
* @param container Where the fragment is contained
* @param savedInstanceState SavedInstanceState
* @return root
*/
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getActivity().getSupportFragmentManager().setFragmentResultListener("getPlayer", this, (requestKey, result) -> {
Player player = (Player) result.getSerializable("player");
playerId = player.getPlayerId();
});
// Get permissions first
requestPermissionsIfNecessary(new String[] { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA });
final Activity activity = getActivity();
View root = inflater.inflate(R.layout.fragment_scanner, container, false);
CodeScannerView scannerView = root.findViewById(R.id.scanner_view);
assert activity != null;
codeScanner = new CodeScanner(activity, scannerView);
codeScanner.setCamera(CodeScanner.CAMERA_BACK);
codeScanner.setScanMode(ScanMode.CONTINUOUS);
codeScanner.setAutoFocusMode(AutoFocusMode.SAFE);
codeScanner.setFlashEnabled(false);
codeScanner.setAutoFocusEnabled(true);
codeScanner.setFormats(CodeScanner.ALL_FORMATS);
codeScanner.setDecodeCallback(result -> activity.runOnUiThread(() -> {
camera = new QrCodeProcessor(FragmentScanner.this, result.getText(), playerId);
codeScanner.setScanMode(ScanMode.PREVIEW);
camera.processQRCode();
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
codeScanner.setScanMode(ScanMode.CONTINUOUS);
}
}, 2000);
}));
codeScanner.setErrorCallback(thrown -> Log.e(TAG, "Camera has failed: ", thrown));
return root;
}
Aggregations