Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25461] HEX backgroundColor with alpha channel act as a mask #9588

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ public boolean onCheckIsTextEditor()
}
}

@Override
protected boolean hasBorder(KrollDict d)
{
if (LOWER_THAN_JELLYBEAN) {
return false;
}
return super.hasBorder(d);
}

private boolean isHTCSenseDevice()
{
boolean isHTC = false;
Expand Down Expand Up @@ -1013,10 +1022,6 @@ public boolean interceptOnBackPressed()
@Override
protected void disableHWAcceleration()
{
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
super.disableHWAcceleration();
} else {
Log.d(TAG, "Do not disable HW acceleration for WebView.", Log.DEBUG_MODE);
}
Log.d(TAG, "Do not disable HW acceleration for WebView.", Log.DEBUG_MODE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,39 @@ protected void onDraw(Canvas canvas)

Path outerPath = new Path();
if (radius > 0f) {
//region create paths
float innerRadius = radius - padding;
if (innerRadius > 0f) {
outerPath.addRoundRect(innerRect, innerRadius, innerRadius, Direction.CW);
} else {
outerPath.addRect(innerRect, Direction.CW);
}
Path innerPath = new Path(outerPath);
//endregion

// draw border
//region draw border
outerPath.addRoundRect(outerRect, radius, radius, Direction.CCW);
canvas.drawPath(outerPath, paint);
//endregion

//region draw inner path with background color
// TIMOB-16909: hack to fix anti-aliasing
if (backgroundColor != Color.TRANSPARENT) {
paint.setColor(backgroundColor);
canvas.drawPath(innerPath, paint);
}
//endregion

//region clip inner path
canvas.clipPath(innerPath);
//endregion

//region fill canvas with transparency
if (backgroundColor != Color.TRANSPARENT) {
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
}
//endregion

} else {
outerPath.addRect(outerRect, Direction.CW);
outerPath.addRect(innerRect, Direction.CCW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public abstract class TiUIView implements KrollProxyListener, OnFocusChangeListe

private static final boolean HONEYCOMB_OR_GREATER = (Build.VERSION.SDK_INT >= 11);
private static final boolean LOLLIPOP_OR_GREATER = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
private static final boolean LOWER_THAN_JELLYBEAN = (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2);
protected static final boolean LOWER_THAN_JELLYBEAN = (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2);
private static final boolean LOWER_THAN_MARSHMALLOW = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M);

private static final int LAYER_TYPE_SOFTWARE = 1;
Expand Down Expand Up @@ -906,8 +906,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP

// TIMOB-24898: disable HW acceleration to allow transparency
// when the backgroundColor alpha channel has been set
byte bgAlpha = bgColor != null ? (byte) (bgColor >> 24) : (byte) 0xFF;
if (bgAlpha != 0xFF) {
if (bgColor != null && bgColor >>> 24 != 0xFF) {
disableHWAcceleration();
}
}
Expand Down Expand Up @@ -1478,8 +1477,7 @@ private void initializeBorder(KrollDict d, Integer bgColor)

// TIMOB-24898: disable HW acceleration to allow transparency
// when the backgroundColor alpha channel has been set
byte bgAlpha = bgColor != null ? (byte) (bgColor >> 24) : (byte) 0xFF;
if (bgAlpha != 0xFF) {
if (bgColor != null && bgColor >>> 24 != 0xFF) {
disableHWAcceleration();
}
}
Expand Down Expand Up @@ -2024,8 +2022,7 @@ public boolean onLongClick(View view)

protected void disableHWAcceleration()
{
if (borderView == null
|| (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN && !borderView.isHardwareAccelerated())) {
if (borderView == null) {
return;
}
Log.d(TAG, "Disabling hardware acceleration for instance of " + borderView.getClass().getSimpleName(),
Expand Down
34 changes: 14 additions & 20 deletions tests/Resources/ti.ui.view.addontest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,21 @@ describe('Titanium.UI.View', function () {
win = null;
});

// FIXME Get working on iOS
it.android('backgroundDisabledColor', function (finish) {
var view;
win = Ti.UI.createWindow({ backgroundColor: 'blue' });
view = Ti.UI.createView({ width: Ti.UI.FILL, height: Ti.UI.FILL });
win.add(view);
win.addEventListener('focus', function () {
if (didFocus) {
return;
}
didFocus = true;

try {
view.backgroundDisabledColor = '#88FFFFFF';
should(view.getBackgroundDisabledColor()).be.eql('#88FFFFFF');
finish();
} catch (err) {
finish(err);
}
// TIMOB-25461: Android - Views with alpha channel in background color and border radius act
// as a mask.
it.android('Border Radius with trasparency', function (finish) {
var win0 = Ti.UI.createWindow({ backgroundColor: 'green' }),
win1 = Ti.UI.createWindow({ backgroundColor: 'transparent' }),
view0 = Ti.UI.createView({ width: '90%', height: '90%', borderRadius: 5, backgroundColor: 'blue' }),
view1 = Ti.UI.createView({ width: 200, height: 200, borderRadius: 100, backgroundColor: '#33FFFFFF' }),
view2 = Ti.UI.createView({ width: 100, height: 100, borderRadius: 100, backgroundColor: 'white' });
view0.add([ view1, view2 ]);
win1.add(view0);
win0.open();
win1.open();
win1.addEventListener('open', function () {
finish();
});
win.open();
});

});