More of the SDK files converted to Kotlin (#646)

This commit is contained in:
Artak Kalantarian
2023-01-03 11:26:07 -08:00
committed by GitHub
parent 0fe2d08b2f
commit 4175a53af6
25 changed files with 1388 additions and 1558 deletions

View File

@@ -79,10 +79,10 @@ class BulkMarkerActivity : AppCompatActivity(), OnItemSelectedListener {
private fun showMarkers(amount: Int) {
var amount = amount
if (mapboxMap == null || locations == null || mapView!!.isDestroyed) {
if (mapboxMap == null || locations == null || mapView.isDestroyed) {
return
}
mapboxMap!!.clear()
mapboxMap.clear()
if (locations!!.size < amount) {
amount = locations!!.size
}
@@ -101,10 +101,10 @@ class BulkMarkerActivity : AppCompatActivity(), OnItemSelectedListener {
MarkerOptions()
.position(latLng)
.title(i.toString())
.snippet(formatter.format(latLng.latitude) + ", " + formatter.format(latLng.longitude))
.snippet(formatter.format(latLng.latitude) + "`, " + formatter.format(latLng.longitude))
)
}
mapboxMap!!.addMarkers(markerOptionsList)
mapboxMap.addMarkers(markerOptionsList)
}
override fun onNothingSelected(parent: AdapterView<*>?) {
@@ -113,27 +113,27 @@ class BulkMarkerActivity : AppCompatActivity(), OnItemSelectedListener {
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 onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView!!.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
override fun onDestroy() {
@@ -141,12 +141,12 @@ class BulkMarkerActivity : AppCompatActivity(), OnItemSelectedListener {
if (progressDialog != null) {
progressDialog!!.dismiss()
}
mapView!!.onDestroy()
mapView.onDestroy()
}
override fun onLowMemory() {
super.onLowMemory()
mapView!!.onLowMemory()
mapView.onLowMemory()
}
private class LoadLocationTask constructor(

View File

@@ -235,10 +235,8 @@ class CameraAnimatorActivity : AppCompatActivity(), OnMapReadyCallback {
private class LatLngEvaluator : TypeEvaluator<LatLng> {
private val latLng = LatLng()
override fun evaluate(fraction: Float, startValue: LatLng, endValue: LatLng): LatLng {
latLng.latitude =
(startValue.latitude + (endValue.latitude - startValue.latitude) * fraction)
latLng.longitude =
(startValue.longitude + (endValue.longitude - startValue.longitude) * fraction)
latLng.setLongitude((startValue.latitude + (endValue.latitude - startValue.latitude) * fraction))
latLng.setLongitude((startValue.longitude + (endValue.longitude - startValue.longitude) * fraction))
return latLng
}
}

View File

@@ -108,7 +108,7 @@ class LocationFragmentActivity : AppCompatActivity() {
component.activateLocationComponent(
LocationComponentActivationOptions
.builder(activity!!, style)
.builder(requireActivity(), style)
.useDefaultLocationEngine(true)
.build()
)
@@ -120,7 +120,7 @@ class LocationFragmentActivity : AppCompatActivity() {
}
override fun onSuccess(result: LocationEngineResult?) {
if (!mapView.isDestroyed) mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(result?.lastLocation), 12.0))
if (!mapView.isDestroyed) mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(result?.lastLocation!!), 12.0))
}
override fun onFailure(exception: Exception) {
@@ -173,7 +173,7 @@ class LocationFragmentActivity : AppCompatActivity() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val textView = TextView(inflater.context)
textView.text = "This is an empty Fragment"
textView.text = getString(R.string.this_is_an_empty_fragment)
return textView
}
}

View File

@@ -10,6 +10,7 @@ import android.os.Bundle
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.LinearInterpolator
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import com.google.gson.JsonObject
import com.mapbox.geojson.Feature
import com.mapbox.geojson.FeatureCollection
@@ -223,7 +224,7 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() {
style!!.addSource(randomCarSource!!)
style!!.addImage(
RANDOM_CAR_IMAGE_ID,
(resources.getDrawable(R.drawable.ic_car_top) as BitmapDrawable).bitmap
(ResourcesCompat.getDrawable(resources, R.drawable.ic_car_top, null) as BitmapDrawable).bitmap
)
val symbolLayer = SymbolLayer(RANDOM_CAR_LAYER, RANDOM_CAR_SOURCE)
symbolLayer.withProperties(
@@ -249,7 +250,7 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() {
)
style!!.addImage(
PASSENGER,
(resources.getDrawable(R.drawable.icon_burned) as BitmapDrawable).bitmap
(ResourcesCompat.getDrawable(resources, R.drawable.icon_burned, null) as BitmapDrawable).bitmap
)
val geoJsonSource = GeoJsonSource(PASSENGER_SOURCE, featureCollection)
style!!.addSource(geoJsonSource)
@@ -277,7 +278,7 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() {
taxi = Car(feature, passenger, duration)
style!!.addImage(
TAXI,
(resources.getDrawable(R.drawable.ic_taxi_top) as BitmapDrawable).bitmap
(ResourcesCompat.getDrawable(resources, R.drawable.ic_taxi_top, null) as BitmapDrawable).bitmap
)
taxiSource = GeoJsonSource(TAXI_SOURCE, featureCollection)
style!!.addSource(taxiSource!!)
@@ -292,7 +293,7 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() {
}
private val latLngInBounds: LatLng
private get() {
get() {
val bounds = mapboxMap!!.projection.visibleRegion.latLngBounds
val generator = Random()
val randomLat = bounds.latSouth + generator.nextDouble() * bounds.latNorth - bounds.latSouth
@@ -302,27 +303,27 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() {
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 onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
mapView!!.onSaveInstanceState(outState)
mapView.onSaveInstanceState(outState)
}
override fun onDestroy() {
@@ -333,12 +334,12 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() {
animator.cancel()
}
}
mapView!!.onDestroy()
mapView.onDestroy()
}
override fun onLowMemory() {
super.onLowMemory()
mapView!!.onLowMemory()
mapView.onLowMemory()
}
/**
@@ -347,14 +348,8 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() {
private class LatLngEvaluator : TypeEvaluator<LatLng> {
private val latLng = LatLng()
override fun evaluate(fraction: Float, startValue: LatLng, endValue: LatLng): LatLng {
latLng.latitude = (
startValue.latitude +
(endValue.latitude - startValue.latitude) * fraction
)
latLng.longitude = (
startValue.longitude +
(endValue.longitude - startValue.longitude) * fraction
)
latLng.setLatitude(startValue.latitude + (endValue.latitude - startValue.latitude) * fraction)
latLng.setLongitude(startValue.longitude + (endValue.longitude - startValue.longitude) * fraction)
return latLng
}
}

View File

@@ -1,3 +1,5 @@
package com.mapbox.mapboxsdk.testapp.activity.telemetry;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
@@ -6,6 +8,7 @@ import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.Gson;
@@ -89,7 +92,7 @@ public class PerformanceMeasurementActivity extends AppCompatActivity {
}
@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@@ -101,7 +104,7 @@ public class PerformanceMeasurementActivity extends AppCompatActivity {
attributes.add(
new Attribute<>("test_perf_event", "true"));
List<Attribute<Long>> counters = new ArrayList();
List<Attribute<Long>> counters = new ArrayList<>();
counters.add(new Attribute<>("elapsed", elapsed));
@@ -146,7 +149,7 @@ public class PerformanceMeasurementActivity extends AppCompatActivity {
private static class EventListener extends okhttp3.EventListener {
private Map<String, Long> startTimes = new HashMap<>();
private final Map<String, Long> startTimes = new HashMap<>();
@Override
public void callStart(Call call) {

View File

@@ -3,4 +3,5 @@
<string name="app_name">MapLibre Android SDK TestApp</string>
<string name="fps30">fps30</string>
<string name="fps60">fps60</string>
<string name="this_is_an_empty_fragment">This is an empty Fragment</string>
</resources>