feat: removed renderer selection from the samples (#1430)

Since the new renderer is default as of Maps SDK for Android v18.2.0, the renderer selection is unnecessary for these demos.
This commit is contained in:
Enrique López Mañas 2023-12-06 23:55:13 +01:00 committed by GitHub
parent e6f8b8a913
commit 596b127a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6 additions and 136 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 The Android Open Source Project
* Copyright 2023 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.
@ -20,19 +20,11 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.MapsInitializer.Renderer;
import com.google.android.gms.maps.OnMapsSdkInitializedCallback;
import androidx.appcompat.app.AppCompatActivity;
@ -41,7 +33,7 @@ import androidx.appcompat.app.AppCompatActivity;
*
* <p>The main layout lists the demonstrated features, with buttons to launch them.
*/
public final class MainActivity extends AppCompatActivity implements OnMapsSdkInitializedCallback {
public final class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
@ -92,47 +84,5 @@ public final class MainActivity extends AppCompatActivity implements OnMapsSdkIn
startActivity(new Intent(view.getContext(), demo.activityClass));
});
}
Spinner spinner = (Spinner) findViewById(R.id.map_renderer_spinner);
ArrayAdapter<CharSequence> spinnerAdapter =
ArrayAdapter.createFromResource(
this, R.array.map_renderer_spinner_array, android.R.layout.simple_spinner_item);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(
new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String preferredRendererName = ((String) spinner.getSelectedItem());
Renderer preferredRenderer;
if (preferredRendererName.equals(getString(R.string.latest))) {
preferredRenderer = Renderer.LATEST;
} else if (preferredRendererName.equals(getString(R.string.legacy))) {
preferredRenderer = Renderer.LEGACY;
} else if (preferredRendererName.equals(getString(R.string.default_renderer))) {
preferredRenderer = null;
} else {
Log.i(TAG, "Error setting renderer with name " + preferredRendererName);
return;
}
MapsInitializer.initialize(getApplicationContext(), preferredRenderer, MainActivity.this);
// Disable spinner since renderer cannot be changed once map is intitialized.
spinner.setEnabled(false);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {}
});
}
@Override
public void onMapsSdkInitialized(MapsInitializer.Renderer renderer) {
Toast.makeText(
getApplicationContext(),
"All demo activities will use " + renderer.toString() + " renderer.",
Toast.LENGTH_LONG)
.show();
}
}

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2012 The Android Open Source Project
Copyright 2023 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.
@ -17,11 +17,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Spinner
android:id="@+id/map_renderer_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog"/>
<ListView
android:id="@+id/list"

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2012 The Android Open Source Project
Copyright 2023 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.
@ -44,7 +44,6 @@
<string name="custom_info_contents">Custom info contents</string>
<string name="custom_info_window">Custom info window</string>
<string name="default_info_window">Default info window</string>
<string name="default_renderer">Default</string>
<string name="down_arrow">\u2193</string>
<string name="drag_melbourne">Drag Melbourne</string>
<string name="duration">Custom Duration</string>
@ -73,21 +72,12 @@
<string name="layers_demo_label">Layers</string>
<string name="layers_demo_description">Demonstrates the different map layers.</string>
<string name="left_arrow">\u2190</string>
<string name="legacy">Legacy</string>
<string name="location_source_demo_label">Location Source Demo</string>
<string name="location_source_demo_description">Demonstrates how to use a custom location source.</string>
<string name="map_circle_description">Google Map with circles.</string>
<string name="map_not_ready">Map is not ready yet</string>
<string name="map_in_pager_demo_label">Map In Pager</string>
<string name="map_in_pager_demo_description">Demonstrates how to add a map to a ViewPager.</string>
<string name="map_renderer_alert_dialog_message">Select a Map renderer before opening any demo.</string>
<string-array name="map_renderer_spinner_array">
<item>@string/map_renderer_spinner_label</item>
<item>@string/default_renderer</item>
<item>@string/legacy</item>
<item>@string/latest</item>
</string-array>
<string name="map_renderer_spinner_label">Select Preferred Map Renderer</string>
<string name="marker_demo_label">Markers</string>
<string name="marker_close_info_window_on_retap_demo_label">Marker Close Info Window on Retap</string>
<string name="marker_close_info_window_on_retap_demo_description">Demonstrates how to close the info window when the currently selected marker is retapped.</string>

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018 Google LLC
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,21 +20,16 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.*
import android.widget.AdapterView.OnItemSelectedListener
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.maps.MapsInitializer
import com.google.android.gms.maps.MapsInitializer.Renderer;
import com.google.android.gms.maps.OnMapsSdkInitializedCallback;
/**
* The main activity of the API library demo gallery.
* The main layout lists the demonstrated features, with buttons to launch them.
*/
class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener, OnMapsSdkInitializedCallback {
class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
private val TAG = MainActivity::class.java.simpleName
@ -59,51 +54,6 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener, OnMap
if (BuildConfig.MAPS_API_KEY.isEmpty()) {
Toast.makeText(this, "Add your own API key in local.properties as MAPS_API_KEY=YOUR_API_KEY", Toast.LENGTH_LONG).show()
}
val spinner = findViewById<Spinner>(R.id.map_renderer_spinner)
val spinnerAdapter = ArrayAdapter.createFromResource(
this, R.array.map_renderer_spinner_array, android.R.layout.simple_spinner_item
)
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = spinnerAdapter
spinner.onItemSelectedListener = object : OnItemSelectedListener {
override fun onItemSelected(
parent: AdapterView<*>?,
view: View,
position: Int,
id: Long
) {
val preferredRendererName = spinner.selectedItem as String
val preferredRenderer: Renderer?
preferredRenderer = if (preferredRendererName == getString(R.string.latest)) {
Renderer.LATEST
} else if (preferredRendererName == getString(R.string.legacy)) {
Renderer.LEGACY
} else if (preferredRendererName == getString(R.string.default_renderer)) {
null
} else {
Log.i(
TAG,
"Error setting renderer with name $preferredRendererName"
)
return
}
MapsInitializer.initialize(applicationContext, preferredRenderer, this@MainActivity)
// Disable spinner since renderer cannot be changed once map is intitialized.
spinner.isEnabled = false
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
}
}
override fun onMapsSdkInitialized(renderer: Renderer) {
Toast.makeText(
this,
"All demo activities will use the $renderer renderer.",
Toast.LENGTH_LONG
).show()
}
/**

View File

@ -25,12 +25,6 @@
android:layout_height="0dp"
android:layout_weight="1" />
<Spinner
android:id="@+id/map_renderer_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="@+id/empty"
android:layout_width="match_parent"

View File

@ -17,17 +17,8 @@
<string name="app_name">Maps SDK for Android Demos (Kotlin)</string>
<string name="default_renderer">Default</string>
<string name="demo_title">Google Maps API Demos</string>
<string name="latest">Latest</string>
<string name="legacy">Legacy</string>
<string name="map_renderer_alert_dialog_message">Select a Map renderer before opening any demo.</string>
<string name="no_demos">No demos</string>
<string name="play_services_not_installed">Google Play services is not installed on this device.</string>
<string-array name="map_renderer_spinner_array">
<item>@string/map_renderer_spinner_label</item>
<item>@string/default_renderer</item>
<item>@string/legacy</item>
<item>@string/latest</item>
</string-array>
<string name="map_renderer_spinner_label">Select Preferred Map Renderer</string>
<!-- Tile Overlay -->