Skip to content
Permalink
Browse files

Merge pull request #1419 from osmdroid/feature/#1418

feature/#1418 - custom zoom refactoring while removing the old standard zoom controllers
  • Loading branch information...
monsieurtanuki committed Oct 14, 2019
2 parents 2aab5a9 + dd0a677 commit 795171a4bbdc797265cce89b69894aa4253a6926
@@ -95,7 +95,6 @@ public void addOverlays() {
mLocationOverlay.enableFollowLocation();
mLocationOverlay.enableMyLocation();
this.mMapView.getOverlayManager().add(mLocationOverlay);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mMapView.setTilesScaledToDpi(true);
}
@@ -69,7 +69,6 @@ public boolean onZoom(ZoomEvent event) {
}
}, DEFAULT_INACTIVITY_DELAY_IN_MILLISECS));

mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mMapView.setTilesScaledToDpi(true);

@@ -53,7 +53,6 @@ protected void addOverlays() {
mMapView2.setTileSource(new MapBoxTileSource(getContext()));
mMapView2.setMapListener(this);

mMapView2.setBuiltInZoomControls(true);
mMapView2.setMultiTouchControls(true);
mMapView2.setTilesScaledToDpi(true);
}
@@ -113,7 +113,6 @@ public void onBindViewHolder(ViewHolder viewHolder, int position) {

Info dat = data.get(position);
MapViewHolder Indicador = (MapViewHolder) viewHolder;
Indicador.mapaShow.setBuiltInZoomControls(true);
Indicador.mapaShow.setMultiTouchControls(true);
Indicador.mapaShow.setClickable(false);

@@ -70,7 +70,6 @@ public void onViewCreated(View view, Bundle savedInstanceState) {

mMapView.getController().setZoom(15);
mMapView.setTilesScaledToDpi(true);
mMapView.setBuiltInZoomControls(true);
mMapView.setMultiTouchControls(true);
mMapView.setFlingEnabled(true);
mMapView.getOverlays().add(this.mLocationOverlay);
@@ -63,7 +63,6 @@ public void addOverlays() {
overlay.setEnableAutoStop(false);
overlay.enableFollowLocation();
overlay.enableMyLocation();
mMapView.setBuiltInZoomControls(true);
this.mMapView.getOverlayManager().add(overlay);
}

@@ -182,20 +182,20 @@ private boolean checkJustActivated() {
return false;
}

private boolean isTouched(final MotionEvent pMotionEvent) {
public boolean isTouched(final MotionEvent pMotionEvent) {
if (mAlpha01 == 0) {
return false;
}
if (checkJustActivated()) {
return false;
}
if (mDisplay.isTouchedRotated(pMotionEvent, true)) {
if (mDisplay.isTouched(pMotionEvent, true)) {
if (mZoomInEnabled && mListener != null) {
mListener.onZoom(true);
}
return true;
}
if (mDisplay.isTouchedRotated(pMotionEvent, false)) {
if (mDisplay.isTouched(pMotionEvent, false)) {
if (mZoomOutEnabled && mListener != null) {
mListener.onZoom(false);
}
@@ -210,10 +210,12 @@ private boolean isTouched(final MotionEvent pMotionEvent) {
void onZoom(boolean b);
}

@Deprecated
public boolean onSingleTapConfirmed(final MotionEvent pMotionEvent) {
return isTouched(pMotionEvent);
}

@Deprecated
public boolean onLongPress(final MotionEvent pMotionEvent) {
return isTouched(pMotionEvent);
}
@@ -137,8 +137,8 @@ private float getFirstLeft(final int pMapViewWidth) {
return pMapViewWidth - mMargin * mBitmapSize - mBitmapSize
- (mHorizontalOrVertical ? mPadding * mBitmapSize + mBitmapSize : 0);
case CENTER:
return pMapViewWidth / 2
- (mHorizontalOrVertical ? mPadding * mBitmapSize / 2 + mBitmapSize : mBitmapSize / 2);
return pMapViewWidth / 2f
- (mHorizontalOrVertical ? mPadding * mBitmapSize / 2 + mBitmapSize : mBitmapSize / 2f);
}
throw new IllegalArgumentException();
}
@@ -151,8 +151,8 @@ private float getFirstTop(final int pMapViewHeight) {
return pMapViewHeight - mMargin * mBitmapSize - mBitmapSize
- (mHorizontalOrVertical ? 0 : mPadding * mBitmapSize + mBitmapSize);
case CENTER:
return pMapViewHeight / 2
- (mHorizontalOrVertical ? mBitmapSize / 2 : mPadding * mBitmapSize / 2 + mBitmapSize);
return pMapViewHeight / 2f
- (mHorizontalOrVertical ? mBitmapSize / 2f : mPadding * mBitmapSize / 2 + mBitmapSize);
}
throw new IllegalArgumentException();
}
@@ -172,6 +172,7 @@ private Bitmap getBitmap(final boolean pInOrOut, final boolean pEnabled) {
return pEnabled ? mZoomOutBitmapEnabled : mZoomOutBitmapDisabled;
}

@Deprecated
public boolean isTouchedRotated(final MotionEvent pMotionEvent, final boolean pInOrOut) {
if (mMapView.getMapOrientation() == 0) {
mUnrotatedPoint.set((int) pMotionEvent.getX(), (int) pMotionEvent.getY());
@@ -182,6 +183,13 @@ public boolean isTouchedRotated(final MotionEvent pMotionEvent, final boolean pI
return isTouched(mUnrotatedPoint.x, mUnrotatedPoint.y, pInOrOut);
}

/**
* @since 6.1.3
*/
public boolean isTouched(final MotionEvent pMotionEvent, final boolean pInOrOut) {
return isTouched((int) pMotionEvent.getX(), (int) pMotionEvent.getY(), pInOrOut);
}

private boolean isTouched(final int pEventX, final int pEventY, final boolean pInOrOut) {
return isTouched(pInOrOut, true, pEventX)
&& isTouched(pInOrOut, false, pEventY);
@@ -16,10 +16,8 @@
import org.osmdroid.events.MapListener;
import org.osmdroid.events.ScrollEvent;
import org.osmdroid.events.ZoomEvent;
import org.osmdroid.tileprovider.MapTileProviderArray;
import org.osmdroid.tileprovider.MapTileProviderBase;
import org.osmdroid.tileprovider.MapTileProviderBasic;
import org.osmdroid.tileprovider.modules.MapTileModuleProviderBase;
import org.osmdroid.tileprovider.tilesource.IStyledTileSource;
import org.osmdroid.tileprovider.tilesource.ITileSource;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
@@ -91,8 +89,6 @@

private final MapController mController;

private final ZoomButtonsController mOldZoomController;
private boolean mEnableOldZoomController;
private final CustomZoomButtonsController mZoomController;


@@ -212,7 +208,6 @@ public MapView(final Context context,
if(isInEditMode()){ //fix for edit mode in the IDE
mTileRequestCompleteHandler=null;
mController=null;
mOldZoomController=null;
mZoomController=null;
mScroller=null;
mGestureDetector=null;
@@ -226,9 +221,7 @@ public MapView(final Context context,

if (tileProvider == null) {
final ITileSource tileSource = getTileSourceFromAttributes(attrs);
tileProvider = isInEditMode()
? new MapTileProviderArray(tileSource, null, new MapTileModuleProviderBase[0])
: new MapTileProviderBasic(context.getApplicationContext(), tileSource);
tileProvider = new MapTileProviderBasic(context.getApplicationContext(), tileSource);
}

mTileRequestCompleteHandler = tileRequestCompleteHandler == null
@@ -241,12 +234,6 @@ public MapView(final Context context,
this.mMapOverlay = new TilesOverlay(mTileProvider, context, horizontalMapRepetitionEnabled, verticalMapRepetitionEnabled);
mOverlayManager = new DefaultOverlayManager(mMapOverlay);

if (isInEditMode()) {
mOldZoomController = null;
} else {
mOldZoomController = new ZoomButtonsController(this);
mOldZoomController.setOnZoomListener(new MapViewZoomListener());
}
mZoomController = new CustomZoomButtonsController(this);
mZoomController.setOnZoomListener(new MapViewZoomListener());
checkZoomButtons();
@@ -263,7 +250,7 @@ public MapView(final Context context,
if (Build.VERSION.SDK_INT >= 16)
this.setHasTransientState(true);

setBuiltInZoomControls(true);
mZoomController.setVisibility(CustomZoomButtonsController.Visibility.SHOW_AND_FADEOUT);
}

/**
@@ -1062,7 +1049,6 @@ public void onResume(){
public void onDetach() {
this.getOverlayManager().onDetach(this);
mTileProvider.detach();
mOldZoomController.setVisible(false);
if (mZoomController != null) {
mZoomController.onDetach();
}
@@ -1112,7 +1098,8 @@ public boolean dispatchTouchEvent(final MotionEvent event) {
Log.d(IMapView.LOGTAG,"dispatchTouchEvent(" + event + ")");
}

if (mOldZoomController.isVisible() && mOldZoomController.onTouch(this, event)) {
if (mZoomController.isTouched(event)) {
mZoomController.activate();
return true;
}

@@ -1405,13 +1392,9 @@ private void checkZoomButtons() {
*/
@Deprecated
public void setBuiltInZoomControls(final boolean on) {
this.mEnableOldZoomController = on;
this.checkZoomButtons();
/*
getZoomController().setVisibility(
mZoomController.setVisibility(
on ? CustomZoomButtonsController.Visibility.SHOW_AND_FADEOUT
: CustomZoomButtonsController.Visibility.NEVER);
*/
}

public void setMultiTouchControls(final boolean on) {
@@ -1520,7 +1503,6 @@ public boolean onDown(final MotionEvent e) {
return true;
}

mOldZoomController.setVisible(mEnableOldZoomController);
if (mZoomController != null) {
mZoomController.activate();
}
@@ -1559,9 +1541,6 @@ public void onLongPress(final MotionEvent e) {
if (mMultiTouchController != null && mMultiTouchController.isPinching()) {
return;
}
if (mZoomController != null && mZoomController.onLongPress(e)) {
return;
}
MapView.this.getOverlayManager().onLongPress(e, MapView.this);
}

@@ -1600,10 +1579,6 @@ public boolean onDoubleTap(final MotionEvent e) {
return true;
}

if (mZoomController != null && mZoomController.onSingleTapConfirmed(e)) {
return true;
}

getProjection().rotateAndScalePoint((int) e.getX(), (int) e.getY(), mRotateScalePoint);
return getController().zoomInFixing(mRotateScalePoint.x, mRotateScalePoint.y);
}
@@ -1619,9 +1594,6 @@ public boolean onDoubleTapEvent(final MotionEvent e) {

@Override
public boolean onSingleTapConfirmed(final MotionEvent e) {
if (mZoomController != null && mZoomController.onSingleTapConfirmed(e)) {
return true;
}
if (MapView.this.getOverlayManager().onSingleTapConfirmed(e, MapView.this)) {
return true;
}
@@ -1886,7 +1858,6 @@ public MapViewRepository getRepository() {
* @since 6.1.0
*/
public CustomZoomButtonsController getZoomController() {
setBuiltInZoomControls(false);
return mZoomController;
}

@@ -13,6 +13,11 @@

public class GarbageCollectorTest {

/**
* @since 6.1.3
*/
private static final long ACTION_MILLISECONDS = 500;

private final AtomicInteger mCount = new AtomicInteger(0);

@Test
@@ -30,10 +35,10 @@ public void testFirst() {
mCount.set(0);

garbageCollector.gc();
sleep(100);
sleepFactor(.5);
Assert.assertEquals(1, mCount.get());
Assert.assertTrue(garbageCollector.isRunning());
sleep(500);
sleepFactor(2);
Assert.assertFalse(garbageCollector.isRunning());
Assert.assertEquals(1, mCount.get());
}
@@ -44,18 +49,18 @@ public void testSecond() {
mCount.set(0);

garbageCollector.gc();
sleep(100);
sleepFactor(.5);
Assert.assertEquals(1, mCount.get());
Assert.assertTrue(garbageCollector.isRunning());
sleep(500);
sleepFactor(2);
Assert.assertFalse(garbageCollector.isRunning());
Assert.assertEquals(1, mCount.get());

garbageCollector.gc();
sleep(100);
sleepFactor(.5);
Assert.assertEquals(2, mCount.get());
Assert.assertTrue(garbageCollector.isRunning());
sleep(500);
sleepFactor(2);
Assert.assertFalse(garbageCollector.isRunning());
Assert.assertEquals(2, mCount.get());
}
@@ -69,10 +74,10 @@ public void testMulti() {
garbageCollector.gc();
garbageCollector.gc();
garbageCollector.gc();
sleep(100);
sleepFactor(.5);
Assert.assertEquals(1, mCount.get());
Assert.assertTrue(garbageCollector.isRunning());
sleep(500);
sleepFactor(2);
Assert.assertFalse(garbageCollector.isRunning());
Assert.assertEquals(1, mCount.get());
}
@@ -82,7 +87,7 @@ private Runnable getAction() {
@Override
public void run() {
mCount.incrementAndGet();
sleep(500);
sleepFactor(1);
}
};
}
@@ -94,4 +99,11 @@ private void sleep(final long millis) {
//
}
}

/**
* @since 6.1.3
*/
private void sleepFactor(final double pFactor) {
sleep(Math.round(ACTION_MILLISECONDS * pFactor));
}
}

0 comments on commit 795171a

Please sign in to comment.
You can’t perform that action at this time.