Skip to content

Commit

Permalink
feat: removed renderer selection from the samples (#1430)
Browse files Browse the repository at this point in the history
Since the new renderer is default as of Maps SDK for Android v18.2.0, the renderer selection is unnecessary for these demos.
  • Loading branch information
kikoso authored Dec 6, 2023
1 parent e6f8b8a commit 596b127
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 136 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,19 +20,11 @@
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;

Expand All @@ -41,7 +33,7 @@
*
* <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();

Expand Down Expand Up @@ -92,47 +84,5 @@ protected void onCreate(Bundle savedInstanceState) {
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();
}
}
7 changes: 1 addition & 6 deletions ApiDemos/java/app/src/gms/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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"
Expand Down
12 changes: 1 addition & 11 deletions ApiDemos/java/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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

Expand All @@ -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()
}

/**
Expand Down
6 changes: 0 additions & 6 deletions ApiDemos/kotlin/app/src/gms/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 0 additions & 9 deletions ApiDemos/kotlin/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down

0 comments on commit 596b127

Please sign in to comment.