private void populateFields() {
   if (currentEntity.isUpdate()) {
     int dayPos =
         getPositionOf(
             getResources().getStringArray(R.array.days_array),
             currentEntity.getValue("day").toString());
     daySpinner.setSelection(dayPos);
     classRoom.setText(currentEntity.getValue("room").toString());
     classStart.setCurrentHour(currentEntity.getInt("starttimehour"));
     classStart.setCurrentMinute(currentEntity.getInt("starttimeminute"));
     classEnd.setCurrentHour(currentEntity.getInt("endtimehour"));
     classEnd.setCurrentMinute(currentEntity.getInt("endtimeminute"));
   }
 }
    @Override
    public void onClick(View v) {

      /*TimePickerDialog timeDialog = new TimePickerDialog(TaskDetailActivity.this, new TimePickerDialog.OnTimeSetListener()
      {
          @Override
          public void onTimeSet(TimePicker view, int hourOfDay, int minute)
          {
              TaskDetailActivity.this.alarm.setTime(Utils.getCalendar(hourOfDay, minute));
              TaskDetailActivity.this.updateView();
          }
      }, TaskDetailActivity.this.alarm.getHour(), TaskDetailActivity.this.alarm.getMinute(), true);
      timeDialog.show();*/
      final TimePicker timePicker = new TimePicker(TaskDetailActivity.this);
      timePicker.setIs24HourView(true);
      timePicker.setCurrentHour(TaskDetailActivity.this.editAlarm.getHour());
      timePicker.setCurrentMinute(TaskDetailActivity.this.editAlarm.getMinute());
      new AlertDialog.Builder(TaskDetailActivity.this)
          .setTitle(TaskDetailActivity.this.getString(R.string.alertDialogTimeChoose_title))
          .setIcon(android.R.drawable.ic_dialog_info)
          .setView(timePicker)
          .setPositiveButton(
              TaskDetailActivity.this.getString(R.string.alertDialog_positive),
              new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                  TaskDetailActivity.this.editAlarm.setTime(
                      timePicker.getCurrentHour(), timePicker.getCurrentMinute());
                  TaskDetailActivity.this.txtTimeView.setText(
                      TaskDetailActivity.this.editAlarm.getTimeStr(TaskDetailActivity.this));
                }
              })
          .setNegativeButton(TaskDetailActivity.this.getString(R.string.alertDialog_negative), null)
          .show();
    }
  @Override
  protected void onBindDialogView(View v) {
    super.onBindDialogView(v);

    picker.setCurrentHour(lastHour);
    picker.setCurrentMinute(lastMinute);
  }
Example #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate Started");

    setContentView(R.layout.alarm_controller);

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    tpAlarm = (TimePicker) findViewById(R.id.tpAlarm);
    chkSnooze = (CheckBox) findViewById(R.id.chkSnooze);
    etxtSnoozeMin = (EditText) findViewById(R.id.etxtSnoozeMin);
    Button button = (Button) findViewById(R.id.btnSetAlarm);
    button.setOnClickListener(setAlarmListener);

    btnSetTone = (Button) findViewById(R.id.btnSetTone);
    btnSetTone.setOnClickListener(setTone);

    tpAlarm.setCurrentHour(prefs.getInt(M_HOUR, 0));
    tpAlarm.setCurrentMinute(prefs.getInt(M_MINT, 0));
    chkSnooze.setChecked(prefs.getBoolean(M_SNOOZE, false));
    etxtSnoozeMin.setText(prefs.getString(SNOOZE_T, "0"));

    Locale loc = new Locale("en");
    Log.i(TAG, Arrays.toString(loc.getAvailableLocales()));
  }
  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();
  }
Example #6
0
  @Override
  protected void onResume() {
    Log.d(TAG, "onResume");
    super.onResume();

    tpAlarm.setCurrentHour(prefs.getInt(M_HOUR, 0));
    tpAlarm.setCurrentMinute(prefs.getInt(M_MINT, 0));
    chkSnooze.setChecked(prefs.getBoolean(M_SNOOZE, false));
    etxtSnoozeMin.setText(prefs.getString(SNOOZE_T, "0"));

    if (prefs.getString(TONE, null) != null) {
      String tone = prefs.getString(TONE, null);
      File f = new File("" + tone);
      btnSetTone.setText("Tone " + f.getName());
    } else btnSetTone.setText(getString(R.string.btn_SetAlarmTone));

    if (prefs.getBoolean(FIRST_LAUNCH, true)) {
      Intent checkIntent = new Intent();
      checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
      startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);

      SharedPreferences.Editor editor = prefs.edit();

      editor.putBoolean(FIRST_LAUNCH, false);
      editor.commit();
    }
  }
Example #7
0
  /** @see Widget.setProperty. */
  @Override
  public boolean setProperty(String property, String value)
      throws PropertyConversionException, InvalidPropertyValueException {
    if (super.setProperty(property, value)) {
      return true;
    }

    TimePicker timePicker = (TimePicker) getView();

    if (property.equals(IX_WIDGET.MAW_TIME_PICKER_CURRENT_HOUR)) {
      int hour = IntConverter.convert(value);
      if (hour < 0 || hour > 23) {
        throw new InvalidPropertyValueException(property, value);
      }
      timePicker.setCurrentHour(IntConverter.convert(value));
    } else if (property.equals(IX_WIDGET.MAW_TIME_PICKER_CURRENT_MINUTE)) {
      int minute = IntConverter.convert(value);
      if (minute < 0 || minute > 59) {
        throw new InvalidPropertyValueException(property, value);
      }
      timePicker.setCurrentMinute(IntConverter.convert(value));
    } else {
      return false;
    }
    return true;
  }
  /** Sets the timePicker to the current time. Used on page load */
  private void setCurrentTimeOnView() {
    final Calendar cal = Calendar.getInstance();
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);

    scheduleTimePicker.setCurrentHour(hour);
    scheduleTimePicker.setCurrentMinute(minute);
  }
 private void initTimePicker(Date crimeDate) {
   Calendar calendar = Calendar.getInstance();
   calendar.setTime(crimeDate);
   int hour = calendar.get(Calendar.HOUR_OF_DAY);
   int minute = calendar.get(Calendar.MINUTE);
   mTimePicker.setCurrentHour(hour);
   mTimePicker.setCurrentMinute(minute);
 }
Example #10
0
    public View getView(Context context) throws UnsupportedOperationException {
      if (mType.equals("date")) {
        try {
          DateTimePicker input =
              new DateTimePicker(context, "yyyy-MM-dd", mValue, DateTimePicker.PickersState.DATE);
          input.toggleCalendar(true);
          mView = (View) input;
        } catch (UnsupportedOperationException ex) {
          // We can't use our custom version of the DatePicker widget because the sdk is too old.
          // But we can fallback on the native one.
          DatePicker input = new DatePicker(context);
          try {
            if (!TextUtils.isEmpty(mValue)) {
              GregorianCalendar calendar = new GregorianCalendar();
              calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(mValue));
              input.updateDate(
                  calendar.get(Calendar.YEAR),
                  calendar.get(Calendar.MONTH),
                  calendar.get(Calendar.DAY_OF_MONTH));
            }
          } catch (Exception e) {
            Log.e(LOGTAG, "error parsing format string: " + e);
          }
          mView = (View) input;
        }
      } else if (mType.equals("week")) {
        DateTimePicker input =
            new DateTimePicker(context, "yyyy-'W'ww", mValue, DateTimePicker.PickersState.WEEK);
        mView = (View) input;
      } else if (mType.equals("time")) {
        TimePicker input = new TimePicker(context);
        input.setIs24HourView(DateFormat.is24HourFormat(context));

        GregorianCalendar calendar = new GregorianCalendar();
        if (!TextUtils.isEmpty(mValue)) {
          try {
            calendar.setTime(new SimpleDateFormat("HH:mm").parse(mValue));
          } catch (Exception e) {
          }
        }
        input.setCurrentHour(calendar.get(GregorianCalendar.HOUR_OF_DAY));
        input.setCurrentMinute(calendar.get(GregorianCalendar.MINUTE));
        mView = (View) input;
      } else if (mType.equals("datetime-local") || mType.equals("datetime")) {
        DateTimePicker input =
            new DateTimePicker(
                context, "yyyy-MM-dd HH:mm", mValue, DateTimePicker.PickersState.DATETIME);
        input.toggleCalendar(true);
        mView = (View) input;
      } else if (mType.equals("month")) {
        DateTimePicker input =
            new DateTimePicker(context, "yyyy-MM", mValue, DateTimePicker.PickersState.MONTH);
        mView = (View) input;
      }
      return mView;
    }
  public void setWaktus(List<Long> waktus) {
    this.waktus = waktus;
    if (waktus != null && waktus.size() > 0) {

      Calendar cal = Calendar.getInstance();

      TimePicker time1 = (TimePicker) findViewById(R.id.monitoringTime1);
      long waktu1 = waktus.get(0);
      cal.setTimeInMillis(waktu1);
      time1.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
      time1.setCurrentMinute(cal.get(Calendar.MINUTE));

      TimePicker time2 = (TimePicker) findViewById(R.id.monitoringTime2);
      long waktu2 = waktus.get(1);
      cal.setTimeInMillis(waktu2);
      time2.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
      time2.setCurrentMinute(cal.get(Calendar.MINUTE));
    }
  }
Example #12
0
 @Override
 protected void onClick() {
   int h = getHour();
   int m = getMinute();
   if (h >= 0 && m >= 0) {
     timePicker.setCurrentHour(h);
     timePicker.setCurrentMinute(m);
   }
   dialog.show();
 }
Example #13
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;
 }
Example #14
0
  @Override
  protected View onCreateDialogView() {
    value = getPersistedValue();

    timePicker = new TimePicker(getContext());
    timePicker.setIs24HourView(true);
    timePicker.setCurrentHour(value.first);
    timePicker.setCurrentMinute(value.second);

    return timePicker;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.new_alarm_layout);

    this.taskNameView = (EditText) findViewById(R.id.taskNameView);
    this.datePicker = (DatePicker) findViewById(R.id.datePicker);
    this.timePicker = (TimePicker) findViewById(R.id.timePicker);
    this.setTaskBtn = (Button) findViewById(R.id.setTaskBtn);

    timePicker.setCurrentMinute(timePicker.getCurrentMinute() + 1);

    this.setTaskBtn.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {

            if (taskNameView.getText().toString().trim().length() < 1) {
              // create alert show no task name given
              AlertDialog alert =
                  new Builder(NewAlarmActivity.this)
                      .setTitle("Ups!")
                      .setMessage("Task name is empty")
                      .setNeutralButton("OK", null)
                      .create();
              alert.show();
            } else {
              // get name of the task new alarm , or something else ...
              Intent intent = new Intent(NewAlarmActivity.this, NewAlarmReciever.class);
              intent.putExtra("ALARM_NAME", taskNameView.getText().toString().trim());
              PendingIntent toReciever =
                  PendingIntent.getBroadcast(
                      NewAlarmActivity.this,
                      new Random().nextInt(65000),
                      intent,
                      PendingIntent.FLAG_ONE_SHOT);

              Calendar calendar = Calendar.getInstance();
              calendar.setTimeInMillis(System.currentTimeMillis());
              calendar.clear();
              calendar.set(
                  datePicker.getYear(),
                  datePicker.getMonth(),
                  datePicker.getDayOfMonth(),
                  timePicker.getCurrentHour(),
                  timePicker.getCurrentMinute());
              AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
              alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), toReciever);

              Toast.makeText(getApplicationContext(), "Alarm set", Toast.LENGTH_SHORT).show();
            }
          }
        });
  }
  private void showDialog_Layout(Context context, String text, int src) {
    LayoutInflater inflater = LayoutInflater.from(this);

    final int currentSelect = src;
    final View timeSetView = inflater.inflate(R.layout.time_dialog, null);
    final TextView tv = (TextView) this.findViewById(src);

    final TimePicker timePicker = (TimePicker) timeSetView.findViewById(R.id.timePicker);
    int index = rId2Index.get(Integer.valueOf(src));
    timePicker.setCurrentHour(hour[index]);
    timePicker.setCurrentMinute(minute[index]);

    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);
    // builder.setIcon(R.drawable.icon); customize icon
    builder.setTitle(text);
    builder.setView(timeSetView);
    builder.setPositiveButton(
        "确认",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            int hour = timePicker.getCurrentHour();
            int minute = timePicker.getCurrentMinute();
            int index = rId2Index.get(Integer.valueOf(currentSelect));

            if (minute < 10) {
              tv.setText(Constants.PREFIX[index] + hour + ":" + "0" + minute);
            } else {
              tv.setText(Constants.PREFIX[index] + hour + ":" + minute);
            }

            Message msg = mHandler.obtainMessage(MSG_UI_UPDATE_TIME);
            Bundle bundle = new Bundle();
            bundle.putInt("index", index);
            bundle.putInt("src", currentSelect);
            bundle.putInt("hour", hour);
            bundle.putInt("minute", minute);
            msg.setData(bundle);

            msg.sendToTarget();
          }
        });
    builder.setNegativeButton(
        "取消",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            setTitle("");
          }
        });
    builder.show();
  }
Example #17
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);
            }
          }
        });
  }
  /*
   * (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;
  }
  @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();
  }
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   Log.i(TAG, "On create view...");
   // Inflate the layout for this fragment
   LocalTime time = LocalTime.now();
   if (getArguments() != null) {
     time = new DateTime(getArguments().getLong(ARG_TIME)).toLocalTime();
   }
   View view = inflater.inflate(R.layout.fragment_time_picker, container, false);
   mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
     mTimePicker.setHour(time.getHourOfDay());
     mTimePicker.setMinute(time.getMinuteOfHour());
   } else {
     mTimePicker.setCurrentHour(time.getHourOfDay());
     mTimePicker.setCurrentMinute(time.getMinuteOfHour());
   }
   return view;
 }
  @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;
    }
  }
Example #23
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.date_time_picker);

    final TimePicker timePicker = (TimePicker) findViewById(R.id.time_picker);
    timePicker.setIs24HourView(true);

    final DatePicker datePicker = (DatePicker) findViewById(R.id.date_picker);

    Intent intent = getIntent();
    Date date = new Date();
    int day = intent.getIntExtra("day", date.getDay());
    int month = intent.getIntExtra("month", date.getMonth() + 1) - 1;
    int year = intent.getIntExtra("year", date.getYear());

    int hours = intent.getIntExtra("hours", date.getHours());
    int minutes = intent.getIntExtra("minutes", date.getMinutes());

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

    datePicker.updateDate(year, month, day);

    Button setDateTimeButton = (Button) findViewById(R.id.date_time_set);
    setDateTimeButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            intent.putExtra("day", datePicker.getDayOfMonth());
            intent.putExtra("month", datePicker.getMonth() + 1);
            intent.putExtra("year", datePicker.getYear());
            intent.putExtra("hours", timePicker.getCurrentHour());
            intent.putExtra("minutes", timePicker.getCurrentMinute());
            setResult(RESULT_OK, intent);
            finish();
          }
        });
  }
Example #24
0
  /**
   * * 初始化日期时间选择控件
   *
   * @param datePicker 日期控件
   * @param timePicker 时间控件
   * @return
   */
  private String initDateTimePicker(DatePicker datePicker, TimePicker timePicker) {
    Calendar calendar = Calendar.getInstance();
    nowDateTime =
        calendar.get(Calendar.YEAR)
            + "-"
            + calendar.get(Calendar.MONTH)
            + "-"
            + calendar.get(Calendar.DAY_OF_MONTH)
            + " "
            + calendar.get(Calendar.HOUR_OF_DAY)
            + ":"
            + calendar.get(Calendar.MINUTE)
            + calendar.get(Calendar.SECOND);
    datePicker.init(
        calendar.get(Calendar.YEAR),
        calendar.get(Calendar.MONTH),
        calendar.get(Calendar.DAY_OF_MONTH),
        mOnDateChangedListener);

    timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));

    return nowDateTime;
  }
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    mDate = (Date) getArguments().getSerializable(ARG_DATE);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mDate);

    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minutes = calendar.get(Calendar.MINUTE);

    final TimePicker timePickerView =
        (TimePicker) LayoutInflater.from(getActivity()).inflate(R.layout.dialog_time, null);
    timePickerView.setIs24HourView(true);
    timePickerView.setCurrentHour(hour);
    timePickerView.setCurrentMinute(minutes);

    return new AlertDialog.Builder(getActivity())
        .setView(timePickerView)
        .setTitle(R.string.date_picker_title)
        .setPositiveButton(
            android.R.string.ok,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(mDate);
                calendar.set(Calendar.HOUR, timePickerView.getCurrentHour());
                calendar.set(Calendar.MINUTE, timePickerView.getCurrentMinute());

                mDate = calendar.getTime();
                sendResult(Activity.RESULT_OK, mDate);
              }
            })
        .create();
  }
  @Override
  public Dialog onCreateDialog(Bundle saveInstanceState) {
    mDate = (Date) getArguments().getSerializable(ARG_TIME);

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mDate);
    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.setCurrentHour(hour);
    mTimePicker.setCurrentMinute(minute);

    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) {
                final int hour = mTimePicker.getCurrentHour();
                final int minute = mTimePicker.getCurrentMinute();

                Calendar calendar = new GregorianCalendar();
                calendar.setTime(mDate);
                calendar.set(Calendar.HOUR, hour);
                calendar.set(Calendar.MINUTE, minute);

                sendResult(CrimeListActivity.RESULT_OK, calendar.getTime());
              }
            })
        .create();
  }
 /** Display the dialog window that allows the user to set the quiet time hours. */
 private void showQuietTimePeriodDialog() {
   LayoutInflater inflater =
       (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   View view = inflater.inflate(R.layout.quiet_time_period_dialog, null);
   final TimePicker startTimePicker = (TimePicker) view.findViewById(R.id.start_time_picker);
   final TimePicker stopTimePicker = (TimePicker) view.findViewById(R.id.stop_time_picker);
   // Sets the view format based on the users time format preference.
   if (_preferences
       .getString(Constants.TIME_FORMAT_KEY, Constants.TIME_FORMAT_DEFAULT)
       .equals(Constants.TIME_FORMAT_24_HOUR)) {
     startTimePicker.setIs24HourView(true);
     stopTimePicker.setIs24HourView(true);
   } else {
     startTimePicker.setIs24HourView(false);
     stopTimePicker.setIs24HourView(false);
   }
   // Initialize the TimePickers
   String startTime = _preferences.getString(Constants.QUIET_TIME_START_TIME_KEY, "");
   String stopTime = _preferences.getString(Constants.QUIET_TIME_STOP_TIME_KEY, "");
   if (!startTime.equals("")) {
     String[] startTimeArray = startTime.split("-");
     if (startTimeArray.length == 2) {
       startTimePicker.setCurrentHour(Integer.parseInt(startTimeArray[0]));
       startTimePicker.setCurrentMinute(Integer.parseInt(startTimeArray[1]));
     } else {
       Log.e(_context, "QuietTimePreferenceActivity() Quiet Time StartTime ERROR: " + startTime);
     }
   }
   if (!stopTime.equals("")) {
     String[] stopTimeArray = stopTime.split("-");
     if (stopTimeArray.length == 2) {
       stopTimePicker.setCurrentHour(Integer.parseInt(stopTimeArray[0]));
       stopTimePicker.setCurrentMinute(Integer.parseInt(stopTimeArray[1]));
     } else {
       Log.e(_context, "QuietTimePreferenceActivity() Quiet Time StopTime ERROR: " + stopTime);
     }
   }
   // Build & Display Dialog
   AlertDialog.Builder quietTimePeriodAlertBuilder = new AlertDialog.Builder(_context);
   try {
     quietTimePeriodAlertBuilder.setIcon(android.R.drawable.ic_dialog_info);
   } catch (Exception ex) {
     // Don't set the icon if this fails.
   }
   quietTimePeriodAlertBuilder.setTitle(R.string.preference_quiet_time_quiet_period_title);
   quietTimePeriodAlertBuilder.setView(view);
   quietTimePeriodAlertBuilder.setPositiveButton(
       android.R.string.ok,
       new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
           SharedPreferences.Editor editor = _preferences.edit();
           editor.putString(
               Constants.QUIET_TIME_START_TIME_KEY,
               startTimePicker.getCurrentHour() + "-" + startTimePicker.getCurrentMinute());
           editor.putString(
               Constants.QUIET_TIME_STOP_TIME_KEY,
               stopTimePicker.getCurrentHour() + "-" + stopTimePicker.getCurrentMinute());
           editor.commit();
           Toast.makeText(
                   _context,
                   _context.getString(R.string.preference_quiet_time_period_set),
                   Toast.LENGTH_LONG)
               .show();
         }
       });
   quietTimePeriodAlertBuilder.show();
 }
 @Override
 protected void onBindDialogView(@NonNull View v) {
   super.onBindDialogView(v);
   m_picker.setCurrentHour(m_minutes / 60);
   m_picker.setCurrentMinute(m_minutes % 60);
 }
  @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;
  }
Example #30
0
  private void pickDelay() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MINUTE, 1);

    int mYear = c.get(Calendar.YEAR);
    int mMonth = c.get(Calendar.MONTH);
    int mDay = c.get(Calendar.DAY_OF_MONTH);
    int mHour = c.get(Calendar.HOUR_OF_DAY);
    int mMinute = c.get(Calendar.MINUTE);

    View multiPickerLayout = LayoutInflater.from(this).inflate(R.layout.delaypicker, null);
    final DatePicker multiPickerDate =
        (DatePicker) multiPickerLayout.findViewById(R.id.multipicker_date);
    final TimePicker multiPickerTime =
        (TimePicker) multiPickerLayout.findViewById(R.id.multipicker_time);

    multiPickerDate.updateDate(mYear, mMonth, mDay);

    multiPickerTime.setCurrentHour(mHour);
    multiPickerTime.setCurrentMinute(mMinute);
    try {
      multiPickerDate.setMinDate(System.currentTimeMillis() + 10000);
    } catch (Exception e) {
      e.printStackTrace();
    }

    DialogInterface.OnClickListener dialogButtonListener =
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              case DialogInterface.BUTTON_NEGATIVE:
                {
                  Log.e(TAG, "Cancel delay");
                  dialog.dismiss();
                  break;
                }
              case DialogInterface.BUTTON_POSITIVE:
                {
                  service_status.setText("Scheduling service...");
                  if (isMyServiceRunning(SoundService.class)) {
                    stopService(new Intent(MainActivity.this, SoundService.class));
                  }
                  Intent i = new Intent(MainActivity.this, SoundService.class);
                  long scheduledMillis = calculateTime(multiPickerDate, multiPickerTime);
                  if (scheduledMillis - System.currentTimeMillis() < 1000) {
                    Snackbar.make(
                            coordinator,
                            "This app cannot travel back in time...",
                            Snackbar.LENGTH_SHORT)
                        .show();
                    break;
                  }
                  Snackbar.make(
                          coordinator,
                          "Starting service at " + scheduledMillis,
                          Snackbar.LENGTH_SHORT)
                      .show();
                  i.putExtra("schedule", scheduledMillis);
                  startService(i);
                  break;
                }
              default:
                {
                  Log.d(TAG, "Uncaught event... closing dialog");
                  dialog.dismiss();
                  break;
                }
            }
          }
        };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(multiPickerLayout);
    builder.setPositiveButton("Set", dialogButtonListener);
    builder.setNegativeButton("Cancel", dialogButtonListener);
    builder.show();
  }