Example usage for java.util Calendar AM

List of usage examples for java.util Calendar AM

Introduction

In this page you can find the example usage for java.util Calendar AM.

Prototype

int AM

To view the source code for java.util Calendar AM.

Click Source Link

Document

Value of the #AM_PM field indicating the period of the day from midnight to just before noon.

Usage

From source file:org.kuali.kfs.pdp.businessobject.PaymentDetail.java

/**
 * Determines if the disbursement date is past the number of days old (configured in system parameter) in which actions can take
 * place//  ww  w.j  a  va  2s. c  o m
 * 
 * @return true if actions are allowed on disbursement, false otherwise
 */
public boolean isDisbursementActionAllowed() {
    if (paymentGroup.getDisbursementDate() == null) {
        if (PdpConstants.PaymentStatusCodes.EXTRACTED.equals(paymentGroup.getPaymentStatus().getCode())) {
            return false;
        }
        return true;
    }

    String daysStr = SpringContext.getBean(ParameterService.class).getParameterValueAsString(
            PaymentDetail.class, PdpParameterConstants.DISBURSEMENT_CANCELLATION_DAYS);
    int days = Integer.valueOf(daysStr);

    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, (days * -1));
    c.set(Calendar.HOUR, 12);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.AM_PM, Calendar.AM);
    Timestamp lastDisbursementActionDate = new Timestamp(c.getTimeInMillis());

    Calendar c2 = Calendar.getInstance();
    c2.setTime(paymentGroup.getDisbursementDate());
    c2.set(Calendar.HOUR, 11);
    c2.set(Calendar.MINUTE, 59);
    c2.set(Calendar.SECOND, 59);
    c2.set(Calendar.MILLISECOND, 59);
    c2.set(Calendar.AM_PM, Calendar.PM);
    Timestamp disbursementDate = new Timestamp(c2.getTimeInMillis());

    // date is equal to or after lastActionDate Allowed
    return ((disbursementDate.compareTo(lastDisbursementActionDate)) >= 0);
}

From source file:amhamogus.com.daysoff.fragments.AddEventFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_add_event, container, false);
    ButterKnife.bind(this, rootView);

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    addEventHeader.setText(calendarId);/*  ww w .j  a  v  a 2s  .c  o  m*/

    // Set default date and time values
    // based on the current time
    final Calendar currentDate = Calendar.getInstance();
    hour = currentDate.get(Calendar.HOUR);
    minute = currentDate.get(Calendar.MINUTE);
    amOrPm = currentDate.get(Calendar.AM_PM);

    if (amOrPm == Calendar.AM) {
        noonOrNight = "AM";
    } else {
        noonOrNight = "PM";
    }

    // By default, events are set to 30 minutes. Based on the
    // current minute value round to the next 30 minute set
    if (minute <= 29) {
        // Minute value is between 0 and 29.
        // Set the start time to half past.
        minute = 30;
        // Set end time to the the next hour.
        futureMinute = 0;
        // Set future hour to the next hour.
        if (hour > 12) {
            // The app tries to mange hours in 12 hour format
            // So hour values should not exceed 12. If hour does
            // exceed 12, we convert to 12 hour format.
            hour = hour - 12;
            futureHour = hour + 1;
        } else if (hour == 0) {
            // In 12 hour format. Convert 0 to 12.
            // Noon or midnight is set to '0' which is not
            // helpful for users, thus we change 0 to 12
            hour = 12;
            futureHour = 1;
        } else {
            //
            futureHour = hour + 1;
        }
    } else {
        // Current minute is between 30 and 60.
        // Round to the nearest hour.
        minute = 0;
        futureMinute = 30;

        if (hour > 12) {
            // The app tries to mange hours in 12 hour format
            // So hour values should not exceed 12. If hour does
            // exceed 12, we convert to 12 hour format.
            hour = hour - 12;
            futureHour = hour;
        } else if (hour == 0 || hour == 12) {
            // In 12 hour format. Convert 0 to 12.
            // Noon or midnight is set to '0' which is not
            // helpful for users, thus we change 0 to 12
            hour = 1;
            futureHour = 1;
        } else {
            hour = hour + 1;
            futureHour = hour;
        }
    }

    // Update form with default start and end time
    // for a new event.
    startTimeLabel.setText("" + hour + ":" + String.format("%02d", minute) + " " + noonOrNight);
    startTimeLabel.setOnClickListener(this);
    endTimeLabel.setText("" + futureHour + ":" + String.format("%02d", futureMinute) + " " + noonOrNight);
    endTimeLabel.setOnClickListener(this);

    // Add click listener to checkboxes
    food.setOnClickListener(this);
    movie.setOnClickListener(this);
    outdoors.setOnClickListener(this);

    return rootView;
}

From source file:org.sakaiproject.user.impl.PrecachingDbUserService.java

/** UVa SAK-1382: replace Aaron's init() code to schedule one task to run at the same time each day
 * add a 2nd task "onetimeTask" to run immediately."
 *//*from  w w w .  j a v  a 2  s .  c  o  m*/
public void init() {
    super.init();
    if (log.isDebugEnabled()) {
        log.debug(
                "init(): (grand-super) BaseUserDirectoryService includes this general cache just created in its code, m_callCache=="
                        + m_callCache);
        log.debug(
                "init(): (super) DbUserService includes this eid/id map, wired in user-components.xml, cache=="
                        + cache);
    }

    // LOAD the various sakai config options
    Boolean runOnStartup = serverConfigurationService().getBoolean("precache.users.run.startup", false);
    Boolean runDaily = serverConfigurationService().getBoolean("precache.users.run.daily", false);
    String cacheTimeString = serverConfigurationService().getString("precache.users.refresh.time", "04:00");
    this.siteUserIdsQuery = serverConfigurationService().getString("precache.users.userlist.query",
            this.siteUserIdsQuery);

    this.logUsersRemoved = serverConfigurationService().getBoolean("precache.users.log.usersRemoved",
            this.logUsersRemoved);
    this.logUsersNotRemoved = serverConfigurationService().getBoolean("precache.users.log.usersNotRemoved",
            this.logUsersNotRemoved);
    this.logUsersAccessed = serverConfigurationService().getBoolean("precache.users.log.usersAccessed",
            this.logUsersAccessed);
    this.logUsersNotAccessed = serverConfigurationService().getBoolean("precache.users.log.usersNotAccessed",
            this.logUsersNotAccessed);

    Calendar cal = Calendar.getInstance();

    if (runOnStartup) {
        log.info("init() scheduling user precache for startup run");
        // set up onetime task to run after short delay
        cal.setTime(new Date());
        cal.add(Calendar.MINUTE, 5);
        Date onetimeTaskStart = cal.getTime();
        onetimeTask = new UserCacheTimerTask();
        bootTimer.schedule(onetimeTask, onetimeTaskStart);
        log.info("User precache refresh onetime task scheduled to run in 5 minutes without repetition.");
    } else {
        log.info("User precache not scheduled for startup run");
    }

    if (runDaily) {
        // set up recurring task
        cal.setTime(new Date());
        cal.add(Calendar.DATE, 1); // start tomorrow
        long recurringTaskPeriod = 24l * 60l * 60l * 1000l;
        log.info("User precache will schedule recurring task every 24 hours, beginning tomorrow");

        try {
            String[] parts = cacheTimeString.trim().split(":");
            Integer hour = new Integer(parts[0]);
            if (hour < 12) {
                cal.set(Calendar.AM_PM, Calendar.AM);
            } else {
                cal.set(Calendar.AM_PM, Calendar.PM);
            }
            cal.set(Calendar.HOUR, hour);
            cal.set(Calendar.MINUTE, new Integer(parts[1]));
            Date recurringTaskStart = cal.getTime();
            scheduledTask = new UserCacheTimerTask();
            dailyTimer.scheduleAtFixedRate(scheduledTask, recurringTaskStart, recurringTaskPeriod);
            log.info("User precache scheduled for daily run at " + cacheTimeString);
        } catch (RuntimeException e) {
            log.error(
                    "User precache: Didn't schedule user cache refresh: Bad config?, it should be like: 'precache.users.refresh.time = 04:00' : "
                            + e.getMessage(),
                    e);
        }
    } else {
        log.info("User precache not scheduled for daily run");
    }
}

From source file:com.etime.ETimeUtils.java

/**
 * Parse a Punch from a given string. The format is assumed to be "12:00AM". All other calendar fields are set
 * to the current days value. The day, month, year, timezone and other misc fields are set to the current days value.
 *
 * @param punchStr The String to be parsed for the punch
 * @return the parsed Punch//ww  w.j av a2  s . c  o  m
 */
private static Punch getPunchFromString(String punchStr) {
    Punch punch = new Punch();
    Calendar calendar;
    Pattern punchPattern = Pattern.compile("(\\d+):(\\d+)(A|P)M");//Format is "12:00PM"
    Matcher punchMatcher = punchPattern.matcher(punchStr);

    if (!punchMatcher.find()) {
        return null;
    }

    int hour = Integer.parseInt(punchMatcher.group(1));
    int min = Integer.parseInt(punchMatcher.group(2));

    calendar = Calendar.getInstance();
    int hour24;
    if (punchMatcher.group(3).equals("A")) {
        calendar.set(Calendar.AM_PM, Calendar.AM);
        calendar.set(Calendar.HOUR, hour);
        if (hour == 12) {
            hour24 = 0;
        } else {
            hour24 = hour;
        }
    } else {
        calendar.set(Calendar.AM_PM, Calendar.PM);
        calendar.set(Calendar.HOUR, hour);

        if (hour != 12) {
            hour24 = hour + 12;
        } else {
            hour24 = hour;
        }
    }

    calendar.set(Calendar.HOUR_OF_DAY, hour24);
    calendar.set(Calendar.MINUTE, min);
    calendar.set(Calendar.SECOND, 0);
    punch.setCalendar(calendar);
    return punch;
}

From source file:org.kuali.coeus.sys.impl.scheduling.ScheduleServiceImpl.java

/**
 * This is helper method, wraps date with time accurately in java.util.Date (milliseconds).
 * //  www .ja  v a 2 s.c  om
 * @param date to be wrapped.
 * @param time to be added to date.
 * @return wrapped date &amp; time.
 */
protected Date wrapTime(Date date, Time24HrFmt time) {
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(date);
    int hour = calendar.get(Calendar.HOUR);
    int min = calendar.get(Calendar.MINUTE);
    int am_pm = calendar.get(Calendar.AM_PM);
    if (am_pm == Calendar.AM) {
        date = DateUtils.addHours(date, -hour);
        date = DateUtils.addMinutes(date, -min);
    } else {
        date = DateUtils.addHours(date, -hour - 12);
        date = DateUtils.addMinutes(date, -min);
    }
    if (null != time) {
        date = DateUtils.addHours(date, new Integer(time.getHours()));
        date = DateUtils.addMinutes(date, new Integer(time.getMinutes()));
    }
    return date;
}

From source file:com.versobit.weatherdoge.WeatherUtil.java

private static String convertYahooCode(String code, String weatherTime, String sunrise, String sunset) {
    Date weatherDate = new Date();
    try {//from w w  w.j a  v  a2s  .  co  m
        weatherDate = YAHOO_DATE_FORMAT.parse(weatherTime);
    } catch (ParseException ex) {
        Log.e(TAG, "Yahoo date format failed!", ex);
    }
    Calendar weatherCal = new GregorianCalendar();
    Calendar sunriseCal = new GregorianCalendar();
    Calendar sunsetCal = new GregorianCalendar();
    weatherCal.setTime(weatherDate);
    sunriseCal.setTime(weatherDate);
    sunsetCal.setTime(weatherDate);

    Matcher sunriseMatch = YAHOO_TIME.matcher(sunrise);
    Matcher sunsetMatch = YAHOO_TIME.matcher(sunset);
    if (!sunriseMatch.matches() || !sunsetMatch.matches()) {
        Log.e(TAG, "Failed to find sunrise/sunset. Using defaults.");
        sunriseMatch = YAHOO_TIME.matcher("6:00 am");
        sunsetMatch = YAHOO_TIME.matcher("6:00 pm");
        sunriseMatch.matches();
        sunsetMatch.matches();
    }
    // Set the sunrise to the correct hour and minute of the same day
    sunriseCal.set(Calendar.HOUR, Integer.parseInt(sunriseMatch.group(1)));
    sunriseCal.set(Calendar.MINUTE, Integer.parseInt(sunriseMatch.group(2)));
    sunriseCal.set(Calendar.SECOND, 0);
    sunriseCal.set(Calendar.MILLISECOND, 0);
    sunriseCal.set(Calendar.AM_PM, "am".equals(sunriseMatch.group(3)) ? Calendar.AM : Calendar.PM);

    // Set the sunset to the correct hour and minute of the same day
    sunsetCal.set(Calendar.HOUR, Integer.parseInt(sunsetMatch.group(1)));
    sunsetCal.set(Calendar.MINUTE, Integer.parseInt(sunsetMatch.group(2)));
    sunsetCal.set(Calendar.SECOND, 0);
    sunsetCal.set(Calendar.MILLISECOND, 0);
    sunsetCal.set(Calendar.AM_PM, "am".equals(sunsetMatch.group(3)) ? Calendar.AM : Calendar.PM);

    boolean isDaytime = true;
    if (weatherCal.before(sunriseCal) || weatherCal.after(sunsetCal)) {
        isDaytime = false;
    }

    String owmCode = "01";
    switch (Integer.parseInt(code)) {
    // Thunderstorms
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 17:
    case 37:
    case 38:
    case 39:
    case 45:
    case 47:
        owmCode = "11";
        break;
    // Snow
    case 5:
    case 7:
    case 13:
    case 14:
    case 15:
    case 16:
    case 18:
    case 41:
    case 42:
    case 43:
    case 46:
        owmCode = "13";
        break;
    // Rain
    case 6:
    case 10:
    case 35:
        owmCode = "09";
        break;
    // Light-ish Rain
    case 8:
    case 9:
    case 11:
    case 12:
    case 40:
        owmCode = "10";
        break;
    // Fog
    case 19:
    case 20:
    case 21:
    case 22:
        owmCode = "50";
        break;
    // Cloudy
    case 27:
    case 28:
        owmCode = "04";
        break;
    // (Other) Cloudy
    case 26:
        owmCode = "03";
        break;
    // Partly Cloudy
    case 23:
    case 24:
    case 25:
    case 29:
    case 30:
    case 44:
        owmCode = "02";
        break;
    // Clear
    case 31:
    case 32:
    case 33:
    case 34:
    case 36:
        owmCode = "01";
        break;
    }
    return owmCode + (isDaytime ? "d" : "n");
}

From source file:com.etime.ETimeActivity.java

/**
 * Update the curStatus button with most recent data from the users
 * time card./* w  ww .  jav  a2  s .  c o m*/
 */
private void updateCurStatusBtn() {
    StringBuilder sb = new StringBuilder("Clocked ");
    Punch lastPunch;
    Calendar lastPunchCalendar;
    int minute;

    if (punches.isEmpty()) {
        return;
    }

    lastPunch = punches.get(punches.size() - 1);
    if (lastPunch.isClockIn()) {
        sb.append("in ");
    } else {
        sb.append("out ");
    }

    sb.append("at ");
    lastPunchCalendar = lastPunch.getCalendar();
    sb.append(Integer.toString(getHourFromCalendar(lastPunchCalendar))).append(":");

    minute = lastPunch.getCalendar().get(Calendar.MINUTE);
    if (minute < 10) {
        sb.append("0");
    }
    sb.append(Integer.toString(minute));

    if (lastPunchCalendar.get(Calendar.AM_PM) == Calendar.AM) {
        sb.append(" AM");
    } else {
        sb.append(" PM");
    }

    curStatus.setText(sb.toString());
}

From source file:com.rockagen.commons.util.CommUtil.java

/**
 * Return the next day's date and time 00:00:00 start date
 *
 * @param date Date/*ww w.j  a v  a2  s .c  o  m*/
 * @return next day begin
 */
public static Date nextDayBegin(Date date) {
    Calendar cal = getCalendar(date);
    cal.add(Calendar.DATE, 1); // next day's am O0:00:00
    cal.set(Calendar.AM_PM, Calendar.AM);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    return cal.getTime();
}

From source file:com.rockagen.commons.util.CommUtil.java

/**
 * Return the next month's date and time 00:00:00 start date
 *
 * @param date Date//from  w  w w  .jav  a  2s .c  o  m
 * @return next month begin
 */
public static Date nextMonthBegin(Date date) {
    Calendar cal = getCalendar(date);
    cal.set(Calendar.DAY_OF_MONTH, 1); // next month's am O0:00:00
    cal.add(Calendar.MONTH, 1);

    cal.set(Calendar.AM_PM, Calendar.AM);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    return cal.getTime();
}

From source file:it.sasabz.android.sasabus.fragments.OnlineSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.inflater_glob = inflater;
    result = inflater.inflate(R.layout.online_search_layout, container, false);

    Date datum = new Date();
    SimpleDateFormat simple = new SimpleDateFormat("dd.MM.yyyy HH:mm");

    TextView datetime = (TextView) result.findViewById(R.id.time);
    String datetimestring = "";

    datetimestring = simple.format(datum);

    datetime.setText(datetimestring);/*  w w w . ja v  a 2s .  com*/

    Button search = (Button) result.findViewById(R.id.search);

    search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AutoCompleteTextView from = (AutoCompleteTextView) result.findViewById(R.id.from_text);
            AutoCompleteTextView to = (AutoCompleteTextView) result.findViewById(R.id.to_text);
            TextView datetime = (TextView) result.findViewById(R.id.time);

            String from_txt = getThis().getResources().getString(R.string.from_txt);

            if ((!from.getText().toString().trim().equals("")
                    || !from.getHint().toString().trim().equals(from_txt))
                    && !to.getText().toString().trim().equals("")) {
                //Intent getSelect = new Intent(getThis().getActivity(), OnlineSelectStopActivity.class);
                String fromtext = "";
                if (from.getText().toString().trim().equals(""))
                    fromtext = from.getHint().toString();
                else
                    fromtext = from.getText().toString();
                String totext = to.getText().toString();
                fromtext = "(" + fromtext.replace(" -", ")");
                totext = "(" + totext.replace(" -", ")");
                Fragment fragment = new OnlineSelectFragment(fromtext, totext, datetime.getText().toString());
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction ft = fragmentManager.beginTransaction();

                Fragment old = fragmentManager.findFragmentById(R.id.onlinefragment);
                if (old != null) {
                    ft.remove(old);
                }
                ft.add(R.id.onlinefragment, fragment);
                ft.addToBackStack(null);
                ft.commit();
                fragmentManager.executePendingTransactions();
            }
        }
    });

    datetime.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(getThis().getActivity());
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater_glob
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
                    .findViewById(R.id.DateTimePicker);
            TextView dt = (TextView) result.findViewById(R.id.time);
            String datetimestring = dt.getText().toString();

            SimpleDateFormat datetimeformat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
            Date datetime = null;
            try {
                datetime = datetimeformat.parse(datetimestring);
            } catch (Exception e) {
                ;
            }
            mDateTimePicker.updateTime(datetime.getHours(), datetime.getMinutes());
            mDateTimePicker.updateDate(datetime.getYear() + 1900, datetime.getMonth(), datetime.getDate());
            // Check is system is set to use 24h time (this doesn't seem to
            // work as expected though)
            final String timeS = android.provider.Settings.System.getString(
                    getThis().getActivity().getContentResolver(), android.provider.Settings.System.TIME_12_24);
            final boolean is24h = !(timeS == null || timeS.equals("12"));

            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();
                            String datetimestring = "";
                            int day = mDateTimePicker.get(Calendar.DAY_OF_MONTH);
                            int month = mDateTimePicker.get(Calendar.MONTH) + 1;
                            int year = mDateTimePicker.get(Calendar.YEAR);
                            int hour = 0;
                            int min = 0;
                            int append = 0;
                            if (mDateTimePicker.is24HourView()) {
                                hour = mDateTimePicker.get(Calendar.HOUR_OF_DAY);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                            } else {
                                hour = mDateTimePicker.get(Calendar.HOUR);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                                if (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM) {
                                    append = 1;
                                } else {
                                    append = 2;
                                }
                            }
                            if (day < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (day + ".");
                            if (month < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (month + "." + year + " ");
                            if (hour < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (hour + ":");
                            if (min < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += min;

                            switch (append) {
                            case 1:
                                datetimestring += " AM";
                                break;
                            case 2:
                                datetimestring += " PM";
                                break;
                            }

                            TextView time = (TextView) result.findViewById(R.id.time);
                            time.setText(datetimestring);
                            mDateTimeDialog.dismiss();
                        }
                    });
            // Cancel the dialog when the "Cancel" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is
            // clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            mDateTimePicker.setIs24HourView(is24h);
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();
        }

    });

    ImageButton datepicker = (ImageButton) result.findViewById(R.id.datepicker);

    datepicker.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(getThis().getActivity());
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) inflater_glob
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
                    .findViewById(R.id.DateTimePicker);
            TextView dt = (TextView) result.findViewById(R.id.time);
            String datetimestring = dt.getText().toString();
            SimpleDateFormat datetimeformat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
            Date datetime = null;
            try {
                datetime = datetimeformat.parse(datetimestring);
            } catch (Exception e) {
                ;
            }
            mDateTimePicker.updateTime(datetime.getHours(), datetime.getMinutes());
            mDateTimePicker.updateDate(datetime.getYear() + 1900, datetime.getMonth(), datetime.getDate());
            // Check is system is set to use 24h time (this doesn't seem to
            // work as expected though)
            final String timeS = android.provider.Settings.System.getString(
                    getThis().getActivity().getContentResolver(), android.provider.Settings.System.TIME_12_24);
            final boolean is24h = !(timeS == null || timeS.equals("12"));

            // Update demo TextViews when the "OK" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();
                            String datetimestring = "";
                            int day = mDateTimePicker.get(Calendar.DAY_OF_MONTH);
                            int month = mDateTimePicker.get(Calendar.MONTH) + 1;
                            int year = mDateTimePicker.get(Calendar.YEAR);
                            int hour = 0;
                            int min = 0;
                            int append = 0;
                            if (mDateTimePicker.is24HourView()) {
                                hour = mDateTimePicker.get(Calendar.HOUR_OF_DAY);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                            } else {
                                hour = mDateTimePicker.get(Calendar.HOUR);
                                min = mDateTimePicker.get(Calendar.MINUTE);
                                if (mDateTimePicker.get(Calendar.AM_PM) == Calendar.AM) {
                                    append = 1;
                                } else {
                                    append = 2;
                                }
                            }
                            if (day < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (day + ".");
                            if (month < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (month + "." + year + " ");
                            if (hour < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += (hour + ":");
                            if (min < 10) {
                                datetimestring += "0";
                            }
                            datetimestring += min;

                            switch (append) {
                            case 1:
                                datetimestring += " AM";
                                break;
                            case 2:
                                datetimestring += " PM";
                                break;
                            }

                            TextView time = (TextView) result.findViewById(R.id.time);
                            time.setText(datetimestring);
                            mDateTimeDialog.dismiss();
                        }
                    });
            // Cancel the dialog when the "Cancel" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is
            // clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new View.OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            mDateTimePicker.setIs24HourView(is24h);
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();
        }

    });
    from = (AutoCompleteTextView) result.findViewById(R.id.from_text);
    to = (AutoCompleteTextView) result.findViewById(R.id.to_text);

    from.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            InputMethodManager mgr = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.hideSoftInputFromWindow(from.getWindowToken(), 0);
        }
    });

    to.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            InputMethodManager mgr = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            mgr.hideSoftInputFromWindow(to.getWindowToken(), 0);
        }
    });

    LocationManager locman = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE);
    Location lastloc = locman.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (MySQLiteDBAdapter.exists(this.getActivity())) {
        if (lastloc == null) {
            lastloc = locman.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        }
        if (lastloc != null) {
            try {
                Palina palina = PalinaList.getPalinaGPS(lastloc);
                if (palina != null) {
                    from.setHint(palina.toString());
                }
            } catch (Exception e) {
                Log.e("HomeActivity", "Fehler bei der Location", e);
            }
        } else {
            Log.v("HomeActivity", "No location found!!");
        }
        Vector<DBObject> palinalist = PalinaList.getNameList();
        MyAutocompleteAdapter adapterfrom = new MyAutocompleteAdapter(this.getActivity(),
                android.R.layout.simple_list_item_1, palinalist);
        MyAutocompleteAdapter adapterto = new MyAutocompleteAdapter(this.getActivity(),
                android.R.layout.simple_list_item_1, palinalist);

        from.setAdapter(adapterfrom);
        to.setAdapter(adapterto);
        InputMethodManager mgr = (InputMethodManager) getActivity()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromWindow(from.getWindowToken(), 0);
        mgr.hideSoftInputFromWindow(to.getWindowToken(), 0);
    }
    Button favorites = (Button) result.findViewById(R.id.favorites);
    favorites.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            SelectFavoritenDialog dialog = new SelectFavoritenDialog(getThis());
            dialog.show();
        }
    });

    Button mappicker = (Button) result.findViewById(R.id.map);
    mappicker.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), MapSelectActivity.class);
            startActivityForResult(intent, REQUESTCODE_ACTIVITY);
        }
    });
    return result;
}