Convert NPVCDownEventState to use RingBuffer
The new one, not the old one. Test: atest Bug: 230669926 Change-Id: Ic643baa9e4887264278e9fa4028e85aa408f0723
This commit is contained in:
@@ -14,9 +14,9 @@
|
|||||||
package com.android.systemui.statusbar.phone
|
package com.android.systemui.statusbar.phone
|
||||||
|
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import com.android.internal.util.RingBuffer
|
|
||||||
import com.android.systemui.dump.DumpsysTableLogger
|
import com.android.systemui.dump.DumpsysTableLogger
|
||||||
import com.android.systemui.dump.Row
|
import com.android.systemui.dump.Row
|
||||||
|
import com.android.systemui.util.collection.RingBuffer
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@@ -67,16 +67,9 @@ class NPVCDownEventState private constructor(
|
|||||||
* Do not use [append] to add new elements. Instead use [insert], as it will recycle if
|
* Do not use [append] to add new elements. Instead use [insert], as it will recycle if
|
||||||
* necessary.
|
* necessary.
|
||||||
*/
|
*/
|
||||||
class Buffer(
|
class Buffer(capacity: Int) {
|
||||||
capacity: Int
|
|
||||||
) : RingBuffer<NPVCDownEventState>(NPVCDownEventState::class.java, capacity) {
|
|
||||||
override fun append(t: NPVCDownEventState?) {
|
|
||||||
throw UnsupportedOperationException("Not supported, use insert instead")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun createNewItem(): NPVCDownEventState {
|
private val buffer = RingBuffer(capacity) { NPVCDownEventState() }
|
||||||
return NPVCDownEventState()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a new element in the buffer.
|
* Insert a new element in the buffer.
|
||||||
@@ -94,7 +87,7 @@ class NPVCDownEventState private constructor(
|
|||||||
touchSlopExceededBeforeDown: Boolean,
|
touchSlopExceededBeforeDown: Boolean,
|
||||||
lastEventSynthesized: Boolean
|
lastEventSynthesized: Boolean
|
||||||
) {
|
) {
|
||||||
nextSlot.apply {
|
buffer.advance().apply {
|
||||||
this.timeStamp = timeStamp
|
this.timeStamp = timeStamp
|
||||||
this.x = x
|
this.x = x
|
||||||
this.y = y
|
this.y = y
|
||||||
@@ -115,7 +108,7 @@ class NPVCDownEventState private constructor(
|
|||||||
* @see NPVCDownEventState.asStringList
|
* @see NPVCDownEventState.asStringList
|
||||||
*/
|
*/
|
||||||
fun toList(): List<Row> {
|
fun toList(): List<Row> {
|
||||||
return toArray().map { it.asStringList }
|
return buffer.asSequence().map { it.asStringList }.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user