Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced top and bottom shadow by background shadow 9patch #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,10 @@ 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 int dragShadowHeight;
private final Drawable dragShadowDrawable;
private final int dragShadowMargin;

/**
* See {@link #setContainerScrollView(android.widget.ScrollView)}.
Expand All @@ -209,9 +205,8 @@ 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);
dragShadowHeight = resources.getDimensionPixelSize(R.dimen.downwards_drop_shadow_height);
dragShadowDrawable = ContextCompat.getDrawable(context, R.drawable.shadow_light);
dragShadowMargin = resources.getDimensionPixelSize(R.dimen.drop_shadow_margin);

TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DragLinearLayout, 0, 0);
try {
Expand Down Expand Up @@ -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();
}
});
Expand All @@ -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) {
Expand Down Expand Up @@ -586,21 +579,16 @@ 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 - dragShadowMargin, top - dragShadowMargin, right + dragShadowMargin, bottom + dragShadowMargin);
dragShadowDrawable.setAlpha(75);
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();
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

2 changes: 1 addition & 1 deletion library/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="downwards_drop_shadow_height">16dp</dimen>
<dimen name="drop_shadow_margin">12dp</dimen>
</resources>
1 change: 1 addition & 0 deletions sample/src/main/res/layout/activity_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
android:text="@string/list_item_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
style="@style/SpaciousListItem" />

<TextView
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<string name="app_name">DragLinearLayout Demo</string>
<string name="list_title">Simple linear layout</string>
<string name="list_item_1">Drag me! Drop me!</string>
<string name="list_item_1">Drag me! Drop me! I have a margin.</string>
<string name="list_item_2">Swap with me! Swap with me!</string>
<string name="list_item_3">I\'m quite sensitive\nabout my height.</string>
<string name="list_item_4">I heard that one of us is a Button!</string>
Expand Down