2121
2222package com .example .mapdemo ;
2323
24+ import android .graphics .Color ;
25+ import android .graphics .Point ;
26+ import android .location .Location ;
27+ import android .os .Bundle ;
28+ import android .view .View ;
29+ import android .widget .AdapterView ;
30+ import android .widget .AdapterView .OnItemSelectedListener ;
31+ import android .widget .ArrayAdapter ;
32+ import android .widget .CheckBox ;
33+ import android .widget .SeekBar ;
34+ import android .widget .SeekBar .OnSeekBarChangeListener ;
35+ import android .widget .Spinner ;
36+
37+ import androidx .appcompat .app .AppCompatActivity ;
38+
2439import com .google .android .libraries .maps .CameraUpdateFactory ;
2540import com .google .android .libraries .maps .GoogleMap ;
2641import com .google .android .libraries .maps .GoogleMap .OnCircleClickListener ;
3954import com .google .android .libraries .maps .model .MarkerOptions ;
4055import com .google .android .libraries .maps .model .PatternItem ;
4156
42- import android .graphics .Color ;
43- import android .graphics .Point ;
44- import android .location .Location ;
45- import android .os .Bundle ;
46- import android .view .View ;
47- import android .widget .AdapterView ;
48- import android .widget .AdapterView .OnItemSelectedListener ;
49- import android .widget .ArrayAdapter ;
50- import android .widget .CheckBox ;
51- import android .widget .SeekBar ;
52- import android .widget .SeekBar .OnSeekBarChangeListener ;
53- import android .widget .Spinner ;
54-
55- import androidx .appcompat .app .AppCompatActivity ;
56-
5757import java .util .ArrayList ;
5858import java .util .Arrays ;
5959import java .util .List ;
@@ -83,20 +83,20 @@ public class CircleDemoActivity extends AppCompatActivity
8383 private static final List <PatternItem > PATTERN_DASHED = Arrays .asList (DASH , GAP );
8484 private static final List <PatternItem > PATTERN_MIXED = Arrays .asList (DOT , GAP , DOT , DASH , GAP );
8585
86- private GoogleMap mMap ;
86+ private GoogleMap map ;
8787
88- private List <DraggableCircle > mCircles = new ArrayList <>(1 );
88+ private List <DraggableCircle > circles = new ArrayList <>(1 );
8989
90- private int mFillColorArgb ;
91- private int mStrokeColorArgb ;
90+ private int fillColorArgb ;
91+ private int strokeColorArgb ;
9292
93- private SeekBar mFillHueBar ;
94- private SeekBar mFillAlphaBar ;
95- private SeekBar mStrokeWidthBar ;
96- private SeekBar mStrokeHueBar ;
97- private SeekBar mStrokeAlphaBar ;
98- private Spinner mStrokePatternSpinner ;
99- private CheckBox mClickabilityCheckbox ;
93+ private SeekBar fillHueBar ;
94+ private SeekBar fillAlphaBar ;
95+ private SeekBar strokeWidthBar ;
96+ private SeekBar strokeHueBar ;
97+ private SeekBar strokeAlphaBar ;
98+ private Spinner strokePatternSpinner ;
99+ private CheckBox clickabilityCheckbox ;
100100
101101 // These are the options for stroke patterns. We use their
102102 // string resource IDs as identifiers.
@@ -109,57 +109,57 @@ public class CircleDemoActivity extends AppCompatActivity
109109 };
110110
111111 private class DraggableCircle {
112- private final Marker mCenterMarker ;
113- private final Marker mRadiusMarker ;
114- private final Circle mCircle ;
115- private double mRadiusMeters ;
112+ private final Marker centerMarker ;
113+ private final Marker radiusMarker ;
114+ private final Circle circle ;
115+ private double radiusMeters ;
116116
117117 public DraggableCircle (LatLng center , double radiusMeters ) {
118- mRadiusMeters = radiusMeters ;
119- mCenterMarker = mMap .addMarker (new MarkerOptions ()
118+ this . radiusMeters = radiusMeters ;
119+ centerMarker = map .addMarker (new MarkerOptions ()
120120 .position (center )
121121 .draggable (true ));
122- mRadiusMarker = mMap .addMarker (new MarkerOptions ()
122+ radiusMarker = map .addMarker (new MarkerOptions ()
123123 .position (toRadiusLatLng (center , radiusMeters ))
124124 .draggable (true )
125125 .icon (BitmapDescriptorFactory .defaultMarker (
126126 BitmapDescriptorFactory .HUE_AZURE )));
127- mCircle = mMap .addCircle (new CircleOptions ()
127+ circle = map .addCircle (new CircleOptions ()
128128 .center (center )
129129 .radius (radiusMeters )
130- .strokeWidth (mStrokeWidthBar .getProgress ())
131- .strokeColor (mStrokeColorArgb )
132- .fillColor (mFillColorArgb )
133- .clickable (mClickabilityCheckbox .isChecked ()));
130+ .strokeWidth (strokeWidthBar .getProgress ())
131+ .strokeColor (strokeColorArgb )
132+ .fillColor (fillColorArgb )
133+ .clickable (clickabilityCheckbox .isChecked ()));
134134 }
135135
136136 public boolean onMarkerMoved (Marker marker ) {
137- if (marker .equals (mCenterMarker )) {
138- mCircle .setCenter (marker .getPosition ());
139- mRadiusMarker .setPosition (toRadiusLatLng (marker .getPosition (), mRadiusMeters ));
137+ if (marker .equals (centerMarker )) {
138+ circle .setCenter (marker .getPosition ());
139+ radiusMarker .setPosition (toRadiusLatLng (marker .getPosition (), radiusMeters ));
140140 return true ;
141141 }
142- if (marker .equals (mRadiusMarker )) {
143- mRadiusMeters =
144- toRadiusMeters (mCenterMarker .getPosition (), mRadiusMarker .getPosition ());
145- mCircle .setRadius (mRadiusMeters );
142+ if (marker .equals (radiusMarker )) {
143+ radiusMeters =
144+ toRadiusMeters (centerMarker .getPosition (), radiusMarker .getPosition ());
145+ circle .setRadius (radiusMeters );
146146 return true ;
147147 }
148148 return false ;
149149 }
150150
151151 public void onStyleChange () {
152- mCircle .setStrokeWidth (mStrokeWidthBar .getProgress ());
153- mCircle .setStrokeColor (mStrokeColorArgb );
154- mCircle .setFillColor (mFillColorArgb );
152+ circle .setStrokeWidth (strokeWidthBar .getProgress ());
153+ circle .setStrokeColor (strokeColorArgb );
154+ circle .setFillColor (fillColorArgb );
155155 }
156156
157157 public void setStrokePattern (List <PatternItem > pattern ) {
158- mCircle .setStrokePattern (pattern );
158+ circle .setStrokePattern (pattern );
159159 }
160160
161161 public void setClickable (boolean clickable ) {
162- mCircle .setClickable (clickable );
162+ circle .setClickable (clickable );
163163 }
164164 }
165165
@@ -182,32 +182,32 @@ protected void onCreate(Bundle savedInstanceState) {
182182 super .onCreate (savedInstanceState );
183183 setContentView (R .layout .circle_demo );
184184
185- mFillHueBar = ( SeekBar ) findViewById (R .id .fillHueSeekBar );
186- mFillHueBar .setMax (MAX_HUE_DEGREES );
187- mFillHueBar .setProgress (MAX_HUE_DEGREES / 2 );
185+ fillHueBar = findViewById (R .id .fillHueSeekBar );
186+ fillHueBar .setMax (MAX_HUE_DEGREES );
187+ fillHueBar .setProgress (MAX_HUE_DEGREES / 2 );
188188
189- mFillAlphaBar = ( SeekBar ) findViewById (R .id .fillAlphaSeekBar );
190- mFillAlphaBar .setMax (MAX_ALPHA );
191- mFillAlphaBar .setProgress (MAX_ALPHA / 2 );
189+ fillAlphaBar = findViewById (R .id .fillAlphaSeekBar );
190+ fillAlphaBar .setMax (MAX_ALPHA );
191+ fillAlphaBar .setProgress (MAX_ALPHA / 2 );
192192
193- mStrokeWidthBar = ( SeekBar ) findViewById (R .id .strokeWidthSeekBar );
194- mStrokeWidthBar .setMax (MAX_WIDTH_PX );
195- mStrokeWidthBar .setProgress (MAX_WIDTH_PX / 3 );
193+ strokeWidthBar = findViewById (R .id .strokeWidthSeekBar );
194+ strokeWidthBar .setMax (MAX_WIDTH_PX );
195+ strokeWidthBar .setProgress (MAX_WIDTH_PX / 3 );
196196
197- mStrokeHueBar = ( SeekBar ) findViewById (R .id .strokeHueSeekBar );
198- mStrokeHueBar .setMax (MAX_HUE_DEGREES );
199- mStrokeHueBar .setProgress (0 );
197+ strokeHueBar = findViewById (R .id .strokeHueSeekBar );
198+ strokeHueBar .setMax (MAX_HUE_DEGREES );
199+ strokeHueBar .setProgress (0 );
200200
201- mStrokeAlphaBar = ( SeekBar ) findViewById (R .id .strokeAlphaSeekBar );
202- mStrokeAlphaBar .setMax (MAX_ALPHA );
203- mStrokeAlphaBar .setProgress (MAX_ALPHA );
201+ strokeAlphaBar = findViewById (R .id .strokeAlphaSeekBar );
202+ strokeAlphaBar .setMax (MAX_ALPHA );
203+ strokeAlphaBar .setProgress (MAX_ALPHA );
204204
205- mStrokePatternSpinner = ( Spinner ) findViewById (R .id .strokePatternSpinner );
206- mStrokePatternSpinner .setAdapter (new ArrayAdapter <>(
205+ strokePatternSpinner = findViewById (R .id .strokePatternSpinner );
206+ strokePatternSpinner .setAdapter (new ArrayAdapter <>(
207207 this , android .R .layout .simple_spinner_item ,
208208 getResourceStrings (PATTERN_TYPE_NAME_RESOURCE_IDS )));
209209
210- mClickabilityCheckbox = ( CheckBox ) findViewById (R .id .toggleClickability );
210+ clickabilityCheckbox = findViewById (R .id .toggleClickability );
211211
212212 SupportMapFragment mapFragment =
213213 (SupportMapFragment ) getSupportFragmentManager ().findFragmentById (R .id .map );
@@ -223,45 +223,45 @@ private String[] getResourceStrings(int[] resourceIds) {
223223 }
224224
225225 @ Override
226- public void onMapReady (GoogleMap map ) {
226+ public void onMapReady (GoogleMap googleMap ) {
227227 // Override the default content description on the view, for accessibility mode.
228- map .setContentDescription (getString (R .string .map_circle_description ));
228+ googleMap .setContentDescription (getString (R .string .map_circle_description ));
229229
230- mMap = map ;
231- mMap .setOnMarkerDragListener (this );
232- mMap .setOnMapLongClickListener (this );
230+ map = googleMap ;
231+ map .setOnMarkerDragListener (this );
232+ map .setOnMapLongClickListener (this );
233233
234- mFillColorArgb = Color .HSVToColor (
235- mFillAlphaBar .getProgress (), new float []{mFillHueBar .getProgress (), 1 , 1 });
236- mStrokeColorArgb = Color .HSVToColor (
237- mStrokeAlphaBar .getProgress (), new float []{mStrokeHueBar .getProgress (), 1 , 1 });
234+ fillColorArgb = Color .HSVToColor (
235+ fillAlphaBar .getProgress (), new float []{fillHueBar .getProgress (), 1 , 1 });
236+ strokeColorArgb = Color .HSVToColor (
237+ strokeAlphaBar .getProgress (), new float []{strokeHueBar .getProgress (), 1 , 1 });
238238
239- mFillHueBar .setOnSeekBarChangeListener (this );
240- mFillAlphaBar .setOnSeekBarChangeListener (this );
239+ fillHueBar .setOnSeekBarChangeListener (this );
240+ fillAlphaBar .setOnSeekBarChangeListener (this );
241241
242- mStrokeWidthBar .setOnSeekBarChangeListener (this );
243- mStrokeHueBar .setOnSeekBarChangeListener (this );
244- mStrokeAlphaBar .setOnSeekBarChangeListener (this );
242+ strokeWidthBar .setOnSeekBarChangeListener (this );
243+ strokeHueBar .setOnSeekBarChangeListener (this );
244+ strokeAlphaBar .setOnSeekBarChangeListener (this );
245245
246- mStrokePatternSpinner .setOnItemSelectedListener (this );
246+ strokePatternSpinner .setOnItemSelectedListener (this );
247247
248248 DraggableCircle circle = new DraggableCircle (SYDNEY , DEFAULT_RADIUS_METERS );
249- mCircles .add (circle );
249+ circles .add (circle );
250250
251251 // Move the map so that it is centered on the initial circle
252- mMap .moveCamera (CameraUpdateFactory .newLatLngZoom (SYDNEY , 4.0f ));
252+ map .moveCamera (CameraUpdateFactory .newLatLngZoom (SYDNEY , 4.0f ));
253253
254254 // Set up the click listener for the circle.
255- map .setOnCircleClickListener (new OnCircleClickListener () {
255+ googleMap .setOnCircleClickListener (new OnCircleClickListener () {
256256 @ Override
257257 public void onCircleClick (Circle circle ) {
258258 // Flip the red, green and blue components of the circle's stroke color.
259259 circle .setStrokeColor (circle .getStrokeColor () ^ 0x00ffffff );
260260 }
261261 });
262262
263- List <PatternItem > pattern = getSelectedPattern (mStrokePatternSpinner .getSelectedItemPosition ());
264- for (DraggableCircle draggableCircle : mCircles ) {
263+ List <PatternItem > pattern = getSelectedPattern (strokePatternSpinner .getSelectedItemPosition ());
264+ for (DraggableCircle draggableCircle : circles ) {
265265 draggableCircle .setStrokePattern (pattern );
266266 }
267267 }
@@ -284,7 +284,7 @@ private List<PatternItem> getSelectedPattern(int pos) {
284284 @ Override
285285 public void onItemSelected (AdapterView <?> parent , View view , int pos , long id ) {
286286 if (parent .getId () == R .id .strokePatternSpinner ) {
287- for (DraggableCircle draggableCircle : mCircles ) {
287+ for (DraggableCircle draggableCircle : circles ) {
288288 draggableCircle .setStrokePattern (getSelectedPattern (pos ));
289289 }
290290 }
@@ -307,21 +307,21 @@ public void onStartTrackingTouch(SeekBar seekBar) {
307307
308308 @ Override
309309 public void onProgressChanged (SeekBar seekBar , int progress , boolean fromUser ) {
310- if (seekBar == mFillHueBar ) {
311- mFillColorArgb =
312- Color .HSVToColor (Color .alpha (mFillColorArgb ), new float []{progress , 1 , 1 });
313- } else if (seekBar == mFillAlphaBar ) {
314- mFillColorArgb = Color .argb (progress , Color .red (mFillColorArgb ),
315- Color .green (mFillColorArgb ), Color .blue (mFillColorArgb ));
316- } else if (seekBar == mStrokeHueBar ) {
317- mStrokeColorArgb =
318- Color .HSVToColor (Color .alpha (mStrokeColorArgb ), new float []{progress , 1 , 1 });
319- } else if (seekBar == mStrokeAlphaBar ) {
320- mStrokeColorArgb = Color .argb (progress , Color .red (mStrokeColorArgb ),
321- Color .green (mStrokeColorArgb ), Color .blue (mStrokeColorArgb ));
310+ if (seekBar == fillHueBar ) {
311+ fillColorArgb =
312+ Color .HSVToColor (Color .alpha (fillColorArgb ), new float []{progress , 1 , 1 });
313+ } else if (seekBar == fillAlphaBar ) {
314+ fillColorArgb = Color .argb (progress , Color .red (fillColorArgb ),
315+ Color .green (fillColorArgb ), Color .blue (fillColorArgb ));
316+ } else if (seekBar == strokeHueBar ) {
317+ strokeColorArgb =
318+ Color .HSVToColor (Color .alpha (strokeColorArgb ), new float []{progress , 1 , 1 });
319+ } else if (seekBar == strokeAlphaBar ) {
320+ strokeColorArgb = Color .argb (progress , Color .red (strokeColorArgb ),
321+ Color .green (strokeColorArgb ), Color .blue (strokeColorArgb ));
322322 }
323323
324- for (DraggableCircle draggableCircle : mCircles ) {
324+ for (DraggableCircle draggableCircle : circles ) {
325325 draggableCircle .onStyleChange ();
326326 }
327327 }
@@ -342,7 +342,7 @@ public void onMarkerDrag(Marker marker) {
342342 }
343343
344344 private void onMarkerMoved (Marker marker ) {
345- for (DraggableCircle draggableCircle : mCircles ) {
345+ for (DraggableCircle draggableCircle : circles ) {
346346 if (draggableCircle .onMarkerMoved (marker )) {
347347 break ;
348348 }
@@ -353,19 +353,19 @@ private void onMarkerMoved(Marker marker) {
353353 public void onMapLongClick (LatLng point ) {
354354 // We know the center, let's place the outline at a point 3/4 along the view.
355355 View view = getSupportFragmentManager ().findFragmentById (R .id .map ).getView ();
356- LatLng radiusLatLng = mMap .getProjection ().fromScreenLocation (new Point (
356+ LatLng radiusLatLng = map .getProjection ().fromScreenLocation (new Point (
357357 view .getHeight () * 3 / 4 , view .getWidth () * 3 / 4 ));
358358
359359 // Create the circle.
360360 DraggableCircle circle = new DraggableCircle (point , toRadiusMeters (point , radiusLatLng ));
361- mCircles .add (circle );
361+ circles .add (circle );
362362 }
363363
364364 public void toggleClickability (View view ) {
365365 boolean clickable = ((CheckBox ) view ).isChecked ();
366366 // Set each of the circles to be clickable or not, based on the
367367 // state of the checkbox.
368- for (DraggableCircle draggableCircle : mCircles ) {
368+ for (DraggableCircle draggableCircle : circles ) {
369369 draggableCircle .setClickable (clickable );
370370 }
371371 }
0 commit comments