<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/zoom_in_focus"/>
<item android:state_pressed="true" android:drawable="@drawable/zoom_in_focus" />
<item android:state_enabled="false" android:drawable="@drawable/max_zoom_reached"/>
<item android:drawable="@drawable/zoom_in" />
</selector>
And this is the Activity
private static final File MAP_FILE = new File(Environment.getExternalStorageDirectory().getPath() + "/Bluetooth/", "isle.map");
private static final Byte MIN_ZOOM_LEVEL = new Byte("12");
private static final Byte MAX_ZOOM_LEVEL = new Byte("22");
private byte zoomLevelMax;
private byte zoomLevelMin;
private MyLocationOverlay myLocationOverlay;
MapView mapView;
private void configureMapView() {
FileOpenResult fileOpenResult = this.mapView.setMapFile(MAP_FILE);
if (!fileOpenResult.isSuccess()) {
Toast.makeText(this, fileOpenResult.getErrorMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mapView = (MapView) findViewById(R.id.mapView);
this.mapView.setBuiltInZoomControls(false);
this.mapView.setClickable(true);
MapFileInfo mapFileInfo = this.mapView.getMapDatabase().getMapFileInfo();
this.mapView.getMapViewPosition().setCenter(mapFileInfo.boundingBox.getCenterPoint());
this.mapView.setFocusable(true);
zoomLevelMin = MIN_ZOOM_LEVEL;
zoomLevelMax = MAX_ZOOM_LEVEL;
this.mapView.getMapZoomControls().setZoomLevelMin(zoomLevelMin);
this.mapView.getMapZoomControls().setZoomLevelMax(zoomLevelMax);
MapScaleBar mapScaleBar = this.mapView.getMapScaleBar();
mapScaleBar.setShowMapScaleBar(true);
ImageButton zoomIn = (ImageButton) findViewById(R.id.zoomIn);
zoomIn.setBackgroundResource(R.drawable.action_click_zoom_in);
zoomIn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mapView.getMapViewPosition().zoomIn();
}
});
ImageButton zoomOut = (ImageButton) findViewById(R.id.zoomOut);
zoomOut.setBackgroundResource(R.drawable.action_click_zoom_out);
zoomOut.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mapView.getMapViewPosition().zoomOut();
}
});
configureMapView();
}
Seems that the selector can not see when the maxzoom is reached and insert the icon max_zoom_reached
void onZoomLevelChange(int newZoomLevel) {
boolean zoomInEnabled = newZoomLevel < this.zoomLevelMax;
boolean zoomOutEnabled = newZoomLevel > this.zoomLevelMin;
this.zoomControls.setIsZoomInEnabled(zoomInEnabled);
this.zoomControls.setIsZoomOutEnabled(zoomOutEnabled);
}
The problem is that i don't know ho to implement a similar function to my activity.
The onZoomLevelChange says that unti the current zoom in less than the max zoom, to set the zoom in enable.
But how can implement a similar function as you suggest, means, check the current zoom level and set the zoomButton.setEnabled(false) ?
I know that if i just put the zoomButton.setEnabled(false). inside the zoom max click method, it return false, show different icon and do not allow to zoom, but i can't understand how to first check the actual zoom level and start zoomButton.setEnabled(false) when max zoom is reached.
int oldZoomLevel = -1;
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (getMapViewPosition().getZoomLevel() != oldZoomLevel) {
// Update zoom controls here
oldZoomLevel = getMapViewPosition().getZoomLevel();
}
}public void onClick(View v) {
mapView.getMapViewPosition().zoomIn();
if(mapView.getMapViewPosition().getZoomLevel() == zoomLevelMax){
zoomOut.setEnabled(true);
zoomIn.setEnabled(false);
zoomLevelMax = mapView.getMapViewPosition().getZoomLevel();
}
else{
zoomIn.setEnabled(true);
zoomOut.setEnabled(true);
}
}
});
zoomOut.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mapView.getMapViewPosition().zoomOut();
if(mapView.getMapViewPosition().getZoomLevel() == zoomLevelMin){
zoomOut.setEnabled(false);
zoomIn.setEnabled(true);
zoomLevelMin = mapView.getMapViewPosition().getZoomLevel();
}
else{
zoomIn.setEnabled(true);
zoomOut.setEnabled(true);
}
}
});
It works perfect.
Thanks again for your time.