diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-03-05 23:46:32 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-05 23:47:55 +0000 |
commit | cd851f18132ffad6f79f7a664aa1999257545297 (patch) | |
tree | 58b05f2e4ce6e7317daad35b0afb1cc128fa947d /src | |
parent | fd3ea4f20b1aa8907ab46b5cb1457c5cd16ae5e3 (diff) | |
parent | a39b82e2eba2580a210e34ce1a842589529348bf (diff) | |
download | android_packages_apps_Trebuchet-cd851f18132ffad6f79f7a664aa1999257545297.tar.gz android_packages_apps_Trebuchet-cd851f18132ffad6f79f7a664aa1999257545297.tar.bz2 android_packages_apps_Trebuchet-cd851f18132ffad6f79f7a664aa1999257545297.zip |
Merge "Using left and top instead of getLocationInWindow for getting target view position" into ub-launcher3-burnaby
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/FocusIndicatorView.java | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/com/android/launcher3/FocusIndicatorView.java b/src/com/android/launcher3/FocusIndicatorView.java index 7d4664abb..53dc2e22b 100644 --- a/src/com/android/launcher3/FocusIndicatorView.java +++ b/src/com/android/launcher3/FocusIndicatorView.java @@ -23,7 +23,6 @@ import android.graphics.Canvas; import android.util.AttributeSet; import android.util.Pair; import android.view.View; -import android.view.ViewParent; public class FocusIndicatorView extends View implements View.OnFocusChangeListener { @@ -32,9 +31,6 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen private static final float MIN_VISIBLE_ALPHA = 0.2f; private static final long ANIM_DURATION = 150; - private static final int[] sTempPos = new int[2]; - private static final int[] sTempShift = new int[2]; - private final int[] mIndicatorPos = new int[2]; private final int[] mTargetViewPos = new int[2]; @@ -44,6 +40,8 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen private View mLastFocusedView; private boolean mInitiated; + private View mCommonParent; + private Pair<View, Boolean> mPendingCall; public FocusIndicatorView(Context context) { @@ -80,7 +78,9 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen } if (!mInitiated) { - getLocationRelativeToParentPagedView(this, mIndicatorPos); + // The parent view should always the a parent of the target view. + mCommonParent = (View) this.getParent(); + computeLocationRelativeToParent(this, mCommonParent, mIndicatorPos); mInitiated = true; } @@ -93,7 +93,7 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen nextState.scaleX = v.getScaleX() * v.getWidth() / indicatorWidth; nextState.scaleY = v.getScaleY() * v.getHeight() / indicatorHeight; - getLocationRelativeToParentPagedView(v, mTargetViewPos); + computeLocationRelativeToParent(v, mCommonParent, mTargetViewPos); nextState.x = mTargetViewPos[0] - mIndicatorPos[0] - (1 - nextState.scaleX) * indicatorWidth / 2; nextState.y = mTargetViewPos[1] - mIndicatorPos[1] - (1 - nextState.scaleY) * indicatorHeight / 2; @@ -150,27 +150,32 @@ public class FocusIndicatorView extends View implements View.OnFocusChangeListen } /** - * Gets the location of a view relative in the window, off-setting any shift due to - * page view scroll + * Computes the location of a view relative to {@link #mCommonParent}, off-setting + * any shift due to page view scroll. + * @param pos an array of two integers in which to hold the coordinates */ - private static void getLocationRelativeToParentPagedView(View v, int[] pos) { - getPagedViewScrollShift(v, sTempShift); - v.getLocationInWindow(sTempPos); - pos[0] = sTempPos[0] + sTempShift[0]; - pos[1] = sTempPos[1] + sTempShift[1]; + private static void computeLocationRelativeToParent(View v, View parent, int[] pos) { + pos[0] = pos[1] = 0; + computeLocationRelativeToParentHelper(v, parent, pos); + + // If a view is scaled, its position will also shift accordingly. For optimization, only + // consider this for the last node. + pos[0] += (1 - v.getScaleX()) * v.getWidth() / 2; + pos[1] += (1 - v.getScaleY()) * v.getHeight() / 2; } - private static void getPagedViewScrollShift(View child, int[] shift) { - ViewParent parent = child.getParent(); + private static void computeLocationRelativeToParentHelper(View child, + View commonParent, int[] shift) { + View parent = (View) child.getParent(); if (parent instanceof PagedView) { - View parentView = (View) parent; - child.getLocationInWindow(sTempPos); - shift[0] = parentView.getPaddingLeft() - sTempPos[0]; - shift[1] = -(int) child.getTranslationY(); - } else if (parent instanceof View) { - getPagedViewScrollShift((View) parent, shift); - } else { - shift[0] = shift[1] = 0; + child = ((PagedView) parent).getPageAt(0); + } + + shift[0] += child.getLeft(); + shift[1] += child.getTop(); + + if (parent != commonParent) { + computeLocationRelativeToParentHelper(parent, commonParent, shift); } } |