Search in sources :

Example 1 with DynamicListView

use of com.nhaarman.listviewanimations.itemmanipulation.DynamicListView in project ListViewAnimations by nhaarman.

the class DynamicListViewTestActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    mListView = new DynamicListView(this);
    List<Integer> integers = new ArrayList<Integer>();
    for (int i = 0; i < 20; i++) {
        integers.add(i);
    }
    ListAdapter myListAdapter = new MyListAdapter(this, integers);
    mListView.setAdapter(myListAdapter);
    setContentView(mListView);
}
Also used : Window(android.view.Window) ArrayList(java.util.ArrayList) DynamicListView(com.nhaarman.listviewanimations.itemmanipulation.DynamicListView) ListAdapter(android.widget.ListAdapter)

Example 2 with DynamicListView

use of com.nhaarman.listviewanimations.itemmanipulation.DynamicListView in project ListViewAnimations by nhaarman.

the class MotionEventUtils method dispatchDragMotionEvents.

public static void dispatchDragMotionEvents(final Instrumentation instrumentation, final DynamicListView dynamicListView, final int fromPosition, final int toPosition) throws InterruptedException {
    int[] location = new int[2];
    dynamicListView.getLocationOnScreen(location);
    View view = dynamicListView.getChildAt(fromPosition);
    float fromY = (int) (view.getY() + view.getHeight() / 2) + location[1];
    View toView = dynamicListView.getChildAt(toPosition);
    float toY = (int) toView.getY() + location[1];
    toY += fromPosition < toPosition ? toView.getHeight() : 0;
    List<MotionEvent> motionEvents = createMotionEvents(dynamicListView, fromY, toY);
    dispatchMotionEvents(instrumentation, motionEvents, true);
}
Also used : View(android.view.View) AbsListView(android.widget.AbsListView) DynamicListView(com.nhaarman.listviewanimations.itemmanipulation.DynamicListView) MotionEvent(android.view.MotionEvent)

Example 3 with DynamicListView

use of com.nhaarman.listviewanimations.itemmanipulation.DynamicListView in project ListViewAnimations by nhaarman.

the class MotionEventUtils method dispatchDragScrollDownMotionEvents.

public static void dispatchDragScrollDownMotionEvents(final Instrumentation instrumentation, final DynamicListView dynamicListView, final int fromPosition) throws InterruptedException {
    int[] location = new int[2];
    dynamicListView.getLocationOnScreen(location);
    View view = dynamicListView.getChildAt(fromPosition);
    float fromY = (int) (view.getY()) + location[1];
    View toView = dynamicListView.getChildAt(dynamicListView.getLastVisiblePosition());
    float toY = (int) (toView.getY() + toView.getHeight()) + location[1] + 2;
    List<MotionEvent> motionEvents = createMotionEvents(dynamicListView, fromY, toY);
    MotionEvent upEvent = motionEvents.remove(motionEvents.size() - 1);
    dispatchMotionEvents(instrumentation, motionEvents, true);
    Thread.sleep(10000);
    dispatchMotionEvents(instrumentation, Arrays.asList(upEvent), true);
}
Also used : View(android.view.View) AbsListView(android.widget.AbsListView) DynamicListView(com.nhaarman.listviewanimations.itemmanipulation.DynamicListView) MotionEvent(android.view.MotionEvent)

Example 4 with DynamicListView

use of com.nhaarman.listviewanimations.itemmanipulation.DynamicListView in project ListViewAnimations by nhaarman.

the class DynamicListViewActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dynamiclistview);
    DynamicListView listView = (DynamicListView) findViewById(R.id.activity_dynamiclistview_listview);
    listView.addHeaderView(LayoutInflater.from(this).inflate(R.layout.activity_dynamiclistview_header, listView, false));
    /* Setup the adapter */
    ArrayAdapter<String> adapter = new MyListAdapter(this);
    SimpleSwipeUndoAdapter simpleSwipeUndoAdapter = new SimpleSwipeUndoAdapter(adapter, this, new MyOnDismissCallback(adapter));
    AlphaInAnimationAdapter animAdapter = new AlphaInAnimationAdapter(simpleSwipeUndoAdapter);
    animAdapter.setAbsListView(listView);
    assert animAdapter.getViewAnimator() != null;
    animAdapter.getViewAnimator().setInitialDelayMillis(INITIAL_DELAY_MILLIS);
    listView.setAdapter(animAdapter);
    /* Enable drag and drop functionality */
    listView.enableDragAndDrop();
    listView.setDraggableManager(new TouchViewDraggableManager(R.id.list_row_draganddrop_touchview));
    listView.setOnItemMovedListener(new MyOnItemMovedListener(adapter));
    listView.setOnItemLongClickListener(new MyOnItemLongClickListener(listView));
    /* Enable swipe to dismiss */
    listView.enableSimpleSwipeUndo();
    /* Add new items on item click */
    listView.setOnItemClickListener(new MyOnItemClickListener(listView));
}
Also used : SimpleSwipeUndoAdapter(com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.undo.SimpleSwipeUndoAdapter) AlphaInAnimationAdapter(com.nhaarman.listviewanimations.appearance.simple.AlphaInAnimationAdapter) DynamicListView(com.nhaarman.listviewanimations.itemmanipulation.DynamicListView) TouchViewDraggableManager(com.nhaarman.listviewanimations.itemmanipulation.dragdrop.TouchViewDraggableManager)

Aggregations

DynamicListView (com.nhaarman.listviewanimations.itemmanipulation.DynamicListView)4 MotionEvent (android.view.MotionEvent)2 View (android.view.View)2 AbsListView (android.widget.AbsListView)2 Window (android.view.Window)1 ListAdapter (android.widget.ListAdapter)1 AlphaInAnimationAdapter (com.nhaarman.listviewanimations.appearance.simple.AlphaInAnimationAdapter)1 TouchViewDraggableManager (com.nhaarman.listviewanimations.itemmanipulation.dragdrop.TouchViewDraggableManager)1 SimpleSwipeUndoAdapter (com.nhaarman.listviewanimations.itemmanipulation.swipedismiss.undo.SimpleSwipeUndoAdapter)1 ArrayList (java.util.ArrayList)1