public PilihWaktu(Context context, Handler handler) { super(context); mHandler = handler; setTitle("Pilih Waktu : "); setContentView(R.layout.monitoring_waktu); TimePicker time1 = (TimePicker) findViewById(R.id.monitoringTime1); time1.setIs24HourView(true); TimePicker time2 = (TimePicker) findViewById(R.id.monitoringTime2); time2.setIs24HourView(true); }
private void initilizeViewVariables() { clearDescriptionButton = (Button) findViewById(R.id.descriptionCLRbtn); clearTitleButton = (Button) findViewById(R.id.titleCLRbtn); notifySwitch = (Switch) findViewById(R.id.switchNotificationLO); repeatSpinner = (Spinner) findViewById(R.id.spinnerRepeatingLO); timepicker = (TimePicker) findViewById(R.id.timePickerLO); datepicker = (DatePicker) findViewById(R.id.datePickerLO); timepicker.setIs24HourView(true); titleInputext = (EditText) findViewById(R.id.TitleEditTextLO); titleInputext.requestFocus(); descriptionInputText = (EditText) findViewById(R.id.descriptionEditTextLO); repeatAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.repeatArray)); repeatSpinner.setAdapter(repeatAdapter); clearDescriptionButton.setOnClickListener(this); clearTitleButton.setOnClickListener(this); drawer.setOnOpenListener(this); drawer.setOnCloseListener(this); notifySwitch.setOnCheckedChangeListener(this); initilizeVariables(); inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null) { inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } }
@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(); }
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; }
/** * 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; }
@Override protected View onCreateDialogView() { value = getPersistedValue(); timePicker = new TimePicker(getContext()); timePicker.setIs24HourView(true); timePicker.setCurrentHour(value.first); timePicker.setCurrentMinute(value.second); return timePicker; }
/** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TimePicker tp = (TimePicker) this.findViewById(R.id.timePicker); tp.setIs24HourView(true); // открываем подключение к БД db = new DB(this); db.open(); refreshCursor(); }
private void setEndTime(final TimeObject startTime) { LinearLayout layout = new LinearLayout(PlayBackActivity.this); layout.setOrientation(LinearLayout.VERTICAL); layout.setBackgroundColor(getResources().getColor(R.color.white)); final TimePicker mTimePicker = new TimePicker(PlayBackActivity.this); final DatePicker mDatePicker = new DatePicker(PlayBackActivity.this); mTimePicker.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS); mTimePicker.setIs24HourView(true); mDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS); final TextView tv = new TextView(PlayBackActivity.this); String time = String.format("%02d:%02d", startTime.getHour(), startTime.getMinute()); String date = String.valueOf(startTime.getYear()) + "年" + String.format("%02d", startTime.getMonth()) + "月" + String.format("%02d", startTime.getDay()) + "日"; tv.setText("开始时间:" + date + " " + time); int version = Integer.valueOf(android.os.Build.VERSION.SDK); if (version >= 11) mDatePicker.setCalendarViewShown(false); layout.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); layout.addView( mDatePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); layout.addView( mTimePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); new AlertDialog.Builder(PlayBackActivity.this) .setTitle("请选择结束时间:") .setView(layout) .setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { TimeObject endTime = new TimeObject( mTimePicker.getCurrentMinute(), mTimePicker.getCurrentHour(), mDatePicker.getDayOfMonth(), mDatePicker.getMonth() + 1, mDatePicker.getYear()); System.out.println("时间:" + endTime.getMinute() + " " + startTime.getMinute()); onTimeSearch(startTime, endTime); } }) .setNegativeButton( android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) {} }) .create() .show(); }
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); }
/* * (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 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(); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.schedulersettime); final LinearLayout btExit = (LinearLayout) findViewById(R.id.btExit); final DatePicker date = (DatePicker) findViewById(R.id.Scheduler_datePicker); final TimePicker time = (TimePicker) findViewById(R.id.Scheduler_timePicker); if (!time.is24HourView()) { time.setIs24HourView(true); } final LinearLayout btSet = (LinearLayout) findViewById(R.id.Scheduler_Settime); btSet.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { ButtonAnimation.ChangingAnimaionBack(btSet); String str = time.getCurrentHour() + ":" + time.getCurrentMinute() + " " + date.getDayOfMonth() + "/" + ((int) date.getMonth() + 1) + "/" + date.getYear(); All_Var.Date = str; finish(); } }); btExit.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { ButtonAnimation.ChangingAnimaionBack(btExit); finish(); } }); }
@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 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); mPixicleId = intent.getIntExtra(Constants.ARG_PIXICLE_IDENTITY, -1); mDeviceIdentifier = intent.getStringExtra(Constants.ARG_DEVICE_IDENTITY); mAccessToken = intent.getStringExtra(Constants.ARG_ACCESS_TOKEN); mConfiguration = intent.getStringExtra(Constants.ARG_CONFIGURATION); setContentView(R.layout.activity_schedule_configuration); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); TimePicker timePicker = (TimePicker) findViewById(R.id.schedule_time); timePicker.setIs24HourView(DateFormat.is24HourFormat(this)); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { DatePicker datePicker = (DatePicker) findViewById(R.id.schedule_date); TimePicker timePicker = (TimePicker) findViewById(R.id.schedule_time); int year = datePicker.getYear(); int month = datePicker.getMonth(); int dayOfMonth = datePicker.getDayOfMonth(); int hour = timePicker.getCurrentHour(); int minute = timePicker.getCurrentMinute(); GregorianCalendar gregDate = new GregorianCalendar(year, month, dayOfMonth, hour, minute, 0); Long gregTime = gregDate.getTimeInMillis() / 1000; Date debugDate = new Date(); Long debugTime = debugDate.getTime() / 1000; Log.d( "SchedCfgActivity", "Current time is " + debugTime + " schedule time is " + gregTime + " which is " + (gregTime - debugTime) + " seconds into the future."); String config = gregTime.toString() + ":" + mConfiguration; new PixicleAsyncTask() .execute( mAccessToken, mDeviceIdentifier, PixicleAsyncTask.FUNCTION_SCHEDULE_CONFIG, config); finish(); } }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
// Metodo que despliega un TimePicker para seleccionar la hora inicial y final del filtro. public void abrirDialogoTiempo() { // Se crea una ventana de dialogo tomando en cuenta un layout que contiene un TimePicker y tres // botones (Aceptar, Reset y Cancelar). final Dialog dialogoHora = new Dialog(this); LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); final RelativeLayout vistaDialogoHora = (RelativeLayout) inflater.inflate(R.layout.hora, null); final Button boton1 = (Button) vistaDialogoHora.findViewById(R.id.Aceptar); final Button boton2 = (Button) vistaDialogoHora.findViewById(R.id.Reset); final Button boton3 = (Button) vistaDialogoHora.findViewById(R.id.Cancelar); final TimePicker timePicker = (TimePicker) vistaDialogoHora.findViewById(R.id.TimePicker); // Se establece que el TimePicker estara en el formato de 24 hrs. timePicker.setIs24HourView(true); // Para el boton "Aceptar", se toma la hora establecida por el usuario a partir del TimePicker y // Se guarda el valor de la hora en la variable hora Inicial y hora Final segun sea el caso. boton1.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { timePicker.clearFocus(); hora = timePicker.getCurrentHour(); minuto = timePicker.getCurrentMinute(); dialogoHora.dismiss(); if (seleccion == 1) { Toast.makeText( getBaseContext(), "Hora Inicial: " + reacomodar(hora) + ":" + reacomodar(minuto) + ":00", Toast.LENGTH_SHORT) .show(); horaInicial = reacomodar(hora) + ":" + reacomodar(minuto) + ":00"; } else { Toast.makeText( getBaseContext(), "Hora Final: " + reacomodar(hora) + ":" + reacomodar(minuto) + ":00", Toast.LENGTH_SHORT) .show(); horaFinal = reacomodar(hora) + ":" + reacomodar(minuto) + ":00"; } } }); // Para el boton "Reset", se reestablecen los valores del TimePicker. boton2.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { final Calendar c = Calendar.getInstance(); timePicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY)); timePicker.setCurrentMinute(c.get(Calendar.MINUTE)); } }); // Para el boton "Cancelar", se desaparece la ventana de Dialogo. boton3.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { dialogoHora.cancel(); } }); // Se establece la vista para la ventana y se muestra. dialogoHora.requestWindowFeature(Window.FEATURE_NO_TITLE); dialogoHora.setContentView(vistaDialogoHora); dialogoHora.show(); }
public void setIs24HourView(final boolean is24HourView) { timePicker.setIs24HourView(is24HourView); }
@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; }
public View getView() throws UnsupportedOperationException { if (mType.equals("checkbox")) { CheckBox checkbox = new CheckBox(GeckoApp.mAppContext); checkbox.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); checkbox.setText(mLabel); checkbox.setChecked(getSafeBool(mJSONInput, "checked")); mView = (View) checkbox; } else if (mType.equals("date")) { try { DateTimePicker input = new DateTimePicker( GeckoApp.mAppContext, "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(GeckoApp.mAppContext); 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( GeckoApp.mAppContext, "yyyy-'W'ww", mValue, DateTimePicker.PickersState.WEEK); mView = (View) input; } else if (mType.equals("time")) { TimePicker input = new TimePicker(GeckoApp.mAppContext); input.setIs24HourView(DateFormat.is24HourFormat(GeckoApp.mAppContext)); GregorianCalendar calendar = new GregorianCalendar(); if (!TextUtils.isEmpty(mValue)) { try { calendar.setTime(new SimpleDateFormat("kk: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( GeckoApp.mAppContext, "yyyy-MM-dd kk:mm", mValue, DateTimePicker.PickersState.DATETIME); input.toggleCalendar(true); mView = (View) input; } else if (mType.equals("month")) { DateTimePicker input = new DateTimePicker( GeckoApp.mAppContext, "yyyy-MM", mValue, DateTimePicker.PickersState.MONTH); mView = (View) input; } else if (mType.equals("textbox") || mType.equals("password")) { EditText input = new EditText(GeckoApp.mAppContext); int inputtype = InputType.TYPE_CLASS_TEXT; if (mType.equals("password")) { inputtype |= InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; } input.setInputType(inputtype); input.setText(mValue); if (!TextUtils.isEmpty(mHint)) { input.setHint(mHint); } if (mAutofocus) { input.setOnFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { ((InputMethodManager) GeckoApp.mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(v, 0); } } }); input.requestFocus(); } mView = (View) input; } else if (mType.equals("menulist")) { Spinner spinner = new Spinner(GeckoApp.mAppContext); try { String[] listitems = getStringArray(mJSONInput, "values"); if (listitems.length > 0) { ArrayAdapter<String> adapter = new ArrayAdapter<String>( GeckoApp.mAppContext, R.layout.simple_dropdown_item_1line, listitems); spinner.setAdapter(adapter); int selectedIndex = getSafeInt(mJSONInput, "selected"); spinner.setSelection(selectedIndex); } } catch (Exception ex) { } mView = (View) spinner; } else if (mType.equals("label")) { // not really an input, but a way to add labels and such to the dialog TextView view = new TextView(GeckoApp.mAppContext); view.setText(Html.fromHtml(mLabel)); mView = view; } return mView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_task_detail); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); setSupportActionBar(toolbar); LineColorPicker colorPicker = (LineColorPicker) findViewById(R.id.picker); // set color palette colorPicker.setColors( new int[] { Color.parseColor("#b8c847"), Color.parseColor("#67bb43"), Color.parseColor("#41b691"), Color.parseColor("#4182b6"), Color.parseColor("#4149b6"), Color.parseColor("#7641b6"), Color.parseColor("#b741a7"), Color.parseColor("#c54657"), Color.parseColor("#d1694a") }); // set on change listener colorPicker.setOnColorChangedListener( new OnColorChangedListener() { @Override public void onColorChanged(int c) { task_color = c; // Log.d(TAG, "Selected color " + Integer.toHexString(c)); } }); // get selected color // task_color = colorPicker.getColor(); Bundle extras = getIntent().getExtras(); task_id = extras.getLong(EXTRA_TASK_ID); task_name = extras.getString(EXTRA_TASK_NAME); setTitle(task_name); task_desc = extras.getString(EXTRA_TASK_DESC); task_done = extras.getBoolean(EXTRA_TASK_DONE); task_color = extras.getInt(EXTRA_TASK_COLOR); colorPicker.setSelectedColor(task_color); task_limitedate = extras.getString(EXTRA_TASK_LIMITE_DATE); int callingActivity = getIntent().getIntExtra("calling-activity", 0); switch (callingActivity) { case ActivityConstants.TasksList: EditText name = (EditText) findViewById(R.id.editTextTaskName); EditText desc = (EditText) findViewById(R.id.editTextTaskDescription); DatePicker date = (DatePicker) findViewById(R.id.datePickerTask); TimePicker time = (TimePicker) findViewById(R.id.timePickerTask); CheckBox checkBox = (CheckBox) findViewById(R.id.checkBoxTaskDetail); checkBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { task_done = isChecked; } }); name.setText(task_name); desc.setText(task_desc); checkBox.setChecked(task_done); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-hh:mm"); Date theDate = new Date(); try { theDate = format.parse(task_limitedate); } catch (ParseException e) { e.printStackTrace(); } Calendar myCal = new GregorianCalendar(); myCal.setTime(theDate); int Year = myCal.get(Calendar.YEAR); int Month = myCal.get(Calendar.MONTH); int Day = myCal.get(Calendar.DAY_OF_MONTH); int Hour = myCal.get(Calendar.HOUR_OF_DAY); int Min = myCal.get(Calendar.MINUTE); date.init( Year, Month, Day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged( DatePicker view, int year, int monthOfYear, int dayOfMonth) { // Notify the user. } }); time.setIs24HourView(true); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= Build.VERSION_CODES.M) { time.setHour(Hour); time.setMinute(Min); } else { time.setCurrentHour(Hour); time.setCurrentMinute(Min); } break; } }
/** 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(); }
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; } }
@Override protected View onCreateDialogView() { m_picker = new TimePicker(getContext()); m_picker.setIs24HourView(DateFormat.is24HourFormat(getContext())); return m_picker; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.newsubject_newclass); getWindow() .setLayout(LayoutParams.FILL_PARENT /* width */, LayoutParams.WRAP_CONTENT /* height */); classRoom = (EditText) findViewById(R.id.room); classStart = (TimePicker) findViewById(R.id.timePicker1); classStart.setIs24HourView(true); classEnd = (TimePicker) findViewById(R.id.timePicker2); classEnd.setIs24HourView(true); try { db.open(this, "com.albertoelias.agenda"); } catch (Exception e) { e.printStackTrace(); } daySpinner = (Spinner) findViewById(R.id.daySpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.days_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); daySpinner.setAdapter(adapter); Button Cancel = (Button) findViewById(R.id.cancel); Button Submit = (Button) findViewById(R.id.submit); long mRowId = savedInstanceState != null ? savedInstanceState.getLong(DataFramework.KEY_ID) : -1; if (mRowId < 0) { Bundle extras = getIntent().getExtras(); if (extras.containsKey("SubjectID")) { this.subjectId = extras.getString("SubjectID"); currentEntity = new Entity("date"); } else { mRowId = extras != null ? extras.getLong(DataFramework.KEY_ID) : -1; currentEntity = new Entity("date", mRowId); populateFields(); } } Submit.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { int daynumber = daySpinner.getSelectedItemPosition() + 2; if (daynumber == 8) { daynumber = 1; } currentEntity.setValue("day", daynumber); currentEntity.setValue("room", classRoom.getText().toString()); currentEntity.setValue("starttimehour", classStart.getCurrentHour()); currentEntity.setValue("starttimeminute", classStart.getCurrentMinute()); currentEntity.setValue("endtimehour", classEnd.getCurrentHour()); currentEntity.setValue("endtimeminute", classEnd.getCurrentMinute()); // Para cuando funcione el pulsar en un elemento de la lista if (subjectId != null) { currentEntity.setValue("subject_id", subjectId); } currentEntity.save(); setResult(RESULT_OK); finish(); } }); Cancel.setOnClickListener( new View.OnClickListener() { public void onClick(View cancel) { setResult(RESULT_CANCELED); finish(); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sleep_time_set); Toolbar toolbar = (Toolbar) findViewById(R.id.set_toolbar); setSupportActionBar(toolbar); toolbar.setTitle("ReSleep"); toolbar.setSubtitle("睡眠時間設定"); toolbar.setNavigationIcon(R.drawable.back_icon); toolbar.setNavigationOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(), SettingActivity.class); startActivity(intent); } }); final TimePicker timePicker = (TimePicker) findViewById(R.id.sleepTimePicker); timePicker.setIs24HourView(true); timePicker.setCurrentHour(loadUserInfo(7L)); timePicker.setCurrentMinute(loadUserInfo(8L)); Button button = (Button) findViewById(R.id.changeButton); button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { int hour = timePicker.getCurrentHour(); int min = timePicker.getCurrentMinute(); User userWakeHour = getUserDao(getApplicationContext()).loadByRowId(3L); int wakeHour = Integer.valueOf(userWakeHour.getText()); User userWakeMin = getUserDao(getApplicationContext()).loadByRowId(4L); int wakeMin = Integer.valueOf(userWakeMin.getText()); int sleepHour, sleepMin; if (min == 0) { sleepMin = wakeMin; sleepHour = wakeHour - hour; } else if (min > wakeMin) { sleepMin = 60 - (min - wakeMin); sleepHour = wakeHour - hour - 1; } else { sleepMin = wakeMin - min; sleepHour = wakeHour - hour; } if (sleepHour < wakeHour) { sleepHour += 24; } insertUserInfo(String.valueOf(sleepHour), System.currentTimeMillis(), "SLEEP_HOUR", 5L); outputUserInfo(String.valueOf(sleepHour) + ", sleep_hour"); insertUserInfo(String.valueOf(sleepMin), System.currentTimeMillis(), "SLEEP_MIN", 6L); outputUserInfo(String.valueOf(sleepMin) + ", sleep_min"); insertUserInfo(String.valueOf(hour), System.currentTimeMillis(), "SLEEPTIME_HOUR", 7L); outputUserInfo(String.valueOf(hour) + ", sleeptime_hour"); insertUserInfo(String.valueOf(min), System.currentTimeMillis(), "SLEEPTIME_MIN", 8L); outputUserInfo(String.valueOf(min) + ", sleeptime_min"); setRange(); Toast.makeText( getApplicationContext(), "睡眠時間を" + hour + "時間" + min + "分に設定しました", Toast.LENGTH_LONG) .show(); } }); }