private void loadUserDOB() {
    DatePicker.OnDateChangedListener onDateChanged =
        new DatePicker.OnDateChangedListener() {
          @Override
          public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Log.v(
                Globals.TAG,
                "year : "
                    + year
                    + ", monthOfYear : "
                    + monthOfYear
                    + ", dayOfMonth : "
                    + dayOfMonth);
          }
        };

    if (null != user.getDateOfBirth()) {
      String dob[] = user.getDateOfBirth().split("-");
      year = Integer.parseInt(dob[0]);
      month = Integer.parseInt(dob[1]);
      day = Integer.parseInt(dob[2]);

    } else {
      Calendar c = Calendar.getInstance();
      year = c.get(Calendar.YEAR);
      month = c.get(Calendar.MONTH);
      day = c.get(Calendar.DAY_OF_MONTH);
    }

    pickerDOB.init(year, month, day, onDateChanged);
    pickerDOB.setCalendarViewShown(false);
    pickerDOB.setSpinnersShown(true);
  }
 /** {@inheritDoc} */
 @Override
 protected View onCreateDialogView() {
   final Calendar c = this.getPersitendCalendar(this.defValue);
   final DatePicker dp = new DatePicker(this.getContext());
   dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), this);
   return dp;
 }
Ejemplo n.º 3
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    expenseData = new ExpenseContentProvider();

    // wire up interface
    dateToday = (DatePicker) findViewById(R.id.dateToday);
    spinnerExpenseType = (Spinner) findViewById(R.id.spinnerExpenseType);
    layoutNewType = (LinearLayout) findViewById(R.id.layoutNewType);
    layoutExpenseType = (LinearLayout) findViewById(R.id.layoutExpenseType);
    txtAmount = (EditText) findViewById(R.id.txtAmount);
    txtAddType = (EditText) findViewById(R.id.txtAddType);
    lblTodaysSpendValue = (TextView) findViewById(R.id.lblTodaysSpendValue);

    Button btnAddType = (Button) findViewById(R.id.btnAddType);
    Button btnSaveNewType = (Button) findViewById(R.id.btnSaveNewType);
    Button btnSave = (Button) findViewById(R.id.btnSave);

    btnAddType.setOnClickListener(lAddTypeClicked);
    btnSaveNewType.setOnClickListener(lSaveNewTypeClicked);
    btnSave.setOnClickListener(lSaveClicked);

    dateToday.init(
        dateToday.getYear(), dateToday.getMonth(), dateToday.getDayOfMonth(), lDateTodayChanged);

    // set up spinner
    bindExpenseTypeSpinner();

    // set up todays spend
    bindTodaysSpend();
  }
Ejemplo n.º 4
0
  private void showPickerDialog(String title, String strDatetime) {
    if (mDialog == null) {
      mDialog = new PopupWindowDialog(mPathActivity);
      mDialog.setContentView(R.layout.datetime_picker);
    }

    View view = mDialog.getContentView();
    {
      view.findViewById(R.id.datetime_picker_close).setOnClickListener(this);
      view.findViewById(R.id.datetime_picker_cancel).setOnClickListener(this);
      view.findViewById(R.id.datetime_picker_submit).setOnClickListener(this);
    }

    TextView lblTitle = (TextView) view.findViewById(R.id.datetime_picker_title);
    datetime_picker_date = (DatePicker) view.findViewById(R.id.datetime_picker_date);
    datetime_picker_time = (TimePicker) view.findViewById(R.id.datetime_picker_time);
    lblTitle.setText(title);

    DateTime datetime = DateTime.from(strDatetime, "yyyy-MM-dd HH:mm");

    datetime_picker_date.init(
        datetime.getYear(), datetime.getMonth(), datetime.getDay(), null); // date.getDay()

    // pkrTime.setIs24HourView(true);// 24小时制
    datetime_picker_time.setCurrentHour(datetime.getHours()); // 设置当前小时。
    datetime_picker_time.setCurrentMinute(datetime.getMinutes()); // 当前分钟
    // datetime_picker_time.setOnTimeChangedListener(null);
    mDialog.show();
  }
Ejemplo n.º 5
0
  // display current date
  public void setCurrentDateOnView() {

    // tvDisplayDate = (TextView) findViewById(R.id.tvDate);
    // dpResult = (DatePicker) findViewById(R.id.dpResult);

    final Calendar c = Calendar.getInstance();
    year = c.get(Calendar.YEAR);
    month = c.get(Calendar.MONTH);
    day = c.get(Calendar.DAY_OF_MONTH);

    // set current date into textview
    tvDisplayDate = new TextView(getApplicationContext());
    tvDisplayDate.setText(
        new StringBuilder()
            // Month is 0 based, just add 1
            .append(month + 1)
            .append("-")
            .append(day)
            .append("-")
            .append(year)
            .append(" "));

    // set current date into datepicker
    dpResult.init(year, month, day, null);
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    Date date = (Date) getArguments().getSerializable(ARG_DATE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    int year = calendar.get(Calendar.YEAR);
    int monthOfYear = calendar.get(Calendar.MONTH);
    int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);

    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_date, null);

    mDatePicker = (DatePicker) dialogView.findViewById(R.id.dialog_date_picker);
    mDatePicker.init(year, monthOfYear, dayOfMonth, null);

    return new AlertDialog.Builder(getActivity())
        .setView(dialogView)
        .setTitle(R.string.date_picker_title)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                int year = mDatePicker.getYear();
                int monthOfYear = mDatePicker.getMonth();
                int dayOfMonth = mDatePicker.getDayOfMonth();
                Date date = new GregorianCalendar(year, monthOfYear, dayOfMonth).getTime();
                sendResult(Activity.RESULT_OK, date);
                // sendResult(DatePicker) -- in the future
              }
            })
        .create();
  }
Ejemplo n.º 7
0
  private static void bindDatePickerValue(final View view, final Object target, final Field f2) {
    f2.setAccessible(true);
    final GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

    DatePicker dp = (DatePicker) view;
    cal.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
    cal.set(Calendar.MONTH, dp.getMonth());
    cal.set(Calendar.YEAR, dp.getYear());
    try {
      f2.set(target, cal.getTime());
    } catch (Exception e) {
      Log.e("CleanDroid", e.getMessage());
    }

    ((DatePicker) view)
        .init(
            dp.getYear(),
            dp.getMonth(),
            dp.getDayOfMonth(),
            new OnDateChangedListener() {

              @Override
              public void onDateChanged(
                  DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                cal.set(Calendar.MONTH, monthOfYear);
                cal.set(Calendar.YEAR, year);
                try {
                  f2.set(target, cal.getTime());
                } catch (Exception e) {
                  Log.e("CleanDroid", e.getMessage());
                }
              }
            });
  }
Ejemplo n.º 8
0
  @Override
  @NonNull
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    Calendar calendar = Calendar.getInstance();

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_date, null);

    mDatePicker = (DatePicker) v.findViewById(R.id.dialog_date_picker);
    mDatePicker.init(year, month, day, null);

    return new AlertDialog.Builder(getActivity())
        .setView(v)
        .setTitle(R.string.date_picker_title)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                int year = mDatePicker.getYear();
                int month = mDatePicker.getMonth();
                int day = mDatePicker.getDayOfMonth();
                Date date = new GregorianCalendar(year, month, day).getTime();

                sendResult(Activity.RESULT_OK, date);
              }
            })
        .create();
  }
Ejemplo n.º 9
0
 /** 显示选择宝贝生日的弹窗 */
 private void showBirthdayDialog() {
   if (mBirthdayDialog == null) {
     mBirthdayDialog = new BaseDialog(this);
     mBirthdayDialog.setWindow(R.style.alpha_animation, 0.3f);
     mBirthdayDialog.setContentView(R.layout.dialog_select_birthday);
     mDatePicker = (DatePicker) mBirthdayDialog.findViewById(R.id.date_picker);
     Calendar cal = Calendar.getInstance();
     cal.setTimeInMillis(System.currentTimeMillis());
     mDatePicker.init(
         cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), null);
     mBirthdayDialog
         .findViewById(R.id.btn_ok)
         .setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                 if (mDatePicker != null) {
                   String birthday =
                       String.format(
                           "%d年%02d月%02d日",
                           mDatePicker.getYear(),
                           mDatePicker.getMonth() + 1,
                           mDatePicker.getDayOfMonth());
                   mTvBabyBirthday.setText(birthday);
                 }
                 if (mBirthdayDialog != null) {
                   mBirthdayDialog.dismiss();
                 }
               }
             });
   }
   mBirthdayDialog.show();
 }
Ejemplo n.º 10
0
 /** {@inheritDoc} */
 @Override
 protected View createView(Context c) {
   dp = new DatePicker(c);
   if (dateAnswer != null) {
     dp.init(dateAnswer.getYear() + 1900, dateAnswer.getMonth(), dateAnswer.getDate(), null);
   }
   return encapsulateQuestion(c, dp);
 }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    Date date = (Date) getArguments().getSerializable(ARG_DATE);
    String pickerType = (String) getArguments().getSerializable(ARG_PICKER_TYPE);

    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);
    View v;
    if (pickerType == "date") {

      v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_date, null);
      mDatePicker = (DatePicker) v.findViewById(R.id.dialog_date_date_picker);
      mDatePicker.init(year, month, day, null);
      return new AlertDialog.Builder(getActivity())
          .setView(v)
          .setTitle(R.string.date_picker_title)
          .setPositiveButton(
              android.R.string.ok,
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  int year = mDatePicker.getYear();
                  int month = mDatePicker.getMonth();
                  int day = mDatePicker.getDayOfMonth();
                  Date date = new GregorianCalendar(year, month, day).getTime();
                  sendResult(Activity.RESULT_OK, date);
                }
              })
          .create();

    } else {
      v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_time, null);
      mTimePicker = (TimePicker) v.findViewById(R.id.dialog_time_time_picker);
      return new AlertDialog.Builder(getActivity())
          .setView(v)
          .setTitle(R.string.time_picker_title)
          .setPositiveButton(
              android.R.string.ok,
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  int hour = mTimePicker.getCurrentHour();
                  int minute = mTimePicker.getCurrentMinute();
                  int year = calendar.get(Calendar.YEAR);
                  int month = calendar.get(Calendar.MONTH);
                  int day = calendar.get(Calendar.DAY_OF_MONTH);
                  Date date = new GregorianCalendar(year, month, day, hour, minute).getTime();
                  sendResult(Activity.RESULT_OK, date);
                }
              })
          .create();
    }
  }
Ejemplo n.º 12
0
  public void setCurrentDateOnView() {
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    // set current date into datepicker
    checkDatePicker.init(year, month, day, null);
  }
 /**
  * Produces a DatePicker set to the date produced by {@link #getDate()}. When overriding be sure
  * to call the super.
  *
  * @return a DatePicker with the date set
  */
 @Override
 protected View onCreateDialogView() {
   this.datePicker = new DatePicker(getContext());
   Calendar calendar = getDate();
   datePicker.init(
       calendar.get(Calendar.YEAR),
       calendar.get(Calendar.MONTH),
       calendar.get(Calendar.DAY_OF_MONTH),
       this);
   return datePicker;
 }
Ejemplo n.º 14
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search);

    Button saveBtn = (Button) findViewById(R.id.searchBtn);
    saveBtn.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            search();
          }
        });

    DatePicker fromDate = (DatePicker) findViewById(R.id.fromDate);
    Calendar now = Calendar.getInstance();
    this.fromYear = now.get(Calendar.YEAR);
    this.fromMonth = now.get(Calendar.MONDAY);
    this.fromDay = now.get(Calendar.DAY_OF_MONTH);
    this.toYear = this.fromYear;
    this.toMonth = this.fromMonth + 1;
    this.toDay = this.fromDay;
    fromDate.init(
        now.get(Calendar.YEAR),
        now.get(Calendar.MONDAY),
        now.get(Calendar.DAY_OF_MONTH),
        new MyListener());
    DatePicker toDate = (DatePicker) findViewById(R.id.toDate);
    toDate.init(
        now.get(Calendar.YEAR),
        now.get(Calendar.MONDAY) + 1,
        now.get(Calendar.DAY_OF_MONTH),
        new MyListener());

    Spinner spinner = (Spinner) findViewById(R.id.typeSpinner);
    ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this, R.layout.spinner, types);
    mAdapter.setDropDownViewResource(R.layout.spinner);
    spinner.setAdapter(mAdapter);
  }
Ejemplo n.º 15
0
 /** Sur le changement de date : mise a jour de l'affichage de la qte */
 private void dat_clic() {
   final DatePicker uneDate = (DatePicker) findViewById(R.id.datNuitee); // recuération de la vue
   uneDate.init(
       uneDate.getYear(),
       uneDate.getMonth(),
       uneDate.getDayOfMonth(),
       new OnDateChangedListener() {
         @Override
         public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
           valoriseProprietes(); // mise a jour de l'affichage de la qte en fonction de la date
         }
       });
 }
Ejemplo n.º 16
0
 /**
  * Fonction événementielle appelée en cas de changement de date : mise à jour de l'affichage de la
  * qte
  */
 private void dat_clic() {
   final DatePicker uneDate = (DatePicker) findViewById(R.id.datRepas);
   uneDate.init(
       uneDate.getYear(),
       uneDate.getMonth(),
       uneDate.getDayOfMonth(),
       new DatePicker.OnDateChangedListener() {
         @Override
         public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
           valoriserProprietes();
         }
       });
 }
Ejemplo n.º 17
0
  @UiThreadTest
  public void testInit() {
    MockOnDateChangedListener onDateChangedListener = new MockOnDateChangedListener();
    DatePicker datePicker = createDatePicker();

    /* The month display uses 1-12 but our internal state stores it
     * 0-11 so add one when setting the display.
     */
    datePicker.init(2000, 10, 15, onDateChangedListener);
    assertEquals(2000, datePicker.getYear());
    assertEquals(10, datePicker.getMonth());
    assertEquals(15, datePicker.getDayOfMonth());
  }
Ejemplo n.º 18
0
  private void myDialog() {
    final Dialog setDate = new Dialog(this);
    setDate.setContentView(R.layout.dialog);
    setDate.setTitle("Select Dates");

    final DatePicker picker1 = (DatePicker) setDate.findViewById(R.id.datePicker1);
    final DatePicker picker2 = (DatePicker) setDate.findViewById(R.id.datePicker2);

    loadDatesV();
    Log.i(
        "Dates", "-" + Sday + " " + Smonth + " " + Syear + " " + Eday + " " + Emonth + " " + Eyear);
    picker1.init(Syear, Smonth, Sday, null);
    picker2.init(Eyear, Emonth, Eday, null);
    setDate.show();

    Button submitDate = (Button) setDate.findViewById(R.id.button1);
    submitDate.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            try {
              String newStartDate =
                  picker1.getDayOfMonth() + "/" + picker1.getMonth() + "/" + picker1.getYear();
              String newEndDate =
                  picker2.getDayOfMonth() + "/" + picker2.getMonth() + "/" + picker2.getYear();

              db.open();
              db.updateDates(1, newStartDate, newEndDate);
            } catch (SQLException sqle) {
              throw sqle;
            }
            db.close();
            updateCounterAndDates();
            vgp1.updateMain(); // mview.updateAll();
            setDate.dismiss();
          }
        });
  }
Ejemplo n.º 19
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    info = (TextView) findViewById(R.id.info);
    editItem = (EditText) findViewById(R.id.editItem);
    editLocation = (EditText) findViewById(R.id.editLocation);
    pickerDate = (DatePicker) findViewById(R.id.editTextDate);
    pickerTime = (TimePicker) findViewById(R.id.editTextTime);

    Calendar now = Calendar.getInstance();

    pickerDate.init(
        now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), null);

    pickerTime.setCurrentHour(now.get(Calendar.HOUR_OF_DAY));
    pickerTime.setCurrentMinute(now.get(Calendar.MINUTE));

    buttonSetAlarm = (Button) findViewById(R.id.setalarm);
    buttonSetAlarm.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            Calendar current = Calendar.getInstance();

            Calendar cal = Calendar.getInstance();
            cal.set(
                pickerDate.getYear(),
                pickerDate.getMonth(),
                pickerDate.getDayOfMonth(),
                pickerTime.getCurrentHour(),
                pickerTime.getCurrentMinute(),
                00);

            if (cal.compareTo(current) <= 0) {
              Toast.makeText(getApplicationContext(), "Invalid Date/Time", Toast.LENGTH_LONG)
                  .show();
            } else {
              Toast.makeText(
                      getApplicationContext(), "Reminder saved SUCCESSFULLY", Toast.LENGTH_LONG)
                  .show();
              setAlarm(cal);
            }
          }
        });
  }
  @NonNull
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
    View view = inflate(R.layout.date_picker_dialog_fragment);
    dialogBuilder.setView(view);

    final DatePicker datePicker = (DatePicker) view.findViewById(R.id.datePicker);
    datePicker.init(
        com.jdroid.java.utils.DateUtils.getYear(defaultDate),
        com.jdroid.java.utils.DateUtils.getMonth(defaultDate),
        com.jdroid.java.utils.DateUtils.getDayOfMonth(defaultDate),
        this);

    if (titleResId != null) {
      dialogBuilder.setTitle(titleResId);
    }

    Boolean disableMinMaxDate = disableMinMaxDate();

    if ((minDate != null) && !disableMinMaxDate) {
      datePicker.setMinDate(minDate.getTime());
    }
    if ((maxDate != null) && !disableMinMaxDate) {
      datePicker.setMaxDate(maxDate.getTime());
    }

    dialogBuilder.setPositiveButton(
        getString(R.string.ok),
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int whichButton) {
            Date date =
                com.jdroid.java.utils.DateUtils.getDate(
                    datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
            int requestCode = getTargetRequestCode();
            ((OnDateSetListener) getTargetFragment()).onDateSet(date, requestCode);
          }
        });

    dialogBuilder.setNegativeButton(getString(R.string.cancel), null);

    Dialog dialog = dialogBuilder.create();
    updateTitle(dialog, defaultDate);
    return dialog;
  }
  private void init(Context context) {
    setContentView(R.layout.timesetting_layout);
    datePicker = (DatePicker) findViewById(R.id.datePicker);
    timePicker = (TimePicker) findViewById(R.id.timePicker);
    this.context = context;

    timePicker.setOnTimeChangedListener(onTimeChangedListener);
    Date date = new Date();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    datePicker.init(
        calendar.get(Calendar.YEAR),
        calendar.get(Calendar.MONTH),
        calendar.get(Calendar.DAY_OF_MONTH),
        onDateChangedListener);
  }
Ejemplo n.º 22
0
 @Override
 public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
   mCalendar = Calendar.getInstance();
   // System.out.println(year + " "+monthOfYear+" "+ dayOfMonth);
   mCalendar.set(year, monthOfYear, dayOfMonth);
   if (mCalendar.getTime().after(mMinDate) || mCalendar.getTime().before(mMaxDate)) {
     mCalendar.setTime(mSelectDate);
     mDpBirthday.init(
         mCalendar.get(Calendar.YEAR),
         mCalendar.get(Calendar.MONTH),
         mCalendar.get(Calendar.DAY_OF_MONTH),
         this);
   } else {
     flushBirthday(mCalendar);
   }
 }
Ejemplo n.º 23
0
  @NonNull
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    date = (Date) getArguments().getSerializable(EXTRA_DATE);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    int year = calendar.get(Calendar.YEAR);
    final int month = calendar.get(Calendar.MONTH);
    final int day = calendar.get(Calendar.DAY_OF_MONTH);

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_date, null);

    DatePicker datePicker = (DatePicker) view.findViewById(R.id.dialog_date_datePicker);
    datePicker.init(
        year,
        month,
        day,
        new DatePicker.OnDateChangedListener() {
          @Override
          public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.set(Calendar.YEAR, year);
            cal.set(Calendar.MONTH, monthOfYear);
            cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            date = cal.getTime();
            // Update argument to preserve selected value on rotation
            getArguments().putSerializable(EXTRA_DATE, date);
          }
        });

    return new AlertDialog.Builder(getActivity())
        .setTitle(R.string.date_picker_title)
        .setView(view)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                sendResult(Activity.RESULT_OK);
              }
            })
        .create();
  }
Ejemplo n.º 24
0
  public void init(DatePicker datePicker) {
    Calendar calendar = Calendar.getInstance();
    if (!(null == initDateTime || "".equals(initDateTime))) {
      calendar = this.getCalendarByInintData(initDateTime);
    } else {
      initDateTime =
          calendar.get(Calendar.YEAR)
              + "-"
              + calendar.get(Calendar.MONTH)
              + "-"
              + calendar.get(Calendar.DAY_OF_MONTH);
    }

    datePicker.init(
        calendar.get(Calendar.YEAR),
        calendar.get(Calendar.MONTH),
        calendar.get(Calendar.DAY_OF_MONTH),
        this);
  }
Ejemplo n.º 25
0
  private void initData() {
    mSelectDate = DateUtils.getDate("19900101");

    Calendar mMinCalendar = Calendar.getInstance();
    Calendar mMaxCalendar = Calendar.getInstance();

    mMinCalendar.set(Calendar.YEAR, mMinCalendar.get(Calendar.YEAR) - MIN_AGE);
    mMinDate = mMinCalendar.getTime();
    mMaxCalendar.set(Calendar.YEAR, mMaxCalendar.get(Calendar.YEAR) - MAX_AGE);
    mMaxDate = mMaxCalendar.getTime();

    mCalendar = Calendar.getInstance();
    mCalendar.setTime(mSelectDate);
    flushBirthday(mCalendar);
    mDpBirthday.init(
        mCalendar.get(Calendar.YEAR),
        mCalendar.get(Calendar.MONTH),
        mCalendar.get(Calendar.DAY_OF_MONTH),
        this);
  }
Ejemplo n.º 26
0
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    final Calendar calendar = Calendar.getInstance();
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
    dialog.setTitle("Elegir Fecha");
    view = getActivity().getLayoutInflater().inflate(R.layout.modelo_datepicker, null);
    datePicker = (DatePicker) view.findViewById(R.id.datepickerFecha);
    datePicker.init(year, month, day, null);
    datePicker.setCalendarViewShown(false);
    btnAceptar = (Button) view.findViewById(R.id.btnAceptarDatePicker);
    btnAceptar.setOnClickListener(this);
    btnCancelar = (Button) view.findViewById(R.id.btnCancelarDatePicker);
    btnCancelar.setOnClickListener(this);
    dialog.setView(view);

    return dialog.create();
  }
Ejemplo n.º 27
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Logger.D(TAG, "onCreate");

    getWindow().setFlags(RhodesService.WINDOW_FLAGS, RhodesService.WINDOW_MASK);
    setContentView(AndroidR.layout.datetime);

    Bundle extras = this.getIntent().getExtras();

    _callback = extras.getString(INTENT_EXTRA_PREFIX + "callback");
    _init = new Date(extras.getLong(INTENT_EXTRA_PREFIX + "init") * 1000);
    _fmt = extras.getInt(INTENT_EXTRA_PREFIX + "fmt");
    _opaque = extras.getByteArray(INTENT_EXTRA_PREFIX + "opaque");

    this.setTitle(extras.getString(INTENT_EXTRA_PREFIX + "title"));

    _datePicker = (DatePicker) findViewById(AndroidR.id.datePicker);
    _timePicker = (TimePicker) findViewById(AndroidR.id.timePicker);
    _okButton = (Button) findViewById(AndroidR.id.okButton);
    _cancelButton = (Button) findViewById(AndroidR.id.cancelButton);

    _okButton.setOnClickListener(mOkListener);
    _cancelButton.setOnClickListener(mCancelListener);

    _datePicker.init(_init.getYear() + 1900, _init.getMonth(), _init.getDay(), null);
    _timePicker.setCurrentHour(_init.getHours());
    _timePicker.setCurrentMinute(_init.getMinutes());

    switch (_fmt) {
      case FORMAT_DATE:
        _timePicker.setVisibility(View.INVISIBLE);
        break;
      case FORMAT_TIME:
        _datePicker.setVisibility(View.INVISIBLE);
        break;
      case FORMAT_DATE_TIME:
        break;
    }
  }
Ejemplo n.º 28
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    date = (Date) getArguments().getSerializable(EXTRA_DATE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    final int year = calendar.get(Calendar.YEAR);
    final int month = calendar.get(Calendar.MONTH);
    final int day = calendar.get(Calendar.DATE);

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_date, null);
    DatePicker datePicker = (DatePicker) view.findViewById(R.id.dialog_date_date_picker);
    datePicker.init(
        year,
        month,
        day,
        new DatePicker.OnDateChangedListener() {
          @Override
          public void onDateChanged(DatePicker datePicker, int i, int i2, int i3) {
            date =
                new GregorianCalendar(
                        datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth())
                    .getTime();
            getArguments().putSerializable(EXTRA_DATE, date);
            // we need it in case of screen rotation
          }
        });
    return new AlertDialog.Builder(getActivity())
        .setView(view)
        .setTitle(R.string.date_picker_title)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {
                sendResult(Activity.RESULT_OK);
              }
            })
        .create();
  }
Ejemplo n.º 29
0
        // when dialog box is closed, below method will be called.
        public void onDateSet(
            DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
          year = selectedYear;
          month = selectedMonth;
          day = selectedDay;
          tvDisplayDate = new TextView(getApplicationContext());
          dpResult = new DatePicker(getApplicationContext());
          Toast.makeText(getApplicationContext(), "Event Works", Toast.LENGTH_SHORT).show();

          // set selected date into textview
          tvDisplayDate.setText(
              new StringBuilder()
                  .append(month + 1)
                  .append("-")
                  .append(day)
                  .append("-")
                  .append(year)
                  .append(" "));

          // set selected date into datepicker also
          dpResult.init(year, month, day, null);
        }
Ejemplo n.º 30
0
  public DateTimePicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Get LayoutInflater instance
    final LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // Inflate myself
    inflater.inflate(R.layout.datetimepicker, this, true);

    // Inflate the date and time picker views
    final LinearLayout datePickerView = (LinearLayout) inflater.inflate(R.layout.datepicker, null);
    final LinearLayout timePickerView = (LinearLayout) inflater.inflate(R.layout.timepicker, null);

    // Grab a Calendar instance
    mCalendar = Calendar.getInstance();
    // Grab the ViewSwitcher so we can attach our picker views to it
    viewSwitcher = (ViewSwitcher) this.findViewById(R.id.DateTimePickerVS);

    // Init date picker
    datePicker = (DatePicker) datePickerView.findViewById(R.id.DatePicker);
    datePicker.init(
        mCalendar.get(Calendar.YEAR),
        mCalendar.get(Calendar.MONTH),
        mCalendar.get(Calendar.DAY_OF_MONTH),
        this);

    // Init time picker
    timePicker = (TimePicker) timePickerView.findViewById(R.id.TimePicker);
    timePicker.setOnTimeChangedListener(this);

    // Handle button clicks
    ((Button) findViewById(R.id.SwitchToTime)).setOnClickListener(this); // shows the time picker
    ((Button) findViewById(R.id.SwitchToDate)).setOnClickListener(this); // shows the date picker

    // Populate ViewSwitcher
    viewSwitcher.addView(datePickerView, 0);
    viewSwitcher.addView(timePickerView, 1);
  }