From bfc237c440e2f0354ad1ca1d78ace3a18290df37 Mon Sep 17 00:00:00 2001 From: ZYFDroid Date: Sat, 5 Oct 2024 17:05:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=9C=E9=97=B4=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deploymentTargetDropDown.xml | 15 +- .idea/misc.xml | 9 +- app/build.gradle | 4 +- .../com/zyfdroid/epub/ReadingActivity.java | 130 ++++++++++++++---- .../com/zyfdroid/epub/SettingActivity.java | 30 ++-- .../java/com/zyfdroid/epub/utils/SpUtils.java | 9 +- app/src/main/res/layout/activity_setting.xml | 39 ++++-- app/src/main/res/values-zh/strings.xml | 4 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/values/styles.xml | 2 +- 10 files changed, 189 insertions(+), 57 deletions(-) diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0c0c338..e2738a6 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -3,7 +3,20 @@ - + + + + + + + + + + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml index 9748f31..5cf50a3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + - + diff --git a/app/build.gradle b/app/build.gradle index 9594cc4..fd1ba27 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,8 @@ android { minSdkVersion 21 //noinspection ExpiredTargetSdkVersion targetSdkVersion 28 - versionCode 1080002 - versionName "1.8.0.2" + versionCode 1080003 + versionName "1.8.0.3" signingConfig signingConfigs.debug } diff --git a/app/src/main/java/com/zyfdroid/epub/ReadingActivity.java b/app/src/main/java/com/zyfdroid/epub/ReadingActivity.java index 7df449a..6fa8928 100644 --- a/app/src/main/java/com/zyfdroid/epub/ReadingActivity.java +++ b/app/src/main/java/com/zyfdroid/epub/ReadingActivity.java @@ -1,12 +1,15 @@ package com.zyfdroid.epub; import android.annotation.SuppressLint; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.AssetManager; import android.content.res.ColorStateList; +import android.content.res.Configuration; import android.graphics.Color; import android.net.Uri; +import android.os.Build; import android.os.Handler; import android.view.*; import androidx.annotation.NonNull; @@ -115,6 +118,39 @@ public boolean onMenuOpened(int featureId, Menu menu) { return super.onMenuOpened(featureId, menu); } + @Override + protected void attachBaseContext(Context newBase) { + Configuration config = newBase.getResources().getConfiguration(); + int nightMode = SpUtils.getInstance(newBase).getNightMode(); + + if(nightMode == 0){ + super.attachBaseContext(newBase); + return; + } + + if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O){ + + int oldInt = config.uiMode; + + // day mode + if(nightMode == 1){ + oldInt = oldInt & (~Configuration.UI_MODE_NIGHT_YES); + oldInt = oldInt & (~Configuration.UI_MODE_NIGHT_UNDEFINED); + oldInt = oldInt | Configuration.UI_MODE_NIGHT_NO; + } + // night mode + if(nightMode == 2){ + oldInt = oldInt & (~Configuration.UI_MODE_NIGHT_NO); + oldInt = oldInt & (~Configuration.UI_MODE_NIGHT_UNDEFINED); + oldInt = oldInt | Configuration.UI_MODE_NIGHT_YES; + } + config.uiMode = oldInt; + } + + Context context = newBase.createConfigurationContext(config); + super.attachBaseContext(context); + } + float readActionBarSize = 0; View readActionBar = null; @Override @@ -162,9 +198,7 @@ public void onClick(View v) { bookView = findViewById(R.id.webEpub); if(getString(R.string.isnightmode).contains("yes")){ - if(SpUtils.getInstance(ReadingActivity.this).getAllowNightMode()){ - bookView.setBackgroundColor(0); - } + bookView.setBackgroundColor(0); } bookmarkAdapter = new BookmarkAdapter(); @@ -330,6 +364,46 @@ public boolean onCreateOptionsMenu(Menu menu) { + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + + if(keyCode==KeyEvent.KEYCODE_VOLUME_UP || keyCode==KeyEvent.KEYCODE_VOLUME_DOWN) { + + if (event.getRepeatCount() > 0) { + return true; + } + if (isDrawerOpen()) { + if (SpUtils.getInstance(this).getEinkMode()) { + if (displayingEinkPage != null) { + if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { + displayingEinkPage.pageUp(); + return true; + } + + if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { + displayingEinkPage.pageDown(); + return true; + } + } + } + return super.onKeyDown(keyCode, event); + } + + if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { + evaluteJavascriptFunction("prev"); + return true; + } + + if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { + evaluteJavascriptFunction("next"); + return true; + } + } + return super.onKeyDown(keyCode, event); + } + + + @Override public boolean dispatchKeyEvent(KeyEvent event) { if(ViewUtils.sourceIsGamepad(event.getSource())){ @@ -785,9 +859,9 @@ public void run(String arg) { @Override public void run(String arg) { if(getString(R.string.isnightmode).contains("yes")){ - if(SpUtils.getInstance(ReadingActivity.this).getAllowNightMode()){ + evaluteJavascriptFunction("setNight()"); - } + } evaluteJavascriptFunction("loadBookAtUrl", contentOpfPath, DBUtils.autoLoad(ReadingActivity.this,readingBook.getUUID()).getEpubcft(),SpUtils.getInstance(ReadingActivity.this).getTextSize()); } @@ -1101,32 +1175,34 @@ protected void onPause() { } bookView.onPause(); } -} -class TocEntry implements Cloneable { - public String id; - public String href; - public String label; - public TocEntry[] subitems; + public static class TocEntry implements Cloneable { + public String id; + public String href; + public String label; + public TocEntry[] subitems; - @Override - protected Object clone() { - TocEntry obj = new TocEntry(); - obj.href = href; - obj.id = id; - obj.label = label; - obj.subitems = null; - return obj; + @Override + protected Object clone() { + TocEntry obj = new TocEntry(); + obj.href = href; + obj.id = id; + obj.label = label; + obj.subitems = null; + return obj; + } + } + + public static class BookSpine { + public String idref; + public int index; + public String href; } -} -class BookSpine { - public String idref; - public int index; - public String href; + public interface Action { + public void run(T arg); + } } -interface Action { - public void run(T arg); -} \ No newline at end of file + diff --git a/app/src/main/java/com/zyfdroid/epub/SettingActivity.java b/app/src/main/java/com/zyfdroid/epub/SettingActivity.java index 09f9c2b..f5b45a0 100644 --- a/app/src/main/java/com/zyfdroid/epub/SettingActivity.java +++ b/app/src/main/java/com/zyfdroid/epub/SettingActivity.java @@ -5,13 +5,11 @@ import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.widget.*; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.Environment; import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.Toast; import com.zyfdroid.epub.utils.CinematicProgressDialog; import com.zyfdroid.epub.utils.DBUtils; @@ -38,14 +36,29 @@ public class SettingActivity extends AppCompatActivity { CheckBox chkEink; CheckBox chkFullscreen; CheckBox chkShowStatusBar; + + RadioGroup readingThemes; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_setting); chkOpenExternal = findViewById(R.id.chkExternalOpen); chkOpenExternal.setChecked(SpUtils.getInstance(this).shouldOpenWithExternalReader()); - chkAllowNight = findViewById(R.id.chkAllowNight); - chkAllowNight.setChecked(SpUtils.getInstance(this).getAllowNightMode()); + readingThemes = findViewById(R.id.radNightModes); + + readingThemes.check(new int[]{ + R.id.chkReadingNightFollowSystem, + R.id.chkReadingNightAlwaysLight, + R.id.chkReadingNightAlwaysDark} + [SpUtils.getInstance(this).getNightMode()]); + readingThemes.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + if(checkedId == R.id.chkReadingNightFollowSystem){SpUtils.getInstance(SettingActivity.this).setNightMode(0);} + if(checkedId == R.id.chkReadingNightAlwaysLight){SpUtils.getInstance(SettingActivity.this).setNightMode(1);} + if(checkedId == R.id.chkReadingNightAlwaysDark){SpUtils.getInstance(SettingActivity.this).setNightMode(2);} + } + }); chkEink = findViewById(R.id.chkEink); chkEink.setChecked(SpUtils.getInstance(this).getEinkMode()); chkFullscreen = findViewById(R.id.chkFullscreen); @@ -60,12 +73,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SpUtils.getInstance(SettingActivity.this).setOpenWithExternalReader(isChecked); } }); - chkAllowNight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - SpUtils.getInstance(SettingActivity.this).setAllowNightMode(isChecked); - } - }); + chkEink.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { diff --git a/app/src/main/java/com/zyfdroid/epub/utils/SpUtils.java b/app/src/main/java/com/zyfdroid/epub/utils/SpUtils.java index d07cef6..b110a68 100644 --- a/app/src/main/java/com/zyfdroid/epub/utils/SpUtils.java +++ b/app/src/main/java/com/zyfdroid/epub/utils/SpUtils.java @@ -30,11 +30,12 @@ public int getTextSize(){ public boolean getEinkMode(){return sp.getBoolean("eink",false);} public void setEinkMode(boolean b){sp.edit().putBoolean("eink",b).apply();} - public boolean getAllowNightMode(){ - return sp.getBoolean("nightmode",true); + + public int getNightMode(){ + return sp.getInt("nightmode2",0); } - public void setAllowNightMode(boolean value){ - sp.edit().putBoolean("nightmode",value).apply(); + public void setNightMode(int value){ + sp.edit().putInt("nightmode2",value).apply(); } public void setOpenWithExternalReader(boolean b){ sp.edit().putBoolean("openWithExternalReader",b).apply(); diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml index 86964fb..0521254 100644 --- a/app/src/main/res/layout/activity_setting.xml +++ b/app/src/main/res/layout/activity_setting.xml @@ -17,20 +17,43 @@ android:gravity="center_vertical" android:id="@+id/chkExternalOpen" /> - + + + + + + + + 要放到桌面的那个位置 已添加到桌面 已从桌面移除 + 阅读页面主题 (Android 8+) + 跟随系统 + 亮色主题(适配电子书模式) + 暗色主题(在OLED/MiniLED上更省电) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7a527f0..79a6583 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,4 +79,8 @@ Which position will the book be put: The book has been put on the desktop. The book has been removed from desktop. + Reading Theme: (Android 8+) + Follow system + Light Theme (for E-Ink devices) + Dark Theme (Save power on OLED device) diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index a658558..24afbc3 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -12,7 +12,7 @@