Skip to content

Commit

Permalink
Merge pull request #5904 from vishalduggal/timob-17287
Browse files Browse the repository at this point in the history
[TIMOB-17287] Support opacity animation on BorderView
  • Loading branch information
pingwang2011 committed Jul 11, 2014
2 parents 605bba1 + e5d7391 commit 9ec9d6d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
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-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 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

0 comments on commit 9ec9d6d

Please sign in to comment.