1919 */
2020
2121public class RecyclerViewSwipeDecorator {
22- private Context context ;
2322 private Canvas canvas ;
2423 private RecyclerView recyclerView ;
2524 private RecyclerView .ViewHolder viewHolder ;
@@ -69,18 +68,34 @@ private RecyclerViewSwipeDecorator() {
6968 * @param dY The amount of vertical displacement caused by user's action
7069 * @param actionState The type of interaction on the View. Is either ACTION_STATE_DRAG or ACTION_STATE_SWIPE.
7170 * @param isCurrentlyActive True if this view is currently being controlled by the user or false it is simply animating back to its original state
71+ *
72+ * @deprecated in RecyclerViewSwipeDecorator 1.2.2
7273 */
74+ @ Deprecated
7375 public RecyclerViewSwipeDecorator (Context context , Canvas canvas , RecyclerView recyclerView , RecyclerView .ViewHolder viewHolder , float dX , float dY , int actionState , boolean isCurrentlyActive ) {
76+ this (canvas , recyclerView , viewHolder , dX , dY , actionState , isCurrentlyActive );
77+ }
78+
79+ /**
80+ * Create a @RecyclerViewSwipeDecorator
81+ * @param canvas The canvas which RecyclerView is drawing its children
82+ * @param recyclerView The RecyclerView to which ItemTouchHelper is attached to
83+ * @param viewHolder The ViewHolder which is being interacted by the User or it was interacted and simply animating to its original position
84+ * @param dX The amount of horizontal displacement caused by user's action
85+ * @param dY The amount of vertical displacement caused by user's action
86+ * @param actionState The type of interaction on the View. Is either ACTION_STATE_DRAG or ACTION_STATE_SWIPE.
87+ * @param isCurrentlyActive True if this view is currently being controlled by the user or false it is simply animating back to its original state
88+ */
89+ public RecyclerViewSwipeDecorator (Canvas canvas , RecyclerView recyclerView , RecyclerView .ViewHolder viewHolder , float dX , float dY , int actionState , boolean isCurrentlyActive ) {
7490 this ();
75- this .context = context ;
7691 this .canvas = canvas ;
7792 this .recyclerView = recyclerView ;
7893 this .viewHolder = viewHolder ;
7994 this .dX = dX ;
8095 this .dY = dY ;
8196 this .actionState = actionState ;
8297 this .isCurrentlyActive = isCurrentlyActive ;
83- this .iconHorizontalMargin = (int )TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , 16 , context .getResources ().getDisplayMetrics ());
98+ this .iconHorizontalMargin = (int )TypedValue .applyDimension (TypedValue .COMPLEX_UNIT_DIP , 16 , recyclerView . getContext () .getResources ().getDisplayMetrics ());
8499 }
85100
86101 /**
@@ -209,7 +224,7 @@ public void setIconHorizontalMargin(int iconHorizontalMargin) {
209224 * @param iconHorizontalMargin the margin in the given unit
210225 */
211226 public void setIconHorizontalMargin (int unit , int iconHorizontalMargin ) {
212- this .iconHorizontalMargin = (int )TypedValue .applyDimension (unit , iconHorizontalMargin , context .getResources ().getDisplayMetrics ());
227+ this .iconHorizontalMargin = (int )TypedValue .applyDimension (unit , iconHorizontalMargin , recyclerView . getContext () .getResources ().getDisplayMetrics ());
213228 }
214229
215230 /**
@@ -263,7 +278,7 @@ public void decorate() {
263278
264279 int iconSize = 0 ;
265280 if ( swipeRightActionIconId != 0 && dX > iconHorizontalMargin ) {
266- Drawable icon = ContextCompat .getDrawable (context , swipeRightActionIconId );
281+ Drawable icon = ContextCompat .getDrawable (recyclerView . getContext () , swipeRightActionIconId );
267282 if ( icon != null ) {
268283 iconSize = icon .getIntrinsicHeight ();
269284 int halfIcon = iconSize / 2 ;
@@ -278,7 +293,7 @@ public void decorate() {
278293 if ( mSwipeRightText != null && mSwipeRightText .length () > 0 && dX > iconHorizontalMargin + iconSize ) {
279294 TextPaint textPaint = new TextPaint ();
280295 textPaint .setAntiAlias (true );
281- textPaint .setTextSize (TypedValue .applyDimension (mSwipeRightTextUnit , mSwipeRightTextSize , context .getResources ().getDisplayMetrics ()));
296+ textPaint .setTextSize (TypedValue .applyDimension (mSwipeRightTextUnit , mSwipeRightTextSize , recyclerView . getContext () .getResources ().getDisplayMetrics ()));
282297 textPaint .setColor (mSwipeRightTextColor );
283298 textPaint .setTypeface (mSwipeRightTypeface );
284299
@@ -297,7 +312,7 @@ public void decorate() {
297312 int iconSize = 0 ;
298313 int imgLeft = viewHolder .itemView .getRight ();
299314 if ( swipeLeftActionIconId != 0 && dX < - iconHorizontalMargin ) {
300- Drawable icon = ContextCompat .getDrawable (context , swipeLeftActionIconId );
315+ Drawable icon = ContextCompat .getDrawable (recyclerView . getContext () , swipeLeftActionIconId );
301316 if ( icon != null ) {
302317 iconSize = icon .getIntrinsicHeight ();
303318 int halfIcon = iconSize / 2 ;
@@ -313,7 +328,7 @@ public void decorate() {
313328 if ( mSwipeLeftText != null && mSwipeLeftText .length () > 0 && dX < - iconHorizontalMargin - iconSize ) {
314329 TextPaint textPaint = new TextPaint ();
315330 textPaint .setAntiAlias (true );
316- textPaint .setTextSize (TypedValue .applyDimension (mSwipeLeftTextUnit , mSwipeLeftTextSize , context .getResources ().getDisplayMetrics ()));
331+ textPaint .setTextSize (TypedValue .applyDimension (mSwipeLeftTextUnit , mSwipeLeftTextSize , recyclerView . getContext () .getResources ().getDisplayMetrics ()));
317332 textPaint .setColor (mSwipeLeftTextColor );
318333 textPaint .setTypeface (mSwipeLeftTypeface );
319334
@@ -343,10 +358,26 @@ public static class Builder {
343358 * @param dY The amount of vertical displacement caused by user's action
344359 * @param actionState The type of interaction on the View. Is either ACTION_STATE_DRAG or ACTION_STATE_SWIPE.
345360 * @param isCurrentlyActive True if this view is currently being controlled by the user or false it is simply animating back to its original state
361+ *
362+ * @deprecated in RecyclerViewSwipeDecorator 1.2.2
363+ */
364+ @ Deprecated
365+ public Builder (Context context , Canvas canvas , RecyclerView recyclerView , RecyclerView .ViewHolder viewHolder , float dX , float dY , int actionState , boolean isCurrentlyActive ) {
366+ this (canvas , recyclerView , viewHolder , dX , dY , actionState , isCurrentlyActive );
367+ }
368+
369+ /**
370+ * Create a builder for a RecyclerViewsSwipeDecorator
371+ * @param canvas The canvas which RecyclerView is drawing its children
372+ * @param recyclerView The RecyclerView to which ItemTouchHelper is attached to
373+ * @param viewHolder The ViewHolder which is being interacted by the User or it was interacted and simply animating to its original position
374+ * @param dX The amount of horizontal displacement caused by user's action
375+ * @param dY The amount of vertical displacement caused by user's action
376+ * @param actionState The type of interaction on the View. Is either ACTION_STATE_DRAG or ACTION_STATE_SWIPE.
377+ * @param isCurrentlyActive True if this view is currently being controlled by the user or false it is simply animating back to its original state
346378 */
347- public Builder (Context context , Canvas canvas , RecyclerView recyclerView , RecyclerView .ViewHolder viewHolder , float dX , float dY , int actionState , boolean isCurrentlyActive ) {
379+ public Builder (Canvas canvas , RecyclerView recyclerView , RecyclerView .ViewHolder viewHolder , float dX , float dY , int actionState , boolean isCurrentlyActive ) {
348380 mDecorator = new RecyclerViewSwipeDecorator (
349- context ,
350381 canvas ,
351382 recyclerView ,
352383 viewHolder ,
0 commit comments