Skip to content

Commit

Permalink
Dual grid Pinch to zoom OK
Browse files Browse the repository at this point in the history
Tile display order on refresh sorted
DEV MODE
  • Loading branch information
jventrib committed Jan 9, 2013
1 parent 22179ca commit 7e65219
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 119 deletions.
8 changes: 6 additions & 2 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
<resources>
<string name="app_name">HexagonMap</string>
<string name="description_search">Search</string>
<string name="tileUrl">http://gpp3-wxs.ign.fr/4l9i6682teki4ang459b653o/geoportail/wmts?SERVICE=WMTS&amp;VERSION=1.0.0&amp;REQUEST=GetTile&amp;LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&amp;STYLE=normal&amp;FORMAT=image/jpeg&amp;TILEMATRIXSET=PM&amp;TILEMATRIX=!SCALE!&amp;TILEROW=!ROW!&amp;TILECOL=!COL!</string>
<string name="searchUrl">http://gpp3-wxs.ign.fr/4l9i6682teki4ang459b653o/geoportail/ols?</string>
<!-- DEV -->
<string name="tileUrl">http://gpp3-wxs.ign.fr/czj03g5y31qfnzwu782qd79t/geoportail/wmts?SERVICE=WMTS&amp;VERSION=1.0.0&amp;REQUEST=GetTile&amp;LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&amp;STYLE=normal&amp;FORMAT=image/jpeg&amp;TILEMATRIXSET=PM&amp;TILEMATRIX=!SCALE!&amp;TILEROW=!ROW!&amp;TILECOL=!COL!</string>
<string name="searchUrl">http://gpp3-wxs.ign.fr/czj03g5y31qfnzwu782qd79t/geoportail/ols?</string>
<!-- PROD -->
<!-- <string name="tileUrl">http://gpp3-wxs.ign.fr/4l9i6682teki4ang459b653o/geoportail/wmts?SERVICE=WMTS&amp;VERSION=1.0.0&amp;REQUEST=GetTile&amp;LAYER=GEOGRAPHICALGRIDSYSTEMS.MAPS&amp;STYLE=normal&amp;FORMAT=image/jpeg&amp;TILEMATRIXSET=PM&amp;TILEMATRIX=!SCALE!&amp;TILEROW=!ROW!&amp;TILECOL=!COL!</string> -->
<!-- <string name="searchUrl">http://gpp3-wxs.ign.fr/4l9i6682teki4ang459b653o/geoportail/ols?</string> -->
<string name="eula_title">Conditions générales d’utilisation finale, API Géoportail</string>
<string name="eula_accept">OK</string>
<string name="eula_refuse">Je refuse</string>
Expand Down
4 changes: 2 additions & 2 deletions src/com/hexagon/map/HexagonMapApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import android.app.Application;

@ReportsCrashes(formKey = "dHR0SUQ4WDEwekpVbHMwOHhGT3ZQeHc6MQ", mode=ReportingInteractionMode.TOAST)
//@ReportsCrashes(formKey = "dHR0SUQ4WDEwekpVbHMwOHhGT3ZQeHc6MQ", mode=ReportingInteractionMode.TOAST)
public class HexagonMapApplication extends Application {
@Override
public void onCreate() {
super.onCreate();

// The following line triggers the initialization of ACRA
ACRA.init(this);
// ACRA.init(this);
}
}
36 changes: 31 additions & 5 deletions src/com/hexagon/map/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@
import com.hexagon.map.preference.Preferences;
import com.hexagon.map.util.JveLog;

public class Image {
public class Image implements Cloneable {

public volatile LoadState state = LoadState.LOADING;

public volatile HttpGet method;

private String src;
private volatile String src;

private String cacheFileName;
private volatile String cacheFileName;

public Bitmap bmp;

public int alpha = 255;

public boolean visibleOnTop = true;

// public boolean visibleOnTop = false;

public Image(String src, String cacheFileName) {
update(src, cacheFileName);
}

public void update(String src, String cacheFileName) {
public Image() {
// TODO Auto-generated constructor stub
}

public synchronized void update(String src, String cacheFileName) {
this.src = src;
this.cacheFileName = cacheFileName;
state = LoadState.LOADING;
startLoadBitmap();
alpha = 0;
}

public void setSrc(String src) {
Expand All @@ -49,11 +57,14 @@ private void startLoadBitmap() {
.getBitmapFromMemCache(cacheFileName);
if (bitmapFromMemCache != null) {
bmp = bitmapFromMemCache;
state = LoadState.LOADED;
visibleOnTop = true;
JveLog.d("Image", "Loaded from LRU Cache");
return;
}
}
// JveLog.d("Image", "NOT Loaded from LRU Cache");
state = LoadState.LOADING;

CacheBitmapDownloadService.getInstance().submit(this);
}
Expand Down Expand Up @@ -87,5 +98,20 @@ public void clear() {
public boolean isCleared() {
return (state == LoadState.CLEARED);
}

@Override
protected Image clone() throws CloneNotSupportedException {
Image clone = (Image) super.clone();
if (bmp != null) {
// clone.bmp = Bitmap.createBitmap(bmp);
clone.bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth()/2, bmp.getHeight(), null, true);
clone.bmp = bmp.copy(bmp.getConfig(), false);
}
return clone;
}

public boolean isLoaded() {
return (state == LoadState.LOADED);
}

}
82 changes: 60 additions & 22 deletions src/com/hexagon/map/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class MapActivity extends SherlockActivity implements OnGestureListener,
private Sensor mSensor;
private ImageButton fsLocationButton;
private Date stopTime;
public long pinchDoneTime;

// /////////////////////////////////////////////////////////////////
// Lifecycle
Expand Down Expand Up @@ -131,7 +132,6 @@ protected void onStart() {
mScaleDetector = new ScaleGestureDetector(this,
new GestureListenerFactory()
.getGestureListener(rescalePinchZoom));

clearTimedCache();
}

Expand Down Expand Up @@ -321,7 +321,6 @@ private void initDisplay() {

main = new MapView(this, this);


setContentView(R.layout.main);
LinearLayout content = (LinearLayout) findViewById(R.id.mapLayout);

Expand All @@ -335,7 +334,11 @@ private void initDisplay() {

handleFullScreen(Preferences.isFullScreen());


initZoomController();

}

private void initZoomController() {
controller = new ZoomButtonsController(main);
controller.setOnZoomListener(new OnZoomListener() {

Expand All @@ -351,9 +354,8 @@ public void onVisibilityChanged(boolean visible) {
controller.setVisible(visible);
}
});
// controller.setVisible(true);
// controller.setVisible(true);
controller.setAutoDismissed(true);

}

/**
Expand Down Expand Up @@ -394,7 +396,7 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
}

private void zoomIn() {
if (!viewport.isZoomMax()) {
if (!viewport.isZoomMax() && !viewport.zoomOnGoing) {
JveLog.d(TAG, "zoom in");
JveLog.d(TAG, "scale : " + viewport.scale);
viewport.zoomInAnimated();
Expand All @@ -403,18 +405,20 @@ private void zoomIn() {
}

private void zoomOut() {
JveLog.d(TAG, "zoom out");
JveLog.d(TAG, "scale : " + viewport.scale);
viewport.zoomOutAnimated();
handleZoomControl();
if (!viewport.isZoomMin() && !viewport.zoomOnGoing) {
JveLog.d(TAG, "zoom out");
JveLog.d(TAG, "scale : " + viewport.scale);
viewport.zoomOutAnimated();
handleZoomControl();
}
}

private void zoom(int zoomOffset) {
if (zoomOffset > 0 && !viewport.isZoomMax()) {
viewport.scale += zoomOffset;
viewport.zoomAnimated(zoomOffset);
}
if (zoomOffset < 0 && !viewport.isZoomMin()) {
viewport.scale += zoomOffset;
viewport.zoomAnimated(zoomOffset);
}
handleZoomControl();
}
Expand Down Expand Up @@ -539,6 +543,19 @@ protected void onSaveInstanceState(Bundle outState) {

@Override
public boolean onTouchEvent(MotionEvent me) {
// long timeSincePinch = System.currentTimeMillis() - pinchDoneTime;
// if (timeSincePinch < 4) {
// return false;
// }
//
// if (me.getAction() == MotionEvent.ACTION_POINTER_UP
// || me.getAction() == MotionEvent.ACTION_UP) {
// pinchDone = false;
// }
// mScaleDetector.onTouchEvent(me);
// if (pinchDone) {
// return true;
// }

mScaleDetector.onTouchEvent(me);
viewport.resetInertiaScroll();
Expand Down Expand Up @@ -658,6 +675,7 @@ public boolean onOptionsItemSelected(
private void handleFullScreen(boolean fullScreen) {
if (fullScreen) {
getSupportActionBar().hide();

} else {
getSupportActionBar().show();
}
Expand All @@ -668,6 +686,7 @@ private void handleFullScreen(boolean fullScreen) {
locationButton.setVisibility(fullScreen ? View.VISIBLE : View.GONE);
ImageButton fsOffButton = (ImageButton) findViewById(R.id.fsOffButton);
fsOffButton.setVisibility(fullScreen ? View.VISIBLE : View.GONE);
initZoomController();
}

// /////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -731,6 +750,7 @@ public void onScaleEnd(ScaleGestureDetector detector) {

@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
viewport.copyGrid();
initialScaleFactor = 1.0f;
return true;
}
Expand Down Expand Up @@ -758,40 +778,58 @@ public boolean onScale(ScaleGestureDetector detector) {
public class TouchUpReScaleGestureListener implements
OnScaleGestureListener {

private static final float ZOOM_OUT_THESHOLD = 0.5f;
private static final float ZOOM_IN_THESHOLD = 2.0f;

@Override
public void onScaleEnd(ScaleGestureDetector detector) {
int zoomOffset = Math.round(viewport.zoomScale) - 1;
Log.d(TAG, "zoom offset : " + zoomOffset);

if (zoomOffset > 1)
zoomOffset = 1;
if (zoomOffset < -1)
zoomOffset = -1;
zoom(zoomOffset);
if (zoomOffset == 0) {
viewport.zoomReset(null);
}
float oldScale = viewport.zoomScale;
if (viewport.zoomScale < 0.5f) {
oldScale = viewport.zoomScale * 2;
} else if (viewport.zoomScale < 2.0f) {
oldScale = viewport.zoomScale / 2;
}
// if (viewport.zoomScale < ZOOM_OUT_THESHOLD) {
// oldScale = ZOOM_OUT_THESHOLD;
//
// } else if (viewport.zoomScale > ZOOM_IN_THESHOLD) {
// oldScale = ZOOM_IN_THESHOLD;
// }
viewport.zoomScale = 1.0f;
viewport.refresh();
// viewport.refresh();
if (zoomOffset != 0) {
viewport.zoomReset(oldScale);
}

pinchDone = true;
pinchDoneTime = System.currentTimeMillis();
}

@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
if (viewport.zoomOnGoing) {
return true;
}
viewport.copyGrid();
return true;
}

@Override
public boolean onScale(ScaleGestureDetector detector) {
Log.d(TAG, "zoom ongoing, scale: " + detector.getScaleFactor());
viewport.zoomScale = detector.getScaleFactor();
if (!viewport.zoomOnGoing) {
return true;
}

JveLog.d(TAG, "zoom ongoing, scale: " + detector.getScaleFactor());
viewport.zoomScale *= detector.getScaleFactor();
pinchDone = true;
return false;
return true;
}

}
Expand Down
Loading

0 comments on commit 7e65219

Please sign in to comment.