// Path: Calender Read Demo/app/src/main/java/example/calandersync/utils/DividerItemDecorator.java
// public class DividerItemDecorator extends RecyclerView.ItemDecoration {
//     private Drawable mDivider;
// 
//     public DividerItemDecorator(Drawable divider){
//         mDivider = divider;
//     }
//     @Override
//     public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//         super.getItemOffsets(outRect, view, parent, state);
// 
//         if (parent.getChildAdapterPosition(view) == 0) {
//             return;
//         }
// 
//         outRect.top = mDivider.getIntrinsicHeight();
//     }
// 
//     @Override
//     public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
//         int dividerLeft = parent.getPaddingLeft();
//         int dividerRight = parent.getWidth() - parent.getPaddingRight();
// 
//         int childCount = parent.getChildCount();
//         for (int i = 0; i < childCount - 1; i++) {
//             View child = parent.getChildAt(i);
// 
//             RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
// 
//             int dividerTop = child.getBottom() + params.bottomMargin;
//             int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();
// 
//             mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
//             mDivider.draw(canvas);
//         }
//     }
// }
// 
// Path: Calender Read Demo/app/src/main/java/example/calandersync/pojo/CalenderPojo.java
// public class CalenderPojo {
// 
//     private String name;
//     private long id;
//     private int color;
//     private String displayName;
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public CalenderPojo(){
//     }
// 
//     @ColorInt
//     public int getColor() {
//         return color;
//     }
// 
//     public void setColor(@ColorInt int color) {
//         this.color = color;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// }


import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import example.calandersync.utils.DividerItemDecorator;
import example.calandersync.R;
import example.calandersync.pojo.CalenderPojo;
package example.calandersync.activity;




/**
 * This activity will display how to display all the available calenders.
 */
public class CalenderListActivity extends AppCompatActivity {

    private static final int REQUEST_CALENDER_PERMISSION = 111;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //check for the calender permission
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CALENDAR}, REQUEST_CALENDER_PERMISSION);
        } else {
            //recycle view
            setRecyclerView();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == REQUEST_CALENDER_PERMISSION) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) setRecyclerView();
        }
    }

    /**
     * Set the recycler view to display calender list
     */
    public void setRecyclerView() {
        RecyclerView calenderList = (RecyclerView) findViewById(R.id.recycler_view);
        calenderList.setLayoutManager(new LinearLayoutManager(this));
        calenderList.setHasFixedSize(true);
        calenderList.setItemAnimator(new DefaultItemAnimator());

        RecyclerView.ItemDecoration dividerItemDecoration = new DividerItemDecorator(ContextCompat.getDrawable(this, R.drawable.line_divider));
        calenderList.addItemDecoration(dividerItemDecoration);

        calenderList.setAdapter(new CalenderListAdapter(getCalenders()));
    }

    /**
     * Adapter to bind calender list
     */
    private class CalenderListAdapter extends RecyclerView.Adapter<CalenderListAdapter.ViewHolder> {
// Path: Calender Read Demo/app/src/main/java/example/calandersync/utils/DividerItemDecorator.java
// public class DividerItemDecorator extends RecyclerView.ItemDecoration {
//     private Drawable mDivider;
// 
//     public DividerItemDecorator(Drawable divider){
//         mDivider = divider;
//     }
//     @Override
//     public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//         super.getItemOffsets(outRect, view, parent, state);
// 
//         if (parent.getChildAdapterPosition(view) == 0) {
//             return;
//         }
// 
//         outRect.top = mDivider.getIntrinsicHeight();
//     }
// 
//     @Override
//     public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
//         int dividerLeft = parent.getPaddingLeft();
//         int dividerRight = parent.getWidth() - parent.getPaddingRight();
// 
//         int childCount = parent.getChildCount();
//         for (int i = 0; i < childCount - 1; i++) {
//             View child = parent.getChildAt(i);
// 
//             RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
// 
//             int dividerTop = child.getBottom() + params.bottomMargin;
//             int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();
// 
//             mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
//             mDivider.draw(canvas);
//         }
//     }
// }
// 
// Path: Calender Read Demo/app/src/main/java/example/calandersync/pojo/CalenderPojo.java
// public class CalenderPojo {
// 
//     private String name;
//     private long id;
//     private int color;
//     private String displayName;
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public CalenderPojo(){
//     }
// 
//     @ColorInt
//     public int getColor() {
//         return color;
//     }
// 
//     public void setColor(@ColorInt int color) {
//         this.color = color;
//     }
// 
//     public String getDisplayName() {
//         return displayName;
//     }
// 
//     public void setDisplayName(String displayName) {
//         this.displayName = displayName;
//     }
// }


// Path: Calender Read Demo/app/src/main/java/example/calandersync/activity/CalenderListActivity.java
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import example.calandersync.utils.DividerItemDecorator;
import example.calandersync.R;
import example.calandersync.pojo.CalenderPojo;

package example.calandersync.activity;




/**
 * This activity will display how to display all the available calenders.
 */
public class CalenderListActivity extends AppCompatActivity {

    private static final int REQUEST_CALENDER_PERMISSION = 111;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //check for the calender permission
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CALENDAR}, REQUEST_CALENDER_PERMISSION);
        } else {
            //recycle view
            setRecyclerView();
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        if (requestCode == REQUEST_CALENDER_PERMISSION) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) setRecyclerView();
        }
    }

    /**
     * Set the recycler view to display calender list
     */
    public void setRecyclerView() {
        RecyclerView calenderList = (RecyclerView) findViewById(R.id.recycler_view);
        calenderList.setLayoutManager(new LinearLayoutManager(this));
        calenderList.setHasFixedSize(true);
        calenderList.setItemAnimator(new DefaultItemAnimator());

        RecyclerView.ItemDecoration dividerItemDecoration = new DividerItemDecorator(ContextCompat.getDrawable(this, R.drawable.line_divider));
        calenderList.addItemDecoration(dividerItemDecoration);

        calenderList.setAdapter(new CalenderListAdapter(getCalenders()));
    }

    /**
     * Adapter to bind calender list
     */
    private class CalenderListAdapter extends RecyclerView.Adapter<CalenderListAdapter.ViewHolder> {
        private ArrayList<CalenderPojo> mData;