IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Délai d'attente ds MapFragment


Sujet :

Android

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut Délai d'attente ds MapFragment
    Bonjour, j'ai un projet qui recense des tremblements de terre aux USA

    L'activité principale recense des tremblements, ensuite je les affiche sur une Map V2 ds un fragment

    çà marche OK, mais je voudrais créer un délai d'attente entre l'affichage de chaque Marker pour que la visualisation soit progressive

    Là, je ne vois pas ... sans doute un problème de Thread ???

    Merci de vitre collaboration

    Voici 3 morceaux de code sui concerne cela

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
     
    for(LatLng ll:arll){					// tab de Latitude , Longitude
    		 Float m = armag.get(i);  			// m = différentes magnitudes
    		 ajouterMarker(ll,m);
    	 }
     
    public void ajouterMarker(LatLng laln,Float m){
     
    	Bitmap bm = marqueur(m);
    	Marker marker = mapView.addMarker(new MarkerOptions()
         .position(laln)  
         .icon(BitmapDescriptorFactory.fromBitmap(bm)));
    		 CameraPosition myPosition = new CameraPosition.Builder()
             .target(laln).zoom(7).bearing(90).tilt(30).build();
    		 mapView.animateCamera(CameraUpdateFactory.newCameraPosition(myPosition));
    	}
     
    public Bitmap marqueur(Float m){
    	  Drawable shape = getResources().getDrawable(R.drawable.markergreen);
    	  int px = getResources().getDimensionPixelSize(R.dimen.marker_size);
    	  Bitmap mDotMarkerBitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
    	  Canvas canvas = new Canvas(mDotMarkerBitmap);
    	  if(m<3){
    		  shape = getResources().getDrawable(R.drawable.markergreen);
    	  }
    	  if( m==3){
    		  shape = getResources().getDrawable(R.drawable.markerorange);
    	  }
    	  if( m>3 && m<4){
    		  shape = getResources().getDrawable(R.drawable.markerorange);
    	  }
    	  if(m>4){
    		  shape = getResources().getDrawable(R.drawable.markerred);
    	  }
    	  shape.setBounds(0, 0, mDotMarkerBitmap.getWidth(), mDotMarkerBitmap.getHeight());
    	  shape.draw(canvas);
    	  Paint paint = new Paint();
    	  paint.setTextSize(50);
    	  paint.setColor(Color.WHITE);
    	  canvas.drawText(m.toString(),40,90,paint);
    	  return mDotMarkerBitmap;
      }

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut Personne ???
    Autrement dit, afficher chaque Marker avec un temps d'attente ds un Fragment

    Merci

  3. #3
    Expert confirmé

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Billets dans le blog
    3
    Par défaut
    Ben si... au lieu de faire une boucle sur tous les marqueurs... mettre les marqueurs dans une liste.
    Utiliser un timer (ou un "Handler.onPostDelayed") pour afficher le premier marqueur de la liste (et le retirer de la liste).

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut Merci mais ........
    j'applique votre suggestion mais .... je ne vois pas ...
    Quand j'affiche les markers ; tous les markers s'affichent simultanément

    Si je les effacent ... tout s'efface simultanément

    Voici le code en entier ... en espérant une piste !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
     
    package com.paad.earthquake;
     
    import java.util.ArrayList;
     
    import android.app.Fragment;
    import android.content.ContentResolver;
    import android.content.Context;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Looper;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
     
    import com.google.android.gms.maps.CameraUpdate;
    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.GoogleMap.OnCameraChangeListener;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.model.BitmapDescriptorFactory;
    import com.google.android.gms.maps.model.CameraPosition;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;
     
    public class CopyOfEarthquakeMapFragment extends Fragment  {
    		GoogleMap mapView;
    		Context context;
    		ArrayList<LatLng> arll = new ArrayList<LatLng>();
    		ArrayList<Float> armag = new ArrayList<Float>();
    		Cursor cur;
    		String titre = "";
    		String snippet = "";
    		Handler handler;
     
    		Marker marker;
     
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.map_fragment, container, false); 
        return view;
      }
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Lister();
        refreshQuakeLocations();
     
        mapView = ((MapFragment) getFragmentManager().findFragmentById(R.id.myMapView)).getMap();
        mapView.setMapType(mapView.MAP_TYPE_HYBRID);
     
    	 mapView.getUiSettings().setZoomControlsEnabled(true);
         mapView.getUiSettings().setCompassEnabled(true);
         mapView.getUiSettings().setMyLocationButtonEnabled(false);
         mapView.getUiSettings().setRotateGesturesEnabled(true);
         mapView.getUiSettings().setScrollGesturesEnabled(true);
         mapView.getUiSettings().setTiltGesturesEnabled(true);
         mapView.getUiSettings().setZoomGesturesEnabled(true);
         mapView.setMyLocationEnabled(false);
     
         int i = 0;
     
         for(LatLng ll:arll){
    		 titre = "";
    		 snippet = "";
     
    		 Float m = armag.get(i);
    		 ++i;
     
    		 useHandler(ll,m,titre,snippet);
    	 }
      }   
     
     
      public void Lister() {  
    	    String[] projection = new String[] {
    	      EarthquakeProvider.KEY_ID,
    	      EarthquakeProvider.KEY_LOCATION_LAT,
    	      EarthquakeProvider.KEY_LOCATION_LNG,
    	      EarthquakeProvider.KEY_MAGNITUDE,
    	    };
     
    	    Earthquake earthquakeActivity = (Earthquake)getActivity();
    	    String where = EarthquakeProvider.KEY_MAGNITUDE + " > " + 
    	                   earthquakeActivity.minimumMagnitude;
     
    	    ContentResolver cr = getActivity().getContentResolver();
    	    cur = cr.query(EarthquakeProvider.CONTENT_URI, projection, where, null, null);
    	  }
     
      public void refreshQuakeLocations() {
    	    arll.clear();
     
    	    if (cur != null && cur.moveToFirst())
    	      do {
    	          int latIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_LOCATION_LAT);
    	          int lngIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_LOCATION_LNG);
    	          int magIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_MAGNITUDE);
     
    	          Double lat = cur.getDouble(latIndex);
    	          Double lng = cur.getDouble(lngIndex);
    	        LatLng geoPoint = new LatLng(lat,lng);
    	        arll.add(geoPoint);
     
    	        Float magnitude = cur.getFloat(magIndex);
    	        armag.add(magnitude);
     
    	      } while(cur.moveToNext());
    	  }
     
      public void ajouterMarker(LatLng laln,Float m,String title,String snippet){
    	Bitmap bm = marqueur(m);
    	marker = mapView.addMarker(new MarkerOptions()
         .position(laln)  
         .title(title)
         .snippet(snippet)
         .icon(BitmapDescriptorFactory.fromBitmap(bm)));
    	 CameraPosition myPosition = new CameraPosition.Builder()
         .target(laln).zoom(7).bearing(90).tilt(30).build();
    	 mapView.animateCamera(CameraUpdateFactory.newCameraPosition(myPosition));
    	}
     
      public void useHandler(final LatLng laln_h,final Float m_h,final String title_h,final String snippet_h) {
    	  long DELAY = 1000;
    	  Handler handler = new Handler();
    	  handler.postDelayed(
    	          new Runnable() {
    	             @Override
    	             public void run() {
    	            	 ajouterMarker(laln_h,m_h,title_h,snippet_h);
    	            	 try {
    						Thread.sleep(500);
    						marker.remove();
    					} catch (InterruptedException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
    	             }
    	          }, (DELAY));
      }
     
      public Bitmap marqueur(Float m){
    	  Drawable shape = getResources().getDrawable(R.drawable.markergreen);
    	  int px = getResources().getDimensionPixelSize(R.dimen.marker_size);
    	  Bitmap mDotMarkerBitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
    	  Canvas canvas = new Canvas(mDotMarkerBitmap);
    	  if(m<3){
    		  shape = getResources().getDrawable(R.drawable.markergreen);
    	  }
    	  if( m==3){
    		  shape = getResources().getDrawable(R.drawable.markerorange);
    	  }
    	  if( m>3 && m<4){
    		  shape = getResources().getDrawable(R.drawable.markerorange);
    	  }
    	  if(m>4){
    		  shape = getResources().getDrawable(R.drawable.markerred);
    	  }
    	  shape.setBounds(0, 0, mDotMarkerBitmap.getWidth(), mDotMarkerBitmap.getHeight());
    	  shape.draw(canvas);
    	  Paint paint = new Paint();
    	  paint.setTextSize(50);
    	  paint.setColor(Color.WHITE);
    	  canvas.drawText(m.toString(),40,90,paint);
    	  return mDotMarkerBitmap;
      }
     
      @Override
      public void onResume() {
          //mapView.onResume();
          super.onResume();
      }
     
      @Override
      public void onStop() {
          super.onStop();
          //mapView.onDestroy();
      }
     
      public void onDestroyView() {
          super.onDestroyView();
          MapFragment f = (MapFragment) getFragmentManager()
                                               .findFragmentById(R.id.myMapView);
          if (f != null) 
              getFragmentManager().beginTransaction().remove(f).commit();
      }
     
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
      @Override
      public void onDetach() {
        super.onDetach();
      }
    }

  5. #5
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Ce que veut dire nicroman c'est que tu ajoutes tes marqueurs dans ta liste un par un après entre un postDelayed suite à l'ajout d'un.

    Du style tu créer ta routine qui sera le contenu de ta fonction ajouterMarker, puis au lieu de faire ton for
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    for(LatLng ll:arll){
    		 titre = "";
    		 snippet = "";
     
    		 Float m = armag.get(i);
    		 ++i;
     
    		 useHandler(ll,m,titre,snippet);
    	 }
    Tu appelle une fois ta routine faite qui elle même se rappelle après une seconde de delay avec le marker suivant de ta liste. Du style

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    int index = 0;
    Runnable ajouterMarker =new Runnable() {
        public void run() {
               // tu vérifies si tu as un élémént à jouter en focntion de l'id
               if(existElement(i)) {
                      // tu récupères ta velur m de l'élémént
                      m = getValueM(i);
                      // tu ajoutes le marker
                     Bitmap bm = marqueur(m);
    	         marker = mapView.addMarker(new MarkerOptions()
                             .position(laln)  
                             .title(title)
                             .snippet(snippet)
                            .icon(BitmapDescriptorFactory.fromBitmap(bm)));
    	          CameraPosition myPosition = new CameraPosition.Builder()
                            .target(laln).zoom(7).bearing(90).tilt(30).build();
    	          mapView.animateCamera(CameraUpdateFactory.newCameraPosition(myPosition));
                              // tu passes a l'index suivant
                       i++;
                       handler.postDelayed(runnable, DELAY);    
               }        
        }
    };
    Il y a moyen de le rendre plus propre via la création d'un Thread ou tu auras comme membre ta liste à ajouter et la gestion de son index.

    Edit: Le code ne marche pas mais c'est pour te montrer l'algorithme à faire.

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut OK ... mais
    Merci pour la réponse, le Handler fonctionne mais je souhaite un fois l'affichage terminé

    utiliser : mapView.setInfoWindowAdapter(new InfoWindowAdapter() {

    ... et là j'obtiens une erreur FATAL à l'exécution

    06-11 12:41:12.468: E/AndroidRuntime(19413): java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.LayoutInflater android.app.Activity.getLayoutInflater()' on a null object reference

    Pour situer : l'activité principale lance un fragment ds lequel l'affichage se déroule

    Je remets le code modifié

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
     
    package com.paad.earthquake;
     
    import java.util.ArrayList;
     
    import android.app.Activity;
    import android.app.Fragment;
    import android.content.ContentResolver;
    import android.content.Context;
    import android.database.Cursor;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.os.Handler;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.TextView;
     
    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.GoogleMap.InfoWindowAdapter;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.model.BitmapDescriptorFactory;
    import com.google.android.gms.maps.model.CameraPosition;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;
     
    public class CopyOfEarthquakeMapFragment extends Fragment  {
    		GoogleMap mapView;
    		Context context;
    		ArrayList<LatLng> arll = new ArrayList<LatLng>();
    		ArrayList<Float> armag = new ArrayList<Float>();
    		ArrayList<String> ardet = new ArrayList<String>();
    		ArrayList<String> ardateaff = new ArrayList<String>();
    		Cursor cur;
    		ArrayList<Marker> allMarkers = new ArrayList<Marker>();
     
    		String titre = "";
    		String snippet = "";
    		Handler handler;
    		Runnable myRunnable;
    		int i;
    		int taille; 
    		long DELAY = 3000;
    		//Float zoom = 4.5f;
    		Float zoom = 7f;
    		Marker marker;
     
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.map_fragment, container, false); 
        return view;
      }
     
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Lister();
        refreshQuakeLocations();
     
        mapView = ((MapFragment) getFragmentManager().findFragmentById(R.id.myMapView)).getMap();
        mapView.setMapType(mapView.MAP_TYPE_HYBRID);
     
    	 mapView.getUiSettings().setZoomControlsEnabled(true);
         mapView.getUiSettings().setCompassEnabled(true);
         mapView.getUiSettings().setMyLocationButtonEnabled(false);
         mapView.getUiSettings().setRotateGesturesEnabled(true);
         mapView.getUiSettings().setScrollGesturesEnabled(true);
         mapView.getUiSettings().setTiltGesturesEnabled(true);
         mapView.getUiSettings().setZoomGesturesEnabled(true);
         mapView.setMyLocationEnabled(false);
     
         i=0;
         taille = arll.size();
         useHandler();
     
         // Associer une info au marker
    		mapView.setInfoWindowAdapter(new InfoWindowAdapter() {
    	           public View getInfoWindow(Marker arg0) {
    	               return null;
    	           }
    	           public View getInfoContents(Marker marker) {
    	        	   LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    	        	   View myContentsView = inflater.inflate(R.layout.infocontent, null);
    	               TextView tvTitle = ((TextView)myContentsView.findViewById(R.id.title));
    	               tvTitle.setText(marker.getTitle());
    	               TextView tvSnippet = ((TextView)myContentsView.findViewById(R.id.snippet));
    	               tvSnippet.setText(marker.getSnippet());
    	               return myContentsView;
    	           }
    	       });
     
      }
     
      public void Lister() {  
    	    String[] projection = new String[] {
    	      EarthquakeProvider.KEY_ID,
    	      EarthquakeProvider.KEY_DETAILS,
    	      EarthquakeProvider.KEY_DATEAFF,
    	      EarthquakeProvider.KEY_LOCATION_LAT,
    	      EarthquakeProvider.KEY_LOCATION_LNG,
    	      EarthquakeProvider.KEY_MAGNITUDE,
    	    };
    	    Earthquake earthquakeActivity = (Earthquake)getActivity();
    	    String where = EarthquakeProvider.KEY_MAGNITUDE + " > " + 
    	                   earthquakeActivity.minimumMagnitude;
     
    	    ContentResolver cr = getActivity().getContentResolver();
    	    cur = cr.query(EarthquakeProvider.CONTENT_URI, projection, where, null, null);
    	  }
     
      public void refreshQuakeLocations() {
    	    arll.clear();
    	    if (cur != null && cur.moveToFirst())
    	      do {
    	    	  int detIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_DETAILS);
    	    	  int dateaffIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_DATEAFF);
    	          int latIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_LOCATION_LAT);
    	          int lngIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_LOCATION_LNG);
    	          int magIndex = cur.getColumnIndexOrThrow(EarthquakeProvider.KEY_MAGNITUDE);
     
    	          String details = cur.getString(detIndex);
    	          ardet.add(details);
    	          String dateaff = cur.getString(dateaffIndex);
    	          ardateaff.add(dateaff);
     
    	          Double lat = cur.getDouble(latIndex);
    	          Double lng = cur.getDouble(lngIndex);
    	          LatLng geoPoint = new LatLng(lat,lng);
    	          arll.add(geoPoint);
     
    	        Float magnitude = cur.getFloat(magIndex);
    	        armag.add(magnitude);
     
    	      } while(cur.moveToNext());
    	  }
     
      public void ajouterMarker(LatLng laln,Float m,String title,String snippet,Float zoomajouter){
    	Bitmap bm = marqueur(m);
    	marker = mapView.addMarker(new MarkerOptions()
         .position(laln)  
         .title(title)
         .snippet(snippet)
         .icon(BitmapDescriptorFactory.fromBitmap(bm)));
    		allMarkers.add(marker);
    		//ICI animation	
    		 CameraPosition myPosition = new CameraPosition.Builder()
             .target(laln).zoom(zoomajouter).bearing(0).tilt(30).build();
    		 mapView.animateCamera(CameraUpdateFactory.newCameraPosition(myPosition));
    		 marker.showInfoWindow();
    	}
     
      public void ajouterMarker_2(LatLng laln_2,Float zoomajouter_2){
    		marker = mapView.addMarker(new MarkerOptions()
    	     .position(laln_2)  
    	     .icon(BitmapDescriptorFactory.fromResource(R.drawable.pixelblanc)));
    			 CameraPosition myPosition_2 = new CameraPosition.Builder()
    	         .target(laln_2).zoom(zoomajouter_2).bearing(0).tilt(30).build();
    			 mapView.animateCamera(CameraUpdateFactory.newCameraPosition(myPosition_2));
    		}
     
      public void useHandler() {
    	  handler = new Handler();
    		 myRunnable = new Runnable(){
    	             @Override
    	             public void run() {
    	            	 if(i < taille) {  
    	    		    	 LatLng laln_h = arll.get(i);
    	    	         	 Float m_h = armag.get(i);
    	    	         	 String title_h = ardet.get(i);
    	    	         	 String snippet_h = ardateaff.get(i);
     
    	    	         	 ajouterMarker(laln_h,m_h,title_h,snippet_h,zoom);
    	    	             useHandler();
    	    	        }
    	             	else if(i == taille) {
    	             		 LatLng finale = new LatLng(51.150002,-110.199997);
    	             		 zoom = 2.0f;
    	      	             ajouterMarker_2(finale,zoom);
    	      	             useHandler();
    	             	}
    	             	else{
    	             		handler.removeCallbacks(myRunnable);
    	             		return;
    	             	}
    	    	        ++i;
    	             }
    			  };
    	          handler.postDelayed(myRunnable,DELAY);
    	}
     
      public Bitmap marqueur(Float m){
    	  Drawable shape = getResources().getDrawable(R.drawable.markergreen);
    	  int px = getResources().getDimensionPixelSize(R.dimen.marker_size);
    	  Bitmap mDotMarkerBitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
    	  Canvas canvas = new Canvas(mDotMarkerBitmap);
    	  if(m<3){
    		  shape = getResources().getDrawable(R.drawable.markergreen);
    	  }
    	  if( m==3){
    		  shape = getResources().getDrawable(R.drawable.markerorange);
    	  }
    	  if( m>3 && m<4){
    		  shape = getResources().getDrawable(R.drawable.markerorange);
    	  }
    	  if(m>4){
    		  shape = getResources().getDrawable(R.drawable.markerred);
    	  }
    	  shape.setBounds(0, 0, mDotMarkerBitmap.getWidth(), mDotMarkerBitmap.getHeight());
    	  shape.draw(canvas);
    	  Paint paint = new Paint();
    	  paint.setTextSize(50);
    	  paint.setColor(Color.WHITE);
    	  canvas.drawText(m.toString(),40,90,paint);
    	  return mDotMarkerBitmap;
      }
     
      @Override
      public void onResume() {
          //mapView.onResume();
          super.onResume();
      }
     
      @Override
      public void onStop() {
          super.onStop();
          //mapView.onDestroy();
      }
     
     
      @Override
      public void onDestroyView() {
          super.onDestroyView();
          MapFragment f = (MapFragment) getFragmentManager()
                                               .findFragmentById(R.id.myMapView);
          if (f != null) 
              getFragmentManager().beginTransaction().remove(f).commit();
      }
     
      @Override
      public void onDestroy() {
          super.onDestroy();
      }
      @Override
      public void onDetach() {
        super.onDetach();
      }
    }

  7. #7
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    alors ta variable context est nulle.

  8. #8
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut
    c'est bien çà mais aussi le pourquoi de ma question ??

    Je suis pas à l'aise avec cela

  9. #9
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Par ce que à aucun moment tu l'as initialisé ... Au lieu de faire avec la variable context tu as juste à faire un getActivity().getLayoutInflater()....

  10. #10
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut
    OK encore merci pour "le juste à faire un getActivity().getLayoutInflater()...."

    Résolu

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 24/05/2006, 11h39
  2. Délai d'attente expiré !
    Par Le Pharaon dans le forum MS SQL Server
    Réponses: 15
    Dernier message: 22/05/2006, 19h25
  3. "Délai d'attente expiré" aléatoire
    Par denilson74 dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 24/07/2005, 10h48
  4. Délai d'attente expiré
    Par zut94 dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 06/07/2005, 21h50
  5. Délai d'attente expiré
    Par amiral thrawn dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 15/04/2003, 12h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo