Java Code Examples for android.widget.TimePicker#setSaveFromParentEnabled()
The following examples show how to use
android.widget.TimePicker#setSaveFromParentEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StartNewSensor.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(!Sensor.isActive()) { setContentView(R.layout.activity_start_new_sensor); button = (Button)findViewById(R.id.startNewSensor); dp = (DatePicker)findViewById(R.id.datePicker); tp = (TimePicker)findViewById(R.id.timePicker); tp.setIs24HourView(DateFormat.is24HourFormat(this)); tp.setSaveFromParentEnabled(false); tp.setSaveEnabled(true); addListenerOnButton(); tp.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { public void onTimeChanged(TimePicker arg0, int arg1, int arg2) { Log.d("NEW SENSOR", "new time " + arg1 + " " + arg2); if(arg1 == 23 && last_hour == 0) { Log.d("NEW SENSOR", "decreading day"); addDays(-1); } if (arg1 == 0 && last_hour == 23) { Log.d("NEW SENSOR", "increasing day"); addDays(1); } last_hour = arg1; } }); last_hour = tp.getCurrentHour(); } else { Intent intent = new Intent(this, StopSensor.class); startActivity(intent); finish(); } }
Example 2
Source File: TimeWidget.java From commcare-android with Apache License 2.0 | 5 votes |
public TimeWidget(Context context, final FormEntryPrompt prompt) { super(context, prompt); mTimePicker = new TimePicker(getContext()); mTimePicker.setFocusable(!prompt.isReadOnly()); mTimePicker.setEnabled(!prompt.isReadOnly()); mTimePicker.setOnTimeChangedListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mTimePicker.setSaveFromParentEnabled(false); mTimePicker.setSaveEnabled(true); } String clockType = android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.System.TIME_12_24); if (clockType == null || clockType.equalsIgnoreCase("24")) { mTimePicker.setIs24HourView(true); } // If there's an answer, use it. setAnswer(); setGravity(Gravity.LEFT); addView(mTimePicker); }
Example 3
Source File: DateTimeWidget.java From commcare-android with Apache License 2.0 | 4 votes |
public DateTimeWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mDatePicker = new DatePicker(getContext()); mDatePicker.setFocusable(!prompt.isReadOnly()); mDatePicker.setEnabled(!prompt.isReadOnly()); mTimePicker = new TimePicker(getContext()); mTimePicker.setFocusable(!prompt.isReadOnly()); mTimePicker.setEnabled(!prompt.isReadOnly()); mTimePicker.setPadding(0, 20, 0, 0); mTimePicker.setOnTimeChangedListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mTimePicker.setSaveFromParentEnabled(false); mTimePicker.setSaveEnabled(true); } String clockType = android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.System.TIME_12_24); if (clockType == null || clockType.equalsIgnoreCase("24")) { mTimePicker.setIs24HourView(true); } mDateListener = (view, year, month, day) -> { if (mPrompt.isReadOnly()) { setAnswer(); } else { // handle leap years and number of days in month // TODO // http://code.google.com/p/android/issues/detail?id=2081 Calendar c = Calendar.getInstance(); c.set(year, month, 1); int max = c.getActualMaximum(Calendar.DAY_OF_MONTH); if (day > max) { //If the day has fallen out of spec, set it to the correct max mDatePicker.updateDate(year, month, max); } else { if (!(mDatePicker.getDayOfMonth() == day && mDatePicker.getMonth() == month && mDatePicker.getYear() == year)) { //CTS: No reason to change the day if it's already correct? mDatePicker.updateDate(year, month, day); } } } widgetEntryChanged(); }; // If there's an answer, use it. setAnswer(); setGravity(Gravity.LEFT); addView(mDatePicker); addView(mTimePicker); }