Search in sources :

Example 26 with Date

use of com.alexstyl.specialdates.date.Date in project Memento-Calendar by alexstyl.

the class PeopleEventsSearchTest method aYearFromNow.

private static TimePeriod aYearFromNow() {
    Date today = Date.Companion.today();
    Date aYearFromNow = today.addDay(364);
    return TimePeriod.Companion.between(today, aYearFromNow);
}
Also used : Date(com.alexstyl.specialdates.date.Date)

Example 27 with Date

use of com.alexstyl.specialdates.date.Date in project Memento-Calendar by alexstyl.

the class DateTest method givenAEndOfTheYearDate_whenAddingOneDay_thenTheFirstDayOftheNextYearIsReturned.

@Test
public void givenAEndOfTheYearDate_whenAddingOneDay_thenTheFirstDayOftheNextYearIsReturned() {
    Date lastDayOfYear = Date.Companion.on(31, DECEMBER, 1990);
    Date firstDayOfNextYear = lastDayOfYear.addDay(1);
    assertThat(firstDayOfNextYear.getMonth()).isEqualTo(1);
    assertThat(firstDayOfNextYear.getDayOfMonth()).isEqualTo(1);
    int nextYear = lastDayOfYear.getYear() + 1;
    assertThat(firstDayOfNextYear.getYear()).isEqualTo(nextYear);
}
Also used : Date(com.alexstyl.specialdates.date.Date) Test(org.junit.Test)

Example 28 with Date

use of com.alexstyl.specialdates.date.Date in project Memento-Calendar by alexstyl.

the class TodayAppWidgetProvider method updateForDate.

private void updateForDate(Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds, ContactEventsOnADate contactEvents) {
    Date eventDate = contactEvents.getDate();
    Date date = Date.Companion.on(eventDate.getDayOfMonth(), eventDate.getMonth(), Date.Companion.today().getYear());
    Intent intent = HomeActivity.getStartIntent(context);
    intent.setData(Uri.parse(String.valueOf(date.hashCode())));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    String title = labelOf(date);
    String label = NaturalLanguageUtils.joinContacts(strings, contactEvents.getContacts(), 2);
    WidgetVariant selectedVariant = preferences.getSelectedVariant();
    TransparencyColorCalculator transparencyColorCalculator = new TransparencyColorCalculator();
    float opacity = preferences.getOppacityLevel();
    int selectedTextColor = context.getResources().getColor(selectedVariant.getTextColor());
    WidgetColorCalculator calculator = new WidgetColorCalculator(selectedTextColor);
    int finalHeaderColor = calculator.getColor(Date.Companion.today(), date);
    int avatarSizeInPx = context.getResources().getDimensionPixelSize(R.dimen.widget_avatar_size);
    for (int appWidgetId : appWidgetIds) {
        // Get the layout for the App Widget and attach an on-click listener
        // to the button
        final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_today);
        remoteViews.setTextViewText(R.id.upcoming_widget_header, title);
        remoteViews.setTextViewText(R.id.upcoming_widget_events_text, label);
        remoteViews.setTextColor(R.id.upcoming_widget_events_text, selectedTextColor);
        remoteViews.setTextColor(R.id.upcoming_widget_header, finalHeaderColor);
        int background = context.getResources().getColor(selectedVariant.getBackgroundColorResId());
        int backgroundColor = transparencyColorCalculator.calculateColor(background, opacity);
        remoteViews.setInt(R.id.upcoming_widget_background_image, "setBackgroundColor", backgroundColor);
        remoteViews.setOnClickPendingIntent(R.id.upcoming_widget_background, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        widgetImageLoader.loadPicture(contactEvents.getContacts(), appWidgetId, remoteViews, avatarSizeInPx);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) Date(com.alexstyl.specialdates.date.Date)

Example 29 with Date

use of com.alexstyl.specialdates.date.Date in project Memento-Calendar by alexstyl.

the class QueryUpcomingPeopleEventsTask method doInBackground.

@Override
protected Optional<ContactEventsOnADate> doInBackground(Object... params) {
    Date today = Date.Companion.today();
    Date date = eventsProvider.findClosestEventDateOnOrAfter(today);
    if (date != null) {
        return new Optional<>(eventsProvider.fetchEventsOn(date));
    }
    return Optional.absent();
}
Also used : Optional(com.alexstyl.specialdates.Optional) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) Date(com.alexstyl.specialdates.date.Date)

Example 30 with Date

use of com.alexstyl.specialdates.date.Date in project Memento-Calendar by alexstyl.

the class NamedaysList method indexOf.

private int indexOf(Date date) {
    for (int i = 0; i < namedays.size(); i++) {
        NamesInADate inlistDate = namedays.get(i);
        Date comparingDate = inlistDate.getDate();
        if (isRecurringEvent(comparingDate) && areMatching(comparingDate, date)) {
            return i;
        } else if (comparingDate.equals(date)) {
            return i;
        }
    }
    return -1;
}
Also used : Date(com.alexstyl.specialdates.date.Date)

Aggregations

Date (com.alexstyl.specialdates.date.Date)53 Test (org.junit.Test)34 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)12 Contact (com.alexstyl.specialdates.contact.Contact)6 ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)6 ArrayList (java.util.ArrayList)4 View (android.view.View)3 Intent (android.content.Intent)2 RecyclerView (android.support.v7.widget.RecyclerView)2 TextView (android.widget.TextView)2 NamedayBundle (com.alexstyl.specialdates.events.namedays.NamedayBundle)2 NamedaysList (com.alexstyl.specialdates.events.namedays.NamedaysList)2 NamesInADate (com.alexstyl.specialdates.events.namedays.NamesInADate)2 Calendar (java.util.Calendar)2 DatePickerDialog (android.app.DatePickerDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Preference (android.preference.Preference)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RemoteViews (android.widget.RemoteViews)1