Example usage for android.app DatePickerDialog DatePickerDialog

List of usage examples for android.app DatePickerDialog DatePickerDialog

Introduction

In this page you can find the example usage for android.app DatePickerDialog DatePickerDialog.

Prototype

public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month,
        int dayOfMonth) 

Source Link

Document

Creates a new date picker dialog for the specified date using the parent context's default date picker dialog theme.

Usage

From source file:cn.count.easydrive366.DriverLicenseEditActivity.java

private void chooseDate() {
    String d = ((TextView) findViewById(R.id.edt_driverlicense_init_date)).getText().toString();
    if (d.equals("")) {
        d = "1990-01-01";
    }/*from w  w w . j  a  v  a  2s  . c om*/
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    final Calendar c = Calendar.getInstance();

    try {
        c.setTime(sdf.parse(d));

        Dialog dialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                c.set(Calendar.YEAR, year);
                c.set(Calendar.MONTH, monthOfYear);
                c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                //showDialog(sdf.format(c.getTime()));
                ((TextView) findViewById(R.id.edt_driverlicense_init_date)).setText(sdf.format(c.getTime()));
            }
        }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
        dialog.show();
    } catch (Exception e) {
        log(e);
    }

}

From source file:in.andres.kandroid.ui.TaskEditActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_edit);
    setupActionBar();//w  w  w  .  jav  a  2 s  .c o m

    editTextTitle = (EditText) findViewById(R.id.edit_task_title);
    editTextDescription = (EditText) findViewById(R.id.edit_task_description);
    btnStartDate = (Button) findViewById(R.id.btn_start_date);
    btnDueDate = (Button) findViewById(R.id.btn_due_date);
    btnColor = (Button) findViewById(R.id.color_button);
    btnColor.setOnClickListener(btnColorClick);
    btnColor.setText(Utils.fromHtml(getString(R.string.taskedit_color, "")));
    editHoursEstimated = (EditText) findViewById(R.id.edit_hours_estimated);
    editHoursSpent = (EditText) findViewById(R.id.edit_hours_spent);
    spinnerProjectUsers = (Spinner) findViewById(R.id.user_spinner);

    if (getIntent().hasExtra("task")) {
        isNewTask = false;
        task = (KanboardTask) getIntent().getSerializableExtra("task");
        taskTitle = task.getTitle();
        taskDescription = task.getDescription();
        startDate = task.getDateStarted();
        dueDate = task.getDateDue();
        timeEstimated = task.getTimeEstimated();
        timeSpent = task.getTimeSpent();
        ownerId = task.getOwnerId();
        colorId = task.getColorId();
        setActionBarTitle(getString(R.string.taskview_fab_edit_task));
    } else {
        isNewTask = true;
        projectid = getIntent().getIntExtra("projectid", 0);
        //            colorId = getIntent().getIntExtra("colorid", 0);
        creatorId = getIntent().getIntExtra("creatorid", 0);
        ownerId = getIntent().getIntExtra("ownerid", 0);
        columnId = getIntent().getIntExtra("columnid", 0);
        swimlaneId = getIntent().getIntExtra("swimlaneid", 0);
        setActionBarTitle(getString(R.string.taskedit_new_task));
    }

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext());
    try {
        kanboardAPI = new KanboardAPI(preferences.getString("serverurl", ""),
                preferences.getString("username", ""), preferences.getString("password", ""));
        kanboardAPI.addOnCreateTaskListener(this);
        kanboardAPI.addOnUpdateTaskListener(this);
        kanboardAPI.addOnGetDefaultColorListener(this);
        kanboardAPI.addOnGetDefaultColorsListener(this);
        kanboardAPI.addOnGetVersionListener(this);
        kanboardAPI.getDefaultTaskColor();
        kanboardAPI.getDefaultTaskColors();
        kanboardAPI.getVersion();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (getIntent().hasExtra("projectusers")) {
        if (getIntent().getSerializableExtra("projectusers") instanceof HashMap) {
            projectUsers = new Hashtable<>(
                    (HashMap<Integer, String>) getIntent().getSerializableExtra("projectusers"));
            ArrayList<String> possibleOwners = Collections.list(projectUsers.elements());
            possibleOwners.add(0, "");
            ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
                    possibleOwners);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinnerProjectUsers.setAdapter(adapter);
            if (ownerId != 0) {
                spinnerProjectUsers.setSelection(possibleOwners.indexOf(projectUsers.get(ownerId)));
            }
        }
    }

    editTextTitle.setText(taskTitle);
    editTextDescription.setText(taskDescription);
    editHoursEstimated.setText(Double.toString(timeEstimated));
    editHoursSpent.setText(Double.toString(timeSpent));
    btnStartDate.setText(Utils.fromHtml(getString(R.string.taskview_date_start, startDate)));
    btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate)));

    btnStartDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            if (startDate != null)
                calendar.setTime(startDate);

            DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                            Calendar calendar = Calendar.getInstance();
                            calendar.set(Calendar.YEAR, year);
                            calendar.set(Calendar.MONTH, month);
                            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                            startDate = calendar.getTime();
                            btnStartDate.setText(
                                    Utils.fromHtml(getString(R.string.taskview_date_start, startDate)));
                        }
                    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            startDate = null;
                            btnStartDate.setText(
                                    Utils.fromHtml(getString(R.string.taskview_date_start, startDate)));
                        }
                    });
            dlgDate.show();
        }
    });
    btnDueDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            if (dueDate != null)
                calendar.setTime(dueDate);

            DatePickerDialog dlgDate = new DatePickerDialog(TaskEditActivity.this,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                            Calendar calendar = Calendar.getInstance();
                            calendar.set(Calendar.YEAR, year);
                            calendar.set(Calendar.MONTH, month);
                            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                            dueDate = calendar.getTime();
                            btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate)));
                        }
                    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                    calendar.get(Calendar.DAY_OF_MONTH));
            dlgDate.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.taskedit_clear_date),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dueDate = null;
                            btnDueDate.setText(Utils.fromHtml(getString(R.string.taskview_date_due, dueDate)));
                        }
                    });
            dlgDate.show();
        }
    });
}

From source file:com.itime.team.itime.fragments.MeetingSubPreferenceFragment.java

@Override
public void onClick(View v) {
    final int id = v.getId();
    switch (id) {
    case R.id.setting_meeting_start_date: {
        final Calendar cal = Calendar.getInstance();
        DatePickerDialog datePicker = new DatePickerDialog(getContext(),
                new DatePickerDialog.OnDateSetListener() {
                    @Override// w  w  w  .  j a v  a2 s  .c  om
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        mStartsDate.setText(String.format("%d/%d/%d", dayOfMonth, monthOfYear + 1, year));
                        mStartsDateCalendar.set(year, monthOfYear, dayOfMonth);
                    }
                }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
        datePicker.show();
        break;
    }
    case R.id.setting_meeting_start_time:
    case R.id.setting_meeting_end_time: {
        final Calendar cal = Calendar.getInstance();
        TimePickerDialog timePicker = new TimePickerDialog(getContext(),
                new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        TextView time = id == R.id.setting_meeting_start_time ? mStartsTime : mEndsTime;

                        if (id == R.id.setting_meeting_start_time) {
                            mStartsTimeHour = hourOfDay;
                            mStartsTimeMinute = minute;
                        } else {
                            mEndsTimeHour = hourOfDay;
                            mEndsTimeMinute = minute;
                        }

                        time.setText(hourOfDay + ":" + minute);
                    }
                }, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), false);
        timePicker.show();
        break;
    }
    case R.id.setting_meeting_repeat: {
        Intent intent = new Intent(getActivity(), SettingsActivity.class);
        intent.putExtra("Settings", 6);
        startActivityForResult(intent, REPEAT_SETTINGS);

        break;
    }
    case R.id.setting_meeting_type: {
        String text = isPrefer ? Type.UNAVAILABLE.getText() : Type.PREFER.getText();
        isPrefer = !isPrefer;
        mType.setText(text);
        mParcelablePreference.preferenceType = text;
        break;
    }
    }
}

From source file:tinygsn.gui.android.ActivityViewData.java

private void addTableViewModeCustomize() {
    table_view_mode = (TableLayout) findViewById(R.id.table_view_mode);
    table_view_mode.removeAllViews();/* ww  w  . j  a  v  a 2  s  . com*/

    // Row From
    TableRow row = new TableRow(this);
    TextView txt = new TextView(this);
    txt.setText("From: ");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    //      Date time = new Date();
    startTime = new Date();
    startTime.setMinutes(startTime.getMinutes() - 1);
    endTime = new Date();

    // Start Time
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
    txtStartTime = new TextView(this);
    txtStartTime.setText(formatter.format(startTime) + "");
    txtStartTime.setTextColor(Color.parseColor("#000000"));
    txtStartTime.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtStartTime);

    txtStartTime.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new TimePickerDialog(context, startTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY) - 1,
                    dateAndTime.get(Calendar.MINUTE), true).show();
        }
    });

    // Add space
    txt = new TextView(this);
    txt.setText("     ");
    row.addView(txt);

    // Start Date
    formatter = new SimpleDateFormat("dd/MM/yyyy");
    // txtStartDate, txtStartTime
    txtStartDate = new TextView(this);
    txtStartDate.setText(formatter.format(startTime) + "");
    txtStartDate.setTextColor(Color.parseColor("#000000"));
    txtStartDate.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtStartDate);

    txtStartDate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new DatePickerDialog(context, startDateSetListener, dateAndTime.get(Calendar.YEAR),
                    dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

    table_view_mode.addView(row);

    // Add a space row
    row = new TableRow(this);
    txt = new TextView(this);
    txt.setText("-");
    row.addView(txt);
    table_view_mode.addView(row);

    // Row To
    row = new TableRow(this);
    txt = new TextView(this);
    txt.setText("To");
    txt.setTextColor(Color.parseColor("#000000"));
    row.addView(txt);

    // End Time
    formatter = new SimpleDateFormat("HH:mm:ss");
    txtEndTime = new TextView(this);
    txtEndTime.setText(formatter.format(endTime) + "");
    txtEndTime.setTextColor(Color.parseColor("#000000"));
    txtEndTime.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtEndTime);

    txtEndTime.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new TimePickerDialog(context, endTimeSetListener, dateAndTime.get(Calendar.HOUR_OF_DAY),
                    dateAndTime.get(Calendar.MINUTE), true).show();
        }
    });

    // Add space
    txt = new TextView(this);
    txt.setText("     ");
    row.addView(txt);

    // End Date
    formatter = new SimpleDateFormat("dd/MM/yyyy");
    // txtStartDate, txtStartTime
    txtEndDate = new TextView(this);
    txtEndDate.setText(formatter.format(endTime) + "");
    txtEndDate.setTextColor(Color.parseColor("#000000"));
    txtEndDate.setBackgroundColor(Color.parseColor("#61a7db"));
    row.addView(txtEndDate);

    txtEndDate.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new DatePickerDialog(context, endDateSetListener, dateAndTime.get(Calendar.YEAR),
                    dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
        }
    });

    table_view_mode.addView(row);

    // Row
    row = new TableRow(this);
    Button detailBtn = new Button(this);
    detailBtn.setTextSize(TEXT_SIZE + 4);
    detailBtn.setText("Detail");
    detailBtn.setTextColor(Color.parseColor("#000000"));
    detailBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });

    Button plotDataBtn = new Button(this);
    plotDataBtn.setTextSize(TEXT_SIZE + 4);
    plotDataBtn.setText("Plot data");
    plotDataBtn.setTextColor(Color.parseColor("#000000"));
    plotDataBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewChart();
        }
    });

    TableRow.LayoutParams params = new TableRow.LayoutParams();
    // params.addRule(TableRow.LayoutParams.FILL_PARENT);
    params.span = 2;

    row.addView(detailBtn, params);
    row.addView(plotDataBtn, params);
    row.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    table_view_mode.addView(row);

}

From source file:org.egov.android.view.activity.EditProfileActivity.java

/**
 * Function used to choose the user dob/*w  w w .  ja  va2 s  .c  o  m*/
 */
@SuppressLint("NewApi")
private void _showDatePicker() {
    DatePickerDialog datePicker = null;
    Calendar c = Calendar.getInstance();
    int year = 0;
    int month = 0;
    int date = 0;
    if (dateOfBirth.equals("")) {
        year = c.get(Calendar.YEAR);
        month = c.get(Calendar.MONTH);
        date = c.get(Calendar.DAY_OF_MONTH);
        datePicker = new DatePickerDialog(this, datepicker, year, month, date);
    } else {
        String[] birth = dateOfBirth.split("-");
        year = Integer.valueOf(birth[0]);
        month = Integer.valueOf(birth[1]) - 1;
        date = Integer.valueOf(birth[2]);
        datePicker = new DatePickerDialog(this, datepicker, date, month, year);
    }

    if (apiLevel > 13) {
        datePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
    }
    datePicker.show();
}

From source file:com.spacejake.jake.ultimatepurduediner.NavigationDrawerFragment.java

public void showDatePicker() {
    new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override//from  ww w. j ava  2 s .c  o  m
        public void onDateSet(DatePicker datePicker, int year, int month, int day) {
            if (!dateSet) {
                Calendar cal = Calendar.getInstance();
                ((MainActivity) getActivity()).dateChange(year, month, day);
                if (datePicker.getDayOfMonth() == cal.get(Calendar.DAY_OF_MONTH)
                        && datePicker.getYear() == cal.get(Calendar.YEAR)) {
                    datePickerButton.setTitle("Today");
                } else {
                    DateFormatSymbols dfs = new DateFormatSymbols(new Locale("en"));
                    cal.set(year, month, day);
                    datePickerButton.setTitle(String.format("%s, %d/%d/%d",
                            dfs.getShortWeekdays()[cal.get(Calendar.DAY_OF_WEEK)], month + 1, day, year));
                }
                dateSet = true;
            } else {
                dateSet = false;
            }
        }
    }, year, month, day).show();
}

From source file:com.flowzr.activity.RecurActivity.java

private void addLayouts(LayoutInflater inflater, LinearLayout layout, Layoutable[] items) {
    for (Layoutable i : items) {
        int layoutId = i.getLayoutId();
        if (layoutId != 0) {
            final View v = inflater.inflate(layoutId, null);
            v.setTag(i);//w w  w .ja v a2  s .  c  om
            v.setVisibility(View.INVISIBLE);
            if (i == RecurPeriod.STOPS_ON_DATE) {
                Button b = (Button) v.findViewById(R.id.bStopsOnDate);
                final Calendar c = this.stopsOnDate;
                editStopsOnDate(v, c.getTimeInMillis());
                b.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(final View view) {
                        DatePickerDialog d = new DatePickerDialog(RecurActivity.this,
                                new DatePickerDialog.OnDateSetListener() {
                                    @Override
                                    public void onDateSet(DatePicker view, int year, int monthOfYear,
                                            int dayOfMonth) {
                                        c.set(Calendar.YEAR, year);
                                        c.set(Calendar.MONTH, monthOfYear);
                                        c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                                        DateUtils.endOfDay(c);
                                        editStopsOnDate(v, c.getTimeInMillis());
                                    }
                                }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
                        d.show();
                    }
                });
            }
            layout.addView(v, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        }
    }
}

From source file:com.dsi.ant.antplus.pluginsampler.geocache.Dialog_GeoProgramDevice.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle("Program Device " + deviceData.deviceId);
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View detailsView = inflater.inflate(R.layout.dialog_geocache_programdevice, null);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(detailsView);//from w w  w  . j ava 2  s. co  m

    // Add action buttons
    //Note we override the positive button in show() below so we can prevent it from closing
    builder.setPositiveButton("Begin Programing", null);
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //Let dialog dismiss
        }
    });

    checkBox_EnableIdString = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableIdentifcationString);
    checkBox_EnablePIN = (CheckBox) detailsView.findViewById(R.id.checkBox_EnablePIN);
    checkBox_EnableLatitude = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLatitude);
    checkBox_EnableLongitude = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLongitude);
    checkBox_EnableHintString = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableHintString);
    checkBox_EnableLastVisit = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLastVisitInfo);

    final TextView textView_NumVisitsTitle = (TextView) detailsView
            .findViewById(R.id.textView_NumberOfVisitsTitle);
    final TextView textView_LastVisitDateTitle = (TextView) detailsView
            .findViewById(R.id.textView_LastVisitDateTitle);
    final TextView textView_LastVisitTimeTitle = (TextView) detailsView
            .findViewById(R.id.textView_LastVisitTimeTitle);

    editText_IdString = (EditText) detailsView.findViewById(R.id.editText_IdentificationString);
    editText_PIN = (EditText) detailsView.findViewById(R.id.editText_PIN);
    editText_Latitude = (EditText) detailsView.findViewById(R.id.editText_Latitude);
    editText_Longitude = (EditText) detailsView.findViewById(R.id.editText_Longitude);
    editText_HintString = (EditText) detailsView.findViewById(R.id.editText_HintString);
    editText_NumVisits = (EditText) detailsView.findViewById(R.id.editText_NumberOfVisits);
    textView_LastVisitDate = (TextView) detailsView.findViewById(R.id.textView_LastVisitDate);
    textView_LastVisitTime = (TextView) detailsView.findViewById(R.id.textView_LastVisitTime);

    radioButton_ClearExisitingData = (RadioButton) detailsView.findViewById(R.id.radioButton_ClearExistingData);

    //Hook up checkboxes to enable/disable fields
    checkBox_EnableIdString.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editText_IdString.setEnabled(isChecked);
            if (isChecked && editText_IdString.getText().length() == 0)
                editText_IdString.setText("ID STR");
        }
    });
    checkBox_EnablePIN.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editText_PIN.setEnabled(isChecked);
            if (isChecked && editText_PIN.getText().length() == 0)
                editText_PIN.setText("123456");
        }
    });
    checkBox_EnableLatitude.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editText_Latitude.setEnabled(isChecked);
            if (isChecked && editText_Latitude.getText().length() == 0)
                editText_Latitude.setText("-40.1");
        }
    });
    checkBox_EnableLongitude.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editText_Longitude.setEnabled(isChecked);
            if (isChecked && editText_Longitude.getText().length() == 0)
                editText_Longitude.setText("-20.1");
        }
    });
    checkBox_EnableHintString.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            editText_HintString.setEnabled(isChecked);
            if (isChecked && editText_HintString.getText().length() == 0)
                editText_HintString.setText("Hint string.");
        }
    });
    checkBox_EnableLastVisit.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            textView_NumVisitsTitle.setEnabled(isChecked);
            textView_LastVisitDateTitle.setEnabled(isChecked);
            textView_LastVisitTimeTitle.setEnabled(isChecked);
            editText_NumVisits.setEnabled(isChecked);
            textView_LastVisitDate.setEnabled(isChecked);
            textView_LastVisitTime.setEnabled(isChecked);

            if (isChecked) {
                if (editText_NumVisits.length() == 0)
                    editText_NumVisits.setText("0");
                if (textView_LastVisitDate.length() == 0)
                    textView_LastVisitDate.setText("dd/mmm/yyyy");
                if (textView_LastVisitTime.length() == 0)
                    textView_LastVisitDate.setText("hh:mm");
            }
        }
    });

    //Set data
    editText_IdString.setText(String.valueOf(deviceData.programmableData.identificationString));
    editText_PIN.setText(String.valueOf(deviceData.programmableData.PIN));

    if (deviceData.programmableData.latitude != null)
        editText_Latitude.setText(
                String.valueOf(deviceData.programmableData.latitude.setScale(5, BigDecimal.ROUND_HALF_UP)));
    else
        editText_Latitude.setText("");

    if (deviceData.programmableData.longitude != null)
        editText_Longitude.setText(
                String.valueOf(deviceData.programmableData.longitude.setScale(5, BigDecimal.ROUND_HALF_UP)));
    else
        editText_Longitude.setText("");

    if (deviceData.programmableData.hintString != null)
        editText_HintString.setText(String.valueOf(deviceData.programmableData.hintString));
    else
        editText_HintString.setText("");

    if (deviceData.programmableData.numberOfVisits != null)
        editText_NumVisits.setText(String.valueOf(deviceData.programmableData.numberOfVisits));
    else
        editText_NumVisits.setText("");

    if (deviceData.programmableData.lastVisitTimestamp != null) {
        currentDisplayDatetime = deviceData.programmableData.lastVisitTimestamp;
        updateDateAndTime();
    } else {
        textView_LastVisitDate.setText("");
        textView_LastVisitTime.setText("");
    }

    //Hook up date and time fields to pickers
    textView_LastVisitDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (currentDisplayDatetime == null)
                currentDisplayDatetime = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
            DatePickerDialog d = new DatePickerDialog(getActivity(), new OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    currentDisplayDatetime.set(year, monthOfYear, dayOfMonth);
                    updateDateAndTime();
                }
            }, currentDisplayDatetime.get(Calendar.YEAR), currentDisplayDatetime.get(Calendar.MONTH),
                    currentDisplayDatetime.get(Calendar.DAY_OF_MONTH));
            d.show();
        }
    });

    textView_LastVisitTime.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (currentDisplayDatetime == null)
                currentDisplayDatetime = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
            TimePickerDialog d = new TimePickerDialog(getActivity(), new OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    currentDisplayDatetime.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    currentDisplayDatetime.set(Calendar.MINUTE, minute);
                    updateDateAndTime();
                }
            }, currentDisplayDatetime.get(Calendar.HOUR_OF_DAY), currentDisplayDatetime.get(Calendar.MINUTE),
                    false);
            d.show();
        }
    });

    return builder.create();
}

From source file:com.markupartist.sthlmtraveling.ChangeRouteTimeActivity.java

@SuppressLint("InlinedApi")
@Override/*ww w.  j a va2  s .  c  o  m*/
protected Dialog onCreateDialog(int id) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mTime);
    switch (id) {
    case DIALOG_DATE:
        // Workaround for broken date time picker on some Samsung devices.
        // http://stackoverflow.com/questions/28618405/datepicker-crashes-on-my-device-when-clicked-with-personal-app
        Context context = this;
        if (isBrokenSamsungDevice()) {
            context = new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog);
        }
        return new DatePickerDialog(context, mDateSetListener, calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
    case DIALOG_TIME:
        return new TimePickerDialog(this, mTimeSetListener, calendar.get(Calendar.HOUR_OF_DAY),
                calendar.get(Calendar.MINUTE), android.text.format.DateFormat.is24HourFormat(this));
    }
    return null;
}

From source file:com.whatsoft.contactbook.activity.ProfileActivity.java

@OnClick(R.id.edt_birthday)
void onClickBirthday() {
    birthday = edtDOB.getText().toString();
    Calendar calendar = Calendar.getInstance();
    DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
        @Override//  w w w.  j a  v  a  2  s.c  o m
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            edtDOB.setError(null);
            edtDOB.setText(String.format(Locale.ENGLISH, "%d/%d/%d", dayOfMonth, monthOfYear, year));
        }
    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            edtDOB.setText(birthday);
        }
    });
    datePickerDialog.show();
}