<commit_before>package com.plusonelabs.calendar.calendar;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Instances;
import android.text.format.DateUtils;

import com.plusonelabs.calendar.DateUtil;
import com.plusonelabs.calendar.prefs.ICalendarPreferences;

public class CalendarContentProvider {

	private static final String EVENT_SORT_ORDER = "startDay ASC, allDay DESC, begin ASC ";
	private static final String EVENT_SELECTION = Instances.SELF_ATTENDEE_STATUS + "!="
			+ Attendees.ATTENDEE_STATUS_DECLINED;
	private static final String[] PROJECTION = new String[] { Instances.EVENT_ID, Instances.TITLE,
			Instances.BEGIN, Instances.END, Instances.ALL_DAY, Instances.CALENDAR_COLOR,
			Instances.HAS_ALARM, Instances.RRULE };
	private static final String CLOSING_BRACKET = " )";
	private static final String OR = " OR ";
	private static final String EQUALS = " = ";
	private static final String AND_BRACKET = " AND (";

	private final Context context;

	public CalendarContentProvider(Context context) {
		this.context = context;
	}

	public ArrayList<CalendarEntry> getEvents() {
		Cursor cursor = createLoadedCursor();
		if (cursor != null) {
			ArrayList<CalendarEntry> eventList = createEventList(cursor);
			cursor.close();
			Collections.sort(eventList);
			return eventList;
		}
		return new ArrayList<CalendarEntry>();
	}

	private ArrayList<CalendarEntry> createEventList(Cursor calendarCursor) {
		ArrayList<CalendarEntry> eventList = new ArrayList<CalendarEntry>();
		for (int i = 0; i < calendarCursor.getCount(); i++) {
			calendarCursor.moveToPosition(i);
			CalendarEntry eventEntry = createCalendarEvent(calendarCursor);
			setupDayOneEntry(eventList, eventEntry);
			createFollowingEntries(eventList, eventEntry);
		}
		return eventList;
	}

	public void setupDayOneEntry(ArrayList<CalendarEntry> eventList, CalendarEntry eventEntry) {
		long today = DateUtil.toMidnight(System.currentTimeMillis());
		int daysCovered = eventEntry.daysCovered();
		if (eventEntry.getStartDate() >= today) {
			if (daysCovered > 1) {
				CalendarEntry clone = eventEntry.clone();
				clone.setEndDate(today + DateUtils.DAY_IN_MILLIS);
				clone.setSpansMultipleDays(true);
				clone.setOriginalEvent(eventEntry);
				eventList.add(clone);
			} else {
				eventList.add(eventEntry);
			}
		}
	}

	public void createFollowingEntries(ArrayList<CalendarEntry> eventList, CalendarEntry eventEntry) {
		int daysCovered = eventEntry.daysCovered();
		for (int j = 1; j < daysCovered; j++) {
			long startDate = DateUtil.toMidnight(eventEntry.getStartDate()
					+ DateUtils.DAY_IN_MILLIS * j);
			if (startDate >= DateUtil.toMidnight(System.currentTimeMillis())) {
				long endDate;
				if (j == daysCovered - 1) {
					endDate = eventEntry.getEndDate();
				} else {
					endDate = startDate + DateUtils.DAY_IN_MILLIS;
				}
				eventList.add(cloneAsSpanningEvent(eventEntry, startDate, endDate));
			}
		}
	}

	public CalendarEntry cloneAsSpanningEvent(CalendarEntry eventEntry, long startDate, long endDate) {
		CalendarEntry clone = eventEntry.clone();
		clone.setStartDate(startDate);
		clone.setEndDate(endDate);
		clone.setSpansMultipleDays(true);
		clone.setOriginalEvent(eventEntry);
		return clone;
	}

	private CalendarEntry createCalendarEvent(Cursor calendarCursor) {
		CalendarEntry eventEntry = new CalendarEntry();
		eventEntry.setEventId(calendarCursor.getInt(0));
		eventEntry.setTitle(calendarCursor.getString(1));
		eventEntry.setStartDate(calendarCursor.getLong(2));
		eventEntry.setEndDate(calendarCursor.getLong(3));
		eventEntry.setAllDay(calendarCursor.getInt(4) > 0);
		eventEntry.setColor(calendarCursor.getInt(5));
		eventEntry.setAlarmActive(calendarCursor.getInt(6) > 0);
		eventEntry.setRecurring(calendarCursor.getString(7) != null);
		return eventEntry;<commit_msg>#22 Set alpha on calendar event colors so that they are not transparent.<commit_after>package com.plusonelabs.calendar.calendar;

import static android.graphics.Color.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Instances;
import android.text.format.DateUtils;

import com.plusonelabs.calendar.DateUtil;
import com.plusonelabs.calendar.prefs.ICalendarPreferences;

public class CalendarContentProvider {

	private static final String EVENT_SORT_ORDER = "startDay ASC, allDay DESC, begin ASC ";
	private static final String EVENT_SELECTION = Instances.SELF_ATTENDEE_STATUS + "!="
			+ Attendees.ATTENDEE_STATUS_DECLINED;
	private static final String[] PROJECTION = new String[] { Instances.EVENT_ID, Instances.TITLE,
			Instances.BEGIN, Instances.END, Instances.ALL_DAY, Instances.CALENDAR_COLOR,
			Instances.HAS_ALARM, Instances.RRULE };
	private static final String CLOSING_BRACKET = " )";
	private static final String OR = " OR ";
	private static final String EQUALS = " = ";
	private static final String AND_BRACKET = " AND (";

	private final Context context;

	public CalendarContentProvider(Context context) {
		this.context = context;
	}

	public ArrayList<CalendarEntry> getEvents() {
		Cursor cursor = createLoadedCursor();
		if (cursor != null) {
			ArrayList<CalendarEntry> eventList = createEventList(cursor);
			cursor.close();
			Collections.sort(eventList);
			return eventList;
		}
		return new ArrayList<CalendarEntry>();
	}

	private ArrayList<CalendarEntry> createEventList(Cursor calendarCursor) {
		ArrayList<CalendarEntry> eventList = new ArrayList<CalendarEntry>();
		for (int i = 0; i < calendarCursor.getCount(); i++) {
			calendarCursor.moveToPosition(i);
			CalendarEntry eventEntry = createCalendarEvent(calendarCursor);
			setupDayOneEntry(eventList, eventEntry);
			createFollowingEntries(eventList, eventEntry);
		}
		return eventList;
	}

	public void setupDayOneEntry(ArrayList<CalendarEntry> eventList, CalendarEntry eventEntry) {
		long today = DateUtil.toMidnight(System.currentTimeMillis());
		int daysCovered = eventEntry.daysCovered();
		if (eventEntry.getStartDate() >= today) {
			if (daysCovered > 1) {
				CalendarEntry clone = eventEntry.clone();
				clone.setEndDate(today + DateUtils.DAY_IN_MILLIS);
				clone.setSpansMultipleDays(true);
				clone.setOriginalEvent(eventEntry);
				eventList.add(clone);
			} else {
				eventList.add(eventEntry);
			}
		}
	}

	public void createFollowingEntries(ArrayList<CalendarEntry> eventList, CalendarEntry eventEntry) {
		int daysCovered = eventEntry.daysCovered();
		for (int j = 1; j < daysCovered; j++) {
			long startDate = DateUtil.toMidnight(eventEntry.getStartDate()
					+ DateUtils.DAY_IN_MILLIS * j);
			if (startDate >= DateUtil.toMidnight(System.currentTimeMillis())) {
				long endDate;
				if (j == daysCovered - 1) {
					endDate = eventEntry.getEndDate();
				} else {
					endDate = startDate + DateUtils.DAY_IN_MILLIS;
				}
				eventList.add(cloneAsSpanningEvent(eventEntry, startDate, endDate));
			}
		}
	}

	public CalendarEntry cloneAsSpanningEvent(CalendarEntry eventEntry, long startDate, long endDate) {
		CalendarEntry clone = eventEntry.clone();
		clone.setStartDate(startDate);
		clone.setEndDate(endDate);
		clone.setSpansMultipleDays(true);
		clone.setOriginalEvent(eventEntry);
		return clone;
	}

	private CalendarEntry createCalendarEvent(Cursor calendarCursor) {
		CalendarEntry eventEntry = new CalendarEntry();
		eventEntry.setEventId(calendarCursor.getInt(0));
		eventEntry.setTitle(calendarCursor.getString(1));
		eventEntry.setStartDate(calendarCursor.getLong(2));
		eventEntry.setEndDate(calendarCursor.getLong(3));
		eventEntry.setAllDay(calendarCursor.getInt(4) > 0);
		eventEntry.setColor(getAsOpaque(calendarCursor.getInt(5)));
		eventEntry.setAlarmActive(calendarCursor.getInt(6) > 0);
		eventEntry.setRecurring(calendarCursor.getString(7) != null);

		System.out.println(eventEntry.getColor());
		return eventEntry;
	}

	private int getAsOpaque(int color) {
		return argb(255, red(color), green(color), blue(color));
{'fraction_non_alphanumeric': 0.10523295845765435, 'fraction_numerical': 0.003787009410144595, 'mean_word_length': 5.542792792792793, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5940997', 'n_tokens_mistral': 2908, 'n_tokens_neox': 2605, 'n_words': 528}