Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ play-services-maps = { module = "com.google.android.gms:play-services-maps", ver
core-ktx = { module = "androidx.core:core-ktx", version.ref = "core-ktx" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }
kxml2 = { module = "net.sf.kxml:kxml2", version.ref = "kxml2" }
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test-core" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "lint" }
lint-checks = { module = "com.android.tools.lint:lint-checks", version.ref = "lint" }
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
testImplementation(libs.mockk)
testImplementation(libs.kotlin.test)
testImplementation(libs.truth)
testImplementation(libs.androidx.test.core)
implementation(libs.kotlin.stdlib.jdk8)

testImplementation(libs.mockk)
Expand Down
110 changes: 0 additions & 110 deletions library/src/main/java/com/google/maps/android/ui/AnimationUtil.java

This file was deleted.

101 changes: 101 additions & 0 deletions library/src/main/java/com/google/maps/android/ui/AnimationUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2025 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.maps.android.ui

import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.Interpolator
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker
import kotlin.math.abs
import kotlin.math.sign

/**
* Animation utilities for markers with Maps API.
*/
object AnimationUtil {
/**
* Animates a marker from it's current position to the provided finalPosition
*
* @param marker marker to animate
* @param finalPosition the final position of the marker after the animation
*/
@JvmStatic
fun animateMarkerTo(marker: Marker, finalPosition: LatLng) {
animateMarkerTo(marker, finalPosition, 2000) // delegate to new version
}

/**
* Animates a marker from its current position to the provided finalPosition.
*
* @param marker marker to animate
* @param finalPosition the final position of the marker after the animation
* @param durationInMs the duration of the animation in milliseconds
*/
@JvmStatic
fun animateMarkerTo(
marker: Marker,
finalPosition: LatLng,
durationInMs: Long
) {
val latLngInterpolator: LatLngInterpolator = LatLngInterpolator.Linear()
val startPosition = marker.position
val handler = Handler(Looper.getMainLooper())
val start = SystemClock.uptimeMillis()
val interpolator: Interpolator = AccelerateDecelerateInterpolator()
handler.post(object : Runnable {
var elapsed: Long = 0
var t = 0f
var v = 0f
override fun run() {
// Calculate progress using interpolator
elapsed = SystemClock.uptimeMillis() - start
t = elapsed / durationInMs.toFloat()
v = interpolator.getInterpolation(t)
marker.position = latLngInterpolator.interpolate(v, startPosition, finalPosition)

// Repeat till progress is complete.
if (t < 1) {
// Post again 16ms later.
handler.postDelayed(this, 16)
}
}
})
}

/**
* For other LatLngInterpolator interpolators, see [this link](https://gist.github.com/broady/6314689)
*/
fun interface LatLngInterpolator {
fun interpolate(fraction: Float, a: LatLng, b: LatLng): LatLng
class Linear : LatLngInterpolator {
override fun interpolate(fraction: Float, a: LatLng, b: LatLng): LatLng {
val lat = (b.latitude - a.latitude) * fraction + a.latitude
var lngDelta = b.longitude - a.longitude

// Take the shortest path across the 180th meridian.
if (abs(lngDelta) > 180) {
lngDelta -= sign(lngDelta) * 360
}
val lng = lngDelta * fraction + a.longitude
return LatLng(lat, lng)
}
}
}
}

This file was deleted.

74 changes: 74 additions & 0 deletions library/src/main/java/com/google/maps/android/ui/BubbleDrawable.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2025 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.maps.android.ui

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.PixelFormat
import android.graphics.PorterDuff
import android.graphics.Rect
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.google.maps.android.R

/**
* Draws a bubble with a shadow, filled with any color.
*/
internal class BubbleDrawable(context: Context) : Drawable() {
private val shadow: Drawable
private val mask: Drawable
var color = Color.WHITE

init {
mask = ContextCompat.getDrawable(context, R.drawable.amu_bubble_mask)!!
shadow = ContextCompat.getDrawable(context, R.drawable.amu_bubble_shadow)!!
}

override fun draw(canvas: Canvas) {
mask.draw(canvas)
canvas.drawColor(color, PorterDuff.Mode.SRC_IN)
shadow.draw(canvas)
}

override fun setAlpha(alpha: Int) {
throw UnsupportedOperationException()
}

override fun setColorFilter(cf: ColorFilter?) {
throw UnsupportedOperationException()
}

override fun getOpacity(): Int {
return PixelFormat.TRANSLUCENT
}

override fun setBounds(left: Int, top: Int, right: Int, bottom: Int) {
mask.setBounds(left, top, right, bottom)
shadow.setBounds(left, top, right, bottom)
}

override fun setBounds(bounds: Rect) {
mask.setBounds(bounds)
shadow.setBounds(bounds)
}

override fun getPadding(padding: Rect): Boolean {
return mask.getPadding(padding)
}
}
Loading
Loading