Skip to content

Commit 7a9c41b

Browse files
committed
Merge pull request #1606 from cascheberg/fix-centerme
Improve map centering button
2 parents 705d0e0 + 04a6ef1 commit 7a9c41b

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

Diff for: android/src/main/java/org/mozilla/mozstumbler/client/mapview/MapFragment.java

+22-24
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.graphics.Canvas;
1111
import android.graphics.Paint;
1212
import android.location.Location;
13-
import android.location.LocationManager;
1413
import android.net.ConnectivityManager;
1514
import android.net.NetworkInfo;
1615
import android.os.Build;
@@ -30,7 +29,6 @@
3029
import org.mozilla.mozstumbler.BuildConfig;
3130
import org.mozilla.mozstumbler.R;
3231
import org.mozilla.mozstumbler.client.ClientPrefs;
33-
import org.mozilla.mozstumbler.client.ClientStumblerService;
3432
import org.mozilla.mozstumbler.client.MainApp;
3533
import org.mozilla.mozstumbler.client.ObservedLocationsReceiver;
3634
import org.mozilla.mozstumbler.client.mapview.tiles.AbstractMapOverlay;
@@ -83,8 +81,8 @@ public class MapFragment extends android.support.v4.app.Fragment
8381
private final Timer mGetUrl = new Timer();
8482
private MapView mMap;
8583
private AccuracyCircleOverlay mAccuracyOverlay;
86-
private boolean mFirstLocationFix;
87-
private boolean mUserPanning = false;
84+
private static boolean sHadFirstLocationFix = false;
85+
private static boolean sUserPanning = true;
8886
private ObservationPointsOverlay mObservationPointsOverlay;
8987
private MapLocationListener mMapLocationListener;
9088
private LowResMapOverlay mLowResMapOverlayHighZoom;
@@ -144,15 +142,15 @@ private void initializeMapControls() {
144142

145143
private void initializeCenterMeListener() {
146144
final ImageButton centerMe = (ImageButton) mRootView.findViewById(R.id.my_location_button);
147-
centerMe.setVisibility(View.INVISIBLE);
145+
updateCenterButtonIcon();
148146
centerMe.setOnClickListener(new View.OnClickListener() {
149147
@Override
150148
public void onClick(View v) {
151149
if (mAccuracyOverlay == null || mAccuracyOverlay.getLocation() == null)
152150
return;
153151
mMap.getController().animateTo((mAccuracyOverlay.getLocation()));
154-
mUserPanning = false;
155-
centerMe.setBackgroundResource(R.drawable.ic_mylocation_android_assets);
152+
sUserPanning = false;
153+
updateCenterButtonIcon();
156154
}
157155
});
158156
}
@@ -163,8 +161,8 @@ private void initializeListeners() {
163161
mMap.getOverlays().add(new SwipeListeningOverlay(getActivity().getApplicationContext(), new SwipeListeningOverlay.OnSwipeListener() {
164162
@Override
165163
public void onSwipe() {
166-
mUserPanning = true;
167-
setCenterButtonToNotCenteredIcon();
164+
sUserPanning = true;
165+
updateCenterButtonIcon();
168166
}
169167
}));
170168

@@ -199,13 +197,11 @@ private void initializeMapOverlays() {
199197
}
200198

201199
private void initializeLastLocation(Bundle savedInstanceState) {
202-
mFirstLocationFix = true;
203200
int zoomLevel;
204201
GeoPoint lastLoc = null;
205202
if (savedInstanceState != null) {
206203
zoomLevel = savedInstanceState.getInt(ZOOM_KEY, DEFAULT_ZOOM);
207204
if (savedInstanceState.containsKey(LAT_KEY) && savedInstanceState.containsKey(LON_KEY)) {
208-
mFirstLocationFix = false;
209205
final double latitude = savedInstanceState.getDouble(LAT_KEY);
210206
final double longitude = savedInstanceState.getDouble(LON_KEY);
211207
lastLoc = new GeoPoint(latitude, longitude);
@@ -504,24 +500,25 @@ private void showCopyright() {
504500
}
505501
}
506502

507-
private void setCenterButtonToNotCenteredIcon() {
503+
private void updateCenterButtonIcon() {
508504
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+
}
511511
}
512512

513513
void setUserPositionAt(Location location) {
514-
if (mAccuracyOverlay.getLocation() == null) {
515-
setCenterButtonToNotCenteredIcon();
516-
}
517-
518514
mAccuracyOverlay.setLocation(location);
519515

520-
if (mFirstLocationFix) {
516+
if (!sHadFirstLocationFix) {
521517
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) {
525522
mMap.getController().animateTo((mAccuracyOverlay.getLocation()));
526523
}
527524
}
@@ -715,8 +712,9 @@ protected void draw(Canvas c, MapView osmv, boolean shadow) {
715712
}
716713

717714
@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) {
720718
mOnSwipe.onSwipe();
721719
}
722720
return false;

0 commit comments

Comments
 (0)