From 711c714686212f3f6a80106ed7cf2b8c3e09991c Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 8 Feb 2018 18:07:52 +0100 Subject: [PATCH] catch exceptions thrown at getting device brightness --- .../gallery/helpers/MediaSideScroll.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt index 652001ec1..8b89d7caf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaSideScroll.kt @@ -69,8 +69,9 @@ class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val c mLastTouchY = event.y mTouchDownTime = System.currentTimeMillis() mSlideInfoText = "${activity.getString(R.string.brightness)}:\n" - if (mTouchDownBrightness == -1) + if (mTouchDownBrightness == -1) { mTouchDownBrightness = getCurrentBrightness() + } } MotionEvent.ACTION_MOVE -> { val diffX = mTouchDownX - event.x @@ -102,7 +103,13 @@ class MediaSideScroll(val activity: Activity, val slideInfoView: TextView, val c private fun getCurrentVolume() = activity.audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) - private fun getCurrentBrightness() = Settings.System.getInt(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS) + private fun getCurrentBrightness(): Int { + return try { + Settings.System.getInt(activity.contentResolver, Settings.System.SCREEN_BRIGHTNESS) + } catch (e: Settings.SettingNotFoundException) { + 70 + } + } private fun volumePercentChanged(percent: Int) { val stream = AudioManager.STREAM_MUSIC