3

Hi guys I have an InfoWindowAdapter with custom content (An image and some textviews). I use Picasso Library to load image from the web or from the cache, but since it need 0,5 sec. and InfoWindowAdapter don't refresh automatically its content How can I do to "refresh" its content?? This is the code I produced for:

map.setInfoWindowAdapter(new InfoWindowAdapter() {

View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);


@Override
public View getInfoWindow(Marker marker) {
    return null;
}

@Override
public View getInfoContents(Marker marker) {
/* Distanza a piedi e macchina sulla nuvoletta */
/***********************************************/

    GPSTracker gpsTracker = new GPSTracker(MainActivity.this);

    if (gpsTracker.canGetLocation())
    {
        String stringLatitude = String.valueOf(gpsTracker.latitude);
        String stringLongitude = String.valueOf(gpsTracker.longitude);

        double currentLat = Double.parseDouble(stringLatitude);
        double currentLng = Double.parseDouble(stringLongitude);

        double destLat = marker.getPosition().latitude;
        double destLng = marker.getPosition().longitude;

        final float[] results = new float[3];
        Location.distanceBetween(currentLat, currentLng, destLat, destLng, results);

        float metri = results[0];
        float km = Math.round((double)metri/1000);

        int minuti_persona = (int)Math.round(metri/125);    //125 metri al minuto -> velocità media di 2,5 m/s
        int minuti_auto = (int)Math.round(km/0.7);          //700 metri al minuto -> velocità media di 42 km/h 


        /***********************************************/



        TextView tvTitle = (TextView) v.findViewById(R.id.title);
        TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
        tvSnippet.setTypeface(tvSnippet.getTypeface(), Typeface.ITALIC); //indirizzo in corsivo
        TextView tvPedonal_distance = (TextView) v.findViewById(R.id.pedonal_time);
        TextView tvCar_distance = (TextView) v.findViewById(R.id.car_time);
        tvTitle.setText(marker.getTitle());
        tvSnippet.setText(marker.getSnippet());

        if(minuti_persona <=0)          // Stampa tempo per coprire la distanza
        {
            tvCar_distance.setText("A piedi: meno di un minuto");
        }else
        {
            tvPedonal_distance.setText("A piedi: "+minuti_persona+ " minuti");
        }

        if(minuti_auto <= 0)
        {
            tvCar_distance.setText("In auto: meno di un minuto");                                   
        }else
        {
            tvCar_distance.setText("In auto: " +minuti_auto+ " minuti");
        }


        //Prova immagine custom
        /***********************************/

        ImageView image;
        String currentUrl="http://upload.wikimedia.org/wikipedia/commons/5/50/Casa_Natale_Benito_Mussolini_(1).jpg";
        image = (ImageView) v.findViewById(R.id.image_nuvoletta);

        Picasso.with(v.getContext())
            .load(currentUrl)
            .error(R.drawable.ic_launcher)  //in caso di errore fa vedere questa immagine (un triangolo penserei)
            .resize(150, 110)
            .into(image, new Callback(){

        @Override
        public void onSuccess(){
            //where I have to update my InfoWindow

        }

        @Override
        public void onError(){

        }
}); 

return v;

InfoWindowAdapter XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|left"
    android:background="#FFFFFF"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/image_nuvoletta"
        android:layout_width="90dp"
        android:layout_height="60dp"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="0dp"
        android:layout_gravity="left|fill"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="12dp"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/snippet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="10dp"/>

            <LinearLayout 
                android:id="@+id/distanceinfo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView 
                    android:id="@+id/pedonal_time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="10dp"/>

                <TextView 
                    android:id="@+id/car_time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="10dp"/>

            </LinearLayout>

        </LinearLayout>

</LinearLayout>
Pierpaolo Ercoli
  • 1,028
  • 2
  • 11
  • 32
  • Please take look @ answer in this thread - should help. http://stackoverflow.com/questions/14279442/i-my-using-google-mapv2-and-i-m-downloading-image-from-google-place-api-and-want – Michał Czerwiński Dec 30 '15 at 11:32

0 Answers0