mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2026-11-07 19:47:36 +00:00
Compare commits
110
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
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 | ||
|
|
59e32fe696 | ||
|
|
15beb0af57 | ||
|
|
14e7fbd127 | ||
|
|
144ff7dfd2 | ||
|
|
d030847992 | ||
|
|
eb1ad1f4af | ||
|
|
fc048c9bd6 |
No files matched your search
+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
|
||||
@@ -49,6 +51,7 @@ public class DebugMenuTopFragment extends Fragment {
|
||||
debugMenuListItems.add(new DebugMenuListItem("Meta Data", "View meta data", R.id.action_debugMenuTopFragment_to_debugMenuMetaDataFragment, true));
|
||||
debugMenuListItems.add(new DebugMenuListItem("Document Tester", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuDocumentTesterTopFragment, true));
|
||||
debugMenuListItems.add(new DebugMenuListItem("Scanner", "placeholder", R.id.action_debugMenuTopFragment_to_scannerDataManagerStubFragment, true));
|
||||
debugMenuListItems.add(new DebugMenuListItem("File Manager", "placeholder", R.id.action_debugMenuTopFragment_to_debugMenuFileManagerTesterFragment, true));
|
||||
|
||||
DebugMenuListItemAdapter adapter = new DebugMenuListItemAdapter(debugMenuListItems);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
@@ -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>
|
||||
@@ -19,6 +19,9 @@
|
||||
<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"
|
||||
@@ -51,4 +54,9 @@
|
||||
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>
|
||||
@@ -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,21 @@
|
||||
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();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package one.nem.lacerta.processor;
|
||||
|
||||
import one.nem.lacerta.processor.model.XmlMetaModel;
|
||||
import one.nem.lacerta.processor.model.XmlMetaPageModel;
|
||||
|
||||
public interface XmlMetaProcessor {
|
||||
|
||||
void saveXmlMeta(XmlMetaModel xmlMetaModel);
|
||||
XmlMetaModel loadXmlMeta();
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package one.nem.lacerta.processor.factory;
|
||||
|
||||
public class DocumentProcessorFactory {
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package one.nem.lacerta.processor.impl;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import one.nem.lacerta.processor.DocumentProcessor;
|
||||
|
||||
import one.nem.lacerta.model.document.DocumentDetail;
|
||||
import one.nem.lacerta.model.document.DocumentMeta;
|
||||
|
||||
import one.nem.lacerta.source.file.FileManager;
|
||||
import one.nem.lacerta.source.file.factory.FileManagerFactory;
|
||||
|
||||
public class DocumentProcessorImpl implements DocumentProcessor{
|
||||
|
||||
// Magic Numbers
|
||||
private static final String DEFAULT_SAVE_DIR = "raw";
|
||||
|
||||
private DocumentDetail documentDetail;
|
||||
|
||||
// Injection
|
||||
@Inject
|
||||
FileManagerFactory fileManagerFactory;
|
||||
|
||||
// Internal utils
|
||||
|
||||
@Override
|
||||
public void addNewPageToLast(Bitmap bitmap) {
|
||||
Path path = documentDetail.getPath().getFullPath();
|
||||
String fileName = String.format(UUID.randomUUID().toString() + ".png"); // TODO-rca: 対応表をもたせる
|
||||
FileManager fileManager = fileManagerFactory.create(path);
|
||||
if(fileManager.getList().contains(path.resolve(DEFAULT_SAVE_DIR))) {
|
||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
||||
} else {
|
||||
fileManager.createDir(DEFAULT_SAVE_DIR);
|
||||
fileManager.changeDir(DEFAULT_SAVE_DIR);
|
||||
}
|
||||
fileManager.saveBitmapAtCurrent(bitmap, fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPagesToLast(Bitmap[] bitmaps) {
|
||||
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package one.nem.lacerta.processor.impl;
|
||||
|
||||
import one.nem.lacerta.processor.XmlMetaProcessor;
|
||||
import one.nem.lacerta.processor.model.XmlMetaModel;
|
||||
|
||||
public class XmlMetaProcessorImpl implements XmlMetaProcessor{
|
||||
|
||||
@Override
|
||||
public void saveXmlMeta(XmlMetaModel xmlMetaModel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlMetaModel loadXmlMeta() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,105 @@
|
||||
package one.nem.lacerta.processor.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
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.processor.model;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package one.nem.lacerta.processor.module;
|
||||
|
||||
public class DocumentProcessorModule {
|
||||
}
|
||||
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,27 @@
|
||||
package one.nem.lacerta.source.file;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public interface FileManager {
|
||||
|
||||
Path getRootDir();
|
||||
void changeDir(String dirName); //cd
|
||||
void backDir(); //cd ..
|
||||
void backRootDir(); //cd /
|
||||
List<Path> getList();
|
||||
void createDir(String dirName);
|
||||
void removeDir(String dirName);
|
||||
|
||||
void saveBitmapAtCurrent(Bitmap bitmap, String fileName);
|
||||
Bitmap loadBitmap(Path path);
|
||||
void removeBitmap(Path path);
|
||||
|
||||
// void saveFileAtCurrent(File file);
|
||||
// File getFile(Path path);
|
||||
// void removeFile(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,130 @@
|
||||
package one.nem.lacerta.source.file.impl;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import java.io.File;
|
||||
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.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedInject;
|
||||
import one.nem.lacerta.source.file.FileManager;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
public FileManagerImpl(@Assisted Path rootDir) {
|
||||
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 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) {
|
||||
currentDir.resolve(dirName).toFile().mkdir(); // TODO-rca: エラーハンドリング
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDir(String dirName) {
|
||||
currentDir.resolve(dirName).toFile().delete(); // TODO-rca: エラーハンドリング
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBitmapAtCurrent(Bitmap bitmap, String fileName) { // TODO-rca: ファイル形式を変更できるようにする?
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void saveFileAtCurrent(File file) {
|
||||
// try {
|
||||
// Files.copy(file.toPath(), currentDir.resolve(file.getName()));
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public File getFile(Path path) {
|
||||
// // ファイルを取得する
|
||||
// return path.toFile();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void removeFile(Path path) {
|
||||
// // ファイルを削除する
|
||||
// if (path.toFile().exists()) {
|
||||
// path.toFile().delete(); // Resultを返す?
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
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.
Reference in new issue
Block a user