Compare commits

..
Author SHA1 Message Date
ろむねこ b67887d4a6 Revert "一旦過去に作成したフラグメントを削除"
This reverts commit fc716df189.
2023-12-21 12:34:46 +09:00
ろむねこ fa299bef21 Revert "スキャナのスタブを実装 WIP"
This reverts commit 4a39c5c525.
2023-12-21 12:34:46 +09:00
ろむねこ b3fe7b08e3 Revert "レイアウト作成 WIP"
This reverts commit b7f91b593e.
2023-12-21 12:34:46 +09:00
ろむねこ 16c93dc9a3 Revert "依存関係追加"
This reverts commit ed9e20ede3.
2023-12-21 12:34:46 +09:00
ろむねこ 25ae68219f Revert "テーマ設定"
This reverts commit 5617dacfe7.
2023-12-21 12:34:46 +09:00
ろむねこ 5c45ebffe3 Revert "レイアウトマージン修正"
This reverts commit 8c83c7adcf.
2023-12-21 12:34:46 +09:00
ろむねこ e763c229e9 Revert "スタイル変更"
This reverts commit 13b53c62ec.
2023-12-21 12:34:46 +09:00
ろむねこ 1fae335355 Revert "引数削除"
This reverts commit ccbbb45f39.
2023-12-21 12:34:46 +09:00
ろむねこ 3572fce1cf Revert "ロジック実装 WIP"
This reverts commit 031a1d2810.
2023-12-21 12:34:46 +09:00
ろむねこ 6622bd2fc0 Revert "ArrayListに変更"
This reverts commit be80e42dc5.
2023-12-21 12:34:46 +09:00
ろむねこ 6d0173039f Revert "カメラ起動を実装"
This reverts commit 3c6541607c.
2023-12-21 12:34:46 +09:00
ろむねこ 914279a582 Revert "ボタンアクションを実装"
This reverts commit be30ce2c62.
2023-12-21 12:34:46 +09:00
ろむねこ 38fe16609b Revert "debugの依存関係にスキャナコンポーネントを追加"
This reverts commit 4d0412e5bd.
2023-12-21 12:34:46 +09:00
ろむねこ cd92fcbc04 Revert "fix typo"
This reverts commit 011cac925a.
2023-12-21 12:34:46 +09:00
ろむねこ cf012daddf Revert "fix typo"
This reverts commit 60d13ac9a9.
2023-12-21 12:34:46 +09:00
ろむねこ 8a0c1e962d Revert "暫定, debugメニューのナビゲーショングラフに追加"
This reverts commit da2ff27391.
2023-12-21 12:34:46 +09:00
ろむねこ 4483af5c38 Revert "デバッグメニューにリンクを追加"
This reverts commit f14b9accee.
2023-12-21 12:34:46 +09:00
ろむねこ fe404e44dc Revert "パーミッションを追加してみた"
This reverts commit 6ac0599f4c.
2023-12-21 12:34:46 +09:00
ろむねこ ce6e76f37f Revert "ログ追加"
This reverts commit 0bf6b3fa1a.
2023-12-21 12:34:46 +09:00
ろむねこ 777c75477d Revert "まちがえてrequireActivityを使っていたので修正"
This reverts commit 8e97dd6972.
2023-12-21 12:34:46 +09:00
ろむねこ 89b12cf10a Revert "レイアウトにRecyclerViewを追加"
This reverts commit e3220910f5.
2023-12-21 12:34:46 +09:00
ろむねこ 6a8b0f2e21 Revert "仮置きデータモデル作成"
This reverts commit 2c74fa3339.
2023-12-21 12:34:46 +09:00
ろむねこ 1c38f889a9 Revert "仮置きデータモデル作成"
This reverts commit d5f3d36d23.
2023-12-21 12:34:46 +09:00
ろむねこ a879b8bb16 Revert "レイアウトファイル作成"
This reverts commit 955c0122cf.
2023-12-21 12:34:46 +09:00
ろむねこ 185b3b899c Revert "レイアウト実装WIP"
This reverts commit e9f2a6b711.
2023-12-21 12:34:46 +09:00
ろむねこ b2a96c30d9 Revert "レイアウト修正"
This reverts commit 3db91fb937.
2023-12-21 12:34:46 +09:00
ろむねこ 5c28a0852d Revert "レイアウト修正"
This reverts commit 9c79e02cc8.
2023-12-21 12:34:46 +09:00
ろむねこ 51fbcb1852 Revert "レイアウト修正"
This reverts commit 979a3f8ee7.
2023-12-21 12:34:46 +09:00
ろむねこ 44e45c0c9d Revert "fix typo"
This reverts commit 48de3f9a8d.
2023-12-21 12:34:46 +09:00
ろむねこ 29da95e67d Revert "レイアウト修正"
This reverts commit a3edcf845a.
2023-12-21 12:34:46 +09:00
ろむねこ 5565bc0d91 Revert "命名修正"
This reverts commit 9ec45096ba.
2023-12-21 12:34:46 +09:00
ろむねこ 3a7b28e330 Revert "WIP 結果をプレビューするロジック実装"
This reverts commit b3dcaefede.
2023-12-21 12:34:46 +09:00
ろむねこ ad3e8946de Revert "WIP 内部クラスじゃだめそうなので切り出し"
This reverts commit 99dea6d6f6.
2023-12-21 12:34:46 +09:00
ろむねこ c5c1a16282 Revert "内部クラスじゃだめそうなので切り出し"
This reverts commit aa4f8360dc.
2023-12-21 12:34:46 +09:00
ろむねこ c82050b931 Revert "Revert "内部クラスじゃだめそうなので切り出し""
This reverts commit c616edf9f7.
2023-12-21 12:34:46 +09:00
ろむねこ 2cfdcec70b Revert "Revert "WIP 内部クラスじゃだめそうなので切り出し""
This reverts commit b5281443bf.
2023-12-21 12:34:46 +09:00
ろむねこ 472ecd2e41 Revert "WIP"
This reverts commit ad66688bf9.
2023-12-21 12:34:46 +09:00
ろむねこ b311b55455 Revert "Revert "Revert "WIP 内部クラスじゃだめそうなので切り出し"""
This reverts commit 9cbf6f9d56.
2023-12-21 12:34:46 +09:00
ろむねこ 562e46f058 Revert "Revert "Revert "内部クラスじゃだめそうなので切り出し"""
This reverts commit d5616d63b6.
2023-12-21 12:34:46 +09:00
ろむねこ 4776656f95 Revert "レイアウト修正"
This reverts commit 8817c62ed3.
2023-12-21 12:34:46 +09:00
ろむねこ b83085d32a Revert "レイアウト修正"
This reverts commit f74abd11fc.
2023-12-21 12:34:46 +09:00
ろむねこ 49e8a6e6bb Revert "取得される画像の解像度が低すぎるので修正 WIP"
This reverts commit 55ae0b541a.
2023-12-21 12:34:46 +09:00
ろむねこ cfde0b1e91 Revert "AndroidManifest.xmlにFileProviderを追加 WIP"
This reverts commit b12c689d4e.
2023-12-21 12:34:46 +09:00
ろむねこ 5ec12658ef Revert "プロバイダパスを追加"
This reverts commit be610059cf.
2023-12-21 12:34:46 +09:00
ろむねこ c0d56ec3c0 Revert "プロバイダパスを追加"
This reverts commit f9247e9114.
2023-12-21 12:34:46 +09:00
ろむねこ 1a2e705906 Revert "権限修正"
This reverts commit 3518464716.
2023-12-21 12:34:46 +09:00
ろむねこ a62b882fe7 Revert "一旦保存して読み込むように"
This reverts commit 83d2d0af02.
2023-12-21 12:34:46 +09:00
ろむねこ 3e7ceb774e Revert "コメント追加"
This reverts commit bbeba2b733.
2023-12-21 12:34:46 +09:00
ろむねこ ad4f8a9aec Revert "余白が異常に大きくなるのを修正"
This reverts commit 732f047ff7.
2023-12-21 12:34:46 +09:00
ろむねこ 2b8c0fbadf Revert "レイアウトマージン設定"
This reverts commit c7a387df3d.
2023-12-21 12:34:46 +09:00
60 changed files with 313 additions and 2195 deletions

No files matched your search

@@ -1,17 +0,0 @@
---
name: 不具合用テンプレート
about: 不具合用テンプレート
title: "[BUG]: "
labels: バグ
assignees: ''
---
# 概要
<!-- Issueの概要 -->
# 詳細
<!-- バグの詳細 -->
# 影響箇所
<!-- 予想される影響箇所(省略可) -->
@@ -1,17 +0,0 @@
---
name: 改善用テンプレート
about: 改善用テンプレート
title: "[IMPROVE]"
labels: ''
assignees: ''
---
# 概要
<!-- Issueの概要 -->
# 詳細
<!-- 改善内容の詳細 -->
# 影響箇所
<!-- 予想される影響箇所(省略可) -->
@@ -1,20 +1,10 @@
---
name: 新機能用テンプレート
about: 新規能用テンプレート
about: 新規開発Issue用テンプレート
title: ''
labels: 新機能
labels: ''
assignees: ''
---
# 概要
<!-- Issueの概要 -->
# 詳細
<!-- 機能の詳細 -->
# 関連Issue
<!-- 関連するIssueがあれば -->
# 影響箇所
<!-- 予想される影響箇所(省略可) -->
WIP
-18
View File
@@ -1,18 +0,0 @@
# 概要
<!-- PRの概要 -->
# 関連Issue
- #000 <!-- 関連するIssueを指定(なければ省略可) -->
# 詳細
<!-- 詳細 -->
# 影響箇所
<!-- 予想される影響箇所 -->
# チェック
<!-- 参考用, 全てにチェックがついている必要があるわけではありません -->
- [ ] 機能として完成している
- [ ] WIP(Work in progress: 作業中)
- [ ] 正常にビルド/起動ができる
- [ ] 既存の機能を壊していない
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State />
</entry>
</value>
</component>
</project>
-1
View File
@@ -4,7 +4,6 @@
<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">
+1 -1
View File
@@ -1,6 +1,6 @@
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
-21
View File
@@ -2,17 +2,6 @@
<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"
@@ -33,16 +22,6 @@
<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>
-4
View File
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="cache" path="." />
</paths>
-12
View File
@@ -1,6 +1,5 @@
plugins {
alias(libs.plugins.com.android.library)
id 'com.google.dagger.hilt.android'
}
android {
@@ -34,16 +33,5 @@ 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')
}
@@ -1,55 +0,0 @@
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);
}
}
}
@@ -1,44 +0,0 @@
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;
}
}
@@ -1,250 +0,0 @@
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();
try {
this.documentProcessor.init();
} catch (Exception e) {
Toast.makeText(getActivity(), "Error occurred while initializing documentProcessor", Toast.LENGTH_LONG).show();
Log.e("ScannerDataManagerStubFragment", "Error occurred while initializing documentProcessor", e);
}
Toast.makeText(getActivity(), "documentProcessor initialized", Toast.LENGTH_LONG).show();
});
view.findViewById(R.id.button_add_page).setOnClickListener(v -> {
Log.d("ScannerDataManagerStubFragment", "button_add_page clicked");
Toast.makeText(getActivity(), "button_add_page clicked", Toast.LENGTH_LONG).show();
if (this.documentProcessor == null) {
Toast.makeText(getActivity(), "documentProcessor is null", Toast.LENGTH_LONG).show();
return;
}
Bitmap[] bitmaps = new Bitmap[results.size()];
for (int i = 0; i < results.size(); i++) {
bitmaps[i] = results.get(i).getBitmap();
}
try {
this.documentProcessor.addNewPagesToLast(bitmaps);
} catch (Exception e) {
Toast.makeText(getActivity(), "Error occurred while adding pages", Toast.LENGTH_LONG).show();
Log.e("ScannerDataManagerStubFragment", "Error occurred while adding pages", e);
}
Toast.makeText(getActivity(), "pages added", Toast.LENGTH_LONG).show();
try {
this.documentProcessor.close();
} catch (Exception e) {
Toast.makeText(getActivity(), "Error occurred while closing documentProcessor", Toast.LENGTH_LONG).show();
Log.e("ScannerDataManagerStubFragment", "Error occurred while closing documentProcessor", e);
}
});
}
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));
}
}
@@ -0,0 +1,75 @@
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
);
}
}
@@ -0,0 +1,64 @@
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);
}
}
@@ -1,93 +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: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>
@@ -0,0 +1,14 @@
<?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>
@@ -0,0 +1,133 @@
<?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>
@@ -1,70 +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="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>
-6
View File
@@ -62,10 +62,4 @@ dependencies {
// Shared
implementation project(':shared:ui')
// Scanner
implementation project(':component:scanner')
// Processor
implementation project(':processor')
}
@@ -1,44 +0,0 @@
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;
}
}
@@ -1,110 +0,0 @@
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,7 +12,6 @@ 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;
@@ -21,7 +20,6 @@ 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
@@ -50,8 +48,6 @@ 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);
@@ -1,36 +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: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>
@@ -1,40 +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"
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,12 +16,6 @@
<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"
@@ -50,13 +44,4 @@
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>
-14
View File
@@ -1,6 +1,5 @@
plugins {
id 'com.android.library'
id 'com.google.dagger.hilt.android'
}
android {
@@ -30,8 +29,6 @@ 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
@@ -41,15 +38,4 @@ 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')
implementation project(':model')
implementation project(':data')
}
@@ -1,55 +0,0 @@
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;
import one.nem.lacerta.model.document.DocumentMeta;
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.DocumentViewHolder> {
private List<DocumentMeta> documentMetas;
public DocumentAdapter(List<DocumentMeta> documentMetas) {
// nullの場合に例外を発生させる
if (documentMetas == null) {
throw new IllegalArgumentException("DocumentMetas list cannot be null or empty");
}
this.documentMetas = documentMetas;
}
@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) {
DocumentMeta documentMeta = documentMetas.get(position);
if (documentMeta != null) {
holder.title.setText(documentMeta.getTitle());
}
}
@Override
public int getItemCount() {
return documentMetas.size();
}
class DocumentViewHolder extends RecyclerView.ViewHolder {
TextView title;
DocumentViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.debug_menu_item_title); // 適切な id に変更する
}
}
}
@@ -1,38 +0,0 @@
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
//画面変移用のコード
//Fragmentへのデータの受け渡し機能
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);
}
});
}
}
@@ -1,51 +0,0 @@
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;
//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;
}
}
@@ -2,40 +2,19 @@ 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 android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
import one.nem.lacerta.data.Document;
import one.nem.lacerta.model.document.DocumentMeta;
import one.nem.lacerta.model.document.tag.DocumentTag;
/**
* A simple {@link Fragment} subclass.
* Use the {@link LibraryTopFragment#newInstance} factory method to
* create an instance of this fragment.
*/
@AndroidEntryPoint
public class LibraryTopFragment extends Fragment {
@Inject
Document document;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
@@ -76,29 +55,10 @@ 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
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<DocumentMeta> metas = document.getAllDocumentMetas(100);
Toast.makeText(getContext(), "Documents: " + Integer.toString(metas.size()), Toast.LENGTH_LONG).show();
// Create and set the adapter
DocumentAdapter adapter = new DocumentAdapter(metas);
documentRecyclerView.setAdapter(adapter);
// Use a LinearLayoutManager to specify the layout
return view;
return inflater.inflate(R.layout.fragment_library_top, container, false);
}
}
}
@@ -1,17 +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"
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,32 +1,14 @@
<?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"
<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"
android:theme="@style/Theme.Lacerta"
tools:context=".LibraryTopFragment">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/tool_bar"
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
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" />
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
<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>
</FrameLayout>
@@ -1,26 +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"
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,3 +1,4 @@
<resources>
<string name="app_name">Library</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
@@ -1,104 +0,0 @@
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);
}
}
}
@@ -1,37 +0,0 @@
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;
}
}
-12
View File
@@ -32,16 +32,4 @@ 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')
}
@@ -1,24 +0,0 @@
package one.nem.lacerta.processor;
import android.graphics.Bitmap;
public interface DocumentProcessor {
// ページ操作
void addNewPageToLast(Bitmap bitmap) throws Exception;
void addNewPagesToLast(Bitmap[] bitmaps) throws Exception;
void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception;
void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception;
void removePageAtIndex(int index) throws Exception;
// 更新
void updatePageAtIndex(Bitmap bitmap, int index);
// ページ取得
Bitmap getPageAtIndex(int index);
int getPageCount();
void close() throws Exception;
void init() throws Exception; // TODO-rca: 例外処理
}
@@ -1,10 +0,0 @@
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);
}
@@ -1,193 +0,0 @@
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.model.document.internal.XmlMetaPageModel;
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";
// Variables
private final DocumentDetail documentDetail;
private XmlMetaModel xmlMetaModel;
private Path documentRootPath;
private FileManager fileManager;
// 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() throws Exception{
logger.debug("init", "called");
// Init Variables
this.documentRootPath = this.documentDetail.getPath().getFullPath();
logger.debug("init", "documentRootPath: " + this.documentRootPath);
this.fileManager = fileManagerFactory.create(this.documentRootPath).enableAutoCreateParent(); //Initialize FileManager
FileManager initFileManager = this.fileManager.getNewInstance();
logger.debug("init", "fileManager created");
// xmlファイルの読み込み
if (initFileManager.isExist("meta.xml")) {
logger.debug("init", "meta.xml found");
try {
this.xmlMetaModel = xmlMetaParser.deserialize(this.fileManager.loadXml("meta.xml"));
logger.debug("init", "meta.xml parsed");
} 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(this.documentDetail.getMeta().getTitle());
xmlMetaModel.setAuthor(this.documentDetail.getAuthor());
xmlMetaModel.setDescription(""); // FIXME-rca:
xmlMetaModel.setDefaultBranch(this.documentDetail.getDefaultBranch());
xmlMetaModel.setPages(new ArrayList<>());
try {
initFileManager.createFileIfNotExist("meta.xml").saveXml(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) throws Exception{
logger.debug("addNewPageToLast", "called");
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaPageModel.setIndex(xmlMetaModel.getPages().size() + 1);
xmlMetaModel.getPages().add(xmlMetaPageModel);
logger.info("addNewPageToLast", "finished");
logger.info("addNewPageToLast", "filename: " + filename + ", index: " + xmlMetaPageModel.getIndex());
}
@Override
public void addNewPagesToLast(Bitmap[] bitmaps) throws Exception{
logger.debug("addNewPagesToLast", "called");
for (Bitmap bitmap : bitmaps) {
addNewPageToLast(bitmap);
} // TODO-rca: 効率悪いので改善する
}
// Internal
// Indexを振り直す
private ArrayList<XmlMetaPageModel> reIndexPages(ArrayList<XmlMetaPageModel> pages) {
logger.debug("reIndexPages", "called"); // TODO-rca: 効率化
ArrayList<XmlMetaPageModel> newPages = new ArrayList<>();
for (int i = 0; i < pages.size(); i++) {
XmlMetaPageModel xmlMetaPageModel = pages.get(i);
xmlMetaPageModel.setIndex(i + 1);
newPages.add(xmlMetaPageModel);
}
return newPages;
}
@Override
public void addNewPageAfterIndex(Bitmap bitmap, int index) throws Exception {
logger.debug("addNewPageAfterIndex", "called");
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaPageModel.setIndex(index + 1);
xmlMetaModel.getPages().add(index, xmlMetaPageModel);
xmlMetaModel.setPages(reIndexPages(xmlMetaModel.getPages()));
}
@Override
public void addNewPageBeforeIndex(Bitmap bitmap, int index) throws Exception {
logger.debug("addNewPageBeforeIndex", "called");
String filename = UUID.randomUUID().toString() + ".png"; // TODO-rca: 拡張子を動的にする
this.fileManager.getNewInstance().createDirectoryIfNotExist(DEFAULT_SAVE_DIR).resolve(DEFAULT_SAVE_DIR).saveBitmap(bitmap, filename);
XmlMetaPageModel xmlMetaPageModel = new XmlMetaPageModel();
xmlMetaPageModel.setFilename(filename);
xmlMetaPageModel.setIndex(index);
xmlMetaModel.getPages().add(index - 1, xmlMetaPageModel);
xmlMetaModel.setPages(reIndexPages(xmlMetaModel.getPages()));
}
@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() throws Exception{
logger.debug("close", "called");
try {
this.fileManager.getNewInstance().createFileIfNotExist("meta.xml").saveXml(xmlMetaParser.serialize(xmlMetaModel), "meta.xml");
logger.debug("close", "meta.xml saved");
} catch (Exception e) {
logger.error("close", "meta.xml save failed");
logger.trace("close", e.getMessage());
}
}
}
Whitespace-only changes.
@@ -1,16 +0,0 @@
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.
@@ -1,4 +0,0 @@
<resources>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
@@ -1,65 +0,0 @@
package one.nem.lacerta.source.file;
import android.graphics.Bitmap;
import org.w3c.dom.Document;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.List;
/** @noinspection unused*/
public interface FileManager {
File getFileRef();
boolean isExist(String name) throws IOException;
boolean isExist();
boolean isDirectory();
boolean isFile();
boolean isWritable();
boolean isReadable();
// Get current instance
FileManager getCurrentInstance();
FileManager getNewInstance();
// Configure
FileManager enableAutoCreateParent();
FileManager disableRootDirCheck();
FileManager setRootDir(Path rootDir);
FileManager setPath(Path path);
FileManager resolve(String path) throws IOException;
// Create
FileManager createFile() throws IOException;
FileManager createFile(String fileName) throws IOException;
FileManager createFileIfNotExist() throws IOException;
FileManager createFileIfNotExist(String fileName) throws IOException;
FileManager createDirectory() throws IOException;
FileManager createDirectory(String directoryName) throws IOException;
FileManager createDirectoryIfNotExist() throws IOException;
FileManager createDirectoryIfNotExist(String directoryName) throws IOException;
// Save
// XML
void saveXml(Document document, String fileName) throws IOException;
void saveXml(Document document) throws IOException;
// Bitmap
void saveBitmap(Bitmap bitmap, String fileName) throws IOException; // TODO-rca: パラメータに対応させる
void saveBitmap(Bitmap bitmap) throws IOException; // TODO-rca: パラメータに対応させる
// Load
// XML
Document loadXml(String fileName) throws IOException;
Document loadXml() throws IOException;
// Bitmap
Bitmap loadBitmap(String fileName) throws IOException;
Bitmap loadBitmap() throws IOException;
}
@@ -1,11 +0,0 @@
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.
@@ -1,364 +0,0 @@
package one.nem.lacerta.source.file.impl;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import org.w3c.dom.Document;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
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 {
// variables
private Path rootDir;
private Path path;
private boolean autoCreateParent = false;
private boolean disableRootDirCheck = false;
// Injection
private final LacertaLogger logger;
@AssistedInject
public FileManagerImpl(LacertaLogger logger, @Assisted Path rootDir) {
this.logger = logger;
this.rootDir = rootDir;
}
// for generate new instance
public FileManagerImpl(LacertaLogger logger, Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) {
this.logger = logger;
this.rootDir = rootDir;
this.path = path;
this.autoCreateParent = autoCreateParent;
this.disableRootDirCheck = disableRootDirCheck;
}
// Internal
private Path resolveStringPath(String path) throws IOException{
String[] pathArray = path.split("/");
Path resolvedPath = this.path;
for (String pathPart : pathArray) {
if (pathPart.equals("..")) {
resolvedPath = resolvedPath.getParent();
continue;
}
try {
resolvedPath = resolvedPath.resolve(pathPart);
} catch (Exception e) {
throw new IOException("Invalid path: " + path);
}
}
logger.debug("resolveStringPath", "resolvedPath: " + resolvedPath);
return resolvedPath;
}
private FileManager newInstance(Path rootDir, Path path, boolean autoCreateParent, boolean disableRootDirCheck) {
logger.debug("newInstance", "Generating new instance");
logger.debug("newInstance", "Path: " + path);
return new FileManagerImpl(this.logger, rootDir, path, autoCreateParent, disableRootDirCheck);
}
@Override
public File getFileRef() {
if (this.isExist()) {
return this.path.toFile();
} else {
return null;
}
}
@Override
public boolean isExist(String name) throws IOException {
Path resolvedPath = this.resolveStringPath(name);
return Files.exists(resolvedPath);
}
@Override
public boolean isExist(){
return Files.exists(this.path);
}
@Override
public boolean isDirectory() {
if (this.isExist()) {
File file = this.path.toFile();
return file.isDirectory();
} else {
return false;
}
}
@Override
public boolean isFile() {
if (this.isExist()) {
File file = this.path.toFile();
return file.isFile();
} else {
return false;
}
}
@Override
public boolean isReadable() {
if (this.isExist()) {
File file = this.path.toFile();
return file.canRead();
} else {
return false;
}
}
@Override
public boolean isWritable() {
if (this.isExist()) {
File file = this.path.toFile();
return file.canWrite();
} else {
return false;
}
}
@Override
public FileManager getCurrentInstance() {
return this;
}
@Override
public FileManager getNewInstance() {
return this.newInstance(this.rootDir, this.rootDir, this.autoCreateParent, this.disableRootDirCheck);
}
@Override
public FileManager enableAutoCreateParent() {
this.autoCreateParent = true;
return this;
}
@Override
public FileManager disableRootDirCheck() {
this.disableRootDirCheck = true;
return this;
}
@Override
public FileManager setRootDir(Path rootDir) {
return this.newInstance(rootDir, this.path, this.autoCreateParent, this.disableRootDirCheck);
}
@Override
public FileManager setPath(Path path) {
Path resolvedPath;
if (this.disableRootDirCheck) {
resolvedPath = path;
} else {
if (path.startsWith(this.rootDir)) {
resolvedPath = path;
} else {
throw new IllegalArgumentException("path must be in rootDir");
}
}
logger.debug("setPath", "resolvedPath: " + resolvedPath);
return this.newInstance(this.rootDir, resolvedPath, this.autoCreateParent, this.disableRootDirCheck);
}
@Override
public FileManager resolve(String path) throws IOException{
Path resolvedPath;
try {
resolvedPath = resolveStringPath(path);
} catch (IOException e) {
logger.error("resolve", e.getMessage());
throw new IOException("Invalid path: " + path);
}
return this.setPath(resolvedPath);
}
// Internal
private void createFileInternal(Path path) throws IOException {
try {
if (this.autoCreateParent) {
if (!path.getParent().toFile().exists()) {
Files.createDirectories(path.getParent());
}
}
Files.createFile(path);
} catch (Exception e) {
logger.error("createFileInternal", e.getMessage());
throw new IOException("Failed to create file");
}
}
@Override
public FileManager createFile() throws IOException {
this.createFileInternal(this.path);
return this;
}
@Override
public FileManager createFile(String fileName) throws IOException { // pathが書き換わってしまうのは想像できない挙動かも?
this.createFileInternal(this.resolveStringPath(fileName));
return this;
}
@Override
public FileManager createFileIfNotExist() throws IOException {
if (!this.isExist()) {
this.createFile();
}
return this;
}
@Override
public FileManager createFileIfNotExist(String fileName) throws IOException {
if (!this.isExist(fileName)) {
this.createFile(fileName);
}
return this;
}
// Internal
private void createDirectoryInternal(Path path) throws IOException {
try {
if (this.autoCreateParent) {
if (!path.getParent().toFile().exists()) {
Files.createDirectories(path.getParent());
}
}
Files.createDirectory(path);
} catch (Exception e) {
logger.error("createDirectoryInternal", e.getMessage());
throw new IOException("Failed to create directory");
}
}
@Override
public FileManager createDirectory() throws IOException {
this.createDirectoryInternal(this.path);
return this;
}
@Override
public FileManager createDirectory(String directoryName) throws IOException {
this.createDirectoryInternal(this.resolveStringPath(directoryName));
return this;
}
@Override
public FileManager createDirectoryIfNotExist() throws IOException {
if (!this.isExist()) {
this.createDirectory();
}
return this;
}
@Override
public FileManager createDirectoryIfNotExist(String directoryName) throws IOException {
if (!this.isExist(directoryName)) {
this.createDirectory(directoryName);
}
return this;
}
// Internal
private void saveXmlInternal(Document document, Path path) throws IOException {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(path.toFile());
transformer.transform(source, result);
} catch (Exception e) {
logger.error("saveXmlInternal", e.getMessage());
e.printStackTrace();
throw new IOException("Failed to save xml");
}
}
private void saveBitmapInternal(Bitmap bitmap, Path path) throws IOException {
try {
logger.debug("saveBitmapInternal", "path: " + path);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(path));
} catch (Exception e) {
logger.error("saveBitmapInternal", e.getMessage());
throw new IOException("Failed to save bitmap");
}
}
@Override
public void saveXml(Document document, String fileName) throws IOException {
this.saveXmlInternal(document, this.resolveStringPath(fileName));
}
@Override
public void saveXml(Document document) throws IOException {
this.saveXmlInternal(document, this.path);
}
@Override
public void saveBitmap(Bitmap bitmap, String fileName) throws IOException {
this.saveBitmapInternal(bitmap, this.resolveStringPath(fileName));
}
@Override
public void saveBitmap(Bitmap bitmap) throws IOException {
this.saveBitmapInternal(bitmap, this.path);
}
// Internal
private Document loadXmlInternal(Path path) throws IOException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(Files.newInputStream(path));
} catch (Exception e) {
logger.error("loadXmlInternal", e.getMessage());
throw new IOException("Failed to load xml");
}
}
private Bitmap loadBitmapInternal(Path path) throws IOException {
try {
return BitmapFactory.decodeFile(path.toString());
} catch (Exception e) {
logger.error("loadBitmapInternal", e.getMessage());
throw new IOException("Failed to load bitmap");
}
}
@Override
public Document loadXml(String fileName) throws IOException {
return this.loadXmlInternal(this.resolveStringPath(fileName));
}
@Override
public Document loadXml() throws IOException {
return this.loadXmlInternal(this.path);
}
@Override
public Bitmap loadBitmap(String fileName) throws IOException {
return this.loadBitmapInternal(this.resolveStringPath(fileName));
}
@Override
public Bitmap loadBitmap() throws IOException {
return this.loadBitmapInternal(this.path);
}
}
Whitespace-only changes.
@@ -1,20 +0,0 @@
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.
+1 -2
View File
@@ -37,6 +37,5 @@ dependencies {
implementation libs.com.google.dagger.hilt.android
annotationProcessor libs.com.google.dagger.hilt.compiler
// model
implementation project(':model')
//
}
@@ -1,7 +1,5 @@
package one.nem.lacerta.utils;
import one.nem.lacerta.utils.model.KeyValueLog;
public interface LacertaLogger {
void info(String tag, String message);
@@ -11,7 +9,4 @@ 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);
}
@@ -1,13 +0,0 @@
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,8 +5,6 @@ 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
@@ -42,30 +40,4 @@ 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();
}
}
@@ -1,98 +0,0 @@
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);
}
}
@@ -1,31 +0,0 @@
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;
}
}
@@ -1,17 +0,0 @@
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);
}