Merge "Make caption a insets source"

This commit is contained in:
TreeHugger Robot
2020-03-27 07:39:45 +00:00
committed by Android (Google) Code Review
13 changed files with 184 additions and 46 deletions

View File

@@ -78,7 +78,6 @@ import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.InputQueue;
import android.view.InsetsState;
import android.view.InsetsController;
import android.view.InsetsState.InternalInsetsType;
import android.view.KeyEvent;
import android.view.KeyboardShortcutGroup;
@@ -1174,6 +1173,12 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
false /* matchVertical */, statusBarNeedsLeftInset, statusBarSideInset,
animate && !disallowAnimate,
mForceWindowDrawsBarBackgrounds, state);
if (mHasCaption) {
final int captionColor = calculateStatusBarColor();
mDecorCaptionView.getCaption().setBackgroundColor(captionColor);
updateDecorCaptionShade();
}
}
// When we expand the window with FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS or
@@ -1355,7 +1360,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
: state.attributes.isPresent(insetsState, mWindow.getAttributes().flags, force);
boolean show = state.attributes.isVisible(state.present, color,
mWindow.getAttributes().flags, force);
boolean showView = show && !isResizing() && size > 0;
boolean showView = show && !isResizing() && !mHasCaption && size > 0;
boolean visibilityChanged = false;
View view = state.view;
@@ -2021,6 +2026,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
if (getForeground() != null) {
drawableChanged();
}
getWindowInsetsController().setCaptionInsetsHeight(getCaptionInsetsHeight());
}
}
@@ -2094,6 +2100,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
mDecorCaptionView.onConfigurationChanged(displayWindowDecor);
enableCaption(displayWindowDecor);
}
getWindowInsetsController().setCaptionInsetsHeight(getCaptionInsetsHeight());
}
void onResourcesLoaded(LayoutInflater inflater, int layoutResource) {
@@ -2182,11 +2189,11 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
inflater = inflater.from(context);
final DecorCaptionView view = (DecorCaptionView) inflater.inflate(R.layout.decor_caption,
null);
setDecorCaptionShade(context, view);
setDecorCaptionShade(view);
return view;
}
private void setDecorCaptionShade(Context context, DecorCaptionView view) {
private void setDecorCaptionShade(DecorCaptionView view) {
final int shade = mWindow.getDecorCaptionShade();
switch (shade) {
case DECOR_CAPTION_SHADE_LIGHT:
@@ -2196,15 +2203,10 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
setDarkDecorCaptionShade(view);
break;
default: {
TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(R.attr.colorPrimary, value, true);
// We invert the shade depending on brightness of the theme. Dark shade for light
// theme and vice versa. Thanks to this the buttons should be visible on the
// background.
if (Color.luminance(value.data) < 0.5) {
setLightDecorCaptionShade(view);
} else {
if ((getWindowSystemUiVisibility() & SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != 0) {
setDarkDecorCaptionShade(view);
} else {
setLightDecorCaptionShade(view);
}
break;
}
@@ -2213,7 +2215,7 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
void updateDecorCaptionShade() {
if (mDecorCaptionView != null) {
setDecorCaptionShade(getContext(), mDecorCaptionView);
setDecorCaptionShade(mDecorCaptionView);
}
}
@@ -2483,6 +2485,15 @@ public class DecorView extends FrameLayout implements RootViewSurfaceTaker, Wind
return isShowingCaption() ? mDecorCaptionView.getCaptionHeight() : 0;
}
/**
* @hide
* @return the height of insets covering the top of window content area.
*/
public int getCaptionInsetsHeight() {
if (!mWindow.isOverlayWithDecorCaptionEnabled()) return 0;
return getCaptionHeight();
}
/**
* Converts a DIP measure into physical pixels.
* @param dip The dip value.

View File

@@ -17,7 +17,6 @@
package com.android.internal.widget;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.RemoteException;
import android.util.AttributeSet;
@@ -53,8 +52,7 @@ import java.util.ArrayList;
* <li>..</li>
* </ul>
*
* Although this ViewGroup has only two direct sub-Views, its behavior is more complex due to
* overlaying caption on the content and drawing.
* Here describe the behavior of overlaying caption on the content and drawing.
*
* First, no matter where the content View gets added, it will always be the first child and the
* caption will be the second. This way the caption will always be drawn on top of the content when
@@ -66,11 +64,9 @@ import java.util.ArrayList;
* <li>DecorCaptionView.onInterceptTouchEvent() will try intercepting the touch events if the
* down action is performed on top close or maximize buttons; the reason for that is we want these
* buttons to always work.</li>
* <li>The content View will receive the touch event. Mind that content is actually underneath the
* caption, so we need to introduce our own dispatch ordering. We achieve this by overriding
* {@link #buildTouchDispatchChildList()}.</li>
* <li>If the touch event is not consumed by the content View, it will go to the caption View
* and the dragging logic will be executed.</li>
* <li>The caption view will try to consume the event to apply the dragging logic.</li>
* <li>If the touch event is not consumed by the caption, the content View will receive the touch
* event</li>
* </ul>
*/
public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
@@ -137,11 +133,6 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
mOwner = owner;
mShow = show;
mOverlayWithAppContent = owner.isOverlayWithDecorCaptionEnabled();
if (mOverlayWithAppContent) {
// The caption is covering the content, so we make its background transparent to make
// the content visible.
mCaption.setBackgroundColor(Color.TRANSPARENT);
}
updateCaptionVisibility();
// By changing the outline provider to BOUNDS, the window can remove its
// background without removing the shadow.
@@ -235,18 +226,6 @@ public class DecorCaptionView extends ViewGroup implements View.OnTouchListener,
return mDragging || mCheckForDragging;
}
@Override
public ArrayList<View> buildTouchDispatchChildList() {
mTouchDispatchList.ensureCapacity(3);
if (mCaption != null) {
mTouchDispatchList.add(mCaption);
}
if (mContent != null) {
mTouchDispatchList.add(mContent);
}
return mTouchDispatchList;
}
@Override
public boolean shouldDelayChildPressedState() {
return false;