Skip to content

Commit

Permalink
Remove unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Apr 20, 2018
1 parent 5edd2a0 commit 452e81f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ app/src/main/res/raw/changelog.md
app/src/main/res/raw/contributors.md
app/src/main/res/raw/readme.md
app/src/main/res/raw/license
app-flavorDefault-debug/
125 changes: 15 additions & 110 deletions app/src/main/java/com/benny/openlauncher/widget/CellContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,6 @@ open class CellContainer : ViewGroup {
super.removeAllViews()
}

private fun getPeekDirectionFromCoordinate(from: Point, to: Point): PeekDirection? {
if (from.y - to.y > 0)
return PeekDirection.UP
else if (from.y - to.y < 0)
return PeekDirection.DOWN

if (from.x - to.x > 0)
return PeekDirection.LEFT
else if (from.x - to.x < 0)
return PeekDirection.RIGHT

return null
}

private var newImageJustProjected: Boolean = false
private var previousProjectedCoordinate: Point? = null

fun projectImageOutlineAt(newCoordinate: Point, bitmap: Bitmap?) {
cachedOutlineBitmap = bitmap
Expand All @@ -113,8 +97,6 @@ open class CellContainer : ViewGroup {
invalidate()
}

fun hasCachedOutlineBitmap(): Boolean = cachedOutlineBitmap != null

private fun drawCachedOutlineBitmap(canvas: Canvas, cell: Rect) {
if (cachedOutlineBitmap != null)
canvas.drawBitmap(cachedOutlineBitmap!!, cell.centerX() - cachedOutlineBitmap!!.width.toFloat() / 2, cell.centerY() - cachedOutlineBitmap!!.width.toFloat() / 2, outlinePaint)
Expand Down Expand Up @@ -191,6 +173,21 @@ open class CellContainer : ViewGroup {
// return null;
}

private fun getPeekDirectionFromCoordinate(from: Point, to: Point): PeekDirection? {
if (from.y - to.y > 0)
return PeekDirection.UP
else if (from.y - to.y < 0)
return PeekDirection.DOWN

if (from.x - to.x > 0)
return PeekDirection.LEFT
else if (from.x - to.x < 0)
return PeekDirection.RIGHT

return null
}


override fun onTouchEvent(event: MotionEvent): Boolean {
when (MotionEventCompat.getActionMasked(event)) {
MotionEvent.ACTION_DOWN -> down = System.currentTimeMillis()
Expand Down Expand Up @@ -277,98 +274,6 @@ open class CellContainer : ViewGroup {
return null
}

/**
* Locate the first 1x1 empty space near but not equal to the supplied starting position.
*
*
* TODO: check this won't return the starting point if the starting point is surrounded by two occupied cells in each direction
*
* @param cx - starting x coordinate
* @param cy - starting y coordinate
* @param peekDirection - direction to look first or null
* @return the first empty space or null if no free space found
*/
fun findFreeSpace(cx: Int, cy: Int, peekDirection: PeekDirection?): Point? {
if (peekDirection != null) {
val target: Point
when (peekDirection) {
CellContainer.PeekDirection.DOWN -> {
target = Point(cx, cy - 1)
if (isValid(target.x, target.y) && !occupied!![target.x][target.y])
return target
}
CellContainer.PeekDirection.LEFT -> {
target = Point(cx + 1, cy)
if (isValid(target.x, target.y) && !occupied!![target.x][target.y])
return target
}
CellContainer.PeekDirection.RIGHT -> {
target = Point(cx - 1, cy)
if (isValid(target.x, target.y) && !occupied!![target.x][target.y])
return target
}
CellContainer.PeekDirection.UP -> {
target = Point(cx, cy + 1)
if (isValid(target.x, target.y) && !occupied!![target.x][target.y])
return target
}
}
}
val toExplore = LinkedList<Point>()
val explored = HashSet<Point>()
toExplore.add(Point(cx, cy))
while (!toExplore.isEmpty()) {
val p = toExplore.remove()
var cp: Point
if (isValid(p.x, p.y - 1)) {
cp = Point(p.x, p.y - 1)
if (!explored.contains(cp)) {
if (!occupied!![cp.x][cp.y])
return cp
else
toExplore.add(cp)
explored.add(p)
}
}

if (isValid(p.x, p.y + 1)) {
cp = Point(p.x, p.y + 1)
if (!explored.contains(cp)) {
if (!occupied!![cp.x][cp.y])
return cp
else
toExplore.add(cp)
explored.add(p)
}
}

if (isValid(p.x - 1, p.y)) {
cp = Point(p.x - 1, p.y)
if (!explored.contains(cp)) {
if (!occupied!![cp.x][cp.y])
return cp
else
toExplore.add(cp)
explored.add(p)
}
}

if (isValid(p.x + 1, p.y)) {
cp = Point(p.x + 1, p.y)
if (!explored.contains(cp)) {
if (!occupied!![cp.x][cp.y])
return cp
else
toExplore.add(cp)
explored.add(p)
}
}
}
return null
}

private fun isValid(x: Int, y: Int): Boolean = x >= 0 && x <= occupied!!.size - 1 && y >= 0 && y <= occupied!![0].size - 1

public override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)

Expand Down

0 comments on commit 452e81f

Please sign in to comment.