Fix resize desync between Android surface and renderable (#4328)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package org.maplibre.android.testapp.activity.surfaceview
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import org.maplibre.android.maps.*
|
||||
import org.maplibre.android.testapp.R
|
||||
@@ -14,6 +14,8 @@ import org.maplibre.android.testapp.styles.TestStyles
|
||||
*/
|
||||
class SurfaceViewResizeActivity : AppCompatActivity() {
|
||||
private lateinit var mapView: MapView
|
||||
private var animatedValue: ValueAnimator? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_surfaceview_resize)
|
||||
@@ -37,18 +39,61 @@ class SurfaceViewResizeActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun setupMap(maplibreMap: MapLibreMap) {
|
||||
maplibreMap.setStyle(TestStyles.AWS_OPEN_DATA_STANDARD_LIGHT)
|
||||
maplibreMap.setStyle(TestStyles.getPredefinedStyleWithFallback("Streets"))
|
||||
}
|
||||
|
||||
private fun setupFab() {
|
||||
val fabDebug = findViewById<FloatingActionButton>(R.id.fabResize)
|
||||
fabDebug.setOnClickListener { view: View? ->
|
||||
val parent = findViewById<View>(R.id.coordinator_layout)
|
||||
val params = mapView.layoutParams
|
||||
|
||||
if (animatedValue != null) {
|
||||
animatedValue?.cancel()
|
||||
animatedValue = null
|
||||
|
||||
params.width = parent.width
|
||||
params.height = parent.height
|
||||
}
|
||||
|
||||
if (this::mapView.isInitialized) {
|
||||
val parent = findViewById<View>(R.id.coordinator_layout)
|
||||
val width = if (parent.width == mapView.width) parent.width / 2 else parent.width
|
||||
val height =
|
||||
if (parent.height == mapView.height) parent.height / 2 else parent.height
|
||||
mapView.layoutParams = CoordinatorLayout.LayoutParams(width, height)
|
||||
params.width = if (parent.width == params.width) parent.width / 2 else parent.width
|
||||
params.height =
|
||||
if (parent.height == params.height) parent.height / 2 else parent.height
|
||||
}
|
||||
|
||||
mapView.requestLayout()
|
||||
}
|
||||
|
||||
val fabAnimatedDebug = findViewById<FloatingActionButton>(R.id.fabAnimatedResize)
|
||||
fabAnimatedDebug.setOnClickListener { view: View? ->
|
||||
val parent = findViewById<View>(R.id.coordinator_layout)
|
||||
|
||||
if (animatedValue != null) {
|
||||
animatedValue?.cancel()
|
||||
animatedValue = null
|
||||
|
||||
mapView.layoutParams.width = parent.width
|
||||
mapView.layoutParams.height = parent.height
|
||||
mapView.requestLayout()
|
||||
} else if (this::mapView.isInitialized) {
|
||||
val minValue = parent.height / 2
|
||||
val maxValue = parent.height
|
||||
|
||||
animatedValue = ValueAnimator.ofInt(maxValue, minValue)
|
||||
animatedValue?.apply {
|
||||
duration = 1000
|
||||
repeatCount = ValueAnimator.INFINITE
|
||||
repeatMode = ValueAnimator.REVERSE
|
||||
|
||||
addUpdateListener { animator ->
|
||||
val height = animator.animatedValue as Int
|
||||
mapView.layoutParams.height = height
|
||||
mapView.requestLayout()
|
||||
}
|
||||
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.maplibre.android.testapp.activity.textureview
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -14,6 +15,8 @@ import org.maplibre.android.testapp.styles.TestStyles
|
||||
*/
|
||||
class TextureViewResizeActivity : AppCompatActivity() {
|
||||
private lateinit var mapView: MapView
|
||||
private var animatedValue: ValueAnimator? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_textureview_resize)
|
||||
@@ -43,12 +46,55 @@ class TextureViewResizeActivity : AppCompatActivity() {
|
||||
private fun setupFab() {
|
||||
val fabDebug = findViewById<FloatingActionButton>(R.id.fabResize)
|
||||
fabDebug.setOnClickListener { view: View? ->
|
||||
val parent = findViewById<View>(R.id.coordinator_layout)
|
||||
val params = mapView.layoutParams
|
||||
|
||||
if (animatedValue != null) {
|
||||
animatedValue?.cancel()
|
||||
animatedValue = null
|
||||
|
||||
params.width = parent.width
|
||||
params.height = parent.height
|
||||
}
|
||||
|
||||
if (this::mapView.isInitialized) {
|
||||
val parent = findViewById<View>(R.id.coordinator_layout)
|
||||
val width = if (parent.width == mapView.width) parent.width / 2 else parent.width
|
||||
val height =
|
||||
if (parent.height == mapView.height) parent.height / 2 else parent.height
|
||||
mapView.layoutParams = CoordinatorLayout.LayoutParams(width, height)
|
||||
params.width = if (parent.width == params.width) parent.width / 2 else parent.width
|
||||
params.height =
|
||||
if (parent.height == params.height) parent.height / 2 else parent.height
|
||||
}
|
||||
|
||||
mapView.requestLayout()
|
||||
}
|
||||
|
||||
val fabAnimatedDebug = findViewById<FloatingActionButton>(R.id.fabAnimatedResize)
|
||||
fabAnimatedDebug.setOnClickListener { view: View? ->
|
||||
val parent = findViewById<View>(R.id.coordinator_layout)
|
||||
|
||||
if (animatedValue != null) {
|
||||
animatedValue?.cancel()
|
||||
animatedValue = null
|
||||
|
||||
mapView.layoutParams.width = parent.width
|
||||
mapView.layoutParams.height = parent.height
|
||||
mapView.requestLayout()
|
||||
} else if (this::mapView.isInitialized) {
|
||||
val minValue = parent.height / 2
|
||||
val maxValue = parent.height
|
||||
|
||||
animatedValue = ValueAnimator.ofInt(maxValue, minValue)
|
||||
animatedValue?.apply {
|
||||
duration = 1000
|
||||
repeatCount = ValueAnimator.INFINITE
|
||||
repeatMode = ValueAnimator.REVERSE
|
||||
|
||||
addUpdateListener { animator ->
|
||||
val height = animator.animatedValue as Int
|
||||
mapView.layoutParams.height = height
|
||||
mapView.requestLayout()
|
||||
}
|
||||
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,17 @@
|
||||
android:layout_height="match_parent"
|
||||
app:maplibre_renderTextureMode="false"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabAnimatedResize"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|left"
|
||||
android:layout_marginBottom="@dimen/fab_margin"
|
||||
android:layout_marginLeft="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_animate_coordinates"
|
||||
app:backgroundTint="@color/blueAccent"
|
||||
app:layout_anchorGravity="bottom"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabResize"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -14,6 +14,17 @@
|
||||
android:layout_height="match_parent"
|
||||
app:maplibre_renderTextureMode="true"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabAnimatedResize"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|left"
|
||||
android:layout_marginBottom="@dimen/fab_margin"
|
||||
android:layout_marginLeft="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_animate_coordinates"
|
||||
app:backgroundTint="@color/blueAccent"
|
||||
app:layout_anchorGravity="bottom"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fabResize"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user