Merge pull request #71 from lacerta-doc/add_scanner_component

スキャナの追加
This commit is contained in:
ろむねこ 2024-01-16 12:28:58 +09:00 committed by GitHub
commit 61ed1bbf79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 442 additions and 2 deletions

View File

@ -30,6 +30,8 @@ dependencies {
implementation libs.androidx.appcompat implementation libs.androidx.appcompat
implementation libs.com.google.android.material implementation libs.com.google.android.material
implementation libs.androidx.activity
implementation libs.androidx.constraintlayout
testImplementation libs.junit testImplementation libs.junit
androidTestImplementation libs.androidx.test.ext.junit androidTestImplementation libs.androidx.test.ext.junit
androidTestImplementation libs.androidx.test.espresso.core androidTestImplementation libs.androidx.test.espresso.core
@ -46,4 +48,8 @@ dependencies {
implementation project(':processor') implementation project(':processor')
implementation project(':utils') implementation project(':utils')
implementation project(':vcs')
implementation project(':data')
} }

View File

@ -1,4 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity
android:name=".ScannerManagerActivity"
android:exported="false" />
</application>
</manifest> </manifest>

View File

@ -0,0 +1,181 @@
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;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.google.android.material.appbar.MaterialToolbar;
import com.websitebeaver.documentscanner.DocumentScanner;
import java.util.ArrayList;
import java.util.Objects;
import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.utils.LacertaLogger;
import one.nem.lacerta.data.Document;
@AndroidEntryPoint
public class ScannerManagerActivity extends AppCompatActivity {
String TAG = "ScannerManagerActivity";
@Inject
LacertaLogger logger;
@Inject
Document document;
// Variables
private ArrayList<Bitmap> croppedImages = new ArrayList<>();
View view;
DocumentScanner documentScanner = new DocumentScanner(
this,
(croppedImageResults) -> {
logger.debug(TAG, "croppedImage size: " + croppedImageResults.size());
ArrayList<Bitmap> croppedImages = new ArrayList<>();
for (String result : croppedImageResults) {
croppedImages.add(BitmapFactory.decodeFile(result));
}
processResult(croppedImages);
return null;
},
(errorMessage) -> {
// an error happened
logger.error(TAG, "Error: " + errorMessage);
logger.e_code("543a230e-cb9a-47a2-8131-3beecfe1c458");
return null;
},
() -> {
// user canceled document scan
logger.debug(TAG, "User canceled document scan");
return null;
},
null,
null,
null
);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_scanner_manager);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
MaterialToolbar toolbar = findViewById(R.id.top_toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
documentScanner.startScan();
// Init
this.view = findViewById(R.id.main); // TODO-rca:なんとかする
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
getMenuInflater().inflate(R.menu.scanner_result_toolbar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(android.view.MenuItem item) {
if (item.getItemId() == R.id.action_save_new) {
// 新ドキュメントとして保存
Toast.makeText(this, "保存処理", Toast.LENGTH_SHORT).show();
saveNewDocument();
return true;
} else if (item.getItemId() == R.id.action_insert_exist) {
// 既存ドキュメントに挿入
Toast.makeText(this, "挿入処理", Toast.LENGTH_SHORT).show();
insertToExistDocument();
return true;
} else if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
private void processResult(ArrayList<Bitmap> 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.e_code("7cb0584e-74ef-48ec-848a-c4d14e75e15a");
// 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;
}
}
private void saveNewDocument() {
logger.debug(TAG, "saveNewDocument");
}
private void insertToExistDocument() {
logger.debug(TAG, "insertToExistDocument");
// TODO-rca: 実装
}
private void updateResultView(ArrayList<Bitmap> resultImages) {
logger.debug(TAG, "updateResultView");
LinearLayout resultView = findViewById(R.id.result_list_container);
ImageView selectedImage = findViewById(R.id.selected_image);
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);
}
}
}

View File

@ -0,0 +1,95 @@
package one.nem.lacerta.component.scanner;
import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.websitebeaver.documentscanner.DocumentScanner;
import com.websitebeaver.documentscanner.DocumentScannerActivity;
import java.util.Objects;
import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.utils.LacertaLogger;
import one.nem.lacerta.vcs.LacertaVcs;
import one.nem.lacerta.vcs.factory.LacertaVcsFactory;
@AndroidEntryPoint
public class ScannerManagerFragment extends Fragment {
String TAG = getClass().getSimpleName();
@Inject
LacertaLogger logger;
@Inject
LacertaVcsFactory vcsFactory;
private static final boolean DEFAULT_SINGLE_PAGE = false;
private boolean singlePage;
public ScannerManagerFragment() {
// Required empty public constructor
}
// public static ScannerManagerFragment newInstance(boolean singlePage) {
// ScannerManagerFragment fragment = new ScannerManagerFragment();
// Bundle args = new Bundle();
// args.putBoolean("singlePage", singlePage);
// fragment.setArguments(args);
// return fragment;
// }
public static ScannerManagerFragment newInstance() {
ScannerManagerFragment fragment = new ScannerManagerFragment();
Bundle args = new Bundle();
args.putBoolean("singlePage", DEFAULT_SINGLE_PAGE);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
singlePage = getArguments().getBoolean("singlePage", DEFAULT_SINGLE_PAGE);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_scanner_manager, container, false);
// ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT
// );
// view.setLayoutParams(layoutParams);
return view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Init
logger.debug(TAG, "called");
view.findViewById(R.id.button_intent_scanner_manager_activity).setOnClickListener(v -> {
// DocumentScannerActivityを起動する
Intent intent = new Intent(requireActivity().getApplicationContext(), ScannerManagerActivity.class);
startActivity(intent);
});
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="#00000000" />
<corners android:radius="8dp" />
<stroke android:color="#FF0000" android:width="2dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#00000000" />
<corners android:radius="8dp" />
</shape>
</item>
</selector>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
android:theme="@style/Theme.Lacerta"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/top_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryContainer"
app:titleTextColor="@color/colorOnPrimaryContainer"
app:title="Preview"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/selected_image"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_above="@+id/horizontal_scroll"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="@+id/horizontal_scroll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/top_toolbar" />
<HorizontalScrollView
android:id="@+id/horizontal_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:scrollbars="none"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/selected_image">
<LinearLayout
android:id="@+id/result_list_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ScannerManagerFragment">
<Button
android:id="@+id/button_intent_scanner_manager_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/result_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="64dp"
android:adjustViewBounds="true"
android:background="@drawable/result_image_container_item_border"
android:padding="8dp"
android:scaleType="centerCrop" />
</FrameLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_save_new"
android:icon="@drawable/save_24px"
android:title="Save"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_insert_exist"
android:icon="@drawable/ic_baseline_add_24"
android:title="Save"
app:showAsAction="ifRoom"/>
</menu>

View File

@ -49,7 +49,8 @@ public class DebugMenuTopFragment extends Fragment {
List<DebugMenuListItem> debugMenuListItems = new ArrayList<>(); List<DebugMenuListItem> debugMenuListItems = new ArrayList<>();
debugMenuListItems.add(new DebugMenuListItem("Document Tester", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment, 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("ScannerStub", "placeholder", R.id.action_debugMenuTopFragment_to_scannerDataManagerStubFragment, true));
debugMenuListItems.add(new DebugMenuListItem("Scanner", "placeholder", R.id.action_debugMenuTopFragment_to_scannerManagerFragment, true));
debugMenuListItems.add(new DebugMenuListItem("Document List", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuLibraryItemListPageFragment, true)); debugMenuListItems.add(new DebugMenuListItem("Document List", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuLibraryItemListPageFragment, true));
debugMenuListItems.add(new DebugMenuListItem("VCS", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuVcsGeneralFragment, true)); debugMenuListItems.add(new DebugMenuListItem("VCS", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuVcsGeneralFragment, true));

View File

@ -22,6 +22,9 @@
<action <action
android:id="@+id/action_debugMenuTopFragment_to_debugMenuVcsGeneralFragment" android:id="@+id/action_debugMenuTopFragment_to_debugMenuVcsGeneralFragment"
app:destination="@id/debugMenuVcsGeneralFragment" /> app:destination="@id/debugMenuVcsGeneralFragment" />
<action
android:id="@+id/action_debugMenuTopFragment_to_scannerManagerFragment"
app:destination="@id/scannerManagerFragment" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/debugMenuDocumentTesterTopFragment" android:id="@+id/debugMenuDocumentTesterTopFragment"
@ -68,4 +71,8 @@
android:name="one.nem.lacerta.feature.debug.DebugMenuVcsRevRecordFragment" android:name="one.nem.lacerta.feature.debug.DebugMenuVcsRevRecordFragment"
android:label="fragment_debug_menu_vcs_rev_record" android:label="fragment_debug_menu_vcs_rev_record"
tools:layout="@layout/fragment_debug_menu_vcs_rev_record" /> tools:layout="@layout/fragment_debug_menu_vcs_rev_record" />
<fragment
android:id="@+id/scannerManagerFragment"
android:name="one.nem.lacerta.component.scanner.ScannerManagerFragment"
android:label="ScannerManagerFragment" />
</navigation> </navigation>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@color/colorOnBackground"
android:pathData="M256,746.15L213.85,704L437.85,480L213.85,256L256,213.85L480,437.85L704,213.85L746.15,256L522.15,480L746.15,704L704,746.15L480,522.15L256,746.15Z"/>
</vector>

View File

@ -5,6 +5,6 @@
android:viewportHeight="960" android:viewportHeight="960"
android:tint="?attr/colorControlNormal"> android:tint="?attr/colorControlNormal">
<path <path
android:fillColor="@android:color/white" android:fillColor="@color/colorOnBackground"
android:pathData="M330,710L630,710L630,650L330,650L330,710ZM330,550L630,550L630,490L330,490L330,550ZM252.31,860Q222,860 201,839Q180,818 180,787.69L180,172.31Q180,142 201,121Q222,100 252.31,100L570,100L780,310L780,787.69Q780,818 759,839Q738,860 707.69,860L252.31,860ZM540,340L540,160L252.31,160Q247.69,160 243.85,163.85Q240,167.69 240,172.31L240,787.69Q240,792.31 243.85,796.15Q247.69,800 252.31,800L707.69,800Q712.31,800 716.15,796.15Q720,792.31 720,787.69L720,340L540,340ZM240,160L240,160L240,340L240,340L240,160L240,340L240,340L240,787.69Q240,792.31 240,796.15Q240,800 240,800L240,800Q240,800 240,796.15Q240,792.31 240,787.69L240,172.31Q240,167.69 240,163.85Q240,160 240,160Z"/> android:pathData="M330,710L630,710L630,650L330,650L330,710ZM330,550L630,550L630,490L330,490L330,550ZM252.31,860Q222,860 201,839Q180,818 180,787.69L180,172.31Q180,142 201,121Q222,100 252.31,100L570,100L780,310L780,787.69Q780,818 759,839Q738,860 707.69,860L252.31,860ZM540,340L540,160L252.31,160Q247.69,160 243.85,163.85Q240,167.69 240,172.31L240,787.69Q240,792.31 243.85,796.15Q247.69,800 252.31,800L707.69,800Q712.31,800 716.15,796.15Q720,792.31 720,787.69L720,340L540,340ZM240,160L240,160L240,340L240,340L240,160L240,340L240,340L240,787.69Q240,792.31 240,796.15Q240,800 240,800L240,800Q240,800 240,796.15Q240,792.31 240,787.69L240,172.31Q240,167.69 240,163.85Q240,160 240,160Z"/>
</vector> </vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@color/colorOnBackground"
android:pathData="M820,288.46L820,747.69Q820,778 799,799Q778,820 747.69,820L212.31,820Q182,820 161,799Q140,778 140,747.69L140,212.31Q140,182 161,161Q182,140 212.31,140L671.54,140L820,288.46ZM760,314L646,200L212.31,200Q206.92,200 203.46,203.46Q200,206.92 200,212.31L200,747.69Q200,753.08 203.46,756.54Q206.92,760 212.31,760L747.69,760Q753.08,760 756.54,756.54Q760,753.08 760,747.69L760,314ZM480,690.77Q521.54,690.77 550.77,661.54Q580,632.31 580,590.77Q580,549.23 550.77,520Q521.54,490.77 480,490.77Q438.46,490.77 409.23,520Q380,549.23 380,590.77Q380,632.31 409.23,661.54Q438.46,690.77 480,690.77ZM255.39,395.38L583.84,395.38L583.84,255.39L255.39,255.39L255.39,395.38ZM200,314L200,747.69Q200,753.08 200,756.54Q200,760 200,760L200,760Q200,760 200,756.54Q200,753.08 200,747.69L200,212.31Q200,206.92 200,203.46Q200,200 200,200L200,200L200,314Z"/>
</vector>