/
UiSettingsDemoActivity.java
147 lines (130 loc) · 4.77 KB
/
UiSettingsDemoActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* 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.example.mapdemo;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.UiSettings;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;
/**
* This shows how UI settings can be toggled.
*/
public class UiSettingsDemoActivity extends FragmentActivity {
private GoogleMap mMap;
private UiSettings mUiSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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());
}
}