/*
* Copyright (C) 2015 Haruki Hasegawa
*
* 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.
*/
package com.h6ah4i.android.widget.advrecyclerview.draggable;
import android.graphics.Rect;
import android.graphics.drawable.NinePatchDrawable;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.FloatRange;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import com.h6ah4i.android.widget.advrecyclerview.adapter.AdapterPath;
import com.h6ah4i.android.widget.advrecyclerview.adapter.ItemIdComposer;
import com.h6ah4i.android.widget.advrecyclerview.utils.CustomRecyclerViewUtils;
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
/**
* Provides item drag & drop operation for {@link android.support.v7.widget.RecyclerView}
*/
@SuppressWarnings("PointlessBitwiseExpression")
public class RecyclerViewDragDropManager implements DraggableItemConstants {
private static final String TAG = "ARVDragDropManager";
/**
* Default interpolator used for "swap target transition"
*/
public static final Interpolator DEFAULT_SWAP_TARGET_TRANSITION_INTERPOLATOR = new BasicSwapTargetTranslationInterpolator();
/**
* Default interpolator used for "item settle back into place" animation
*/
public static final Interpolator DEFAULT_ITEM_SETTLE_BACK_INTO_PLACE_ANIMATION_INTERPOLATOR = new DecelerateInterpolator();
@Retention(RetentionPolicy.SOURCE)
@IntDef({ITEM_MOVE_MODE_DEFAULT, ITEM_MOVE_MODE_SWAP})
public @interface ItemMoveMode {
}
/**
* Default item move mode
*/
public static final int ITEM_MOVE_MODE_DEFAULT = 0;
/**
* Swap two items between dragging item and the item under a finger (or mouse pointer)
*/
public static final int ITEM_MOVE_MODE_SWAP = 1;
// ---
/**
* Used for listening item drag events
*/
public interface OnItemDragEventListener {
/**
* Callback method to be invoked when dragging is started.
*
* @param position The position of the item.
*/
void onItemDragStarted(int position);
/**
* Callback method to be invoked when item position is changed during drag.
*
* @param fromPosition The old position of the item.
* @param toPosition The new position of the item
*/
void onItemDragPositionChanged(int fromPosition, int toPosition);
/**
* Callback method to be invoked when dragging is finished.
*
* @param fromPosition Previous position of the item.
* @param toPosition New position of the item.
* @param result Indicates whether the dragging operation was succeeded.
*/
void onItemDragFinished(int fromPosition, int toPosition, boolean result);
/**
* Callback method to be invoked when the distance of currently dragging item is updated.
*
* @param offsetX The horizontal distance of currently dragging item from the initial position in pixels.
* @param offsetY The vertical distance of currently dragging item from the initial position in pixels.
*/
void onItemDragMoveDistanceUpdated(int offsetX, int offsetY);
}
// --
private static final int SCROLL_DIR_NONE = 0;
private static final int SCROLL_DIR_UP = (1 << 0);
private static final int SCROLL_DIR_DOWN = (1 << 1);
private static final int SCROLL_DIR_LEFT = (1 << 2);
private static final int SCROLL_DIR_RIGHT = (1 << 3);
private static final boolean LOCAL_LOGV = false;
private static final boolean LOCAL_LOGD = false;
private static final boolean LOCAL_LOGI = true;
private static final float SCROLL_THRESHOLD = 0.3f; // 0.0f < X < 0.5f
private static final float SCROLL_AMOUNT_COEFF = 25;
private static final float SCROLL_TOUCH_SLOP_MULTIPLY = 1.5f;
static class SwapTarget {
public RecyclerView.ViewHolder holder;
public int position;
public boolean self;
public void clear() {
holder = null;
position = RecyclerView.NO_POSITION;
self = false;
}
}
static class FindSwapTargetContext {
public RecyclerView rv;
public DraggingItemInfo draggingItemInfo;
public RecyclerView.ViewHolder draggingItem;
public int lastTouchX;
public int lastTouchY;
public int overlayItemLeft;
public int overlayItemTop;
public int overlayItemLeftNotClipped;
public int overlayItemTopNotClipped;
public int layoutType;
public boolean vertical;
public ItemDraggableRange wrappedAdapterRange;
public ItemDraggableRange rootAdapterRange;
public boolean checkCanSwap;
public void setup(
RecyclerView rv, RecyclerView.ViewHolder vh,
DraggingItemInfo info, int lastTouchX, int lastTouchY,
ItemDraggableRange wrappedAdapterPange,
ItemDraggableRange rootAdapterRange,
boolean checkCanSwap) {
this.rv = rv;
this.draggingItemInfo = info;
this.draggingItem = vh;
this.lastTouchX = lastTouchX;
this.lastTouchY = lastTouchY;
this.wrappedAdapterRange = wrappedAdapterPange;
this.rootAdapterRange = rootAdapterRange;
this.checkCanSwap = checkCanSwap;
this.layoutType = CustomRecyclerViewUtils.getLayoutType(rv);
this.vertical = CustomRecyclerViewUtils.extractOrientation(this.layoutType) == CustomRecyclerViewUtils.ORIENTATION_VERTICAL;
this.overlayItemLeft = this.overlayItemLeftNotClipped = lastTouchX - info.grabbedPositionX;
this.overlayItemTop = this.overlayItemTopNotClipped = lastTouchY - info.grabbedPositionY;
if (this.vertical) {
this.overlayItemLeft = Math.max(this.overlayItemLeft, rv.getPaddingLeft());
this.overlayItemLeft = Math.min(this.overlayItemLeft, Math.max(0, rv.getWidth() - rv.getPaddingRight() - draggingItemInfo.width));
} else {
this.overlayItemTop = Math.max(this.overlayItemTop, rv.getPaddingTop());
this.overlayItemTop = Math.min(this.overlayItemTop, Math.max(0, rv.getHeight() - rv.getPaddingBottom() - draggingItemInfo.height));
}
}
public void clear() {
this.rv = null;
this.draggingItemInfo = null;
this.draggingItem = null;
}
}
private RecyclerView mRecyclerView;
private Interpolator mSwapTargetTranslationInterpolator = DEFAULT_SWAP_TARGET_TRANSITION_INTERPOLATOR;
private
没有合适的资源?快使用搜索试试~ 我知道了~
RecyclerView进阶使用-实现仿支付宝菜单编辑页面拖拽功能(改版)
共225个文件
java:135个
png:49个
xml:23个
需积分: 1 37 下载量 63 浏览量
2020-07-20
10:27:14
上传
评论 1
收藏 2.73MB ZIP 举报
温馨提示
RecyclerView进阶使用-实现仿支付宝菜单编辑页面拖拽功能, 这个是改版后的代码,代码包更小。 详细的说明在http://blog.csdn.net/cjs1534717040/article/details/78459821, 现在将这个代码设为免费,谢谢支持
资源推荐
资源详情
资源评论
收起资源包目录
RecyclerView进阶使用-实现仿支付宝菜单编辑页面拖拽功能(改版) (225个子文件)
adb 0B
gradlew.bat 2KB
effect.gif 1.92MB
.gitignore 127B
.gitignore 8B
.gitignore 8B
build.gradle 905B
build.gradle 741B
build.gradle 521B
settings.gradle 116B
gradlew 5KB
fastjson-1.2.38.jar 514KB
gradle-wrapper.jar 52KB
RecyclerViewDragDropManager.java 83KB
RecyclerViewExpandableItemManager.java 51KB
ExpandableRecyclerViewWrapperAdapter.java 48KB
RecyclerViewSwipeManager.java 41KB
ItemSlidingAnimator.java 24KB
ComposedAdapter.java 22KB
ExpandablePositionTranslator.java 22KB
DraggingItemDecorator.java 19KB
SwipeableItemConstants.java 17KB
DraggableItemWrapperAdapter.java 17KB
AbstractHeaderFooterWrapperAdapter.java 16KB
CustomRecyclerViewUtils.java 16KB
SwipeableItemWrapperAdapter.java 14KB
RefactoredDefaultItemAnimator.java 12KB
ExpandableItemAdapter.java 12KB
SwipeableItemViewHolder.java 11KB
GeneralItemAnimator.java 11KB
SimpleWrapperAdapter.java 11KB
MenuHelper.java 10KB
SwapTargetItemOperator.java 10KB
BaseHeaderFooterRecyclerAdapterWrapper.java 9KB
MenuRecyclerListHeaderWrapper.java 9KB
AppHeadBar.java 9KB
RemovingItemDecorator.java 9KB
BridgeAdapterDataObserver.java 9KB
ItemIdComposer.java 8KB
BaseItemAnimationManager.java 8KB
WrapperAdapterUtils.java 8KB
FingerPrintDialog.java 8KB
BaseExpandableSwipeableItemAdapter.java 7KB
BaseRecyclerViewEventDistributor.java 7KB
BaseDraggableItemDecorator.java 7KB
RecyclerViewTouchActionGuardManager.java 7KB
EditActivity.java 7KB
SwipingItemOperator.java 6KB
BaseEdgeEffectDecorator.java 6KB
SwipeDismissItemAnimator.java 6KB
SimpleListDividerDecorator.java 6KB
ExpandableDraggableItemAdapter.java 6KB
SegmentedPositionTranslator.java 5KB
DebugWrapperAdapter.java 5KB
ItemViewTypeComposer.java 5KB
AbstractSwipeableItemViewHolder.java 5KB
AbstractExpandableItemAdapter.java 5KB
AdaptersSet.java 5KB
BaseItemAnimator.java 4KB
SwipeableItemAdapter.java 4KB
AbstractDialogFragment.java 4KB
MenuHeaderRecyclerGridAdapter.java 4KB
MainActivity.java 4KB
FingerPrintHelper.java 4KB
BaseSimpleRecyclerAdapter.java 4KB
BaseDraggableRecyclerAdapter.java 4KB
ItemShadowDecorator.java 4KB
ItemChangeAnimationManager.java 3KB
ExpandableSwipeableItemAdapter.java 3KB
MenuRecyclerListAdapter.java 3KB
WrappedAdapter.java 3KB
AdapterPath.java 3KB
SwipeableItemReactions.java 3KB
DraggingItemInfo.java 3KB
SegmentedViewTypeTranslator.java 3KB
DraggableItemAdapter.java 3KB
WrappedAdapterUtils.java 3KB
RecyclerViewRecyclerEventDistributor.java 3KB
DrawableKit.java 2KB
RecyclerViewAdapterUtils.java 2KB
ItemMoveAnimationManager.java 2KB
ItemRemoveAnimationManager.java 2KB
ItemAddAnimationManager.java 2KB
ImageKit.java 2KB
ExpandableItemConstants.java 2KB
MenuItem.java 2KB
ChangeAnimationInfo.java 2KB
SwipeReactionUtils.java 2KB
DraggableItemViewHolder.java 2KB
ExpandableItemViewHolder.java 2KB
WrapperAdapter.java 2KB
DraggableItemConstants.java 2KB
EditItem.java 2KB
SwipeResultAction.java 2KB
UnwrapPositionResult.java 2KB
MoveAnimationInfo.java 2KB
ComposedChildAdapterDataObserver.java 2KB
MenuRecyclerGridAdapter.java 2KB
BasicSwapTargetTranslationInterpolator.java 2KB
ExpandableAdapterHelper.java 2KB
共 225 条
- 1
- 2
- 3
资源评论
森之千手
- 粉丝: 61
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功