From 5f3a4778f26d71fddc73dc65b3ab3639abc4771a Mon Sep 17 00:00:00 2001 From: Santos Cordon Date: Fri, 27 Sep 2013 15:13:22 -0700 Subject: Make sure glowpad is centered when gravity is centered. +----------------+ | ---- | | - - | | - - | | - - | | ---- | +----------------+ | h | from square edge to circle edge | d | diameter of circle | w | width of square Those are the three values involved in the calculation that we are changing. The formula calculated the center of the circle (glowpad). When setting the x position of the glowpad we should always grab the radius of the circle (d/2) then set h to a proper value depending on the gravity setting: left) h = 0 // do not shift at all center) h = (w - d) / 2 // half the diff. between box and circle widths right) h = (w - d) // total diff. between box and circle widths This is what the code does after this change. The flaw that I saw was that instead of using the radius and adding to h, we used the maximum between the radius or w/2 (half the width of the box). The result was that in rare occassion (possibly for the first time in the associated bug) where the circle is smaller than the box, we would shift too far to the right because w/2 is always larger than the more appropriate d/2. I don't know why this was done, but I have added jaggies@ who originally wrote the code. I consulted with christinech@ and both determined that this is the correct mathematical formula. I verified that the old code did not work correctly for left, right, or center and that all three work as expected with the new code. bug:10958942 Change-Id: I781dc25601382d7a43408cbce0badf8a0a90d663 --- InCallUI/res/layout/answer_fragment.xml | 1 + .../src/com/android/incallui/widget/multiwaveview/GlowPadView.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/InCallUI/res/layout/answer_fragment.xml b/InCallUI/res/layout/answer_fragment.xml index 4f31e3fd8..ee2b0767c 100644 --- a/InCallUI/res/layout/answer_fragment.xml +++ b/InCallUI/res/layout/answer_fragment.xml @@ -24,6 +24,7 @@ android:layout_height="wrap_content" android:focusable="true" android:layout_centerHorizontal="true" + android:gravity="center" android:background="@android:color/black" android:visibility="gone" diff --git a/InCallUI/src/com/android/incallui/widget/multiwaveview/GlowPadView.java b/InCallUI/src/com/android/incallui/widget/multiwaveview/GlowPadView.java index 3fc978a10..a346ba593 100644 --- a/InCallUI/src/com/android/incallui/widget/multiwaveview/GlowPadView.java +++ b/InCallUI/src/com/android/incallui/widget/multiwaveview/GlowPadView.java @@ -48,7 +48,7 @@ import java.util.ArrayList; /** * This is a copy of com.android.internal.widget.multiwaveview.GlowPadView with minor changes * to remove dependencies on private api's. - * + * * Incoporated the scaling functionality. * * A re-usable widget containing a center, outer ring and wave animation. @@ -1114,9 +1114,9 @@ public class GlowPadView extends View { final float placementWidth = getRingWidth(); final float placementHeight = getRingHeight(); float newWaveCenterX = mHorizontalInset - + Math.max(width, mMaxTargetWidth + placementWidth) / 2; + + (mMaxTargetWidth + placementWidth) / 2; float newWaveCenterY = mVerticalInset - + Math.max(height, + mMaxTargetHeight + placementHeight) / 2; + + (mMaxTargetHeight + placementHeight) / 2; if (mInitialLayout) { stopAndHideWaveAnimation(); -- cgit v1.2.3