Android Open Source - BonetCalendarView Custom Day Grid Adapter






From Project

Back to project page BonetCalendarView.

License

The source code is released under:

Apache License

If you think the Android project BonetCalendarView listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bonet.example.bonetcalendarviewactivity;
// w  w  w  .  j av  a 2  s  .  c  o  m
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bonet.views.BtDate;
import com.bonet.views.BtMonth;
import com.bonet.views.DayGridAdapter;

public class CustomDayGridAdapter extends DayGridAdapter {
  
  /* The selected date */
  private BtDate mSelectedDay;
  public CustomDayGridAdapter(Context context, 
                BtMonth month, 
                BtDate minDay,
                BtDate maxDay,
                BtDate selectedDay) {
    
    super(context, month,minDay,maxDay);
    
    mSelectedDay = selectedDay;
  }
  
  public void setSelectedDay(BtDate day){
    mSelectedDay = day;
    if(BtMonth.fromDay(mSelectedDay).equals(getMonth()))
      notifyDataSetChanged();
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    
    /*
     * So, two modifications here:
     * 1) we have to somehow highlight the date. I am going to do it by
     *   setting a special background and foreground
     * 
     * 2 ) I am going to alternate between row colors
     * 
     */
    
    // create the view using the super method
    View v = super.getView(position, convertView, parent);
    
    // if it is a odd row, gonna set the background to grey
    if((position / 7) % 2 == 1)
      v.setBackgroundColor(Color.rgb(130, 130, 130));
    else
      v.setBackgroundColor(Color.WHITE);
    
    // if it is the selected day, I am going to load a special background
    // from the resources
    int fp = getDisplayHelper().getRowOf(1)*7+ getDisplayHelper().getColumnOf(1);
    
    if(getMonth().getDate(position + 1 - fp).equals(mSelectedDay)){
      TextView tv = (TextView) v.findViewById(R.id.text);
      tv.setBackgroundResource(R.drawable.selected_day_button_style);
    }
    else
      v.findViewById(R.id.text).setBackgroundColor(Color.TRANSPARENT);
    
    return v;
  }
  

}




Java Source Code List

com.bonet.example.bonetcalendarviewactivity.CustomDayGridAdapter.java
com.bonet.example.bonetcalendarviewactivity.CustomGridCalendarActivity.java
com.bonet.example.bonetcalendarviewactivity.CustomGridCalendar.java
com.bonet.example.bonetcalendarviewactivity.CustomMonthProvider.java
com.bonet.example.bonetcalendarviewactivity.CustomYearAdapter.java
com.bonet.example.bonetcalendarviewactivity.CustomYearProvider.java
com.bonet.example.bonetcalendarviewactivity.ExampleActivity.java
com.bonet.example.bonetcalendarviewactivity.GridCalendarActivity.java
com.bonet.example.bonetcalendarviewactivity.ListCalendarActivity.java
com.bonet.views.BtCalendarView.java
com.bonet.views.BtCalendar.java
com.bonet.views.BtDate.java
com.bonet.views.BtMonthViewProvider.java
com.bonet.views.BtMonth.java
com.bonet.views.BtYearViewProvider.java
com.bonet.views.DayGridAdapter.java
com.bonet.views.DayListAdapter.java
com.bonet.views.GridBtMonthViewProvider.java
com.bonet.views.ListBtMonthViewProvider.java
com.bonet.views.ListBtYearViewProvider.java
com.bonet.views.MonthListAdapter.java
com.bonet.views.OnDateSelectedListener.java
com.bonet.views.package-info.java