Add an overlay on top of the reader to simulate a lower brightness. Closes #362
This commit is contained in:
parent
a32e0e4ec5
commit
f15df40a54
@ -163,6 +163,7 @@ dependencies {
|
|||||||
compile 'com.afollestad.material-dialogs:core:0.8.6.1'
|
compile 'com.afollestad.material-dialogs:core:0.8.6.1'
|
||||||
compile 'net.xpece.android:support-preference:0.8.1'
|
compile 'net.xpece.android:support-preference:0.8.1'
|
||||||
compile 'me.zhanghai.android.systemuihelper:library:1.0.0'
|
compile 'me.zhanghai.android.systemuihelper:library:1.0.0'
|
||||||
|
compile 'org.adw.library:discrete-seekbar:1.0.1'
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
|
@ -48,7 +48,7 @@ class PreferencesHelper(context: Context) {
|
|||||||
|
|
||||||
fun customBrightness() = rxPrefs.getBoolean(keys.customBrightness, false)
|
fun customBrightness() = rxPrefs.getBoolean(keys.customBrightness, false)
|
||||||
|
|
||||||
fun customBrightnessValue() = rxPrefs.getFloat(keys.customBrightnessValue, 0f)
|
fun customBrightnessValue() = rxPrefs.getInteger(keys.customBrightnessValue, 0)
|
||||||
|
|
||||||
fun defaultViewer() = prefs.getInt(keys.defaultViewer, 1)
|
fun defaultViewer() = prefs.getInt(keys.defaultViewer, 1)
|
||||||
|
|
||||||
|
@ -415,20 +415,39 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||||||
private fun setCustomBrightness(enabled: Boolean) {
|
private fun setCustomBrightness(enabled: Boolean) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
customBrightnessSubscription = preferences.customBrightnessValue().asObservable()
|
customBrightnessSubscription = preferences.customBrightnessValue().asObservable()
|
||||||
.map { Math.max(0.01f, it) }
|
|
||||||
.subscribe { setCustomBrightnessValue(it) }
|
.subscribe { setCustomBrightnessValue(it) }
|
||||||
|
|
||||||
subscriptions.add(customBrightnessSubscription)
|
subscriptions.add(customBrightnessSubscription)
|
||||||
} else {
|
} else {
|
||||||
if (customBrightnessSubscription != null) {
|
customBrightnessSubscription?.let { subscriptions.remove(it) }
|
||||||
subscriptions.remove(customBrightnessSubscription)
|
setCustomBrightnessValue(0)
|
||||||
}
|
|
||||||
setCustomBrightnessValue(WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setCustomBrightnessValue(value: Float) {
|
/**
|
||||||
window.attributes = window.attributes.apply { screenBrightness = value }
|
* Sets the brightness of the screen. Range is [-50, 100].
|
||||||
|
* From -50 to -1 a semi-transparent black view is shown at the top with the minimum brightness.
|
||||||
|
* From 1 to 100 it sets that value as brightness.
|
||||||
|
* 0 sets system brightness and hides the overlay.
|
||||||
|
*/
|
||||||
|
private fun setCustomBrightnessValue(value: Int) {
|
||||||
|
// Calculate and set reader brightness.
|
||||||
|
val readerBrightness = if (value > 0) {
|
||||||
|
value / 100f
|
||||||
|
} else if (value < 0) {
|
||||||
|
0.01f
|
||||||
|
} else WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
|
||||||
|
|
||||||
|
window.attributes = window.attributes.apply { screenBrightness = readerBrightness }
|
||||||
|
|
||||||
|
// Set black overlay visibility.
|
||||||
|
if (value < 0) {
|
||||||
|
brightness_overlay.visibility = View.VISIBLE
|
||||||
|
val alpha = (Math.abs(value) * 2.56).toInt()
|
||||||
|
brightness_overlay.setBackgroundColor(Color.argb(alpha, 0, 0, 0))
|
||||||
|
} else {
|
||||||
|
brightness_overlay.visibility = View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun applyTheme(theme: Int) {
|
private fun applyTheme(theme: Int) {
|
||||||
|
@ -4,15 +4,14 @@ import android.app.Dialog
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v4.app.DialogFragment
|
import android.support.v4.app.DialogFragment
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.SeekBar
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.util.plusAssign
|
import eu.kanade.tachiyomi.util.plusAssign
|
||||||
import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
|
import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener
|
||||||
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
|
||||||
import kotlinx.android.synthetic.main.dialog_reader_settings.view.*
|
import kotlinx.android.synthetic.main.dialog_reader_settings.view.*
|
||||||
|
import org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
import rx.subscriptions.CompositeSubscription
|
import rx.subscriptions.CompositeSubscription
|
||||||
@ -108,17 +107,18 @@ class ReaderSettingsDialog : DialogFragment() {
|
|||||||
preferences.customBrightness().set(isChecked)
|
preferences.customBrightness().set(isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
brightness_seekbar.max = 100
|
brightness_seekbar.progress = preferences.customBrightnessValue().getOrDefault()
|
||||||
brightness_seekbar.progress = Math.round(
|
brightness_seekbar.setOnProgressChangeListener(object : DiscreteSeekBar.OnProgressChangeListener {
|
||||||
preferences.customBrightnessValue().getOrDefault() * brightness_seekbar.max)
|
override fun onProgressChanged(seekBar: DiscreteSeekBar, value: Int, fromUser: Boolean) {
|
||||||
brightness_seekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() {
|
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
|
||||||
if (fromUser) {
|
if (fromUser) {
|
||||||
preferences.customBrightnessValue().set(progress.toFloat() / seekBar.max)
|
preferences.customBrightnessValue().set(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
override fun onStartTrackingTouch(seekBar: DiscreteSeekBar) {}
|
||||||
|
|
||||||
|
override fun onStopTrackingTouch(seekBar: DiscreteSeekBar) {}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
@ -99,4 +99,10 @@
|
|||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/brightness_overlay"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@ -188,10 +189,15 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/pref_custom_brightness"/>
|
android:text="@string/pref_custom_brightness"/>
|
||||||
|
|
||||||
<SeekBar
|
<org.adw.library.widgets.discreteseekbar.DiscreteSeekBar
|
||||||
android:id="@+id/brightness_seekbar"
|
android:id="@+id/brightness_seekbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/TextAppearance.Regular.Body1.Light"/>
|
app:dsb_min="-50"
|
||||||
|
app:dsb_max="100"
|
||||||
|
app:dsb_indicatorFormatter="%d%%"
|
||||||
|
app:dsb_indicatorTextAppearance="@style/TextAppearance.Regular"
|
||||||
|
app:dsb_indicatorColor="?colorAccent"
|
||||||
|
app:dsb_progressColor="?colorAccent" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -27,7 +27,7 @@
|
|||||||
<string name="pref_show_page_number_key">pref_show_page_number_key</string>
|
<string name="pref_show_page_number_key">pref_show_page_number_key</string>
|
||||||
<string name="pref_keep_screen_on_key">pref_keep_screen_on_key</string>
|
<string name="pref_keep_screen_on_key">pref_keep_screen_on_key</string>
|
||||||
<string name="pref_custom_brightness_key">pref_custom_brightness_key</string>
|
<string name="pref_custom_brightness_key">pref_custom_brightness_key</string>
|
||||||
<string name="pref_custom_brightness_value_key">pref_custom_brightness_value_key</string>
|
<string name="pref_custom_brightness_value_key">custom_brightness_value</string>
|
||||||
<string name="pref_reader_theme_key">pref_reader_theme_key</string>
|
<string name="pref_reader_theme_key">pref_reader_theme_key</string>
|
||||||
<string name="pref_image_decoder_key">pref_image_decoder_key</string>
|
<string name="pref_image_decoder_key">pref_image_decoder_key</string>
|
||||||
<string name="pref_read_with_volume_keys_key">reader_volume_keys</string>
|
<string name="pref_read_with_volume_keys_key">reader_volume_keys</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user