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

Feature/2.0/swipe directions #182

Open
wants to merge 1 commit into
base: feature/2.0/dev
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
6 changes: 3 additions & 3 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ android {
dependencies {
compile project(':library')

compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:support-v4:25.0.1'

compile 'com.squareup.moshi:moshi:1.3.1'
compile 'com.squareup.okio:okio:1.11.0'
Expand Down
37 changes: 28 additions & 9 deletions example/src/main/java/com/lorentzos/swipecards/AsyncActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import static io.reactivex.schedulers.Schedulers.newThread;

/**
* Activity with example of a network call to obtain the data and load the avatars
* in the image views.
* Activity with example of a network call to obtain the data and load the avatars in the image
* views.
*/
public class AsyncActivity extends AppCompatActivity {

Expand Down Expand Up @@ -87,8 +87,8 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
// Optionally add an onScrollListener
flingContainer.setOnScrollListener(new OnScrollListener() {
@Override
public void onScroll(View view, float scrollProgressPercent) {
Log.i("MyActivity", "onScroll " + scrollProgressPercent);
public void onScroll(View view, float scrollProgressPercent, int direction) {
Log.i("MyActivity", "onScroll " + direction + ": " + scrollProgressPercent);
}
});

Expand Down Expand Up @@ -116,14 +116,14 @@ protected void onDestroy() {
super.onDestroy();
}

@OnClick(R.id.right)
public void swipeRight() {
@OnClick(R.id.up)
public void swipeTop() {
if (memberAdapter.isEmpty()) {
Snackbar.make(coordinatorLayout, "Cannot swipe right. Adapter is empty.", Snackbar.LENGTH_SHORT).show();
Snackbar.make(coordinatorLayout, "Cannot swipe up. Adapter is empty.", Snackbar.LENGTH_SHORT).show();
return;
}
//Trigger the right event manually.
flingContainer.swipeRight();
//Trigger the up event manually.
flingContainer.swipeUp();
}

@OnClick(R.id.left)
Expand All @@ -136,4 +136,23 @@ public void swipeLeft() {
flingContainer.swipeLeft();
}

@OnClick(R.id.right)
public void swipeRight() {
if (memberAdapter.isEmpty()) {
Snackbar.make(coordinatorLayout, "Cannot swipe right. Adapter is empty.", Snackbar.LENGTH_SHORT).show();
return;
}
//Trigger the right event manually.
flingContainer.swipeRight();
}

@OnClick(R.id.down)
public void swipeDown() {
if (memberAdapter.isEmpty()) {
Snackbar.make(coordinatorLayout, "Cannot swipe down. Adapter is empty.", Snackbar.LENGTH_SHORT).show();
return;
}
//Trigger the down event manually.
flingContainer.swipeDown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void onCardExited(View view, @Direction int direction) {
}

@Override
public void onScroll(View view, float scrollProgressPercent) {
public void onScroll(View view, float scrollProgressPercent, @Direction int direction) {

}

Expand Down
30 changes: 27 additions & 3 deletions example/src/main/res/layout/buttons.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
Expand All @@ -10,11 +10,22 @@
android:orientation="horizontal"
tools:showIn="@layout/activity_main">

<Button
android:id="@+id/up"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="Up"
tools:ignore="HardcodedText"/>

<Button
android:id="@+id/left"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/up"
android:layout_margin="10dp"
android:text="Left"
tools:ignore="HardcodedText"/>
Expand All @@ -24,8 +35,21 @@
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_below="@id/up"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/left"
android:text="Right"
tools:ignore="HardcodedText"/>

</LinearLayout>
<Button
android:id="@+id/down"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/left"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:text="Down"
tools:ignore="HardcodedText"/>

</RelativeLayout>
2 changes: 1 addition & 1 deletion example/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="buttons_bottom_margin">80dp</dimen>
<dimen name="buttons_bottom_margin">20dp</dimen>
<dimen name="naive_snackbar_help_padding">48dp</dimen>
</resources>
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
}

dependencies {
compile 'com.android.support:support-annotations:25.0.0'
compile 'com.android.support:support-annotations:25.0.1'

testCompile 'com.google.truth:truth:0.30'
testCompile 'org.mockito:mockito-core:2.2.9'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import android.view.View;

import com.lorentzos.flingswipe.internal.Direction;

/**
*
*/
public interface OnScrollListener {
void onScroll(View view, float scrollProgressPercent);
void onScroll(View view, float scrollProgressPercent, @Direction int direction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Adapter;
Expand Down Expand Up @@ -71,8 +70,6 @@ private void layoutChildren(int startingIndex, int adapterCount) {
for (int i = startingIndex; i < min; i++) {
View child = adapter.getView(i, null, this);

Log.wtf("SwipeFlingAdapterView", "layoutChildren i: " + i);

if (child.getVisibility() != GONE) {
makeAndAddView(child);
}
Expand Down Expand Up @@ -229,11 +226,11 @@ public void onCardExited(View view, @Direction int direction) {
}

@Override
public void onScroll(View view, float scrollProgressPercent) {
public void onScroll(View view, float scrollProgressPercent, @Direction int direction) {
if (onScrollListener == null) {
return;
}
onScrollListener.onScroll(view, scrollProgressPercent);
onScrollListener.onScroll(view, scrollProgressPercent, direction);
}

@Override
Expand Down Expand Up @@ -273,6 +270,18 @@ public void swipeLeft() {
}
}

public void swipeUp() {
synchronized (object) {
swipe(Direction.UP);
}
}

public void swipeDown() {
synchronized (object) {
swipe(Direction.DOWN);
}
}

private void swipe(int direction) {
if (nextLayoutPass) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public interface CardEventListener {
void onCardExited(View view, @Direction int direction);

void onScroll(View view, float scrollProgressPercent);
void onScroll(View view, float scrollProgressPercent, @Direction int direction);

void onRecenter(View view);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
*/
@SuppressWarnings("ConstantDeclaredInInterface")
@Retention(SOURCE)
@IntDef({Direction.CENTER, Direction.LEFT, Direction.RIGHT})
@IntDef({Direction.CENTER, Direction.LEFT, Direction.RIGHT, Direction.UP, Direction.DOWN})
public @interface Direction {

int CENTER = -1;
int LEFT = 1;
int RIGHT = 2;

int UP = 3;
int DOWN = 4;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ExitPosition {

private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();
private static final int DURATION = 100;
private static final int DURATION = 100*10;
private final float exitX;
private final float exitY;
private final float exitRotation;
Expand Down
Loading