Search in sources :

Example 1 with ContactEventsOnADate

use of com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate in project Memento-Calendar by alexstyl.

the class WearSyncService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (!permissions.canReadAndWriteContacts()) {
        return;
    }
    Optional<ContactEventsOnADate> eventsOptional = fetchContactEvents();
    if (eventsOptional.isPresent()) {
        ContactEventsOnADate contactEvents = eventsOptional.get();
        PutDataRequest putDataRequest = createDataRequest(contactEvents);
        GoogleApiClient googleApiClient = new GoogleApiClient.Builder(getApplicationContext()).addApi(Wearable.API).build();
        if (googleApiClient.blockingConnect().isSuccess()) {
            Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
        }
    }
}
Also used : GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) PutDataRequest(com.google.android.gms.wearable.PutDataRequest) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)

Example 2 with ContactEventsOnADate

use of com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate in project Memento-Calendar by alexstyl.

the class ContactActionTest method testReturnedContactsSizeIsCorrect.

@Test
public void testReturnedContactsSizeIsCorrect() {
    Date date = Date.Companion.on(1, JANUARY, 2016);
    ArrayList<ContactEvent> contactEvent = new ArrayList<>();
    contactEvent.add(EVENT_ONE);
    contactEvent.add(EVENT_TWO);
    ContactEventsOnADate events = ContactEventsOnADate.Companion.createFrom(date, contactEvent);
    List<Contact> contacts = events.getContacts();
    assertThat(contacts.size()).isEqualTo(2);
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) ArrayList(java.util.ArrayList) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) Date(com.alexstyl.specialdates.date.Date) Contact(com.alexstyl.specialdates.contact.Contact) Test(org.junit.Test)

Example 3 with ContactEventsOnADate

use of com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate 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 4 with ContactEventsOnADate

use of com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate 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 5 with ContactEventsOnADate

use of com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate in project Memento-Calendar by alexstyl.

the class ContactActionTest method testContactsAreCorrectlyReturned.

@Test
public void testContactsAreCorrectlyReturned() {
    Date date = Date.Companion.on(1, JANUARY, 2016);
    ArrayList<ContactEvent> contactEvent = new ArrayList<>();
    contactEvent.add(EVENT_ONE);
    contactEvent.add(EVENT_TWO);
    ContactEventsOnADate events = ContactEventsOnADate.Companion.createFrom(date, contactEvent);
    List<Contact> contacts = events.getContacts();
    assertThat(contacts).contains(CONTACT_ONE);
    assertThat(contacts).contains(CONTACT_TWO);
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) ArrayList(java.util.ArrayList) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) ContactEventsOnADate(com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate) Date(com.alexstyl.specialdates.date.Date) Contact(com.alexstyl.specialdates.contact.Contact) Test(org.junit.Test)

Aggregations

ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)7 Date (com.alexstyl.specialdates.date.Date)6 Test (org.junit.Test)4 Contact (com.alexstyl.specialdates.contact.Contact)3 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 RemoteViews (android.widget.RemoteViews)1 Optional (com.alexstyl.specialdates.Optional)1 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)1 PutDataRequest (com.google.android.gms.wearable.PutDataRequest)1