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-17287] Support opacity animation on BorderView #5904

Merged
merged 3 commits into from
Jul 11, 2014
Merged
Show file tree
Hide file tree
Changes from 2 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
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2012-1014 by Appcelerator, Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2014

* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand All @@ -10,6 +10,8 @@

import org.appcelerator.kroll.common.Log;

import com.nineoldandroids.view.ViewHelper;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
Expand All @@ -19,6 +21,8 @@
import android.graphics.Path.FillType;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.view.View;
import android.widget.FrameLayout;

/**
Expand All @@ -38,6 +42,7 @@ public class TiBorderWrapperView extends FrameLayout
private Path innerPath;
private Path borderPath;
private Paint paint;
private View child;

public TiBorderWrapperView(Context context)
{
Expand Down Expand Up @@ -109,7 +114,7 @@ private void drawBorder(Canvas canvas)
paint.setColor(color);
if (alpha > -1) {
paint.setAlpha(alpha);
}
}
canvas.drawPath(borderPath, paint);
}

Expand All @@ -127,9 +132,34 @@ public void setBorderWidth(float borderWidth)
{
this.borderWidth = borderWidth;
}

public void setBorderAlpha(int alpha)

@Override
public boolean onSetAlpha(int alpha)
{
this.alpha = alpha;
if (Build.VERSION.SDK_INT < 11) {
/*
* This is an ugly hack. ViewHelper.setAlpha does not work on border when
* alpha < 1. So we are going to manage alpha animation for ourselves and our
* child view manually. This needs to be researched and factored out.
*
* TIMOB-17287
*/
this.alpha = alpha;
float falpha = alpha/255.0f;
if (child == null) {
try {
child = getChildAt(0);
} catch (Throwable t) {
//Ignore this error.
child = null;
}
}
if (child != null) {
//Set alpha of child view
ViewHelper.setAlpha(child, falpha);
}
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2014 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
Expand Down Expand Up @@ -1596,13 +1596,11 @@ public void setOpacity(float opacity)
Log.w(TAG, "Ignoring invalid value for opacity: " + opacity);
return;
}

if (borderView != null) {
borderView.setBorderAlpha(Math.round(opacity * 255));
borderView.postInvalidate();
}
if (nativeView != null) {
setOpacity(borderView, opacity);
} else if (nativeView != null) {
setOpacity(nativeView, opacity);
nativeView.postInvalidate();
}
}

Expand All @@ -1615,6 +1613,7 @@ public void setOpacity(float opacity)
protected void setAlpha(View view, float alpha)
{
view.setAlpha(alpha);
view.postInvalidate();
}

/**
Expand Down