Example usage for android.graphics.drawable LevelListDrawable setLevel

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

Introduction

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

Prototype

public final boolean setLevel(@IntRange(from = 0, to = 10000) int level) 

Source Link

Document

Specify the level for the drawable.

Usage

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

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapa);/*from w  w  w.jav a  2s.  co 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)));
    }
}