Java Code Examples for android.widget.TimePicker#setPadding()

The following examples show how to use android.widget.TimePicker#setPadding() . 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: TimeMeasurementView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected View getInputView() {
    TimePicker timePicker = new TimePicker(getContext());
    timePicker.setPadding(0, 15, 0, 0);

    Calendar cal = Calendar.getInstance();
    cal.setTime(time);

    timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(cal.get(Calendar.MINUTE));
    timePicker.setIs24HourView(android.text.format.DateFormat.is24HourFormat(getContext()));

    return timePicker;
}
 
Example 2
Source File: DateTimeWidget.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
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);

}