forked from janishar/PlaceHolderView
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request janishar#43 from janishar/swipe-directional-place-…
…holder-view Swipe directional place holder view
- Loading branch information
Showing
18 changed files
with
1,250 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
app/src/main/java/com/mindorks/test/ActivitySwipeDirectional.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.mindorks.test; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
|
||
import com.mindorks.butterknifelite.ButterKnifeLite; | ||
import com.mindorks.butterknifelite.annotations.BindView; | ||
import com.mindorks.butterknifelite.annotations.OnClick; | ||
import com.mindorks.placeholderview.SwipeDecor; | ||
import com.mindorks.placeholderview.SwipeDirectionalView; | ||
import com.mindorks.placeholderview.listeners.ItemRemovedListener; | ||
import com.mindorks.test.swipe.TinderDirectionalCard; | ||
|
||
/** | ||
* Created by janisharali on 09/08/17. | ||
*/ | ||
|
||
public class ActivitySwipeDirectional extends AppCompatActivity { | ||
|
||
private static final String TAG = "ActivityTinder"; | ||
|
||
@BindView(R.id.swipeView) | ||
private SwipeDirectionalView mSwipeView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_tinder_directional_swipe); | ||
ButterKnifeLite.bind(this); | ||
|
||
} | ||
|
||
@Override | ||
protected void onPostCreate(@Nullable Bundle savedInstanceState) { | ||
super.onPostCreate(savedInstanceState); | ||
mSwipeView.addItemRemoveListener(new ItemRemovedListener() { | ||
|
||
@Override | ||
public void onItemRemoved(int count) { | ||
Log.d(TAG, "onItemRemoved: " + count); | ||
if (count == 0) { | ||
mSwipeView.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()); | ||
} | ||
} | ||
}); | ||
mSwipeView.getBuilder() | ||
.setDisplayViewCount(3) | ||
.setIsUndoEnabled(true) | ||
.setSwipeVerticalThreshold(Utils.dpToPx(50)) | ||
.setSwipeHorizontalThreshold(Utils.dpToPx(50)) | ||
.setSwipeDecor(new SwipeDecor() | ||
.setPaddingTop(20) | ||
.setRelativeScale(0.01f) | ||
.setSwipeInMsgLayoutId(R.layout.tinder_swipe_in_msg_view) | ||
.setSwipeOutMsgLayoutId(R.layout.tinder_swipe_out_msg_view)); | ||
|
||
mSwipeView.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()) | ||
.addView(new TinderDirectionalCard()); | ||
} | ||
|
||
@OnClick(R.id.rejectBtn) | ||
private void onRejectClick() { | ||
mSwipeView.doSwipe(false); | ||
} | ||
|
||
@OnClick(R.id.acceptBtn) | ||
private void onAcceptClick() { | ||
mSwipeView.doSwipe(true); | ||
} | ||
|
||
@OnClick(R.id.undoBtn) | ||
private void onUndoClick() { | ||
mSwipeView.undoLastSwipe(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
app/src/main/java/com/mindorks/test/swipe/TinderDirectionalCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.mindorks.test.swipe; | ||
|
||
import android.util.Log; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.mindorks.placeholderview.SwipeDirection; | ||
import com.mindorks.placeholderview.annotations.Click; | ||
import com.mindorks.placeholderview.annotations.Layout; | ||
import com.mindorks.placeholderview.annotations.NonReusable; | ||
import com.mindorks.placeholderview.annotations.Resolve; | ||
import com.mindorks.placeholderview.annotations.View; | ||
import com.mindorks.placeholderview.annotations.swipe.SwipeCancelState; | ||
import com.mindorks.placeholderview.annotations.swipe.SwipeInDirectional; | ||
import com.mindorks.placeholderview.annotations.swipe.SwipeOutDirectional; | ||
import com.mindorks.placeholderview.annotations.swipe.SwipeTouch; | ||
import com.mindorks.placeholderview.annotations.swipe.SwipingDirection; | ||
import com.mindorks.test.R; | ||
|
||
/** | ||
* Created by janisharali on 09/08/17. | ||
*/ | ||
|
||
@NonReusable | ||
@Layout(R.layout.tinder_card_view) | ||
public class TinderDirectionalCard { | ||
|
||
private static int count; | ||
|
||
@View(R.id.profileImageView) | ||
private ImageView profileImageView; | ||
|
||
@View(R.id.nameAgeTxt) | ||
private TextView nameAgeTxt; | ||
|
||
@View(R.id.locationNameTxt) | ||
private TextView locationNameTxt; | ||
|
||
@Click(R.id.profileImageView) | ||
private void onClick() { | ||
Log.d("DEBUG", "profileImageView"); | ||
} | ||
|
||
@Resolve | ||
private void onResolve() { | ||
nameAgeTxt.setText("Name " + count++); | ||
} | ||
|
||
@SwipeOutDirectional | ||
private void onSwipeOutDirectional(SwipeDirection direction) { | ||
Log.d("DEBUG", "SwipeOutDirectional " + direction.name()); | ||
} | ||
|
||
@SwipeCancelState | ||
private void onSwipeCancelState() { | ||
Log.d("DEBUG", "onSwipeCancelState"); | ||
} | ||
|
||
@SwipeInDirectional | ||
private void onSwipeInDirectional(SwipeDirection direction) { | ||
Log.d("DEBUG", "SwipeInDirectional " + direction.name()); | ||
} | ||
|
||
@SwipingDirection | ||
private void onSwipingDirection(SwipeDirection direction) { | ||
Log.d("DEBUG", "SwipingDirection " + direction.name()); | ||
} | ||
|
||
@SwipeTouch | ||
private void onSwipeTouch(float xStart, float yStart, float xCurrent, float yCurrent) { | ||
Log.d("DEBUG", "onSwipeTouch " | ||
+ " xStart : " + xStart | ||
+ " yStart : " + yStart | ||
+ " xCurrent : " + xCurrent | ||
+ " yCurrent : " + yCurrent | ||
+ " distance : " | ||
+ Math.sqrt(Math.pow(xCurrent - xStart, 2) + (Math.pow(yCurrent - yStart, 2))) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/res/layout/activity_tinder_directional_swipe.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout xmlns:android="http:https://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/grey" | ||
android:orientation="vertical"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="80dp" | ||
android:layout_gravity="bottom" | ||
android:gravity="center" | ||
android:orientation="horizontal"> | ||
|
||
<ImageButton | ||
android:id="@+id/rejectBtn" | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:background="@drawable/ic_cancel" /> | ||
|
||
<ImageButton | ||
android:id="@+id/acceptBtn" | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:layout_marginLeft="30dp" | ||
android:background="@drawable/ic_heart" /> | ||
|
||
<ImageButton | ||
android:id="@+id/undoBtn" | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:layout_marginLeft="30dp" | ||
android:background="@drawable/ic_book_black_18dp" /> | ||
</LinearLayout> | ||
|
||
<com.mindorks.placeholderview.SwipeDirectionalView | ||
android:id="@+id/swipeView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</FrameLayout> |
27 changes: 27 additions & 0 deletions
27
placeholderview/src/main/java/com/mindorks/placeholderview/SwipeDirection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.mindorks.placeholderview; | ||
|
||
/** | ||
* Created by janisharali on 09/08/17. | ||
*/ | ||
|
||
public enum SwipeDirection { | ||
|
||
TOP(0), | ||
LEFT(1), | ||
BOTTOM(2), | ||
RIGHT(3), | ||
RIGHT_TOP(4), | ||
RIGHT_BOTTOM(5), | ||
LEFT_TOP(6), | ||
LEFT_BOTTOM(7); | ||
|
||
private final int mDirection; | ||
|
||
SwipeDirection(int direction) { | ||
mDirection = direction; | ||
} | ||
|
||
public int getDirection() { | ||
return mDirection; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
placeholderview/src/main/java/com/mindorks/placeholderview/SwipeDirectionalView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.mindorks.placeholderview; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
import android.os.Build; | ||
import android.util.AttributeSet; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* Created by janisharali on 09/08/17. | ||
*/ | ||
|
||
public class SwipeDirectionalView extends SwipePlaceHolderView { | ||
|
||
private ArrayList<SwipeDirectionalViewBinder | ||
<Object, FrameView, SwipeDirectionalOption, SwipeDecor>> mSwipeViewBinderList; | ||
|
||
public SwipeDirectionalView(Context context) { | ||
super(context); | ||
mSwipeViewBinderList = new ArrayList<>(); | ||
setupView(mSwipeViewBinderList, | ||
new SwipeDirectionalViewBuilder<>(this), | ||
new SwipeDirectionalOption(), | ||
new SwipeDecor()); | ||
} | ||
|
||
public SwipeDirectionalView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
mSwipeViewBinderList = new ArrayList<>(); | ||
setupView(mSwipeViewBinderList, | ||
new SwipeDirectionalViewBuilder<>(this), | ||
new SwipeDirectionalOption(), | ||
new SwipeDecor()); | ||
} | ||
|
||
public SwipeDirectionalView(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
mSwipeViewBinderList = new ArrayList<>(); | ||
setupView(mSwipeViewBinderList, | ||
new SwipeDirectionalViewBuilder<>(this), | ||
new SwipeDirectionalOption(), | ||
new SwipeDecor()); | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
public SwipeDirectionalView( | ||
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
mSwipeViewBinderList = new ArrayList<>(); | ||
setupView(mSwipeViewBinderList, | ||
new SwipeDirectionalViewBuilder<>(this), | ||
new SwipeDirectionalOption(), | ||
new SwipeDecor()); | ||
} | ||
|
||
@Override | ||
protected <T, | ||
F extends FrameView, | ||
P extends SwipeOption, | ||
Q extends SwipeDecor, | ||
V extends SwipeViewBinder<T, F, P, Q>> | ||
V getViewBinder(T resolver) { | ||
return (V) new SwipeDirectionalViewBinder<T, F, SwipeDirectionalOption, Q>(resolver); | ||
} | ||
|
||
protected void setSwipeHorizontalThreshold(int threshold) { | ||
((SwipeDirectionalOption) getSwipeOption()).setSwipeHorizontalThreshold(threshold); | ||
} | ||
|
||
protected void setSwipeVerticalThreshold(int threshold) { | ||
((SwipeDirectionalOption) getSwipeOption()).setSwipeVerticalThreshold(threshold); | ||
} | ||
|
||
@Override | ||
public SwipeDirectionalViewBuilder<SwipeDirectionalView> getBuilder() { | ||
return super.<SwipeDirectionalView, SwipeDirectionalViewBuilder<SwipeDirectionalView>>getBuilder(); | ||
} | ||
|
||
protected static class SwipeDirectionalOption extends SwipeOption { | ||
|
||
private int mSwipeHorizontalThreshold; | ||
private int mSwipeVerticalThreshold; | ||
|
||
public SwipeDirectionalOption() { | ||
super(); | ||
mSwipeHorizontalThreshold = Utils.dpToPx(30); | ||
mSwipeVerticalThreshold = Utils.dpToPx(30); | ||
} | ||
|
||
protected int getSwipeHorizontalThreshold() { | ||
return mSwipeHorizontalThreshold; | ||
} | ||
|
||
protected void setSwipeHorizontalThreshold(int threshold) { | ||
this.mSwipeHorizontalThreshold = threshold; | ||
} | ||
|
||
protected int getSwipeVerticalThreshold() { | ||
return mSwipeVerticalThreshold; | ||
} | ||
|
||
protected void setSwipeVerticalThreshold(int threshold) { | ||
this.mSwipeVerticalThreshold = threshold; | ||
} | ||
} | ||
} |
Oops, something went wrong.