Converted a few of SDK files (one package) to Kotlin (#637)
Co-authored-by: Artak Kalantarian <artak@amazon.com> Co-authored-by: Birk Skyum <74932975+birkskyum@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
cf35b29b54
commit
ccd3c60e55
@@ -32,9 +32,9 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_camera_animator)
|
||||
mapView = findViewById<View>(R.id.mapView) as MapView
|
||||
if (mapView != null) {
|
||||
mapView!!.onCreate(savedInstanceState)
|
||||
mapView!!.getMapAsync(this)
|
||||
if (::mapView.isInitialized) {
|
||||
mapView.onCreate(savedInstanceState)
|
||||
mapView.getMapAsync(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
.zoom(14.5)
|
||||
.bearing(135.0)
|
||||
.build()
|
||||
set = createExampleAnimator(mapboxMap!!.cameraPosition, animatedPosition)
|
||||
set!!.start()
|
||||
set = createExampleAnimator(mapboxMap.cameraPosition, animatedPosition)
|
||||
set.start()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
targetPosition: CameraPosition
|
||||
): Animator {
|
||||
val animatorSet = AnimatorSet()
|
||||
animatorSet.play(createLatLngAnimator(currentPosition.target, targetPosition.target))
|
||||
animatorSet.play(createLatLngAnimator(currentPosition.target!!, targetPosition.target!!))
|
||||
animatorSet.play(createZoomAnimator(currentPosition.zoom, targetPosition.zoom))
|
||||
animatorSet.play(createBearingAnimator(currentPosition.bearing, targetPosition.bearing))
|
||||
animatorSet.play(createTiltAnimator(currentPosition.tilt, targetPosition.tilt))
|
||||
@@ -80,7 +80,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
latLngAnimator.duration = (1000 * ANIMATION_DELAY_FACTOR).toLong()
|
||||
latLngAnimator.interpolator = FastOutSlowInInterpolator()
|
||||
latLngAnimator.addUpdateListener { animation: ValueAnimator ->
|
||||
mapboxMap!!.moveCamera(
|
||||
mapboxMap.moveCamera(
|
||||
CameraUpdateFactory.newLatLng((animation.animatedValue as LatLng))
|
||||
)
|
||||
}
|
||||
@@ -93,7 +93,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
zoomAnimator.startDelay = (600 * ANIMATION_DELAY_FACTOR).toLong()
|
||||
zoomAnimator.interpolator = AnticipateOvershootInterpolator()
|
||||
zoomAnimator.addUpdateListener { animation: ValueAnimator ->
|
||||
mapboxMap!!.moveCamera(
|
||||
mapboxMap.moveCamera(
|
||||
CameraUpdateFactory.zoomTo((animation.animatedValue as Float).toDouble())
|
||||
)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
bearingAnimator.startDelay = (1000 * ANIMATION_DELAY_FACTOR).toLong()
|
||||
bearingAnimator.interpolator = FastOutLinearInInterpolator()
|
||||
bearingAnimator.addUpdateListener { animation: ValueAnimator ->
|
||||
mapboxMap!!.moveCamera(
|
||||
mapboxMap.moveCamera(
|
||||
CameraUpdateFactory.bearingTo((animation.animatedValue as Float).toDouble())
|
||||
)
|
||||
}
|
||||
@@ -119,7 +119,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
tiltAnimator.duration = (1000 * ANIMATION_DELAY_FACTOR).toLong()
|
||||
tiltAnimator.startDelay = (1500 * ANIMATION_DELAY_FACTOR).toLong()
|
||||
tiltAnimator.addUpdateListener { animation: ValueAnimator ->
|
||||
mapboxMap!!.moveCamera(
|
||||
mapboxMap.moveCamera(
|
||||
CameraUpdateFactory.tiltTo((animation.animatedValue as Float).toDouble())
|
||||
)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (mapboxMap == null) {
|
||||
if (!::mapboxMap.isInitialized) {
|
||||
return false
|
||||
}
|
||||
if (item.itemId != android.R.id.home) {
|
||||
@@ -151,7 +151,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
}
|
||||
|
||||
private fun resetCameraPosition() {
|
||||
mapboxMap!!.moveCamera(
|
||||
mapboxMap.moveCamera(
|
||||
CameraUpdateFactory.newCameraPosition(
|
||||
CameraPosition.Builder()
|
||||
.target(START_LAT_LNG)
|
||||
@@ -176,7 +176,7 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
zoomAnimator.duration = (duration * ANIMATION_DELAY_FACTOR).toLong()
|
||||
zoomAnimator.interpolator = interpolator
|
||||
zoomAnimator.addUpdateListener { animation: ValueAnimator ->
|
||||
mapboxMap!!.moveCamera(
|
||||
mapboxMap.moveCamera(
|
||||
CameraUpdateFactory.zoomTo((animation.animatedValue as Float).toDouble())
|
||||
)
|
||||
}
|
||||
@@ -188,43 +188,47 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
//
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
mapView!!.onStart()
|
||||
mapView.onStart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
mapView!!.onResume()
|
||||
mapView.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
mapView!!.onPause()
|
||||
mapView.onPause()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
mapView!!.onStop()
|
||||
mapView.onStop()
|
||||
for (i in 0 until animators.size()) {
|
||||
animators[animators.keyAt(i)]!!.cancel()
|
||||
}
|
||||
if (set != null) {
|
||||
set!!.cancel()
|
||||
set.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
mapView!!.onSaveInstanceState(outState)
|
||||
mapView.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
mapView!!.onDestroy()
|
||||
if (::mapView.isInitialized) {
|
||||
mapView.onDestroy()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLowMemory() {
|
||||
super.onLowMemory()
|
||||
mapView!!.onLowMemory()
|
||||
if (::mapView.isInitialized) {
|
||||
mapView.onLowMemory()
|
||||
}
|
||||
}
|
||||
|
||||
/** Helper class to evaluate LatLng objects with a ValueAnimator */
|
||||
|
||||
@@ -28,8 +28,7 @@ import com.mapbox.mapboxsdk.testapp.R
|
||||
import timber.log.Timber
|
||||
|
||||
/** Test activity showcasing how to listen to camera change events. */
|
||||
class CameraPositionActivity :
|
||||
FragmentActivity(), OnMapReadyCallback, View.OnClickListener, OnMapLongClickListener {
|
||||
class CameraPositionActivity : FragmentActivity(), OnMapReadyCallback, View.OnClickListener, OnMapLongClickListener {
|
||||
private lateinit var mapView: MapView
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
private lateinit var fab: FloatingActionButton
|
||||
@@ -56,7 +55,7 @@ class CameraPositionActivity :
|
||||
toggleLogCameraChanges()
|
||||
|
||||
// listen to long click events to toggle logging camera changes
|
||||
mapboxMap!!.addOnMapLongClickListener(this)
|
||||
mapboxMap.addOnMapLongClickListener(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +67,7 @@ class CameraPositionActivity :
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onClick(view: View) {
|
||||
val context = view.context
|
||||
val dialogContent =
|
||||
LayoutInflater.from(context).inflate(R.layout.dialog_camera_position, null)
|
||||
val dialogContent = LayoutInflater.from(context).inflate(R.layout.dialog_camera_position, null)
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(R.string.dialog_camera_position)
|
||||
builder.setView(onInflateDialogContent(dialogContent))
|
||||
@@ -82,49 +80,51 @@ class CameraPositionActivity :
|
||||
private fun toggleLogCameraChanges() {
|
||||
logCameraChanges = !logCameraChanges
|
||||
if (logCameraChanges) {
|
||||
mapboxMap!!.addOnCameraIdleListener(idleListener)
|
||||
mapboxMap!!.addOnCameraMoveCancelListener(moveCanceledListener)
|
||||
mapboxMap!!.addOnCameraMoveListener(moveListener)
|
||||
mapboxMap!!.addOnCameraMoveStartedListener(moveStartedListener)
|
||||
mapboxMap.addOnCameraIdleListener(idleListener)
|
||||
mapboxMap.addOnCameraMoveCancelListener(moveCanceledListener)
|
||||
mapboxMap.addOnCameraMoveListener(moveListener)
|
||||
mapboxMap.addOnCameraMoveStartedListener(moveStartedListener)
|
||||
} else {
|
||||
mapboxMap!!.removeOnCameraIdleListener(idleListener)
|
||||
mapboxMap!!.removeOnCameraMoveCancelListener(moveCanceledListener)
|
||||
mapboxMap!!.removeOnCameraMoveListener(moveListener)
|
||||
mapboxMap!!.removeOnCameraMoveStartedListener(moveStartedListener)
|
||||
mapboxMap.removeOnCameraIdleListener(idleListener)
|
||||
mapboxMap.removeOnCameraMoveCancelListener(moveCanceledListener)
|
||||
mapboxMap.removeOnCameraMoveListener(moveListener)
|
||||
mapboxMap.removeOnCameraMoveStartedListener(moveStartedListener)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
mapView!!.onStart()
|
||||
mapView.onStart()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
mapView!!.onResume()
|
||||
mapView.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
mapView!!.onPause()
|
||||
mapView.onPause()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
mapView!!.onStop()
|
||||
mapView.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap!!.removeOnMapLongClickListener(this)
|
||||
if (::mapboxMap.isInitialized) {
|
||||
mapboxMap.removeOnMapLongClickListener(this)
|
||||
}
|
||||
if (::mapView.isInitialized) {
|
||||
mapView.onDestroy()
|
||||
}
|
||||
mapView!!.onDestroy()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
mapView!!.onSaveInstanceState(outState)
|
||||
mapView.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
private fun onInflateDialogContent(view: View): View {
|
||||
@@ -136,13 +136,7 @@ class CameraPositionActivity :
|
||||
return view
|
||||
}
|
||||
|
||||
private fun linkTextView(
|
||||
view: View,
|
||||
@IdRes textViewRes: Int,
|
||||
@IdRes seekBarRes: Int,
|
||||
listener: ValueChangeListener,
|
||||
defaultValue: Int
|
||||
) {
|
||||
private fun linkTextView(view: View, @IdRes textViewRes: Int, @IdRes seekBarRes: Int, listener: ValueChangeListener, defaultValue: Int) {
|
||||
val value = view.findViewById<View>(textViewRes) as TextView
|
||||
val seekBar = view.findViewById<View>(seekBarRes) as SeekBar
|
||||
listener.setLinkedValueView(value)
|
||||
@@ -152,42 +146,30 @@ class CameraPositionActivity :
|
||||
|
||||
private val idleListener = OnCameraIdleListener {
|
||||
Timber.e("OnCameraIdle")
|
||||
fab!!.setColorFilter(
|
||||
fab.setColorFilter(
|
||||
ContextCompat.getColor(this@CameraPositionActivity, android.R.color.holo_green_dark)
|
||||
)
|
||||
}
|
||||
private val moveListener = OnCameraMoveListener {
|
||||
Timber.e("OnCameraMove")
|
||||
fab!!.setColorFilter(
|
||||
ContextCompat.getColor(
|
||||
this@CameraPositionActivity,
|
||||
android.R.color.holo_orange_dark
|
||||
)
|
||||
fab.setColorFilter(
|
||||
ContextCompat.getColor(this@CameraPositionActivity, android.R.color.holo_orange_dark)
|
||||
)
|
||||
}
|
||||
private val moveCanceledListener = OnCameraMoveCanceledListener {
|
||||
Timber.e("OnCameraMoveCanceled")
|
||||
}
|
||||
private val moveStartedListener: OnCameraMoveStartedListener =
|
||||
object : OnCameraMoveStartedListener {
|
||||
private val REASONS =
|
||||
arrayOf(
|
||||
"REASON_API_GESTURE",
|
||||
"REASON_DEVELOPER_ANIMATION",
|
||||
"REASON_API_ANIMATION"
|
||||
)
|
||||
private val moveStartedListener: OnCameraMoveStartedListener = object : OnCameraMoveStartedListener {
|
||||
private val REASONS = arrayOf("REASON_API_GESTURE", "REASON_DEVELOPER_ANIMATION", "REASON_API_ANIMATION")
|
||||
|
||||
override fun onCameraMoveStarted(reason: Int) {
|
||||
// reason ranges from 1 <-> 3
|
||||
fab!!.setColorFilter(
|
||||
ContextCompat.getColor(
|
||||
this@CameraPositionActivity,
|
||||
android.R.color.holo_red_dark
|
||||
)
|
||||
)
|
||||
Timber.e("OnCameraMoveStarted: %s", REASONS[reason - 1])
|
||||
}
|
||||
override fun onCameraMoveStarted(reason: Int) {
|
||||
// reason ranges from 1 <-> 3
|
||||
fab.setColorFilter(
|
||||
ContextCompat.getColor(this@CameraPositionActivity, android.R.color.holo_red_dark)
|
||||
)
|
||||
Timber.e("OnCameraMoveStarted: %s", REASONS[reason - 1])
|
||||
}
|
||||
}
|
||||
|
||||
private open inner class ValueChangeListener : OnSeekBarChangeListener {
|
||||
protected var textView: TextView? = null
|
||||
@@ -208,58 +190,20 @@ class CameraPositionActivity :
|
||||
}
|
||||
}
|
||||
|
||||
private class DialogClickListener(
|
||||
private val mapboxMap: MapboxMap?,
|
||||
private val dialogContent: View
|
||||
) : DialogInterface.OnClickListener {
|
||||
private class DialogClickListener(private val mapboxMap: MapboxMap?, private val dialogContent: View) : DialogInterface.OnClickListener {
|
||||
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||
val latitude =
|
||||
(dialogContent.findViewById<View>(R.id.value_lat) as TextView)
|
||||
.text
|
||||
.toString()
|
||||
.toDouble()
|
||||
val longitude =
|
||||
(dialogContent.findViewById<View>(R.id.value_lon) as TextView)
|
||||
.text
|
||||
.toString()
|
||||
.toDouble()
|
||||
val zoom =
|
||||
(dialogContent.findViewById<View>(R.id.value_zoom) as TextView)
|
||||
.text
|
||||
.toString()
|
||||
.toDouble()
|
||||
val bearing =
|
||||
(dialogContent.findViewById<View>(R.id.value_bearing) as TextView)
|
||||
.text
|
||||
.toString()
|
||||
.toDouble()
|
||||
val tilt =
|
||||
(dialogContent.findViewById<View>(R.id.value_tilt) as TextView)
|
||||
.text
|
||||
.toString()
|
||||
.toDouble()
|
||||
if (latitude < GeometryConstants.MIN_LATITUDE ||
|
||||
latitude > GeometryConstants.MAX_LATITUDE
|
||||
) {
|
||||
Toast.makeText(
|
||||
dialogContent.context,
|
||||
"latitude value must be set " +
|
||||
" between " +
|
||||
GeometryConstants.MIN_LATITUDE +
|
||||
" and " +
|
||||
GeometryConstants.MAX_LATITUDE,
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
val latitude = (dialogContent.findViewById<View>(R.id.value_lat) as TextView).text.toString().toDouble()
|
||||
val longitude = (dialogContent.findViewById<View>(R.id.value_lon) as TextView).text.toString().toDouble()
|
||||
val zoom = (dialogContent.findViewById<View>(R.id.value_zoom) as TextView).text.toString().toDouble()
|
||||
val bearing = (dialogContent.findViewById<View>(R.id.value_bearing) as TextView).text.toString().toDouble()
|
||||
val tilt = (dialogContent.findViewById<View>(R.id.value_tilt) as TextView).text.toString().toDouble()
|
||||
if (latitude < GeometryConstants.MIN_LATITUDE || latitude > GeometryConstants.MAX_LATITUDE) {
|
||||
Toast.makeText(dialogContent.context, "latitude value must be set between " + GeometryConstants.MIN_LATITUDE + " and " + GeometryConstants.MAX_LATITUDE, Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
val cameraPosition =
|
||||
CameraPosition.Builder()
|
||||
.target(LatLng(latitude, longitude))
|
||||
.zoom(zoom)
|
||||
.bearing(bearing)
|
||||
.tilt(tilt)
|
||||
.build()
|
||||
|
||||
val cameraPosition = CameraPosition.Builder().target(LatLng(latitude, longitude)).zoom(zoom).bearing(bearing).tilt(tilt).build()
|
||||
|
||||
mapboxMap!!.animateCamera(
|
||||
CameraUpdateFactory.newCameraPosition(cameraPosition),
|
||||
5000,
|
||||
|
||||
Reference in New Issue
Block a user