This file contains hidden or 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
| // maps | |
| implementation 'com.google.android.gms:play-services-maps:17.0.0' | |
| // design | |
| implementation 'com.google.android.material:material:1.1.0' | |
| // retrofit | |
| implementation 'com.squareup.retrofit2:retrofit:2.6.0' | |
| implementation 'com.squareup.retrofit2:converter-gson:2.6.0' | |
| implementation 'com.squareup.okhttp3:logging-interceptor:4.0.1' |
This file contains hidden or 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
| (map_view as SupportMapFragment).getMapAsync { map -> | |
| // move camera ke jakarta | |
| map.moveCamera(CameraUpdateFactory.newLatLngZoom(jakartaLatLng, 18f)) | |
| // get old position camera | |
| val oldPosition = map.cameraPosition.target | |
| map.setOnCameraMoveStartedListener { | |
| // drag started | |
| } |
This file contains hidden or 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
| fun moveMarkerSmoothly(marker: Marker, newLatLng: LatLng) { | |
| val animator: ValueAnimator = movementAnimator(marker, newLatLng) | |
| animator.start() | |
| val f = getAngle(marker.position, newLatLng).toFloat() | |
| rotateMarker(marker, f) | |
| } |
This file contains hidden or 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
| fun rotateMarker(marker: Marker, toRotation: Float) { | |
| val handler = Handler() | |
| val start = SystemClock.uptimeMillis() | |
| val startRotation = marker.rotation | |
| val duration: Long = 300 | |
| handler.post(object : Runnable { | |
| override fun run() { | |
| val elapsed = SystemClock.uptimeMillis() - start | |
| val t = LinearInterpolator().getInterpolation(elapsed.toFloat() / duration) |
This file contains hidden or 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
| fun getAngle(fromLatLon: LatLng, toLatLon: LatLng): Double { | |
| var heading = 0.0 | |
| if (fromLatLon != toLatLon) { | |
| heading = MathUtil.computeHeading(fromLatLon, toLatLon) | |
| } | |
| return heading | |
| } |
This file contains hidden or 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
| object MathUtil { | |
| fun computeHeading(from: LatLng, to: LatLng): Double { | |
| val fromLat = Math.toRadians(from.latitude) | |
| val fromLng = Math.toRadians(from.longitude) | |
| val toLat = Math.toRadians(to.latitude) | |
| val toLng = Math.toRadians(to.longitude) | |
| val dLng = toLng - fromLng | |
| val heading = atan2( | |
| sin(dLng) * cos(toLat), | |
| cos(fromLat) * sin(toLat) - sin(fromLat) * cos(toLat) * cos(dLng) |
This file contains hidden or 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
| val marker = map.addMarker(markerOption) | |
| map.setOnMapClickListener { newLatLng -> | |
| val animator = MarkerUtil.movementAnimator(marker, newLatLng) | |
| animator.start() | |
| } |
This file contains hidden or 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
| fun movementAnimator(marker: Marker, newLatLng: LatLng) : ValueAnimator { | |
| val animator = ValueAnimator.ofFloat(0f, 100f) | |
| val deltaLatitude = doubleArrayOf(newLatLng.latitude - marker.position.latitude) | |
| val deltaLongitude = newLatLng.longitude - marker.position.longitude | |
| val prevStep = floatArrayOf(0f) | |
| animator.duration = 1500 | |
| animator.addUpdateListener { animation -> | |
| val deltaStep = (animation.animatedValue as Float - prevStep[0]).toDouble() |
This file contains hidden or 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
| fun bitmapFromVector(context: Context, @DrawableRes icon: Int): BitmapDescriptor { | |
| val background = ContextCompat.getDrawable(context, icon) | |
| background!!.setBounds(0, 0, background.intrinsicWidth, background.intrinsicHeight) | |
| val bitmap = Bitmap.createBitmap(background.intrinsicWidth, background.intrinsicHeight, Bitmap.Config.ARGB_8888) | |
| val canvas = Canvas(bitmap) | |
| background.draw(canvas) | |
| return BitmapDescriptorFactory.fromBitmap(bitmap) | |
| } |
This file contains hidden or 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
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| .... | |
| // Pengambilan nilai intro | |
| SharedPreferences preferences = getSharedPreferences("intro", Context.MODE_PRIVATE); | |
| Boolean introComplete = preferences.getBoolean("intro_complete", false); // secara default nilai intro bernilai false | |
| // Jika intro bernilai false | |
| if (!introComplete) { |
NewerOlder