diff --git a/android/build.gradle b/android/build.gradle index 54b7214..566db07 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -12,6 +12,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.0.1' classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-4' + classpath "org.jetbrains.kotlin:kotlin-android-extensions:1.1.2-4'" } } @@ -26,6 +27,7 @@ rootProject.allprojects { apply plugin: 'com.android.library' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 27 diff --git a/android/src/main/kotlin/com/apptreesoftware/mapview/CustomInfoWindowGoogleMap.kt b/android/src/main/kotlin/com/apptreesoftware/mapview/CustomInfoWindowGoogleMap.kt new file mode 100644 index 0000000..e5ad0d9 --- /dev/null +++ b/android/src/main/kotlin/com/apptreesoftware/mapview/CustomInfoWindowGoogleMap.kt @@ -0,0 +1,42 @@ +package com.apptreesoftware.mapview +import android.app.Activity +import android.content.Context +import android.view.View +import android.view.LayoutInflater +import android.widget.ImageView +import android.widget.TextView +import android.text.Html +import android.text.Spanned +import android.os.Build + +import com.google.android.gms.maps.GoogleMap +import com.google.android.gms.maps.model.Marker +import kotlinx.android.synthetic.main.map_custom_infowindow.view.* + + +class CustomInfoWindowGoogleMap(private val context: Context) : GoogleMap.InfoWindowAdapter { + + + override fun getInfoWindow(marker: Marker): View? { + return null + } + + + override fun getInfoContents(marker: Marker): View { + + val view = LayoutInflater.from(context).inflate(R.layout.map_custom_infowindow, null) + + view.name.text = fromHtml(marker.getTitle()) + + return view + } + + @SuppressWarnings("deprecation") + fun fromHtml(html: String): Spanned { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY) + } else { + Html.fromHtml(html) + } + } +} \ No newline at end of file diff --git a/android/src/main/kotlin/com/apptreesoftware/mapview/MapActivity.kt b/android/src/main/kotlin/com/apptreesoftware/mapview/MapActivity.kt index 0e74d92..b38df4e 100644 --- a/android/src/main/kotlin/com/apptreesoftware/mapview/MapActivity.kt +++ b/android/src/main/kotlin/com/apptreesoftware/mapview/MapActivity.kt @@ -34,7 +34,7 @@ class MapActivity : AppCompatActivity(), @SuppressLint("MissingPermission") override fun onMapReady(map: GoogleMap) { googleMap = map - + map.setInfoWindowAdapter(CustomInfoWindowGoogleMap(this)) map.setMapType(MapViewPlugin.mapViewType) if (MapViewPlugin.showUserLocation) { diff --git a/android/src/main/res/layout/map_custom_infowindow.xml b/android/src/main/res/layout/map_custom_infowindow.xml new file mode 100644 index 0000000..58d3b3d --- /dev/null +++ b/android/src/main/res/layout/map_custom_infowindow.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file