Merge "Adds setCornerRadius to ActivityView & SurfaceView" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b46293f8f6
@@ -188,6 +188,17 @@ public class ActivityView extends ViewGroup {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the corner radius for the Activity displayed here. The corners will be
|
||||
* cropped from the window painted by the contained Activity.
|
||||
*
|
||||
* @param cornerRadius the radius for the corners, in pixels
|
||||
* @hide
|
||||
*/
|
||||
public void setCornerRadius(float cornerRadius) {
|
||||
mSurfaceView.setCornerRadius(cornerRadius);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch a new activity into this container.
|
||||
* <p>Activity resolved by the provided {@link Intent} must have
|
||||
|
||||
@@ -24,8 +24,10 @@ import android.annotation.UnsupportedAppUsage;
|
||||
import android.content.Context;
|
||||
import android.content.res.CompatibilityInfo.Translator;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.BlendMode;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
@@ -127,6 +129,8 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
|
||||
final Rect mTmpRect = new Rect();
|
||||
final Configuration mConfiguration = new Configuration();
|
||||
|
||||
Paint mRoundedViewportPaint;
|
||||
|
||||
int mSubLayer = APPLICATION_MEDIA_SUBLAYER;
|
||||
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||
@@ -180,6 +184,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
|
||||
int mWindowSpaceTop = -1;
|
||||
int mSurfaceWidth = -1;
|
||||
int mSurfaceHeight = -1;
|
||||
float mCornerRadius;
|
||||
@UnsupportedAppUsage
|
||||
int mFormat = -1;
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||
@@ -395,7 +400,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
|
||||
// draw() is not called when SKIP_DRAW is set
|
||||
if ((mPrivateFlags & PFLAG_SKIP_DRAW) == 0) {
|
||||
// punch a whole in the view-hierarchy below us
|
||||
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
|
||||
clearSurfaceViewPort(canvas);
|
||||
}
|
||||
}
|
||||
super.draw(canvas);
|
||||
@@ -407,12 +412,39 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
|
||||
// draw() is not called when SKIP_DRAW is set
|
||||
if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) {
|
||||
// punch a whole in the view-hierarchy below us
|
||||
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
|
||||
clearSurfaceViewPort(canvas);
|
||||
}
|
||||
}
|
||||
super.dispatchDraw(canvas);
|
||||
}
|
||||
|
||||
private void clearSurfaceViewPort(Canvas canvas) {
|
||||
if (mCornerRadius > 0f) {
|
||||
canvas.getClipBounds(mTmpRect);
|
||||
canvas.drawRoundRect(mTmpRect.left, mTmpRect.top, mTmpRect.right, mTmpRect.bottom,
|
||||
mCornerRadius, mCornerRadius, mRoundedViewportPaint);
|
||||
} else {
|
||||
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the corner radius for the SurfaceView. This will round both the corners of the
|
||||
* underlying surface, as well as the corners of the hole created to expose the surface.
|
||||
*
|
||||
* @param cornerRadius the new radius of the corners in pixels
|
||||
* @hide
|
||||
*/
|
||||
public void setCornerRadius(float cornerRadius) {
|
||||
mCornerRadius = cornerRadius;
|
||||
if (mCornerRadius > 0f && mRoundedViewportPaint == null) {
|
||||
mRoundedViewportPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
mRoundedViewportPaint.setBlendMode(BlendMode.CLEAR);
|
||||
mRoundedViewportPaint.setColor(0);
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Control whether the surface view's surface is placed on top of another
|
||||
* regular surface view in the window (but still behind the window itself).
|
||||
@@ -634,6 +666,7 @@ public class SurfaceView extends View implements ViewRootImpl.WindowStoppedCallb
|
||||
// size.
|
||||
mSurfaceControl.setWindowCrop(mSurfaceWidth, mSurfaceHeight);
|
||||
}
|
||||
mSurfaceControl.setCornerRadius(mCornerRadius);
|
||||
if (sizeChanged && !creating) {
|
||||
mSurfaceControl.setBufferSize(mSurfaceWidth, mSurfaceHeight);
|
||||
}
|
||||
|
||||
@@ -151,5 +151,11 @@
|
||||
<attr name="optedOut" format="boolean" />
|
||||
</declare-styleable>
|
||||
|
||||
<!-- Theme attributes used to style the appearance of expanded Bubbles -->
|
||||
<declare-styleable name="BubbleExpandedView">
|
||||
<attr name="android:colorBackgroundFloating" />
|
||||
<attr name="android:dialogCornerRadius" />
|
||||
</declare-styleable>
|
||||
|
||||
</resources>
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.internal.policy.ScreenDecorationsUtils;
|
||||
import com.android.systemui.Dependency;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.recents.TriangleShape;
|
||||
@@ -87,6 +88,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
|
||||
private int mBubbleHeight;
|
||||
private int mPointerWidth;
|
||||
private int mPointerHeight;
|
||||
private ShapeDrawable mPointerDrawable;
|
||||
|
||||
private NotificationEntry mEntry;
|
||||
private PackageManager mPm;
|
||||
@@ -170,16 +172,10 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
|
||||
mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width);
|
||||
mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height);
|
||||
|
||||
TypedArray ta = getContext().obtainStyledAttributes(
|
||||
new int[] {android.R.attr.colorBackgroundFloating});
|
||||
int bgColor = ta.getColor(0, Color.WHITE);
|
||||
ta.recycle();
|
||||
|
||||
ShapeDrawable triangleDrawable = new ShapeDrawable(TriangleShape.create(
|
||||
mPointerDrawable = new ShapeDrawable(TriangleShape.create(
|
||||
mPointerWidth, mPointerHeight, false /* pointUp */));
|
||||
|
||||
triangleDrawable.setTint(bgColor);
|
||||
mPointerView.setBackground(triangleDrawable);
|
||||
mPointerView.setBackground(mPointerDrawable);
|
||||
|
||||
mSettingsIconHeight = getContext().getResources().getDimensionPixelSize(
|
||||
R.dimen.bubble_expanded_header_height);
|
||||
@@ -193,6 +189,8 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
|
||||
// Make sure pointer is below activity view
|
||||
bringChildToFront(mPointerView);
|
||||
|
||||
applyThemeAttrs();
|
||||
|
||||
setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> {
|
||||
// Keep track of IME displaying because we should not make any adjustments that might
|
||||
// cause a config change while the IME is displayed otherwise it'll loose focus.
|
||||
@@ -206,6 +204,23 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
|
||||
});
|
||||
}
|
||||
|
||||
void applyThemeAttrs() {
|
||||
TypedArray ta = getContext().obtainStyledAttributes(R.styleable.BubbleExpandedView);
|
||||
int bgColor = ta.getColor(
|
||||
R.styleable.BubbleExpandedView_android_colorBackgroundFloating, Color.WHITE);
|
||||
float cornerRadius = ta.getDimension(
|
||||
R.styleable.BubbleExpandedView_android_dialogCornerRadius, 0);
|
||||
ta.recycle();
|
||||
|
||||
// Update triangle color.
|
||||
mPointerDrawable.setTint(bgColor);
|
||||
|
||||
// Update ActivityView cornerRadius
|
||||
if (ScreenDecorationsUtils.supportsRoundedCornersOnWindows(mContext.getResources())) {
|
||||
mActivityView.setCornerRadius(cornerRadius);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
@@ -266,7 +281,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
|
||||
if (mAppIcon == null) {
|
||||
mAppIcon = mPm.getDefaultActivityIcon();
|
||||
}
|
||||
updateTheme();
|
||||
applyThemeAttrs();
|
||||
showSettingsIcon();
|
||||
updateExpandedView();
|
||||
}
|
||||
@@ -306,21 +321,6 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
|
||||
}
|
||||
}
|
||||
|
||||
void updateTheme() {
|
||||
// Get new colors.
|
||||
TypedArray ta = mContext.obtainStyledAttributes(
|
||||
new int[]{android.R.attr.colorBackgroundFloating, android.R.attr.colorForeground});
|
||||
int backgroundColor = ta.getColor(0, Color.WHITE /* default */);
|
||||
int foregroundColor = ta.getColor(1, Color.BLACK /* default */);
|
||||
ta.recycle();
|
||||
|
||||
// Update triangle color.
|
||||
ShapeDrawable triangleDrawable = new ShapeDrawable(
|
||||
TriangleShape.create(mPointerWidth, mPointerHeight, false /* pointUp */));
|
||||
triangleDrawable.setTint(backgroundColor);
|
||||
mPointerView.setBackground(triangleDrawable);
|
||||
}
|
||||
|
||||
private void updateExpandedView() {
|
||||
mBubbleIntent = getBubbleIntent(mEntry);
|
||||
if (mBubbleIntent != null) {
|
||||
|
||||
@@ -451,7 +451,7 @@ public class BubbleStackView extends FrameLayout {
|
||||
public void onThemeChanged() {
|
||||
for (Bubble b: mBubbleData.getBubbles()) {
|
||||
b.iconView.updateViews();
|
||||
b.expandedView.updateTheme();
|
||||
b.expandedView.applyThemeAttrs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user