Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

package com.google.maps.android.utils.demo

import android.os.Build
import android.util.DisplayMetrics
import android.view.View
import android.view.WindowManager
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Spinner
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.MapView
import com.google.android.gms.maps.model.LatLng
import com.google.maps.android.clustering.ClusterManager
import com.google.maps.android.clustering.algo.AbstractAlgorithm
import com.google.maps.android.clustering.algo.CentroidNonHierarchicalDistanceBasedAlgorithm
import com.google.maps.android.clustering.algo.ContinuousZoomEuclideanCentroidAlgorithm
import com.google.maps.android.clustering.algo.GridBasedAlgorithm
Expand All @@ -40,7 +41,6 @@ import kotlin.random.Random
class ClusterAlgorithmsDemoActivity : BaseDemoActivity() {

private var clusterManager: ClusterManager<MyItem>? = null
private lateinit var mapView: MapView

override fun getLayoutId(): Int {
return R.layout.activity_cluster_algorithms_demo
Expand Down Expand Up @@ -85,6 +85,28 @@ class ClusterAlgorithmsDemoActivity : BaseDemoActivity() {
* Sets up the ClusterManager with the chosen algorithm and populates it with items.
*/
private fun setupClusterer(algorithmPosition: Int) {

val windowManager = getSystemService(WINDOW_SERVICE) as WindowManager
val metrics = DisplayMetrics()
val width: Int
val height: Int

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
// For devices with Android 11 (API 30) and above
val windowMetrics = windowManager.currentWindowMetrics
width = windowMetrics.bounds.width()
height = windowMetrics.bounds.height()
metrics.density = resources.displayMetrics.density
} else {
// For devices below Android 11
windowManager.defaultDisplay.getMetrics(metrics)
width = metrics.widthPixels
height = metrics.heightPixels
}

val widthDp = (width / metrics.density).toInt()
val heightDp = (height / metrics.density).toInt()

// 1. Clear the map and previous cluster manager
map.clear()

Expand All @@ -96,9 +118,11 @@ class ClusterAlgorithmsDemoActivity : BaseDemoActivity() {
1 -> GridBasedAlgorithm()
2 -> NonHierarchicalDistanceBasedAlgorithm()
3 -> CentroidNonHierarchicalDistanceBasedAlgorithm()
4 -> NonHierarchicalViewBasedAlgorithm(mapView.width, mapView.height)
4 -> NonHierarchicalViewBasedAlgorithm(widthDp, heightDp)
5 -> ContinuousZoomEuclideanCentroidAlgorithm()
else -> error("Unsupported algorithm position: $algorithmPosition")
else -> {
GridBasedAlgorithm()
}
}

// 4. Point the map's listeners to the ClusterManager
Expand Down
39 changes: 39 additions & 0 deletions demo/src/main/res/layout/multi_profile_two.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2020 Google Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="2dp"
android:layout_width="@dimen/custom_profile_image"
android:layout_height="@dimen/custom_profile_image">

<ImageView
android:id="@+id/image"
android:layout_width="130dp"
android:layout_height="@dimen/custom_profile_image"/>

<TextView
android:id="@id/amu_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/amu_Bubble.TextAppearance.Light"
android:background="@android:color/black"
android:paddingLeft="@dimen/custom_profile_padding"
android:paddingRight="@dimen/custom_profile_padding"
android:layout_gravity="center"
android:alpha=".8"/>

</FrameLayout>