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

Commit a951475a authored by Kiran Ramachandra's avatar Kiran Ramachandra Committed by Gerrit Code Review
Browse files

Merge changes from topic "cherrypicker-L56400030010015106:N36200030169426477"...

Merge changes from topic "cherrypicker-L56400030010015106:N36200030169426477" into android15-tests-dev

* changes:
  Exposed EdgeToEdgeUtils.enable() for broader use outside the package
  Handle Edget to Edge after sdk 35
parents 5921d5fa 9dbdac35
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",
        "SettingsLibUtils",
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class CollapsingToolbarAppCompatActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        EdgeToEdgeUtils.enable(this);
        super.onCreate(savedInstanceState);
        if (BuildCompatUtils.isAtLeastS()) {
            DynamicColors.applyToActivityIfAvailable(this);
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,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 && (!BuildCompatUtils.isAtLeastS() || isWatch())) {
+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.
     */
    public 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" />