summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/Utilities.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-06-15 10:11:30 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-06-15 10:11:56 -0700
commit8cf47a5121205486e20694bf48eafc171175027a (patch)
treeeda8a9ca67430b2b63a21492d1faf70a1eb65423 /src/com/android/launcher3/Utilities.java
parentb25b2c41c2fa277e16d708ad827e283efcb86452 (diff)
downloadpackages_apps_Trebuchet-8cf47a5121205486e20694bf48eafc171175027a.tar.gz
packages_apps_Trebuchet-8cf47a5121205486e20694bf48eafc171175027a.tar.bz2
packages_apps_Trebuchet-8cf47a5121205486e20694bf48eafc171175027a.zip
Removing unnecessary object creation and double loop during
getDescendantCoordRelativeToAncestor Change-Id: I034db2282a8aaf129336a425338c6a80d6a3a073
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r--src/com/android/launcher3/Utilities.java32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 35113758a..6bfce192c 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -341,35 +341,27 @@ public final class Utilities {
*/
public static float getDescendantCoordRelativeToAncestor(
View descendant, View ancestor, int[] coord, boolean includeRootScroll) {
- ArrayList<View> ancestorChain = new ArrayList<View>();
-
float[] pt = {coord[0], coord[1]};
-
+ float scale = 1.0f;
View v = descendant;
while(v != ancestor && v != null) {
- ancestorChain.add(v);
- v = (View) v.getParent();
- }
-
- float scale = 1.0f;
- int count = ancestorChain.size();
- for (int i = 0; i < count; i++) {
- View v0 = ancestorChain.get(i);
// For TextViews, scroll has a meaning which relates to the text position
// which is very strange... ignore the scroll.
- if (v0 != descendant || includeRootScroll) {
- pt[0] -= v0.getScrollX();
- pt[1] -= v0.getScrollY();
+ if (v != descendant || includeRootScroll) {
+ pt[0] -= v.getScrollX();
+ pt[1] -= v.getScrollY();
}
- v0.getMatrix().mapPoints(pt);
- pt[0] += v0.getLeft();
- pt[1] += v0.getTop();
- scale *= v0.getScaleX();
+ v.getMatrix().mapPoints(pt);
+ pt[0] += v.getLeft();
+ pt[1] += v.getTop();
+ scale *= v.getScaleX();
+
+ v = (View) v.getParent();
}
- coord[0] = (int) Math.round(pt[0]);
- coord[1] = (int) Math.round(pt[1]);
+ coord[0] = Math.round(pt[0]);
+ coord[1] = Math.round(pt[1]);
return scale;
}