From 2fe5b92035934a24369197c41598c0a3972c44c5 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 20 Mar 2020 02:28:49 -0600 Subject: EdgeToEdge: move into widget Signed-off-by: Jason A. Donenfeld --- .../android/fragment/TunnelDetailFragment.kt | 4 +- .../android/fragment/TunnelEditorFragment.kt | 4 +- .../android/fragment/TunnelListFragment.kt | 8 ++- .../java/com/wireguard/android/ui/EdgeToEdge.kt | 62 ---------------------- .../com/wireguard/android/widget/EdgeToEdge.kt | 62 ++++++++++++++++++++++ 5 files changed, 69 insertions(+), 71 deletions(-) delete mode 100644 ui/src/main/java/com/wireguard/android/ui/EdgeToEdge.kt create mode 100644 ui/src/main/java/com/wireguard/android/widget/EdgeToEdge.kt (limited to 'ui/src/main') diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt index 2ed1b1df..2b5a4ba6 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.kt @@ -16,8 +16,8 @@ import com.wireguard.android.backend.Tunnel import com.wireguard.android.databinding.TunnelDetailFragmentBinding import com.wireguard.android.databinding.TunnelDetailPeerBinding import com.wireguard.android.model.ObservableTunnel -import com.wireguard.android.ui.EdgeToEdge.setUpRoot -import com.wireguard.android.ui.EdgeToEdge.setUpScrollingContent +import com.wireguard.android.widget.EdgeToEdge.setUpRoot +import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent import java.util.Timer import java.util.TimerTask diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt index 33749911..387d0962 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.kt @@ -22,8 +22,8 @@ import com.wireguard.android.backend.Tunnel import com.wireguard.android.databinding.TunnelEditorFragmentBinding import com.wireguard.android.fragment.AppListDialogFragment.AppExclusionListener import com.wireguard.android.model.ObservableTunnel -import com.wireguard.android.ui.EdgeToEdge.setUpRoot -import com.wireguard.android.ui.EdgeToEdge.setUpScrollingContent +import com.wireguard.android.widget.EdgeToEdge.setUpRoot +import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent import com.wireguard.android.util.ErrorMessages import com.wireguard.android.viewmodel.ConfigProxy import com.wireguard.config.Config diff --git a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt index ff7b8bce..32bd34f6 100644 --- a/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt +++ b/ui/src/main/java/com/wireguard/android/fragment/TunnelListFragment.kt @@ -28,17 +28,15 @@ import com.wireguard.android.databinding.TunnelListFragmentBinding import com.wireguard.android.databinding.TunnelListItemBinding import com.wireguard.android.fragment.ConfigNamingDialogFragment.Companion.newInstance import com.wireguard.android.model.ObservableTunnel -import com.wireguard.android.ui.EdgeToEdge.setUpFAB -import com.wireguard.android.ui.EdgeToEdge.setUpRoot -import com.wireguard.android.ui.EdgeToEdge.setUpScrollingContent +import com.wireguard.android.widget.EdgeToEdge.setUpFAB +import com.wireguard.android.widget.EdgeToEdge.setUpRoot +import com.wireguard.android.widget.EdgeToEdge.setUpScrollingContent import com.wireguard.android.util.ErrorMessages import com.wireguard.android.widget.MultiselectableRelativeLayout -import com.wireguard.config.BadConfigException import com.wireguard.config.Config import java9.util.concurrent.CompletableFuture import java.io.BufferedReader import java.io.ByteArrayInputStream -import java.io.IOException import java.io.InputStreamReader import java.nio.charset.StandardCharsets import java.util.ArrayList diff --git a/ui/src/main/java/com/wireguard/android/ui/EdgeToEdge.kt b/ui/src/main/java/com/wireguard/android/ui/EdgeToEdge.kt deleted file mode 100644 index ac4d214d..00000000 --- a/ui/src/main/java/com/wireguard/android/ui/EdgeToEdge.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.* -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 { - 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 { - leftMargin = originalMarginLeft + windowInsets.systemWindowInsetLeft - rightMargin = originalMarginRight + windowInsets.systemWindowInsetRight - bottomMargin = originalMarginBottom + windowInsets.systemWindowInsetBottom - } - windowInsets - } - } -} diff --git a/ui/src/main/java/com/wireguard/android/widget/EdgeToEdge.kt b/ui/src/main/java/com/wireguard/android/widget/EdgeToEdge.kt new file mode 100644 index 00000000..544e9ddb --- /dev/null +++ b/ui/src/main/java/com/wireguard/android/widget/EdgeToEdge.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2017-2020 WireGuard LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package com.wireguard.android.widget + +import android.view.View +import android.view.ViewGroup +import androidx.core.view.* +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 { + 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 { + leftMargin = originalMarginLeft + windowInsets.systemWindowInsetLeft + rightMargin = originalMarginRight + windowInsets.systemWindowInsetRight + bottomMargin = originalMarginBottom + windowInsets.systemWindowInsetBottom + } + windowInsets + } + } +} -- cgit v1.2.3