I am working to an aplication who calculate the menstruation of girls.

input:  a calendar
          - start_day(the start day of menstrual cycle wich is with
red in the calendar )
          - end_day(the end day of menstrual cycle wich is with yellow
in the calendar)
           - mens(menstruation length)


output(what I want to optain):

                          I want to display on the calendar the
start(red background) and the end(yellow background) of menstruation
for the next 6 month. I manage to do this for 2 months and im block
now.

PLEASE IF SOMEONE  HAVE ANY IDEA!! Thank you verry much!

        Catalin







code for calendar: ShowCalendar.java:



                            public class ShowCalendar extends Activity
{
    public static final String selectedDate="selectedDate";
    public int mYear;
    public int mMonth;
    public int mDay;
    static int realDay, realMonth, realYear, currentMonth,
currentYear;
    private Enumeration<Girl.Period> e;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar);
        GregorianCalendar cal = new GregorianCalendar(); //Create
calendar
        realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); //Get day
        realMonth = cal.get(GregorianCalendar.MONTH); //Get month
        realYear = cal.get(GregorianCalendar.YEAR); //Get year
        currentMonth=realMonth;
        currentYear=realYear;

            TextView t1=(TextView) findViewById(R.id.t1);
            TextView t2=(TextView) findViewById(R.id.t2);
            TextView t3=(TextView) findViewById(R.id.t3);
            TextView t4=(TextView) findViewById(R.id.t4);
            TextView t5=(TextView) findViewById(R.id.t5);
            TextView t6=(TextView) findViewById(R.id.t6);
            TextView t7=(TextView) findViewById(R.id.t7);
            TextView t8=(TextView) findViewById(R.id.t8);
            TextView t9=(TextView) findViewById(R.id.t9);
            TextView t10=(TextView) findViewById(R.id.t10);
            TextView t11=(TextView) findViewById(R.id.t11);
            TextView t12=(TextView) findViewById(R.id.t12);
            TextView t13=(TextView) findViewById(R.id.t13);
            TextView t14=(TextView) findViewById(R.id.t14);
            TextView t15=(TextView) findViewById(R.id.t15);
            TextView t16=(TextView) findViewById(R.id.t16);
            TextView t17=(TextView) findViewById(R.id.t17);
            TextView t18=(TextView) findViewById(R.id.t18);
            TextView t19=(TextView) findViewById(R.id.t19);
            TextView t20=(TextView) findViewById(R.id.t20);
            TextView t21=(TextView) findViewById(R.id.t21);
            TextView t22=(TextView) findViewById(R.id.t22);
            TextView t23=(TextView) findViewById(R.id.t23);
            TextView t24=(TextView) findViewById(R.id.t24);
            TextView t25=(TextView) findViewById(R.id.t25);
            TextView t26=(TextView) findViewById(R.id.t26);
            TextView t27=(TextView) findViewById(R.id.t27);
            TextView t28=(TextView) findViewById(R.id.t28);
            TextView t29=(TextView) findViewById(R.id.t29);
            TextView t30=(TextView) findViewById(R.id.t30);
            TextView t31=(TextView) findViewById(R.id.t31);
            TextView t32=(TextView) findViewById(R.id.t32);
            TextView t33=(TextView) findViewById(R.id.t33);
            TextView t34=(TextView) findViewById(R.id.t34);
            TextView t35=(TextView) findViewById(R.id.t35);
            TextView t36=(TextView) findViewById(R.id.t36);
            TextView t37=(TextView) findViewById(R.id.t37);
            TextView t38=(TextView) findViewById(R.id.t38);
            TextView t39=(TextView) findViewById(R.id.t39);
            TextView t40=(TextView) findViewById(R.id.t40);
            TextView t41=(TextView) findViewById(R.id.t41);
            TextView t42=(TextView) findViewById(R.id.t42);

        TextView[][] a=new TextView[][]{{t1,t2,t3,t4,t5,t6,t7},
{t8,t9,t10,t11,t12,t13,t14},{t15,t16,t17,t18,t19,t20,t21},
{t22,t23,t24,t25,t26,t27,t28},{t29,t30,t31,t32,t33,t34,t35},
{t36,t37,t38,t39,t40,t41,t42}};

        refreshCalendar(realMonth,realYear,a);

    }
    public void refreshCalendar(int month,int year,final TextView[][]
a){
        Girl aGirl=null;
        //Variables
        String[] months = {"January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December"};
        int nod, som, mom;
        //Get number of days and start of month
        GregorianCalendar cal2 = new GregorianCalendar(year, month,
7);
        nod = cal2.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
        som = cal2.get(GregorianCalendar.DAY_OF_WEEK);
        mom= cal2.get(GregorianCalendar.MONTH);
        int row;
        int column;

        TextView monthYear=(TextView) findViewById(R.id.month);
        TextView average=(TextView) findViewById(R.id.mens_red);

        Bundle extras = getIntent().getExtras();
        if(extras !=null){
            final int id = extras.getInt("id");
            SqLiteGirlList g = SqLiteGirlList.getInstance();
            aGirl = g.get(id);

            e = aGirl.getPeriods();
        }
         //clear table
        for (int i=0;i<6;i++){
            for (int j=0;j<7;j++){
                a[i][j].setText(null);
            }
        }
        //Draw calendar
        for (int i=1; i<=nod; i++){
            row = (i + som - 2) / 7;
            column  =  (i+som-2)%7;
            if(i<10)
                a[row][column].setText(i+"");
            else
                a[row][column].setText(i+"");
        }

        Button back=(Button) findViewById(R.id.back);
        Button forward=(Button) findViewById(R.id.forward);
        //Allow/disallow buttons
        if (month == 0 && year <= realYear-100)
{back.setEnabled(false);} //Too early
        if (month == 11 && year >= realYear+100)
{forward.setEnabled(false);} //Too late
        monthYear.setText(months[month]+" "+year);


        //System.out.println("outside");

            //System.out.println("inside");
            Girl.Period p=e.nextElement();
            String start_day_m, end_day_m,  end_day;
            Date d=p.getPeriodStart() ;
            int end_day_m1, end_day_m2;
            int start_day_m1, start_day_m2;
            long milPerDay = 1000*60*60*24;
            int mens = p.getMenstruation() ;//menstruation length
            int mens1= mens-1;
            long length_cycle = p.calcDif(p.getPeriodStart() ,
p.getPeriodEnd() ) ;
            long sumMC= mens+length_cycle;


             //System.out.println("insideeemens"+ sumMC);
             //System.out.println("insideee"+ ss/milPerDay);

             // start_day_m is the first day of bleeding in the first
month
               start_day_m=String.valueOf(d.getDate());
              // System.out.println("insideeestart"+ start_day_m);

              // end_day_m is the last day of bleeding in the first
month
               end_day_m = String.valueOf(d.getDay()+ mens1);
              // System.out.println("insideeend"+ end_day_m);





            Date d3=null;
            if(p.getPeriodEnd()!=null){
                d3=p.getPeriodEnd() ;
                start_day_m1=d3.getDate()+1;
            }
            else
                start_day_m1=0;

                end_day_m1=start_day_m1+mens-1;
                int end_day_mm1= end_day_m1;

            if(end_day_m1>nod ){
                d3=p.getPeriodEnd() ;
                end_day_m1-=nod+1;

            }else if(end_day_mm1<nod){
                d3=p.getPeriodEnd() ;
                end_day_mm1=start_day_m1+mens-1;
            }








            //
System.out.println("------------------------------------------------------------------------------------");
            for(int i=0;i<6;i++){
                for(int j=0;j<7;j++){
                    a[i][j].setBackgroundResource(R.color.gray);
                    //System.out.println("Start month &
year="+monthYear.getText().toString()+" Start day="+a[i]
[j].getText());
                    //System.out.println("comp with year="+(d.getYear()
+1900)+" month="+months[d.getMonth()]+" day="+start_day);
                   //-----------------------------------------month1
its
ok-----------------------------------------------------------------
 
if(monthYear.getText().toString().indexOf(String.valueOf(d.getYear()
+1900))>-1 &&
monthYear.getText().toString().indexOf(months[d.getMonth()])>-1 && a[i]
[j].getText().equals(String.valueOf(start_day_m))){
                        a[i][j].setBackgroundResource(R.color.red) ;
                     System.out.println("arayStart"+ a[i][j]);
                    }
 
if(monthYear.getText().toString().indexOf(String.valueOf(d.getYear()
+1900))>-1 &&
monthYear.getText().toString().indexOf(months[d.getMonth()])>-1 && a[i]
[j].getText().equals(String.valueOf(end_day_m))){
                       a[i][j].setBackgroundResource(R.color.yellow) ;
                        //System.out.println("arayEnd"+ a[i][j]);
                        //System.out.println("startMatch");
                    }


                    //-----------------------------------------month2
its
ok-----------------------------------------------------------------
                    //System.out.println("End month &
year="+monthYear.getText().toString()+" End day="+a[i][j].getText());
                    //System.out.println("comp with year="+
(d2.getYear()+1900)+" month="+months[d2.getMonth()]+" day="+end_day);

 
if(monthYear.getText().toString().indexOf(String.valueOf(d3.getYear()
+1900))>-1 &&
monthYear.getText().toString().indexOf(months[d3.getMonth()])>-1 &&
a[i][j].getText().equals(String.valueOf(start_day_m1))){
                          a[i][j].setBackgroundResource(R.color.red) ;
                           //System.out.println("endMatch");
                        }
 
if(monthYear.getText().toString().indexOf(String.valueOf(d3.getYear()
+1900))>-1 &&
monthYear.getText().toString().indexOf(months[d3.getMonth()])>-1 &&
a[i][j].getText().equals(String.valueOf(end_day_mm1))){
                           a[i]
[j].setBackgroundResource(R.color.yellow);
                        }
 
if(monthYear.getText().toString().indexOf(String.valueOf(d3.getYear()
+1900))>-1 &&
monthYear.getText().toString().indexOf(months[d3.getMonth()+1])>-1 &&
a[i][j].getText().equals(String.valueOf(end_day_m1))){
                           a[i]
[j].setBackgroundResource(R.color.yellow);
                        }
                     //-----------------------------------------
month3-----------------------------------------------------------------



                    //
System.out.println("------------------------------------------------------------------------------------");

            }
            }


        back.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View v){
                if (currentMonth == 0){ //Back one year
                currentMonth = 11;
                currentYear -= 1;
                }
                else{ //Back one month
                    currentMonth -= 1;
                }
                refreshCalendar(currentMonth, currentYear,a);
            }
        });
        forward.setOnClickListener(new Button.OnClickListener(){
            public void onClick(View v){
                if (currentMonth == 11){ //Forward one year
                currentMonth = 0;
                currentYear += 1;
                }
                else{ //Forward one month
                    currentMonth += 1;
                }
                refreshCalendar(currentMonth, currentYear,a);
            }
        });


    }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to