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