/** * Find the view under the pointer. */ private View getViewAtPosition(int x, int y) { final int count = getChildCount(); View child; for (int childIdx = 0; childIdx < count; childIdx++) { child = getChildAt(childIdx); if (y >= child.getTop() && y <= child.getBottom() && x >= child.getLeft() && x <= child.getRight()) { return child; } } return null; }
private void ensureScrollHandler() { if (mScrollHandler == null) { mScrollHandler = getHandler(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_simple); mSimpleTileAdapter = new SimpleTileAdapter(this, this, new TileView.OnSelectedListener() { @Override public void onTileSelected(IDragEntity entity) { Toast.makeText(SimpleActivity.this, ((SimpleDragEntity) entity).getName(), Toast.LENGTH_SHORT).show(); } }); //TODO :set data source mSimpleTileAdapter.setData(obtainData()); mListView = (DragDropListView) findViewById(R.id.list_view); mListView.setVerticalScrollBarEnabled(false); mListView.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT); mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY); mListView.getDragDropController().addOnDragDropListener(mSimpleTileAdapter); final ImageView dragShadowOverlay = (ImageView) findViewById(R.id.tile_drag_shadow_overlay); mListView.setDragShadowOverlay(dragShadowOverlay); final LayoutAnimationController controller = new LayoutAnimationController( AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); controller.setDelay(0); mListView.setLayoutAnimation(controller); mListView.setAdapter(mSimpleTileAdapter); }
(Math.abs(mLastDragY - mTouchDownForDragStartY) >= 4 * mTouchSlop)) { mIsDragScrollerRunning = true; ensureScrollHandler(); mScrollHandler.postDelayed(mDragScroller, SCROLL_HANDLER_DELAY_MILLIS); final int boundGap = (int) (getHeight() * BOUND_GAP_RATIO); mTopScrollBound = (getTop() + boundGap); mBottomScrollBound = (getBottom() - boundGap); break; case DragEvent.ACTION_DRAG_EXITED: case DragEvent.ACTION_DRAG_ENDED: case DragEvent.ACTION_DROP: ensureScrollHandler(); mScrollHandler.removeCallbacks(mDragScroller); mIsDragScrollerRunning = false;
private void saveOffsets() { final int firstVisiblePosition = mDragDropListener.getDragDropListView().getFirstVisiblePosition(); for (int i = 0; i < mDragDropListener.getDragDropListView().getChildCount(); i++) { final View child = mDragDropListener.getDragDropListView().getChildAt(i); final int position = firstVisiblePosition + i; if (!isIndexInBound(position)) { continue; } final long itemId = getItemId(position); // Log.d(TAG, "Saving itemId: " + itemId + " for listview child " + i + " Top: " // + child.getTop() + " Left: " // + child.getLeft()); mItemIdTopMap.put(itemId, child.getTop()); mItemIdLeftMap.put(itemId, child.getLeft()); } }
@Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop(); }
@Override public void onDragStarted(int x, int y, View tileView) { if (mDragShadowOverlay == null) { return; } mDragShadowOverlay.clearAnimation(); mDragShadowBitmap = createDraggedChildBitmap(tileView); if (mDragShadowBitmap == null) { return; } tileView.getLocationOnScreen(mLocationOnScreen); mDragShadowLeft = mLocationOnScreen[0]; mDragShadowTop = mLocationOnScreen[1]; // To offset the drag shadow position, this looks under finger. mTouchOffsetToChildLeft = x - mDragShadowLeft; mTouchOffsetToChildTop = y - mDragShadowTop; mDragShadowParent.getLocationOnScreen(mLocationOnScreen); mDragShadowLeft -= mLocationOnScreen[0]; mDragShadowTop -= mLocationOnScreen[1]; mDragShadowOverlay.setImageBitmap(mDragShadowBitmap); mDragShadowOverlay.setVisibility(VISIBLE); mDragShadowOverlay.setAlpha(DRAG_SHADOW_ALPHA); mDragShadowOverlay.setX(mDragShadowLeft); mDragShadowOverlay.setY(mDragShadowTop); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_thumbtack); mThumbtackTileAdapter = new ThumbtackTileAdapter(this, this, new TileView.OnSelectedListener() { @Override public void onTileSelected(IDragEntity entity) { Toast.makeText(ThumbtackActivity.this, ((SimpleDragEntity) entity).getName(), Toast.LENGTH_SHORT).show(); } }); //TODO :set data source mThumbtackTileAdapter.setData(obtainData()); mListView = (DragDropListView) findViewById(R.id.list_view); mListView.setVerticalScrollBarEnabled(false); mListView.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT); mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY); mListView.getDragDropController().addOnDragDropListener(mThumbtackTileAdapter); final ImageView dragShadowOverlay = (ImageView) findViewById(R.id.tile_drag_shadow_overlay); mListView.setDragShadowOverlay(dragShadowOverlay); final LayoutAnimationController controller = new LayoutAnimationController( AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); controller.setDelay(0); mListView.setLayoutAnimation(controller); mListView.setAdapter(mThumbtackTileAdapter); }
public boolean onPreDraw() { observer.removeOnPreDrawListener(this); final int firstVisiblePosition = mDragDropListener.getDragDropListView().getFirstVisiblePosition(); for (int i = 0; i < mDragDropListener.getDragDropListView().getChildCount(); i++) { final View child = mDragDropListener.getDragDropListView().getChildAt(i); int position = firstVisiblePosition + i;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_single_row); mSimpleTileAdapter = new SimpleTileAdapter(this, this, new TileView.OnSelectedListener() { @Override public void onTileSelected(IDragEntity entity) { Toast.makeText(SingleRowActivity.this, ((SimpleDragEntity) entity).getName(), Toast.LENGTH_SHORT).show(); } }); //TODO :set data source mSimpleTileAdapter.setData(obtainData()); mListView = (DragDropListView) findViewById(R.id.list_view); mListView.setVerticalScrollBarEnabled(false); mListView.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT); mListView.setScrollBarStyle(ListView.SCROLLBARS_OUTSIDE_OVERLAY); mListView.getDragDropController().addOnDragDropListener(mSimpleTileAdapter); final ImageView dragShadowOverlay = (ImageView) findViewById(R.id.tile_drag_shadow_overlay); mListView.setDragShadowOverlay(dragShadowOverlay); final LayoutAnimationController controller = new LayoutAnimationController( AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); controller.setDelay(0); mListView.setLayoutAnimation(controller); mListView.setAdapter(mSimpleTileAdapter); }