Skip to content

Commit

Permalink
Better calculation for arc and its position wrt target
Browse files Browse the repository at this point in the history
  • Loading branch information
29jitender committed Jun 17, 2016
1 parent 7ecadee commit 3a02111
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,29 +476,29 @@ public void onAnimationRepeat(Animation animation) {
private void addArcAnimation(final Activity activity) {
AppCompatImageView mImageView = new AppCompatImageView(activity);
mImageView.setImageResource(R.drawable.ic_spotlight_arc);
LayoutParams params = new LayoutParams(targetView.getViewWidth() + 2 * (padding + extraPaddingForArc),
targetView.getViewHeight() + 2 * (padding + extraPaddingForArc));
LayoutParams params = new LayoutParams(2 * (circleShape.getRadius() + extraPaddingForArc),
2 * (circleShape.getRadius() + extraPaddingForArc));


if (targetView.getPoint().y > getHeight() / 2) {//bottom
if (targetView.getPoint().x > getWidth() / 2) {//Right
params.rightMargin = getWidth() - targetView.getViewRight() - padding - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getViewBottom() - padding - extraPaddingForArc;
params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
} else {
params.leftMargin = targetView.getViewLeft() - padding - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getViewBottom() - padding - extraPaddingForArc;
params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
}
} else {//up
mImageView.setRotation(180); //Reverse the view
if (targetView.getPoint().x > getWidth() / 2) {//Right
params.rightMargin = getWidth() - targetView.getViewRight() - padding - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getViewBottom() - padding - extraPaddingForArc;
params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
} else {
params.leftMargin = targetView.getViewLeft() - padding - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getViewBottom() - padding - extraPaddingForArc;
params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
}

Expand All @@ -518,7 +518,6 @@ private void addArcAnimation(final Activity activity) {
AnimatedVectorDrawableCompat avdc =
AnimatedVectorDrawableCompat.create(activity, R.drawable.avd_spotlight_arc);
avdc.setColorFilter(porterDuffColorFilter);

mImageView.setImageDrawable(avdc);
avdc.start();
}
Expand Down Expand Up @@ -636,7 +635,7 @@ private List<AnimPoint> checkLinePoint() {
if (targetView.getPoint().y > screenHeight / 2) {//Down TODO: add a logic for by 2
if (targetView.getPoint().x > screenWidth / 2) {//Right
animPoints.add(new AnimPoint((targetView.getViewRight() - targetView.getViewWidth() / 2),
targetView.getViewTop() - padding - extraPaddingForArc, (targetView.getViewRight() - targetView.getViewWidth() / 2),
targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc, (targetView.getViewRight() - targetView.getViewWidth() / 2),
targetView.getViewTop() / 2
));
animPoints.add(new AnimPoint((targetView.getViewRight() - targetView.getViewWidth() / 2),
Expand All @@ -660,7 +659,7 @@ private List<AnimPoint> checkLinePoint() {
subHeadingTv.setGravity(Gravity.LEFT);

} else {//left
animPoints.add(new AnimPoint((targetView.getViewRight() - targetView.getViewWidth() / 2), targetView.getViewTop() - padding - extraPaddingForArc,
animPoints.add(new AnimPoint((targetView.getViewRight() - targetView.getViewWidth() / 2), targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc,
(targetView.getViewRight() - targetView.getViewWidth() / 2),
targetView.getViewTop() / 2
));
Expand Down Expand Up @@ -688,7 +687,7 @@ private List<AnimPoint> checkLinePoint() {
} else {//top
if (targetView.getPoint().x > screenWidth / 2) {//Right
animPoints.add(new AnimPoint(targetView.getViewRight() - targetView.getViewWidth() / 2,
targetView.getViewBottom() + padding + extraPaddingForArc,
targetView.getPoint().y + circleShape.getRadius() + extraPaddingForArc,
targetView.getViewRight() - targetView.getViewWidth() / 2,
(screenHeight - targetView.getViewBottom()) / 2 + targetView.getViewBottom()));

Expand All @@ -714,7 +713,7 @@ private List<AnimPoint> checkLinePoint() {

} else {//left
animPoints.add(new AnimPoint(targetView.getViewRight() - targetView.getViewWidth() / 2,
targetView.getViewBottom() + padding + extraPaddingForArc,
targetView.getPoint().y + circleShape.getRadius() + extraPaddingForArc,
targetView.getViewRight() - targetView.getViewWidth() / 2,
(screenHeight - targetView.getViewBottom()) / 2 + targetView.getViewBottom()));

Expand Down Expand Up @@ -752,7 +751,7 @@ private List<AnimPoint> checkLinePoint() {
private void removeSpotlightView() {
if (listener != null)
listener.onUserClicked(usageId);

if (getParent() != null)
((ViewGroup) getParent()).removeView(this);
}
Expand Down

0 comments on commit 3a02111

Please sign in to comment.