/* * 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. */ package com.google.mcommerce.sample.android.chapter09.googleMap; import android.os.Bundle; import android.view.View; import android.widget.CheckBox; import android.widget.Toast; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.UiSettings; import com.google.mcommerce.sample.android.R; /** * This shows how UI settings can be toggled. */ public class UiSettingsDemoActivity extends android.support.v4.app.FragmentActivity { private GoogleMap mMap; private UiSettings mUiSettings; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.c09_ui_settings_demo); setUpMapIfNeeded(); } @Override protected void onResume() { super.onResume(); setUpMapIfNeeded(); } private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap(); // Check if we were successful in obtaining the map. if (mMap != null) { setUpMap(); } } } private void setUpMap() { mMap.setMyLocationEnabled(true); mUiSettings = mMap.getUiSettings(); } /** * Checks if the map is ready (which depends on whether the Google Play services APK is * available. This should be called prior to calling any methods on GoogleMap. */ private boolean checkReady() { if (mMap == null) { Toast.makeText(this, R.string.map_not_ready, Toast.LENGTH_SHORT).show(); return false; } return true; } public void setZoomButtonsEnabled(View v) { if (!checkReady()) { return; } // Enables/disables the zoom controls (+/- buttons in the bottom right of the map). mUiSettings.setZoomControlsEnabled(((CheckBox) v).isChecked()); } public void setCompassEnabled(View v) { if (!checkReady()) { return; } // Enables/disables the compass (icon in the top left that indicates the orientation of the // map). mUiSettings.setCompassEnabled(((CheckBox) v).isChecked()); } public void setMyLocationButtonEnabled(View v) { if (!checkReady()) { return; } // Enables/disables the my location button (this DOES NOT enable/disable the my location // dot/chevron on the map). The my location button will never appear if the my location // layer is not enabled. mUiSettings.setMyLocationButtonEnabled(((CheckBox) v).isChecked()); } public void setMyLocationLayerEnabled(View v) { if (!checkReady()) { return; } // Enables/disables the my location layer (i.e., the dot/chevron on the map). If enabled, it // will also cause the my location button to show (if it is enabled); if disabled, the my // location button will never show. mMap.setMyLocationEnabled(((CheckBox) v).isChecked()); } public void setScrollGesturesEnabled(View v) { if (!checkReady()) { return; } // Enables/disables scroll gestures (i.e. panning the map). mUiSettings.setScrollGesturesEnabled(((CheckBox) v).isChecked()); } public void setZoomGesturesEnabled(View v) { if (!checkReady()) { return; } // Enables/disables zoom gestures (i.e., double tap, pinch & stretch). mUiSettings.setZoomGesturesEnabled(((CheckBox) v).isChecked()); } public void setTiltGesturesEnabled(View v) { if (!checkReady()) { return; } // Enables/disables tilt gestures. mUiSettings.setTiltGesturesEnabled(((CheckBox) v).isChecked()); } public void setRotateGesturesEnabled(View v) { if (!checkReady()) { return; } // Enables/disables rotate gestures. mUiSettings.setRotateGesturesEnabled(((CheckBox) v).isChecked()); } }