MojioMS
MojioMS

Reputation: 1693

how to change look of default zoomcontrol buttons in google map v2?

I can access the zoom in and zoom out button of the default zoom controle as follows:

View zoomControls = mapFragment.getView().findViewById(0x1);

    for(int i=0;i<((ViewGroup)zoomControls).getChildCount();i++){
        View child=((ViewGroup)zoomControls).getChildAt(i);
        if (i==0) {
            btn_zoomIn = child;
            // there is your "+" button, zoom in
            child.setOnTouchListener(new View.OnTouchListener(){
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()){
                        case MotionEvent.ACTION_DOWN:
                            updateZoom = new ZoomInMapThread();
                            updateZoom.start();
                            break;
                        case MotionEvent.ACTION_UP:
                            updateZoom.interrupt();
                            zoomingIn++;
                            break;
                    }
                    return true;
                }
            });
        }
        if (i==1) {
            btn_zoomOut = child;
            // there is your "+" button, zoom in
            child.setOnTouchListener(new View.OnTouchListener(){
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()){
                        case MotionEvent.ACTION_DOWN:
                            updateZoom = new ZoomOutMapThread();
                            updateZoom.start();
                            break;
                        case MotionEvent.ACTION_UP:
                            updateZoom.interrupt();
                            zoomingOut++;
                            break;
                    }
                    return true;
                }
            });
        }
    }

Im starting Threads here to update the UI by zooming in or out while a button is pressed. What I want to do next, is change the look of a button, when the user reached the maxZoom/minZoom. Here the code for the zooming in/out threads:

    private class ZoomOutMapThread extends Thread {
    @Override
    public void run(){
        try {
            while (!Thread.currentThread().isInterrupted()){
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        currentZoomLevel = currentZoomLevel - 0.1f;
                        if (currentZoomLevel < minZoom){
                            currentZoomLevel = minZoom;
                            btn_zoomIn.setVisibility(View.VISIBLE);
                            btn_zoomOut.setVisibility(View.INVISIBLE);
                        } else {
                            btn_zoomIn.setVisibility(View.VISIBLE);
                            btn_zoomOut.setVisibility(View.VISIBLE);
                        }
                        mMap.animateCamera(CameraUpdateFactory.zoomTo(currentZoomLevel));
                        Log.d("Zoom", "Level:" + currentZoomLevel);
                    }
                });
                Thread.sleep(100);
            }
        } catch (InterruptedException consumed) {
            consumed.printStackTrace();
        }
    }
}

private class ZoomInMapThread extends Thread {
    @Override
    public void run(){
        try {
            while (!Thread.currentThread().isInterrupted()){
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        currentZoomLevel = currentZoomLevel + 0.1f;
                        if (currentZoomLevel > maxZoom){
                            currentZoomLevel = maxZoom;
                            btn_zoomIn.setVisibility(View.INVISIBLE);
                            btn_zoomOut.setVisibility(View.VISIBLE);
                        } else {
                            btn_zoomIn.setVisibility(View.VISIBLE);
                            btn_zoomOut.setVisibility(View.VISIBLE);
                        }
                        mMap.animateCamera(CameraUpdateFactory.zoomTo(currentZoomLevel));
                        Log.d("Zoom","Level:"+currentZoomLevel);
                    }
                });
                Thread.sleep(100);
            }
        } catch (InterruptedException consumed) {
            consumed.printStackTrace();
        }
    }
}

For now, I am setting it invisible, but instead, i would like to have it be looking like a disabled/non-clickable button. Any idea on how I can do it on a general View like here?

Upvotes: 0

Views: 42

Answers (0)

Related Questions