Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Commit

Permalink
Added new marker asset and re-use marker across flight path updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bachhuberdesign committed May 28, 2018
1 parent 33b99f5 commit 57f62af
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
14 changes: 14 additions & 0 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies {
def effortless_android_version = "1.0.4"
def effortless_prefs_version = "1.1.0"
def architecture_components_version = "1.1.1"
def material_drawer_version = "6.0.7"

implementation "com.google.android.gms:play-services-maps:$play_services_version"

Expand Down Expand Up @@ -64,4 +65,7 @@ dependencies {

// Shared Preferences Wrapper
implementation "io.milkcan:effortless-prefs:$effortless_prefs_version"

// MaterialDrawer
implementation("com.mikepenz:materialdrawer:$material_drawer_version@aar") { transitive = true }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open class UDPListener(private val callback: UDPCallback) : Thread() {
private var isKeepRunning = true

override fun run() {
var packet = DatagramPacket(ByteArray(64), MAX_UDP_DATAGRAM_LENGTH)
val packet = DatagramPacket(ByteArray(MAX_UDP_DATAGRAM_LENGTH), MAX_UDP_DATAGRAM_LENGTH)

var socket: DatagramSocket? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
import io.milkcan.effortlessandroid.d
import io.milkcan.effortlessandroid.e
import io.milkcan.effortlessandroid.toastLong
import xplaneopenmap.bachhuberdesign.com.openmap.R
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.support.v4.content.ContextCompat

class FlightMapActivity : AppCompatActivity(), OnMapReadyCallback {

Expand All @@ -25,6 +30,7 @@ class FlightMapActivity : AppCompatActivity(), OnMapReadyCallback {

private var cameraMoved: Boolean = false
private var dialog: AlertDialog? = null
private var currentFlightMarker: Marker? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -48,6 +54,7 @@ class FlightMapActivity : AppCompatActivity(), OnMapReadyCallback {

override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
map.mapType = GoogleMap.MAP_TYPE_SATELLITE
}

private fun showIpAddressDialog() {
Expand Down Expand Up @@ -82,14 +89,30 @@ class FlightMapActivity : AppCompatActivity(), OnMapReadyCallback {
d("Flight path position: $position")
val cameraUpdate = CameraUpdateFactory.newLatLngZoom(position, 12.0f)

map.clear()

if (!cameraMoved){
map.moveCamera(cameraUpdate)
cameraMoved = true
try {
if (currentFlightMarker == null) {
val drawable = ContextCompat.getDrawable(this, R.drawable.icon_plane_marker) as BitmapDrawable

val iconBitmap = Bitmap.createScaledBitmap(drawable.bitmap, 85, 85, false)

currentFlightMarker = map.addMarker(
MarkerOptions()
.position(position)
.title("Current Flight")
.icon(BitmapDescriptorFactory.fromBitmap(iconBitmap))
)
} else {
currentFlightMarker?.position = position
}

if (!cameraMoved) {
map.moveCamera(cameraUpdate)
cameraMoved = true
}

} catch (ex: Exception) {
e("Error updating map: ${ex.message}", ex)
}

map.addMarker(MarkerOptions().position(position).title("Current Flight"))
})
}

Expand Down
Binary file added app/src/main/res/drawable/icon_plane_marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57f62af

Please sign in to comment.