summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/FocusIndicatorView.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-03-05 13:43:28 -0800
committerSunny Goyal <sunnygoyal@google.com>2015-03-05 15:45:02 -0800
commita39b82e2eba2580a210e34ce1a842589529348bf (patch)
tree3f4200e8c496579aa64f91ca57f99a9df938fd5c /src/com/android/launcher3/FocusIndicatorView.java
parent49b39d667d3fa662352fdcc5278db97ab45de7cf (diff)
downloadandroid_packages_apps_Trebuchet-a39b82e2eba2580a210e34ce1a842589529348bf.tar.gz
android_packages_apps_Trebuchet-a39b82e2eba2580a210e34ce1a842589529348bf.tar.bz2
android_packages_apps_Trebuchet-a39b82e2eba2580a210e34ce1a842589529348bf.zip
Using left and top instead of getLocationInWindow for getting target view position
Change-Id: I1c295b8fd8be46ed9f0b12d7019572d9adc4af54
Diffstat (limited to 'src/com/android/launcher3/FocusIndicatorView.java')
-rw-r--r--src/com/android/launcher3/FocusIndicatorView.java51
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);
}
}