Add EdgeToEdge and coreKtx dependency
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
cbf2ea7b48
commit
c889a8c8de
@ -76,6 +76,7 @@ ext {
|
|||||||
annotationsVersion = '1.1.0'
|
annotationsVersion = '1.1.0'
|
||||||
appcompatVersion = '1.1.0'
|
appcompatVersion = '1.1.0'
|
||||||
cardviewVersion = '1.0.0'
|
cardviewVersion = '1.0.0'
|
||||||
|
coreKtxVersion = '1.2.0'
|
||||||
coordinatorLayoutVersion = '1.1.3'
|
coordinatorLayoutVersion = '1.1.3'
|
||||||
databindingVersion = '3.6.0'
|
databindingVersion = '3.6.0'
|
||||||
materialComponentsVersion = '1.1.0'
|
materialComponentsVersion = '1.1.0'
|
||||||
@ -95,6 +96,7 @@ dependencies {
|
|||||||
implementation "androidx.annotation:annotation:$annotationsVersion"
|
implementation "androidx.annotation:annotation:$annotationsVersion"
|
||||||
implementation "androidx.appcompat:appcompat:$appcompatVersion"
|
implementation "androidx.appcompat:appcompat:$appcompatVersion"
|
||||||
implementation "androidx.cardview:cardview:$cardviewVersion"
|
implementation "androidx.cardview:cardview:$cardviewVersion"
|
||||||
|
implementation "androidx.core:core-ktx:$coreKtxVersion"
|
||||||
implementation "androidx.databinding:databinding-runtime:$databindingVersion"
|
implementation "androidx.databinding:databinding-runtime:$databindingVersion"
|
||||||
implementation "androidx.preference:preference:$preferenceVersion"
|
implementation "androidx.preference:preference:$preferenceVersion"
|
||||||
implementation "com.google.android.material:material:$materialComponentsVersion"
|
implementation "com.google.android.material:material:$materialComponentsVersion"
|
||||||
|
67
app/src/main/java/com/wireguard/android/ui/EdgeToEdge.kt
Normal file
67
app/src/main/java/com/wireguard/android/ui/EdgeToEdge.kt
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2017-2020 WireGuard LLC. All Rights Reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
package com.wireguard.android.ui
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.view.marginBottom
|
||||||
|
import androidx.core.view.marginLeft
|
||||||
|
import androidx.core.view.marginRight
|
||||||
|
import androidx.core.view.marginTop
|
||||||
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.core.view.updatePadding
|
||||||
|
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A utility for edge-to-edge display. It provides several features needed to make the app
|
||||||
|
* displayed edge-to-edge on Android Q with gestural navigation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
object EdgeToEdge {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun setUpRoot(root: ViewGroup) {
|
||||||
|
root.systemUiVisibility =
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun setUpScrollingContent(scrollingContent: ViewGroup, fab: ExtendedFloatingActionButton?) {
|
||||||
|
val originalPaddingLeft = scrollingContent.paddingLeft
|
||||||
|
val originalPaddingRight = scrollingContent.paddingRight
|
||||||
|
val originalPaddingBottom = scrollingContent.paddingBottom
|
||||||
|
|
||||||
|
val fabPaddingBottom = fab?.height ?: 0
|
||||||
|
|
||||||
|
val originalMarginTop = scrollingContent.marginTop
|
||||||
|
|
||||||
|
scrollingContent.setOnApplyWindowInsetsListener { _, windowInsets ->
|
||||||
|
scrollingContent.updatePadding(
|
||||||
|
left = originalPaddingLeft + windowInsets.systemWindowInsetLeft,
|
||||||
|
right = originalPaddingRight + windowInsets.systemWindowInsetRight,
|
||||||
|
bottom = originalPaddingBottom + fabPaddingBottom + windowInsets.systemWindowInsetBottom
|
||||||
|
)
|
||||||
|
scrollingContent.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
|
topMargin = originalMarginTop + windowInsets.systemWindowInsetTop
|
||||||
|
}
|
||||||
|
windowInsets
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun setUpFAB(fab: ExtendedFloatingActionButton) {
|
||||||
|
val originalMarginLeft = fab.marginLeft
|
||||||
|
val originalMarginRight = fab.marginRight
|
||||||
|
val originalMarginBottom = fab.marginBottom
|
||||||
|
fab.setOnApplyWindowInsetsListener { _, windowInsets ->
|
||||||
|
fab.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||||
|
leftMargin = originalMarginLeft + windowInsets.systemWindowInsetLeft
|
||||||
|
rightMargin = originalMarginRight + windowInsets.systemWindowInsetRight
|
||||||
|
bottomMargin = originalMarginBottom + windowInsets.systemWindowInsetBottom
|
||||||
|
}
|
||||||
|
windowInsets
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user