Search in sources :

Example 6 with ReminderEntry

use of com.android.calendar.CalendarEventModel.ReminderEntry in project Etar-Calendar by Etar-Group.

the class EventViewUtils method reminderItemsToReminders.

/**
     * Extracts reminder minutes info from UI elements.
     *
     * @param reminderItems UI elements (layouts with spinners) that hold array indices.
     * @param reminderMinuteValues Maps array index to time in minutes.
     * @param reminderMethodValues Maps array index to alert method constant.
     * @return Array with reminder data.
     */
public static ArrayList<ReminderEntry> reminderItemsToReminders(ArrayList<LinearLayout> reminderItems, ArrayList<Integer> reminderMinuteValues, ArrayList<Integer> reminderMethodValues) {
    int len = reminderItems.size();
    ArrayList<ReminderEntry> reminders = new ArrayList<ReminderEntry>(len);
    for (int index = 0; index < len; index++) {
        LinearLayout layout = reminderItems.get(index);
        Spinner minuteSpinner = (Spinner) layout.findViewById(R.id.reminder_minutes_value);
        Spinner methodSpinner = (Spinner) layout.findViewById(R.id.reminder_method_value);
        int minutes = reminderMinuteValues.get(minuteSpinner.getSelectedItemPosition());
        int method = reminderMethodValues.get(methodSpinner.getSelectedItemPosition());
        reminders.add(ReminderEntry.valueOf(minutes, method));
    }
    return reminders;
}
Also used : Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) ReminderEntry(com.android.calendar.CalendarEventModel.ReminderEntry) LinearLayout(android.widget.LinearLayout)

Example 7 with ReminderEntry

use of com.android.calendar.CalendarEventModel.ReminderEntry in project Etar-Calendar by Etar-Group.

the class EditEventView method prepareReminders.

/**
     * Prepares the reminder UI elements.
     * <p>
     * (Re-)loads the minutes / methods lists from the XML assets, adds/removes items as
     * needed for the current set of reminders and calendar properties, and then creates UI
     * elements.
     */
private void prepareReminders() {
    CalendarEventModel model = mModel;
    Resources r = mActivity.getResources();
    // Load the labels and corresponding numeric values for the minutes and methods lists
    // from the assets.  If we're switching calendars, we need to clear and re-populate the
    // lists (which may have elements added and removed based on calendar properties).  This
    // is mostly relevant for "methods", since we shouldn't have any "minutes" values in a
    // new event that aren't in the default set.
    mReminderMinuteValues = loadIntegerArray(r, R.array.reminder_minutes_values);
    mReminderMinuteLabels = loadStringArray(r, R.array.reminder_minutes_labels);
    mReminderMethodValues = loadIntegerArray(r, R.array.reminder_methods_values);
    mReminderMethodLabels = loadStringArray(r, R.array.reminder_methods_labels);
    // a new event, mCalendarAllowedReminders may not be set the first time we're called.
    if (mModel.mCalendarAllowedReminders != null) {
        EventViewUtils.reduceMethodList(mReminderMethodValues, mReminderMethodLabels, mModel.mCalendarAllowedReminders);
    }
    int numReminders = 0;
    if (model.mHasAlarm) {
        ArrayList<ReminderEntry> reminders = model.mReminders;
        numReminders = reminders.size();
        // Insert any minute values that aren't represented in the minutes list.
        for (ReminderEntry re : reminders) {
            if (mReminderMethodValues.contains(re.getMethod())) {
                EventViewUtils.addMinutesToList(mActivity, mReminderMinuteValues, mReminderMinuteLabels, re.getMinutes());
            }
        }
        // Create a UI element for each reminder.  We display all of the reminders we get
        // from the provider, even if the count exceeds the calendar maximum.  (Also, for
        // a new event, we won't have a maxReminders value available.)
        mUnsupportedReminders.clear();
        for (ReminderEntry re : reminders) {
            if (mReminderMethodValues.contains(re.getMethod()) || re.getMethod() == Reminders.METHOD_DEFAULT) {
                EventViewUtils.addReminder(mActivity, mScrollView, this, mReminderItems, mReminderMinuteValues, mReminderMinuteLabels, mReminderMethodValues, mReminderMethodLabels, re, Integer.MAX_VALUE, null);
            } else {
                // TODO figure out a way to display unsupported reminders
                mUnsupportedReminders.add(re);
            }
        }
    }
    updateRemindersVisibility(numReminders);
    EventViewUtils.updateAddReminderButton(mView, mReminderItems, mModel.mCalendarMaxReminders);
}
Also used : ReminderEntry(com.android.calendar.CalendarEventModel.ReminderEntry) CalendarEventModel(com.android.calendar.CalendarEventModel) Resources(android.content.res.Resources)

Example 8 with ReminderEntry

use of com.android.calendar.CalendarEventModel.ReminderEntry in project Etar-Calendar by Etar-Group.

the class EditEventHelper method saveReminders.

/**
     * Saves the reminders, if they changed. Returns true if operations to
     * update the database were added.
     *
     * @param ops the array of ContentProviderOperations
     * @param eventId the id of the event whose reminders are being updated
     * @param reminders the array of reminders set by the user
     * @param originalReminders the original array of reminders
     * @param forceSave if true, then save the reminders even if they didn't change
     * @return true if operations to update the database were added
     */
public static boolean saveReminders(ArrayList<ContentProviderOperation> ops, long eventId, ArrayList<ReminderEntry> reminders, ArrayList<ReminderEntry> originalReminders, boolean forceSave) {
    // If the reminders have not changed, then don't update the database
    if (reminders.equals(originalReminders) && !forceSave) {
        return false;
    }
    // Delete all the existing reminders for this event
    String where = Reminders.EVENT_ID + "=?";
    String[] args = new String[] { Long.toString(eventId) };
    ContentProviderOperation.Builder b = ContentProviderOperation.newDelete(Reminders.CONTENT_URI);
    b.withSelection(where, args);
    ops.add(b.build());
    ContentValues values = new ContentValues();
    int len = reminders.size();
    // Insert the new reminders, if any
    for (int i = 0; i < len; i++) {
        ReminderEntry re = reminders.get(i);
        values.clear();
        values.put(Reminders.MINUTES, re.getMinutes());
        values.put(Reminders.METHOD, re.getMethod());
        values.put(Reminders.EVENT_ID, eventId);
        b = ContentProviderOperation.newInsert(Reminders.CONTENT_URI).withValues(values);
        ops.add(b.build());
    }
    return true;
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) ReminderEntry(com.android.calendar.CalendarEventModel.ReminderEntry)

Example 9 with ReminderEntry

use of com.android.calendar.CalendarEventModel.ReminderEntry in project Etar-Calendar by Etar-Group.

the class EventInfoActivity method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    dynamicTheme.onCreate(this);
    // Workaround reverts Noactionbar in dynamicTheme
    setTheme(R.style.Base_CalendarAppThemeWithActionBar);
    // Get the info needed for the fragment
    Intent intent = getIntent();
    int attendeeResponse = 0;
    mEventId = -1;
    boolean isDialog = false;
    ArrayList<ReminderEntry> reminders = null;
    if (icicle != null) {
        mEventId = icicle.getLong(EventInfoFragment.BUNDLE_KEY_EVENT_ID);
        mStartMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_START_MILLIS);
        mEndMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_END_MILLIS);
        attendeeResponse = icicle.getInt(EventInfoFragment.BUNDLE_KEY_ATTENDEE_RESPONSE);
        isDialog = icicle.getBoolean(EventInfoFragment.BUNDLE_KEY_IS_DIALOG);
        reminders = Utils.readRemindersFromBundle(icicle);
    } else if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
        mStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
        mEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
        attendeeResponse = intent.getIntExtra(ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_NONE);
        Uri data = intent.getData();
        if (data != null) {
            try {
                List<String> pathSegments = data.getPathSegments();
                int size = pathSegments.size();
                if (size > 2 && "EventTime".equals(pathSegments.get(2))) {
                    // Support non-standard VIEW intent format:
                    //dat = content://com.android.calendar/events/[id]/EventTime/[start]/[end]
                    mEventId = Long.parseLong(pathSegments.get(1));
                    if (size > 4) {
                        mStartMillis = Long.parseLong(pathSegments.get(3));
                        mEndMillis = Long.parseLong(pathSegments.get(4));
                    }
                } else {
                    mEventId = Long.parseLong(data.getLastPathSegment());
                }
            } catch (NumberFormatException e) {
                if (mEventId == -1) {
                // do nothing here , deal with it later
                } else if (mStartMillis == 0 || mEndMillis == 0) {
                    // Parsing failed on the start or end time , make sure the times were not
                    // pulled from the intent's extras and reset them.
                    mStartMillis = 0;
                    mEndMillis = 0;
                }
            }
        }
    }
    if (mEventId == -1) {
        Log.w(TAG, "No event id");
        Toast.makeText(this, R.string.event_not_found, Toast.LENGTH_SHORT).show();
        finish();
    }
    // If we do not support showing full screen event info in this configuration,
    // close the activity and show the event in AllInOne.
    Resources res = getResources();
    if (!res.getBoolean(R.bool.agenda_show_event_info_full_screen) && !res.getBoolean(R.bool.show_event_info_full_screen)) {
        CalendarController.getInstance(this).launchViewEvent(mEventId, mStartMillis, mEndMillis, attendeeResponse);
        finish();
        return;
    }
    setContentView(R.layout.simple_frame_layout);
    // Get the fragment if exists
    mInfoFragment = (EventInfoFragment) getFragmentManager().findFragmentById(R.id.main_frame);
    // Remove the application title
    ActionBar bar = getSupportActionBar();
    if (bar != null) {
        bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME);
    }
    // Create a new fragment if none exists
    if (mInfoFragment == null) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis, attendeeResponse, isDialog, (isDialog ? EventInfoFragment.DIALOG_WINDOW_STYLE : EventInfoFragment.FULL_WINDOW_STYLE), reminders);
        ft.replace(R.id.main_frame, mInfoFragment);
        ft.commit();
    }
}
Also used : ReminderEntry(com.android.calendar.CalendarEventModel.ReminderEntry) Intent(android.content.Intent) Uri(android.net.Uri) FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction) ArrayList(java.util.ArrayList) List(java.util.List) Resources(android.content.res.Resources) ActionBar(android.support.v7.app.ActionBar)

Aggregations

ReminderEntry (com.android.calendar.CalendarEventModel.ReminderEntry)9 ArrayList (java.util.ArrayList)4 ContentProviderOperation (android.content.ContentProviderOperation)3 ContentValues (android.content.ContentValues)3 Resources (android.content.res.Resources)2 Uri (android.net.Uri)2 LinearLayout (android.widget.LinearLayout)2 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 Intent (android.content.Intent)1 ActionBar (android.support.v7.app.ActionBar)1 SpannableString (android.text.SpannableString)1 Spinner (android.widget.Spinner)1 CalendarEventModel (com.android.calendar.CalendarEventModel)1 Attendee (com.android.calendar.CalendarEventModel.Attendee)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1