From a62b882fe70cb54716b45f4b5ed88706c90a3ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= <66072112+r-ca@users.noreply.github.com> Date: Thu, 21 Dec 2023 12:34:46 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"=E4=B8=80=E6=97=A6=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E3=81=97=E3=81=A6=E8=AA=AD=E3=81=BF=E8=BE=BC=E3=82=80=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 83d2d0af027b4f20de1713c1e50fee62900320b2. --- .../ScannerDataManagerStubFragment.java | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java index 04568e36..222ecb82 100644 --- a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java +++ b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerDataManagerStubFragment.java @@ -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 results = new ArrayList<>(); - - private Uri photoURI; - private final ActivityResultLauncher 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 {