mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
chore: Add IndoorDemoActivity in Kotlin (#232)
Also apply following changes to Java version: * Refactor variables to remove Hungarian notation * Remove redundant cast for TextView * Fix spelling in string
This commit is contained in:
parent
92290d690d
commit
09dcb13876
@ -36,7 +36,7 @@ import java.util.List;
|
||||
*/
|
||||
public class IndoorDemoActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
private GoogleMap mMap;
|
||||
private GoogleMap map;
|
||||
|
||||
private boolean showLevelPicker = true;
|
||||
|
||||
@ -51,9 +51,9 @@ public class IndoorDemoActivity extends AppCompatActivity implements OnMapReadyC
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(GoogleMap map) {
|
||||
mMap = map;
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.614631, -122.385153), 18));
|
||||
public void onMapReady(GoogleMap googleMap) {
|
||||
map = googleMap;
|
||||
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.614631, -122.385153), 18));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,14 +61,14 @@ public class IndoorDemoActivity extends AppCompatActivity implements OnMapReadyC
|
||||
*/
|
||||
public void onToggleLevelPicker(View view) {
|
||||
showLevelPicker = !showLevelPicker;
|
||||
mMap.getUiSettings().setIndoorLevelPickerEnabled(showLevelPicker);
|
||||
map.getUiSettings().setIndoorLevelPickerEnabled(showLevelPicker);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the focused building info is clicked.
|
||||
*/
|
||||
public void onFocusedBuildingInfo(View view) {
|
||||
IndoorBuilding building = mMap.getFocusedBuilding();
|
||||
IndoorBuilding building = map.getFocusedBuilding();
|
||||
if (building != null) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (IndoorLevel level : building.getLevels()) {
|
||||
@ -87,7 +87,7 @@ public class IndoorDemoActivity extends AppCompatActivity implements OnMapReadyC
|
||||
* Called when the focused level info is clicked.
|
||||
*/
|
||||
public void onVisibleLevelInfo(View view) {
|
||||
IndoorBuilding building = mMap.getFocusedBuilding();
|
||||
IndoorBuilding building = map.getFocusedBuilding();
|
||||
if (building != null) {
|
||||
IndoorLevel level =
|
||||
building.getLevels().get(building.getActiveLevelIndex());
|
||||
@ -105,7 +105,7 @@ public class IndoorDemoActivity extends AppCompatActivity implements OnMapReadyC
|
||||
* Called when the activate higher level is clicked.
|
||||
*/
|
||||
public void onHigherLevel(View view) {
|
||||
IndoorBuilding building = mMap.getFocusedBuilding();
|
||||
IndoorBuilding building = map.getFocusedBuilding();
|
||||
if (building != null) {
|
||||
List<IndoorLevel> levels = building.getLevels();
|
||||
if (!levels.isEmpty()) {
|
||||
@ -117,7 +117,7 @@ public class IndoorDemoActivity extends AppCompatActivity implements OnMapReadyC
|
||||
newLevel = levels.size() - 1;
|
||||
}
|
||||
IndoorLevel level = levels.get(newLevel);
|
||||
setText("Activiating level " + level.getName());
|
||||
setText("Activating level " + level.getName());
|
||||
level.activate();
|
||||
} else {
|
||||
setText("No levels in building");
|
||||
@ -128,7 +128,7 @@ public class IndoorDemoActivity extends AppCompatActivity implements OnMapReadyC
|
||||
}
|
||||
|
||||
private void setText(String message) {
|
||||
TextView text = (TextView) findViewById(R.id.top_text);
|
||||
TextView text = findViewById(R.id.top_text);
|
||||
text.setText(message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,8 @@ class DemoDetailsList {
|
||||
R.string.ground_overlay_demo_label,
|
||||
R.string.ground_overlay_demo_details,
|
||||
GroundOverlayDemoActivity::class.java),
|
||||
DemoDetails(R.string.indoor_demo_label, R.string.indoor_demo_details,
|
||||
IndoorDemoActivity::class.java),
|
||||
DemoDetails(R.string.layers_demo_label, R.string.layers_demo_description,
|
||||
LayersDemoActivity::class.java),
|
||||
DemoDetails(R.string.lite_demo_label, R.string.lite_demo_details,
|
||||
|
||||
@ -0,0 +1,129 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// 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.
|
||||
package com.example.kotlindemos
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
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.LatLng
|
||||
|
||||
/**
|
||||
* A demo activity showing how to use indoor.
|
||||
*/
|
||||
class IndoorDemoActivity : AppCompatActivity(), OnMapReadyCallback {
|
||||
|
||||
private lateinit var map: GoogleMap
|
||||
private var showLevelPicker = true
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.indoor_demo)
|
||||
val mapFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
|
||||
mapFragment?.getMapAsync(this)
|
||||
}
|
||||
|
||||
override fun onMapReady(googleMap: GoogleMap?) {
|
||||
map = googleMap ?: return
|
||||
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(37.614631, -122.385153), 18f))
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the toggle level picker button is clicked.
|
||||
*/
|
||||
fun onToggleLevelPicker(view: View?) {
|
||||
if (!::map.isInitialized) return
|
||||
|
||||
showLevelPicker = !showLevelPicker
|
||||
map.uiSettings.isIndoorLevelPickerEnabled = showLevelPicker
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the focused building info is clicked.
|
||||
*/
|
||||
fun onFocusedBuildingInfo(view: View?) {
|
||||
if (!::map.isInitialized) return
|
||||
|
||||
val building = map.focusedBuilding
|
||||
if (building != null) {
|
||||
val s = StringBuilder()
|
||||
for (level in building.levels) {
|
||||
s.append(level.name).append(" ")
|
||||
}
|
||||
if (building.isUnderground) {
|
||||
s.append("is underground")
|
||||
}
|
||||
setText(s.toString())
|
||||
} else {
|
||||
setText("No visible building")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the focused level info is clicked.
|
||||
*/
|
||||
fun onVisibleLevelInfo(view: View?) {
|
||||
if (!::map.isInitialized) return
|
||||
|
||||
val building = map.focusedBuilding
|
||||
if (building != null) {
|
||||
val level = building.levels[building.activeLevelIndex]
|
||||
if (level != null) {
|
||||
setText(level.name)
|
||||
} else {
|
||||
setText("No visible level")
|
||||
}
|
||||
} else {
|
||||
setText("No visible building")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activate higher level is clicked.
|
||||
*/
|
||||
fun onHigherLevel(view: View?) {
|
||||
if (!::map.isInitialized) return
|
||||
|
||||
val building = map.focusedBuilding
|
||||
if (building != null) {
|
||||
val levels = building.levels
|
||||
if (!levels.isEmpty()) {
|
||||
val currentLevel = building.activeLevelIndex
|
||||
// The levels are in 'display order' from top to bottom,
|
||||
// i.e. higher levels in the building are lower numbered in the array.
|
||||
var newLevel = currentLevel - 1
|
||||
if (newLevel == -1) {
|
||||
newLevel = levels.size - 1
|
||||
}
|
||||
val level = levels[newLevel]
|
||||
setText("Activating level " + level.name)
|
||||
level.activate()
|
||||
} else {
|
||||
setText("No levels in building")
|
||||
}
|
||||
} else {
|
||||
setText("No visible building")
|
||||
}
|
||||
}
|
||||
|
||||
private fun setText(message: String) {
|
||||
val text = findViewById<TextView>(R.id.top_text)
|
||||
text.text = message
|
||||
}
|
||||
}
|
||||
84
ApiDemos/kotlin/app/src/gms/res/layout/indoor_demo.xml
Normal file
84
ApiDemos/kotlin/app/src/gms/res/layout/indoor_demo.xml
Normal file
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Copyright (C) 2012 The Android Open Source Project
|
||||
|
||||
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.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
class="com.google.android.gms.maps.SupportMapFragment" />
|
||||
<!-- A small label at the top of the screen. -->
|
||||
<TextView
|
||||
android:id="@+id/top_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true" />
|
||||
</RelativeLayout>
|
||||
<!-- A set of test buttons. -->
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="1">
|
||||
|
||||
<TableRow>
|
||||
|
||||
<Button
|
||||
android:id="@+id/focused_bulding_info_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onFocusedBuildingInfo"
|
||||
android:text="@string/focused_building_info" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/toggle_level_picker_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onToggleLevelPicker"
|
||||
android:text="@string/toggle_level_picker" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
|
||||
<Button
|
||||
android:id="@+id/focused_level_info_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onVisibleLevelInfo"
|
||||
android:text="@string/focused_level_info" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/higher_level_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onHigherLevel"
|
||||
android:text="@string/activate_higher_level" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
@ -65,6 +65,7 @@
|
||||
<activity android:name=".LiteDemoActivity" />
|
||||
<activity android:name=".EventsDemoActivity" />
|
||||
<activity android:name=".GroundOverlayDemoActivity" />
|
||||
<activity android:name=".IndoorDemoActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -61,6 +61,14 @@
|
||||
<string name="transparency">Transparency</string>
|
||||
<string name="switch_image">Switch Image</string>
|
||||
|
||||
<!-- Indoor -->
|
||||
<string name="indoor_demo_label">Indoor</string>
|
||||
<string name="indoor_demo_details">Demonstrates how to use the Indoor API.</string>
|
||||
<string name="activate_higher_level">Activate Higher Level</string>
|
||||
<string name="focused_building_info">Focused Building</string>
|
||||
<string name="focused_level_info">Focused Level</string>
|
||||
<string name="toggle_level_picker">Toggle Level Picker</string>
|
||||
|
||||
<!-- Layers Demo -->
|
||||
<string name="buildings">Buildings</string>
|
||||
<string name="hybrid">Hybrid</string>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user