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 :

Créer un chronogramme en Android


Sujet :

Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Expert sécurité informatique
    Inscrit en
    Novembre 2011
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Expert sécurité informatique
    Secteur : Enseignement

    Informations forums :
    Inscription : Novembre 2011
    Messages : 21
    Points : 22
    Points
    22
    Par défaut Créer un chronogramme en Android
    je suis un développeur Android débutant et je en train de développer une application pour faire un Chronogramme, j'ai comme entré une liste d'objet contenant le début et la fin de chaque période mais j'ai pas réussi pour dessiner ce chronogramme w j'ai besoin de votre aide svp.

    c'est le code que j'ai essayé:

    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
    public class TourTimingAdapter extends ArrayAdapter<TourExt> {
     
    	private Context context;
    	private int layoutResourceId;
    	private List<TourExt> data = null;
    	private LayoutInflater mInflater;
    	private long idOfGuard;
     
    	private static final String dateTemplate = "HH:mm";
    	public static int i = 1;
    	private int textWidth;
    	@SuppressLint("SimpleDateFormat")
    	private final SimpleDateFormat df = new SimpleDateFormat(dateTemplate);
     
    	public TourTimingAdapter(Context context, int layoutResourceId, List<TourExt> data) {
    		super(context, layoutResourceId, data);
     
    		this.context 			= context;
    		this.layoutResourceId 	= layoutResourceId;
    		this.data 				= data;
    		mInflater 				= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	}
     
    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
     
    		View row = convertView;
    		RouteHolder holder = null;
     
    		if (row == null) {
    			row = mInflater.inflate(layoutResourceId, parent, false);
     
    			holder 				= new RouteHolder();
    			holder.number = (TextView) row.findViewById(R.id.numberDate);
    			holder.lay 			= (LinearLayout) row.findViewById(R.id.layPlage);
     
    			row.setTag(holder);
    		} else {
    			holder = (RouteHolder) row.getTag();
    		}
     
    		//initialize layout
    		holder.lay.removeAllViews();
    		TourExt tourExt = data.get(position);
     
    		Date beginPlage = tourExt.getBegin();
    		Date endPlage = tourExt.getEnd();
     
    		Calendar cal = Calendar.getInstance();
    		cal.setTime(beginPlage);
     
    		float from = 0;
    		if(cal.get(Calendar.HOUR_OF_DAY) != 0)
    			from = (float) cal.get(Calendar.HOUR_OF_DAY)/(float)24;
    		else 
    			from = (float) (cal.get(Calendar.HOUR_OF_DAY) + 1)/(float)24;
    		cal.setTime(endPlage);
    		float to = 0;
    		if(cal.get(Calendar.HOUR_OF_DAY) != 0)
    			to = (float) cal.get(Calendar.HOUR_OF_DAY)/(float)24;
    		else 
    			from = (float) (cal.get(Calendar.HOUR_OF_DAY) + 1)/(float)24;
     
    		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    		Display display = wm.getDefaultDisplay();
     
    //					Point size = new Point();
    //					display.getSize(size);
    //					LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    //				    llp.setMargins(5, 5, 5, 5); // llp.setMargins(left, top, right, bottom);
    //				    
    //					holder.plage.setLayoutParams(llp);
    		float width;
    		if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) < 13 ) {
    			width = display.getWidth();
    	        //height = display.getHeight();
    	       } else {
    	    	   Point size = new Point();
    	           display.getSize(size);
    	           width = size.x;
    	           //height = size.y;
    	       }
     
    		/*final TextView upV = (TextView)row.findViewById(R.id.numberDate);
    		   ViewTreeObserver vto = upV.getViewTreeObserver();
    		    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    		        @Override
    		        public void onGlobalLayout() {
     
    		            Log.d("W ", ""+upV.getWidth());
    		            Log.d("H ", ""+upV.getHeight());
    		        }
    		    });*/
     
    		int marginleft = (int)(from * (float)(width - /*textWidth*/ 45));
    		int marginright = (int)(to * (float)(width  - /*textWidth*/ 45));
     
    		Log.d("TourTimingAdapter",  "width =   " + width + "from =   " + from + "  " + marginleft + "  " + to + " " + ((int)width - marginright) + "  " + width);
    		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
     
    		//params.setMargins(marginleft, 5, (int)width - marginright, 5);
    		params.setMargins(marginleft, 5, (int)width - marginright - 45, 5);
    		//MarginLayoutParams marginLayoutParams = (MarginLayoutParams) params.getLayoutParams();
     
    		//marginLayoutParams.setMargins(marginleft, 5, display.getWidth() - marginright, 5);
    		TextView newplage = new TextView(context);
    		newplage.setLayoutParams(params);
    		newplage.setBackgroundColor(context.getResources().getColor(R.color.darkorrange));
     
    		//newplage.setLayoutParams(marginLayoutParams);
     
    		ActionItem fromItem = new ActionItem(ActionParameter3D.ID_DOWN, "From :" + df.format(beginPlage), context.getResources().getDrawable(R.drawable.planning_icon));
    		ActionItem toItem = new ActionItem(ActionParameter3D.ID_DOWN, "		 To :" + df.format(endPlage), null);
    		//ActionItem everyItem = new ActionItem(ActionParameter3D.ID_DOWN, "		 Every :" + myPlannig.getEvery() + " minutes", null);
    		fromItem.setSticky(true);
    		toItem.setSticky(true);
    		//everyItem.setSticky(true);
     
    		final QuickActionMap quickAction = new QuickActionMap(context, QuickActionMap.VERTICAL);
     
    		//add action items into QuickAction 
            quickAction.addActionItem(fromItem);
            quickAction.addActionItem(toItem);
            //quickAction.addActionItem(everyItem);
     
    		newplage.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				quickAction.setAnimStyle(QuickActionMap.ANIM_REFLECT);
    				quickAction.show(v);
    			}
    		});
    		//holder.lay.setBackground(context.getResources().getDrawable(R.drawable.planning_back));
    		holder.lay.addView(newplage);
     
    //	else{
    //		//row.set
    //		return null;
    //	}
    		holder.number.setText(" " + i + " ");
    		return row;
    	}
     
    	class RouteHolder {
    		TextView number;
    		LinearLayout lay;
    	}
    }

  2. #2
    Expert éminent

    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
    Points : 9 149
    Points
    9 149
    Par défaut
    Salut,

    En fait c'est quoi ton problème ?
    Responsable Android de Developpez.com (Twitter et Facebook)
    Besoin d"un article/tutoriel/cours sur Android, consulter la page cours
    N'hésitez pas à consulter la FAQ Android et à poser vos questions sur les forums d'entraide mobile d'Android.

Discussions similaires

  1. Réponses: 3
    Dernier message: 26/05/2012, 19h18
  2. Réponses: 0
    Dernier message: 16/02/2012, 10h30
  3. Réponses: 2
    Dernier message: 12/01/2012, 20h35
  4. Comment créer un formulaire sur Android
    Par raider95 dans le forum Android
    Réponses: 10
    Dernier message: 25/08/2011, 19h39
  5. Réponses: 2
    Dernier message: 10/05/2011, 17h32

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