diff --git a/component/scanner/build.gradle b/component/scanner/build.gradle index fa7765d2..61a9b1de 100644 --- a/component/scanner/build.gradle +++ b/component/scanner/build.gradle @@ -1,5 +1,6 @@ plugins { alias(libs.plugins.com.android.library) + id 'com.google.dagger.hilt.android' } android { @@ -33,8 +34,16 @@ dependencies { androidTestImplementation libs.androidx.test.ext.junit androidTestImplementation libs.androidx.test.espresso.core + // Hilt (DI) + implementation libs.com.google.dagger.hilt.android + annotationProcessor libs.com.google.dagger.hilt.compiler + implementation 'com.websitebeaver:documentscanner:1.0.0' implementation project(':shared:ui') implementation project(':model') + + implementation project(':processor') + + implementation project(':utils') } \ No newline at end of file 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 05b8dea8..2d15b51b 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 @@ -25,15 +25,32 @@ import android.widget.Toast; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.Locale; +import java.util.UUID; + +import javax.inject.Inject; + +import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.model.document.DocumentDetail; +import one.nem.lacerta.model.document.DocumentMeta; +import one.nem.lacerta.model.document.path.DocumentPath; +import one.nem.lacerta.processor.DocumentProcessor; +import one.nem.lacerta.processor.factory.DocumentProcessorFactory; + +import one.nem.lacerta.utils.LacertaLogger; + +import one.nem.lacerta.utils.repository.DeviceInfoUtils; /** * A simple {@link Fragment} subclass. * Use the {@link ScannerDataManagerStubFragment#newInstance} factory method to * create an instance of this fragment. */ +@AndroidEntryPoint public class ScannerDataManagerStubFragment extends Fragment { // TODO-rca: 時間があったらcacheを使うようにする? @@ -43,6 +60,19 @@ public class ScannerDataManagerStubFragment extends Fragment { private Uri photoURI; + private DocumentDetail documentDetail; + + private DocumentProcessor documentProcessor; + + @Inject + DocumentProcessorFactory documentProcessorFactory; + + @Inject + LacertaLogger logger; + + @Inject + DeviceInfoUtils deviceInfoUtils; + private final ActivityResultLauncher cameraLauncher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), result -> { @@ -120,6 +150,65 @@ public class ScannerDataManagerStubFragment extends Fragment { } updateResults(); }); + + view.findViewById(R.id.button_create_documnent).setOnClickListener(v -> { + Log.d("ScannerDataManagerStubFragment", "button_create_documnent clicked"); + Toast.makeText(getActivity(), "button_create_documnent clicked", Toast.LENGTH_LONG).show(); + + this.documentDetail = createSampleDocumentDetail(); + + }); + + view.findViewById(R.id.button_init_document_processor).setOnClickListener(v -> { + Log.d("ScannerDataManagerStubFragment", "button_init_document_processor clicked"); + Toast.makeText(getActivity(), "button_init_document_processor clicked", Toast.LENGTH_LONG).show(); + // TODO-rca: ここでDocumentProcessorを初期化する + if (this.documentDetail == null) { + Toast.makeText(getActivity(), "documentDetail is null", Toast.LENGTH_LONG).show(); + return; + } + this.documentProcessor = documentProcessorFactory.create(this.documentDetail); + Toast.makeText(getActivity(), "documentProcessor created", Toast.LENGTH_LONG).show(); + this.documentProcessor.init(); + Toast.makeText(getActivity(), "documentProcessor initialized", Toast.LENGTH_LONG).show(); + }); + + view.findViewById(R.id.button_add_page).setOnClickListener(v -> { + Log.d("ScannerDataManagerStubFragment", "button_add_page clicked"); + Toast.makeText(getActivity(), "button_add_page clicked", Toast.LENGTH_LONG).show(); + if (this.documentProcessor == null) { + Toast.makeText(getActivity(), "documentProcessor is null", Toast.LENGTH_LONG).show(); + return; + } + Bitmap[] bitmaps = new Bitmap[results.size()]; + for (int i = 0; i < results.size(); i++) { + bitmaps[i] = results.get(i).getBitmap(); + } + + this.documentProcessor.addNewPagesToLast(bitmaps); + + this.documentProcessor.close(); + }); + } + + public DocumentDetail createSampleDocumentDetail() { + + String id = UUID.randomUUID().toString(); + + Toast.makeText(getActivity(), "Generated id: " + id, Toast.LENGTH_LONG).show(); + //logger.debug("CreateSample", "Generated id: " + id); + + DocumentMeta meta = new DocumentMeta( + id, + "Sample" + DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now()), + new Date(), + new Date()); + + DocumentPath path = new DocumentPath( + deviceInfoUtils.getExternalStorageDirectoryString(), + "Sample" + DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now())); + + return new DocumentDetail(meta, path, "SampleAuthor", "SampleDefaultBranch"); } @Override diff --git a/component/scanner/src/main/res/layout/fragment_scanner_data_manager_stub.xml b/component/scanner/src/main/res/layout/fragment_scanner_data_manager_stub.xml index 23f74a7b..61753a90 100644 --- a/component/scanner/src/main/res/layout/fragment_scanner_data_manager_stub.xml +++ b/component/scanner/src/main/res/layout/fragment_scanner_data_manager_stub.xml @@ -11,6 +11,7 @@ android:id="@+id/action_button_container" android:layout_width="match_parent" android:layout_height="0dp" + android:weightSum="2" android:orientation="horizontal" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -19,7 +20,7 @@ + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/doc_button_container" /> \ No newline at end of file diff --git a/feature/debug/build.gradle b/feature/debug/build.gradle index e029dff3..ba7689a6 100644 --- a/feature/debug/build.gradle +++ b/feature/debug/build.gradle @@ -65,4 +65,7 @@ dependencies { // Scanner implementation project(':component:scanner') + // Processor + implementation project(':processor') + } \ No newline at end of file diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuDocProcessorTesterFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuDocProcessorTesterFragment.java new file mode 100644 index 00000000..c144a934 --- /dev/null +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuDocProcessorTesterFragment.java @@ -0,0 +1,44 @@ +package one.nem.lacerta.feature.debug; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link DebugMenuDocProcessorTesterFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class DebugMenuDocProcessorTesterFragment extends Fragment { + public DebugMenuDocProcessorTesterFragment() { + // Required empty public constructor + } + + public static DebugMenuDocProcessorTesterFragment newInstance() { + DebugMenuDocProcessorTesterFragment fragment = new DebugMenuDocProcessorTesterFragment(); + Bundle args = new Bundle(); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_debug_menu_doc_processor_tester, container, false); + + + + return view; + } +} \ No newline at end of file diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFileManagerTesterFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFileManagerTesterFragment.java new file mode 100644 index 00000000..f27bfe3a --- /dev/null +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuFileManagerTesterFragment.java @@ -0,0 +1,110 @@ +package one.nem.lacerta.feature.debug; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; + +import dagger.hilt.android.AndroidEntryPoint; +import one.nem.lacerta.source.file.FileManager; +import one.nem.lacerta.source.file.factory.FileManagerFactory; + +import one.nem.lacerta.utils.repository.DeviceInfoUtils; + +import javax.inject.Inject; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link DebugMenuFileManagerTesterFragment#newInstance} factory method to + * create an instance of this fragment. + */ +@AndroidEntryPoint +public class DebugMenuFileManagerTesterFragment extends Fragment { + + public DebugMenuFileManagerTesterFragment() { + // Required empty public constructor + } + + @Inject + FileManagerFactory fileManagerFactory; + + @Inject + DeviceInfoUtils deviceInfoUtils; + + // TODO: Rename and change types and number of parameters + public static DebugMenuFileManagerTesterFragment newInstance() { + DebugMenuFileManagerTesterFragment fragment = new DebugMenuFileManagerTesterFragment(); + Bundle args = new Bundle(); + + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.fragment_debug_menu_file_manager_tester, container, false); + + view.findViewById(R.id.button_create_directory).setOnClickListener(v -> { + EditText editText = view.findViewById(R.id.edit_text_dir_name); + String dirName = editText.getText().toString(); + + FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); + fileManager.createDir(dirName); + }); + + view.findViewById(R.id.button_save_item).setOnClickListener(v -> { + FileManager fileManager = fileManagerFactory.create(deviceInfoUtils.getExternalStorageDirectory()); + fileManager.createDir("test"); + fileManager.changeDir("test"); + Bitmap bitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888); + // Bitmapに描画処理を行う + Canvas canvas = new Canvas(bitmap); + // 大きな山の形状を作成 + android.graphics.Path bigMountainPath = new android.graphics.Path(); + bigMountainPath.moveTo(100, 800); // 左下の開始点 + bigMountainPath.lineTo(500, 300); // 頂点 + bigMountainPath.lineTo(900, 800); // 右下 + bigMountainPath.close(); // パスを閉じる + + // 山の描画設定 + Paint mountainPaint = new Paint(); + mountainPaint.setColor(Color.GREEN); + mountainPaint.setStyle(Paint.Style.FILL); + + // 大きな山を描画 + canvas.drawPath(bigMountainPath, mountainPaint); + + // 小さな山の形状を作成 + android.graphics.Path smallMountainPath = new android.graphics.Path(); + smallMountainPath.moveTo(400, 800); // 左下の開始点 + smallMountainPath.lineTo(650, 400); // 頂点 + smallMountainPath.lineTo(900, 800); // 右下 + smallMountainPath.close(); // パスを閉じる + + Paint smallMountainPaint = new Paint(); + smallMountainPaint.setColor(Color.parseColor("#006e54")); + smallMountainPaint.setStyle(Paint.Style.FILL); + + // 小さな山を描画 + canvas.drawPath(smallMountainPath, smallMountainPaint); + fileManager.saveBitmapAtCurrent(bitmap, "test.png"); + }); + + return view; + } +} \ No newline at end of file diff --git a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java index e37833c1..3ddb0006 100644 --- a/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java +++ b/feature/debug/src/main/java/one/nem/lacerta/feature/debug/DebugMenuTopFragment.java @@ -12,6 +12,7 @@ import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; +import dagger.hilt.android.AndroidEntryPoint; import one.nem.lacerta.feature.debug.common.adapter.DebugMenuListItemAdapter; import one.nem.lacerta.feature.debug.common.model.DebugMenuListItem; @@ -20,6 +21,7 @@ import one.nem.lacerta.feature.debug.common.model.DebugMenuListItem; * Use the {@link DebugMenuTopFragment#newInstance} factory method to * create an instance of this fragment. */ +@AndroidEntryPoint public class DebugMenuTopFragment extends Fragment { public DebugMenuTopFragment() { // Required empty public constructor @@ -49,6 +51,7 @@ public class DebugMenuTopFragment extends Fragment { debugMenuListItems.add(new DebugMenuListItem("Meta Data", "View meta data", R.id.action_debugMenuTopFragment_to_debugMenuMetaDataFragment, true)); debugMenuListItems.add(new DebugMenuListItem("Document Tester", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment, true)); debugMenuListItems.add(new DebugMenuListItem("Scanner", "placeholder", R.id.action_debugMenuTopFragment_to_scannerDataManagerStubFragment, true)); + debugMenuListItems.add(new DebugMenuListItem("File Manager", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuFileManagerTesterFragment, true)); DebugMenuListItemAdapter adapter = new DebugMenuListItemAdapter(debugMenuListItems); recyclerView.setAdapter(adapter); diff --git a/feature/debug/src/main/res/layout/fragment_debug_menu_doc_processor_tester.xml b/feature/debug/src/main/res/layout/fragment_debug_menu_doc_processor_tester.xml new file mode 100644 index 00000000..bb931a16 --- /dev/null +++ b/feature/debug/src/main/res/layout/fragment_debug_menu_doc_processor_tester.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/feature/debug/src/main/res/layout/fragment_debug_menu_file_manager_tester.xml b/feature/debug/src/main/res/layout/fragment_debug_menu_file_manager_tester.xml new file mode 100644 index 00000000..3b0c30b9 --- /dev/null +++ b/feature/debug/src/main/res/layout/fragment_debug_menu_file_manager_tester.xml @@ -0,0 +1,40 @@ + + + + + + + +