Skip to content

Commit

Permalink
Fix the wrong position of the joystick when it is turned on again
Browse files Browse the repository at this point in the history
  • Loading branch information
fuqiuluo committed Oct 14, 2024
1 parent 7845799 commit 0caa9fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ class RockerView(context: Context, attributeSet: AttributeSet): View(context, at
}
}

fun reset() {
mRockerPosition = Point()
isLocked.set(false)
invalidate()
}

companion object {
const val DEFAULT_SIZE: Int = 400
const val DEFAULT_PADDING_SIZE: Int = 80
Expand Down
15 changes: 3 additions & 12 deletions app/src/main/java/moe/fuqiuluo/portal/ui/mock/Rocker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.view.MotionEvent
import android.view.View
import android.view.WindowManager
import moe.fuqiuluo.portal.R
import moe.fuqiuluo.portal.android.widget.RockerView
import moe.fuqiuluo.portal.ext.rockerCoords


Expand Down Expand Up @@ -57,6 +58,8 @@ class Rocker(private val activity: Activity): View.OnTouchListener {
}

fun hide() {
val rockerView = root.findViewById<RockerView>(R.id.rocker)
rockerView.reset()
windowManager.removeView(root)
isStart = false
}
Expand Down Expand Up @@ -97,16 +100,4 @@ class Rocker(private val activity: Activity): View.OnTouchListener {
}
return false
}

private fun getScreenWidth(): Int {
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
return metrics.widthPixels
}

private fun getScreenHeight(): Int {
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
return metrics.heightPixels
}
}

0 comments on commit 0caa9fb

Please sign in to comment.