hide dragged icons label during drag

This commit is contained in:
tibbi 2022-09-21 15:35:09 +02:00
parent 0c9edeaa51
commit 4667cc447c
2 changed files with 22 additions and 20 deletions

View File

@ -43,7 +43,7 @@ class MainActivity : SimpleActivity(), FlingListener {
private var mScreenHeight = 0 private var mScreenHeight = 0
private var mIgnoreUpEvent = false private var mIgnoreUpEvent = false
private var mIgnoreMoveEvents = false private var mIgnoreMoveEvents = false
private var mIsIconLongPressed = false private var mLongPressedIcon: HomeScreenGridItem? = null
private var mOpenPopupMenu: PopupMenu? = null private var mOpenPopupMenu: PopupMenu? = null
private var mCachedLaunchers = ArrayList<AppLauncher>() private var mCachedLaunchers = ArrayList<AppLauncher>()
@ -133,10 +133,10 @@ class MainActivity : SimpleActivity(), FlingListener {
} }
MotionEvent.ACTION_MOVE -> { MotionEvent.ACTION_MOVE -> {
if (mIsIconLongPressed && mOpenPopupMenu != null) { if (mLongPressedIcon != null && mOpenPopupMenu != null) {
mOpenPopupMenu?.dismiss() mOpenPopupMenu?.dismiss()
mOpenPopupMenu = null mOpenPopupMenu = null
home_screen_grid.itemDraggingStarted() home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
} }
if (mTouchDownY != -1 && !mIgnoreMoveEvents) { if (mTouchDownY != -1 && !mIgnoreMoveEvents) {
@ -150,7 +150,7 @@ class MainActivity : SimpleActivity(), FlingListener {
MotionEvent.ACTION_UP -> { MotionEvent.ACTION_UP -> {
mTouchDownY = -1 mTouchDownY = -1
mIgnoreMoveEvents = false mIgnoreMoveEvents = false
mIsIconLongPressed = false mLongPressedIcon = null
home_screen_grid.itemDraggingStopped() home_screen_grid.itemDraggingStopped()
if (!mIgnoreUpEvent) { if (!mIgnoreUpEvent) {
if (all_apps_fragment.y < mScreenHeight * 0.7) { if (all_apps_fragment.y < mScreenHeight * 0.7) {
@ -233,7 +233,7 @@ class MainActivity : SimpleActivity(), FlingListener {
main_holder.performHapticFeedback() main_holder.performHapticFeedback()
val clickedGridItem = home_screen_grid.isClickingGridItem(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop) val clickedGridItem = home_screen_grid.isClickingGridItem(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
if (clickedGridItem != null) { if (clickedGridItem != null) {
mIsIconLongPressed = true mLongPressedIcon = clickedGridItem
showHomeIconMenu(x, y, clickedGridItem.packageName) showHomeIconMenu(x, y, clickedGridItem.packageName)
return return
} }

View File

@ -26,7 +26,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
private var iconMargin = context.resources.getDimension(R.dimen.icon_side_margin).toInt() private var iconMargin = context.resources.getDimension(R.dimen.icon_side_margin).toInt()
private var labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt() private var labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
private var textPaint: TextPaint private var textPaint: TextPaint
private var isDraggingItem = false private var draggedItem: HomeScreenGridItem? = null
// let's use a 6x5 grid for now with 1 special row at the bottom, prefilled with default apps // let's use a 6x5 grid for now with 1 special row at the bottom, prefilled with default apps
private var rowXCoords = ArrayList<Int>(COLUMN_COUNT) private var rowXCoords = ArrayList<Int>(COLUMN_COUNT)
@ -63,13 +63,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
} }
} }
fun itemDraggingStarted() { fun itemDraggingStarted(draggedGridItem: HomeScreenGridItem) {
isDraggingItem = true draggedItem = draggedGridItem
invalidate() invalidate()
} }
fun itemDraggingStopped() { fun itemDraggingStopped() {
isDraggingItem = false draggedItem = null
invalidate() invalidate()
} }
@ -102,6 +102,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
val drawableY = rowYCoords[item.top] + iconSize / 2 val drawableY = rowYCoords[item.top] + iconSize / 2
drawable.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize) drawable.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
if (item.id != draggedItem?.id) {
val textY = rowYCoords[item.top] + iconSize * 1.5f + labelSideMargin val textY = rowYCoords[item.top] + iconSize * 1.5f + labelSideMargin
val staticLayout = StaticLayout.Builder val staticLayout = StaticLayout.Builder
.obtain(item.title, 0, item.title.length, textPaint, rowWidth - 2 * labelSideMargin) .obtain(item.title, 0, item.title.length, textPaint, rowWidth - 2 * labelSideMargin)
@ -115,6 +116,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
staticLayout.draw(canvas) staticLayout.draw(canvas)
canvas.restore() canvas.restore()
} }
}
drawable.draw(canvas) drawable.draw(canvas)
} }