public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { int buttonID = buttonView.getId(); if (buttonID == R.id.switchNotificationLO) { if (isChecked) { repeatSpinner.setEnabled(true); timepicker.setEnabled(true); datepicker.setEnabled(true); } else { repeatSpinner.setEnabled(false); timepicker.setEnabled(false); datepicker.setEnabled(false); } } }
public void initilizeForNewTask() { repeatAlarmInterval = -1; // disable the time picker on the oncreate // set the timepicker to view 24 hours format timepicker.setEnabled(false); datepicker.setEnabled(false); repeatSpinner.setEnabled(false); notifySwitch.setChecked(false); // button, add the task }
private void setFieldsEnabled(boolean v) { _datePicker.setEnabled(v); _timePicker.setEnabled(v); _okButton.setEnabled(v); _cancelButton.setEnabled(v); }
/** * 생성자 * * @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)); }
@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(); } }); }