draw a resizing line around widgets at long pressing

This commit is contained in:
tibbi 2022-10-02 15:26:10 +02:00
parent b5433b40a7
commit 24a4723bb2
2 changed files with 35 additions and 0 deletions

View File

@ -357,6 +357,10 @@ class MainActivity : SimpleActivity(), FlingListener {
val yOffset = resources.getDimension(R.dimen.long_press_anchor_button_offset_y) * (visibleMenuButtons - 1)
anchorView.y -= yOffset
if (gridItem.type == ITEM_TYPE_WIDGET) {
home_screen_grid.widgetLongPressed(gridItem)
}
val contextTheme = ContextThemeWrapper(this, getPopupMenuTheme())
return PopupMenu(contextTheme, anchorView, Gravity.TOP or Gravity.END).apply {
setForceShowIcon(true)
@ -377,6 +381,10 @@ class MainActivity : SimpleActivity(), FlingListener {
setOnDismissListener {
mOpenPopupMenu = null
(all_apps_fragment as AllAppsFragment).ignoreTouches = false
if (gridItem.type == ITEM_TYPE_WIDGET) {
home_screen_grid.hideResizeLines()
}
}
show()

View File

@ -32,7 +32,9 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
private var roundedCornerRadius = context.resources.getDimension(R.dimen.activity_margin)
private var textPaint: TextPaint
private var dragShadowCirclePaint: Paint
private var resizeWidgetLinePaint: Paint
private var draggedItem: HomeScreenGridItem? = null
private var resizedWidget: HomeScreenGridItem? = null
private var isFirstDraw = true
// let's use a 6x5 grid for now with 1 special row at the bottom, prefilled with default apps
@ -66,6 +68,12 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
style = Paint.Style.STROKE
}
resizeWidgetLinePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.WHITE
strokeWidth = context.resources.getDimension(R.dimen.tiny_margin)
style = Paint.Style.STROKE
}
val sideMargin = context.resources.getDimension(R.dimen.normal_margin).toInt()
sideMargins.apply {
top = context.statusBarHeight
@ -164,6 +172,16 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
}
}
fun widgetLongPressed(item: HomeScreenGridItem) {
resizedWidget = item
redrawGrid()
}
fun hideResizeLines() {
resizedWidget = null
redrawGrid()
}
private fun addAppIcon() {
val center = gridCenters.minBy {
Math.abs(it.first - draggedItemCurrentCoords.first + sideMargins.left) + Math.abs(it.second - draggedItemCurrentCoords.second + sideMargins.top)
@ -532,6 +550,15 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
}
}
if (resizedWidget != null) {
val widgetView = widgetViews.firstOrNull { it.tag == resizedWidget!!.widgetId }
if (widgetView != null) {
val viewX = widgetView.x.toInt()
val viewY = widgetView.y.toInt()
canvas.drawRect(Rect(viewX, viewY, viewX + widgetView.width, viewY + widgetView.height), resizeWidgetLinePaint)
}
}
isFirstDraw = false
}