예제 #1
0
  private static void bindTimePickerValue(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(), e);
    }

    ((TimePicker) view)
        .setOnTimeChangedListener(
            new OnTimeChangedListener() {

              @Override
              public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
                cal.set(Calendar.HOUR, hourOfDay);
                cal.set(Calendar.MINUTE, minute);
                try {
                  f2.set(target, cal.getTime());
                } catch (Exception e) {
                  Log.e("CleanDroid", e.getMessage(), e);
                }
              }
            });
  }
예제 #2
0
 /**
  * Produces a TimePicker set to the time produced by {@link #getTime()}. When overriding be sure
  * to call the super.
  *
  * @return a DatePicker with the date set
  */
 @Override
 protected View onCreateDialogView() {
   TimePicker timePicker = new TimePicker(getContext());
   timePicker.setIs24HourView(android.text.format.DateFormat.is24HourFormat(getContext()));
   Calendar calendar = getTime();
   timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
   timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
   timePicker.setOnTimeChangedListener(this);
   return timePicker;
 }
예제 #3
0
 private void init() {
   setPersistent(true);
   timePicker = new TimePicker(getContext());
   timePicker.setOnTimeChangedListener(this);
   timePicker.setIs24HourView(DateFormat.is24HourFormat(getContext()));
   timePicker.setLayoutParams(
       new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
   CustomDialog.Builder builder = new CustomDialog.Builder(getContext());
   builder.setTitle(getTitle().toString());
   builder.setContentView(timePicker);
   builder.setPositiveButton(R.string.ok, onClickListener);
   builder.setNegativeButton(R.string.cancel, onClickListener);
   dialog = builder.create(R.layout.custom_dialog_layout);
 }
예제 #4
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    date = (Date) getArguments().getSerializable(ARG_TIME);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    year = calendar.get(Calendar.YEAR);
    month = calendar.get(Calendar.MONTH);
    day = calendar.get(Calendar.DAY_OF_MONTH);
    int hour = calendar.get(Calendar.HOUR);
    int minute = calendar.get(Calendar.MINUTE);

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

    mTimePicker = (TimePicker) v.findViewById(R.id.dialog_time_time_picker);
    mTimePicker.setHour(hour);
    mTimePicker.setMinute(minute);

    mTimePicker.setOnTimeChangedListener(
        new TimePicker.OnTimeChangedListener() {
          @Override
          public void onTimeChanged(TimePicker view, int hour, int minute) {
            date = new GregorianCalendar(year, month, day, hour, minute).getTime();
            getArguments().putSerializable(EXTRA_TIME, date);
          }
        });

    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.getHour();
                int minute = mTimePicker.getMinute();
                /*Date date = (Date) getArguments().getSerializable(ARG_TIME);
                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);*/
                Date date = new GregorianCalendar(year, month, day, hour, minute).getTime();
                sendResult(Activity.RESULT_OK, date);
              }
            })
        .create();
  }
  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);
  }
  /*
   * (non-Javadoc)
   *
   * @see android.preference.DialogPreference#onCreateDialogView()
   */
  @Override
  protected View onCreateDialogView() {

    TimePicker tp = new TimePicker(getContext());
    tp.setIs24HourView(DateFormat.is24HourFormat(tp.getContext()));
    tp.setOnTimeChangedListener(this);

    int h = getHour();
    int m = getMinute();
    if (h >= 0 && m >= 0) {
      tp.setCurrentHour(h);
      tp.setCurrentMinute(m);
    }

    return tp;
  }
예제 #7
0
  private void initView() {
    calendarView = (MaterialCalendarView) findViewById(R.id.calendarView);
    newSchDate = (TextView) findViewById(R.id.new_sch_date);

    timePicker = (TimePicker) findViewById(R.id.timePicker);
    newSchTime = (TextView) findViewById(R.id.new_sch_time);
    timePicker.setOnTimeChangedListener(this);

    calendarView.setOnDateChangedListener(this);
    calendarView.setOnMonthChangedListener(this);

    spinner = (Spinner) findViewById(R.id.spinner_location);
    setCourseNames();

    schContentsNew = (EditText) findViewById(R.id.sch_contents_new);
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    mDate = (Date) getArguments().getSerializable(EXTRA_DATE);

    // Extract date info from Date object with Calendar object
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mDate);
    int hours = calendar.get(Calendar.HOUR_OF_DAY);
    int minutes = calendar.get(Calendar.MINUTE);

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

    TimePicker timePicker = (TimePicker) view.findViewById(R.id.dialog_time_timePicker);

    timePicker.setCurrentHour(hours);
    timePicker.setCurrentMinute(minutes);

    timePicker.setOnTimeChangedListener(
        new TimePicker.OnTimeChangedListener() {

          @Override
          public void onTimeChanged(TimePicker view, int hourOfDay, int minutes) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(mDate);
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            mDate = new GregorianCalendar(year, month, day, hourOfDay, minutes).getTime();
          }
        });

    return new AlertDialog.Builder(getActivity())
        .setView(view)
        .setTitle(R.string.time_picker_title)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {
                sendResult(Activity.RESULT_OK);
              }
            })
        .create();
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    mDate = (Date) getArguments().getSerializable(CrimeFragment.EXRA_DATE);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mDate);
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);

    View v = getActivity().getLayoutInflater().inflate(R.layout.dialog_time, null);

    TimePicker timePicker = (TimePicker) v.findViewById(R.id.dialog_time_timePicker);
    timePicker.setCurrentHour(hour);
    timePicker.setCurrentMinute(minute);

    timePicker.setOnTimeChangedListener(
        new OnTimeChangedListener() {

          @Override
          public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(mDate);
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);
            mDate = calendar.getTime();
          }
        });

    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) {
                sendResult(Activity.RESULT_OK);
              }
            })
        .create();
  }
예제 #10
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);
  }
  protected void onCreate(android.os.Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.title_choose_time);
    setContentView(R.layout.date_time_layout);
    createmeeting_date_start = (TextView) findViewById(R.id.createmeeting_date_start);
    createmeeting_date_to = (TextView) findViewById(R.id.createmeeting_date_to);
    createmeeting_date = (TextView) findViewById(R.id.createmeeting_date);

    createmeeting_date_start.setText("");
    createmeeting_date_to.setText("");
    createmeeting_date.setText("");
    layout_header = (LinearLayout) findViewById(R.id.layout_header);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) layout_header.getLayoutParams();
    params.topMargin = top;
    layout_header.setLayoutParams(params);
    datePicker = (DatePicker) findViewById(R.id.datePicker1);
    timePicker = (TimePicker) findViewById(R.id.timePicker1);

    datePicker.init(
        year,
        month,
        day,
        new OnDateChangedListener() {

          @Override
          public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

            DateTimeCreateDialog.this.year = year;
            DateTimeCreateDialog.this.month = monthOfYear;
            DateTimeCreateDialog.this.day = dayOfMonth;

            updateTime();
          }
        });

    timePicker.setOnTimeChangedListener(
        new OnTimeChangedListener() {

          @Override
          public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {

            hour = hourOfDay;
            minus = minute;
            updateTime();
          }
        });

    timePicker.setCurrentHour(hour);
    timePicker.setCurrentMinute(minus);

    if (type == CreateType.DAY) {
      timePicker.setVisibility(View.GONE);
      findViewById(R.id.layout_time).setVisibility(View.GONE);
    } else {
      datePicker.setVisibility(View.GONE);
      findViewById(R.id.layout_date).setVisibility(View.GONE);

      if (type == CreateType.TIME_END) {
        findViewById(R.id.layout_start).setVisibility(View.GONE);
      } else {
        findViewById(R.id.layout_end).setVisibility(View.GONE);
      }
    }

    updateTime();

    // TODO
    findViewById(R.id.layout_time).setVisibility(View.GONE);
    findViewById(R.id.layout_time).setVisibility(View.GONE);
  }
  private void updateRounds(final Patients p) {
    final Dialog in_d = new Dialog(getActivity());
    in_d.setTitle("Update Hospital Details");
    in_d.setContentView(R.layout.input_rounds_schedule);

    Calendar c = Calendar.getInstance();
    final EditText h_name = (EditText) in_d.findViewById(R.id.hospital_name_next);
    final EditText h_room = (EditText) in_d.findViewById(R.id.hospital_room_next);
    TimePicker timePicker = (TimePicker) in_d.findViewById(R.id.round_schedule);
    final View amPmView = ((ViewGroup) timePicker.getChildAt(0)).getChildAt(3);
    Button add_rounds_setup = (Button) in_d.findViewById(R.id.save_rounds_setup);
    Button cancel_rounds_setup = (Button) in_d.findViewById(R.id.cancel_rounds_setup);

    c.setTimeInMillis(p.getTime());
    h_name.setText(p.getHosp_name());
    h_room.setText(p.getHosp_room());
    timePicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(c.get(Calendar.MINUTE));

    mHour = timePicker.getCurrentHour();
    mMin = timePicker.getCurrentMinute();

    timePicker.setOnTimeChangedListener(
        new TimePicker.OnTimeChangedListener() {

          public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            mHour = hourOfDay;
            mMin = minute;
          }
        });

    add_rounds_setup.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            // Temporary Workaround bug on timepicker
            if (amPmView instanceof NumberPicker) {
              if (((NumberPicker) amPmView).getValue() == 1) {
                if (mHour >= 12) mHour = mHour - 12;
                mHour = mHour + 12;
              }

              if (((NumberPicker) amPmView).getValue() == 0) {
                if (mHour >= 12) mHour = mHour - 12;
              }
            }

            // Toast.makeText(getActivity(), "Time of this record is: "+formatTime(timeInMills),
            // Toast.LENGTH_LONG).show();
            Time time = new Time();
            time.hour = mHour;
            time.minute = mMin;
            timeInMills = time.toMillis(false);

            Patients patients = p;

            patients.setHosp_name(h_name.getText().toString());
            patients.setHosp_room(h_room.getText().toString());

            patients.setLocation(h_name.getText().toString() + " - " + h_room.getText().toString());
            patients.setTime(timeInMills);

            Toast.makeText(getActivity(), "Rounds Schedule Updated!", Toast.LENGTH_SHORT).show();
            help.update(patients, Helper.UPDATE_SCHEDULE);
            loadPatientMasterList();
            loadPatientList(1);
            in_d.cancel();
          }
        });

    cancel_rounds_setup.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            in_d.cancel();
          }
        });

    in_d.show();
  }
예제 #13
0
  public void show() {
    Calendar c = Calendar.getInstance();
    switch (chooseType) {
      case DATE:
        new DatePickerDialog(
                context,
                new DatePickerDialog.OnDateSetListener() {
                  public void onDateSet(
                      DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(
                        datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
                    targetView.setText(formatDateTime(calendar.getTime(), DF_YYYY_MM_DD));
                  }
                },
                c.get(Calendar.YEAR),
                c.get(Calendar.MONTH),
                c.get(Calendar.DATE))
            .show();
        break;
      case TIME:
        new TimePickerDialog(
                context,
                new TimePickerDialog.OnTimeSetListener() {
                  public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(
                        Calendar.YEAR,
                        Calendar.MONTH,
                        Calendar.DAY_OF_MONTH,
                        timePicker.getCurrentHour(),
                        timePicker.getCurrentMinute());
                    targetView.setText(formatDateTime(calendar.getTime(), DF_HH_MM_SS));
                  }
                },
                c.get(Calendar.HOUR_OF_DAY),
                c.get(Calendar.MINUTE),
                true)
            .show();
        break;
      default:
        LinearLayout dateTimeLayout =
            (LinearLayout)
                LayoutInflater.from(context)
                    .inflate(ToolResource.getLayoutId("view_datetime"), null);
        datePicker = (DatePicker) dateTimeLayout.findViewById(ToolResource.getIdId("datepicker"));
        timePicker = (TimePicker) dateTimeLayout.findViewById(ToolResource.getIdId("timepicker"));

        initDateTimePicker(datePicker, timePicker);
        timePicker.setIs24HourView(true);
        timePicker.setOnTimeChangedListener(mOnTimeChangedListener);

        dialog =
            new AlertDialog.Builder(context)
                .setTitle(nowDateTime)
                .setView(dateTimeLayout)
                .setPositiveButton(
                    android.R.string.ok,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                        targetView.setText(nowDateTime);
                      }
                    })
                .setNegativeButton(
                    android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int whichButton) {
                        targetView.setText("");
                      }
                    })
                .show();

        mOnDateChangedListener.onDateChanged(null, 0, 0, 0);
        break;
    }
  }
예제 #14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_morning_scheduler);
    startBedReportCal = Calendar.getInstance();

    sp = getSharedPreferences(Utilities.SP_BED_TIME, MODE_PRIVATE);
    boolean setDefault = (sp.getInt(Utilities.SP_KEY_BED_TIME_HOUR, -1) == -1 ? false : true);
    if (setDefault) {
      hour = sp.getInt(Utilities.SP_KEY_BED_TIME_HOUR, -1);
      minute = sp.getInt(Utilities.SP_KEY_BED_TIME_MINUTE, -1);
    }

    timeText = (TextView) findViewById(R.id.morning_text);
    timeBox = (CheckBox) findViewById(R.id.morning_box);
    timePicker = (TimePicker) findViewById(R.id.morning_picker);
    setPicker = (Button) findViewById(R.id.btnSchedule);
    backButton = (Button) findViewById(R.id.btnReturn);

    timeText.setText(Utilities.getMorningTimeWithFlag(this));

    timeBox.setChecked(setDefault);
    timeBox.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
            // TODO Auto-generated method stub
            if (arg1) {
              Log.d("test", "checked");
              timePicker.setEnabled(false);
            } else {
              Log.d("test", "unchecked");
              timePicker.setEnabled(true);
            }
          }
        });

    timePicker.setEnabled(!setDefault);
    //		timePicker.setIs24HourView(true)
    timePicker.setCurrentHour(hour);
    timePicker.setCurrentMinute(minute);
    timePicker.setOnTimeChangedListener(
        new OnTimeChangedListener() {

          @Override
          public void onTimeChanged(TimePicker arg0, int arg1, int arg2) {
            // TODO Auto-generated method stub

            Utilities.Log(TAG, "on time changed listener");

            hour = arg1;
            minute = arg2;
          }
        });

    setPicker.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View arg0) {
            // TODO Auto-generated method stub

            Utilities.Log(TAG, "" + hour + ":" + minute);

            if (hour >= 3 && hour < 12 || (hour == 12 && minute == 0)) {
              //				if(true){

              setAsDefault();
              Utilities.bedtimeComplete(MorningScheduler.this, hour, minute); // as following

              //					//set flag for bedtime, press-in survey should be blocked
              //					Utilities.morningReset(MorningScheduler.this);
              //
              //					//cancel all the running survey
              //					Utilities.cancelSchedule(MorningScheduler.this);
              //
              //					//schedule for next morning
              //					Utilities.scheduleMorningSurvey(MorningScheduler.this, hour, minute);
              //
              //					//next midnight
              //					Intent i = new Intent(Utilities.BD_ACTION_DAEMON);
              //					i.putExtra(Utilities.BD_ACTION_DAEMON_FUNC, -3);
              //					sendBroadcast(i);

              NumberFormat nf = NumberFormat.getInstance();
              nf.setMinimumIntegerDigits(2);

              Toast.makeText(
                      getApplicationContext(),
                      getString(R.string.bedtime_set)
                          + " "
                          + nf.format(hour)
                          + ":"
                          + nf.format(minute),
                      Toast.LENGTH_LONG)
                  .show();
              nf = null;

              try {
                Utilities.writeEventToFile(
                    MorningScheduler.this,
                    Utilities.CODE_BEDTIME,
                    Utilities.sdf.format(Utilities.getMorningCal(hour, minute).getTime()),
                    "",
                    "",
                    "",
                    Utilities.sdf.format(startBedReportCal.getTime()),
                    Utilities.sdf.format(Calendar.getInstance().getTime()));
              } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }

              finish();
            } else {
              Toast.makeText(getApplicationContext(), R.string.bedtime_alert, Toast.LENGTH_LONG)
                  .show();
            }
          }
        });

    backButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
          }
        });
  }
예제 #15
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    int type = this.getItemViewType(position);
    switch (type) {
      case TYPE_TIME:
        convertView = LayoutInflater.from(context).inflate(R.layout.time_item, null);
        TimePicker timepicker = (TimePicker) convertView.findViewById(R.id.timePicker);
        timepicker.setIs24HourView(true);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(newalarm.timeinmillis);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        timepicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
        timepicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
        timepicker.setOnTimeChangedListener(
            new OnTimeChangedListener() {
              @Override
              public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                // TODO Auto-generated method stub
                Calendar calendar = Calendar.getInstance();
                calendar.setTimeInMillis(newalarm.timeinmillis);
                calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                calendar.set(Calendar.MINUTE, minute);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);
                //					if (calendar.getTimeInMillis() <= System
                //							.currentTimeMillis()) {
                //						newalarm.timeinmillis = calendar.getTimeInMillis() + 24 * 3600 * 1000;
                //					} else {
                newalarm.timeinmillis = calendar.getTimeInMillis();
                //					}
              }
            });
        break;
      case TYPE_DESCRIPTION:
        convertView = LayoutInflater.from(context).inflate(R.layout.name_item, null);
        EditText edittext = (EditText) convertView.findViewById(R.id.name_text);
        edittext.setText(newalarm.description);
        edittext.addTextChangedListener(
            new TextWatcher() {

              @Override
              public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // TODO Auto-generated method stub

              }

              @Override
              public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub

              }

              @Override
              public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
                newalarm.description = s.toString();
              }
            });
        break;
      case TYPE_ENABLE:
        convertView = LayoutInflater.from(context).inflate(R.layout.enable_item, null);
        final CheckBox checkbox = (CheckBox) convertView.findViewById(R.id.enable_checkbox);
        checkbox.setChecked(newalarm.enable);
        checkbox.setOnCheckedChangeListener(
            new OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                Log.e("setting", "checked:" + isChecked);
                newalarm.enable = isChecked;
              }
            });
        convertView.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                boolean isChecked = checkbox.isChecked();
                newalarm.enable = !isChecked;
                checkbox.setChecked(!isChecked);
              }
            });
        break;
      case TYPE_FREQUENCY:
        convertView = LayoutInflater.from(context).inflate(R.layout.frequency_item, null);
        final TextView textview = (TextView) convertView.findViewById(R.id.frequency_text);
        textview.setText(AlarmParser.getFrequencyText(newalarm));
        final boolean[] selecteddays = AlarmParser.getSelectedDaysofweek(newalarm);
        LinearLayout frequencylayout =
            (LinearLayout) convertView.findViewById(R.id.frequencyLayout);
        frequencylayout.setOnClickListener(
            new OnClickListener() {
              int selected = newalarm.frequency;

              @Override
              public void onClick(View v) {
                // TODO Auto-generated method stub
                Log.e("setting", "frequency clicked");
                Dialog alertDialog =
                    new AlertDialog.Builder(context)
                        .setTitle("重复模式")
                        .setSingleChoiceItems(
                            R.array.frequencytype,
                            newalarm.frequency,
                            new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub
                                selected = which;
                              }
                            })
                        .setPositiveButton(
                            R.string.confirm,
                            new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub
                                switch (selected) {
                                  case 0:
                                    newalarm.frequency = AlarmInfo.FREQUENCY_ONCE;
                                    newalarm.daysofweek = 0;
                                    break;
                                  case 1:
                                    newalarm.frequency = AlarmInfo.FREQUENCY_EVERYDAY;
                                    newalarm.daysofweek = 0;
                                    break;
                                  case 2:
                                    Dialog alertDialog =
                                        new AlertDialog.Builder(context)
                                            .setTitle("重复")
                                            .setMultiChoiceItems(
                                                R.array.daysofweek,
                                                selecteddays,
                                                new OnMultiChoiceClickListener() {
                                                  @Override
                                                  public void onClick(
                                                      DialogInterface dialog,
                                                      int which,
                                                      boolean isChecked) {
                                                    // TODO
                                                    // Auto-generated
                                                    // method
                                                    // stub
                                                    selecteddays[which] = isChecked;
                                                  }
                                                })
                                            .setPositiveButton(
                                                "确定",
                                                new DialogInterface.OnClickListener() {
                                                  @Override
                                                  public void onClick(
                                                      DialogInterface dialog, int which) {
                                                    // TODO
                                                    // Auto-generated
                                                    // method
                                                    // stub
                                                    newalarm.frequency =
                                                        AlarmInfo.FREQUENCY_SPECIFIED;
                                                    newalarm.daysofweek =
                                                        AlarmParser.daysofweek_ArraytoInt(
                                                            selecteddays);
                                                    if (newalarm.daysofweek == 0)
                                                      newalarm.frequency = AlarmInfo.FREQUENCY_ONCE;
                                                    textview.setText(
                                                        AlarmParser.getFrequencyText(newalarm));
                                                  }
                                                })
                                            .setNegativeButton(
                                                "取消",
                                                new DialogInterface.OnClickListener() {
                                                  @Override
                                                  public void onClick(
                                                      DialogInterface dialog, int which) {
                                                    // TODO
                                                    // Auto-generated
                                                    // method
                                                    // stub

                                                  }
                                                })
                                            .create();
                                    alertDialog.show();
                                    break;
                                  case 3:
                                    Dialog datedialog =
                                        new CustomDatePickerDialog(
                                            context,
                                            new OnDateSetListener() {
                                              @Override
                                              public void onDateSet(
                                                  DatePicker view,
                                                  int year,
                                                  int monthOfYear,
                                                  int dayOfMonth) {
                                                // TODO
                                                // Auto-generated
                                                // method stub
                                                Calendar calendar = Calendar.getInstance();
                                                calendar.setTimeInMillis(newalarm.timeinmillis);
                                                calendar.set(year, monthOfYear, dayOfMonth);
                                                newalarm.timeinmillis = calendar.getTimeInMillis();
                                                newalarm.frequency = AlarmInfo.FREQUENCY_INTERNAL;
                                                newalarm.daysofweek = 0;
                                                textview.setText(
                                                    AlarmParser.getFrequencyText(newalarm));
                                              }
                                            },
                                            newalarm.getYear(),
                                            newalarm.getMonth(),
                                            newalarm.getDayOfMonth(),
                                            "请选择首日上班时间");
                                    datedialog.show();
                                    break;
                                  default:
                                    break;
                                }
                                textview.setText(AlarmParser.getFrequencyText(newalarm));
                              }
                            })
                        .setNegativeButton(
                            R.string.cancel,
                            new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                // TODO Auto-generated method stub

                              }
                            })
                        .create();
                alertDialog.show();

                // Dialog alertDialog = new
                // AlertDialog.Builder(context).setTitle("重复").setMultiChoiceItems(R.array.daysofweek,
                // selecteddays, new OnMultiChoiceClickListener(){
                // @Override
                // public void onClick(DialogInterface dialog, int which,
                // boolean isChecked) {
                // // TODO Auto-generated method stub
                // selecteddays[which] = isChecked;
                // }
                //
                // }).setPositiveButton("确定", new
                // DialogInterface.OnClickListener(){
                // @Override
                // public void onClick(DialogInterface dialog, int which) {
                // // TODO Auto-generated method stub
                // newalarm.daysofweek =
                // AlarmParser.daysofweek_ArraytoInt(selecteddays);
                // }
                // }).setNegativeButton("取消", new
                // DialogInterface.OnClickListener(){
                // @Override
                // public void onClick(DialogInterface dialog, int which) {
                // // TODO Auto-generated method stub
                //
                // }
                // }).create();
                // alertDialog.show();
              }
            });
        break;
      case TYPE_NULL:
        convertView = null;
        break;
      default:
        convertView = null;
        break;
    }

    return convertView;
  }
  /**
   * 생성자
   *
   * @param context
   * @param attrs
   */
  public DateTimePicker(Context context, AttributeSet attrs) {
    super(context, attrs);

    // XML 레이아웃을 인플레이션함
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.datetimepicker, this, true);

    // 시간 정보 참조
    Calendar calendar = Calendar.getInstance();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DataTimePicker);
    final int _currentYear = a.getInt(R.styleable.DataTimePicker_year, calendar.get(Calendar.YEAR));
    final int _currentMonth =
        a.getInt(R.styleable.DataTimePicker_month, calendar.get(Calendar.MONTH));
    final int _currentDay =
        a.getInt(R.styleable.DataTimePicker_day, calendar.get(Calendar.DAY_OF_MONTH));
    final int _currentHour =
        a.getInt(R.styleable.DataTimePicker_hour, calendar.get(Calendar.HOUR_OF_DAY));
    final int _currentMinute =
        a.getInt(R.styleable.DataTimePicker_minute, calendar.get(Calendar.MINUTE));

    // 날짜선택 위젯 초기화
    datePicker = (DatePicker) findViewById(R.id.datePicker);
    datePicker.init(
        _currentYear,
        _currentMonth,
        _currentDay,
        new OnDateChangedListener() {
          public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            // 새로 정의한 리스너로 이벤트 전달
            if (onDateTimeChangedListener != null) {
              onDateTimeChangedListener.onDateTimeChanged(
                  DateTimePicker.this,
                  year,
                  monthOfYear,
                  dayOfMonth,
                  timePicker.getCurrentHour(),
                  timePicker.getCurrentMinute());
            }
          }
        });

    // 체크박스 이벤트 처리
    enableTimeCheckBox = (CheckBox) findViewById(R.id.enableTimeCheckBox);
    enableTimeCheckBox.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            timePicker.setEnabled(isChecked);
            timePicker.setVisibility(
                (enableTimeCheckBox).isChecked() ? View.VISIBLE : View.INVISIBLE);
          }
        });

    // 시간선택 위젯 이벤트 처리
    timePicker = (TimePicker) findViewById(R.id.timePicker);
    timePicker.setOnTimeChangedListener(
        new OnTimeChangedListener() {
          public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            if (onDateTimeChangedListener != null) {
              onDateTimeChangedListener.onDateTimeChanged(
                  DateTimePicker.this,
                  datePicker.getYear(),
                  datePicker.getMonth(),
                  datePicker.getDayOfMonth(),
                  hourOfDay,
                  minute);
            }
          }
        });

    timePicker.setCurrentHour(_currentHour);
    timePicker.setCurrentMinute(_currentMinute);
    timePicker.setEnabled(enableTimeCheckBox.isChecked());
    timePicker.setVisibility((enableTimeCheckBox.isChecked() ? View.VISIBLE : View.INVISIBLE));
  }
  private void updateRounds(final Patients p) {
    final Dialog in_d = new Dialog(getActivity());
    in_d.setTitle("Update Hospital Details");
    in_d.setContentView(R.layout.input_rounds_schedule);

    Calendar c = Calendar.getInstance();
    final EditText h_name = (EditText) in_d.findViewById(R.id.hospital_name_next);
    final EditText h_room = (EditText) in_d.findViewById(R.id.hospital_room_next);
    TimePicker timePicker = (TimePicker) in_d.findViewById(R.id.round_schedule);
    final View amPmView = ((ViewGroup) timePicker.getChildAt(0)).getChildAt(3);
    save = (Button) in_d.findViewById(R.id.save_rounds_setup);
    Button cancel_rounds_setup = (Button) in_d.findViewById(R.id.cancel_rounds_setup);
    save.setEnabled(false);

    c.setTimeInMillis(p.getTime());
    h_name.setText(p.getHosp_name());
    h_room.setText(p.getHosp_room());
    timePicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(c.get(Calendar.MINUTE));

    mHour = timePicker.getCurrentHour();
    mMin = timePicker.getCurrentMinute();

    timePicker.setOnTimeChangedListener(
        new TimePicker.OnTimeChangedListener() {

          public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            mHour = hourOfDay;
            mMin = minute;
            save.setEnabled(true);
          }
        });

    h_name.addTextChangedListener(this);
    h_room.addTextChangedListener(this);

    save.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
            build.setMessage("Are all edits Correct?");
            build.setCancelable(false);
            build.setPositiveButton(
                "Yes",
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                    // Temporary Workaround bug on timepicker
                    if (amPmView instanceof NumberPicker) {
                      if (((NumberPicker) amPmView).getValue() == 1) {
                        if (mHour >= 12) mHour = mHour - 12;
                        mHour = mHour + 12;
                      }

                      if (((NumberPicker) amPmView).getValue() == 0) {
                        if (mHour >= 12) mHour = mHour - 12;
                      }
                    }

                    // Toast.makeText(getActivity(), "Time of this record is:
                    // "+formatTime(timeInMills), Toast.LENGTH_LONG).show();

                    Time time = new Time();
                    time.hour = mHour;
                    time.minute = mMin;
                    time.second = 0;
                    timeInMills = time.toMillis(false);

                    Patients patients = p;

                    patients.setHosp_name(h_name.getText().toString());
                    patients.setHosp_room(h_room.getText().toString());

                    patients.setLocation(
                        h_name.getText().toString() + " - " + h_room.getText().toString());
                    patients.setTime(timeInMills);

                    Toast.makeText(getActivity(), "Rounds Schedule Updated!", Toast.LENGTH_SHORT)
                        .show();
                    help.update(patients, Helper.UPDATE_SCHEDULE);
                    // Helper.scheduleRepeatingAlarm(getActivity(), patients,
                    // patients.getRequestCode(), patients.getTime());
                    loadPatientMasterList();
                    loadPatientList(1);
                    in_d.cancel();
                  }
                });
            build.setNegativeButton(
                "No",
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                  }
                });

            AlertDialog alert = build.create();
            alert.show();
          }
        });

    cancel_rounds_setup.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            in_d.cancel();
          }
        });

    in_d.show();
  }