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

Commit 9dbe94d8 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Magic null-background filling for PhoneWindows" into lmp-dev

parents ac60bea0 f849a5e1
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Outline;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.ActionMode;
@@ -384,7 +385,23 @@ public class ActionBarContainer extends FrameLayout {

        @Override
        public int getOpacity() {
            return 0;
            if (mIsSplit) {
                if (mSplitBackground != null
                        && mSplitBackground.getOpacity() == PixelFormat.OPAQUE) {
                    return PixelFormat.OPAQUE;
                }
            } else {
                if (mIsStacked && (mStackedBackground == null
                        || mStackedBackground.getOpacity() != PixelFormat.OPAQUE)) {
                    return PixelFormat.UNKNOWN;
                }
                if (!isCollapsed(mActionBarView) && mBackground != null
                        && mBackground.getOpacity() == PixelFormat.OPAQUE) {
                    return PixelFormat.OPAQUE;
                }
            }

            return PixelFormat.UNKNOWN;
        }
    }
}
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.internal.widget;

import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;

/**
 * Helper class for drawing a fallback background in framework decor layouts.
 * Useful for when an app has not set a window background but we're asked to draw
 * an uncovered area.
 */
public class BackgroundFallback {
    private Drawable mBackgroundFallback;

    public void setDrawable(Drawable d) {
        mBackgroundFallback = d;
    }

    public boolean hasFallback() {
        return mBackgroundFallback != null;
    }

    public void draw(ViewGroup root, Canvas c, View content) {
        if (!hasFallback()) {
            return;
        }

        // Draw the fallback in the padding.
        final int width = root.getWidth();
        final int height = root.getHeight();
        int left = width;
        int top = height;
        int right = 0;
        int bottom = 0;

        final int childCount = root.getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View child = root.getChildAt(i);
            final Drawable childBg = child.getBackground();
            if (child == content) {
                // We always count the content view container unless it has no background
                // and no children.
                if (childBg == null && child instanceof ViewGroup &&
                        ((ViewGroup) child).getChildCount() == 0) {
                    continue;
                }
            } else if (child.getVisibility() != View.VISIBLE || childBg == null ||
                    childBg.getOpacity() != PixelFormat.OPAQUE) {
                // Potentially translucent or invisible children don't count, and we assume
                // the content view will cover the whole area if we're in a background
                // fallback situation.
                continue;
            }
            left = Math.min(left, child.getLeft());
            top = Math.min(top, child.getTop());
            right = Math.max(right, child.getRight());
            bottom = Math.max(bottom, child.getBottom());
        }

        if (left >= right || top >= bottom) {
            // No valid area to draw in.
            return;
        }

        if (top > 0) {
            mBackgroundFallback.setBounds(0, 0, width, top);
            mBackgroundFallback.draw(c);
        }
        if (left > 0) {
            mBackgroundFallback.setBounds(0, top, left, height);
            mBackgroundFallback.draw(c);
        }
        if (right < width) {
            mBackgroundFallback.setBounds(right, top, width, height);
            mBackgroundFallback.draw(c);
        }
        if (bottom < height) {
            mBackgroundFallback.setBounds(left, bottom, right, height);
            mBackgroundFallback.draw(c);
        }
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -49,5 +49,4 @@ public interface DecorContentParent {
    void saveToolbarHierarchyState(SparseArray<Parcelable> toolbarStates);
    void restoreToolbarHierarchyState(SparseArray<Parcelable> toolbarStates);
    void dismissPopups();

}
+5 −0
Original line number Diff line number Diff line
@@ -308,6 +308,10 @@
                  null so it will not be drawn.
             </ul> -->
        <attr name="windowBackground" format="reference" />
        <!-- Drawable to draw selectively within the inset areas when the windowBackground
             has been set to null. This protects against seeing visual garbage in the
             surface when the app has not drawn any content into this area. -->
        <attr name="windowBackgroundFallback" format="reference" />
        <!-- Drawable to use as a frame around the window. -->
        <attr name="windowFrame" format="reference" />
        <!-- Flag indicating whether there should be no title on this window. -->
@@ -1772,6 +1776,7 @@
    <!-- The set of attributes that describe a Windows's theme. -->
    <declare-styleable name="Window">
        <attr name="windowBackground" />
        <attr name="windowBackgroundFallback" />
        <attr name="windowContentOverlay" />
        <attr name="windowFrame" />
        <attr name="windowNoTitle" />
+1 −0
Original line number Diff line number Diff line
@@ -2060,4 +2060,5 @@
  <java-symbol type="layout" name="resolver_different_item_header" />
  <java-symbol type="array" name="config_default_vm_number" />
  <java-symbol type="integer" name="config_cdma_3waycall_flash_delay"/>
  <java-symbol type="attr" name="windowBackgroundFallback" />
</resources>
Loading