-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC - position indicator rotation performance issue #497
Open
flasher297
wants to merge
1
commit into
heremaps:master
Choose a base branch
from
flasher297:feature/position_rotation_mpv_performance_issue
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...tioning/app/src/main/java/com/here/android/example/basicpositioningsolution/ArrowState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.here.android.example.basicpositioningsolution | ||
|
||
data class ArrowState(@JvmField val angle: Float, @JvmField val tilt: Float) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...tioning/app/src/main/java/com/here/android/example/basicpositioningsolution/HereHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.here.android.example.basicpositioningsolution | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.Camera | ||
import android.graphics.Canvas | ||
import android.graphics.Matrix | ||
import androidx.annotation.DrawableRes | ||
import androidx.core.content.ContextCompat | ||
import com.here.android.mpa.common.Image | ||
import com.here.android.mpa.mapping.Map | ||
import com.here.android.mpa.mapping.MapState | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.conflate | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.flow.scan | ||
|
||
fun Context.getBitmapFromVectorDrawable(@DrawableRes drawableId: Int): Bitmap { | ||
val drawable = ContextCompat.getDrawable(this, drawableId) | ||
val bitmap = Bitmap.createBitmap( | ||
drawable!!.intrinsicWidth, | ||
drawable.intrinsicHeight, Bitmap.Config.ARGB_8888 | ||
) | ||
val canvas = Canvas(bitmap) | ||
drawable.setBounds(0, 0, canvas.width, canvas.height) | ||
drawable.draw(canvas) | ||
return bitmap | ||
} | ||
|
||
fun Image.rotateAndSkewImage(srcBitmap: Bitmap, angle: Float, tilt: Float) { | ||
val old = bitmap | ||
setBitmap(srcBitmap.rotateAndSkewBitmap(angle, tilt)) | ||
old?.recycle() | ||
} | ||
|
||
fun Bitmap.rotateAndSkewBitmap(angle: Float, tilt: Float): Bitmap { | ||
val transformationCamera = Camera() | ||
val matrix = Matrix() | ||
transformationCamera.rotateX(-tilt); | ||
transformationCamera.rotateY(0f); | ||
transformationCamera.rotateZ(0f); | ||
transformationCamera.getMatrix(matrix); | ||
|
||
val centerX = this.width / 2f; | ||
val centerY = this.height / 2f; | ||
matrix.preRotate(angle) | ||
matrix.preTranslate(-centerX, -centerY) | ||
matrix.postTranslate(centerX, centerY) | ||
|
||
return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true) | ||
} | ||
|
||
fun getArrowBitmap(context: Context):Bitmap { | ||
return context.getBitmapFromVectorDrawable(R.drawable.ic_map_arrow) | ||
} | ||
|
||
val Map.mapTransformationStateFlow: Flow<MapTransformationState> | ||
get() = trackMapTransform() | ||
.let { combine(it, it.scanCountActiveTransform(), ::Pair) } | ||
.conflate() | ||
.map { (event, count) -> | ||
when (event) { | ||
MapTransformEvent.MapTransformStart -> | ||
MapTransformationState( | ||
activeTransformationCount = count.toInt(), | ||
mapState = null | ||
) | ||
is MapTransformEvent.MapTransformEnd -> { | ||
MapTransformationState( | ||
activeTransformationCount = count.toInt(), | ||
mapState = event.mapState | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class MapTransformationState( | ||
val activeTransformationCount: Int, | ||
val mapState: MapState? = null | ||
) | ||
|
||
sealed class MapTransformEvent { | ||
object MapTransformStart : MapTransformEvent() | ||
data class MapTransformEnd(val mapState: MapState) : MapTransformEvent() | ||
} | ||
|
||
|
||
fun Map.trackMapTransform(): Flow<MapTransformEvent> = | ||
callbackFlow { | ||
val listener = object : Map.OnTransformListener { | ||
override fun onMapTransformStart() { | ||
trySend(MapTransformEvent.MapTransformStart) | ||
} | ||
|
||
override fun onMapTransformEnd(mapState: MapState) { | ||
trySend(MapTransformEvent.MapTransformEnd(mapState)) | ||
} | ||
} | ||
addTransformListener(listener) | ||
awaitClose { removeTransformListener(listener) } | ||
} | ||
|
||
fun Flow<MapTransformEvent>.scanCountActiveTransform(): Flow<Long> = | ||
scan(0L) { acc, event -> | ||
return@scan when (event) { | ||
is MapTransformEvent.MapTransformEnd -> (acc - 1).coerceAtLeast(0) | ||
MapTransformEvent.MapTransformStart -> acc + 1 | ||
} | ||
}.conflate() |
79 changes: 79 additions & 0 deletions
79
...app/src/main/java/com/here/android/example/basicpositioningsolution/MapGestureListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.here.android.example.basicpositioningsolution | ||
|
||
import android.graphics.PointF | ||
import com.here.android.mpa.common.ViewObject | ||
import com.here.android.mpa.mapping.MapGesture | ||
|
||
internal class MapGestureListener( | ||
private val userAction: (mapUserAction: MapUserAction) -> Unit | ||
) : MapGesture.OnGestureListener { | ||
|
||
|
||
override fun onPanStart() { | ||
userAction(MapUserAction.CONTINUOUS_ACTION_STARTED) | ||
} | ||
|
||
override fun onPanEnd() { | ||
userAction(MapUserAction.CONTINUOUS_ACTION_FINISHED) | ||
} | ||
|
||
override fun onMultiFingerManipulationStart() { | ||
userAction(MapUserAction.CONTINUOUS_ACTION_STARTED) | ||
} | ||
|
||
override fun onMultiFingerManipulationEnd() { | ||
userAction(MapUserAction.CONTINUOUS_ACTION_FINISHED) | ||
} | ||
|
||
override fun onMapObjectsSelected(p0: MutableList<ViewObject>): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
|
||
override fun onTapEvent(p0: PointF): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
|
||
override fun onDoubleTapEvent(p0: PointF): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
|
||
override fun onPinchLocked() { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
} | ||
|
||
override fun onPinchZoomEvent(p0: Float, p1: PointF): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
|
||
override fun onRotateLocked() { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
} | ||
|
||
override fun onRotateEvent(p0: Float): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
|
||
override fun onTiltEvent(p0: Float): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
|
||
override fun onLongPressEvent(p0: PointF): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
|
||
override fun onLongPressRelease() { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
} | ||
|
||
override fun onTwoFingerTapEvent(p0: PointF): Boolean { | ||
userAction(MapUserAction.ONE_TIME_ACTION) | ||
return false | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ning/app/src/main/java/com/here/android/example/basicpositioningsolution/MapUserAction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.here.android.example.basicpositioningsolution | ||
|
||
enum class MapUserAction { | ||
CONTINUOUS_ACTION_STARTED, | ||
CONTINUOUS_ACTION_FINISHED, | ||
ONE_TIME_ACTION | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assignment causes performance issue.