Java 类android.support.v7.widget.helper.ItemTouchHelper 实例源码
项目:WeatherPlus
文件:CityListFragment.java
@Override
public void onActivityCreated(Bundle state) {
Log.d(TAG, "onActivityCreated");
super.onActivityCreated(state);
if (state != null) {
isRefreshing = state.getBoolean(KEY_IS_REFRESHING);
isAddQueueHandling = state.getBoolean(KEY_IS_ADD_QUEUE_HANDLING);
currNameIndex = state.getInt(KEY_CURR_NAME_INDEX);
cityWeatherList = state.getParcelableArrayList(KEY_CITY_WEATHER_LIST);
cityAddQueue = state.getParcelableArrayList(KEY_CITY_ADD_QUEUE);
updateRecyclerView();
} else {
loadCitiesFromDisk();
}
itemTouchCallBack = new ItemTouchHelperAdapter(ItemTouchHelper.UP | ItemTouchHelper.DOWN,
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this, cityWeatherList, true);
new ItemTouchHelper(itemTouchCallBack).attachToRecyclerView(recyclerView);
}
项目:letv
文件:ChannelFragmentAdapter.java
public ChannelFragmentAdapter(Context context, ItemTouchHelper helper, ChannelListBean channelListBean, RecyclerView view) {
this.mInflater = LayoutInflater.from(context);
this.mContext = context;
this.mItemTouchHelper = helper;
this.mRecyclerView = view;
this.mChannelListBean = channelListBean;
if (channelListBean != null && !BaseTypeUtils.isListEmpty(channelListBean.listChannel)) {
for (int i = 0; i < channelListBean.listChannel.size(); i++) {
if (channelListBean.listChannel.get(i) != null) {
this.mMyChannelItems.add(channelListBean.listChannel.get(i));
if (((Channel) channelListBean.listChannel.get(i)).top == 0) {
this.mTopSize++;
}
if (((Channel) channelListBean.listChannel.get(i)).lock == 1) {
this.mLockSize++;
}
}
}
this.mImageDownloader = ImageDownloader.getInstance();
}
}
项目:RLibrary
文件:DefaultItemTouchHelperCallback.java
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
//判断当前是否是swipe方式:侧滑。
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
//1.ItemView--ViewHolder; 2.侧滑条目的透明度程度关联谁?dX(delta增量,范围:当前条目-width~width)。
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
float alpha = 1;
if (layoutManager instanceof LinearLayoutManager) {
int orientation = ((LinearLayoutManager) layoutManager).getOrientation();
if (orientation == LinearLayoutManager.HORIZONTAL) {
alpha = 1 - Math.abs(dY) / viewHolder.itemView.getHeight();
} else if (orientation == LinearLayoutManager.VERTICAL) {
alpha = 1 - Math.abs(dX) / viewHolder.itemView.getWidth();
}
}
viewHolder.itemView.setAlpha(alpha);//1~0
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
项目:JD-Test
文件:ItemDragAndSwipeCallback.java
@Override
public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
&& !isViewCreateByAdapter(viewHolder)) {
View itemView = viewHolder.itemView;
c.save();
if (dX > 0) {
c.clipRect(itemView.getLeft(), itemView.getTop(),
itemView.getLeft() + dX, itemView.getBottom());
c.translate(itemView.getLeft(), itemView.getTop());
} else {
c.clipRect(itemView.getRight() + dX, itemView.getTop(),
itemView.getRight(), itemView.getBottom());
c.translate(itemView.getRight() + dX, itemView.getTop());
}
mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
c.restore();
}
}
项目:GitHub
文件:ItemDragAndSwipeCallback.java
@Override
public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
&& !isViewCreateByAdapter(viewHolder)) {
View itemView = viewHolder.itemView;
c.save();
if (dX > 0) {
c.clipRect(itemView.getLeft(), itemView.getTop(),
itemView.getLeft() + dX, itemView.getBottom());
c.translate(itemView.getLeft(), itemView.getTop());
} else {
c.clipRect(itemView.getRight() + dX, itemView.getTop(),
itemView.getRight(), itemView.getBottom());
c.translate(itemView.getRight() + dX, itemView.getTop());
}
mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
c.restore();
}
}
项目:letv
文件:FirstPageCustomAdapter.java
public FirstPageCustomAdapter(Context context, ItemTouchHelper helper, List<HomeBlock> list, TextView view, RecyclerView recyclerView) {
this.mInflater = LayoutInflater.from(context);
if (!BaseTypeUtils.isListEmpty(list)) {
for (HomeBlock block : list) {
if (block != null) {
if (TextUtils.equals(block.isLock, "1")) {
this.mList.add(this.mLockSize, block);
this.mLockSize++;
} else {
this.mList.add(block);
}
}
}
this.mItemTouchHelper = helper;
this.mContext = context;
if (this.mLockSize == 0) {
this.mHeadSize = 1;
} else {
this.mHeadSize = 2;
}
this.mSaveView = view;
this.mRecyclerView = recyclerView;
}
}
项目:MyCalendar
文件:LocationListActivity.java
private void initView() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(mContext, R.color.color_Actionbar)));
}
mCoordinatorLayout = findViewById(R.id.coordinator);
RecyclerView recyclerView = findViewById(R.id.recycle_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new LocationAdapter(this, new ArrayList<Location>());
@SuppressWarnings("unchecked") SwingBottomInAnimationAdapter animatorAdapter = new SwingBottomInAnimationAdapter(mAdapter, recyclerView);
recyclerView.setAdapter(animatorAdapter);
ItemTouchHelper.Callback callback = new ItemTouchHelperCallBackNoMove(mAdapter);
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
touchHelper.attachToRecyclerView(recyclerView);
mView_FABMenu = findViewById(R.id.fab_menu_1);
FloatingActionButton addLocation = findViewById(R.id.fab_action_1);
addLocation.setVisibility(View.VISIBLE);
addLocation.setLabelText(mContext.getResources().getString(R.string.add_location));
addLocation.setOnClickListener(this);
}
项目:GitHub
文件:MyItemTouchHelperCallback.java
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder holder) {
//方向:up,down,left,right
//常量:
int up = ItemTouchHelper.UP;//1 0x0001
int down = ItemTouchHelper.DOWN;//2 0x0010
// ItemTouchHelper.LEFT
// ItemTouchHelper.RIGHT
//我要监听的拖拽方向是哪两个方向。
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN|ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
//我要监听的swipe侧滑方向是哪个方向
// int swipeFlags = 0;
int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
int flags = makeMovementFlags(dragFlags, swipeFlags);
return flags;
}
项目:Hands-On-Android-UI-Development
文件:OverviewActivity.java
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_overview);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
final RecyclerView claimItems = findViewById(R.id.claim_items);
claimItems.setAdapter(new ClaimItemAdapter(
this, this,
ClaimApplication.getClaimDatabase().claimItemDao().selectAll()
));
new ItemTouchHelper(new SwipeToDeleteCallback())
.attachToRecyclerView(claimItems);
}
项目:GitHub
文件:MyItemTouchHelperCallback.java
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState,
boolean isCurrentlyActive) {
//dX:水平方向移动的增量(负:往左;正:往右)范围:0~View.getWidth 0~1
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
//透明度动画
float alpha = 1 - Math.abs(dX) / viewHolder.itemView.getWidth();
viewHolder.itemView.setAlpha(alpha);//1~0
viewHolder.itemView.setScaleX(alpha);//1~0
viewHolder.itemView.setScaleY(alpha);//1~0
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState,
isCurrentlyActive);
}
项目:OpenHub
文件:TraceFragment.java
@Override
protected void initFragment(Bundle savedInstanceState) {
super.initFragment(savedInstanceState);
setLoadMoreEnable(true);
ItemTouchHelperCallback callback = new ItemTouchHelperCallback(0,
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this);
itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recyclerView);
StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(adapter);
recyclerView.addItemDecoration(headersDecor);
StickyRecyclerHeadersTouchListener touchListener =
new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor);
touchListener.setOnHeaderClickListener((header, position, headerId) -> {
//wrong position returned
// recyclerView.smoothScrollToPosition(mPresenter.getFirstItemByDate((Long) header.getTag()));
});
recyclerView.addOnItemTouchListener(touchListener);
}
项目:GitHub
文件:ItemDragAndSwipeCallback.java
@Override
public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
&& !isViewCreateByAdapter(viewHolder)) {
View itemView = viewHolder.itemView;
c.save();
if (dX > 0) {
c.clipRect(itemView.getLeft(), itemView.getTop(),
itemView.getLeft() + dX, itemView.getBottom());
c.translate(itemView.getLeft(), itemView.getTop());
} else {
c.clipRect(itemView.getRight() + dX, itemView.getTop(),
itemView.getRight(), itemView.getBottom());
c.translate(itemView.getRight() + dX, itemView.getTop());
}
mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
c.restore();
}
}
项目:DynamicTab
文件:MainActivity.java
private void initView() {
mRecyclerSrc = (RecyclerView) findViewById(R.id.teach_src);
mRecyclerDst = (RecyclerView) findViewById(R.id.teach_dst);
GridLayoutManager layoutManagerSrc = new GridLayoutManager(this, 4);
GridLayoutManager layoutManagerDst = new GridLayoutManager(this, 4);
mRecyclerSrc.setLayoutManager(layoutManagerSrc);
mRecyclerDst.setLayoutManager(layoutManagerDst);
TeachAdapter srcAdapter = new TeachAdapter(this, getDataSrc());
mRecyclerSrc.setAdapter(srcAdapter);
srcAdapter.setListener(this);
TeachAdapter detAdapter = new TeachAdapter(this, getDataDst());
mRecyclerDst.setAdapter(detAdapter);
detAdapter.setListener(this);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchCallback(srcAdapter));
itemTouchHelper.attachToRecyclerView(mRecyclerSrc);
}
项目:GitHub
文件:ItemTouchHelperCallback.java
/**
* {@inheritDoc}
*/
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
int dragFlags;
int swipeFlags;
//Set movement flags based on the Layout Manager and Orientation
if (layoutManager instanceof GridLayoutManager || layoutManager instanceof StaggeredGridLayoutManager) {
dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
swipeFlags = 0;
} else if (Utils.getOrientation(layoutManager) == LinearLayoutManager.VERTICAL) {
dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
swipeFlags = mSwipeFlags > 0 ? mSwipeFlags : ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
} else {
dragFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
swipeFlags = mSwipeFlags > 0 ? mSwipeFlags : ItemTouchHelper.UP | ItemTouchHelper.DOWN;
}
//Disallow item swiping or dragging
if (viewHolder instanceof ViewHolderCallback) {
ViewHolderCallback viewHolderCallback = (ViewHolderCallback) viewHolder;
if (!viewHolderCallback.isDraggable()) dragFlags = 0;
if (!viewHolderCallback.isSwipeable()) swipeFlags = 0;
}
return makeMovementFlags(dragFlags, swipeFlags);
}
项目:GitHub
文件:FlexibleViewHolder.java
/**
* {@inheritDoc}
*
* @see #toggleActivation()
* @since 5.0.0-b1
*/
@Override
@CallSuper
public void onClick(View view) {
int position = getFlexibleAdapterPosition();
if (!mAdapter.isEnabled(position)) return;
// Experimented that, if LongClick is not consumed, onClick is fired. We skip the
// call to the listener in this case, which is allowed only in ACTION_STATE_IDLE.
if (mAdapter.mItemClickListener != null && mActionState == ItemTouchHelper.ACTION_STATE_IDLE) {
if (FlexibleAdapter.DEBUG)
Log.v(TAG, "onClick on position " + position + " mode=" + mAdapter.getMode());
// Get the permission to activate the View from user
if (mAdapter.mItemClickListener.onItemClick(position)) {
// Now toggle the activation
toggleActivation();
}
}
}
项目:JSSample
文件:SRecyclerView.java
/**
* 设置移动方向 模式
*
* @param recyclerView
* @param viewHolder
* @return
*/
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
int dragflag = 0;
int swipeflag = 0;
if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
if (canswitch)
dragflag = ItemTouchHelper.UP |
ItemTouchHelper.DOWN |
ItemTouchHelper.LEFT |
ItemTouchHelper.RIGHT;
if (canswipe)
swipeflag = ItemTouchHelper.END;
} else {
if (canswitch)
dragflag = ItemTouchHelper.UP |
ItemTouchHelper.DOWN;
if (canswipe)
swipeflag = ItemTouchHelper.END;
}
return makeMovementFlags(dragflag, swipeflag);
}
项目:Hands-On-Android-UI-Development
文件:OverviewActivity.java
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_overview);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
final RecyclerView claimItems = findViewById(R.id.claim_items);
claimItems.setAdapter(new ClaimItemAdapter(
this, this,
ClaimApplication.getClaimDatabase().claimItemDao().selectAll()
));
new ItemTouchHelper(new SwipeToDeleteCallback())
.attachToRecyclerView(claimItems);
}
项目:UiLib
文件:DefaultItemTouchHelperCallback.java
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int
actionState, boolean isCurrentlyActive) {
//判断当前是否是swipe方式:侧滑。
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
//1.ItemView--ViewHolder; 2.侧滑条目的透明度程度关联谁?dX(delta增量,范围:当前条目-width~width)。
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
float alpha = 1;
if (layoutManager instanceof LinearLayoutManager) {
int orientation = ((LinearLayoutManager) layoutManager).getOrientation();
if (orientation == LinearLayoutManager.HORIZONTAL) {
alpha = 1 - Math.abs(dY) / viewHolder.itemView.getHeight();
} else if (orientation == LinearLayoutManager.VERTICAL) {
alpha = 1 - Math.abs(dX) / viewHolder.itemView.getWidth();
}
}
viewHolder.itemView.setAlpha(alpha);//1~0
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
项目:GoogleVR
文件:ItemDragAndSwipeCallback.java
@Override
public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
View itemView = viewHolder.itemView;
c.save();
if (dX > 0) {
c.clipRect(itemView.getLeft(), itemView.getTop(), itemView.getLeft() + dX, itemView.getBottom());
c.translate(itemView.getLeft(), itemView.getTop());
} else {
c.clipRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom());
c.translate(itemView.getRight() + dX, itemView.getTop());
}
mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
c.restore();
}
}
项目:Android-Code-Demos
文件:LinearActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_linear);
List<String> list = new ArrayList<>();
for (int i = 1; i <= 20; i++) {
list.add("Hello, I am " + i);
}
Adapter adapter = new Adapter(this, this);
adapter.addAll(list);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.linear_recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
ItemTouchHelper.Callback callback = new ItemTouchHelperCallBack(adapter);
mItemTouchHelper = new ItemTouchHelper(callback);
mItemTouchHelper.attachToRecyclerView(recyclerView);
}
项目:ImitateZHRB
文件:SimpleItemTouchHelperCallback.java
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
// Fade out the view as it is swiped out of the parent's bounds
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
View itemView = viewHolder.itemView;
final float alpha = ALPHA_FULL - Math.abs(dX) / (float) itemView.getWidth();
itemView.setAlpha(alpha);
}
}
项目:AvatarTinderView
文件:SimpleItemTouchHelperCallback.java
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
// Fade out the view as it is swiped out of the parent's bounds
final float alpha = ALPHA_FULL - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
viewHolder.itemView.setAlpha(alpha);
viewHolder.itemView.setTranslationX(dX);
} else {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
}
项目:ucar-weex-core
文件:DragSupportCallback.java
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE && viewHolder instanceof ListBaseViewHolder) {
ListBaseViewHolder vh = (ListBaseViewHolder) viewHolder;
if (vh.getComponent() != null) {
mDragHelper.onDragStart(vh.getComponent(), vh.getAdapterPosition());
}
}
super.onSelectedChanged(viewHolder, actionState);
}
项目:Android-Open-Shopping-List
文件:ItemTouchHelperCallback.java
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
ShoppingListAdapter.ViewHolder vh = (ShoppingListAdapter.ViewHolder) viewHolder;
vh.isSwiped = true;
if (direction == ItemTouchHelper.START) {
listener.onSwipeLeft(vh);
} else if (direction == ItemTouchHelper.END) {
listener.onSwipeRight(vh);
}
}
项目:MyCalendar
文件:WeekLessonDetailActivity.java
private void initView() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(mContext, R.color.color_Actionbar)));
}
mView_Coordinator = findViewById(R.id.coordinator);
mView_SubjectName = findViewById(R.id.week_lesson_detail_subject_name);
mView_SubjectArrow = findViewById(R.id.arrow);
mView_Weekday = findViewById(R.id.week_lesson_detail_weekday);
mView_Repeat = findViewById(R.id.week_lesson_detail_repeat);
mView_Day = findViewById(R.id.week_lesson_detail_day);
mView_FABMenu = findViewById(R.id.fab_menu_1);
FloatingActionButton addDayLesson = findViewById(R.id.fab_action_1);
FloatingActionButton editWeekLesson = findViewById(R.id.fab_action_2);
addDayLesson.setVisibility(View.VISIBLE);
editWeekLesson.setVisibility(View.VISIBLE);
addDayLesson.setLabelText(mResources.getString(R.string.add_day_lesson));
editWeekLesson.setLabelText(mResources.getString(R.string.edit_week_lesson));
editWeekLesson.setImageResource(R.drawable.ic_edit_white_24dp);
RecyclerView mView_RecyclerView = findViewById(R.id.recycle_view);
mView_RecyclerView.setNestedScrollingEnabled(false);
mView_RecyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new DayLessonAdapter(mContext, new ArrayList<DayLesson>(), mColorText, mColorBackground);
@SuppressWarnings("unchecked") SwingBottomInAnimationAdapter animatorAdapter = new SwingBottomInAnimationAdapter(mAdapter, mView_RecyclerView);
mView_RecyclerView.setAdapter(animatorAdapter);
ItemTouchHelper.Callback callback = new ItemTouchHelperCallBackNoMove(mAdapter);
ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
touchHelper.attachToRecyclerView(mView_RecyclerView);
registerForContextMenu(mView_SubjectArrow);
mView_SubjectArrow.setOnClickListener(this);
mView_SubjectName.setOnClickListener(this);
addDayLesson.setOnClickListener(this);
editWeekLesson.setOnClickListener(this);
setUpInfo();
}
项目:OddLauncher
文件:RecyclerItemSwiper.java
public RecyclerItemSwiper(int dragDirs, int swipeDirs, Context context,
AppAdapter adapter, List<AppInfo> list, DatabaseHelper db, String tag, RecyclerView recyclerView) {
super(dragDirs, swipeDirs);
this.context = context;
this.adapter = adapter;
this.list = list;
this.db = db;
this.tag = tag;
itemTouchHelper = new ItemTouchHelper(RecyclerItemSwiper.this);
itemTouchHelper.attachToRecyclerView(recyclerView);
}
项目:EasyTodo
文件:SimpleItemTouchHelperCallback.java
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
// We only want the active item to change
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
if (viewHolder instanceof ItemTouchHelperViewHolder) {
// Let the view holder know that this item is being moved or dragged
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemSelected();
}
}
super.onSelectedChanged(viewHolder, actionState);
}
项目:decoy
文件:ItemDragAndSwipeCallback.java
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG
&& !isViewCreateByAdapter(viewHolder)) {
mAdapter.onItemDragStart(viewHolder);
viewHolder.itemView.setTag(R.id.BaseQuickAdapter_dragging_support, true);
} else if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE
&& !isViewCreateByAdapter(viewHolder)) {
mAdapter.onItemSwipeStart(viewHolder);
viewHolder.itemView.setTag(R.id.BaseQuickAdapter_swiping_support, true);
}
super.onSelectedChanged(viewHolder, actionState);
}
项目:MaterialDesignDemo
文件:MyItemTouchHelperCallback.java
/**
* 当item被拖拽或侧滑时触发
*
* @param viewHolder
* @param actionState 当前item的状态
*/
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
super.onSelectedChanged(viewHolder, actionState);
//不管是拖拽或是侧滑,背景色都要变化
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE)
viewHolder.itemView.setBackgroundColor(viewHolder.itemView.getContext().getResources().getColor(android.R.color.darker_gray));
}
项目:GitHub
文件:SimpleItemTouchHelperCallback.java
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
// Set movement flags based on the layout manager
int dragFlags;
int swipeFlags;
if (recyclerView.getLayoutManager() instanceof GridLayoutManager ||
recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
if (mDragFlags != 0) {
dragFlags = mDragFlags;
} else {
dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
}
if (mSwipeFlags != 0) {
swipeFlags = mSwipeFlags;
} else {
swipeFlags = ItemTouchHelper.START;
}
} else {
if (mDragFlags != 0) {
dragFlags = mDragFlags;
} else {
dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
}
if (mSwipeFlags != 0) {
swipeFlags = mSwipeFlags;
} else {
swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
}
}
return makeMovementFlags(dragFlags, swipeFlags);
}
项目:OSchina_resources_android
文件:TweetPicturesPreviewerItemTouchCallback.java
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
// We only want the active item to change
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
if (viewHolder instanceof ItemTouchHelperViewHolder) {
// Let the view holder know that this item is being moved or dragged
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemSelected();
}
}
super.onSelectedChanged(viewHolder, actionState);
}
项目:GitHub
文件:SimpleItemTouchHelperCallback.java
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
// We only want the active item to change
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
if (viewHolder instanceof ItemTouchHelperViewHolder) {
// Let the view holder know that this item is being moved or dragged
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemSelected();
}
}
super.onSelectedChanged(viewHolder, actionState);
}
项目:GitHub
文件:RecyclerViewHelper.java
/**
* 启动拖拽和滑动
* @param view 视图
* @param adapter 适配器
*/
public static void startDragAndSwipe(RecyclerView view, BaseQuickAdapter adapter) {
SimpleItemTouchHelperCallback callback = new SimpleItemTouchHelperCallback(adapter);
final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(view);
adapter.setDragStartListener(new OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
itemTouchHelper.startDrag(viewHolder);
}
});
adapter.setDragCallback(callback);
adapter.setDragColor(Color.LTGRAY);
}
项目:text_converter
文件:StylistFragment.java
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mGenerator = new StylistGenerator(getContext());
mInput = view.findViewById(R.id.edit_input);
mAdapter = new StyleAdapter(getActivity(), R.layout.list_item_style);
mAdapter.setOnSwapStyleListener(new OnSwapStyleListener() {
@Override
public void onSwap(int fromPosition, int toPosition) {
mGenerator.swapPosition(fromPosition, toPosition);
}
});
mListResult = view.findViewById(R.id.recycler_view);
mListResult.setLayoutManager(new LinearLayoutManager(getContext()));
mListResult.setHasFixedSize(true);
mListResult.setAdapter(mAdapter);
mListResult.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
ItemTouchHelperCallback callback = new ItemTouchHelperCallback(mAdapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(mListResult);
mInput.addTextChangedListener(this);
restore();
}
项目:GitHub
文件:SimpleItemTouchCallback.java
/**
* 状态改变时回调
*/
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
super.onSelectedChanged(viewHolder, actionState);
Log.i("Callback", actionState + "");
if(actionState != ItemTouchHelper.ACTION_STATE_IDLE){
NormalAdapter.VH holder = (NormalAdapter.VH)viewHolder;
holder.itemView.setBackgroundColor(0xffbcbcbc);
}
}
项目:Fairy
文件:MyItemTouchCallback.java
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
//滑动时改变 Item 的透明度,以实现滑动过程中实现渐变效果
final float alpha = 1 - Math.abs(dX) / (float) viewHolder.itemView.getWidth();
viewHolder.itemView.setAlpha(alpha);
viewHolder.itemView.setTranslationX(dX);
} else {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
}
项目:RetroMusicPlayer
文件:SwipeAndDragHelper.java
@Override
public void onChildDraw(Canvas c,
RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder,
float dX,
float dY,
int actionState,
boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
float alpha = 1 - (Math.abs(dX) / recyclerView.getWidth());
viewHolder.itemView.setAlpha(alpha);
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
项目:Rey-MusicPlayer
文件:SimpleItemTouchHelperCallback.java
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
// We only want the active item to change
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
if (viewHolder instanceof ItemTouchHelperViewHolder) {
ItemTouchHelperViewHolder itemViewHolder = (ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemSelected();
}
}
super.onSelectedChanged(viewHolder, actionState);
}
项目:MusicX-music-player
文件:TabRemoveFragment.java
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.playlist_picker, new LinearLayout(getActivity()), false);
rv = (RecyclerView) view.findViewById(R.id.rv);
btn = (Button) view.findViewById(R.id.create_playlist);
btn.setVisibility(View.GONE);
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
CustomLayoutManager customlayoutmanager = new CustomLayoutManager(getActivity());
customlayoutmanager.setOrientation(LinearLayoutManager.VERTICAL);
customlayoutmanager.setSmoothScrollbarEnabled(true);
rv.setLayoutManager(customlayoutmanager);
tabAdapter = new RemoveTabAdapter(getActivity(), this);
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(tabAdapter);
mItemTouchHelper = new ItemTouchHelper(callback);
mItemTouchHelper.attachToRecyclerView(rv);
List<String> data = new ArrayList<String>();
data.add("1. Recent");
data.add("2. Folder");
data.add("3. Song");
data.add("4. Album");
data.add("5. Artist");
data.add("6.Playlist");
tabAdapter.addDataList(data);
rv.setAdapter(tabAdapter);
builder.title("Tab Remove")
.autoDismiss(true)
.positiveText(R.string.okay)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
}
})
.customView(view, false);
return builder.show();
}
项目:OpenHub
文件:BookmarksFragment.java
@Override
protected void initFragment(Bundle savedInstanceState) {
super.initFragment(savedInstanceState);
setLoadMoreEnable(true);
ItemTouchHelperCallback callback = new ItemTouchHelperCallback(0,
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, this);
itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recyclerView);
}