Example usage for android.graphics.drawable LevelListDrawable getCurrent

List of usage examples for android.graphics.drawable LevelListDrawable getCurrent

Introduction

In this page you can find the example usage for android.graphics.drawable LevelListDrawable getCurrent.

Prototype

@Override
    public Drawable getCurrent() 

Source Link

Usage

From source file:com.jesjimher.bicipalma.MapaActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapa);// www .j  a  va2 s .c o  m

    // Activar zoom
    GoogleMap mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapfragment))
            .getMap();
    //        mapa.setBuiltInZoomControls(true);
    mapa.setMyLocationEnabled(true);

    // Si el mapa no est en Palma o similar, ponerlo en pza espaa
    CameraPosition c = mapa.getCameraPosition();
    Location actual = new Location("");
    actual.setLatitude(c.target.latitude);
    actual.setLongitude(c.target.longitude);
    Location pe = new Location("");
    pe.setLatitude(PZAESPANYA.latitude);
    pe.setLongitude(PZAESPANYA.longitude);
    if (actual.distanceTo(pe) >= 5000)
        mapa.moveCamera(CameraUpdateFactory.newLatLng(PZAESPANYA));

    Intent i = getIntent();
    //        GeoPoint point=null;
    if (i.hasExtra("estaciones")) {
        estaciones = i.getExtras().getParcelableArrayList("estaciones");

        for (Estacion e : estaciones) {
            LevelListDrawable d = (LevelListDrawable) getResources().getDrawable(R.drawable.estado_variable);
            d.setLevel(e.getBicisLibres() + 1);
            BitmapDrawable bd = (BitmapDrawable) d.getCurrent();
            Bitmap b = bd.getBitmap();
            Bitmap petit = Bitmap.createScaledBitmap(b, b.getWidth() / 2, b.getHeight() / 2, false);
            String mensaje = String.format("%s: %d, %s: %d", getResources().getString(R.string.lbicislibres),
                    e.getBicisLibres(), getResources().getString(R.string.lanclajeslibres),
                    e.getAnclajesLibres());
            mapa.addMarker(new MarkerOptions()
                    .position(new LatLng(e.getLoc().getLatitude(), e.getLoc().getLongitude()))
                    .title(e.getNombre()).snippet(mensaje).icon(BitmapDescriptorFactory.fromBitmap(petit)));
        }
        Double lat = i.getExtras().getDouble("latcentro");
        Double lon = i.getExtras().getDouble("longcentro");
        mapa.moveCamera(CameraUpdateFactory.zoomTo(16));
        mapa.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lon)));
    }
}