Search in sources :

Example 31 with DateFormatSymbols

use of java.text.DateFormatSymbols in project underlx by underlx.

the class EditNotifScheduleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        ruleId = getIntent().getStringExtra(EXTRA_RULE_ID);
    } else {
        ruleId = savedInstanceState.getString(STATE_RULE_ID);
    }
    setContentView(R.layout.activity_edit_notif_schedule);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    realm = Application.getDefaultRealmInstance(this);
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(final Realm realm) {
            if (ruleId == null) {
                rule = realm.createObject(NotificationRule.class, UUID.randomUUID().toString());
            } else {
                rule = realm.where(NotificationRule.class).equalTo("id", ruleId).findFirst();
                if (rule == null) {
                    finish();
                    return;
                }
            }
            ruleId = rule.getId();
            List<Map<String, String>> data = new ArrayList<>();
            weekDaysItem = new HashMap<>(3);
            weekDaysItem.put("title", getString(R.string.act_edit_notif_schedule_days));
            weekDaysItem.put("desc", "");
            data.add(weekDaysItem);
            startTimeItem = new HashMap<>(3);
            startTimeItem.put("title", getString(R.string.act_edit_notif_schedule_start_time));
            startTimeItem.put("desc", "");
            data.add(startTimeItem);
            endTimeItem = new HashMap<>(3);
            endTimeItem.put("title", getString(R.string.act_edit_notif_schedule_end_time));
            endTimeItem.put("desc", "");
            data.add(endTimeItem);
            listView = (ListView) findViewById(R.id.list_view);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    if (position == 0) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(EditNotifScheduleActivity.this);
                        DateFormatSymbols symbols = new DateFormatSymbols();
                        String[] dayNames = Arrays.copyOfRange(symbols.getWeekdays(), 1, 8);
                        final boolean[] checkedDays = new boolean[7];
                        for (int day : rule.getWeekDays()) {
                            checkedDays[day - 1] = true;
                        }
                        builder.setMultiChoiceItems(dayNames, checkedDays, new DialogInterface.OnMultiChoiceClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                checkedDays[which] = isChecked;
                            }
                        });
                        builder.setTitle(getString(R.string.act_edit_notif_schedule_days));
                        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                realm.executeTransaction(new Realm.Transaction() {

                                    @Override
                                    public void execute(Realm realm) {
                                        RealmList<Integer> days = rule.getWeekDays();
                                        days.clear();
                                        for (int i = 0; i < 7; i++) {
                                            if (checkedDays[i]) {
                                                days.add(i + 1);
                                            }
                                        }
                                    }
                                });
                                updateUI();
                            }
                        });
                        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        });
                        builder.create().show();
                    } else if (position == 1) {
                        RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment().setOnTimeSetListener(EditNotifScheduleActivity.this).setStartTime((int) TimeUnit.MILLISECONDS.toHours(rule.getStartTime()) % 24, (int) TimeUnit.MILLISECONDS.toMinutes(rule.getStartTime()) % 60).setDoneText(getString(android.R.string.ok)).setCancelText(getString(android.R.string.cancel)).setThemeDark();
                        rtpd.show(getSupportFragmentManager(), TAG_START_TIME_PICKER);
                    } else if (position == 2) {
                        RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment().setOnTimeSetListener(EditNotifScheduleActivity.this).setStartTime((int) TimeUnit.MILLISECONDS.toHours(rule.getEndTime()) % 24, (int) TimeUnit.MILLISECONDS.toMinutes(rule.getEndTime()) % 60).setDoneText(getString(android.R.string.ok)).setCancelText(getString(android.R.string.cancel)).setThemeDark();
                        rtpd.show(getSupportFragmentManager(), TAG_END_TIME_PICKER);
                    }
                }
            });
            adapter = new SimpleAdapter(EditNotifScheduleActivity.this, data, android.R.layout.simple_list_item_2, new String[] { "title", "desc" }, new int[] { android.R.id.text1, android.R.id.text2 });
            listView.setAdapter(adapter);
            updateUI();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) ListView(android.widget.ListView) RealmList(io.realm.RealmList) ArrayList(java.util.ArrayList) List(java.util.List) Realm(io.realm.Realm) Toolbar(android.support.v7.widget.Toolbar) SimpleAdapter(android.widget.SimpleAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) DateFormatSymbols(java.text.DateFormatSymbols) RadialTimePickerDialogFragment(com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment)

Example 32 with DateFormatSymbols

use of java.text.DateFormatSymbols in project evosuite by EvoSuite.

the class SimpleDateFormat method getDateFormatSymbols.

public DateFormatSymbols getDateFormatSymbols() {
    Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_TEXT_SIMPLEDATEFORMAT, this, "getDateFormatSymbols", "()Ljava/text/DateFormatSymbols;", new Object[] {});
    DateFormatSymbols ret = super.getDateFormatSymbols();
    Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_TEXT_SIMPLEDATEFORMAT, this, ret);
    return ret;
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols)

Example 33 with DateFormatSymbols

use of java.text.DateFormatSymbols in project BroadleafCommerce by BroadleafCommerce.

the class BLCPaymentMethodUtils method getExpirationMonthOptions.

/**
 * A helper method used to construct a list of Credit Card Expiration Months
 * Useful for expiration dropdown menus.
 * Will use locale to determine language if a locale is available.
 *
 * @return List containing expiration months of the form "01 - January"
 */
public static List<String> getExpirationMonthOptions() {
    DateFormatSymbols dateFormatter;
    if (BroadleafRequestContext.hasLocale()) {
        Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getJavaLocale();
        dateFormatter = new DateFormatSymbols(locale);
    } else {
        dateFormatter = new DateFormatSymbols();
    }
    List<String> expirationMonths = new ArrayList<>();
    NumberFormat formatter = new DecimalFormat("00");
    String[] months = dateFormatter.getMonths();
    for (int i = 1; i < months.length; i++) {
        expirationMonths.add(formatter.format(i) + " - " + months[i - 1]);
    }
    return expirationMonths;
}
Also used : Locale(java.util.Locale) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) DateFormatSymbols(java.text.DateFormatSymbols) NumberFormat(java.text.NumberFormat)

Example 34 with DateFormatSymbols

use of java.text.DateFormatSymbols in project BroadleafCommerce by BroadleafCommerce.

the class FormBuilderServiceImpl method createListGrid.

/**
 * Populate a ListGrid with ListGridRecords.
 *
 * @param className
 * @param headerFields
 * @param type
 * @param drs
 * @param sectionKey
 * @param order
 * @param idProperty
 * @param sectionCrumbs
 * @param sortPropery
 * @return
 */
protected ListGrid createListGrid(String className, List<Field> headerFields, ListGrid.Type type, DynamicResultSet drs, String sectionKey, Integer order, String idProperty, List<SectionCrumb> sectionCrumbs, String sortPropery) {
    // Create the list grid and set some basic attributes
    ListGrid listGrid = new ListGrid();
    listGrid.setClassName(className);
    listGrid.getHeaderFields().addAll(headerFields);
    listGrid.setListGridType(type);
    listGrid.setSectionCrumbs(sectionCrumbs);
    listGrid.setSectionKey(sectionKey);
    listGrid.setOrder(order);
    listGrid.setIdProperty(idProperty);
    listGrid.setStartIndex(drs.getStartIndex());
    listGrid.setTotalRecords(drs.getTotalRecords());
    listGrid.setPageSize(drs.getPageSize());
    String sectionIdentifier = extractSectionIdentifierFromCrumb(sectionCrumbs);
    AdminSection section = navigationService.findAdminSectionByClassAndSectionId(className, sectionIdentifier);
    if (section != null) {
        listGrid.setExternalEntitySectionKey(section.getUrl());
    }
    // format date list grid cells
    SimpleDateFormat formatter = new SimpleDateFormat("MMM d, Y @ hh:mma");
    DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
    symbols.setAmPmStrings(new String[] { "am", "pm" });
    formatter.setDateFormatSymbols(symbols);
    // that are used for the header fields.
    for (Entity e : drs.getRecords()) {
        ListGridRecord record = new ListGridRecord();
        record.setListGrid(listGrid);
        record.setDirty(e.isDirty());
        record.setEntity(e);
        if (StringUtils.isNotBlank(sortPropery) && e.findProperty(sortPropery) != null) {
            Property sort = e.findProperty(sortPropery);
            record.setDisplayOrder(sort.getValue());
        }
        if (e.findProperty("hasError") != null) {
            Boolean hasError = Boolean.parseBoolean(e.findProperty("hasError").getValue());
            record.setIsError(hasError);
            if (hasError) {
                ExtensionResultStatusType messageResultStatus = listGridErrorExtensionManager.getProxy().determineErrorMessageForEntity(e, record);
                if (ExtensionResultStatusType.NOT_HANDLED.equals(messageResultStatus)) {
                    record.setErrorKey("listgrid.record.error");
                }
            }
        }
        if (e.findProperty("progressStatus") != null) {
            ExtensionResultStatusType messageResultStatus = listGridErrorExtensionManager.getProxy().determineStatusMessageForEntity(e, record);
            if (ExtensionResultStatusType.NOT_HANDLED.equals(messageResultStatus)) {
                record.setStatus(e.findProperty("progressStatus").getValue());
                record.setStatusCssClass("listgrid.record.status");
            }
        }
        if (e.findProperty(idProperty) != null) {
            record.setId(e.findProperty(idProperty).getValue());
        }
        for (Field headerField : headerFields) {
            Property p = e.findProperty(headerField.getName());
            if (p != null) {
                Field recordField = new Field().withName(headerField.getName()).withFriendlyName(headerField.getFriendlyName()).withOrder(p.getMetadata().getOrder());
                if (headerField instanceof ComboField) {
                    recordField.setValue(((ComboField) headerField).getOption(p.getValue()));
                    recordField.setDisplayValue(p.getDisplayValue());
                } else {
                    if (headerField.getFieldType().equals("DATE")) {
                        try {
                            Date date = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").parse(p.getValue());
                            String newValue = formatter.format(date);
                            recordField.setValue(newValue);
                        } catch (Exception ex) {
                            recordField.setValue(p.getValue());
                        }
                    } else {
                        recordField.setValue(p.getValue());
                    }
                    recordField.setDisplayValue(p.getDisplayValue());
                }
                recordField.setDerived(isDerivedField(headerField, recordField, p));
                record.getFields().add(recordField);
            }
        }
        if (e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY) != null) {
            Field hiddenField = new Field().withName(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
            hiddenField.setValue(e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY).getValue());
            record.getHiddenFields().add(hiddenField);
        }
        if (e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY) != null) {
            record.setAltId(e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY).getValue());
        }
        extensionManager.getProxy().modifyListGridRecord(className, record, e);
        listGrid.getRecords().add(record);
    }
    if (drs.getFirstId() != null) {
        listGrid.setFirstId(drs.getFirstId());
    }
    if (drs.getLastId() != null) {
        listGrid.setLastId(drs.getLastId());
    }
    if (drs.getUpperCount() != null) {
        listGrid.setUpperCount(drs.getUpperCount());
    }
    if (drs.getLowerCount() != null) {
        listGrid.setLowerCount(drs.getLowerCount());
    }
    if (drs.getFetchType() != null) {
        listGrid.setFetchType(drs.getFetchType().toString());
    }
    if (drs.getTotalCountLessThanPageSize() != null) {
        listGrid.setTotalCountLessThanPageSize(drs.getTotalCountLessThanPageSize());
    }
    if (drs.getPromptSearch() != null) {
        listGrid.setPromptSearch(drs.getPromptSearch());
    }
    return listGrid;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) ListGridRecord(org.broadleafcommerce.openadmin.web.form.component.ListGridRecord) AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) Date(java.util.Date) ServiceException(org.broadleafcommerce.common.exception.ServiceException) IOException(java.io.IOException) NoSuchMessageException(org.springframework.context.NoSuchMessageException) ParseException(java.text.ParseException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 35 with DateFormatSymbols

use of java.text.DateFormatSymbols in project onebusaway-application-modules by camsys.

the class ScheduleAction method getShortWeekDays.

public List<String> getShortWeekDays() {
    List<String> result = new ArrayList<String>();
    DateFormatSymbols dateFormatSymbols = new DateFormatSymbols(getLocale());
    String[] shortWeekdays = dateFormatSymbols.getShortWeekdays();
    Calendar calendar = Calendar.getInstance(getLocale());
    int firstDayOfWeek = calendar.getFirstDayOfWeek();
    for (int dayOfWeek = firstDayOfWeek; dayOfWeek < shortWeekdays.length; dayOfWeek++) {
        result.add(shortWeekdays[dayOfWeek]);
    }
    for (int dayOfWeek = Calendar.SUNDAY; dayOfWeek < firstDayOfWeek; dayOfWeek++) {
        result.add(shortWeekdays[dayOfWeek]);
    }
    return result;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) DateFormatSymbols(java.text.DateFormatSymbols)

Aggregations

DateFormatSymbols (java.text.DateFormatSymbols)140 SimpleDateFormat (java.text.SimpleDateFormat)38 Date (java.util.Date)26 ArrayList (java.util.ArrayList)23 Locale (java.util.Locale)21 Resources (android.content.res.Resources)15 View (android.view.View)14 TextView (android.widget.TextView)12 Calendar (java.util.Calendar)10 GregorianCalendar (java.util.GregorianCalendar)9 List (java.util.List)8 OnClickListener (android.view.View.OnClickListener)7 Test (org.junit.Test)7 Typeface (android.graphics.Typeface)6 RelativeLayout (android.widget.RelativeLayout)6 LayoutParams (android.app.ActionBar.LayoutParams)5 IOException (java.io.IOException)5 TypedArray (android.content.res.TypedArray)4 AdapterView (android.widget.AdapterView)4 Button (android.widget.Button)4