Example usage for android.provider CalendarContract EXTRA_EVENT_END_TIME

List of usage examples for android.provider CalendarContract EXTRA_EVENT_END_TIME

Introduction

In this page you can find the example usage for android.provider CalendarContract EXTRA_EVENT_END_TIME.

Prototype

String EXTRA_EVENT_END_TIME

To view the source code for android.provider CalendarContract EXTRA_EVENT_END_TIME.

Click Source Link

Document

Intent Extras key: The end time of an event or an instance of a recurring event.

Usage

From source file:Main.java

public static Intent createOpenCalendarEventIntent(int eventId, DateTime from, DateTime to) {
    Intent intent = createCalendarIntent(Intent.ACTION_VIEW);
    intent.setData(ContentUris.withAppendedId(Events.CONTENT_URI, eventId));
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, from.getMillis());
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, to.getMillis());
    return intent;
}

From source file:Main.java

/**
 * Builds an Intent to add a new event to the calendar.
 *
 * @param title The title of the event./*  w ww  .j  a  v a  2s . c  o  m*/
 * @param start The start date and time.
 * @param end   The end date and time.
 * @param where Where the event is held (e.g.: an address).
 */
public static Intent getAddEventIntent(final String title, final Date start, final Date end,
        final String where) {
    Intent intent = new Intent(Intent.ACTION_INSERT);
    intent.setData(CalendarContract.Events.CONTENT_URI);
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start.getTime());
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end.getTime());
    intent.putExtra(CalendarContract.Events.TITLE, title);

    if (where != null) {
        intent.putExtra(CalendarContract.Events.EVENT_LOCATION, where);
    }

    return intent;
}

From source file:com.battlelancer.seriesguide.util.ShareUtils.java

/**
 * Launches a calendar insert intent for the given episode.
 *///from  ww  w.j a  v a 2s.  c o m
public static void suggestCalendarEvent(Context context, String showTitle, String episodeTitle,
        long episodeReleaseTime, int showRunTime) {
    Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI)
            .putExtra(CalendarContract.Events.TITLE, showTitle)
            .putExtra(CalendarContract.Events.DESCRIPTION, episodeTitle);

    long beginTime = TimeTools.getEpisodeReleaseTime(context, episodeReleaseTime).getTime();
    long endTime = beginTime + showRunTime * DateUtils.MINUTE_IN_MILLIS;
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime);
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime);

    if (!Utils.tryStartActivity(context, intent, false)) {
        Toast.makeText(context, context.getString(R.string.addtocalendar_failed), Toast.LENGTH_SHORT).show();
        Utils.trackCustomEvent(context, TAG, "Calendar", "Failed");
    }
}

From source file:com.dev.campus.event.EventViewActivity.java

/**
 * Launches the device's calendar and pre-fills event info
 * @param event the event to add to the calendar
 *//*from   w ww .  j av a  2s.com*/
public void addToCalendar(Event event) {
    //Strip HTML tags and carriage returns for better readability
    String details = Html.fromHtml(event.getDetails()).toString().replace("\n", " ");
    Intent calIntent = new Intent(Intent.ACTION_EDIT);
    calIntent.setType("vnd.android.cursor.item/event");
    calIntent.putExtra(Events.TITLE, event.getTitle());
    calIntent.putExtra(Events.DESCRIPTION, details);
    calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, event.getStartDate().getTime());
    calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.getEndDate().getTime());
    startActivity(calIntent);
}

From source file:com.intuitlabs.wear.voiceandchoice.ActionReceiver.java

/**
 * {@inheritDoc}/*  www .j a v  a2s .c  o m*/
 */
@Override
public void onReceive(final Context context, final Intent _intent) {

    /** notificationId used to issue the notification, so we can cancel the notification */
    final int notificationId = _intent.getIntExtra(Intent.EXTRA_UID, -1);

    /** The bundle that was created during the speech recognition process */
    final Bundle remoteInput = RemoteInput.getResultsFromIntent(_intent);

    /* The user's choice, either directly selected or as a speech recognition result. */
    final String reply = remoteInput != null
            ? remoteInput.getCharSequence(AndroidNotification.EXTRA_VOICE_REPLY).toString()
            : "";

    /* The integer value, associated with the command string in the original json document that was used to generate the notification */
    @SuppressWarnings("unchecked")
    final Map<String, Integer> cmdkeys = (Map<String, Integer>) ListStyle.readFromSharedPreference(context);
    final int selectedId = new PhoneticSearch<>(cmdkeys).match(reply);

    Log.v(LOG_TAG, "Selection / Speech Recognition result: " + reply);
    Log.i(LOG_TAG, "Selection / Selected ID " + selectedId);

    /* Cancel the Notification, which makes it disappear on phone and watch */
    final NotificationManager manager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(notificationId);

    switch (selectedId) {
    // Purchase Turbo Tax / Go to Web Page
    case 0:
    case 4:
        final String url = context.getString(R.string.turbotax_url);
        context.startActivity(
                new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        break;

    // create a calendar Event
    case 1:
    case 5:
        final Calendar cal = Calendar.getInstance();
        cal.set(2015, 3, 15);

        final Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI)
                .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTimeInMillis())
                .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, cal.getTimeInMillis() + 60 * 60 * 1000)
                .putExtra(CalendarContract.Events.TITLE, context.getString(R.string.turbotax_title))
                .putExtra(CalendarContract.Events.DESCRIPTION, context.getString(R.string.turbotax_description))
                .putExtra(CalendarContract.Events.EVENT_LOCATION, context.getString(R.string.turbotax_location))
                .putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY)
                .putExtra(Intent.EXTRA_EMAIL, context.getString(R.string.turbotax_email))
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        break;

    // set a reminder
    case 2:
    case 6:
        // todo, set a reminder ..
        break;

    // dismiss, do nothing
    case 3:
    case 7:
    default:
    }
}

From source file:com.dgsd.android.ShiftTracker.EditShiftActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.delete) {
        if (mEditShiftFragment.isEditing()) {
            //Remove any alarms
            AlarmUtils.get(this).cancel(mEditShiftFragment.getShift());
            DbService.async_delete(this, Provider.SHIFTS_URI,
                    DbField.ID + "=" + mEditShiftFragment.getEditingId());
        }/*from   ww  w.  jav  a 2 s.  c  om*/

        finish();
        return true;
    } else if (item.getItemId() == R.id.export_to_calendar) {
        final Shift shift = mEditShiftFragment == null ? null : mEditShiftFragment.getShift();
        if (!Api.isMin(Api.ICS) || shift == null)
            return true;

        Intent intent = new Intent(Intent.ACTION_INSERT);
        intent.setData(Events.CONTENT_URI);
        intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, shift.getStartTime());
        intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, shift.getEndTime());
        intent.putExtra(Events.TITLE, shift.name);
        intent.putExtra(Events.DESCRIPTION, shift.note);
        intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);

        startActivity(intent);

        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java

@SuppressLint("NewApi")
public static void addToCalender(Context context, Lecture l) {
    Intent intent = new Intent(Intent.ACTION_INSERT, CalendarContract.Events.CONTENT_URI);

    intent.putExtra(CalendarContract.Events.TITLE, l.title);
    intent.putExtra(CalendarContract.Events.EVENT_LOCATION, l.room);

    long when;//  ww  w . ja va2  s  .c o m
    if (l.dateUTC > 0) {
        when = l.dateUTC;
    } else {
        Time time = l.getTime();
        when = time.normalize(true);
    }
    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, when);
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, when + (l.duration * 60000));
    final String description = getCalendarDescription(context, l);
    intent.putExtra(CalendarContract.Events.DESCRIPTION, description);
    try {
        context.startActivity(intent);
        return;
    } catch (ActivityNotFoundException e) {
    }
    intent.setAction(Intent.ACTION_EDIT);
    try {
        context.startActivity(intent);
        return;
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, R.string.add_to_calendar_failed, Toast.LENGTH_LONG).show();
    }
}

From source file:fr.bde_eseo.eseomega.events.EventItem.java

public Intent toCalendarIntent() {
    Intent calIntent = new Intent(Intent.ACTION_INSERT);
    calIntent.setType("vnd.android.cursor.item/event");
    calIntent.putExtra(CalendarContract.Events.TITLE, name);
    calIntent.putExtra(CalendarContract.Events.EVENT_LOCATION, (lieu != null ? lieu : ""));
    calIntent.putExtra(CalendarContract.Events.DESCRIPTION, (details != null ? details : ""));

    SimpleDateFormat sdf = new SimpleDateFormat("HH'h'mm", Locale.FRANCE);
    String sDate = sdf.format(this.date);
    boolean allDay = sDate.equals(HOUR_PASS_ALLDAY);
    calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, allDay);
    calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, cal.getTimeInMillis());
    if (!allDay)/*from   ww  w. j a  v  a2s .c  o  m*/
        calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calFin.getTimeInMillis());

    return calIntent;
}

From source file:com.salesforce.marketingcloud.android.demoapp.LearningAppApplication.java

@Override
public NotificationCompat.Builder setupNotificationBuilder(@NonNull Context context,
        @NonNull NotificationMessage notificationMessage) {
    NotificationCompat.Builder builder = NotificationManager.getDefaultNotificationBuilder(context,
            notificationMessage, NotificationManager.createDefaultNotificationChannel(context),
            R.drawable.ic_stat_app_logo_transparent);

    Map<String, String> customKeys = notificationMessage.customKeys();
    if (!customKeys.containsKey("category") || !customKeys.containsKey("sale_date")) {
        return builder;
    }/* w  w  w  .j a v  a  2 s . com*/

    if ("sale".equalsIgnoreCase(customKeys.get("category"))) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        simpleDateFormat.setTimeZone(TimeZone.getDefault());
        try {
            Date saleDate = simpleDateFormat.parse(customKeys.get("sale_date"));
            Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI)
                    .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, saleDate.getTime())
                    .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, saleDate.getTime())
                    .putExtra(CalendarContract.Events.TITLE, customKeys.get("event_title"))
                    .putExtra(CalendarContract.Events.DESCRIPTION, customKeys.get("alert"))
                    .putExtra(CalendarContract.Events.HAS_ALARM, 1)
                    .putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
            PendingIntent pendingIntent = PendingIntent.getActivity(context,
                    R.id.interactive_notification_reminder, intent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.addAction(android.R.drawable.ic_menu_my_calendar, getString(R.string.in_btn_add_reminder),
                    pendingIntent);
        } catch (ParseException e) {
            Log.e(TAG, e.getMessage(), e);
        }
    }
    return builder;
}

From source file:com.wit.android.support.content.intent.CalendarIntent.java

/**
 *///from  ww  w. j  a  va 2s. c  om
@Nullable
@Override
public Intent buildIntent() {
    switch (mType) {
    case TYPE_VIEW:
        if (checkTime(mBeginTime, "Time isn't valid.")) {
            final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
            builder.appendPath("time");
            ContentUris.appendId(builder, mBeginTime);
            /**
             * Build the intent.
             */
            return new Intent(Intent.ACTION_VIEW).setData(builder.build());
        }
        break;
    case TYPE_INSERT_EVENT:
        if (!checkTime(mBeginTime, "Begin time(" + mBeginTime + ") isn't valid.")) {
            return null;
        }
        if (!checkTime(mEndTime, "End time(" + mEndTime + ") isn't valid.")) {
            return null;
        }
        if (mEndTime <= mBeginTime) {
            this.logMessage(
                    "End time(" + mEndTime + ") is wrong specified before/at begin time(" + mBeginTime + ").");
            return null;
        }
        /**
         * Build the intent.
         */
        final Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI)
                .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, mBeginTime)
                .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, mEndTime)
                .putExtra(CalendarContract.Events.TITLE, mTitle)
                .putExtra(CalendarContract.Events.DESCRIPTION, mDescription)
                .putExtra(CalendarContract.Events.EVENT_LOCATION, mLocation)
                .putExtra(CalendarContract.Events.AVAILABILITY, mAvailability);
        // todo: add extra emails.
        // intent.putExtra(Intent.EXTRA_EMAIL, "rowan@example.com,trevor@example.com");
        return intent;
    case TYPE_EDIT_EVENT:
        if (checkEventId()) {
            /**
             * Build the intent.
             */
            final Intent eventIntent = new Intent(Intent.ACTION_EDIT);
            eventIntent.setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId));
            if (!TextUtils.isEmpty(mTitle)) {
                eventIntent.putExtra(CalendarContract.Events.TITLE, mTitle);
            }
            return eventIntent;
        }
        break;
    case TYPE_VIEW_EVENT:
        if (checkEventId()) {
            /**
             * Build the intent.
             */
            return new Intent(Intent.ACTION_VIEW)
                    .setData(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, mEventId));
        }
        break;
    }
    return null;
}