diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7edd2bbd..f3d5e97e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,7 @@ androidx-compose-ui-test = "1.7.0-alpha08" androidx-constraintlayout = "2.2.0" androidx-constraintlayout-compose = "1.1.0" androidx-coordinator-layout = "1.2.0" -androidx-corektx = "1.15.0" +androidx-corektx = "1.16.0-beta01" androidx-credentials = "1.5.0" androidx-credentials-play-services-auth = "1.5.0" androidx-emoji2-views = "1.5.0" diff --git a/views/src/main/java/insets/SystemBarProtectionSnippet.kt b/views/src/main/java/insets/SystemBarProtectionSnippet.kt new file mode 100644 index 00000000..d4774fd2 --- /dev/null +++ b/views/src/main/java/insets/SystemBarProtectionSnippet.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package insets + +import android.graphics.Color +import android.os.Bundle +import android.view.View +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.core.view.insets.GradientProtection +import androidx.core.view.insets.ProtectionLayout +import com.example.example.snippet.views.R + +class SystemBarProtectionSnippet : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.system_bar_protection) + + enableEdgeToEdge() + + ViewCompat.setOnApplyWindowInsetsListener( + findViewById(R.id.item_list) + ) { v: View, insets: WindowInsetsCompat -> + val innerPadding = insets.getInsets( + WindowInsetsCompat.Type.systemBars() or + WindowInsetsCompat.Type.displayCutout() + ) + v.setPadding( + innerPadding.left, + innerPadding.top, + innerPadding.right, + innerPadding.bottom + ) + insets + } + + // [START android_system_bar_protection_kotlin] + val red = 52 + val green = 168 + val blue = 83 + findViewById(R.id.list_protection) + .setProtections( + listOf( + GradientProtection( + WindowInsetsCompat.Side.TOP, + // Ideally, this is the pane's background color + // alpha = 204 for an 80% gradient + Color.argb(204, red, green, blue) + ) + ) + ) + // [END android_system_bar_protection_kotlin] + } +} diff --git a/views/src/main/res/layout/system_bar_protection.xml b/views/src/main/res/layout/system_bar_protection.xml new file mode 100644 index 00000000..f70ccd21 --- /dev/null +++ b/views/src/main/res/layout/system_bar_protection.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + \ No newline at end of file