mirror of
				https://github.com/lacerta-doc/Lacerta.git
				synced 2025-11-04 08:50:47 +00:00 
			
		
		
		
	WIP 結果をプレビューするロジック実装
This commit is contained in:
		
							parent
							
								
									576d1d7c9b
								
							
						
					
					
						commit
						1419100e1f
					
				@ -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<Bitmap> results = new ArrayList<>();
 | 
			
		||||
    private ArrayList<CapturedData> results = new ArrayList<>();
 | 
			
		||||
    private final ActivityResultLauncher<Intent> 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<ResultAdapter.ViewHolder> {
 | 
			
		||||
        private final ArrayList<CapturedData> results;
 | 
			
		||||
 | 
			
		||||
        public ResultAdapter(ArrayList<CapturedData> 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);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user