Revert "一旦保存して読み込むように"

This reverts commit 83d2d0af02.
This commit is contained in:
ろむねこ 2023-12-21 12:34:46 +09:00 committed by GitHub
parent 3e7ceb774e
commit a62b882fe7

View File

@ -3,12 +3,10 @@ package one.nem.lacerta.component.scanner;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.content.FileProvider;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
@ -20,7 +18,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
@ -38,28 +35,15 @@ public class ScannerDataManagerStubFragment extends Fragment {
// Results
private ArrayList<CapturedData> results = new ArrayList<>();
private Uri photoURI;
private final ActivityResultLauncher<Intent> cameraLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
try {
if (getActivity() == null) {
Log.d("ScannerDataManagerStubFragment", "getActivity() is null");
return;
}
if (photoURI == null) {
Log.d("ScannerDataManagerStubFragment", "photoURI is null");
Toast.makeText(getActivity(), "photoURI is null", Toast.LENGTH_LONG).show();
return;
}
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), photoURI);
results.add(new CapturedData("Placeholder", Integer.toString(imageBitmap.getHeight()), Integer.toString(imageBitmap.getWidth()), "Placeholder", imageBitmap));
} catch (IOException e) {
Log.e("ScannerDataManagerStubFragment", "Error occurred while reading the file", e);
}
Intent data = result.getData();
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
// TODO-rca: エラーハンドリング
results.add(new CapturedData("Placeholder", Integer.toString(imageBitmap.getHeight()), Integer.toString(imageBitmap.getWidth()), "Placeholder", imageBitmap));
}
}
);
@ -97,7 +81,7 @@ public class ScannerDataManagerStubFragment extends Fragment {
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
File photoFile = null;
try {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
photoFile = File.createTempFile(imageFileName, ".jpg", storageDir);
@ -105,8 +89,7 @@ public class ScannerDataManagerStubFragment extends Fragment {
Log.e("ScannerDataManagerStubFragment", "Error occurred while creating the file", ex);
}
if (photoFile != null) {
photoURI = FileProvider.getUriForFile(getActivity(), "one.nem.lacerta.provider", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoFile);
cameraLauncher.launch(takePictureIntent);
}
else {