adding some resizing improvements
This commit is contained in:
parent
71b4deced1
commit
fd6fe125a9
|
@ -17,7 +17,6 @@ import androidx.core.graphics.drawable.toDrawable
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.helpers.isSPlus
|
import com.simplemobiletools.commons.helpers.isSPlus
|
||||||
import com.simplemobiletools.commons.helpers.mydebug
|
|
||||||
import com.simplemobiletools.launcher.R
|
import com.simplemobiletools.launcher.R
|
||||||
import com.simplemobiletools.launcher.activities.MainActivity
|
import com.simplemobiletools.launcher.activities.MainActivity
|
||||||
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
|
import com.simplemobiletools.launcher.extensions.getDrawableForPackageName
|
||||||
|
@ -190,7 +189,6 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
}
|
}
|
||||||
|
|
||||||
resize_frame.onResizeListener = { cellsRect ->
|
resize_frame.onResizeListener = { cellsRect ->
|
||||||
mydebug("resized to $cellsRect")
|
|
||||||
val minWidth = (cellsRect.width() + 1) * cellWidth
|
val minWidth = (cellsRect.width() + 1) * cellWidth
|
||||||
val minHeight = (cellsRect.height() + 1) * cellHeight
|
val minHeight = (cellsRect.height() + 1) * cellHeight
|
||||||
widgetView.updateAppWidgetSize(Bundle(), minWidth, minHeight, minWidth, minHeight)
|
widgetView.updateAppWidgetSize(Bundle(), minWidth, minHeight, minWidth, minHeight)
|
||||||
|
@ -237,8 +235,8 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
var areAllCellsEmpty = true
|
var areAllCellsEmpty = true
|
||||||
val wantedCell = Pair(xIndex, yIndex)
|
val wantedCell = Pair(xIndex, yIndex)
|
||||||
gridItems.forEach { item ->
|
gridItems.forEach { item ->
|
||||||
for (xCell in item.left .. item.right) {
|
for (xCell in item.left..item.right) {
|
||||||
for (yCell in item.top .. item.bottom) {
|
for (yCell in item.top..item.bottom) {
|
||||||
val cell = Pair(xCell, yCell)
|
val cell = Pair(xCell, yCell)
|
||||||
val isAnyCellOccupied = wantedCell == cell
|
val isAnyCellOccupied = wantedCell == cell
|
||||||
if (isAnyCellOccupied) {
|
if (isAnyCellOccupied) {
|
||||||
|
@ -311,16 +309,16 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
if (gridCells != null) {
|
if (gridCells != null) {
|
||||||
val widgetRect = getWidgetOccupiedRect(gridCells)
|
val widgetRect = getWidgetOccupiedRect(gridCells)
|
||||||
val widgetTargetCells = ArrayList<Pair<Int, Int>>()
|
val widgetTargetCells = ArrayList<Pair<Int, Int>>()
|
||||||
for (xCell in widgetRect.left .. widgetRect.right) {
|
for (xCell in widgetRect.left..widgetRect.right) {
|
||||||
for (yCell in widgetRect.top .. widgetRect.bottom) {
|
for (yCell in widgetRect.top..widgetRect.bottom) {
|
||||||
widgetTargetCells.add(Pair(xCell, yCell))
|
widgetTargetCells.add(Pair(xCell, yCell))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var areAllCellsEmpty = true
|
var areAllCellsEmpty = true
|
||||||
gridItems.filter { it.id != draggedItem?.id }.forEach { item ->
|
gridItems.filter { it.id != draggedItem?.id }.forEach { item ->
|
||||||
for (xCell in item.left .. item.right) {
|
for (xCell in item.left..item.right) {
|
||||||
for (yCell in item.top .. item.bottom) {
|
for (yCell in item.top..item.bottom) {
|
||||||
val cell = Pair(xCell, yCell)
|
val cell = Pair(xCell, yCell)
|
||||||
val isAnyCellOccupied = widgetTargetCells.contains(cell)
|
val isAnyCellOccupied = widgetTargetCells.contains(cell)
|
||||||
if (isAnyCellOccupied) {
|
if (isAnyCellOccupied) {
|
||||||
|
@ -620,7 +618,7 @@ class HomeScreenGrid(context: Context, attrs: AttributeSet, defStyle: Int) : Rel
|
||||||
// drag the center of the widget, not the top left corner
|
// drag the center of the widget, not the top left corner
|
||||||
private fun getWidgetOccupiedRect(item: Pair<Int, Int>): Rect {
|
private fun getWidgetOccupiedRect(item: Pair<Int, Int>): Rect {
|
||||||
val left = item.first - Math.floor((draggedItem!!.getWidthInCells() - 1) / 2.0).toInt()
|
val left = item.first - Math.floor((draggedItem!!.getWidthInCells() - 1) / 2.0).toInt()
|
||||||
val rect = Rect(left, item.second, left + draggedItem!!.getWidthInCells(), item.second + draggedItem!!.getHeightInCells())
|
val rect = Rect(left, item.second, left + draggedItem!!.getWidthInCells() - 1, item.second + draggedItem!!.getHeightInCells() - 1)
|
||||||
if (rect.left < 0) {
|
if (rect.left < 0) {
|
||||||
rect.right -= rect.left
|
rect.right -= rect.left
|
||||||
rect.left = 0
|
rect.left = 0
|
||||||
|
|
|
@ -67,7 +67,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||||
allGridItems: ArrayList<HomeScreenGridItem>
|
allGridItems: ArrayList<HomeScreenGridItem>
|
||||||
) {
|
) {
|
||||||
frameRect = coords
|
frameRect = coords
|
||||||
cellsRect = Rect(gridItem.left, gridItem.top, gridItem.right - 1, gridItem.bottom - 1)
|
cellsRect = Rect(gridItem.left, gridItem.top, gridItem.right, gridItem.bottom)
|
||||||
this.cellWidth = cellWidth
|
this.cellWidth = cellWidth
|
||||||
this.cellHeight = cellHeight
|
this.cellHeight = cellHeight
|
||||||
this.sideMargins = sideMargins
|
this.sideMargins = sideMargins
|
||||||
|
@ -187,7 +187,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||||
|
|
||||||
val closestCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1
|
val closestCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1
|
||||||
var areAllCellsFree = true
|
var areAllCellsFree = true
|
||||||
for (xCell in cellsRect.left..closestCellX + 1) {
|
for (xCell in cellsRect.left..closestCellX) {
|
||||||
for (yCell in cellsRect.top..cellsRect.bottom) {
|
for (yCell in cellsRect.top..cellsRect.bottom) {
|
||||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||||
areAllCellsFree = false
|
areAllCellsFree = false
|
||||||
|
@ -213,7 +213,7 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
||||||
val closestCellY = roundToClosestMultiplyOfNumber(wantedBottom - sideMargins.top, cellHeight) / cellHeight - 1
|
val closestCellY = roundToClosestMultiplyOfNumber(wantedBottom - sideMargins.top, cellHeight) / cellHeight - 1
|
||||||
var areAllCellsFree = true
|
var areAllCellsFree = true
|
||||||
for (xCell in cellsRect.left..cellsRect.right) {
|
for (xCell in cellsRect.left..cellsRect.right) {
|
||||||
for (yCell in cellsRect.top..closestCellY + 1) {
|
for (yCell in cellsRect.top..closestCellY) {
|
||||||
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
if (occupiedCells.contains(Pair(xCell, yCell))) {
|
||||||
areAllCellsFree = false
|
areAllCellsFree = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue