@@ -34,22 +34,17 @@ public abstract class CardStackAdapter implements View.OnTouchListener, View.OnC
3434 public static final int DECELERATION_FACTOR = 2 ;
3535
3636 public static final int INVALID_CARD_POSITION = -1 ;
37-
37+ private final int mScreenHeight ;
38+ private final int dp30 ;
3839 // Settings for the adapter from layout
3940 private float mCardGapBottom ;
4041 private float mCardGap ;
4142 private int mParallaxScale ;
4243 private boolean mParallaxEnabled ;
4344 private boolean mShowInitAnimation ;
44-
45- private final int mScreenHeight ;
4645 private int fullCardHeight ;
47-
4846 private View [] mCardViews ;
49-
5047 private float dp8 ;
51- private final int dp30 ;
52-
5348 private CardStackLayout mParent ;
5449
5550 private boolean mScreenTouchable = false ;
@@ -61,6 +56,16 @@ public abstract class CardStackAdapter implements View.OnTouchListener, View.OnC
6156 private int mParentPaddingTop = 0 ;
6257 private int mCardPaddingInternal = 0 ;
6358
59+ public CardStackAdapter (Context context ) {
60+ Resources resources = context .getResources ();
61+
62+ DisplayMetrics dm = Resources .getSystem ().getDisplayMetrics ();
63+ mScreenHeight = dm .heightPixels ;
64+ dp30 = (int ) resources .getDimension (R .dimen .dp30 );
65+ scaleFactorForElasticEffect = (int ) resources .getDimension (R .dimen .dp8 );
66+ dp8 = (int ) resources .getDimension (R .dimen .dp8 );
67+ }
68+
6469 /**
6570 * Defines and initializes the view to be shown in the {@link CardStackLayout}
6671 * Provides two parameters to the sub-class namely -
@@ -79,10 +84,6 @@ public abstract class CardStackAdapter implements View.OnTouchListener, View.OnC
7984 */
8085 public abstract int getCount ();
8186
82- private void setScreenTouchable (boolean screenTouchable ) {
83- this .mScreenTouchable = screenTouchable ;
84- }
85-
8687 /**
8788 * Returns true if no animation is in progress currently. Can be used to disable any events
8889 * if they are not allowed during an animation. Returns false if an animation is in progress.
@@ -93,16 +94,8 @@ public boolean isScreenTouchable() {
9394 return mScreenTouchable ;
9495 }
9596
96- public CardStackAdapter (Context context ) {
97- Resources resources = context .getResources ();
98-
99- DisplayMetrics dm = Resources .getSystem ().getDisplayMetrics ();
100- mScreenHeight = dm .heightPixels ;
101- dp30 = (int ) resources .getDimension (R .dimen .dp30 );
102- scaleFactorForElasticEffect = (int ) resources .getDimension (R .dimen .dp8 );
103- dp8 = (int ) resources .getDimension (R .dimen .dp8 );
104-
105- mCardViews = new View [getCount ()];
97+ private void setScreenTouchable (boolean screenTouchable ) {
98+ this .mScreenTouchable = screenTouchable ;
10699 }
107100
108101 void addView (final int position ) {
@@ -266,6 +259,7 @@ private void moveCards(int positionOfCardToMove, float diff) {
266259 */
267260 void setAdapterParams (CardStackLayout cardStackLayout ) {
268261 mParent = cardStackLayout ;
262+ mCardViews = new View [getCount ()];
269263 mCardGapBottom = cardStackLayout .getCardGapBottom ();
270264 mCardGap = cardStackLayout .getCardGap ();
271265 mParallaxScale = cardStackLayout .getParallaxScale ();
0 commit comments