mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-21 20:19:23 +01:00
Test CustomScannerContract
This commit is contained in:
parent
e33297def4
commit
d82c7a4e59
2 changed files with 32 additions and 4 deletions
|
@ -0,0 +1,21 @@
|
|||
package net.foucry.pilldroid;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.activity.result.contract.ActivityResultContract;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class CustomScanContract extends ActivityResultContract<ScanOptions, ScanIntentResult> {
|
||||
@NonNull
|
||||
@Override
|
||||
public Intent createIntent(@NonNull Context context, ScanOptions input {
|
||||
return input createScanIntent(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) {
|
||||
return ScanIntentResult.parseActivityResult(resultCode, intent)
|
||||
}
|
||||
}
|
|
@ -205,7 +205,7 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Log.d(TAG, "onPause really!");
|
||||
Log.d(TAG, "onPause");
|
||||
AlarmReceiver.scheduleAlarm(this);
|
||||
}
|
||||
|
||||
|
@ -216,8 +216,15 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
/** Register the launcher and result handler
|
||||
* ActivityResultLauncher
|
||||
*/
|
||||
private final ActivityResultLauncher<ScanOptions> barcodeLauncher = registerForActivityResult(new ScanContract(),
|
||||
result -> {
|
||||
private final ActivityResultLauncher<ScanOptions, ScanIntentResult> barcodeLauncher = registerForActivityResult(new CustomScanContract.StartActivityForResult(),
|
||||
new ActivityResultCallback<ActivityResult>() {
|
||||
@Override
|
||||
public void onActivityResult(ActivityResult result) {
|
||||
if(result.getResultCode() = Activity.RESULT_OK) {
|
||||
Intent data = result.getData();
|
||||
Log.d(TAG, "return data ==" + data);
|
||||
//doSomeOperations();
|
||||
/*result -> {
|
||||
if(result.getContents() == null) {
|
||||
Intent originalIntent = result.getOriginalIntent();
|
||||
if (originalIntent == null) {
|
||||
|
@ -237,7 +244,7 @@ public class DrugListActivity extends AppCompatActivity {
|
|||
Log.d(TAG, "Scanned");
|
||||
Toast.makeText(DrugListActivity.this, "Scanned: " + result.getContents(),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}*/
|
||||
});
|
||||
|
||||
// Launch scan
|
||||
|
|
Loading…
Reference in a new issue