(转)Launcher长按拖拽流程(二)

图标拖动

上篇文章简单讲述了图标的拖动流程,关于回调里的并没有介绍。(因为我也蒙蔽,哈哈哈,看着各种坐标、各种变量、头很大)but,在小编的不断努力

(注释掉代码看效果)下,逐渐有了一点点眉目。在这里和各位盆友分享一下。

由于是调试总结出来的文章,小编只能从可见的功能上给大家做一介绍。在此,非常抱歉没有一个好的功底来完全熟悉后来写。只能慢慢补充

如果有更详细的介绍的blog,欢迎留言告诉我,大家共同进步。

1、关于dropTarget.onDragOver( mDragObject );

当长按起桌面图标,移动时,经过空位置、其他图标、文件夹,都是workspace的onDragOver

从功能上看,分为1、拖动到另一个图标上创建一个个文件夹虚影;2、拖动到另一个图标附近挤走原本的图标


   
   
  1. //获得拖动图标的视觉中心位置
  2. mDragViewVisualCenter = getDragViewVisualCenter( d.x , d.y , d.xOffset , d.yOffset , d.dragView , mDragViewVisualCenter );

   
   
  1. //拖动的时候也要判断当前位置Layout的是处于翻动的页面还是Hotseat中,确定mDragTargetLayout
  2. // Test to see if we are over the hotseat otherwise just use the current page
  3. if( mLauncher.getHotseat() != null && !isDragWidget( d ) )
  4. {
  5. if( isPointInSelfOverHotseat( d.x , d.y , r ) )
  6. {
  7. layout = mLauncher.getHotseat().getLayout();
  8. }
  9. }
  10. if( layout == null )
  11. {
  12. layout = getCurrentDropLayout();
  13. }
  14. if( layout != mDragTargetLayout )
  15. {
  16. setCurrentDropLayout( layout );
  17. setCurrentDragOverlappingLayout( layout );
  18. }

   
   
  1. //findNearestArea方法根据mDragViewVisualCenter先大致当前的落点
  2. mTargetCell = findNearestArea( (int)mDragViewVisualCenter[0] , (int)mDragViewVisualCenter[1] , minSpanX , minSpanY , mDragTargetLayout , mTargetCell );

   
   
  1. //管理文件夹反馈(修改mDragMode)。是否生成文件夹虚影,是否添加到文件夹,都是这里判断的
  2. manageFolderFeedback( info , mDragTargetLayout , mTargetCell , targetCellDistance , dragOverView );
  3. //落点位置是否被占用
  4. boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied(
  5. (int)mDragViewVisualCenter[0] ,
  6. (int)mDragViewVisualCenter[1] ,
  7. item.getSpanX() ,
  8. item.getSpanY() ,
  9. child ,
  10. mTargetCell );
  11. if( !nearestDropOccupied )
  12. {
  13. mDragTargetLayout.visualizeDropLocation(
  14. child ,
  15. mDragOutline ,
  16. (int)mDragViewVisualCenter[0] ,
  17. (int)mDragViewVisualCenter[1] ,
  18. mTargetCell[0] ,
  19. mTargetCell[1] ,
  20. item.getSpanX() ,
  21. item.getSpanY() ,
  22. false ,
  23. d.dragView.getDragVisualizeOffset() ,
  24. d.dragView.getDragRegion() );
  25. }
  26. else if( ( mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER ) && !mReorderAlarm.alarmPending() && ( mLastReorderX != reorderX || mLastReorderY != reorderY ) )
  27. {//位置被占用,把图标挤走,并且挤走的图标来回晃动逻辑在这里
  28. // Otherwise, if we aren't adding to or creating a folder and there's no pending
  29. // reorder, then we schedule a reorder
  30. ReorderAlarmListener listener = new ReorderAlarmListener( mDragViewVisualCenter , minSpanX , minSpanY , item.getSpanX() , item.getSpanY() , d.dragView , child );
  31. mReorderAlarm.setIOnAlarmListener( listener );
  32. mReorderAlarm.setAlarm( REORDER_TIMEOUT );
  33. }
  34. if( mDragMode == DRAG_MODE_CREATE_FOLDER || mDragMode == DRAG_MODE_ADD_TO_FOLDER || !nearestDropOccupied )
  35. {
  36. if( mDragTargetLayout != null )
  37. {
  38. mDragTargetLayout.revertTempState();
  39. }
  40. }
FolderCreationAlarmListener:文件夹创建动画监听。监听的处理都在onAlarm方法里。文件夹的预览图在Folder的onDraw里:


   
   
  1. int centerX = mTempLocation[0] + mCellWidth / 2;
  2. //文件夹预览图(一个图标覆盖到另一个图标或者文件夹上会生成文件夹预览图)的图标在绘制时的中心点的y坐标
  3. int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop() + grid.folderBackgroundOffset;//xiatian add note //桌面图标显示的样式(详见BaseDefaultConfig.java中的“ITEM_STYLE_XXX”)。//BubbleTextView重载方法“getPaddingTop”
  4. // Draw outer ring, if it exists
  5. if( FolderIcon.HAS_OUTER_RING )
  6. {
  7. d = FolderRingAnimator.sSharedOuterRingDrawable;//文件夹预览图
  8. width = (int)( fra.getOuterRingWidthSize() * getChildrenScale() );
  9. height = (int)( fra.getOuterRingHeightSize() * getChildrenScale() );
  10. canvas.save();
  11. canvas.translate( centerX - width / 2 , centerY - height / 2 );
  12. d.setBounds( 0 , 0 , width , height );
  13. d.draw( canvas );
  14. canvas.restore();
  15. }

ReorderAlarmListener:重新排序动画监听。监听的处理都在onAlarm方法里。mDragTargetLayout.createArea(里,是把图标挤走和晃动的逻辑:


   
   
  1. // If we're just testing for a possible location (MODE_ACCEPT_DROP), we don't bother
  2. // committing anything or animating anything as we just want to determine if a solution
  3. // exists
  4. if( mode == MODE_DRAG_OVER || mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL )
  5. {
  6. if( !DESTRUCTIVE_REORDER )
  7. {
  8. copySolutionToTempState( finalSolution , dragView ); //记录被挤走的图标的位置
  9. }
  10. setItemPlacementDirty( true );
  11. animateItemsToSolution( finalSolution , dragView , mode == MODE_ON_DROP ); //把图标挤走
  12. if( !DESTRUCTIVE_REORDER && ( mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL ) )
  13. {
  14. commitTempPlacement();
  15. completeAndClearReorderHintAnimations();
  16. setItemPlacementDirty( false );
  17. }
  18. else
  19. {
  20. beginOrAdjustHintAnimations( finalSolution , dragView , REORDER_ANIMATION_DURATION ); //被挤走的图标晃啊晃的动画
  21. }
  22. }

2、关于dropTarget.onDragEnter( mDragObject );和mLastDropTarget.onDragExit( mDragObject );

当图标移动到(拖出)垃圾筐或者应用信息框上时,文字和图标变色功能介绍

回调在在DeleteDropTarget和InfoDropTarget里

卸载框:


   
   
  1. public void onDragEnter(
  2. DragObject d )
  3. {
  4. super.onDragEnter( d );
  5. mCurrentDrawable.startTransition( mTransitionDuration );
  6. setTextColor( mHoverColor );//当图标进入卸载框时,改变文字颜色
  7. }


   
   
  1. public void onDragExit(
  2. DragObject d )
  3. {
  4. super.onDragExit( d );
  5. if( !d.dragComplete )
  6. {
  7. mCurrentDrawable.resetTransition();
  8. setTextColor( mOriginalTextColor ); //当图标拖出卸载框时,还原文字颜色
  9. }
  10. else
  11. {
  12. // Restore the hover color if we are deleting
  13. d.dragView.setColor( mHoverColor );
  14. }
  15. }

应用信息框:


   
   
  1. public void onDragEnter(
  2. DragObject d )
  3. {
  4. super.onDragEnter( d );
  5. mDrawable.startTransition( mTransitionDuration );
  6. setTextColor( mHoverColor ); //当图标进入应用信息框时,改变文字颜色
  7. }


   
   
  1. public void onDragExit(
  2. DragObject d )
  3. {
  4. super.onDragExit( d );
  5. if( !d.dragComplete )
  6. {
  7. mDrawable.resetTransition();
  8. setTextColor( mOriginalTextColor ); //当图标拖出应用信息框时,还原文字颜色
  9. }
  10. }

他们都是调用了父类的方法并且改变的文字的颜色。

父类onDragEnter:


   
   
  1. public void onDragEnter(
  2. DragObject d )
  3. {
  4. d.dragView.setColor( mHoverColor ); //当图标拖入时,修改图标颜色
  5. }


   
   
  1. public void onDragExit(
  2. DragObject d )
  3. {
  4. d.dragView.setColor( 0 ); //当图标拖出时,修改图标颜色
  5. }

以上就是长按 图标进入或者拖出时,颜色的变化功能。

尾注:

暂时就跟踪代码呆这里,如果有进展,会持续更新。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值