From a6aeb5480ad8ce3708a8a24cad3d64277d45d848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Tue, 16 Jan 2024 11:05:43 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=82=AD=E3=83=A3=E3=83=B3=E5=BE=8C?= =?UTF-8?q?=E3=81=AE=E6=93=8D=E4=BD=9C=E3=82=92=E8=A1=8C=E3=81=86=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E3=82=92=E5=AE=9F=E8=A3=85=20WIP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/ScannerManagerActivity.java | 60 +++++++++++++++---- .../layout/result_image_container_item.xml | 16 +++++ 2 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 component/scanner/src/main/res/layout/result_image_container_item.xml diff --git a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java index 151e1fc7..0fb77633 100644 --- a/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java +++ b/component/scanner/src/main/java/one/nem/lacerta/component/scanner/ScannerManagerActivity.java @@ -2,10 +2,13 @@ package one.nem.lacerta.component.scanner; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.annotation.AnimatorRes; @@ -32,17 +35,19 @@ public class ScannerManagerActivity extends AppCompatActivity { LacertaLogger logger; // Variables - private ArrayList resultImages = new ArrayList<>(); + private ArrayList croppedImages = new ArrayList<>(); View view; DocumentScanner documentScanner = new DocumentScanner( this, (croppedImageResults) -> { + logger.debug(TAG, "croppedImage size: " + croppedImageResults.size()); + ArrayList croppedImages = new ArrayList<>(); for (String result : croppedImageResults) { - this.resultImages.add(BitmapFactory.decodeFile(result)); + croppedImages.add(BitmapFactory.decodeFile(result)); } - initResultView(); + processResult(croppedImages); return null; }, (errorMessage) -> { @@ -78,18 +83,51 @@ public class ScannerManagerActivity extends AppCompatActivity { } - private void initResultView() { - if (this.view == null) { - logger.debug(TAG, "initResultView: view is null"); - return; + private void processResult(ArrayList resultImages) { + logger.debug(TAG, "processResult"); + + if (resultImages.isEmpty()) { + logger.debug(TAG, "resultImages(arg) is empty"); + if (this.croppedImages.isEmpty()) { + logger.debug(TAG, "this.resultImages is empty"); + logger.error(TAG, "error code: 398f4ca7-06f4-43c4-a153-e2ba5bbdb92b"); // TODO-rca: Loggerに組み込む? + // TODO-rca: なんかする + } else { + logger.debug(TAG, "this.resultImages is not empty"); + updateResultView(this.croppedImages); + } + } else { + logger.debug(TAG, "resultImages(arg) is not empty"); + updateResultView(resultImages); + this.croppedImages = resultImages; } - // Log pt - logger.debug(TAG, "Total images: " + this.resultImages.size()); + } - LinearLayout resultContainer = view.findViewById(R.id.result_list_container); + private void updateResultView(ArrayList resultImages) { + logger.debug(TAG, "updateResultView"); - // ImageButtonを追加する + LinearLayout resultView = findViewById(R.id.result_list_container); + resultView.removeAllViews(); + + for (Bitmap resultImage : resultImages) { + View resultImageView = getLayoutInflater().inflate(R.layout.result_image_container_item, null); + ImageView imageView = resultImageView.findViewById(R.id.result_image); + imageView.setImageBitmap(resultImage); + imageView.setOnClickListener(v -> { + // タッチされた画像をプレビューに設定します。 +// selectedImage.setImageBitmap(resultImage); + // すべての画像の選択状態を解除します。 + for (int i = 0; i < resultView.getChildCount(); i++) { + View child = resultView.getChildAt(i).findViewById(R.id.result_image); + child.setSelected(false); + } + // タッチされた画像を選択状態にします。 + v.setSelected(true); + }); + + resultView.addView(resultImageView); + } } } \ No newline at end of file diff --git a/component/scanner/src/main/res/layout/result_image_container_item.xml b/component/scanner/src/main/res/layout/result_image_container_item.xml new file mode 100644 index 00000000..c0217701 --- /dev/null +++ b/component/scanner/src/main/res/layout/result_image_container_item.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file