From 021dde66ebb854f54de7b461c8e6783b43c5198f Mon Sep 17 00:00:00 2001 From: Deumiankio <39210184+Deumiankio@users.noreply.github.com> Date: Mon, 29 Apr 2019 19:32:49 +0200 Subject: [PATCH] Add color filter blend modes (#2013) * Add color filter blend modes * Only show modes supported by currently used API level. * Fix arrays.xml for API level <=27. --- .../data/preference/PreferenceKeys.kt | 2 ++ .../data/preference/PreferencesHelper.kt | 2 ++ .../tachiyomi/ui/reader/ReaderActivity.kt | 5 ++- .../ui/reader/ReaderColorFilterSheet.kt | 11 +++++- .../ui/reader/ReaderColorFilterView.kt | 32 +++++++++++++++++ .../layout-land/reader_color_filter_sheet.xml | 2 +- app/src/main/res/layout/reader_activity.xml | 2 +- .../main/res/layout/reader_color_filter.xml | 36 ++++++++++++++++++- .../res/layout/reader_color_filter_sheet.xml | 2 +- app/src/main/res/values-v28/arrays.xml | 15 ++++++++ app/src/main/res/values/arrays.xml | 6 ++++ app/src/main/res/values/strings.xml | 7 ++++ 12 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt create mode 100644 app/src/main/res/values-v28/arrays.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 1b2e6bb322..eb5f9d4a1e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -29,6 +29,8 @@ object PreferenceKeys { const val colorFilterValue = "color_filter_value" + const val colorFilterMode = "color_filter_mode" + const val defaultViewer = "pref_default_viewer_key" const val imageScaleType = "pref_image_scale_type_key" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 58ad2b0aff..6545b4a39e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -57,6 +57,8 @@ class PreferencesHelper(val context: Context) { fun colorFilterValue() = rxPrefs.getInteger(Keys.colorFilterValue, 0) + fun colorFilterMode() = rxPrefs.getInteger(Keys.colorFilterMode, 0) + fun defaultViewer() = prefs.getInt(Keys.defaultViewer, 1) fun imageScaleType() = rxPrefs.getInteger(Keys.imageScaleType, 1) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index c3b8aefd80..ee324e8966 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -574,6 +574,9 @@ class ReaderActivity : BaseRxActivity() { subscriptions += preferences.colorFilter().asObservable() .subscribe { setColorFilter(it) } + + subscriptions += preferences.colorFilterMode().asObservable() + .subscribe { setColorFilter(preferences.colorFilter().getOrDefault()) } } /** @@ -722,7 +725,7 @@ class ReaderActivity : BaseRxActivity() { */ private fun setColorFilterValue(value: Int) { color_overlay.visibility = View.VISIBLE - color_overlay.setBackgroundColor(value) + color_overlay.setFilterColor(value, preferences.colorFilterMode().getOrDefault()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt index 263bd5de2c..a0579cdccf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.plusAssign +import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import kotlinx.android.synthetic.main.reader_color_filter.* import kotlinx.android.synthetic.main.reader_color_filter_sheet.* @@ -54,6 +55,9 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ subscriptions += preferences.colorFilter().asObservable() .subscribe { setColorFilter(it, view) } + subscriptions += preferences.colorFilterMode().asObservable() + .subscribe { setColorFilter(preferences.colorFilter().getOrDefault(), view) } + subscriptions += preferences.customBrightness().asObservable() .subscribe { setCustomBrightness(it, view) } @@ -84,6 +88,11 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ preferences.customBrightness().set(isChecked) } + color_filter_mode.onItemSelectedListener = IgnoreFirstSpinnerListener { position -> + preferences.colorFilterMode().set(position) + } + color_filter_mode.setSelection(preferences.colorFilterMode().getOrDefault(), false) + seekbar_color_filter_alpha.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { if (fromUser) { @@ -248,7 +257,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog(activ */ private fun setColorFilterValue(@ColorInt color: Int, view: View) = with(view) { color_overlay.visibility = View.VISIBLE - color_overlay.setBackgroundColor(color) + color_overlay.setFilterColor(color, preferences.colorFilterMode().getOrDefault()) setValues(color, view) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt new file mode 100644 index 0000000000..01d91a3b4a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterView.kt @@ -0,0 +1,32 @@ +package eu.kanade.tachiyomi.ui.reader + +import android.content.Context +import android.graphics.* +import android.util.AttributeSet +import android.view.View + +class ReaderColorFilterView( + context: Context, + attrs: AttributeSet? = null +) : View(context, attrs) { + + private val colorFilterPaint: Paint = Paint() + + fun setFilterColor(color: Int, filterMode: Int) { + colorFilterPaint.setColor(color) + colorFilterPaint.xfermode = PorterDuffXfermode(when (filterMode) { + 1 -> PorterDuff.Mode.MULTIPLY + 2 -> PorterDuff.Mode.SCREEN + 3 -> PorterDuff.Mode.OVERLAY + 4 -> PorterDuff.Mode.LIGHTEN + 5 -> PorterDuff.Mode.DARKEN + else -> PorterDuff.Mode.SRC_OVER + }) + invalidate() + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + canvas.drawPaint(colorFilterPaint) + } +} diff --git a/app/src/main/res/layout-land/reader_color_filter_sheet.xml b/app/src/main/res/layout-land/reader_color_filter_sheet.xml index ba4d45e406..761c279928 100644 --- a/app/src/main/res/layout-land/reader_color_filter_sheet.xml +++ b/app/src/main/res/layout-land/reader_color_filter_sheet.xml @@ -29,7 +29,7 @@ android:layout_height="wrap_content" android:visibility="gone" /> - - + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/color_filter_mode_text"/> @@ -202,4 +229,11 @@ app:layout_constraintBottom_toBottomOf="@id/brightness_seekbar" app:layout_constraintRight_toRightOf="parent"/> + + diff --git a/app/src/main/res/layout/reader_color_filter_sheet.xml b/app/src/main/res/layout/reader_color_filter_sheet.xml index 618a8a77f0..3155bc15cb 100644 --- a/app/src/main/res/layout/reader_color_filter_sheet.xml +++ b/app/src/main/res/layout/reader_color_filter_sheet.xml @@ -21,7 +21,7 @@ android:layout_height="match_parent" android:visibility="gone" /> - + + + + @string/filter_mode_default + @string/filter_mode_multiply + @string/filter_mode_screen + + + @string/filter_mode_overlay + @string/filter_mode_lighten + @string/filter_mode_darken + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 9018a31f7c..76bd9430ce 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -102,4 +102,10 @@ 2 + + @string/filter_mode_default + @string/filter_mode_multiply + @string/filter_mode_screen + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2388bdc1f8..14ab046b10 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -178,6 +178,13 @@ Crop borders Use custom brightness Use custom color filter + Color filter blend mode + Default + Overlay + Multiply + Screen + Dodge / Lighten + Burn / Darken Keep screen on Skip chapters marked read Navigation