Skip to content

Instantly share code, notes, and snippets.

@skooltch84
Created February 10, 2017 23:27
Show Gist options
  • Save skooltch84/5575780e1822c7eb38bb249c78f9fe4d to your computer and use it in GitHub Desktop.
Save skooltch84/5575780e1822c7eb38bb249c78f9fe4d to your computer and use it in GitHub Desktop.
This fragment uses the sundeepk compact calendar view
package com.blogspot.skooltchdev.christchurchgirls;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.github.sundeepk.compactcalendarview.CompactCalendarView;
import com.github.sundeepk.compactcalendarview.domain.Event;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class Events extends Fragment{
private Toolbar toolbar;
private SimpleDateFormat dateFormatForMonth = new SimpleDateFormat("MMMM- yyyy", Locale.getDefault());
CompactCalendarView compactCalendar;
public Events() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.activity_events, container, false);
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
final ActionBar actionBar = ((AppCompatActivity)getActivity()).getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setTitle(null);
compactCalendar = (CompactCalendarView) view.findViewById(R.id.compactcalendar_view);
compactCalendar.setUseThreeLetterAbbreviation(true);
Event ev1 = new Event(Color.RED, 1477040400000L, "Teacher's Professional Day");
compactCalendar.addEvent(ev1);
Event ev2 = new Event(Color.RED, 1477990800000L, "Church Service and Flag Raising Ceremony");
compactCalendar.addEvent(ev2);
Event ev3 = new Event(Color.RED, 1478077200000L, "Display of Bajan Artefacts");
compactCalendar.addEvent(ev3);
Event ev4 = new Event(Color.RED, 1478509200000L, "Reading Activities - Story Telling");
compactCalendar.addEvent(ev4);
Event ev5 = new Event(Color.RED, 1478854800000L, "Healthy Lifestyle Day");
compactCalendar.addEvent(ev5);
Event ev6 = new Event(Color.RED, 1479459600000L, "Games Day/Tour");
compactCalendar.addEvent(ev6);
Event ev7 = new Event(Color.RED, 1479891600000L, "Independence Quiz");
compactCalendar.addEvent(ev7);
Event ev8 = new Event(Color.RED, 1480064400000L, "Cultural Day");
compactCalendar.addEvent(ev8);
Event ev9 = new Event(Color.RED, 1480237200000L, "P.T.A Picnic");
compactCalendar.addEvent(ev9);
Event ev10 = new Event(Color.RED, 1480323600000L, "Human Chainlink");
compactCalendar.addEvent(ev10);
Event ev11 = new Event(Color.RED, 1480410000000L, "Back in Time Modelling");
compactCalendar.addEvent(ev11);
Event ev12 = new Event(Color.RED, 1480496400000L, "Independence");
compactCalendar.addEvent(ev12);
Event ev13 = new Event(Color.BLUE, 1481792400000L, "End of Term for Students");
compactCalendar.addEvent(ev13);
Event ev14 = new Event(Color.BLUE, 1481878800000L, "End of Term for Teachers");
compactCalendar.addEvent(ev14);
Event ev15 = new Event(Color.GREEN, 1482638400000L, "Christmas Day");
compactCalendar.addEvent(ev15);
Event ev16 = new Event(Color.GREEN, 1482724800000L, "Boxing Day");
compactCalendar.addEvent(ev16);
Event ev17 = new Event(Color.GREEN, 1483243200000L, "New Years Day");
compactCalendar.addEvent(ev17);
Event ev18 = new Event(Color.BLUE, 1483934400000L, "Beginning of Term for Teachers");
compactCalendar.addEvent(ev18);
Event ev19 = new Event(Color.BLUE, 1484020800000L, "Beginning of Term for Students");
compactCalendar.addEvent(ev19);
actionBar.setTitle(dateFormatForMonth.format(compactCalendar.getFirstDayOfCurrentMonth()));
compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
@Override
public void onDayClick(Date dateClicked) {
Context context = getActivity().getApplicationContext();
if (dateClicked.toString().compareTo("Fri Oct 21 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Teacher's Professional Day", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Tue Nov 01 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Church Service & Flag Raising", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Wed Nov 02 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Bajan Display of Artifacts", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Mon Nov 07 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Reading Activities - Storytelling", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Fri Nov 11 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Healthy Lifestyle Day", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Fri Nov 18 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Games Day / Tour", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Wed Nov 23 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Independence Quiz", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Fri Nov 25 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Cultural Day", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Sun Nov 27 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "P.T.A Picnic", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Tue Nov 29 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Back in Time Modelling", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Mon Nov 28 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Chain Link", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Wed Nov 30 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Independence", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Thu Dec 15 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "End of Term for Students", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Fri Dec 16 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "End of Term for Teachers", Toast.LENGTH_SHORT).show();
} else if (dateClicked.toString().compareTo("Sun Dec 25 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Christmas Day", Toast.LENGTH_SHORT).show();
}else if (dateClicked.toString().compareTo("Mon Dec 26 00:00:00 AST 2016") == 0) {
Toast.makeText(context, "Boxing Day", Toast.LENGTH_SHORT).show();
}else if (dateClicked.toString().compareTo("Sun Jan 01 00:00:00 AST 2017") == 0) {
Toast.makeText(context, "New Years Day", Toast.LENGTH_SHORT).show();
}else if (dateClicked.toString().compareTo("Mon Jan 09 00:00:00 AST 2017") == 0) {
Toast.makeText(context, "Beginning of Term for Teachers", Toast.LENGTH_SHORT).show();
}else if (dateClicked.toString().compareTo("Tue Jan 10 00:00:00 AST 2017") == 0) {
Toast.makeText(context, "Beginning of Term for Students", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(context, "No Events Planned for that day", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onMonthScroll(Date firstDayOfNewMonth) {
// Changes toolbar title on monthChange
actionBar.setTitle(dateFormatForMonth.format(firstDayOfNewMonth));
}
});
gotoToday();
return view;
}
public void gotoToday() {
// Set any date to navigate to particular date
compactCalendar.setCurrentDate(Calendar.getInstance(Locale.getDefault()).getTime());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment