Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fcc29956 authored by Edgar Wang's avatar Edgar Wang Committed by Android (Google) Code Review
Browse files

Merge "Handle Edget to Edge after sdk 35" into main

parents 216b51ce bddf1693
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ android_library {
    static_libs: [
        "androidx.annotation_annotation",
        "androidx.core_core",
        "androidx.activity_activity",
        "com.google.android.material_material",
        "SettingsLibSettingsTransition",
        "SettingsLibSettingsTheme",
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ public class CollapsingToolbarAppCompatActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        EdgeToEdgeUtils.enable(this);
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            DynamicColors.applyToActivityIfAvailable(this);
+1 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class CollapsingToolbarBaseActivity extends FragmentActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        EdgeToEdgeUtils.enable(this);
        super.onCreate(savedInstanceState);
        // for backward compatibility on R devices or wearable devices due to small device size.
        if (mCustomizeLayoutResId > 0 && (Build.VERSION.SDK_INT < Build.VERSION_CODES.S
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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
 *
 *      http://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 com.android.settingslib.collapsingtoolbar;

import android.os.Build;

import androidx.activity.ComponentActivity;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

/**
 * Util class for edge to edge.
 */
public class EdgeToEdgeUtils {
    private EdgeToEdgeUtils() {
    }

    /**
     * Enable Edge to Edge and handle overlaps using insets. It should be called before
     * setContentView.
     */
    static void enable(@NonNull ComponentActivity activity) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
            return;
        }

        EdgeToEdge.enable(activity);

        ViewCompat.setOnApplyWindowInsetsListener(activity.findViewById(android.R.id.content),
                (v, windowInsets) -> {
                    Insets insets = windowInsets.getInsets(
                            WindowInsetsCompat.Type.systemBars()
                                    | WindowInsetsCompat.Type.ime()
                                    | WindowInsetsCompat.Type.displayCutout());
                    int statusBarHeight = activity.getWindow().getDecorView().getRootWindowInsets()
                            .getInsets(WindowInsetsCompat.Type.statusBars()).top;
                    // Apply the insets paddings to the view.
                    v.setPadding(insets.left, statusBarHeight, insets.right, insets.bottom);

                    // Return CONSUMED if you don't want the window insets to keep being
                    // passed down to descendant views.
                    return WindowInsetsCompat.CONSUMED;
                });
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
        <item name="android:textColorPrimary">@color/settingslib_materialColorOnSurface</item>
        <item name="android:textColorSecondary">@color/settingslib_text_color_secondary</item>
        <item name="android:textColorTertiary">@color/settingslib_materialColorOutline</item>
        <!-- Set up edge-to-edge configuration for top app bar -->
        <item name="android:clipToPadding">false</item>
        <item name="android:clipChildren">false</item>
    </style>

    <style name="Theme.SettingsBase" parent="Theme.SettingsBase_v35" />