Skip to content

Commit

Permalink
kotlin app updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
syslogic committed Jan 14, 2023
1 parent 12b2ce2 commit 215bb5c
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 87 deletions.
37 changes: 21 additions & 16 deletions kotlin/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.huawei.agconnect'
plugins {
id 'com.android.application'
id 'com.huawei.agconnect'
id 'kotlin-android'
}

android {
compileSdkVersion 31
buildToolsVersion = "31.0.0"

compileSdkVersion 33

defaultConfig {
applicationId "com.huawei.hms.maps.sample"
namespace "com.huawei.hms.maps.sample"
minSdkVersion 19
targetSdkVersion 31
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

signingConfigs {
debug {
}
release {
storeFile file("xxx.xxx")
storePassword "xxxxxx"
Expand All @@ -25,13 +29,14 @@ android {
}
}
buildTypes {
release {
debug {
// signingConfig signingConfigs.debug
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
signingConfig signingConfigs.release
release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// signingConfig signingConfigs.release
minifyEnabled true
}
}

Expand All @@ -53,9 +58,9 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.aar'])
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.huawei.hms:maps:6.5.0.301'
implementation 'com.squareup.okhttp3:okhttp:3.5.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.huawei.hms:maps:6.8.1.301'
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
//noinspection GradleDependency
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

}
25 changes: 14 additions & 11 deletions kotlin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.hms.maps.sample">
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
Expand All @@ -21,7 +21,18 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:dataExtractionRules="@xml/data_extraction_rules"
tools:ignore="DataExtractionRules"
tools:targetApi="s">

<meta-data
android:name="com.huawei.hms.client.channel.androidMarket"
android:value="false" />

<meta-data
android:name="com.huawei.hms.client.appid"
android:value="appid=appid" />

<activity
android:name=".MainActivity"
Expand Down Expand Up @@ -107,14 +118,6 @@
android:name=".RoutePlanningDemoActivity"
android:label="RoutePlanningDemo" />

<meta-data
android:name="com.huawei.hms.client.channel.androidMarket"
android:value="false" />

<meta-data
android:name="com.huawei.hms.client.appid"
android:value="appid=appid" />

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.appcompat.app.AppCompatActivity
/**
* This shows how we create a basic activity with a map.
*/
@Suppress("UNUSED_PARAMETER")
class BasicMapDemoActivity : AppCompatActivity() {
companion object {
private const val TAG = "BasicMapDemoActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.huawei.hms.maps.sample.utils.MapUtils
/**
* Show how to move a map camera
*/
@Suppress("UNUSED_PARAMETER")
class CameraDemoActivity : AppCompatActivity(), OnMapReadyCallback, View.OnClickListener, OnCameraMoveStartedListener, OnCameraMoveListener, OnCameraIdleListener {
companion object {
private const val TAG = "CameraDemoActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.huawei.hms.maps.sample.utils.CheckUtils
/**
* circle related
*/
@Suppress("UNUSED_PARAMETER")
class CircleDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "CircleDemoActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.huawei.hms.maps.UiSettings
/**
* about gesture
*/
@Suppress("UNUSED_PARAMETER")
class GestureDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "GestureDemoActivity"
Expand Down Expand Up @@ -84,7 +85,7 @@ class GestureDemoActivity : AppCompatActivity(), OnMapReadyCallback {
/**
* Set my location button is available
*/
fun setMyLocationButtonEnabled(v: View?) {
fun setMyLocationButtonEnabled(view: View?) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
if (mMyLocationLayerCheckbox.isChecked) {
Expand All @@ -104,7 +105,7 @@ class GestureDemoActivity : AppCompatActivity(), OnMapReadyCallback {
/**
* Set my location layer available
*/
fun setMyLocationLayerEnabled(v: View?) {
fun setMyLocationLayerEnabled(view: View?) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
hMap?.isMyLocationEnabled = mMyLocationLayerCheckbox.isChecked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import java.io.IOException
/**
* about groundOverlay
*/
@Suppress("UNUSED_PARAMETER")
@SuppressLint("LongLogTag")
class GroundOverlayDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
Expand Down Expand Up @@ -235,24 +236,21 @@ class GroundOverlayDemoActivity : AppCompatActivity(), OnMapReadyCallback {
*/
fun getAttributes(view: View?) {
if (null != overlay) {
var bounds: String? = null
var position: String? = null
bounds = if (overlay?.bounds == null) {
val bounds: String? = if (overlay?.bounds == null) {
"null"
} else {
overlay?.bounds.toString()
}
position = if (overlay?.position == null) {
val position: String? = if (overlay?.position == null) {
"null"
} else {
overlay?.position.toString()
}
val message = "position:" + position + "width:" + overlay?.width +
"height:" + overlay?.height + "bounds:" + bounds
Toast
.makeText(this,
"position:" + position + "width:" + overlay?.width + "height:" + overlay?.height + "bounds:"
+ bounds,
Toast.LENGTH_LONG)
.show()
.makeText(this, message, Toast.LENGTH_LONG)
.show()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import java.util.*
/**
* about HeatMap
*/
@Suppress("UNUSED_PARAMETER")
class HeatMapDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "HeatMapDemoActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
}

private fun hasPermissions(context: Context, vararg permissions: String): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permissions != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (permission in permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.huawei.hms.maps.sample.utils.MapUtils
* Basical functions
*/

@Suppress("UNUSED_PARAMETER")
@SuppressLint("LongLogTag")
class MapFunctionsDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.json.JSONException
/**
* MarkerClustering related
*/
@Suppress("UNUSED_PARAMETER")
@SuppressLint("LongLogTag")
class MarkerClusteringDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import java.util.*
/**
* Marker related
*/
@Suppress("UNUSED_PARAMETER")
class MarkerDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "MarkerDemoActivity"
Expand Down Expand Up @@ -271,7 +272,7 @@ class MarkerDemoActivity : AppCompatActivity(), OnMapReadyCallback {
}

// remove the markers added by long click.
if (null != markerList && markerList.size > 0) {
if (markerList.size > 0) {
for (iMarker in markerList) {
iMarker.remove()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.huawei.hms.maps.sample.utils.MapUtils
/**
* about polygon
*/
@Suppress("UNUSED_PARAMETER")
class PolygonDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "PolygonDemoActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import java.util.*
/**
* about polyline
*/
@Suppress("UNUSED_PARAMETER")
class PolylineDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "PolylineDemoActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import java.util.*
* Route Planning
*/
@SuppressLint("LongLogTag")
@Suppress("UNUSED_PARAMETER")
class RoutePlanningDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "RoutePlanningDemoActivity"
Expand Down Expand Up @@ -161,44 +162,48 @@ class RoutePlanningDemoActivity : AppCompatActivity(), OnMapReadyCallback {

private fun generateRoute(json: String?) {
try {
val jsonObject = JSONObject(json)
val jsonObject = JSONObject(json.toString())
val routes = jsonObject.optJSONArray("routes")
if (null == routes || routes.length() == 0) {
return
}
if (null == routes || routes.length() == 0) {return}
val route = routes.getJSONObject(0)

// get route bounds
val bounds = route.optJSONObject("bounds")
if (null != bounds && bounds.has("southwest") && bounds.has("northeast")) {
val southwest = bounds.optJSONObject("southwest")
val northeast = bounds.optJSONObject("northeast")
val sw = LatLng(southwest.optDouble("lat"), southwest.optDouble("lng"))
val ne = LatLng(northeast.optDouble("lat"), northeast.optDouble("lng"))
val sw = LatLng(southwest!!.optDouble("lat"), southwest.optDouble("lng"))
val ne = LatLng(northeast!!.optDouble("lat"), northeast.optDouble("lng"))
mLatLngBounds = LatLngBounds(sw, ne)
}

// get paths
val paths = route.optJSONArray("paths")
for (i in 0 until paths.length()) {
val path = paths.optJSONObject(i)
val mPath: MutableList<LatLng> = ArrayList()
val steps = path.optJSONArray("steps")
for (j in 0 until steps.length()) {
val step = steps.optJSONObject(j)
val polyline = step.optJSONArray("polyline")
for (k in 0 until polyline.length()) {
if (j > 0 && k == 0) {
continue
if (paths != null) {
for (i in 0 until paths.length()) {
val path = paths.optJSONObject(i)
val mPath: MutableList<LatLng> = ArrayList()
val steps = path.optJSONArray("steps")
if (steps != null) {
for (j in 0 until steps.length()) {
val step = steps.optJSONObject(j)
val polyline = step.optJSONArray("polyline")
if (polyline != null) {
for (k in 0 until polyline.length()) {
if (j > 0 && k == 0) {
continue
}
val line = polyline.getJSONObject(k)
val lat = line.optDouble("lat")
val lng = line.optDouble("lng")
val latLng = LatLng(lat, lng)
mPath.add(latLng)
}
}
}
val line = polyline.getJSONObject(k)
val lat = line.optDouble("lat")
val lng = line.optDouble("lng")
val latLng = LatLng(lat, lng)
mPath.add(latLng)
}
mPaths.add(i, mPath)
}
mPaths.add(i, mPath)
}
mHandler.sendEmptyMessage(0)
} catch (e: JSONException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.huawei.hms.maps.model.MapStyleOptions
/**
* StyleMap related
*/
@Suppress("UNUSED_PARAMETER")
class StyleMapDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "StyleMapDemoActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.huawei.hms.maps.model.MarkerOptions
/**
* Create a simple activity with a map and a marker on the map.
*/
@Suppress("UNUSED_PARAMETER")
class SupportMapDemoActivity : AppCompatActivity(), OnMapReadyCallback {
companion object {
private const val TAG = "SupportMapDemoActivity"
Expand Down Expand Up @@ -187,4 +188,4 @@ class SupportMapDemoActivity : AppCompatActivity(), OnMapReadyCallback {
mBeijing?.setIcon(bitmapDescriptor)
}
}
}
}
Loading

0 comments on commit 215bb5c

Please sign in to comment.