From 1419100e1f5ddc917daaffc30d5d82a4423dc6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=8D=E3=82=80=E3=81=AD=E3=81=93?= Date: Wed, 20 Dec 2023 12:44:55 +0900 Subject: [PATCH] =?UTF-8?q?WIP=20=E7=B5=90=E6=9E=9C=E3=82=92=E3=83=97?= =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC=E3=81=99=E3=82=8B=E3=83=AD?= =?UTF-8?q?=E3=82=B8=E3=83=83=E3=82=AF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ScannerDataManagerStubFragment.java | 72 ++++++++++++++++++- 1 file changed, 70 insertions(+), 2 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 fc11c575..17f09277 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 @@ -8,12 +8,15 @@ import android.os.Bundle; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; import android.provider.MediaStore; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; import java.util.ArrayList; @@ -25,7 +28,7 @@ import java.util.ArrayList; public class ScannerDataManagerStubFragment extends Fragment { // Results - private ArrayList results = new ArrayList<>(); + private ArrayList results = new ArrayList<>(); private final ActivityResultLauncher cameraLauncher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { @@ -33,7 +36,8 @@ public class ScannerDataManagerStubFragment extends Fragment { Intent data = result.getData(); Bundle extras = data.getExtras(); Bitmap imageBitmap = (Bitmap) extras.get("data"); - results.add(imageBitmap); + // TODO-rca: エラーハンドリング + results.add(new CapturedData("Placeholder", Integer.toString(imageBitmap.getHeight()), Integer.toString(imageBitmap.getWidth()), "Placeholder", imageBitmap)); } } ); @@ -77,4 +81,68 @@ public class ScannerDataManagerStubFragment extends Fragment { } }); } + + @Override + public void onResume() { + super.onResume(); + Log.d("ScannerDataManagerStubFragment", "onResume"); + + + } + + public void updateResults() { + Log.d("ScannerDataManagerStubFragment", "updateResults"); + + // TODO-rca: エラーハンドリング + RecyclerView recyclerView = getView().findViewById(R.id.result_recycler_view); + + recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext())); + recyclerView.setAdapter(new ResultAdapter(this.results)); + + + } + + public class ResultAdapter extends RecyclerView.Adapter { + private final ArrayList results; + + public ResultAdapter(ArrayList results) { + this.results = results; + } + + @Override + public ResultAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_scanner_component_manager_stub, parent, false); + return new ResultAdapter.ViewHolder(view); + } + + @Override + public void onBindViewHolder(ResultAdapter.ViewHolder holder, int position) { + CapturedData result = results.get(position); + holder.textViewPath.setText(result.getPath()); + holder.textViewResolutionHeight.setText(result.getResolutionHeight()); + holder.textViewResolutionWidth.setText(result.getResolutionWidth()); + holder.imageView.setImageBitmap(result.getBitmap()); + } + + @Override + public int getItemCount() { + return results.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + + public TextView textViewPath; + public TextView textViewResolutionHeight; + public TextView textViewResolutionWidth; + public ImageView imageView; + + public ViewHolder(View view) { + super(view); + textViewPath = view.findViewById(R.id.textViewPath); + textViewResolutionHeight = view.findViewById(R.id.textViewResHeight); + textViewResolutionWidth = view.findViewById(R.id.textViewResWidth); + imageView = view.findViewById(R.id.imageViewResult); + } + } + } } \ No newline at end of file