use of android.support.v7.widget.RecyclerView.OnScrollListener in project UltimateRecyclerView by cymcsg.
the class SwipeListViewTouchListener method makeScrollListener.
/**
* Return ScrollListener for ListView
*
* @return OnScrollListener
*/
public RecyclerView.OnScrollListener makeScrollListener() {
return new RecyclerView.OnScrollListener() {
private boolean isFirstItem = false;
private boolean isLastItem = false;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
setEnabled(newState != recyclerView.SCROLL_STATE_DRAGGING);
if (swipeClosesAllItemsWhenListMoves && newState == recyclerView.SCROLL_STATE_DRAGGING) {
closeOpenedItems();
}
if (newState == recyclerView.SCROLL_STATE_DRAGGING) {
listViewMoving = true;
setEnabled(false);
}
if (newState != recyclerView.SCROLL_STATE_SETTLING && newState != recyclerView.SCROLL_STATE_DRAGGING) {
listViewMoving = false;
downPosition = ListView.INVALID_POSITION;
swipeListView.resetScrolling();
new Handler().postDelayed(new Runnable() {
public void run() {
setEnabled(true);
}
}, 500);
}
}
@Override
public void onScrolled(RecyclerView view, int dx, int dy) {
// if (isFirstItem) {
// boolean onSecondItemList = firstVisibleItem == 1;
// if (onSecondItemList) {
// isFirstItem = false;
// }
// } else {
// boolean onFirstItemList = firstVisibleItem == 0;
// if (onFirstItemList)
// isFirstItem = true;
// swipeListView.onFirstListItem();
// }
// }
// if (isLastItem) {
// boolean onBeforeLastItemList = firstVisibleItem + visibleItemCount == totalItemCount - 1;
// if (onBeforeLastItemList) {
// isLastItem = false;
// }
// } else {
// boolean onLastItemList = firstVisibleItem + visibleItemCount >= totalItemCount;
// if (onLastItemList) {
// isLastItem = true;
// swipeListView.onLastListItem();
// }
// }
}
};
}
use of android.support.v7.widget.RecyclerView.OnScrollListener in project platform_frameworks_base by android.
the class RecentsTvView method launchTaskFomRecents.
/**
* Launch the given task from recents with animation. If the task is not focused, this will
* attempt to scroll to focus the task before launching.
* @param task
*/
private void launchTaskFomRecents(final Task task, boolean animate) {
if (!animate) {
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
return;
}
mTaskStackHorizontalView.requestFocus();
Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
if (focusedTask != null && task != focusedTask) {
if (mScrollListener != null) {
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
mScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
if (cardView != null) {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
} else {
// This should not happen normally. If this happens then the data in
// the grid view was altered during the scroll. Log error and launch
// task with no animation.
Log.e(TAG, "Card view for task : " + task + ", returned null.");
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
}
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
}
};
mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
} else {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
}
}
use of android.support.v7.widget.RecyclerView.OnScrollListener in project android_frameworks_base by ResurrectionRemix.
the class RecentsTvView method launchTaskFomRecents.
/**
* Launch the given task from recents with animation. If the task is not focused, this will
* attempt to scroll to focus the task before launching.
* @param task
*/
private void launchTaskFomRecents(final Task task, boolean animate) {
if (!animate) {
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
return;
}
mTaskStackHorizontalView.requestFocus();
Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
if (focusedTask != null && task != focusedTask) {
if (mScrollListener != null) {
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
mScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
if (cardView != null) {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
} else {
// This should not happen normally. If this happens then the data in
// the grid view was altered during the scroll. Log error and launch
// task with no animation.
Log.e(TAG, "Card view for task : " + task + ", returned null.");
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
}
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
}
};
mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
} else {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
}
}
use of android.support.v7.widget.RecyclerView.OnScrollListener in project android_frameworks_base by crdroidandroid.
the class RecentsTvView method launchTaskFomRecents.
/**
* Launch the given task from recents with animation. If the task is not focused, this will
* attempt to scroll to focus the task before launching.
* @param task
*/
private void launchTaskFomRecents(final Task task, boolean animate) {
if (!animate) {
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
return;
}
mTaskStackHorizontalView.requestFocus();
Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
if (focusedTask != null && task != focusedTask) {
if (mScrollListener != null) {
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
mScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
if (cardView != null) {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
} else {
// This should not happen normally. If this happens then the data in
// the grid view was altered during the scroll. Log error and launch
// task with no animation.
Log.e(TAG, "Card view for task : " + task + ", returned null.");
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
}
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
}
};
mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
} else {
mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
}
}
use of android.support.v7.widget.RecyclerView.OnScrollListener in project AndroidSwipeLayout by daimajia.
the class RecyclerViewExample method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recyclerview);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setTitle("RecyclerView");
}
}
// Layout Managers:
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// Item Decorator:
recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.divider)));
recyclerView.setItemAnimator(new FadeInLeftAnimator());
// Adapter:
String[] adapterData = new String[] { "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming" };
mDataSet = new ArrayList<String>(Arrays.asList(adapterData));
mAdapter = new RecyclerViewAdapter(this, mDataSet);
((RecyclerViewAdapter) mAdapter).setMode(Attributes.Mode.Single);
recyclerView.setAdapter(mAdapter);
/* Listeners */
recyclerView.setOnScrollListener(onScrollListener);
}
Aggregations