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 mIgnoreUpEvent = false
private var mIgnoreMoveEvents = false
private var mIsIconLongPressed = false
private var mLongPressedIcon: HomeScreenGridItem? = null
private var mOpenPopupMenu: PopupMenu? = null
private var mCachedLaunchers = ArrayList<AppLauncher>()
@ -133,10 +133,10 @@ class MainActivity : SimpleActivity(), FlingListener {
}
MotionEvent.ACTION_MOVE -> {
if (mIsIconLongPressed && mOpenPopupMenu != null) {
if (mLongPressedIcon != null && mOpenPopupMenu != null) {
mOpenPopupMenu?.dismiss()
mOpenPopupMenu = null
home_screen_grid.itemDraggingStarted()
home_screen_grid.itemDraggingStarted(mLongPressedIcon!!)
}
if (mTouchDownY != -1 && !mIgnoreMoveEvents) {
@ -150,7 +150,7 @@ class MainActivity : SimpleActivity(), FlingListener {
MotionEvent.ACTION_UP -> {
mTouchDownY = -1
mIgnoreMoveEvents = false
mIsIconLongPressed = false
mLongPressedIcon = null
home_screen_grid.itemDraggingStopped()
if (!mIgnoreUpEvent) {
if (all_apps_fragment.y < mScreenHeight * 0.7) {
@ -233,7 +233,7 @@ class MainActivity : SimpleActivity(), FlingListener {
main_holder.performHapticFeedback()
val clickedGridItem = home_screen_grid.isClickingGridItem(x - home_screen_grid.marginLeft, y - home_screen_grid.marginTop)
if (clickedGridItem != null) {
mIsIconLongPressed = true
mLongPressedIcon = clickedGridItem
showHomeIconMenu(x, y, clickedGridItem.packageName)
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 labelSideMargin = context.resources.getDimension(R.dimen.small_margin).toInt()
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
private var rowXCoords = ArrayList<Int>(COLUMN_COUNT)
@ -63,13 +63,13 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
}
}
fun itemDraggingStarted() {
isDraggingItem = true
fun itemDraggingStarted(draggedGridItem: HomeScreenGridItem) {
draggedItem = draggedGridItem
invalidate()
}
fun itemDraggingStopped() {
isDraggingItem = false
draggedItem = null
invalidate()
}
@ -102,18 +102,20 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Vie
val drawableY = rowYCoords[item.top] + iconSize / 2
drawable.setBounds(drawableX, drawableY, drawableX + iconSize, drawableY + iconSize)
val textY = rowYCoords[item.top] + iconSize * 1.5f + labelSideMargin
val staticLayout = StaticLayout.Builder
.obtain(item.title, 0, item.title.length, textPaint, rowWidth - 2 * labelSideMargin)
.setMaxLines(2)
.setEllipsize(TextUtils.TruncateAt.END)
.setAlignment(Layout.Alignment.ALIGN_CENTER)
.build()
if (item.id != draggedItem?.id) {
val textY = rowYCoords[item.top] + iconSize * 1.5f + labelSideMargin
val staticLayout = StaticLayout.Builder
.obtain(item.title, 0, item.title.length, textPaint, rowWidth - 2 * labelSideMargin)
.setMaxLines(2)
.setEllipsize(TextUtils.TruncateAt.END)
.setAlignment(Layout.Alignment.ALIGN_CENTER)
.build()
canvas.save()
canvas.translate(rowXCoords[item.left].toFloat() + labelSideMargin, textY)
staticLayout.draw(canvas)
canvas.restore()
canvas.save()
canvas.translate(rowXCoords[item.left].toFloat() + labelSideMargin, textY)
staticLayout.draw(canvas)
canvas.restore()
}
}
drawable.draw(canvas)