mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
Change zxing call method using contract
Clean imports
This commit is contained in:
parent
062d3f960b
commit
5cc0483487
1 changed files with 19 additions and 11 deletions
|
@ -21,15 +21,15 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.zxing.client.android.Intents;
|
import com.journeyapps.barcodescanner.ScanContract;
|
||||||
import com.google.zxing.integration.android.IntentIntegrator;
|
import com.journeyapps.barcodescanner.ScanOptions;
|
||||||
import com.google.zxing.integration.android.IntentResult;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -212,16 +212,24 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** scanNow
|
/** Register the launcher and result handler
|
||||||
*
|
* ActivityResultLauncher
|
||||||
* @param view
|
|
||||||
* call ZXing Library to scan a new QR/EAN code
|
|
||||||
*/
|
*/
|
||||||
public void scanNow(View view) {
|
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
|
||||||
new IntentIntegrator(this).setOrientationLocked(false).setCaptureActivity(CustomScannerActivity.class).initiateScan();
|
result -> {
|
||||||
|
if(result.getContents() == null) {
|
||||||
|
Toast.makeText(DrugListActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(DrugListActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Launch scan
|
||||||
|
public void onButtonClick(View view) {
|
||||||
|
barcodeLauncher.launch(new ScanOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* @Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
|
if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
|
||||||
// This is important, otherwise the result will not be passed to the fragment
|
// This is important, otherwise the result will not be passed to the fragment
|
||||||
|
@ -295,7 +303,7 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
askToAddInDB(scannedDrug);
|
askToAddInDB(scannedDrug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show keyboardInput dialog
|
* show keyboardInput dialog
|
||||||
|
|
Loading…
Reference in a new issue