mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-07 19:47:36 +00:00
Compare commits
295
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc5d0edd68 | ||
|
|
3540f20c46 | ||
|
|
164b6ea6d4 | ||
|
|
8fdefb9850 | ||
|
|
8e4018beb0 | ||
|
|
ddd2b097e6 | ||
|
|
9fe646fad8 | ||
|
|
5e1d1f6a76 | ||
|
|
649d6ccfdc | ||
|
|
dccb3090e1 | ||
|
|
de4a501c3f | ||
|
|
28b5f97c31 | ||
|
|
4656914203 | ||
|
|
1996d8dc4a | ||
|
|
dec4983bfc | ||
|
|
88dfae7d37 | ||
|
|
48101190a2 | ||
|
|
2b79c7669f | ||
|
|
3b6d88bafd | ||
|
|
a439bbd888 | ||
|
|
3453d224e1 | ||
|
|
b75759b650 | ||
|
|
a78cac8178 | ||
|
|
a42ef8f4fc | ||
|
|
5c16ea6e21 | ||
|
|
f000addbce | ||
|
|
73fa8201d6 | ||
|
|
5c0fd4fdbb | ||
|
|
6e514b216a | ||
|
|
59ba2cdcfc | ||
|
|
b3be0b9e21 | ||
|
|
a836410cbd | ||
|
|
15d454690e | ||
|
|
2ba243ea4a | ||
|
|
52657fdbbd | ||
|
|
88cd58f920 | ||
|
|
1ee0a1b8ea | ||
|
|
656482e968 | ||
|
|
efc16423d4 | ||
|
|
38db65c9d3 | ||
|
|
31a0220b90 | ||
|
|
5cb57997b8 | ||
|
|
0fade2c41b | ||
|
|
5a0b215626 | ||
|
|
49775a1f49 | ||
|
|
552f0e42b5 | ||
|
|
b8e70cd015 | ||
|
|
67350639c7 | ||
|
|
eb6a13baba | ||
|
|
bd0a16bec6 | ||
|
|
1019b1d035 | ||
|
|
2f0460a9ea | ||
|
|
2b4a24de7c | ||
|
|
b683c311df | ||
|
|
4bbb119729 | ||
|
|
8c714d5193 | ||
|
|
f441a957f7 | ||
|
|
dfe5c36e9e | ||
|
|
c54967f016 | ||
|
|
95beda8cc2 | ||
|
|
02d72ffa68 | ||
|
|
b159db97bb | ||
|
|
1653da9c94 | ||
|
|
1b00f2c64e | ||
|
|
de668412fc | ||
|
|
07042f4e91 | ||
|
|
78c36df105 | ||
|
|
14837f83cc | ||
|
|
4fd490ee12 | ||
|
|
d453c0705f | ||
|
|
aca90aa6e1 | ||
|
|
f52d00f930 | ||
|
|
9b70adecac | ||
|
|
80c5bca179 | ||
|
|
0a639d4b05 | ||
|
|
3ed6f7b5a6 | ||
|
|
f86dc981b4 | ||
|
|
c9eda4837b | ||
|
|
4d72fc10bf | ||
|
|
c9a594763d | ||
|
|
5a93b79b07 | ||
|
|
8a5cbe7b18 | ||
|
|
ca153f5602 | ||
|
|
73f553cff3 | ||
|
|
bd1a1d56cb | ||
|
|
b98fa18cae | ||
|
|
4875394417 | ||
|
|
b675e7ffa9 | ||
|
|
453fa4c4cf | ||
|
|
ce3565c082 | ||
|
|
523a66429e | ||
|
|
b7062a4942 | ||
|
|
43c7f4ae0f | ||
|
|
77702b9da5 | ||
|
|
d2950ab781 | ||
|
|
4aefae6b51 | ||
|
|
f2ed0515f8 | ||
|
|
b30834479e | ||
|
|
aa0728e97b | ||
|
|
3affd2dd2f | ||
|
|
9534e36a9d | ||
|
|
3bfcc9fd63 | ||
|
|
e3186249a0 | ||
|
|
c8517ad814 | ||
|
|
ffb6ebb358 | ||
|
|
a4db519fcf | ||
|
|
5ff6ac32ba | ||
|
|
bc06438811 | ||
|
|
6adcbf81c6 | ||
|
|
bc24ec45af | ||
|
|
ca3b4d78a5 | ||
|
|
c1b8722b82 | ||
|
|
646627ac49 | ||
|
|
6a98deab83 | ||
|
|
92b48336ac | ||
|
|
81d545b90b | ||
|
|
9daccbb084 | ||
|
|
a47d652275 | ||
|
|
e55b5709dd | ||
|
|
9fc5d160ac | ||
|
|
544b09dc39 | ||
|
|
bc42d59471 | ||
|
|
5d46fc3e81 | ||
|
|
9a17910862 | ||
|
|
8441b88ab3 | ||
|
|
92d147ab65 | ||
|
|
1eee31316a | ||
|
|
302eccfdfe | ||
|
|
93d1fa3f19 | ||
|
|
2154e67178 | ||
|
|
de9b78035a | ||
|
|
7cb5b1ca7c | ||
|
|
85c419c3ea | ||
|
|
685bdd56f8 | ||
|
|
a32ea3568f | ||
|
|
275cd77f53 | ||
|
|
a8274d3882 | ||
|
|
8b0b58ce99 | ||
|
|
eeb5387cdf | ||
|
|
41d5f8d71f | ||
|
|
b90ef6a487 | ||
|
|
734f6eb41d | ||
|
|
4f762627cf | ||
|
|
85a1f8a505 | ||
|
|
98232dc403 | ||
|
|
e925893ad2 | ||
|
|
2f21ecd6bd | ||
|
|
d203b1b76e | ||
|
|
a15383d420 | ||
|
|
6433b9a1ae | ||
|
|
1a1446ac62 | ||
|
|
60544c7905 | ||
|
|
7e7d72f903 | ||
|
|
5a468e37f9 | ||
|
|
25cbc32ef9 | ||
|
|
310944f51e | ||
|
|
c90715b0f5 | ||
|
|
effdd8e9f3 | ||
|
|
b07d370e69 | ||
|
|
f51313411b | ||
|
|
c183327842 | ||
|
|
95d9af1281 | ||
|
|
413c42fdc1 | ||
|
|
7eca8e9528 | ||
|
|
a0deb45fa0 | ||
|
|
e19198446b | ||
|
|
e0fe27eadd | ||
|
|
83707f8bec | ||
|
|
c3d9bb0cf9 | ||
|
|
39d356841b | ||
|
|
4db67a59d7 | ||
|
|
26f5968a4a | ||
|
|
6be44cd9b5 | ||
|
|
efa3134dc6 | ||
|
|
21f2f55531 | ||
|
|
02f1ac13cf | ||
|
|
e0f634fcb6 | ||
|
|
69a0b392ff | ||
|
|
0d42dc3461 | ||
|
|
2aa6bf8c5b | ||
|
|
123145b6a8 | ||
|
|
e723174b81 | ||
|
|
c1b3c06a9d | ||
|
|
a23010b535 | ||
|
|
29e0dca2c7 | ||
|
|
a1c87535c6 | ||
|
|
a0c4718b3a | ||
|
|
7c0d82f25c | ||
|
|
5f74123c63 | ||
|
|
d0543d89b9 | ||
|
|
fd74f5eab0 | ||
|
|
1bac068c8c | ||
|
|
bbad45fbbd | ||
|
|
f2dfd2ca56 | ||
|
|
e3d6826912 | ||
|
|
b28a939792 | ||
|
|
7ba70cc84b | ||
|
|
865d8b994c | ||
|
|
1c5325711a | ||
|
|
aff7af76d4 | ||
|
|
9fecefeb4e | ||
|
|
577453a4db | ||
|
|
814dfd23fa | ||
|
|
0309864d0b | ||
|
|
947c2aa2ab | ||
|
|
0f4ce1b9b1 | ||
|
|
8a851e4f11 | ||
|
|
a298247824 | ||
|
|
acb039ee23 | ||
|
|
59e32fe696 | ||
|
|
7965ce90a6 | ||
|
|
142ca57f76 | ||
|
|
15beb0af57 | ||
|
|
14e7fbd127 | ||
|
|
144ff7dfd2 | ||
|
|
d030847992 | ||
|
|
eb1ad1f4af | ||
|
|
fc048c9bd6 | ||
|
|
c7a387df3d | ||
|
|
732f047ff7 | ||
|
|
bbeba2b733 | ||
|
|
83d2d0af02 | ||
|
|
3518464716 | ||
|
|
f9247e9114 | ||
|
|
be610059cf | ||
|
|
b12c689d4e | ||
|
|
55ae0b541a | ||
|
|
f74abd11fc | ||
|
|
8817c62ed3 | ||
|
|
d5616d63b6 | ||
|
|
9cbf6f9d56 | ||
|
|
ad66688bf9 | ||
|
|
b5281443bf | ||
|
|
c616edf9f7 | ||
|
|
aa4f8360dc | ||
|
|
99dea6d6f6 | ||
|
|
b3dcaefede | ||
|
|
9ec45096ba | ||
|
|
a3edcf845a | ||
|
|
48de3f9a8d | ||
|
|
979a3f8ee7 | ||
|
|
9c79e02cc8 | ||
|
|
3db91fb937 | ||
|
|
e9f2a6b711 | ||
|
|
955c0122cf | ||
|
|
d5f3d36d23 | ||
|
|
2c74fa3339 | ||
|
|
e3220910f5 | ||
|
|
8e97dd6972 | ||
|
|
0bf6b3fa1a | ||
|
|
6ac0599f4c | ||
|
|
f14b9accee | ||
|
|
da2ff27391 | ||
|
|
60d13ac9a9 | ||
|
|
011cac925a | ||
|
|
4d0412e5bd | ||
|
|
be30ce2c62 | ||
|
|
3c6541607c | ||
|
|
be80e42dc5 | ||
|
|
031a1d2810 | ||
|
|
ccbbb45f39 | ||
|
|
13b53c62ec | ||
|
|
8c83c7adcf | ||
|
|
5617dacfe7 | ||
|
|
ed9e20ede3 | ||
|
|
b7f91b593e | ||
|
|
4a39c5c525 | ||
|
|
fc716df189 | ||
|
|
9d108212dd | ||
|
|
e34dd65dda | ||
|
|
3386418abd | ||
|
|
c8b99e10e8 | ||
|
|
d8f8b87c54 | ||
|
|
31d3b975ea | ||
|
|
fb5de4f12a | ||
|
|
b02c0a421c | ||
|
|
2843ed749d | ||
|
|
9722a3d9b7 | ||
|
|
0d21f7a783 | ||
|
|
866b8270fe | ||
|
|
e0af9381cb | ||
|
|
e70f930929 | ||
|
|
2364a32de9 | ||
|
|
c8c0c2f42c | ||
|
|
e87056a12f | ||
|
|
cfd3153620 | ||
|
|
78c11ee41e | ||
|
|
ac2001142f | ||
|
|
6d71322982 | ||
|
|
3bf14799b5 | ||
|
|
aaf4264f44 | ||
|
|
b097e8070a | ||
|
|
99ad244376 | ||
|
|
99817d3e33 | ||
|
|
5a92c210f7 |
No files matched your search
Generated
+12
-5
@@ -1,10 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<value>
|
||||
<entry key="app">
|
||||
<State />
|
||||
</entry>
|
||||
</value>
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="ZY227DCBHN" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-12-21T04:53:14.729902700Z" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+1
@@ -4,6 +4,7 @@
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="jbr-17" />
|
||||
<option name="modules">
|
||||
|
||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
+10
-3
@@ -11,8 +11,11 @@ android {
|
||||
applicationId "one.nem.lacerta"
|
||||
minSdk 26
|
||||
targetSdk 33
|
||||
|
||||
// ベータ, Internal, Release問わず毎回インクリメントする
|
||||
// https://developer.android.com/studio/publish/versioning#versioningsettings
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionName "0.1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -23,14 +26,18 @@ android {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
applicationIdSuffix ".debug"
|
||||
matchingFallbacks = ['release']
|
||||
}
|
||||
internal_release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
matchingFallbacks = ['release']
|
||||
}
|
||||
beta_release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
|
||||
applicationIdSuffix ".beta"
|
||||
matchingFallbacks = ['release']
|
||||
}
|
||||
release {
|
||||
|
||||
@@ -2,6 +2,17 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="false" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.media.action.IMAGE_CAPTURE" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
@@ -22,6 +33,16 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="one.nem.lacerta.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<cache-path name="cache" path="." />
|
||||
</paths>
|
||||
@@ -1,5 +1,6 @@
|
||||
plugins {
|
||||
alias(libs.plugins.com.android.library)
|
||||
id 'com.google.dagger.hilt.android'
|
||||
}
|
||||
|
||||
android {
|
||||
@@ -33,5 +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')
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package one.nem.lacerta.component.scanner;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CaptureResultAdapter extends RecyclerView.Adapter<CaptureResultAdapter.ViewHolder> {
|
||||
private final ArrayList<CapturedData> results;
|
||||
|
||||
public CaptureResultAdapter(ArrayList<CapturedData> results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaptureResultAdapter.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 CaptureResultAdapter.ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CaptureResultAdapter.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package one.nem.lacerta.component.scanner;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public class CapturedData {
|
||||
|
||||
private String path;
|
||||
private String resolutionHeight;
|
||||
private String resolutionWidth;
|
||||
private String size;
|
||||
private Bitmap bitmap;
|
||||
|
||||
// Constructor
|
||||
|
||||
public CapturedData(String path, String resolutionHeight, String resolutionWidth, String size, Bitmap bitmap) {
|
||||
this.path = path;
|
||||
this.resolutionHeight = resolutionHeight;
|
||||
this.resolutionWidth = resolutionWidth;
|
||||
this.size = size;
|
||||
this.bitmap = bitmap;
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getResolutionHeight() {
|
||||
return resolutionHeight;
|
||||
}
|
||||
|
||||
public String getResolutionWidth() {
|
||||
return resolutionWidth;
|
||||
}
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
package one.nem.lacerta.component.scanner;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Environment;
|
||||
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 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を使うようにする?
|
||||
|
||||
// Results
|
||||
private ArrayList<CapturedData> results = new ArrayList<>();
|
||||
|
||||
private Uri photoURI;
|
||||
|
||||
private DocumentDetail documentDetail;
|
||||
|
||||
private DocumentProcessor documentProcessor;
|
||||
|
||||
@Inject
|
||||
DocumentProcessorFactory documentProcessorFactory;
|
||||
|
||||
@Inject
|
||||
LacertaLogger logger;
|
||||
|
||||
@Inject
|
||||
DeviceInfoUtils deviceInfoUtils;
|
||||
|
||||
private final ActivityResultLauncher<Intent> cameraLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(),
|
||||
result -> {
|
||||
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||
try {
|
||||
if (getActivity() == null) {
|
||||
Log.d("ScannerDataManagerStubFragment", "getActivity() is null");
|
||||
return;
|
||||
}
|
||||
if (photoURI == null) {
|
||||
Log.d("ScannerDataManagerStubFragment", "photoURI is null");
|
||||
Toast.makeText(getActivity(), "photoURI is null", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Bitmap imageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), photoURI);
|
||||
results.add(new CapturedData("Placeholder", Integer.toString(imageBitmap.getHeight()), Integer.toString(imageBitmap.getWidth()), "Placeholder", imageBitmap));
|
||||
} catch (IOException e) {
|
||||
Log.e("ScannerDataManagerStubFragment", "Error occurred while reading the file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
public ScannerDataManagerStubFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static ScannerDataManagerStubFragment newInstance() {
|
||||
ScannerDataManagerStubFragment fragment = new ScannerDataManagerStubFragment();
|
||||
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
|
||||
return inflater.inflate(R.layout.fragment_scanner_data_manager_stub, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
view.findViewById(R.id.button_call_camera).setOnClickListener(v -> {
|
||||
Log.d("ScannerDataManagerStubFragment", "button_call_camera clicked");
|
||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
|
||||
File photoFile = null;
|
||||
try {
|
||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
|
||||
String imageFileName = "JPEG_" + timeStamp + "_";
|
||||
File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
||||
photoFile = File.createTempFile(imageFileName, ".jpg", storageDir);
|
||||
} catch (IOException ex) {
|
||||
Log.e("ScannerDataManagerStubFragment", "Error occurred while creating the file", ex);
|
||||
}
|
||||
if (photoFile != null) {
|
||||
photoURI = FileProvider.getUriForFile(getActivity(), "one.nem.lacerta.provider", photoFile);
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
|
||||
cameraLauncher.launch(takePictureIntent);
|
||||
}
|
||||
else {
|
||||
Log.d("ScannerDataManagerStubFragment", "photoFile is null");
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log.d("ScannerDataManagerStubFragment", "camera not available");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
for (CapturedData capturedData : this.results) {
|
||||
this.documentProcessor.addNewPageToLast(capturedData.getBitmap());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log.d("ScannerDataManagerStubFragment", "onResume");
|
||||
updateResults();
|
||||
}
|
||||
|
||||
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 CaptureResultAdapter(this.results));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
package one.nem.lacerta.component.scanner;
|
||||
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.constraintlayout.utils.widget.ImageFilterView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.websitebeaver.documentscanner.DocumentScanner;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link ScannerScanFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ScannerScanFragment extends Fragment {
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
// private static final String MAX_SCAN_COUNT = "max_scan_count"; // 規定値
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
|
||||
|
||||
public ScannerScanFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
public static ScannerScanFragment newInstance(String param1) {
|
||||
ScannerScanFragment fragment = new ScannerScanFragment();
|
||||
Bundle args = new Bundle();
|
||||
// args.putString(MAX_SCAN_COUNT, param1);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
// mParam1 = getArguments().getString(MAX_SCAN_COUNT);
|
||||
// scan(Integer.parseInt(mParam1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DocumentScanner getDocumentScanner() {
|
||||
return new DocumentScanner(
|
||||
this,
|
||||
(croppedImageResults) -> {
|
||||
// display the first cropped image
|
||||
croppedImageView.setImageBitmap(
|
||||
BitmapFactory.decodeFile(croppedImageResults.get(0))
|
||||
);
|
||||
return null;
|
||||
},
|
||||
(errorMessage) -> {
|
||||
// an error happened
|
||||
return null;
|
||||
},
|
||||
() -> {
|
||||
// user canceled document scan
|
||||
return null;
|
||||
},
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package one.nem.lacerta.component.scanner;
|
||||
|
||||
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 ScannerScanResultFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class ScannerScanResultFragment extends Fragment {
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
public ScannerScanResultFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment ScannerScanResultFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static ScannerScanResultFragment newInstance(String param1, String param2) {
|
||||
ScannerScanResultFragment fragment = new ScannerScanResultFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_scanner_scan_result, container, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?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"
|
||||
android:theme="@style/Theme.Lacerta"
|
||||
tools:context=".ScannerDataManagerStubFragment" >
|
||||
|
||||
<LinearLayout
|
||||
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"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_call_camera"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16px"
|
||||
android:layout_weight="1"
|
||||
android:text="Call camera" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/init_button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/action_button_container">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_create_documnent"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16px"
|
||||
android:layout_weight="1"
|
||||
android:text="Create Doc Obj" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_init_document_processor"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16px"
|
||||
android:layout_weight="1"
|
||||
android:text="Init Processor" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/doc_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"
|
||||
app:layout_constraintTop_toBottomOf="@id/init_button_container">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_add_page"
|
||||
style="@style/Widget.Material3.Button.IconButton.Filled"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16px"
|
||||
android:layout_weight="1"
|
||||
android:text="Add page to last" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/result_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/doc_button_container" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ScannerScanFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
|
||||
</FrameLayout>
|
||||
@@ -1,133 +0,0 @@
|
||||
<?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"
|
||||
android:orientation="vertical"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<androidx.constraintlayout.utils.widget.ImageFilterView
|
||||
android:id="@+id/cropped_image_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintBottom_toTopOf="@+id/linear_layout_buttons">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_margin="12dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:text="Saturation" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar_saturation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:max="200"
|
||||
android:progress="100"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_margin="12dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:text="Contrast" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar_contrast"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:max="200"
|
||||
android:progress="100"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_margin="12dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:text="Brightness" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar_brightness"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="200"
|
||||
android:progress="100"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:layout_margin="12dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:text="Warmth" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBar_warmth"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="500"
|
||||
android:progress="100"
|
||||
android:layout_weight="1"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_layout_buttons"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_save_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:insetLeft="12dp"
|
||||
android:insetRight="12dp"
|
||||
android:text="Save Image" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_kill_me"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:insetLeft="12dp"
|
||||
android:insetRight="12dp"
|
||||
android:text="Kill me" />
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,70 @@
|
||||
<?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="wrap_content"
|
||||
android:layout_margin="24px">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageViewResult"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:srcCompat="@android:drawable/presence_video_online"
|
||||
android:adjustViewBounds="true"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/imageViewResult">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:text="Resolution:"
|
||||
android:textIsSelectable="false"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewResHeight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Height"
|
||||
android:textIsSelectable="false"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewResWidth"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Width"
|
||||
android:textIsSelectable="false"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewPath"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Path"
|
||||
android:textIsSelectable="false"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -62,4 +62,10 @@ dependencies {
|
||||
// Shared
|
||||
implementation project(':shared:ui')
|
||||
|
||||
// Scanner
|
||||
implementation project(':component:scanner')
|
||||
|
||||
// Processor
|
||||
implementation project(':processor')
|
||||
|
||||
}
|
||||
+44
@@ -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;
|
||||
}
|
||||
}
|
||||
+110
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -48,6 +50,8 @@ 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);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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"
|
||||
android:theme="@style/Theme.Lacerta"
|
||||
tools:context=".DebugMenuDocProcessorTesterFragment" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="1dp"
|
||||
android:layout_marginTop="1dp"
|
||||
android:layout_marginEnd="1dp"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_gen_random_img"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Generate random image" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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=".DebugMenuFileManagerTesterFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edit_text_dir_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_create_directory"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Create dir" />
|
||||
<Button
|
||||
android:id="@+id/button_dir_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="List item in current" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_save_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Save Test Image" />
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -16,6 +16,12 @@
|
||||
<action
|
||||
android:id="@+id/action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment"
|
||||
app:destination="@id/debugMenuDocumentTesterTopFragment" />
|
||||
<action
|
||||
android:id="@+id/action_debugMenuTopFragment_to_scannerDataManagerStubFragment"
|
||||
app:destination="@id/scannerDataManagerStubFragment" />
|
||||
<action
|
||||
android:id="@+id/action_debugMenuTopFragment_to_debugMenuFileManagerTesterFragment"
|
||||
app:destination="@id/debugMenuFileManagerTesterFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/debugMenuMetaDataFragment"
|
||||
@@ -44,4 +50,13 @@
|
||||
android:name="one.nem.lacerta.feature.debug.DebugMenuDocumentTesterManageFragment"
|
||||
android:label="fragment_debug_menu_document_tester_manage"
|
||||
tools:layout="@layout/fragment_debug_menu_document_tester_manage" />
|
||||
<fragment
|
||||
android:id="@+id/scannerDataManagerStubFragment"
|
||||
android:name="one.nem.lacerta.component.scanner.ScannerDataManagerStubFragment"
|
||||
android:label="ScannerDataManagerStubFragment" />
|
||||
<fragment
|
||||
android:id="@+id/debugMenuFileManagerTesterFragment"
|
||||
android:name="one.nem.lacerta.feature.debug.DebugMenuFileManagerTesterFragment"
|
||||
android:label="fragment_debug_menu_file_manager_tester"
|
||||
tools:layout="@layout/fragment_debug_menu_file_manager_tester" />
|
||||
</navigation>
|
||||
@@ -29,6 +29,8 @@ dependencies {
|
||||
|
||||
implementation libs.androidx.appcompat
|
||||
implementation libs.com.google.android.material
|
||||
implementation 'androidx.navigation:navigation-fragment:2.7.5'
|
||||
implementation 'androidx.navigation:navigation-ui:2.7.5'
|
||||
testImplementation libs.junit
|
||||
androidTestImplementation libs.androidx.test.ext.junit
|
||||
androidTestImplementation libs.androidx.test.espresso.core
|
||||
@@ -38,4 +40,11 @@ dependencies {
|
||||
implementation libs.navigation.ui
|
||||
implementation libs.navigation.dynamic.features.fragment
|
||||
|
||||
// Hilt (DI)
|
||||
implementation libs.com.google.dagger.hilt.android
|
||||
annotationProcessor libs.com.google.dagger.hilt.compiler
|
||||
|
||||
implementation project(':shared:ui')
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package one.nem.lacerta.feature.library;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
|
||||
|
||||
private List<String> documentList;
|
||||
|
||||
public DocumentAdapter(List<String> documentList) {
|
||||
this.documentList = documentList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public DocumentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_library_menu, parent, false);
|
||||
return new DocumentViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull DocumentViewHolder holder, int position) {
|
||||
holder.title.setText(documentList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return documentList.size();
|
||||
}
|
||||
|
||||
class DocumentViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView title;
|
||||
|
||||
DocumentViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
title = itemView.findViewById(R.id.debug_menu_item_title);
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package one.nem.lacerta.feature.library;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
// LibraryArchiveFragment.java
|
||||
public class LibraryArchiveFragment extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fragment_library_top);
|
||||
|
||||
// ここに入力された内容を表示する機能
|
||||
TextView textView = findViewById(R.id.document_list);
|
||||
|
||||
textView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 文字をタップしたときの処理
|
||||
|
||||
// 移動先のアクティビティを指定
|
||||
Intent intent = new Intent(LibraryArchiveFragment.this, LibraryDocFragment.class);
|
||||
|
||||
// データを付加する
|
||||
intent.putExtra("key_name", "value_data");
|
||||
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package one.nem.lacerta.feature.library;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
public class LibraryDocFragment extends Fragment {
|
||||
|
||||
private TextView textView; // フィールドとして TextView を定義
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_library_file, container, false);
|
||||
|
||||
textView = view.findViewById(R.id.textView);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// フラグメントに渡されたデータを取得
|
||||
if (getArguments() != null) {
|
||||
String receivedData = getArguments().getString("key_name");
|
||||
|
||||
// onCreateView メソッドで取得した TextView にデータをセットする
|
||||
if (textView != null) {
|
||||
textView.setText(receivedData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Factory method for creating a new instance of the fragment
|
||||
public static LibraryDocFragment newInstance(String data) {
|
||||
LibraryDocFragment fragment = new LibraryDocFragment();
|
||||
|
||||
// フラグメントにデータを渡す
|
||||
Bundle args = new Bundle();
|
||||
args.putString("key_name", data);
|
||||
fragment.setArguments(args);
|
||||
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
+31
-4
@@ -2,11 +2,20 @@ package one.nem.lacerta.feature.library;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
@@ -55,10 +64,28 @@ public class LibraryTopFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_library_top, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_library_top, container, false);
|
||||
|
||||
// Use view.findViewById instead of findViewById
|
||||
RecyclerView documentRecyclerView = view.findViewById(R.id.document_list);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
||||
documentRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
List<String> documentList = new ArrayList<>();
|
||||
documentList.add("Document A");
|
||||
documentList.add("Document B");
|
||||
documentList.add("Document C");
|
||||
|
||||
// Create and set the adapter
|
||||
DocumentAdapter adapter = new DocumentAdapter(documentList);
|
||||
documentRecyclerView.setAdapter(adapter);
|
||||
|
||||
// Use a LinearLayoutManager to specify the layout
|
||||
return view;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginEnd="8dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,14 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<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"
|
||||
android:theme="@style/Theme.Lacerta"
|
||||
tools:context=".LibraryTopFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/tool_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/colorPrimaryContainer"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="?attr/actionBarTheme"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:title="Library"
|
||||
app:titleTextColor="@color/colorOnPrimaryContainer" />
|
||||
|
||||
</FrameLayout>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/document_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tool_bar" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/debug_menu_item_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginEnd="8dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/debug_menu_item_description"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/debug_menu_item_title" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,4 +1,3 @@
|
||||
<resources>
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
<string name="app_name">Library</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,104 @@
|
||||
package one.nem.lacerta.model.document.internal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class XmlMetaModel {
|
||||
|
||||
String title;
|
||||
String author;
|
||||
String description;
|
||||
// Date created;
|
||||
// Date updated;
|
||||
String defaultBranch;
|
||||
ArrayList<XmlMetaPageModel> pages;
|
||||
|
||||
// Constructor
|
||||
|
||||
public XmlMetaModel() {
|
||||
}
|
||||
|
||||
public XmlMetaModel(String title, String author, String description, String defaultBranch, ArrayList<XmlMetaPageModel> pages) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.description = description;
|
||||
this.defaultBranch = defaultBranch;
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
|
||||
// Getter
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getDefaultBranch() {
|
||||
return defaultBranch;
|
||||
}
|
||||
|
||||
public ArrayList<XmlMetaPageModel> getPages() {
|
||||
return pages;
|
||||
}
|
||||
|
||||
// Setter
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setDefaultBranch(String defaultBranch) {
|
||||
this.defaultBranch = defaultBranch;
|
||||
}
|
||||
|
||||
public void setPages(ArrayList<XmlMetaPageModel> pages) {
|
||||
this.pages = pages;
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
|
||||
public void addPage(XmlMetaPageModel page) {
|
||||
this.pages.add(page);
|
||||
}
|
||||
|
||||
public void addPageAfterIndex(int index, XmlMetaPageModel page) {
|
||||
this.pages.add(index, page);
|
||||
|
||||
//Update index
|
||||
this.updateIndex();
|
||||
}
|
||||
|
||||
public void removePage(XmlMetaPageModel page) {
|
||||
this.pages.remove(page);
|
||||
}
|
||||
|
||||
public void removePageAtIndex(int index) {
|
||||
this.pages.remove(index);
|
||||
|
||||
//Update index
|
||||
this.updateIndex();
|
||||
}
|
||||
|
||||
// Internal Methods
|
||||
private void updateIndex() { // TODO-rca: 効率悪そう
|
||||
for (int i = 0; i < this.pages.size(); i++) {
|
||||
this.pages.get(i).setIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package one.nem.lacerta.model.document.internal;
|
||||
|
||||
public class XmlMetaPageModel {
|
||||
|
||||
int index;
|
||||
String filename;
|
||||
|
||||
// Constructor
|
||||
|
||||
public XmlMetaPageModel() {
|
||||
}
|
||||
|
||||
public XmlMetaPageModel(int index, String filename) {
|
||||
this.index = index;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
// Getter
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// Setter
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
}
|
||||
@@ -32,4 +32,16 @@ dependencies {
|
||||
testImplementation libs.junit
|
||||
androidTestImplementation libs.androidx.test.ext.junit
|
||||
androidTestImplementation libs.androidx.test.espresso.core
|
||||
|
||||
// DI
|
||||
implementation libs.com.google.dagger.hilt.android
|
||||
annotationProcessor libs.com.google.dagger.hilt.compiler
|
||||
|
||||
// JGit
|
||||
implementation 'org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r'
|
||||
|
||||
implementation project(':model')
|
||||
implementation project(':source')
|
||||
implementation project(':utils')
|
||||
implementation project(':data')
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package one.nem.lacerta.processor;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
public interface DocumentProcessor {
|
||||
|
||||
// ページ操作
|
||||
void addNewPageToLast(Bitmap bitmap);
|
||||
void addNewPagesToLast(Bitmap[] bitmaps);
|
||||
void addNewPageAfterIndex(Bitmap bitmap, int index);
|
||||
void addNewPageBeforeIndex(Bitmap bitmap, int index);
|
||||
void removePageAtIndex(int index);
|
||||
|
||||
// 更新
|
||||
void updatePageAtIndex(Bitmap bitmap, int index);
|
||||
|
||||
// ページ取得
|
||||
Bitmap getPageAtIndex(int index);
|
||||
int getPageCount();
|
||||
|
||||
void close();
|
||||
void init();
|
||||
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package one.nem.lacerta.processor.factory;
|
||||
|
||||
import dagger.assisted.AssistedFactory;
|
||||
import one.nem.lacerta.model.document.DocumentDetail;
|
||||
import one.nem.lacerta.processor.impl.DocumentProcessorImpl;
|
||||
|
||||
@AssistedFactory
|
||||
public interface DocumentProcessorFactory {
|
||||
DocumentProcessorImpl create(DocumentDetail documentDetail);
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package one.nem.lacerta.processor.impl;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
import one.nem.lacerta.processor.DocumentProcessor;
|
||||
|
||||
import one.nem.lacerta.model.document.DocumentDetail;
|
||||
|
||||
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||
import one.nem.lacerta.source.file.FileManager;
|
||||
import one.nem.lacerta.source.file.factory.FileManagerFactory;
|
||||
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
|
||||
import one.nem.lacerta.utils.XmlMetaParser;
|
||||
|
||||
|
||||
public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
|
||||
// Magic Numbers
|
||||
private static final String DEFAULT_SAVE_DIR = "raw";
|
||||
private final DocumentDetail documentDetail;
|
||||
private XmlMetaModel xmlMetaModel;
|
||||
private Path documentRootPath;
|
||||
|
||||
// Injection
|
||||
private final FileManagerFactory fileManagerFactory;
|
||||
private final LacertaLogger logger;
|
||||
private final XmlMetaParser xmlMetaParser;
|
||||
@AssistedInject
|
||||
public DocumentProcessorImpl(FileManagerFactory fileManagerFactory, LacertaLogger logger, XmlMetaParser xmlMetaParser, @Assisted DocumentDetail documentDetail) {
|
||||
this.fileManagerFactory = fileManagerFactory;
|
||||
this.logger = logger;
|
||||
this.xmlMetaParser = xmlMetaParser;
|
||||
if (documentDetail == null) {
|
||||
throw new IllegalArgumentException("documentDetail must not be null");
|
||||
}
|
||||
this.documentDetail = documentDetail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
logger.debug("init", "called");
|
||||
// Init Variables
|
||||
this.documentRootPath = documentDetail.getPath().getFullPath();
|
||||
logger.debug("init", "documentRootPath: " + this.documentRootPath);
|
||||
|
||||
FileManager fileManager = fileManagerFactory.create(this.documentRootPath); //Initialize FileManager
|
||||
logger.debug("init", "fileManager created");
|
||||
|
||||
fileManager.autoCreateDir(this.documentRootPath);
|
||||
|
||||
// rawディレクトリInit
|
||||
fileManager.autoCreateDir(DEFAULT_SAVE_DIR);
|
||||
|
||||
// xmlファイルの読み込み
|
||||
if (fileManager.isExist("meta.xml")) {
|
||||
logger.debug("init", "meta.xml found");
|
||||
try {
|
||||
xmlMetaModel = xmlMetaParser.deserialize(fileManager.loadDocument("meta.xml"));
|
||||
} catch (Exception e) {
|
||||
logger.debug("init", "meta.xml parse failed");
|
||||
logger.trace("init", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
logger.debug("init", "meta.xml not found");
|
||||
xmlMetaModel = new XmlMetaModel();
|
||||
|
||||
xmlMetaModel.setTitle(documentDetail.getMeta().getTitle());
|
||||
xmlMetaModel.setAuthor(documentDetail.getAuthor());
|
||||
xmlMetaModel.setDescription(""); // FIXME-rca:
|
||||
xmlMetaModel.setDefaultBranch(documentDetail.getDefaultBranch());
|
||||
xmlMetaModel.setPages(new ArrayList<>());
|
||||
|
||||
try {
|
||||
fileManager.saveDocument(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
|
||||
logger.debug("init", "meta.xml saved");
|
||||
} catch (Exception e) {
|
||||
logger.error("init", "meta.xml save failed");
|
||||
logger.trace("init", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("init", "finished");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPageToLast(Bitmap bitmap) {
|
||||
logger.debug("addNewPageToLast", "called");
|
||||
String fileName = String.format(UUID.randomUUID().toString() + ".png"); // TODO-rca: 対応表をもたせる
|
||||
logger.debug("addNewPageToLast", "fileName: " + fileName);
|
||||
FileManager fileManager = fileManagerFactory.create(this.documentRootPath);
|
||||
if(fileManager.getList().contains(this.documentRootPath.resolve(DEFAULT_SAVE_DIR))) {
|
||||
logger.debug("addNewPageToLast", "raw dir found");
|
||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
||||
} else {
|
||||
logger.debug("addNewPageToLast", "raw dir not found");
|
||||
fileManager.createDir(DEFAULT_SAVE_DIR);
|
||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
||||
}
|
||||
fileManager.saveBitmapAtCurrent(bitmap, fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPagesToLast(Bitmap[] bitmaps) {
|
||||
logger.debug("addNewPagesToLast(List)", "called");
|
||||
for(Bitmap bitmap : bitmaps) {
|
||||
addNewPageToLast(bitmap);
|
||||
} // TODO-rca: 保存処理をまとめて行う?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPageAfterIndex(Bitmap bitmap, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPageBeforeIndex(Bitmap bitmap, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePageAtIndex(int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePageAtIndex(Bitmap bitmap, int index) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap getPageAtIndex(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPageCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,16 @@
|
||||
package one.nem.lacerta.processor.module;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
import one.nem.lacerta.model.document.DocumentDetail;
|
||||
|
||||
public class DocumentProcessorModule {
|
||||
|
||||
private final DocumentDetail documentDetail;
|
||||
|
||||
@AssistedInject
|
||||
public DocumentProcessorModule(@Assisted DocumentDetail documentDetail) {
|
||||
this.documentDetail = documentDetail;
|
||||
}
|
||||
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,4 @@
|
||||
<resources>
|
||||
<!-- TODO: Remove or change this placeholder text -->
|
||||
<string name="hello_blank_fragment">Hello blank fragment</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,57 @@
|
||||
package one.nem.lacerta.source.file;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/** @noinspection unused*/
|
||||
public interface FileManager {
|
||||
|
||||
Path getRootDir();
|
||||
void changeDir(String dirName); //cd
|
||||
void changeDir(Path path); //cd
|
||||
void backDir(); //cd ..
|
||||
void backRootDir(); //cd /
|
||||
List<Path> getList();
|
||||
void createDir(String dirName);
|
||||
void createDir(Path path);
|
||||
void removeDir(String dirName);
|
||||
void removeDir(Path path);
|
||||
|
||||
File createFile(String fileName);
|
||||
void removeFile(String fileName);
|
||||
|
||||
File getFile(String fileName);
|
||||
File getFile(Path path);
|
||||
|
||||
String loadText(String fileName);
|
||||
String loadText(Path path);
|
||||
|
||||
void saveText(String text, String fileName);
|
||||
void saveText(String text, Path path);
|
||||
|
||||
void saveDocument(Document document, String fileName);
|
||||
void saveDocument(Document document, Path path);
|
||||
|
||||
Document loadDocument(String fileName);
|
||||
Document loadDocument(Path path);
|
||||
|
||||
|
||||
boolean isExist(Path path);
|
||||
boolean isExist(String fileName);
|
||||
|
||||
void autoCreateDir(Path path);
|
||||
void autoCreateDir(String dirName);
|
||||
|
||||
void autoCreateToCurrentDir();
|
||||
|
||||
void saveBitmapAtCurrent(Bitmap bitmap, String fileName);
|
||||
Bitmap loadBitmap(Path path);
|
||||
void removeBitmap(Path path);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package one.nem.lacerta.source.file.factory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import dagger.assisted.AssistedFactory;
|
||||
import one.nem.lacerta.source.file.impl.FileManagerImpl;
|
||||
|
||||
@AssistedFactory
|
||||
public interface FileManagerFactory {
|
||||
FileManagerImpl create(Path rootDir);
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,342 @@
|
||||
package one.nem.lacerta.source.file.impl;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
import one.nem.lacerta.source.file.FileManager;
|
||||
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
|
||||
public class FileManagerImpl implements FileManager {
|
||||
|
||||
// RootDir
|
||||
private Path rootDir;
|
||||
|
||||
// CurrentDir
|
||||
private Path currentDir;
|
||||
|
||||
// Internal Methods
|
||||
private Path convertPath(String path) {
|
||||
Path convertedPath = currentDir.resolve(path);
|
||||
if (convertedPath.startsWith(rootDir)) { // 異常なパスの場合はnullを返す // TODO-rca: エラーハンドリング
|
||||
return convertedPath;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Injection
|
||||
private LacertaLogger logger;
|
||||
|
||||
@AssistedInject
|
||||
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
|
||||
this.logger = logger;
|
||||
this.rootDir = rootDir;
|
||||
this.currentDir = rootDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getRootDir() {
|
||||
return rootDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeDir(String dirName) {
|
||||
this.currentDir = rootDir.resolve(dirName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeDir(Path path) {
|
||||
if (path.startsWith(rootDir)) {
|
||||
this.currentDir = path;
|
||||
}
|
||||
else {
|
||||
logger.debug("changeDir", "invalid path: " + path);
|
||||
// TODO-rca: 例外を投げる
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backDir() {
|
||||
this.currentDir = currentDir.getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backRootDir() {
|
||||
this.currentDir = rootDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Path> getList() {
|
||||
List<Path> list = new ArrayList<>();
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(currentDir)) {
|
||||
for (Path entry : stream) { // TODO-rca: エラーハンドリング, 効率化
|
||||
list.add(entry);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDir(String dirName) {
|
||||
//ディレクトリ作成
|
||||
logger.debug("createDir", "called");
|
||||
|
||||
Path path = currentDir.resolve(dirName);
|
||||
logger.debug("createDir", "path: " + path);
|
||||
try {
|
||||
Files.createDirectory(path);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDir(Path path) {
|
||||
logger.debug("createDir", "called");
|
||||
try {
|
||||
Files.createDirectory(path);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDir(String dirName) {
|
||||
logger.debug("removeDir", "called");
|
||||
currentDir.resolve(dirName).toFile().delete(); // TODO-rca: エラーハンドリング
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDir(Path path) {
|
||||
logger.debug("removeDir", "called");
|
||||
path.toFile().delete(); // TODO-rca: エラーハンドリング
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public File createFile(String fileName) {
|
||||
logger.debug("createFile", "called");
|
||||
return currentDir.resolve(fileName).toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFile(String fileName) {
|
||||
logger.debug("removeFile", "called");
|
||||
currentDir.resolve(fileName).toFile().delete(); // TODO-rca: エラーハンドリング
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile(String fileName) {
|
||||
logger.debug("getFile", "called");
|
||||
return currentDir.resolve(fileName).toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile(Path path) {
|
||||
logger.debug("getFile", "called");
|
||||
return path.toFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loadText(String fileName) { // TODO-rca: 統合
|
||||
try(FileInputStream fileInputStream = new FileInputStream(currentDir.resolve(fileName).toFile())) {
|
||||
byte[] bytes = new byte[fileInputStream.available()];
|
||||
fileInputStream.read(bytes); // TODO-rca: エラーハンドリング
|
||||
return new String(bytes);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loadText(Path path) {
|
||||
try(FileInputStream fileInputStream = new FileInputStream(path.toFile())) {
|
||||
byte[] bytes = new byte[fileInputStream.available()];
|
||||
fileInputStream.read(bytes); // TODO-rca: エラーハンドリング
|
||||
return new String(bytes);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveText(String text, String fileName) { // TODO-rca: リファクタリング // TODO-rca: 統合
|
||||
if (isExist(fileName)) {
|
||||
logger.debug("saveText", "file already exists");
|
||||
// Overwrite
|
||||
try {
|
||||
Files.write(currentDir.resolve(fileName), text.getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Files.createFile(currentDir.resolve(fileName));
|
||||
Files.write(currentDir.resolve(fileName), text.getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveText(String text, Path path) {
|
||||
if (isExist(path)) {
|
||||
logger.debug("saveText", "file already exists");
|
||||
// Overwrite
|
||||
try {
|
||||
Files.write(path, text.getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Files.createFile(path);
|
||||
Files.write(path, text.getBytes());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDocument(Document document, String fileName) {
|
||||
try {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMSource source = new DOMSource(document);
|
||||
File file = createFile(fileName);
|
||||
StreamResult result = new StreamResult(file);
|
||||
transformer.transform(source, result);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDocument(Document document, Path path) {
|
||||
// TODO-rca 実装する
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document loadDocument(String fileName) {
|
||||
try {
|
||||
File file = getFile(fileName);
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.parse(file);
|
||||
return document;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document loadDocument(Path path) {
|
||||
// TODO-rca 実装する
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExist(Path path) {
|
||||
logger.debug("isExist", "called");
|
||||
return Files.exists(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExist(String fileName) {
|
||||
logger.debug("isExist", "called");
|
||||
return Files.exists(currentDir.resolve(fileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoCreateDir(Path path) {
|
||||
logger.debug("autoCreateDir", "called");
|
||||
if (!Files.exists(path)) {
|
||||
try {
|
||||
Files.createDirectories(path);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoCreateDir(String dirName) {
|
||||
logger.debug("autoCreateDir", "called");
|
||||
if (!Files.exists(currentDir.resolve(dirName))) {
|
||||
try {
|
||||
Files.createDirectories(currentDir.resolve(dirName));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoCreateToCurrentDir() {
|
||||
logger.debug("autoGenerateToCurrentDir", "called");
|
||||
if (isExist(currentDir)) {
|
||||
logger.debug("autoGenerateToCurrentDir", "currentDir already exists");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
Files.createDirectories(currentDir);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveBitmapAtCurrent(Bitmap bitmap, String fileName) { // TODO-rca: ファイル形式を変更できるようにする?
|
||||
logger.debug("saveBitmapAtCurrent", "called");
|
||||
try {
|
||||
File file = currentDir.resolve(fileName).toFile();
|
||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(file.toPath()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap loadBitmap(Path path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBitmap(Path path) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,20 @@
|
||||
package one.nem.lacerta.source.file.module;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
|
||||
public class FileManagerModule {
|
||||
|
||||
private final Path rootDir;
|
||||
|
||||
@AssistedInject
|
||||
public FileManagerModule(@Assisted Path rootDir) {
|
||||
this.rootDir = rootDir;
|
||||
}
|
||||
|
||||
public Path getRootDir() {
|
||||
return rootDir;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
+2
-1
@@ -37,5 +37,6 @@ dependencies {
|
||||
implementation libs.com.google.dagger.hilt.android
|
||||
annotationProcessor libs.com.google.dagger.hilt.compiler
|
||||
|
||||
//
|
||||
// model
|
||||
implementation project(':model')
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package one.nem.lacerta.utils;
|
||||
|
||||
import one.nem.lacerta.utils.model.KeyValueLog;
|
||||
|
||||
public interface LacertaLogger {
|
||||
|
||||
void info(String tag, String message);
|
||||
@@ -9,4 +11,7 @@ public interface LacertaLogger {
|
||||
void trace(String tag, String message);
|
||||
void fatal(String tag, String message);
|
||||
|
||||
String buildKVMessage(KeyValueLog... logs);
|
||||
// With name
|
||||
String buildKVMessage(String name, KeyValueLog... logs);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package one.nem.lacerta.utils;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||
|
||||
public interface XmlMetaParser {
|
||||
|
||||
XmlMetaModel deserialize(Document document);
|
||||
|
||||
Document serialize(XmlMetaModel meta);
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import android.util.Log;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
import one.nem.lacerta.utils.model.KeyValueLog;
|
||||
|
||||
public class LacertaLoggerImpl implements LacertaLogger{
|
||||
|
||||
@Inject
|
||||
@@ -40,4 +42,30 @@ public class LacertaLoggerImpl implements LacertaLogger{
|
||||
public void fatal(String tag, String message) {
|
||||
Log.wtf(tag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildKVMessage(KeyValueLog... logs) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (KeyValueLog log : logs) {
|
||||
builder.append(log.getKey());
|
||||
builder.append(": ");
|
||||
builder.append(log.getValue());
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildKVMessage(String name, KeyValueLog... logs) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(name);
|
||||
builder.append("\n");
|
||||
for (KeyValueLog log : logs) {
|
||||
builder.append(log.getKey());
|
||||
builder.append(": ");
|
||||
builder.append(log.getValue());
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package one.nem.lacerta.utils.impl;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import one.nem.lacerta.model.document.internal.XmlMetaModel;
|
||||
import one.nem.lacerta.model.document.internal.XmlMetaPageModel;
|
||||
import one.nem.lacerta.utils.XmlMetaParser;
|
||||
|
||||
import one.nem.lacerta.utils.LacertaLogger;
|
||||
|
||||
public class XmlMetaParserImpl implements XmlMetaParser{
|
||||
|
||||
@Inject
|
||||
LacertaLogger logger;
|
||||
|
||||
@Inject
|
||||
public XmlMetaParserImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlMetaModel deserialize(Document document) {
|
||||
logger.debug("deserialize", "called");
|
||||
try {
|
||||
Element rootElement = document.getDocumentElement();
|
||||
|
||||
XmlMetaModel meta = new XmlMetaModel();
|
||||
|
||||
meta.setTitle(rootElement.getElementsByTagName("title").item(0).getTextContent());
|
||||
meta.setAuthor(rootElement.getElementsByTagName("author").item(0).getTextContent());
|
||||
meta.setDescription(rootElement.getElementsByTagName("description").item(0).getTextContent());
|
||||
meta.setDefaultBranch(rootElement.getElementsByTagName("defaultBranch").item(0).getTextContent());
|
||||
|
||||
ArrayList<XmlMetaPageModel> pages = new ArrayList<>();
|
||||
for(int i = 0; i < rootElement.getElementsByTagName("pages").getLength(); i++) {
|
||||
Element pageElement = (Element) rootElement.getElementsByTagName("page").item(i);
|
||||
XmlMetaPageModel page = new XmlMetaPageModel();
|
||||
page.setIndex(Integer.parseInt(pageElement.getElementsByTagName("index").item(0).getTextContent()));
|
||||
page.setFilename(pageElement.getElementsByTagName("filename").item(0).getTextContent());
|
||||
pages.add(page);
|
||||
}
|
||||
|
||||
meta.setPages(pages);
|
||||
|
||||
return meta;
|
||||
} catch (Exception e) {
|
||||
logger.error("deserialize", "something wrong");
|
||||
logger.trace("deserialize", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Document serialize(XmlMetaModel meta) {
|
||||
logger.debug("serialize", "called");
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
|
||||
Element rootElement = document.createElement("meta");
|
||||
|
||||
appendElement(document, rootElement, "title", meta.getTitle());
|
||||
appendElement(document, rootElement, "author", meta.getAuthor());
|
||||
appendElement(document, rootElement, "description", meta.getDescription());
|
||||
appendElement(document, rootElement, "defaultBranch", meta.getDefaultBranch());
|
||||
|
||||
Element pagesElement = document.createElement("pages");
|
||||
for(XmlMetaPageModel page : meta.getPages()) {
|
||||
Element pageElement = document.createElement("page");
|
||||
appendElement(document, pageElement, "index", String.valueOf(page.getIndex()));
|
||||
appendElement(document, pageElement, "filename", page.getFilename());
|
||||
pagesElement.appendChild(pageElement);
|
||||
}
|
||||
|
||||
rootElement.appendChild(pagesElement);
|
||||
|
||||
document.appendChild(rootElement);
|
||||
|
||||
return document;
|
||||
} catch (Exception e) {
|
||||
logger.error("serialize", "something wrong");
|
||||
logger.trace("serialize", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// Internal Methods
|
||||
private void appendElement(Document document, Element rootElement, String name, String textContent) {
|
||||
Element element = document.createElement(name);
|
||||
element.setTextContent(textContent);
|
||||
rootElement.appendChild(element);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package one.nem.lacerta.utils.model;
|
||||
|
||||
public class KeyValueLog {
|
||||
|
||||
String key;
|
||||
String value;
|
||||
|
||||
public KeyValueLog(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
// Getter
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Setter
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package one.nem.lacerta.utils.module;
|
||||
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.components.SingletonComponent;
|
||||
|
||||
import one.nem.lacerta.utils.XmlMetaParser;
|
||||
import one.nem.lacerta.utils.impl.XmlMetaParserImpl;
|
||||
@Module
|
||||
@InstallIn(SingletonComponent.class)
|
||||
abstract public class XmlMetaParserModule {
|
||||
|
||||
@Binds
|
||||
public abstract XmlMetaParser bindXmlMetaParser(XmlMetaParserImpl impl);
|
||||
}
|
||||
Reference in new issue
Block a user