| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.transition; |
| 17 |
|
| 18 |
import android.view.View; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public abstract class VisibilityPropagation extends TransitionPropagation { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
private static final String PROPNAME_VISIBILITY = "android:visibilityPropagation:visibility"; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
private static final String PROPNAME_VIEW_CENTER = "android:visibilityPropagation:center"; |
| 36 |
|
| 37 |
private static final String[] VISIBILITY_PROPAGATION_VALUES = { |
| 38 |
PROPNAME_VISIBILITY, |
| 39 |
PROPNAME_VIEW_CENTER, |
| 40 |
}; |
| 41 |
|
| 42 |
@Override |
| 43 |
public void captureValues(TransitionValues values) { |
| 44 |
View view = values.view; |
| 45 |
Integer visibility = (Integer) values.values.get(Visibility.PROPNAME_VISIBILITY); |
| 46 |
if (visibility == null) { |
| 47 |
visibility = view.getVisibility(); |
| 48 |
} |
| 49 |
values.values.put(PROPNAME_VISIBILITY, visibility); |
| 50 |
int[] loc = new int[2]; |
| 51 |
view.getLocationOnScreen(loc); |
| 52 |
loc[0] += Math.round(view.getTranslationX()); |
| 53 |
loc[0] += view.getWidth() / 2; |
| 54 |
loc[1] += Math.round(view.getTranslationY()); |
| 55 |
loc[1] += view.getHeight() / 2; |
| 56 |
values.values.put(PROPNAME_VIEW_CENTER, loc); |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public String[] getPropagationProperties() { |
| 61 |
return VISIBILITY_PROPAGATION_VALUES; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public int getViewVisibility(TransitionValues values) { |
| 72 |
if (values == null) { |
| 73 |
return View.GONE; |
| 74 |
} |
| 75 |
Integer visibility = (Integer) values.values.get(PROPNAME_VISIBILITY); |
| 76 |
if (visibility == null) { |
| 77 |
return View.GONE; |
| 78 |
} |
| 79 |
return visibility; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
public int getViewX(TransitionValues values) { |
| 90 |
return getViewCoordinate(values, 0); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public int getViewY(TransitionValues values) { |
| 101 |
return getViewCoordinate(values, 1); |
| 102 |
} |
| 103 |
|
| 104 |
private static int getViewCoordinate(TransitionValues values, int coordinateIndex) { |
| 105 |
if (values == null) { |
| 106 |
return -1; |
| 107 |
} |
| 108 |
|
| 109 |
int[] coordinates = (int[]) values.values.get(PROPNAME_VIEW_CENTER); |
| 110 |
if (coordinates == null) { |
| 111 |
return -1; |
| 112 |
} |
| 113 |
|
| 114 |
return coordinates[coordinateIndex]; |
| 115 |
} |
| 116 |
} |