Giter VIP home page Giter VIP logo

shuffle's Introduction

Shuffle

API Build Status

An easy to use swiping-view for Android

intro

Usage

Just declare a Shuffle into your layout

<com.meetic.shuffle.Shuffle
      android:id="@+id/shuffle"
      android:layout_width="match_parent"
      android:layout_height="200dp"
      />

Then fill it with an Adapter

Shuffle shuffle = (Shuffle)findViewById(R.id.shuffle);
shuffle.setShuffleAdapter(new Shuffle.Adapter(){
    @Override
    public Shuffle.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) {

    }

    @Override
    public void onBindViewHolder(final Shuffle.ViewHolder viewHolder, int position) {

    }

    @Override
    public int getItemCount() {

    }
});

Customisation

Movements

Free movements

intro

<com.meetic.shuffle.Shuffle
      android:id="@+id/shuffle"
      android:layout_width="match_parent"
      android:layout_height="200dp"
      app:shuffle_inlineMove="false"
      />

Inline movements

intro

<com.meetic.shuffle.Shuffle
      android:id="@+id/shuffle"
      android:layout_width="match_parent"
      android:layout_height="200dp"
      app:shuffle_inlineMove="true"
      />

Orientation

If you want to set it vertical (by default Suffle is horizontal oriented)

<com.meetic.shuffle.Shuffle
     android:id="@+id/shuffle"
     android:layout_width="match_parent"
     android:layout_height="200dp"
     app:shuffle_orientation="horizontal / vertical"
     />

intro

Rotation

Without rotation

<com.meetic.shuffle.Shuffle
     android:id="@+id/shuffle"
     android:layout_width="match_parent"
     android:layout_height="200dp"
     app:shuffle_rotationEnabled="false"
     />

intro

With rotation

<com.meetic.shuffle.Shuffle
     android:id="@+id/shuffle"
     android:layout_width="match_parent"
     android:layout_height="200dp"
     app:shuffle_rotationEnabled="false"
     app:shuffle_rotation="10"
     />

intro

Restart

To restart the shuffling

shuffle.restartShuffling();

intro

Revert

To undo a card exit

shuffle.revert(duration);

intro

Infinite

<com.meetic.shuffle.Shuffle
     android:id="@+id/shuffle"
     android:layout_width="match_parent"
     android:layout_height="200dp"
     app:shuffle_infinite="true"
     />

intro

Options

You can set the max number of cards displayed and adjust the space between cards

<com.meetic.shuffle.Shuffle
     android:id="@+id/shuffle"
     android:layout_width="match_parent"
     android:layout_height="200dp"
     app:shuffle_numberOfDisplayedCards="4"
     app:shuffle_differenceTranslationY="5dp"
     app:shuffle_differenceTranslationX="1dp"
     />

right

Listeners

shuffle.addListener(new Shuffle.Listener() {
            @Override
            public void onViewChanged(int position) {

            }

            @Override
            public void onScrollStarted() {

            }

            @Override
            public void onScrollFinished() {

            }

            @Override
            public void onViewExited(DraggableView draggableView, Direction direction) {

            }

            @Override
            public void onViewScrolled(DraggableView draggableView, float percentX, float percent) {

            }
        });

CardDraggableView

<Shuffle
    ...
    //overlay color displayed while scrolling
    app:shuffle_colorRight="@color/blue"
    app:shuffle_colorLeft="@color/blue"

    //overlay content displayed while scrolling (ex: containing logo)
    app:shuffle_layoutLeft="@layout/bal_shuffle_cell_left"
    app:shuffle_layoutRight="@layout/bal_shuffle_cell_right"
    ...
    />

right

Animations

All Shuffle animations can be overriden

shuffle.setViewAnimator(new ShuffleViewAnimator(){
            //override methods
});

Try ShuffleViewAnimator and `ShuffleViewAnimatorOnSecondCard

ShuffleViewAnimator

You can easily set dismiss animations for ShuffleViewAnimator ( scaleUp / goBackBehind )

shuffle.setViewAnimator(new ShuffleViewAnimator()
            .setPushLeftAnimateViewStackScaleUp(false)
            .setPushRightAnimateViewStackScaleUp(true)
            .setPushTopAnimateViewStackScaleUp(false)
            .setPushBottomAnimateViewStackScaleUp(false)
        );

Enable

shuffle.enable(true / false);

Download

Add into your build.gradle

Download

compile 'com.meetic.shuffle:shuffle:(last version)'
compile 'com.meetic.dragueur:dragueur:1.0.3'

Move your views with Dragueur !

#Log

1.0.8

  • infinite

1.0.6

  • revert

1.0.4

  • Layer animations

1.0.3

  • ShuffleViewAnimator is now customisable

1.0.2

  • added restart shuffling

Credits

A project initiated by Meetic

This project was first developed by Meetic and has been open-sourced since. We will continue working on it. We encourage the community to contribute to the project by opening tickets and/or pull requests.

logo meetic

Contributor: Florent Champigny

#License

Copyright 2016 Meetic, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

shuffle's People

Contributors

firezenk avatar florent37 avatar prezccr avatar yujloup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shuffle's Issues

disable swipe

Is it possible to disable swipe for left or right? in my app I want users to just swipe right to depict moving through a list.

Stack Swiped Views Below Others

While swiping currently removes the views from the screen. Is it possible to prevent this, and just create an unending chain of swiping the same finite views? I just want users to be able to move through the images, like an album.

Restart Shuffleing

Hello

nice Library - thanks.

i have the following use case:
App shows some cards to shuffle. With a reload button i want to reload the data and restart the shuffeling.

I cannot find how to do that. Can you give me a hint?

Thanks a lot

Revert shuffle page

Hi

need following feature:

User swipes a card away.
User can restore last card by button click.

-> swipe back

Need a possibility to set adapter position (optional with animation to specific position)

Would be great if you can add this feature

3 Directions to swipe issue

In my project, I have to implement swipe to the right, bottom and left. Can you help me with some workaround?

OnClick Listener

How would you set a Click Listener on the shuffle component ?
I tried this with no success:

        shuffle.setOnClickListener(new Shuffle.OnClickListener() {
            @Override
            public void onClick(View view) {
                Debug.i("test");
                // Do something here
            }
        });

Recycler view item

Can this be used as a recycler view item. I have a list of items in my recycler view and I want to make each one of the items swappable not like a dark deck, if you know what I mean. Regards.

IndexOutOfBoundsException

Hey again,

my app has a bottom bar with 5 fragments. one of them contains the shuffle view.
If I change the fragments very fast I get the following Exception.

FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException
at java.util.LinkedList.get(LinkedList.java:519)
at com.meetic.shuffle.Shuffle.updateAdapter(Shuffle.java:261)
at com.meetic.shuffle.Shuffle$1.animationMiddle(Shuffle.java:144)
at com.meetic.shuffle.ShuffleViewAnimator$1.onAnimationEnd(ShuffleViewAnimator.java:91)
at android.support.v4.view.ViewPropertyAnimatorCompatJB$1.onAnimationEnd(ViewPropertyAnimatorCompatJB.java:47)
at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1114)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1239)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:766)
at android.animation.ValueAnimator$AnimationHandler$1.run(ValueAnimator.java:801)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
at android.view.Choreographer.doCallbacks(Choreographer.java:695)
at android.view.Choreographer.doFrame(Choreographer.java:628)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

More directions to swipe

In my project, I have to implement swipe to the top, right and left. Can you help me with some workaround?

Custom shapes for the card

In my project I have to implement circle shapes for cards, but cards have shadows and squared layout, how to ignore that?
Thanks for the answer

Variable number of cards to shuffle

I am having trouble using this library with a variable number of cards. I want an infinite shuffle, but if I have less than 3 elements I get an IllegalStatementException.

Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. at android.view.ViewGroup.addViewInner(ViewGroup.java:4656) at android.view.ViewGroup.addView(ViewGroup.java:4497) at android.view.ViewGroup.addView(ViewGroup.java:4437) at android.view.ViewGroup.addView(ViewGroup.java:4410) at com.meetic.shuffle.Shuffle.updateAdapter(Shuffle.java:317) at com.meetic.shuffle.Shuffle.notifyDataSetChanged(Shuffle.java:215) at com.meetic.shuffle.Shuffle.setShuffleAdapter(Shuffle.java:68) at xprodevelopers.com.appclinicas.MainActivity$override.onCreate(MainActivity.java:53) at xprodevelopers.com.appclinicas.MainActivity$override.access$dispatch(MainActivity.java) at xprodevelopers.com.appclinicas.MainActivity.onCreate(MainActivity.java:0) at android.app.Activity.performCreate(Activity.java:6912) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3008)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4974)  at android.app.ActivityThread.-wrap21(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6688)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 

Is there any way to change the number of cards displayed through code?

Thanks.

Crash if used in recyclerview.

I have used Shuffle inside a recyclerview. App crashes when user trying to drag card. It is easy to repro.

  1. Add few elements in recyclerview. Keep one of them as Shuffle layout.
  2. Scroll to make Shuffle view inside view port.
  3. scroll back to make shuffle outside of view port.
    4 Scroll again to make same shuffle view inside view port again.
  4. Now try to drag a view.

App crashes with following stack.

11-12 15:11:27.558 10126-10126/com.fabulyst.mobile E/AndroidRuntime: FATAL EXCEPTION: main Process: com.fabulyst.mobile, PID: 10126 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setScaleX(float)' on a null object reference at android.support.v4.view.ViewCompatHC.setScaleX(ViewCompatHC.java:126) at android.support.v4.view.ViewCompat$HCViewCompatImpl.setScaleX(ViewCompat.java:1177) at android.support.v4.view.ViewCompat.setScaleX(ViewCompat.java:2613) at com.meetic.shuffle.ShuffleViewAnimator.updateViewsPositions(ShuffleViewAnimator.java:323) at com.meetic.shuffle.Shuffle$3.onDrag(Shuffle.java:339) at com.meetic.dragueur.DraggableView.update(DraggableView.java:245) at com.meetic.dragueur.DraggableView.update(DraggableView.java:236) at com.meetic.dragueur.DraggableView.handleTouch(DraggableView.java:344) at com.meetic.dragueur.DraggableView.onTouchEvent(DraggableView.java:230) at android.view.View.dispatchTouchEvent(View.java:9300) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2547) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2240) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2254) at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2403) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1737) at android.app.Activity.dispatchTouchEvent(Activity.java:2771) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60) at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60) at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2364) at android.view.View.dispatchPointerEvent(View.java:9520) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4230) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4096) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3642) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3695) at android

Swiping cards using buttons causes erratic behavior

Hi guys,

I'm having several problems when using the library and swiping card by using a Button. Here is my fork to illustrate this (see Horizontal section) : https://github.com/JorisPotier/Shuffle.
I have just changed the implementation of the HorizontalActivity by adding a ShuffleListener, which goal is to finish the activity when all the 20 cards have been swiped, and to do some business logic for each swiped card (actually in the provided sample I'm just logging the position of the current swiped card).

My use case is the following : the user is swiping card very fast by using the "Right" button on the HorizontalActivity.

Problem 1 :
capture du 2017-01-23 16 14 47
Some cards are randomly oriented.

Problem 2 :
logs.txt
It seems that the business logic is not triggered for all cards, and for some it has been made twice (see the log traces).

Problem 3 :
The listener calls the onViewExited method for some non existing positions (see the log traces, we are logging a currentAdapterPosition equal to 21, which is not possible since I should have only 20 cards).

Problem 4 :
The app is randomly crashing when we returned to the MainActivity after all cards have been swiped. Since the HorizontalActivity is finished, it seems that we have a non destroyed ShuffleViewAnimator which leaks a NullPointerException (see the same logs).

In my real production application we have implemented a workaround by disabling the buttons during the time a card is animating (and so the user cannot swipe fastly), but it is not very user friendly.

Can you help me on this ?

Regards.

Fixed Height

Can the shuffle view be made to "wrap_content" instead of a fixed height? I want to implement it on a chat view where the message length is not capped, if you know what I mean. Any help will be appreciated.

Discarding views

Hey

Nice library.

Was wondering if you could add an attribute that would make the swiped cards get discarded instead of getting sent to the end of the stack?

Also, does it have an onClick listener for the views?

Nest within scrollview

How do you nest it within a scrollview so that both work smoothly?

e.g. if shuffle has inline=true, and scrollview is vertical (nested or otherwise?)

even disabling the scrollview with LockedScrollView custom class is not 100% solid

Error when Using ViewHolder

Whenever the user selects images and adds them to the ViewHolder, the app keeps crashing with the following stack trace:

capture

My code is very basic, and yet the solution to this bug evades me. see the code below:

class ImageShuffleAdapter : Shuffle.Adapter<ImageShuffleViewHolder>() {

        private var uris: List<Uri> = emptyList()

        override fun onCreateViewHolder(parent: ViewGroup?, type: Int): ImageShuffleViewHolder {
            val view = LayoutInflater.from(parent!!.context).inflate(R.layout.content_product_images_shuffle, parent, false)
            return ImageShuffleViewHolder(view)
        }

        override fun onBindViewHolder(viewHolder: ImageShuffleViewHolder?, position: Int) {
            viewHolder!!.bind(this.uris.get(position), position)
        }

  // More coe
}

I think there is a bug with the library. Could you have sone thoughts?

Default card by position?

Hi, nice library and easy to use.
I want to go to a specific card by his position but I can't find the way to do it.
You know, like the method .setCurrentItem(int item) from ViewPager.

Infinite shuffle

It seems like it is not possible to implement a infinite shuffle.

Any workaround to do that ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.