Merge pull request #1598 from Naveen3Singh/status_bar_height_fix

Update status bar height using WindowInsetCompat API
This commit is contained in:
Tibor Kaputa 2023-01-15 20:36:56 +01:00 committed by GitHub
commit d9af24ed94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -36,6 +36,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.app.ActivityCompat
import androidx.core.util.Pair
import androidx.core.view.ScrollingView
import androidx.core.view.WindowInsetsCompat
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.R
@ -227,11 +228,13 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
if (navigationBarHeight > 0 || isUsingGestureNavigation()) {
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility.addBit(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
nestedView?.setPadding(nestedView!!.paddingLeft, nestedView!!.paddingTop, nestedView!!.paddingRight, navigationBarHeight)
(mainCoordinatorLayout?.layoutParams as? FrameLayout.LayoutParams)?.topMargin = statusBarHeight
} else {
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility.removeBit(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
nestedView?.setPadding(nestedView!!.paddingLeft, nestedView!!.paddingTop, nestedView!!.paddingRight, 0)
(mainCoordinatorLayout?.layoutParams as? FrameLayout.LayoutParams)?.topMargin = 0
}
onApplyWindowInsets {
val insets = it.getInsets(WindowInsetsCompat.Type.systemBars())
(mainCoordinatorLayout?.layoutParams as? FrameLayout.LayoutParams)?.topMargin = insets.top
}
}
}

View file

@ -32,6 +32,7 @@ import androidx.biometric.BiometricPrompt
import androidx.biometric.auth.AuthPromptCallback
import androidx.biometric.auth.AuthPromptHost
import androidx.biometric.auth.Class2BiometricAuthPrompt
import androidx.core.view.WindowInsetsCompat
import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.FragmentActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -1716,3 +1717,10 @@ fun BaseSimpleActivity.getTempFile(folderName: String, fileName: String): File?
return File(folder, fileName)
}
fun Activity.onApplyWindowInsets(callback: (WindowInsetsCompat) -> Unit) {
window.decorView.setOnApplyWindowInsetsListener { v, insets ->
callback(WindowInsetsCompat.toWindowInsetsCompat(insets))
insets
}
}