Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show event information with ExtendedCalendarView

I'm trying to create a custom calendar for show events and relative informations in my app. But I don't know how to show this informations. That's the code of the calendar:

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ExtendedCalendarView calendar = (ExtendedCalendarView)findViewById(R.id.calendar);
    ContentValues values = new ContentValues();
    values.put(CalendarProvider.COLOR, Event.COLOR_BLUE);
    values.put(CalendarProvider.DESCRIPTION, "Some Description");
    values.put(CalendarProvider.LOCATION, "Some location");
    values.put(CalendarProvider.EVENT, "Event name");

    Calendar cal = Calendar.getInstance();
    TimeZone tz = TimeZone.getDefault();
    cal.set(startDayYear, startDayMonth, startDayDay, startTimeHour, startTimeMin);
    int StartDayJulian = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));
    values.put(CalendarProvider.START, cal.getTimeInMillis());
    values.put(CalendarProvider.START_DAY, StartDayJulian);

    cal.set(endDayYear, endDayMonth, endDayDay, endTimeHour, endTimeMin);
    int endDayJulian = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));

    values.put(CalendarProvider.END, cal.getTimeInMillis());
    values.put(CalendarProvider.END_DAY, endDayJulian);

   // Uri uri = getContentResolver().insert(CalendarProvider.CONTENT_URI, values);
}

I can see the calendar and the Event , but probably i've to implement some "Onclick" method for display the infomations. Anyone that are using this library that can help me? Beacuse i can't find any information about. Thank you.

like image 488
Giacomo De Bacco Avatar asked Oct 01 '14 13:10

Giacomo De Bacco


2 Answers

I've found the answer by myself.

cal.setOnDayClickListener(new OnDayClickListener() {
        @Override
        public void onDayClicked(AdapterView<?> adapter, View view,
                int position, long id, Day day) {

            dayIsClicked = true;
            clickedDay = day;
            getScheduleDetails(day);

            list.setAdapter(new ListaAdapter(context, R.layout.itemlist,
                            itemsList));

                }

            }

    });

private void getScheduleDetails(Day day) {

itemsList = new ArrayList();

for (Event e : day.getEvents())
{   
    itemsList.add(e);
}

}

like image 132
Giacomo De Bacco Avatar answered Oct 18 '22 06:10

Giacomo De Bacco


i show the informations in a listview below the calendar.

like this. enter image description here

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_location_site_calendar);
        this.ctx = this;

        this.extendedCalendarView = (ExtendedCalendarView) findViewById(R.id.extendedCalendarView_addLocationSiteCalendar_CALENDAR);
        this.listViewCalendar = (ListView) findViewById(R.id.listView_addLocationSiteCalendar_CALENDARLIST);
        //Disable Scrolling
        this.listViewCalendar.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        this.extendedCalendarView.setGesture(ExtendedCalendarView.LEFT_RIGHT_GESTURE);
        addEvent();//test
        addEvent2();//test

        initExtras(savedInstanceState);
        initListener();
    }


private void initListener() {
        extendedCalendarView.setOnDayClickListener(new ExtendedCalendarView.OnDayClickListener() {
            @Override
            public void onDayClicked(AdapterView<?> adapter, View view, int position, long id, Day day) {
                ArrayList<HashMap<Integer, String>> eventList = new ArrayList<HashMap<Integer, String>>();
                for (Event e : day.getEvents()) {
                    HashMap<Integer, String> event = new HashMap<Integer, String>();
                    event.put(NumericValues.LISTROW_ID_IMG_T_ST_IDC_KEY_TITLE, e.getTitle());
                    event.put(NumericValues.LISTROW_ID_IMG_T_ST_IDC_KEY_SUBTITLE, e.getDescription());
                    event.put(NumericValues.LISTROW_ID_IMG_T_ST_IDC_KEY_INDICATOR, e.getStartDate("hh:mm") + " - " + e.getEndDate("hh:mm"));
                    eventList.add(event);
                }
                CalendarListViewAdapter listAdapter = new CalendarListViewAdapter(_this, eventList);
                listViewCalendar.setAdapter(listAdapter);
                ListViewUtil.setListViewHeightBasedOnChildren(listViewCalendar);
            }
        });
    }

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="match_parent">

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

       <com.tyczj.extendedcalendarview.ExtendedCalendarView
            android:id="@+id/extendedCalendarView_addLocationSiteCalendar_CALENDAR"
            android:layout_height="350dp"
            android:layout_width="match_parent" />
        <ListView
            android:id="@+id/listView_addLocationSiteCalendar_CALENDARLIST"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="@drawable/list_divider"
            android:dividerHeight="1px"
            android:listSelector="@drawable/contacts_list_selector" />
    </LinearLayout>
</ScrollView>

like image 35
Alexander Sidikov Pfeif Avatar answered Oct 18 '22 08:10

Alexander Sidikov Pfeif