Example usage for android.app DatePickerDialog show

List of usage examples for android.app DatePickerDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.vkassin.mtrade.Common.java

public static void putArcDeal(final Context ctx) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.arcdeal_dialog);
    dialog.setTitle(R.string.ArcDealDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));/*ww  w. j  a  va 2s . com*/
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(Common.arcfilter);

    Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt);
    customDialog_Cancel.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.dismiss();
        }

    });

    Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder);
    customDialog_Put.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            Double price = new Double(0);
            Long qval = new Long(0);
            final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
            final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            //            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay)
            //            .getTime()) > 0) {
            //
            //               Toast.makeText(ctx, R.string.CorrectDate,
            //               Toast.LENGTH_SHORT).show();
            //
            //            return;
            //            }

            long maxkey = 0;
            Iterator<String> itr2 = arcdealMap.keySet().iterator();
            while (itr2.hasNext()) {
                String key1 = itr2.next();
                long k = Long.parseLong(key1);
                if (k > maxkey)
                    maxkey = k;
            }

            Deal adeal = new Deal();
            Iterator<String> itr1 = instrMap.keySet().iterator();
            while (itr1.hasNext()) {
                String key1 = itr1.next();
                Instrument in = instrMap.get(key1);
                if (in.symbol.equals(Common.arcfilter)) {

                    adeal.instrId = Long.valueOf(in.id);
                    break;
                }
            }

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);

            adeal.price = price;
            adeal.qty = qval;
            adeal.dtime = new GregorianCalendar(mYear, mMonth, mDay).getTimeInMillis();
            adeal.direct = bu0.isChecked() ? Long.valueOf(0) : Long.valueOf(1);
            Collection<String> lacc = Common.getAccountList();
            adeal.account = (lacc == null) ? "" : lacc.iterator().next();
            arcdealMap.put(String.valueOf(maxkey + 1), adeal);
            Common.saveArcDeals();
            Common.arcActivity.refresh();
            dialog.dismiss();
        }
    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

From source file:com.shalzz.attendance.fragment.TimeTablePagerFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_logout) {
        userAccount.Logout();/*from   www.j  a  v a 2s.  c  o  m*/
        return true;
    } else if (item.getItemId() == R.id.menu_refresh) {
        // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator
        if (!mSwipeRefreshLayout.isRefreshing()) {
            mSwipeRefreshLayout.setRefreshing(true);
            mController.updatePeriods();
            return true;
        }
    } else if (item.getItemId() == R.id.menu_date) {
        Calendar today = Calendar.getInstance();
        today.setTime(new Date());
        DatePickerDialog mDatePickerDialog = new DatePickerDialog(mContext, onDateSetListener(),
                today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH));
        mDatePickerDialog.setOnCancelListener(dialog -> {
            mTracker.send(new HitBuilders.EventBuilder().setCategory("Scroll to Date").setAction("Button")
                    .setLabel("Cancel").build());
        });
        mDatePickerDialog.show();

        mTracker.send(new HitBuilders.EventBuilder().setCategory("Action").setAction("Scroll to Date").build());
        return true;
    } else if (item.getItemId() == R.id.menu_today) {
        mController.setToday();

        mTracker.send(
                new HitBuilders.EventBuilder().setCategory("Action").setAction("Scroll to Today").build());
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.owncloud.android.ui.activity.ContactsPreferenceActivity.java

public void openDate(View v) {
    String backupFolderString = getResources().getString(R.string.contacts_backup_folder)
            + OCFile.PATH_SEPARATOR;/*w  w  w  . ja va2s. c  o m*/
    OCFile backupFolder = getStorageManager().getFileByPath(backupFolderString);

    Vector<OCFile> backupFiles = getStorageManager().getFolderContent(backupFolder, false);

    Collections.sort(backupFiles, new Comparator<OCFile>() {
        @Override
        public int compare(OCFile o1, OCFile o2) {
            if (o1.getModificationTimestamp() == o2.getModificationTimestamp()) {
                return 0;
            }

            if (o1.getModificationTimestamp() > o2.getModificationTimestamp()) {
                return 1;
            } else {
                return -1;
            }
        }
    });

    Calendar cal = Calendar.getInstance();
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            String backupFolderString = getResources().getString(R.string.contacts_backup_folder)
                    + OCFile.PATH_SEPARATOR;
            OCFile backupFolder = getStorageManager().getFileByPath(backupFolderString);
            Vector<OCFile> backupFiles = getStorageManager().getFolderContent(backupFolder, false);

            // find file with modification with date and time between 00:00 and 23:59
            // if more than one file exists, take oldest
            Calendar date = Calendar.getInstance();
            date.set(year, month, dayOfMonth);

            // start
            date.set(Calendar.HOUR, 0);
            date.set(Calendar.MINUTE, 0);
            date.set(Calendar.SECOND, 1);
            date.set(Calendar.MILLISECOND, 0);
            date.set(Calendar.AM_PM, Calendar.AM);
            Long start = date.getTimeInMillis();

            // end
            date.set(Calendar.HOUR, 23);
            date.set(Calendar.MINUTE, 59);
            date.set(Calendar.SECOND, 59);
            Long end = date.getTimeInMillis();

            OCFile backupToRestore = null;

            for (OCFile file : backupFiles) {
                if (start < file.getModificationTimestamp() && end > file.getModificationTimestamp()) {
                    if (backupToRestore == null) {
                        backupToRestore = file;
                    } else if (backupToRestore.getModificationTimestamp() < file.getModificationTimestamp()) {
                        backupToRestore = file;
                    }
                }
            }

            if (backupToRestore != null) {
                Fragment contactListFragment = ContactListFragment.newInstance(backupToRestore, getAccount());

                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.contacts_linear_layout, contactListFragment);
                transaction.commit();
            } else {
                Toast.makeText(ContactsPreferenceActivity.this, R.string.contacts_preferences_no_file_found,
                        Toast.LENGTH_SHORT).show();
            }
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(this, dateSetListener, year, month, day);
    datePickerDialog.getDatePicker().setMaxDate(backupFiles.lastElement().getModificationTimestamp());
    datePickerDialog.getDatePicker().setMinDate(backupFiles.firstElement().getModificationTimestamp());

    datePickerDialog.show();
}

From source file:org.irmacard.cardemu.selfenrol.EnrollSelectActivity.java

public void onDateTouch(View v) {
    final EditText dateView = (EditText) v;
    final String name = v.getId() == R.id.dob_edittext ? "dob" : "doe";
    Long current = settings.getLong("enroll_bac_" + name, 0);

    final Calendar c = Calendar.getInstance();
    if (current != 0)
        c.setTimeInMillis(current);/*  w w w.  ja v  a  2 s .  c  o m*/

    int currentYear = c.get(Calendar.YEAR);
    int currentMonth = c.get(Calendar.MONTH);
    int currentDay = c.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog dpd = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar date = new GregorianCalendar(year, monthOfYear, dayOfMonth);
            setDateEditText(dateView, date);
        }
    }, currentYear, currentMonth, currentDay);
    dpd.show();
}

From source file:com.vkassin.mtrade.Common.java

public static void putOrder(final Context ctx, Quote quote) {

    final Instrument it = Common.selectedInstrument;// adapter.getItem(selectedRowId);

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.order_dialog);
    dialog.setTitle(R.string.OrderDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));/*  w w  w . ja v a2 s .c o  m*/
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(it.symbol);

    final Spinner aspinner = (Spinner) dialog.findViewById(R.id.acc_spinner);
    List<String> list = new ArrayList<String>(Common.getAccountList());
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(Common.app_ctx,
            android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    aspinner.setAdapter(dataAdapter);

    final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
    final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

    final Button buttonpm = (Button) dialog.findViewById(R.id.buttonPriceMinus);
    buttonpm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price -= 0.01;
                if (price < 0)
                    price = 0;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonpp = (Button) dialog.findViewById(R.id.buttonPricePlus);
    buttonpp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price += 0.01;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonqm = (Button) dialog.findViewById(R.id.buttonQtyMinus);
    buttonqm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty -= 1;
                if (qty < 0)
                    qty = 0;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final Button buttonqp = (Button) dialog.findViewById(R.id.buttonQtyPlus);
    buttonqp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty += 1;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
            }
        }
    });

    final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);
    final RadioButton bu1 = (RadioButton) dialog.findViewById(R.id.radio1);

    if (quote != null) {

        // pricetxt.setText(quote.price.toString());
        pricetxt.setText(quote.getPriceS());
        if (quote.qtyBuy > 0) {

            quanttxt.setText(quote.qtyBuy.toString());
            bu1.setChecked(true);
            bu0.setChecked(false);

        } else {

            quanttxt.setText(quote.qtySell.toString());
            bu1.setChecked(false);
            bu0.setChecked(true);

        }
    }

    Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt);
    customDialog_Cancel.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.dismiss();
        }

    });

    Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder);
    customDialog_Put.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            Double price = new Double(0);
            Long qval = new Long(0);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay).getTime()) > 0) {

                Toast.makeText(ctx, R.string.CorrectDate, Toast.LENGTH_SHORT).show();

                return;

            }

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.CREATE_REMOVE_ORDER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("device", "Android");
                msg.put("instrumId", Long.valueOf(it.id));
                msg.put("price", price);
                msg.put("qty", qval);
                msg.put("ordType", 1);
                msg.put("side", bu0.isChecked() ? 0 : 1);
                msg.put("code", String.valueOf(aspinner.getSelectedItem()));
                msg.put("orderNum", ++ordernum);
                msg.put("action", "CREATE");
                boolean b = (((mYear - 1900) == dat.getYear()) && (mMonth == dat.getMonth())
                        && (mDay == dat.getDate()));
                if (!b)
                    msg.put("expired", String.format("%02d.%02d.%04d", mDay, mMonth + 1, mYear));

                if (isSSL) {

                    //                ? ?:    newOrder-orderNum-instrumId-side-price-qty-code-ordType
                    //               :                  newOrder-16807-20594623-0-1150-13-1027700451-1
                    String forsign = "newOrder-" + ordernum + "-" + msg.getString("instrumId") + "-"
                            + msg.getString("side") + "-"
                            + JSONObject.numberToString(Double.valueOf(msg.getDouble("price"))) + "-"
                            + msg.getString("qty") + "-" + msg.getString("code") + "-"
                            + msg.getString("ordType");
                    byte[] signed = Common.signText(Common.signProfile, forsign.getBytes(), true);
                    String gsign = Base64.encodeToString(signed, Base64.DEFAULT);
                    msg.put("gostSign", gsign);
                }
                mainActivity.writeJSONMsg(msg);

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON order object", e);
            }

            dialog.dismiss();
        }

    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

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  . co  m*/
                    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:pl.bcichecki.rms.client.android.activities.EditEventActivity.java

private void showEndsOnDateDialog() {
    Calendar endDateCalendar = Calendar.getInstance();
    endDateCalendar.setTime(endDate);/*from ww  w.  ja va  2  s  . c  om*/

    OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            endDate = DateUtils.setYears(endDate, year);
            endDate = DateUtils.setMonths(endDate, monthOfYear);
            endDate = DateUtils.setDays(endDate, dayOfMonth);
            updateEndDateButtons();
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener,
            endDateCalendar.get(Calendar.YEAR), endDateCalendar.get(Calendar.MONTH),
            endDateCalendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setTitle(R.string.activity_edit_event_pick_end_date);
    datePickerDialog.show();
}

From source file:uk.ac.horizon.artcodes.fragment.AvailabilityEditDialogFragment.java

private void selectDate(Long timestamp, final DateListener listener) {
    final Calendar calendar = Calendar.getInstance();
    if (timestamp != null) {
        calendar.setTimeInMillis(timestamp);
    } else {/*from   w ww . j  a  v a 2s  .com*/
        calendar.setTimeInMillis(System.currentTimeMillis());
    }
    int mYear = calendar.get(Calendar.YEAR);
    int mMonth = calendar.get(Calendar.MONTH);
    int mDay = calendar.get(Calendar.DAY_OF_MONTH);

    DatePickerDialog dialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            final Calendar calendar = Calendar.getInstance();
            calendar.set(year, monthOfYear, dayOfMonth);
            listener.dateSelected(calendar.getTimeInMillis());
        }
    }, mYear, mMonth, mDay);
    dialog.setButton(DatePickerDialog.BUTTON_NEUTRAL, getString(R.string.clear),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    listener.dateSelected(null);
                }
            });
    dialog.show();
}

From source file:pl.bcichecki.rms.client.android.activities.EditEventActivity.java

private void showStartsOnDateDialog() {
    Calendar startDateCalendar = Calendar.getInstance();
    startDateCalendar.setTime(startDate);

    OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

        @Override/*from   w w  w .ja  v  a  2 s .  co m*/
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            long diff = endDate.getTime() - startDate.getTime();

            startDate = DateUtils.setYears(startDate, year);
            startDate = DateUtils.setMonths(startDate, monthOfYear);
            startDate = DateUtils.setDays(startDate, dayOfMonth);
            updateStartDateButtons();

            endDate.setTime(startDate.getTime() + diff);
            updateEndDateButtons();
        }
    };

    DatePickerDialog datePickerDialog = new DatePickerDialog(context, onDateSetListener,
            startDateCalendar.get(Calendar.YEAR), startDateCalendar.get(Calendar.MONTH),
            startDateCalendar.get(Calendar.DAY_OF_MONTH));
    datePickerDialog.setTitle(R.string.activity_edit_event_pick_start_date);
    datePickerDialog.show();
}

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  a va  2s  .  c o  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();
}