diff --git a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt index 26af4f49..803df755 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/LauncherActivity.kt @@ -653,13 +653,13 @@ open class LauncherActivity : CommonActivity() { // } private fun updateWidgetOptions(appWidgetId: Int, hostView: AppWidgetHostView) { - val width = hostView.layoutParams.width - val height = hostView.layoutParams.height + val width = (hostView.layoutParams.width - hostView.paddingLeft - hostView.paddingRight).coerceAtLeast(1) + val height = (hostView.layoutParams.height - hostView.paddingTop - hostView.paddingBottom).coerceAtLeast(1) // DP 단위로 변환 (시스템은 픽셀이 아니라 DP를 기준으로 레이아웃을 결정함) val density = resources.displayMetrics.density - val widthDp = (width / density).toInt() - val heightDp = (height / density).toInt() + val widthDp = Math.round(width / density) + val heightDp = Math.round(height / density) val options = Bundle().apply { putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, widthDp) @@ -817,6 +817,8 @@ open class LauncherActivity : CommonActivity() { } } } + binding.widgetContainer.clipChildren = false + binding.widgetContainer.clipToPadding = false widgetResizeOverlay = overlay binding.widgetContainer.addView(overlay) } @@ -828,6 +830,8 @@ open class LauncherActivity : CommonActivity() { val hostView = appWidgetHost?.createView(applicationContext, appWidgetId, appWidgetInfo) hostView?.setAppWidget(appWidgetId, appWidgetInfo) + // AppWidgetHostView 기본 시스템 패딩(보통 8dp) 제거로 우측/하단 잘림 방지 + hostView?.setPadding(0, 0, 0, 0) // 크기 및 위치 설정 val width = savedWidgetData?.width ?: appWidgetInfo.minWidth diff --git a/app/src/main/kotlin/bums/lunatic/launcher/feeds/WidgetResizeOverlay.kt b/app/src/main/kotlin/bums/lunatic/launcher/feeds/WidgetResizeOverlay.kt index eacb389b..7a6b2730 100644 --- a/app/src/main/kotlin/bums/lunatic/launcher/feeds/WidgetResizeOverlay.kt +++ b/app/src/main/kotlin/bums/lunatic/launcher/feeds/WidgetResizeOverlay.kt @@ -112,11 +112,21 @@ class WidgetResizeOverlay(context: Context) : View(context) { super.onDraw(canvas) val r = getTargetRect() ?: return - canvas.drawRect(r, borderPaint) + val halfStroke = borderPaint.strokeWidth / 2f + val drawRect = RectF( + r.left.coerceIn(halfStroke, max(halfStroke, width - halfStroke)), + r.top.coerceIn(halfStroke, max(halfStroke, height - halfStroke)), + r.right.coerceIn(halfStroke, max(halfStroke, width - halfStroke)), + r.bottom.coerceIn(halfStroke, max(halfStroke, height - halfStroke)) + ) + canvas.drawRect(drawRect, borderPaint) + val handleMargin = handleRadius + handleStrokePaint.strokeWidth / 2f for ((_, pt) in getHandlePoints(r)) { - canvas.drawCircle(pt.first, pt.second, handleRadius, handleFillPaint) - canvas.drawCircle(pt.first, pt.second, handleRadius, handleStrokePaint) + val cx = pt.first.coerceIn(handleMargin, max(handleMargin, width - handleMargin)) + val cy = pt.second.coerceIn(handleMargin, max(handleMargin, height - handleMargin)) + canvas.drawCircle(cx, cy, handleRadius, handleFillPaint) + canvas.drawCircle(cx, cy, handleRadius, handleStrokePaint) } val wDp = (r.width() / density).toInt() @@ -200,6 +210,7 @@ class WidgetResizeOverlay(context: Context) : View(context) { lp.width = (newRight - newLeft).toInt().coerceAtLeast(minSizePx) lp.height = (newBottom - newTop).toInt().coerceAtLeast(minSizePx) v.layoutParams = lp + v.requestLayout() } invalidate() return true