From 9bc1d261b23438687d6b337bb30377623e7ca2cf Mon Sep 17 00:00:00 2001 From: Christian Meese Date: Sat, 21 May 2016 18:20:58 +0200 Subject: [PATCH 1/2] replace top and bottom shadow by background shadow 9patch --- .../draglinearlayout/DragLinearLayout.java | 29 +++++------------- .../drawable-hdpi/ab_solid_shadow_holo.9.png | Bin 192 -> 0 bytes .../drawable-mdpi/ab_solid_shadow_holo.9.png | Bin 168 -> 0 bytes .../drawable-xhdpi/ab_solid_shadow_holo.9.png | Bin 290 -> 0 bytes .../ab_solid_shadow_holo.9.png | Bin 1126 -> 0 bytes .../res/drawable-xxhdpi/shadow_light.9.png | Bin 0 -> 2904 bytes .../drawable/ab_solid_shadow_holo_flipped.xml | 9 ------ library/src/main/res/values/dimens.xml | 2 +- sample/src/main/res/layout/activity_demo.xml | 1 + sample/src/main/res/values/strings.xml | 2 +- 10 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 library/src/main/res/drawable-hdpi/ab_solid_shadow_holo.9.png delete mode 100644 library/src/main/res/drawable-mdpi/ab_solid_shadow_holo.9.png delete mode 100644 library/src/main/res/drawable-xhdpi/ab_solid_shadow_holo.9.png delete mode 100644 library/src/main/res/drawable-xxhdpi/ab_solid_shadow_holo.9.png create mode 100644 library/src/main/res/drawable-xxhdpi/shadow_light.9.png delete mode 100644 library/src/main/res/drawable/ab_solid_shadow_holo_flipped.xml diff --git a/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java b/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java index 168b32f..f75cae7 100644 --- a/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java +++ b/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java @@ -176,13 +176,9 @@ public void stopDetecting() { private int activePointerId = INVALID_POINTER_ID; /** - * The shadow to be drawn above the {@link #draggedItem}. + * The shadow to be drawn behind the {@link #draggedItem}. */ - private final Drawable dragTopShadowDrawable; - /** - * The shadow to be drawn below the {@link #draggedItem}. - */ - private final Drawable dragBottomShadowDrawable; + private final Drawable dragShadowDrawable; private final int dragShadowHeight; /** @@ -209,8 +205,7 @@ public DragLinearLayout(Context context, AttributeSet attrs) { slop = vc.getScaledTouchSlop(); final Resources resources = getResources(); - dragTopShadowDrawable = ContextCompat.getDrawable(context, R.drawable.ab_solid_shadow_holo_flipped); - dragBottomShadowDrawable = ContextCompat.getDrawable(context, R.drawable.ab_solid_shadow_holo); + dragShadowDrawable = ContextCompat.getDrawable(context, R.drawable.shadow_light); dragShadowHeight = resources.getDimensionPixelSize(R.dimen.downwards_drop_shadow_height); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DragLinearLayout, 0, 0); @@ -394,8 +389,7 @@ public void onAnimationUpdate(ValueAnimator animation) { draggedItem.setTotalOffset(((Float) animation.getAnimatedValue()).intValue()); final int shadowAlpha = (int) ((1 - animation.getAnimatedFraction()) * 255); - if (null != dragTopShadowDrawable) dragTopShadowDrawable.setAlpha(shadowAlpha); - dragBottomShadowDrawable.setAlpha(shadowAlpha); + if (null != dragShadowDrawable) dragShadowDrawable.setAlpha(shadowAlpha); invalidate(); } }); @@ -414,8 +408,7 @@ public void onAnimationEnd(Animator animation) { draggedItem.settleAnimation = null; draggedItem.stopDetecting(); - if (null != dragTopShadowDrawable) dragTopShadowDrawable.setAlpha(255); - dragBottomShadowDrawable.setAlpha(255); + if (null != dragShadowDrawable) dragShadowDrawable.setAlpha(255); // restore layout transition if (layoutTransition != null && getLayoutTransition() == null) { @@ -586,21 +579,15 @@ protected void dispatchDraw(@NonNull Canvas canvas) { if (draggedItem.detecting && (draggedItem.dragging || draggedItem.settling())) { canvas.save(); canvas.translate(0, draggedItem.totalDragOffset); - draggedItem.viewDrawable.draw(canvas); final int left = draggedItem.viewDrawable.getBounds().left; final int right = draggedItem.viewDrawable.getBounds().right; final int top = draggedItem.viewDrawable.getBounds().top; final int bottom = draggedItem.viewDrawable.getBounds().bottom; + dragShadowDrawable.setBounds(left - dragShadowHeight, top - dragShadowHeight, right + dragShadowHeight, bottom + dragShadowHeight); + dragShadowDrawable.draw(canvas); - dragBottomShadowDrawable.setBounds(left, bottom, right, bottom + dragShadowHeight); - dragBottomShadowDrawable.draw(canvas); - - if (null != dragTopShadowDrawable) { - dragTopShadowDrawable.setBounds(left, top - dragShadowHeight, right, top); - dragTopShadowDrawable.draw(canvas); - } - + draggedItem.viewDrawable.draw(canvas); canvas.restore(); } } diff --git a/library/src/main/res/drawable-hdpi/ab_solid_shadow_holo.9.png b/library/src/main/res/drawable-hdpi/ab_solid_shadow_holo.9.png deleted file mode 100644 index 2d59f354eed3ce3f0564fac30fc8ac278ed4a60f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 192 zcmeAS@N?(olHy`uVBq!ia0vp^QXtI11|(N{`J4k%?Vc`-^V;Vpy{TG>rs2jRbtPg`@kT=WR_nY-)l@u)2m z9YjR(TNrC5J8zlf@MOx-MX#^q?zd~tP;1Ok`WbQLQ#YGy{=Yfu7pEGW;JmVaai5Cr S@!LSF89ZJ6T-G@yGywoUXh2*5 diff --git a/library/src/main/res/drawable-xhdpi/ab_solid_shadow_holo.9.png b/library/src/main/res/drawable-xhdpi/ab_solid_shadow_holo.9.png deleted file mode 100644 index d0df29d8b3fef9f71cda9b7a0975c68dcfb05685..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 290 zcmV+-0p0$IP)(^RAa&-b-qmfdL= zKY^DZ_=R_1v^+>Y{!mW=MF!v|2#Q>Q>z_&4i6T94j-Y4q`P>I~g?cE`S~^QhBCU5$ z-8a`dJ38hrt)qwm8XJx0+%VAuW=z7Jg@`1pBAUrf#Ef=wZl|UqH7RO)u1OwK(@xK~ zuV&5*5lN0GQV~igR!o15*n1TfDTP6ilQ72>QBJOyK^2jQYHlAzlrUMuFCtAA$s$=K oi)4{qME3aCu~lSF#Q4a(0o}otDK%H_Q2+n{07*qoM6N<$f*T@rc>n+a diff --git a/library/src/main/res/drawable-xxhdpi/ab_solid_shadow_holo.9.png b/library/src/main/res/drawable-xxhdpi/ab_solid_shadow_holo.9.png deleted file mode 100644 index 8071886c0091c72feb665ff8213d9eeb4ee33f35..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1126 zcmbVLTWHfz7>-v&m^kL0p@+<;VUu&xrfK8q);5i++Bv(TMG?%Bvn_17n4H;eAl{}- z7`iDaC?d$-1VO}?$xw#id=mB|3gUzMB3=*?!3XhVYo`xm4+fI+|0n8id(75B z4|fc<74*SgJ#MhgyFgP}rUVuy8Yo+Rwl9|x>@2TL<=~oU!K?}CO|Wx86?5$%?RXf7 z91Q6&3PBWcC>)U_X$KG>f;<#>B!rM8hXolzP{>yrNcoQ7yst5aP-_Un-Tj zQkZkRZXU(s@qj}RLewJU57)`%=U8C2zOuQ1|Aq2SMPOVCXVjD!QP>LB_@A2b zG#EY@j(>)wdPOHN5a&mqD)Y;OZMrcYU5&)vb9d=lUCS!TLizQl8wb|3z_lxWif!+H zA39$5_F(qcv)eOAA8ah@YGd+?J-K`4!o~5JTU*8-P zC&nV?5}|SWLhZ=0_uJH|bL;jB^~2-mYiFibf$_{?DvdCy!>30#sPJrU%dYy#Z?`6Q z4!s{2>!;s*UB79`^3fsiNj&b2i|D?%7>a_zTk)W)eksL=i@O{>q;?!icUgf-o~Dm&vp{(_QtZy4Rj{eB=0d zeMriVRkeK&KYE+Sm+8$vpvNDkH~cXD-*|9<9-s&40eXNQpa z@tV^81I$Cb;P1h^fb#w1K46-kpMOozzr=3*0^dj)&w@Tie97}fOo1)K?`Hetj zp02kORd$*F5VfZW-8|0UkGdx{;X@YC&6Bt4fV2v|e;oET@ z{Ome&|I!m~a_wI;4tql9lAa~EEPq-GpYexs!e0ikA&aayQV=5WDvD@vhj#UNy209w zM>P66is;OV)Q{9!Td!)HY-A zw?`2TcW~=hfUd9`PaXPI)HXlC=z<)jP%J#*0&DvWf`8vaZ67FqNeC$6WU~E4xO`;d$Ab*!#K?2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zMKxwCHGn{sT+AoFxf4-OkxEOHii}jA0|n_*pxf@sD@afyQ5Ga-2(==9;;suLVkfWz zT;V~Sq8w|nE%B{FWrD&{g ziV;Pttm!6EF1~rIP-HAEdup4}oM;p=YiG_kqeqSx@;es>7y*Ht6K$JO)xsMt?-a_3 zRsmBU@DTKoUH2hq)D&g3#@m8kERt%<9coM7tplRD@<|MpH}rl&A%PVlmYMk~S9*fS z*x~H&5j1tEtvqw$#SZF8ZtuF$aZ7xNi<_cGg%f(3aF@D+Vnmgq>jtgw6;zl>?!CP{ zlq&AMy*R-B_Mr!;9yO>h-yT%@8nx@^K_9v69-s&40s3F<+`$%H`U+M>{KGO!OKfDL(f29o6{~Q}A{@poH;{&^q1Tkc4Y}gL3+-s%$AGylRy|QMT%HWp+VNkZ?j!h$Mwc z^8<*RQgH!twRCyB05PRyl2SlBn@AW?LkIefzwQSj^)6fxqe~Y60000 - - - \ No newline at end of file diff --git a/library/src/main/res/values/dimens.xml b/library/src/main/res/values/dimens.xml index ecb3ceb..fdd321f 100644 --- a/library/src/main/res/values/dimens.xml +++ b/library/src/main/res/values/dimens.xml @@ -1,4 +1,4 @@ - 16dp + 12dp \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_demo.xml b/sample/src/main/res/layout/activity_demo.xml index 9eb7908..b99cdf6 100644 --- a/sample/src/main/res/layout/activity_demo.xml +++ b/sample/src/main/res/layout/activity_demo.xml @@ -17,6 +17,7 @@ android:text="@string/list_item_1" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_margin="10dp" style="@style/SpaciousListItem" /> DragLinearLayout Demo Simple linear layout - Drag me! Drop me! + Drag me! Drop me! I have a margin. Swap with me! Swap with me! I\'m quite sensitive\nabout my height. I heard that one of us is a Button! From 7e301e65d488e65ffe25d86ab4623111ce81f091 Mon Sep 17 00:00:00 2001 From: Christian Meese Date: Sun, 22 May 2016 14:05:25 +0200 Subject: [PATCH 2/2] fix minor issues --- .../com/jmedeisis/draglinearlayout/DragLinearLayout.java | 7 ++++--- library/src/main/res/values/dimens.xml | 2 +- sample/src/main/res/layout/activity_demo.xml | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java b/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java index f75cae7..25b7ba1 100644 --- a/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java +++ b/library/src/main/java/com/jmedeisis/draglinearlayout/DragLinearLayout.java @@ -179,7 +179,7 @@ public void stopDetecting() { * The shadow to be drawn behind the {@link #draggedItem}. */ private final Drawable dragShadowDrawable; - private final int dragShadowHeight; + private final int dragShadowMargin; /** * See {@link #setContainerScrollView(android.widget.ScrollView)}. @@ -206,7 +206,7 @@ public DragLinearLayout(Context context, AttributeSet attrs) { final Resources resources = getResources(); dragShadowDrawable = ContextCompat.getDrawable(context, R.drawable.shadow_light); - dragShadowHeight = resources.getDimensionPixelSize(R.dimen.downwards_drop_shadow_height); + dragShadowMargin = resources.getDimensionPixelSize(R.dimen.drop_shadow_margin); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DragLinearLayout, 0, 0); try { @@ -584,7 +584,8 @@ protected void dispatchDraw(@NonNull Canvas canvas) { final int right = draggedItem.viewDrawable.getBounds().right; final int top = draggedItem.viewDrawable.getBounds().top; final int bottom = draggedItem.viewDrawable.getBounds().bottom; - dragShadowDrawable.setBounds(left - dragShadowHeight, top - dragShadowHeight, right + dragShadowHeight, bottom + dragShadowHeight); + dragShadowDrawable.setBounds(left - dragShadowMargin, top - dragShadowMargin, right + dragShadowMargin, bottom + dragShadowMargin); + dragShadowDrawable.setAlpha(75); dragShadowDrawable.draw(canvas); draggedItem.viewDrawable.draw(canvas); diff --git a/library/src/main/res/values/dimens.xml b/library/src/main/res/values/dimens.xml index fdd321f..300d8bd 100644 --- a/library/src/main/res/values/dimens.xml +++ b/library/src/main/res/values/dimens.xml @@ -1,4 +1,4 @@ - 12dp + 12dp \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_demo.xml b/sample/src/main/res/layout/activity_demo.xml index b99cdf6..98a38fc 100644 --- a/sample/src/main/res/layout/activity_demo.xml +++ b/sample/src/main/res/layout/activity_demo.xml @@ -17,7 +17,7 @@ android:text="@string/list_item_1" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_margin="10dp" + android:layout_margin="8dp" style="@style/SpaciousListItem" />