Skip to content

Commit

Permalink
Complete helper class for delegating to native when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Jun 24, 2012
1 parent c9f3ff9 commit cfcee0b
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 22 deletions.
220 changes: 214 additions & 6 deletions library/src/com/nineoldandroids/view/ViewHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,45 @@
public final class ViewHelper {
private ViewHelper() {}

public static void setPivotX(View view, float pivotX) {
public static float getAlpha(View view) {
return NEEDS_PROXY ? wrap(view).getAlpha() : GetAlpha.invoke(view);
}

private static final class GetAlpha {
static float invoke(View view) {
return view.getAlpha();
}
}

public static void setAlpha(View view, float alpha) {
if (NEEDS_PROXY) {
wrap(view).setPivotX(pivotX);
wrap(view).setAlpha(alpha);
} else {
SetPivotX.invoke(view, pivotX);
SetAlpha.invoke(view, alpha);
}
}

public static void setPivotY(View view, float pivotY) {
private static final class SetAlpha {
static void invoke(View view, float alpha) {
view.setAlpha(alpha);
}
}

public static float getPivotX(View view) {
return NEEDS_PROXY ? wrap(view).getPivotX() : GetPivotX.invoke(view);
}

private static final class GetPivotX {
static float invoke(View view) {
return view.getPivotX();
}
}

public static void setPivotX(View view, float pivotX) {
if (NEEDS_PROXY) {
wrap(view).setPivotY(pivotY);
wrap(view).setPivotX(pivotX);
} else {
SetPivotY.invoke(view, pivotY);
SetPivotX.invoke(view, pivotX);
}
}

Expand All @@ -30,9 +56,191 @@ static void invoke(View view, float pivotX) {
}
}

public static float getPivotY(View view) {
return NEEDS_PROXY ? wrap(view).getPivotY() : GetPivotY.invoke(view);
}

private static final class GetPivotY {
static float invoke(View view) {
return view.getPivotY();
}
}

public static void setPivotY(View view, float pivotY) {
if (NEEDS_PROXY) {
wrap(view).setPivotY(pivotY);
} else {
SetPivotY.invoke(view, pivotY);
}
}

private static final class SetPivotY {
static void invoke(View view, float pivotY) {
view.setPivotY(pivotY);
}
}

public static float getRotation(View view) {
return NEEDS_PROXY ? wrap(view).getRotation() : GetRotation.invoke(view);
}

private static final class GetRotation {
static float invoke(View view) {
return view.getRotation();
}
}

public static void setRotation(View view, float rotation) {
if (NEEDS_PROXY) {
wrap(view).setRotation(rotation);
} else {
SetRotation.invoke(view, rotation);
}
}

private static final class SetRotation {
static void invoke(View view, float rotation) {
view.setRotation(rotation);
}
}

public static void setRotationX(View view, float rotationX) {
if (NEEDS_PROXY) {
wrap(view).setRotationX(rotationX);
} else {
SetRotationX.invoke(view, rotationX);
}
}

private static final class SetRotationX {
static void invoke(View view, float rotationX) {
view.setRotationX(rotationX);
}
}

public static void setRotationY(View view, float rotationY) {
if (NEEDS_PROXY) {
wrap(view).setRotationY(rotationY);
} else {
SetRotationY.invoke(view, rotationY);
}
}

private static final class SetRotationY {
static void invoke(View view, float rotationY) {
view.setRotationY(rotationY);
}
}

public static void setScaleX(View view, float scaleX) {
if (NEEDS_PROXY) {
wrap(view).setScaleX(scaleX);
} else {
SetScaleX.invoke(view, scaleX);
}
}

private static final class SetScaleX {
static void invoke(View view, float scaleX) {
view.setScaleX(scaleX);
}
}

public static void setScaleY(View view, float scaleY) {
if (NEEDS_PROXY) {
wrap(view).setScaleY(scaleY);
} else {
SetScaleY.invoke(view, scaleY);
}
}

private static final class SetScaleY {
static void invoke(View view, float scaleY) {
view.setScaleY(scaleY);
}
}

public static void setScrollX(View view, int scrollX) {
if (NEEDS_PROXY) {
wrap(view).setScrollX(scrollX);
} else {
SetScrollX.invoke(view, scrollX);
}
}

private static final class SetScrollX {
static void invoke(View view, int scrollX) {
view.setScrollX(scrollX);
}
}

public static void setScrollY(View view, int scrollY) {
if (NEEDS_PROXY) {
wrap(view).setScrollY(scrollY);
} else {
SetScrollY.invoke(view, scrollY);
}
}

private static final class SetScrollY {
static void invoke(View view, int scrollY) {
view.setScrollY(scrollY);
}
}

public static void setTranslationX(View view, float translationX) {
if (NEEDS_PROXY) {
wrap(view).setTranslationX(translationX);
} else {
SetTranslationX.invoke(view, translationX);
}
}

private static final class SetTranslationX {
static void invoke(View view, float translationX) {
view.setTranslationX(translationX);
}
}

public static void setTranslationY(View view, float translationY) {
if (NEEDS_PROXY) {
wrap(view).setTranslationY(translationY);
} else {
SetTranslationY.invoke(view, translationY);
}
}

private static final class SetTranslationY {
static void invoke(View view, float translationY) {
view.setTranslationY(translationY);
}
}

public static void setX(View view, float x) {
if (NEEDS_PROXY) {
wrap(view).setX(x);
} else {
SetX.invoke(view, x);
}
}

private static final class SetX {
static void invoke(View view, float x) {
view.setX(x);
}
}

public static void setY(View view, float y) {
if (NEEDS_PROXY) {
wrap(view).setY(y);
} else {
SetY.invoke(view, y);
}
}

private static final class SetY {
static void invoke(View view, float y) {
view.setY(y);
}
}
}
16 changes: 0 additions & 16 deletions library/src/com/nineoldandroids/view/animation/AnimatorProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,6 @@ public void setY(float y) {
}
}

public float getScale() {
// this is a pseudo-property for the frequent case where
// scaleX and scaleY are being updated synchronously
return Math.max(mScaleX, mScaleY);
}
public void setScale(float scale) {
// this is a pseudo-property for the frequent case where
// scaleX and scaleY are being updated synchronously
if (mScaleX != scale || mScaleY != scale) {
prepareForUpdate();
mScaleX = scale;
mScaleY = scale;
invalidateAfterUpdate();
}
}

private void prepareForUpdate() {
View view = mView.get();
if (view != null) {
Expand Down

0 comments on commit cfcee0b

Please sign in to comment.