Merge "Slide supports Gravity.START and Gravity.END." into lmp-mr1-dev

This commit is contained in:
George Mount
2014-11-20 15:23:52 +00:00
committed by Android (Google) Code Review
3 changed files with 59 additions and 7 deletions

View File

@@ -44,8 +44,8 @@ public class SidePropagation extends VisibilityPropagation {
* farther from the edge. The default is {@link Gravity#BOTTOM}.
*
* @param side The side that is used to calculate the transition propagation. Must be one of
* {@link Gravity#LEFT}, {@link Gravity#TOP}, {@link Gravity#RIGHT}, or
* {@link Gravity#BOTTOM}.
* {@link Gravity#LEFT}, {@link Gravity#TOP}, {@link Gravity#RIGHT},
* {@link Gravity#BOTTOM}, {@link Gravity#START}, or {@link Gravity#END}.
*/
public void setSide(int side) {
mSide = side;
@@ -106,7 +106,7 @@ public class SidePropagation extends VisibilityPropagation {
epicenterY = (top + bottom) / 2;
}
float distance = distance(viewCenterX, viewCenterY, epicenterX, epicenterY,
float distance = distance(sceneRoot, viewCenterX, viewCenterY, epicenterX, epicenterY,
left, top, right, bottom);
float maxDistance = getMaxDistance(sceneRoot);
float distanceFraction = distance/maxDistance;
@@ -119,10 +119,20 @@ public class SidePropagation extends VisibilityPropagation {
return Math.round(duration * directionMultiplier / mPropagationSpeed * distanceFraction);
}
private int distance(int viewX, int viewY, int epicenterX, int epicenterY,
private int distance(View sceneRoot, int viewX, int viewY, int epicenterX, int epicenterY,
int left, int top, int right, int bottom) {
final int side;
if (mSide == Gravity.START) {
final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
side = isRtl ? Gravity.RIGHT : Gravity.LEFT;
} else if (mSide == Gravity.END) {
final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
side = isRtl ? Gravity.LEFT : Gravity.RIGHT;
} else {
side = mSide;
}
int distance = 0;
switch (mSide) {
switch (side) {
case Gravity.LEFT:
distance = right - viewX + Math.abs(epicenterY - viewY);
break;
@@ -143,6 +153,8 @@ public class SidePropagation extends VisibilityPropagation {
switch (mSide) {
case Gravity.LEFT:
case Gravity.RIGHT:
case Gravity.START:
case Gravity.END:
return sceneRoot.getWidth();
default:
return sceneRoot.getHeight();

View File

@@ -76,6 +76,20 @@ public class Slide extends Visibility {
}
};
private static final CalculateSlide sCalculateStart = new CalculateSlideHorizontal() {
@Override
public float getGoneX(ViewGroup sceneRoot, View view) {
final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
final float x;
if (isRtl) {
x = view.getTranslationX() + sceneRoot.getWidth();
} else {
x = view.getTranslationX() - sceneRoot.getWidth();
}
return x;
}
};
private static final CalculateSlide sCalculateTop = new CalculateSlideVertical() {
@Override
public float getGoneY(ViewGroup sceneRoot, View view) {
@@ -90,6 +104,20 @@ public class Slide extends Visibility {
}
};
private static final CalculateSlide sCalculateEnd = new CalculateSlideHorizontal() {
@Override
public float getGoneX(ViewGroup sceneRoot, View view) {
final boolean isRtl = sceneRoot.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
final float x;
if (isRtl) {
x = view.getTranslationX() - sceneRoot.getWidth();
} else {
x = view.getTranslationX() + sceneRoot.getWidth();
}
return x;
}
};
private static final CalculateSlide sCalculateBottom = new CalculateSlideVertical() {
@Override
public float getGoneY(ViewGroup sceneRoot, View view) {
@@ -144,7 +172,8 @@ public class Slide extends Visibility {
*
* @param slideEdge The edge of the scene to use for Views appearing and disappearing. One of
* {@link android.view.Gravity#LEFT}, {@link android.view.Gravity#TOP},
* {@link android.view.Gravity#RIGHT}, {@link android.view.Gravity#BOTTOM}.
* {@link android.view.Gravity#RIGHT}, {@link android.view.Gravity#BOTTOM},
* {@link android.view.Gravity#START}, {@link android.view.Gravity#END}.
* @attr ref android.R.styleable#Slide_slideEdge
*/
public void setSlideEdge(int slideEdge) {
@@ -161,6 +190,12 @@ public class Slide extends Visibility {
case Gravity.BOTTOM:
mSlideCalculator = sCalculateBottom;
break;
case Gravity.START:
mSlideCalculator = sCalculateStart;
break;
case Gravity.END:
mSlideCalculator = sCalculateEnd;
break;
default:
throw new IllegalArgumentException("Invalid slide direction");
}
@@ -175,7 +210,8 @@ public class Slide extends Visibility {
*
* @return the edge of the scene to use for Views appearing and disappearing. One of
* {@link android.view.Gravity#LEFT}, {@link android.view.Gravity#TOP},
* {@link android.view.Gravity#RIGHT}, {@link android.view.Gravity#BOTTOM}.
* {@link android.view.Gravity#RIGHT}, {@link android.view.Gravity#BOTTOM},
* {@link android.view.Gravity#START}, {@link android.view.Gravity#END}.
* @attr ref android.R.styleable#Slide_slideEdge
*/
public int getSlideEdge() {

View File

@@ -5665,6 +5665,10 @@
<enum name="right" value="0x05" />
<!-- Slide to and from the bottom edge of the Scene. -->
<enum name="bottom" value="0x50" />
<!-- Slide to and from the x-axis position at the start of the Scene root. -->
<enum name="start" value="0x00800003"/>
<!-- Slide to and from the x-axis position at the end of the Scene root. -->
<enum name="end" value="0x00800005"/>
</attr>
</declare-styleable>