Skip to content

Commit

Permalink
Merge branch 'release/0.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Brabenetz committed May 17, 2021
2 parents f6b0583 + bc87cee commit a6ddbc2
Show file tree
Hide file tree
Showing 22 changed files with 555 additions and 381 deletions.
4 changes: 2 additions & 2 deletions ChoiceSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ buildscript {
}
project.ext.buildNumber = buildNumber

project.ext.sdkVersionName = "0.1.5"
project.ext.sdkVersionName = "0.1.6"
project.ext.appVersionName = "${project.sdkVersionName}.${project.buildNumber}"
project.ext.versionCode = 6
project.ext.versionCode = 7
project.ext.groupId = "at.bluesource.choicesdk"

ext.kotlin_version = "1.4.32"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bluesource.choicesdk_app.map

import android.Manifest
import android.annotation.SuppressLint
import android.content.Context
import android.content.pm.PackageManager
import android.graphics.Color
Expand Down Expand Up @@ -28,18 +29,9 @@ import io.reactivex.rxjava3.observers.DisposableObserver


class MapActivity : AppCompatActivity() {
private val TAG = "Test"
private lateinit var mapDisposable: Disposable
private lateinit var mapFragment: MapFragment

private val PERMISSIONS = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.INTERNET
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map)
Expand All @@ -51,7 +43,7 @@ class MapActivity : AppCompatActivity() {
fragmentTransaction.add(R.id.mapContainer, mapFragment)
fragmentTransaction.commit()

if (!hasPermissions(this, PERMISSIONS)) {
if (!hasPermissions(this)) {
ActivityCompat.requestPermissions(this, PERMISSIONS, 3)
} else {
testMap()
Expand All @@ -75,9 +67,9 @@ class MapActivity : AppCompatActivity() {
}
}

private fun hasPermissions(context: Context, permissions: Array<String>): Boolean {
private fun hasPermissions(context: Context): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (permission in permissions) {
for (permission in PERMISSIONS) {
if (ActivityCompat.checkSelfPermission(
context,
permission
Expand Down Expand Up @@ -168,7 +160,7 @@ class MapActivity : AppCompatActivity() {
)

map.addCircle(
Circle.CircleOptions()
CircleOptions()
.center(location)
.radius(100.0)
.fillColor(Color.YELLOW)
Expand All @@ -185,7 +177,7 @@ class MapActivity : AppCompatActivity() {
map.addPolyline(
PolylineOptions()
.add(location2, location3)
.strokeWidth(15f)
.width(15f)
.startCap(Cap.RoundCap())
.endCap(
Cap.CustomCap(
Expand All @@ -204,7 +196,6 @@ class MapActivity : AppCompatActivity() {
.fillColor(Color.RED)
.strokeColor(Color.GREEN)
.strokeWidth(3f)
.addHole(listOf(locationHole1, location6))
)

map.addMarker(
Expand Down Expand Up @@ -311,6 +302,7 @@ class MapActivity : AppCompatActivity() {
return null
}

@SuppressLint("SetTextI18n")
override fun getInfoWindow(marker: Marker?): View {
val view: View = layoutInflater.inflate(R.layout.infow_window_layout, null)

Expand All @@ -331,4 +323,16 @@ class MapActivity : AppCompatActivity() {
super.onDestroy()
mapDisposable.dispose()
}

companion object {
private const val TAG = "MapActivity"

private val PERMISSIONS = arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.INTERNET
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface Map {
* Other
*/
@Throws(ApiException::class)
fun addCircle(options: Circle.CircleOptions): Circle
fun addCircle(options: CircleOptions): Circle
fun addGroundOverlay(options: GroundOverlayOptions)
fun addMarker(options: MarkerOptions): Marker
fun addPolygon(options: PolygonOptions): Polygon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ sealed class PatternItem {
*/
class Dot : PatternItem() {
companion object {
internal fun toGmsDot(): com.google.android.gms.maps.model.Dot {
internal fun Dot.toGmsDot(): com.google.android.gms.maps.model.Dot {
return com.google.android.gms.maps.model.Dot()
}

internal fun toHmsDot(): com.huawei.hms.maps.model.Dot {
internal fun Dot.toHmsDot(): com.huawei.hms.maps.model.Dot {
return com.huawei.hms.maps.model.Dot()
}
}
Expand Down Expand Up @@ -75,18 +75,27 @@ sealed class PatternItem {
}
}

internal fun com.huawei.hms.maps.model.PatternItem.toChoice(): PatternItem {
return when (this) {
is com.huawei.hms.maps.model.Dash -> Dash(length = this.length)
is com.huawei.hms.maps.model.Dot -> Dot()
is com.huawei.hms.maps.model.Gap -> Gap(length = this.length)
else -> throw IllegalArgumentException("No implementation provided for PatternItem of type: ${this.javaClass}")
}
}

internal fun PatternItem.toGmsPatternItem(): com.google.android.gms.maps.model.PatternItem {
return when (this) {
is Dash -> this.toGmsDash()
is Dot -> toGmsDot()
is Dot -> this.toGmsDot()
is Gap -> this.toGmsGap()
}
}

internal fun PatternItem.toHmsPatternItem(): com.huawei.hms.maps.model.PatternItem {
return when (this) {
is Dash -> this.toHmsDash()
is Dot -> toHmsDot()
is Dot -> this.toHmsDot()
is Gap -> this.toHmsGap()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,111 +3,27 @@
package at.bluesource.choicesdk.maps.common.shape

import at.bluesource.choicesdk.maps.common.LatLng
import at.bluesource.choicesdk.maps.common.LatLng.Companion.toGmsLatLng
import at.bluesource.choicesdk.maps.common.LatLng.Companion.toHmsLatLng
import at.bluesource.choicesdk.maps.common.PatternItem
import at.bluesource.choicesdk.maps.common.PatternItem.Companion.toGmsPatternItem
import at.bluesource.choicesdk.maps.common.PatternItem.Companion.toHmsPatternItem
import at.bluesource.choicesdk.maps.gms.shape.GmsCircle
import at.bluesource.choicesdk.maps.hms.shape.HmsCircle

/**
* A circle on the earth's surface (spherical cap).
*/
interface Circle : Shape {
interface Circle {
val id: String
var center: LatLng
var radius: Double
var clickable: Boolean
var fillColor: Int

/**
* Defines options for a [Circle].
* Use this Builder to add a circle to the map.
*/
class CircleOptions : ShapeOptions() {
private var center: LatLng = LatLng(0.0, 0.0)
private var fillColor: Int = 0x00000000 // transparent
private var radius = 1.0
private var pattern: List<PatternItem> = listOf()

fun center(center: LatLng): CircleOptions {
this.center = center
return this
}

fun fillColor(color: Int): CircleOptions {
fillColor = color
return this
}

fun radius(radius: Double): CircleOptions {
this.radius = radius
return this
}

fun strokePattern(pattern: List<PatternItem>): CircleOptions {
this.pattern = pattern
return this
}

override fun clickable(clickable: Boolean): CircleOptions {
super.clickable(clickable)
return this
}

override fun strokeColor(color: Int): CircleOptions {
super.strokeColor(color)
return this
}

override fun strokeWidth(widthInPx: Float): CircleOptions {
super.strokeWidth(widthInPx)
return this
}

override fun visible(visible: Boolean): CircleOptions {
super.visible(visible)
return this
}

override fun zIndex(zIndex: Float): CircleOptions {
super.zIndex(zIndex)
return this
}

companion object {
internal fun CircleOptions.toGmsCircleOptions(): com.google.android.gms.maps.model.CircleOptions {
val co = com.google.android.gms.maps.model.CircleOptions()
.center(center.toGmsLatLng())
.clickable(clickable)
.fillColor(fillColor)
.radius(radius)
.strokeColor(strokeColor)
.strokeWidth(strokeWidthInPx)
.visible(visible)
.zIndex(zIndex)
.strokePattern(pattern.map { it.toGmsPatternItem() })

// special case since gms does not draw anything if the list is empty
if (pattern.isNotEmpty()) {
co.strokePattern(pattern.map { it.toGmsPatternItem() })
}
return co
}

internal fun CircleOptions.toHmsCircleOptions(): com.huawei.hms.maps.model.CircleOptions {
return com.huawei.hms.maps.model.CircleOptions()
.center(center.toHmsLatLng())
.clickable(clickable)
.fillColor(fillColor)
.radius(radius)
.strokeColor(strokeColor)
.strokeWidth(strokeWidthInPx)
.visible(visible)
.zIndex(zIndex)
.strokePattern(pattern.map { it.toHmsPatternItem() })
}
}
}
var radius: Double
var strokeColor: Int
var strokePattern: List<PatternItem>
var strokeWidth: Float
var tag: Any?
var visible: Boolean
var zIndex: Float

fun remove()

companion object {
internal fun com.google.android.gms.maps.model.Circle.toChoiceCircle(): Circle {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package at.bluesource.choicesdk.maps.common.shape

import at.bluesource.choicesdk.maps.common.LatLng
import at.bluesource.choicesdk.maps.common.LatLng.Companion.toGmsLatLng
import at.bluesource.choicesdk.maps.common.LatLng.Companion.toHmsLatLng
import at.bluesource.choicesdk.maps.common.PatternItem
import at.bluesource.choicesdk.maps.common.PatternItem.Companion.toGmsPatternItem
import at.bluesource.choicesdk.maps.common.PatternItem.Companion.toHmsPatternItem

/**
* Defines options for a [Circle].
* Use this Builder to add a circle to the map.
*/
class CircleOptions {
private var center: LatLng = LatLng(0.0, 0.0)
private var clickable = false
private var fillColor: Int = 0x00000000 // transparent
private var radius = 1.0
private var strokeColor: Int = 0xff000000.toInt() // black, also toInt workaround for compiler issue: https://youtrack.jetbrains.com/issue/KT-4749
private var strokePattern: List<PatternItem> = listOf()
private var strokeWidth: Float = 10f
private var visible = true
private var zIndex: Float = 0f

fun center(center: LatLng): CircleOptions {
this.center = center
return this
}

fun clickable(clickable: Boolean): CircleOptions {
this.clickable = clickable
return this
}

fun fillColor(color: Int): CircleOptions {
this.fillColor = color
return this
}

fun radius(radius: Double): CircleOptions {
this.radius = radius
return this
}

fun strokeColor(color: Int): CircleOptions {
this.strokeColor = color
return this
}

fun strokePattern(pattern: List<PatternItem>): CircleOptions {
this.strokePattern = pattern
return this
}

fun strokeWidth(width: Float): CircleOptions {
this.strokeWidth = width
return this
}

fun visible(visible: Boolean): CircleOptions {
this.visible = visible
return this
}

fun zIndex(zIndex: Float): CircleOptions {
this.zIndex = zIndex
return this
}

companion object {
internal fun CircleOptions.toGmsCircleOptions(): com.google.android.gms.maps.model.CircleOptions {
val co = com.google.android.gms.maps.model.CircleOptions()
.center(center.toGmsLatLng())
.clickable(clickable)
.fillColor(fillColor)
.radius(radius)
.strokeColor(strokeColor)
.strokeWidth(strokeWidth)
.visible(visible)
.zIndex(zIndex)

// special case since gms does not draw anything if the list is empty
if (strokePattern.isNotEmpty()) {
co.strokePattern(strokePattern.map { it.toGmsPatternItem() })
}
return co
}

internal fun CircleOptions.toHmsCircleOptions(): com.huawei.hms.maps.model.CircleOptions {
return com.huawei.hms.maps.model.CircleOptions()
.center(center.toHmsLatLng())
.clickable(clickable)
.fillColor(fillColor)
.radius(radius)
.strokeColor(strokeColor)
.strokeWidth(strokeWidth)
.visible(visible)
.zIndex(zIndex)
.strokePattern(strokePattern.map { it.toHmsPatternItem() })
}
}
}
Loading

0 comments on commit a6ddbc2

Please sign in to comment.