Skip to content

Commit

Permalink
Merge pull request #156 from TeamAmaze/feature-42
Browse files Browse the repository at this point in the history
Overlay notch area in video player landscape
  • Loading branch information
VishalNehra authored Dec 20, 2023
2 parents 7b395b9 + acad9f0 commit bc5c7e6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.PlaybackParameters
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.audio.AudioAttributes
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicReference
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicReference

class AudioPlayerService : Service(), ServiceOperationCallback, OnPlayerRepeatingCallback {

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/amaze/fileutilities/utilis/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import android.os.Environment
import android.os.ParcelFileDescriptor
import android.os.TransactionTooLargeException
import android.provider.MediaStore
import android.provider.Settings
import android.util.DisplayMetrics
import android.view.Gravity
import android.view.View
Expand Down Expand Up @@ -686,3 +687,15 @@ fun View.fadInAnimation(duration: Long = 300, completion: (() -> Unit)? = null)
}
}
}

fun Context.getScreenBrightness(): Float {
var brightness = 0
try {
val contentResolver = this.contentResolver
brightness = Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS)
} catch (e: Exception) {
log.warn("failed to get system brightness", e)
return -1f
}
return (brightness / 255).toFloat()
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import com.amaze.fileutilities.utilis.dialog_picker.FileFilter
import com.amaze.fileutilities.utilis.getAppCommonSharedPreferences
import com.amaze.fileutilities.utilis.getExternalStorageDirectory
import com.amaze.fileutilities.utilis.getFileFromUri
import com.amaze.fileutilities.utilis.getScreenBrightness
import com.amaze.fileutilities.utilis.hideFade
import com.amaze.fileutilities.utilis.isNetworkAvailable
import com.amaze.fileutilities.utilis.removeExtension
Expand Down Expand Up @@ -990,7 +991,16 @@ abstract class BaseVideoPlayerActivity :

private fun invalidateBrightness() {
val layout = window.attributes
layout.screenBrightness = videoPlayerViewModel?.brightnessLevel ?: 0.3f
val systemBrightness = this.getScreenBrightness()
layout.screenBrightness = if (videoPlayerViewModel != null &&
videoPlayerViewModel?.brightnessLevel != 0.3f
) {
videoPlayerViewModel!!.brightnessLevel
} else if (systemBrightness != -1f) {
systemBrightness
} else {
0.3f
}
window.attributes = layout
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@

package com.amaze.fileutilities.video_player

import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.view.WindowManager

class VideoPlayerActivity : BaseVideoPlayerActivity() {

Expand All @@ -36,5 +42,30 @@ class VideoPlayerActivity : BaseVideoPlayerActivity() {
initLocalVideoModel(intent)
super.onCreate(savedInstanceState)
handleVideoPlayerActivityResources()
val orientation = resources.configuration.orientation
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
// allow to go in notch area in landscape mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// Set the system UI visibility flags
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

// Get the WindowInsetsController
val controller = window.insetsController

// Hide the system bars (navigation bar, status bar)
controller?.hide(WindowInsets.Type.systemBars())

// Enable the extended layout to be displayed in the notch area
controller?.systemBarsBehavior =
WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
} else {
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
}
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values-v27/themes.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.AmazeFileUtilities.FullScreen.Dark" parent="Theme.AmazeFileUtilities.Dark">
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
<item name="android:windowLayoutInDisplayCutoutMode">always</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Expand Down

0 comments on commit bc5c7e6

Please sign in to comment.