Merge pull request #97 from lacerta-doc/scan_setting

Scan setting
This commit is contained in:
ろむねこ 2024-01-23 03:05:44 +09:00 committed by GitHub
commit 9d229a2857
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 134 additions and 22 deletions

View File

@ -45,4 +45,8 @@ dependencies {
// shared
implementation project(':shared:ui')
// https://mvnrepository.com/artifact/androidx.preference/preference
implementation 'androidx.preference:preference:1.2.1'
}

View File

@ -2,8 +2,12 @@ package one.nem.lacerta.setting;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceFragmentCompat;
import android.preference.PreferenceFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,12 +17,17 @@ import android.view.ViewGroup;
* Use the {@link SettingScanPageFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class SettingScanPageFragment extends Fragment {
public class SettingScanPageFragment extends PreferenceFragmentCompat {
public SettingScanPageFragment() {
// Required empty public constructor
}
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
addPreferencesFromResource(R.xml.scan_preferences);
}
public static SettingScanPageFragment newInstance() {
SettingScanPageFragment fragment = new SettingScanPageFragment();
Bundle args = new Bundle();
@ -26,16 +35,4 @@ public class SettingScanPageFragment extends Fragment {
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_setting_scan_page, container, false);
}
}

View File

@ -1,14 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SettingScanPageFragment">
android:background="@color/colorSurface">
<!-- TODO: Update blank fragment layout -->
<TextView
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
app:contentScrim="@color/colorSecondaryContainer"
android:background="@color/colorSurface"
android:layout_width="match_parent"
android:layout_height="160dp"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:collapsedTitleGravity="start|center_vertical"
app:expandedTitleGravity="start|bottom"
app:expandedTitleMarginBottom="16dp"
app:expandedTitleMarginStart="16dp"
app:expandedTitleTextAppearance="@style/TextAppearance.MaterialComponents.Headline4"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="@string/setting_top_scan_title" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@+id/setting_scan_page_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</FrameLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="png_quality_array">
<item name="5">5</item>
<item name="6">6</item>
<item name="7">7</item>
<item name="8">8</item>
<item name="9">9</item>
</array>
</resources>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="png_quality_default">70</integer>
<integer name="png_quality_min">5</integer>
<integer name="png_quality_max">100</integer>
</resources>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="@string/setting_scan_quality_title">
<SeekBarPreference
android:defaultValue="@integer/png_quality_default"
android:key="png_quality"
android:max="@integer/png_quality_max"
android:min="@integer/png_quality_min"
android:summary="@string/setting_scan_quality_png_quality_description"
android:title="@string/setting_scan_quality_png_quality_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/setting_scan_default_title">
<EditTextPreference
android:defaultValue="Untitled"
android:key="new_doc_default_title"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/setting_scan_default_document_name" />
<EditTextPreference
android:defaultValue="NewFolder"
android:key="new_dir_default_title"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/setting_scan_default_folder_name" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -19,6 +19,14 @@
<string name="setting_top_scan_title">スキャン</string>
<string name="setting_top_scan_description">画質, 保存先</string>
<string name="setting_scan_quality_title">画質</string>
<string name="setting_scan_quality_png_quality_title">PNG画質</string>
<string name="setting_scan_quality_png_quality_description">PNG画質を設定します. 画質が高いほどファイルサイズが大きくなります.</string>
<string name="setting_scan_default_title">保存先</string>
<string name="setting_scan_default_document_name">新規ドキュメントのデフォルトタイトル</string>
<string name="setting_scan_default_folder_name">新規フォルダのデフォルト名</string>
<string name="setting_top_display_title">表示</string>
<string name="setting_top_display_description">テーマ, フォントサイズ</string>

View File

@ -22,6 +22,7 @@ import dagger.assisted.AssistedInject;
import one.nem.lacerta.source.file.FileManager;
import one.nem.lacerta.utils.LacertaLogger;
import one.nem.lacerta.utils.Store;
public class FileManagerImpl implements FileManager {
@ -303,7 +304,16 @@ public class FileManagerImpl implements FileManager {
private void saveBitmapInternal(Bitmap bitmap, Path path) throws IOException {
try {
logger.debug("saveBitmapInternal", "path: " + path);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, Files.newOutputStream(path));
// Bitmapの長辺を1024pxにする
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float scale = 1.0f;
if (width > height) {
scale = Store.Scan.MAX_RESOLUTION_LONG / width;
} else {
scale = Store.Scan.MAX_RESOLUTION_LONG / height;
}
bitmap.compress(new Store.Scan().COMPRESS_FORMAT, Store.Scan.QUALITY, Files.newOutputStream(path));
} catch (Exception e) {
logger.error("saveBitmapInternal", e.getMessage());
throw new IOException("Failed to save bitmap");

View File

@ -8,7 +8,7 @@ public class FeatureSwitch {
public static class FeatureMaster {
public static boolean enableSearch = false;
public static boolean enableDebugMenu = false;
public static boolean enableDebugMenu = true;
}
public static class Vcs {

View File

@ -0,0 +1,11 @@
package one.nem.lacerta.utils;
import android.graphics.Bitmap;
public class Store {
public static class Scan {
public Bitmap.CompressFormat COMPRESS_FORMAT = Bitmap.CompressFormat.JPEG;
public static final int QUALITY = 60;
public static final float MAX_RESOLUTION_LONG = 2048;
}
}