10
10
import android .graphics .Canvas ;
11
11
import android .graphics .Paint ;
12
12
import android .location .Location ;
13
- import android .location .LocationManager ;
14
13
import android .net .ConnectivityManager ;
15
14
import android .net .NetworkInfo ;
16
15
import android .os .Build ;
30
29
import org .mozilla .mozstumbler .BuildConfig ;
31
30
import org .mozilla .mozstumbler .R ;
32
31
import org .mozilla .mozstumbler .client .ClientPrefs ;
33
- import org .mozilla .mozstumbler .client .ClientStumblerService ;
34
32
import org .mozilla .mozstumbler .client .MainApp ;
35
33
import org .mozilla .mozstumbler .client .ObservedLocationsReceiver ;
36
34
import org .mozilla .mozstumbler .client .mapview .tiles .AbstractMapOverlay ;
@@ -83,8 +81,8 @@ public class MapFragment extends android.support.v4.app.Fragment
83
81
private final Timer mGetUrl = new Timer ();
84
82
private MapView mMap ;
85
83
private AccuracyCircleOverlay mAccuracyOverlay ;
86
- private boolean mFirstLocationFix ;
87
- private boolean mUserPanning = false ;
84
+ private static boolean sHadFirstLocationFix = false ;
85
+ private static boolean sUserPanning = true ;
88
86
private ObservationPointsOverlay mObservationPointsOverlay ;
89
87
private MapLocationListener mMapLocationListener ;
90
88
private LowResMapOverlay mLowResMapOverlayHighZoom ;
@@ -144,15 +142,15 @@ private void initializeMapControls() {
144
142
145
143
private void initializeCenterMeListener () {
146
144
final ImageButton centerMe = (ImageButton ) mRootView .findViewById (R .id .my_location_button );
147
- centerMe . setVisibility ( View . INVISIBLE );
145
+ updateCenterButtonIcon ( );
148
146
centerMe .setOnClickListener (new View .OnClickListener () {
149
147
@ Override
150
148
public void onClick (View v ) {
151
149
if (mAccuracyOverlay == null || mAccuracyOverlay .getLocation () == null )
152
150
return ;
153
151
mMap .getController ().animateTo ((mAccuracyOverlay .getLocation ()));
154
- mUserPanning = false ;
155
- centerMe . setBackgroundResource ( R . drawable . ic_mylocation_android_assets );
152
+ sUserPanning = false ;
153
+ updateCenterButtonIcon ( );
156
154
}
157
155
});
158
156
}
@@ -163,8 +161,8 @@ private void initializeListeners() {
163
161
mMap .getOverlays ().add (new SwipeListeningOverlay (getActivity ().getApplicationContext (), new SwipeListeningOverlay .OnSwipeListener () {
164
162
@ Override
165
163
public void onSwipe () {
166
- mUserPanning = true ;
167
- setCenterButtonToNotCenteredIcon ();
164
+ sUserPanning = true ;
165
+ updateCenterButtonIcon ();
168
166
}
169
167
}));
170
168
@@ -199,13 +197,11 @@ private void initializeMapOverlays() {
199
197
}
200
198
201
199
private void initializeLastLocation (Bundle savedInstanceState ) {
202
- mFirstLocationFix = true ;
203
200
int zoomLevel ;
204
201
GeoPoint lastLoc = null ;
205
202
if (savedInstanceState != null ) {
206
203
zoomLevel = savedInstanceState .getInt (ZOOM_KEY , DEFAULT_ZOOM );
207
204
if (savedInstanceState .containsKey (LAT_KEY ) && savedInstanceState .containsKey (LON_KEY )) {
208
- mFirstLocationFix = false ;
209
205
final double latitude = savedInstanceState .getDouble (LAT_KEY );
210
206
final double longitude = savedInstanceState .getDouble (LON_KEY );
211
207
lastLoc = new GeoPoint (latitude , longitude );
@@ -504,24 +500,25 @@ private void showCopyright() {
504
500
}
505
501
}
506
502
507
- private void setCenterButtonToNotCenteredIcon () {
503
+ private void updateCenterButtonIcon () {
508
504
ImageButton centerMe = (ImageButton ) mRootView .findViewById (R .id .my_location_button );
509
- centerMe .setVisibility (View .VISIBLE );
510
- centerMe .setBackgroundResource (R .drawable .ic_mylocation_no_dot_android_assets );
505
+ centerMe .setVisibility (sHadFirstLocationFix ? View .VISIBLE : View .INVISIBLE );
506
+ if (sUserPanning ) {
507
+ centerMe .setBackgroundResource (R .drawable .ic_mylocation_no_dot_android_assets );
508
+ } else {
509
+ centerMe .setBackgroundResource (R .drawable .ic_mylocation_android_assets );
510
+ }
511
511
}
512
512
513
513
void setUserPositionAt (Location location ) {
514
- if (mAccuracyOverlay .getLocation () == null ) {
515
- setCenterButtonToNotCenteredIcon ();
516
- }
517
-
518
514
mAccuracyOverlay .setLocation (location );
519
515
520
- if (mFirstLocationFix ) {
516
+ if (! sHadFirstLocationFix ) {
521
517
setCenterAndZoom (new GeoPoint (location ), DEFAULT_ZOOM_AFTER_FIX );
522
- mFirstLocationFix = false ;
523
- mUserPanning = false ;
524
- } else if (!mUserPanning ) {
518
+ sHadFirstLocationFix = true ;
519
+ sUserPanning = false ;
520
+ updateCenterButtonIcon ();
521
+ } else if (!sUserPanning ) {
525
522
mMap .getController ().animateTo ((mAccuracyOverlay .getLocation ()));
526
523
}
527
524
}
@@ -715,8 +712,9 @@ protected void draw(Canvas c, MapView osmv, boolean shadow) {
715
712
}
716
713
717
714
@ Override
718
- public boolean onTouchEvent (final MotionEvent event , final MapView mapView ) {
719
- if (mOnSwipe != null && event .getAction () == MotionEvent .ACTION_MOVE ) {
715
+ public boolean onScroll (final MotionEvent pEvent1 , final MotionEvent pEvent2 ,
716
+ final float pDistanceX , final float pDistanceY , final MapView pMapView ) {
717
+ if (mOnSwipe != null ) {
720
718
mOnSwipe .onSwipe ();
721
719
}
722
720
return false ;
0 commit comments