fix: 홈 화면 위젯 우측/하단 잘림 및 내부 시스템 패딩 제거

- LauncherActivity.kt:
  * createWidget(): AppWidgetHostView 기본 시스템 패딩(보통 8dp)을 제거하기 위해 hostView.setPadding(0, 0, 0, 0) 적용
  * setupWidgetResizeOverlay(): widgetContainer.clipChildren = false, clipToPadding = false 설정으로 경계 핸들 잘림 방지
  * updateWidgetOptions(): 패딩을 제외한 순수 콘텐츠 영역 기준으로 Math.round(px / density) dp 계산
- WidgetResizeOverlay.kt:
  * onDraw(): 테두리 스트로크(halfStroke) 및 핸들 반지름(handleMargin)만큼 캔버스 경계 안쪽으로 클램핑해 우측/하단 끝선 및 핸들이 잘리지 않도록 개선
  * ACTION_MOVE 리사이즈 중 v.requestLayout() 호출로 즉각 레이아웃 갱신
- 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (19s, 133 actionable tasks)
This commit is contained in:
2026-11-16 13:48:51 +09:00
parent f99ad57870
commit 8a1485cac0
2 changed files with 22 additions and 7 deletions
@@ -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
@@ -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