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);
}
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);
}
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);
}
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));
}
Aggregations